@fluixi/core 1.0.0-alpha.83 → 1.0.0-alpha.84

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 (177) hide show
  1. package/dist/cdn/core.global.js +2 -1
  2. package/dist/cli/generate.cjs +4117 -292
  3. package/dist/cli/generate.mjs +4122 -292
  4. package/dist/cli/index.cjs +4117 -292
  5. package/dist/cli/index.mjs +4122 -292
  6. package/dist/cli/run.cjs +63 -1
  7. package/dist/cli/run.mjs +39 -1
  8. package/dist/src/cdn/chunk-VNLCQBFQ.mjs +747 -0
  9. package/dist/src/cdn/core.cjs +1279 -1
  10. package/dist/src/cdn/core.d.ts +3 -3
  11. package/dist/src/cdn/core.js +3 -3
  12. package/dist/src/cdn/core.mjs +642 -1
  13. package/dist/src/cdn/router-WMN2AA7E.mjs +66 -0
  14. package/dist/src/index.cjs +1201 -1
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +1 -11
  17. package/dist/src/index.mjs +1313 -1
  18. package/dist/src/jsx-dev-runtime.cjs +26 -1
  19. package/dist/src/jsx-dev-runtime.mjs +24 -1
  20. package/dist/src/jsx-runtime.cjs +26 -1
  21. package/dist/src/jsx-runtime.js +0 -9
  22. package/dist/src/jsx-runtime.mjs +24 -1
  23. package/dist/src/lib/client/chunk-2C2KDDQV.mjs +133 -0
  24. package/dist/src/lib/client/index.cjs +870 -1
  25. package/dist/src/lib/client/index.d.ts +17 -6
  26. package/dist/src/lib/client/index.d.ts.map +1 -1
  27. package/dist/src/lib/client/index.js +26 -19
  28. package/dist/src/lib/client/index.mjs +222 -1
  29. package/dist/src/lib/client/router-X526HSWQ.mjs +548 -0
  30. package/dist/src/lib/context/context.cjs +118 -1
  31. package/dist/src/lib/context/context.d.ts +19 -37
  32. package/dist/src/lib/context/context.d.ts.map +1 -1
  33. package/dist/src/lib/context/context.js +8 -45
  34. package/dist/src/lib/context/context.mjs +99 -1
  35. package/dist/src/lib/context/index.cjs +120 -1
  36. package/dist/src/lib/context/index.mjs +99 -1
  37. package/dist/src/lib/control-flow.cjs +35 -1
  38. package/dist/src/lib/control-flow.mjs +25 -1
  39. package/dist/src/lib/core.cjs +1200 -1
  40. package/dist/src/lib/core.d.ts +0 -2
  41. package/dist/src/lib/core.d.ts.map +1 -1
  42. package/dist/src/lib/core.js +14 -48
  43. package/dist/src/lib/core.mjs +1313 -1
  44. package/dist/src/lib/env/index.cjs +60 -1
  45. package/dist/src/lib/env/index.d.ts +5 -5
  46. package/dist/src/lib/env/index.js +5 -5
  47. package/dist/src/lib/env/index.mjs +39 -1
  48. package/dist/src/lib/i18n/index.cjs +108 -1
  49. package/dist/src/lib/i18n/index.d.ts +31 -10
  50. package/dist/src/lib/i18n/index.d.ts.map +1 -1
  51. package/dist/src/lib/i18n/index.js +31 -10
  52. package/dist/src/lib/i18n/index.mjs +88 -1
  53. package/dist/src/lib/index.cjs +633 -1
  54. package/dist/src/lib/index.d.ts +0 -2
  55. package/dist/src/lib/index.d.ts.map +1 -1
  56. package/dist/src/lib/index.js +5 -11
  57. package/dist/src/lib/index.mjs +721 -1
  58. package/dist/src/lib/isomorphic.cjs +85 -1
  59. package/dist/src/lib/isomorphic.d.ts +41 -8
  60. package/dist/src/lib/isomorphic.d.ts.map +1 -1
  61. package/dist/src/lib/isomorphic.js +38 -5
  62. package/dist/src/lib/isomorphic.mjs +64 -1
  63. package/dist/src/lib/jsx-runtime/index.cjs +21 -1
  64. package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
  65. package/dist/src/lib/jsx-runtime/index.js +1 -11
  66. package/dist/src/lib/jsx-runtime/index.mjs +4 -1
  67. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
  68. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
  69. package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
  70. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
  71. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
  72. package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
  73. package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
  74. package/dist/src/lib/plugins/index.cjs +311 -8
  75. package/dist/src/lib/plugins/index.mjs +279 -8
  76. package/dist/src/lib/plugins/route-codegen.cjs +73 -8
  77. package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
  78. package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
  79. package/dist/src/lib/plugins/route-codegen.js +4 -5
  80. package/dist/src/lib/plugins/route-codegen.mjs +52 -8
  81. package/dist/src/lib/plugins/route-scanner.cjs +189 -1
  82. package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
  83. package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
  84. package/dist/src/lib/plugins/route-scanner.js +7 -8
  85. package/dist/src/lib/plugins/route-scanner.mjs +158 -1
  86. package/dist/src/lib/plugins/vite.cjs +27 -1
  87. package/dist/src/lib/plugins/vite.mjs +6 -1
  88. package/dist/src/lib/render/await.cjs +38 -1
  89. package/dist/src/lib/render/await.d.ts +18 -0
  90. package/dist/src/lib/render/await.d.ts.map +1 -1
  91. package/dist/src/lib/render/await.js +20 -2
  92. package/dist/src/lib/render/await.mjs +17 -1
  93. package/dist/src/lib/render/component.cjs +221 -1
  94. package/dist/src/lib/render/component.d.ts +3 -44
  95. package/dist/src/lib/render/component.d.ts.map +1 -1
  96. package/dist/src/lib/render/component.js +23 -55
  97. package/dist/src/lib/render/component.mjs +214 -1
  98. package/dist/src/lib/render/deferred.cjs +175 -1
  99. package/dist/src/lib/render/deferred.js +5 -5
  100. package/dist/src/lib/render/deferred.mjs +158 -1
  101. package/dist/src/lib/render/index.cjs +573 -1
  102. package/dist/src/lib/render/index.d.ts +3 -17
  103. package/dist/src/lib/render/index.d.ts.map +1 -1
  104. package/dist/src/lib/render/index.js +8 -22
  105. package/dist/src/lib/render/index.mjs +590 -1
  106. package/dist/src/lib/render/lazy.cjs +67 -1
  107. package/dist/src/lib/render/lazy.d.ts +22 -1
  108. package/dist/src/lib/render/lazy.d.ts.map +1 -1
  109. package/dist/src/lib/render/lazy.js +26 -5
  110. package/dist/src/lib/render/lazy.mjs +50 -1
  111. package/dist/src/lib/render/suspense.cjs +141 -1
  112. package/dist/src/lib/render/suspense.d.ts +40 -0
  113. package/dist/src/lib/render/suspense.d.ts.map +1 -1
  114. package/dist/src/lib/render/suspense.js +46 -6
  115. package/dist/src/lib/render/suspense.mjs +136 -1
  116. package/dist/src/lib/render/versions.cjs +35 -1
  117. package/dist/src/lib/render/versions.js +6 -6
  118. package/dist/src/lib/render/versions.mjs +14 -1
  119. package/dist/src/lib/router/data.cjs +230 -1
  120. package/dist/src/lib/router/data.d.ts +1 -13
  121. package/dist/src/lib/router/data.d.ts.map +1 -1
  122. package/dist/src/lib/router/data.js +0 -12
  123. package/dist/src/lib/router/data.mjs +214 -1
  124. package/dist/src/lib/router/index.cjs +627 -1
  125. package/dist/src/lib/router/index.d.ts +62 -10
  126. package/dist/src/lib/router/index.d.ts.map +1 -1
  127. package/dist/src/lib/router/index.js +85 -33
  128. package/dist/src/lib/router/index.mjs +639 -1
  129. package/dist/src/lib/server/hydration.cjs +169 -1
  130. package/dist/src/lib/server/hydration.d.ts +15 -55
  131. package/dist/src/lib/server/hydration.d.ts.map +1 -1
  132. package/dist/src/lib/server/hydration.js +23 -62
  133. package/dist/src/lib/server/hydration.mjs +148 -1
  134. package/dist/src/lib/server/index.cjs +401 -11
  135. package/dist/src/lib/server/index.d.ts +30 -6
  136. package/dist/src/lib/server/index.d.ts.map +1 -1
  137. package/dist/src/lib/server/index.js +34 -11
  138. package/dist/src/lib/server/index.mjs +379 -11
  139. package/dist/src/lib/server/reactive.cjs +197 -1
  140. package/dist/src/lib/server/reactive.d.ts +18 -77
  141. package/dist/src/lib/server/reactive.d.ts.map +1 -1
  142. package/dist/src/lib/server/reactive.js +19 -78
  143. package/dist/src/lib/server/reactive.mjs +176 -1
  144. package/dist/src/lib/theme/index.cjs +110 -1
  145. package/dist/src/lib/theme/index.d.ts +19 -4
  146. package/dist/src/lib/theme/index.d.ts.map +1 -1
  147. package/dist/src/lib/theme/index.js +17 -2
  148. package/dist/src/lib/theme/index.mjs +89 -1
  149. package/dist/src/lib/utils/index.cjs +209 -1
  150. package/dist/src/lib/utils/index.d.ts +0 -93
  151. package/dist/src/lib/utils/index.d.ts.map +1 -1
  152. package/dist/src/lib/utils/index.js +0 -93
  153. package/dist/src/lib/utils/index.mjs +188 -1
  154. package/dist/src/routes.cjs +37 -1
  155. package/dist/src/routes.d.ts +1 -1
  156. package/dist/src/routes.js +2 -2
  157. package/dist/src/routes.mjs +17 -1
  158. package/dist/src/server.cjs +400 -11
  159. package/dist/src/server.d.ts +0 -1
  160. package/dist/src/server.d.ts.map +1 -1
  161. package/dist/src/server.js +0 -1
  162. package/dist/src/server.mjs +377 -11
  163. package/dist/src/utils.cjs +21 -1
  164. package/dist/src/utils.d.ts +1 -1
  165. package/dist/src/utils.js +1 -1
  166. package/dist/src/utils.mjs +4 -1
  167. package/dist/src/version.generated.cjs +26 -1
  168. package/dist/src/version.generated.d.ts +1 -1
  169. package/dist/src/version.generated.js +2 -2
  170. package/dist/src/version.generated.mjs +5 -1
  171. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  172. package/package.json +17 -16
  173. package/src/index.ts +2 -14
  174. package/dist/src/cdn/chunk-55BT3H6E.mjs +0 -1
  175. package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
  176. package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
  177. package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
@@ -1,8 +1,279 @@
1
- import{fluixi as X,createVitePlugin as q}from"@fluixi/vite-plugin";import*as j from"path";import{nodePolyfills as k}from"vite-plugin-node-polyfills";import*as g from"fs";import*as h from"path";var w=[".tsx",".ts",".jsx",".js"];function b(t,e={}){let n=e.extensions??w,s=h.resolve(t);return g.existsSync(s)?_(s,s,"",n):[]}function _(t,e,n,s){let u=g.readdirSync(t,{withFileTypes:!0}),o=[],m=null,c=[],p=[];for(let r of u)r.isDirectory()?p.push(r):r.isFile()&&E(r.name,s)&&c.push(r);let i,l=[];for(let r of c)L(r.name)==="layout"?i=I(r.name,t,e,n,!0):l.push(r);let d=[];for(let r of l)d.push(I(r.name,t,e,n,!1));let a=[];for(let r of p){let f=r.name,y=G(f),x=y?"":M(f),D=x?A(n,x):n,P=_(h.join(t,f),e,D,s);if(y)a.push(...P);else{let S=P.find(R=>R.isLayout&&R.urlPath===D),O=P.filter(R=>!R.isLayout||R.urlPath!==D);S?(S.children=[...S.children,...O],a.push(S)):O.length>0&&a.push(...O)}}return i?(i.children=[...d,...a],o.push(i)):o.push(...d,...a),T(o)}function I(t,e,n,s,u){let o=L(t),m=h.relative(n,h.join(e,t)),c=o==="index",p=o.startsWith("[..."),i=!p&&o.startsWith("[")&&o.endsWith("]"),l;u?l="":c?l="/":p?l=`*${o.slice(4,-1)}`:i?l=`:${o.slice(1,-1)}`:l=o;let d=u||c?s||"/":A(s,l),a=h.join(e,t),r=!1;try{let f=g.readFileSync(a,"utf-8");r=/export\s+(const|function|async\s+function)\s+routeData\b/.test(f)}catch{}return{filePath:m.replace(/\\/g,"/"),urlSegment:l,urlPath:d,isLayout:u,isIndex:c,isDynamic:i,isCatchAll:p,isGroup:!1,children:[],parentUrlPath:s,hasRouteData:r,rootDir:n,dir:e}}function E(t,e){return e.some(n=>t.endsWith(n))}function L(t){let e=t.lastIndexOf(".");return e>0?t.slice(0,e):t}function G(t){return t.startsWith("(")&&t.endsWith(")")}function M(t){return t.startsWith("[...")&&t.endsWith("]")?"*"+t.slice(4,-1):t.startsWith("[")&&t.endsWith("]")?":"+t.slice(1,-1):t}function A(t,e){return(t.endsWith("/")?t:t+"/")+e}function T(t){return t.sort((e,n)=>e.isLayout&&!n.isLayout?-1:!e.isLayout&&n.isLayout?1:e.isIndex&&!n.isIndex?-1:!e.isIndex&&n.isIndex?1:!e.isDynamic&&!e.isCatchAll&&(n.isDynamic||n.isCatchAll)?-1:(e.isDynamic||e.isCatchAll)&&!n.isDynamic&&!n.isCatchAll?1:e.isDynamic&&n.isCatchAll?-1:e.isCatchAll&&n.isDynamic?1:e.urlSegment.localeCompare(n.urlSegment))}function C(t,e){let n=[];return n.push("// Auto-generated by fluixi route plugin"),n.push("// Do not edit manually"),n.push(""),n.push("import { lazy } from '@fluixi/core/router';"),n.push(""),n.push(`export const routes = ${W(t,e,0)};`),n.push(""),n.join(`
2
- `)}function W(t,e,n){if(t.length===0)return"[]";let s=" ".repeat(n);return`[
3
- ${t.map(o=>V(o,e,n+1)).join(`,
4
- `)}
5
- ${s}]`}function V(t,e,n){let s=" ".repeat(n),u=[],o=N(t.filePath,e),m=v(t);if(u.push(`${s} path: ${JSON.stringify(m)}`),u.push(`${s} component: lazy(() => import(${JSON.stringify(o)}))`),t.hasRouteData&&u.push(`${s} data: (args, __owner, __isCancelled) => import(${JSON.stringify(o)}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`),t.children.length>0){let c=W(t.children,e,n+1);u.push(`${s} children: ${c}`)}return`${s}{
6
- ${u.join(`,
7
- `)}
8
- ${s}}`}function v(t){return t.urlPath}function N(t,e){return`${e.replace(/\\/g,"/").replace(/\/$/,"")}/${t}`}var F="virtual:fluixi-routes",$="\0"+F,J="@fluixi/core/routes";function U(t={}){let e=t.routesDir??"src/routes",n=t.extensions??[".tsx",".ts",".jsx",".js"],s="",u=null;function o(i){let l=j.resolve(i,e),a=b(l,{extensions:n});return C(a,"./"+e)}let c=t.polyfills!==!1?Object.assign({},k({include:["fs","path"]}),{apply:"serve"}):null,p={name:"fluixi-routes",enforce:"pre",configResolved(i){s=i.root||process.cwd()},resolveId(i){return i===F||i===J?$:null},load(i){return i!==$?null:(u=o(s||process.cwd()),u)},configureServer(i){let l=s||process.cwd(),d=j.resolve(l,e);i.watcher.add(d),i.watcher.on("all",(a,r)=>{if(!r.startsWith(d)||!["add","unlink","addDir","unlinkDir","change"].includes(a)||a!=="addDir"&&a!=="unlinkDir"&&!n.some(x=>r.endsWith(x)))return;let f=o(l);if(f===u)return;u=f;let y=i.moduleGraph.getModuleById($);y&&(i.moduleGraph.invalidateModule(y),i.ws.send({type:"full-reload"}))})}};return c?[c,p]:[p]}export{q as createVitePlugin,X as fluixi,U as fluixiRoutesPlugin,b as scanRoutes};
1
+ /*! @fluixi/core v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
+
3
+ // src/lib/plugins/vite.ts
4
+ import { fluixi, createVitePlugin } from "@fluixi/vite-plugin";
5
+
6
+ // src/lib/plugins/fluixi-routes-plugin.ts
7
+ import * as path2 from "path";
8
+ import { nodePolyfills } from "vite-plugin-node-polyfills";
9
+
10
+ // src/lib/plugins/route-scanner.ts
11
+ import * as fs from "fs";
12
+ import * as path from "path";
13
+ var DEFAULT_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
14
+ function scanRoutes(routesDir, options = {}) {
15
+ const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
16
+ const absDir = path.resolve(routesDir);
17
+ if (!fs.existsSync(absDir)) {
18
+ return [];
19
+ }
20
+ return scanDirectory(absDir, absDir, "", extensions);
21
+ }
22
+ function scanDirectory(dir, rootDir, parentUrlPath, extensions) {
23
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
24
+ const routes = [];
25
+ const layoutRoute = null;
26
+ const files = [];
27
+ const dirs = [];
28
+ for (const entry of entries) {
29
+ if (entry.isDirectory()) {
30
+ dirs.push(entry);
31
+ } else if (entry.isFile() && hasValidExtension(entry.name, extensions)) {
32
+ files.push(entry);
33
+ }
34
+ }
35
+ let layout;
36
+ const nonLayoutFiles = [];
37
+ for (const file of files) {
38
+ const baseName = stripExtension(file.name);
39
+ if (baseName === "layout") {
40
+ layout = buildFileRoute(file.name, dir, rootDir, parentUrlPath, true);
41
+ } else {
42
+ nonLayoutFiles.push(file);
43
+ }
44
+ }
45
+ const fileRoutes = [];
46
+ for (const file of nonLayoutFiles) {
47
+ fileRoutes.push(
48
+ buildFileRoute(file.name, dir, rootDir, parentUrlPath, false)
49
+ );
50
+ }
51
+ const dirRoutes = [];
52
+ for (const d of dirs) {
53
+ const dirName = d.name;
54
+ const isGroup = isRouteGroup(dirName);
55
+ const segment = isGroup ? "" : dirNameToSegment(dirName);
56
+ const childUrlPath = segment ? joinUrlPath(parentUrlPath, segment) : parentUrlPath;
57
+ const children = scanDirectory(
58
+ path.join(dir, dirName),
59
+ rootDir,
60
+ childUrlPath,
61
+ extensions
62
+ );
63
+ if (isGroup) {
64
+ dirRoutes.push(...children);
65
+ } else {
66
+ const childLayout = children.find((c) => c.isLayout && c.urlPath === childUrlPath);
67
+ const childNonLayout = children.filter((c) => !c.isLayout || c.urlPath !== childUrlPath);
68
+ if (childLayout) {
69
+ childLayout.children = [...childLayout.children, ...childNonLayout];
70
+ dirRoutes.push(childLayout);
71
+ } else if (childNonLayout.length > 0) {
72
+ dirRoutes.push(...childNonLayout);
73
+ }
74
+ }
75
+ }
76
+ if (layout) {
77
+ layout.children = [...fileRoutes, ...dirRoutes];
78
+ routes.push(layout);
79
+ } else {
80
+ routes.push(...fileRoutes, ...dirRoutes);
81
+ }
82
+ return sortRoutes(routes);
83
+ }
84
+ function buildFileRoute(fileName, dir, rootDir, parentUrlPath, isLayout) {
85
+ const baseName = stripExtension(fileName);
86
+ const filePath = path.relative(rootDir, path.join(dir, fileName));
87
+ const isIndex = baseName === "index";
88
+ const isCatchAll = baseName.startsWith("[...");
89
+ const isDynamic = !isCatchAll && baseName.startsWith("[") && baseName.endsWith("]");
90
+ let urlSegment;
91
+ if (isLayout) {
92
+ urlSegment = "";
93
+ } else if (isIndex) {
94
+ urlSegment = "/";
95
+ } else if (isCatchAll) {
96
+ const paramName = baseName.slice(4, -1);
97
+ urlSegment = `*${paramName}`;
98
+ } else if (isDynamic) {
99
+ const paramName = baseName.slice(1, -1);
100
+ urlSegment = `:${paramName}`;
101
+ } else {
102
+ urlSegment = baseName;
103
+ }
104
+ const urlPath = isLayout ? parentUrlPath || "/" : isIndex ? parentUrlPath || "/" : joinUrlPath(parentUrlPath, urlSegment);
105
+ const absoluteFilePath = path.join(dir, fileName);
106
+ let hasRouteData = false;
107
+ try {
108
+ const content = fs.readFileSync(absoluteFilePath, "utf-8");
109
+ hasRouteData = /export\s+(const|function|async\s+function)\s+routeData\b/.test(content);
110
+ } catch {
111
+ }
112
+ return {
113
+ filePath: filePath.replace(/\\/g, "/"),
114
+ // normalize to forward slashes
115
+ urlSegment,
116
+ urlPath,
117
+ isLayout,
118
+ isIndex,
119
+ isDynamic,
120
+ isCatchAll,
121
+ isGroup: false,
122
+ children: [],
123
+ parentUrlPath,
124
+ hasRouteData,
125
+ rootDir,
126
+ dir
127
+ };
128
+ }
129
+ function hasValidExtension(fileName, extensions) {
130
+ return extensions.some((ext) => fileName.endsWith(ext));
131
+ }
132
+ function stripExtension(fileName) {
133
+ const lastDot = fileName.lastIndexOf(".");
134
+ return lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
135
+ }
136
+ function isRouteGroup(dirName) {
137
+ return dirName.startsWith("(") && dirName.endsWith(")");
138
+ }
139
+ function dirNameToSegment(dirName) {
140
+ if (dirName.startsWith("[...") && dirName.endsWith("]")) {
141
+ return "*" + dirName.slice(4, -1);
142
+ }
143
+ if (dirName.startsWith("[") && dirName.endsWith("]")) {
144
+ return ":" + dirName.slice(1, -1);
145
+ }
146
+ return dirName;
147
+ }
148
+ function joinUrlPath(parent, segment) {
149
+ const base = parent.endsWith("/") ? parent : parent + "/";
150
+ return base + segment;
151
+ }
152
+ function sortRoutes(routes) {
153
+ return routes.sort((a, b) => {
154
+ if (a.isLayout && !b.isLayout) return -1;
155
+ if (!a.isLayout && b.isLayout) return 1;
156
+ if (a.isIndex && !b.isIndex) return -1;
157
+ if (!a.isIndex && b.isIndex) return 1;
158
+ if (!a.isDynamic && !a.isCatchAll && (b.isDynamic || b.isCatchAll)) return -1;
159
+ if ((a.isDynamic || a.isCatchAll) && !b.isDynamic && !b.isCatchAll) return 1;
160
+ if (a.isDynamic && b.isCatchAll) return -1;
161
+ if (a.isCatchAll && b.isDynamic) return 1;
162
+ return a.urlSegment.localeCompare(b.urlSegment);
163
+ });
164
+ }
165
+
166
+ // src/lib/plugins/route-codegen.ts
167
+ function generateRouteModule(routes, routesDir) {
168
+ const lines = [];
169
+ lines.push(`// Auto-generated by fluixi route plugin`);
170
+ lines.push(`// Do not edit manually`);
171
+ lines.push(``);
172
+ lines.push(`import { lazy } from '@fluixi/core/router';`);
173
+ lines.push(``);
174
+ lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
175
+ lines.push(``);
176
+ return lines.join("\n");
177
+ }
178
+ function generateRouteArray(routes, routesDir, depth) {
179
+ if (routes.length === 0) return "[]";
180
+ const indent = " ".repeat(depth);
181
+ const items = routes.map((route) => generateRouteObject(route, routesDir, depth + 1));
182
+ return `[
183
+ ${items.join(",\n")}
184
+ ${indent}]`;
185
+ }
186
+ function generateRouteObject(route, routesDir, depth) {
187
+ const indent = " ".repeat(depth);
188
+ const props = [];
189
+ const importPath = buildImportPath(route.filePath, routesDir);
190
+ const routePath = computeRoutePath(route);
191
+ props.push(`${indent} path: ${JSON.stringify(routePath)}`);
192
+ props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
193
+ if (route.hasRouteData) {
194
+ props.push(
195
+ `${indent} data: (args, __owner, __isCancelled) => import(${JSON.stringify(
196
+ importPath
197
+ )}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`
198
+ );
199
+ }
200
+ if (route.children.length > 0) {
201
+ const childArray = generateRouteArray(route.children, routesDir, depth + 1);
202
+ props.push(`${indent} children: ${childArray}`);
203
+ }
204
+ return `${indent}{
205
+ ${props.join(",\n")}
206
+ ${indent}}`;
207
+ }
208
+ function computeRoutePath(route) {
209
+ return route.urlPath;
210
+ }
211
+ function buildImportPath(filePath, routesDir) {
212
+ const base = routesDir.replace(/\\/g, "/").replace(/\/$/, "");
213
+ return `${base}/${filePath}`;
214
+ }
215
+
216
+ // src/lib/plugins/fluixi-routes-plugin.ts
217
+ var VIRTUAL_MODULE_ID = "virtual:fluixi-routes";
218
+ var RESOLVED_VIRTUAL_ID = "\0" + VIRTUAL_MODULE_ID;
219
+ var PUBLIC_MODULE_ID = "@fluixi/core/routes";
220
+ function fluixiRoutesPlugin(options = {}) {
221
+ const routesDir = options.routesDir ?? "src/routes";
222
+ const extensions = options.extensions ?? [".tsx", ".ts", ".jsx", ".js"];
223
+ let projectRoot = "";
224
+ let lastGenerated = null;
225
+ function generateModule(root) {
226
+ const absRoutesDir = path2.resolve(root, routesDir);
227
+ const scanOpts = { extensions };
228
+ const routes = scanRoutes(absRoutesDir, scanOpts);
229
+ return generateRouteModule(routes, "./" + routesDir);
230
+ }
231
+ const usePolyfills = options.polyfills !== false;
232
+ const polyfillsPlugin = usePolyfills ? Object.assign({}, nodePolyfills({ include: ["fs", "path"] }), { apply: "serve" }) : null;
233
+ const routesPlugin = {
234
+ name: "fluixi-routes",
235
+ enforce: "pre",
236
+ configResolved(config) {
237
+ projectRoot = config.root || process.cwd();
238
+ },
239
+ resolveId(id) {
240
+ if (id === VIRTUAL_MODULE_ID || id === PUBLIC_MODULE_ID) {
241
+ return RESOLVED_VIRTUAL_ID;
242
+ }
243
+ return null;
244
+ },
245
+ load(id) {
246
+ if (id !== RESOLVED_VIRTUAL_ID) return null;
247
+ lastGenerated = generateModule(projectRoot || process.cwd());
248
+ return lastGenerated;
249
+ },
250
+ // Vite dev server: watch routes directory for changes
251
+ configureServer(server) {
252
+ const root = projectRoot || process.cwd();
253
+ const absRoutesDir = path2.resolve(root, routesDir);
254
+ server.watcher.add(absRoutesDir);
255
+ server.watcher.on("all", (event, filePath) => {
256
+ if (!filePath.startsWith(absRoutesDir)) return;
257
+ if (!["add", "unlink", "addDir", "unlinkDir", "change"].includes(event)) return;
258
+ if (event !== "addDir" && event !== "unlinkDir" && !extensions.some((ext) => filePath.endsWith(ext))) {
259
+ return;
260
+ }
261
+ const next = generateModule(root);
262
+ if (next === lastGenerated) return;
263
+ lastGenerated = next;
264
+ const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
265
+ if (mod) {
266
+ server.moduleGraph.invalidateModule(mod);
267
+ server.ws.send({ type: "full-reload" });
268
+ }
269
+ });
270
+ }
271
+ };
272
+ return polyfillsPlugin ? [polyfillsPlugin, routesPlugin] : [routesPlugin];
273
+ }
274
+ export {
275
+ createVitePlugin,
276
+ fluixi,
277
+ fluixiRoutesPlugin,
278
+ scanRoutes
279
+ };
@@ -1,8 +1,73 @@
1
- "use strict";var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var g=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},d=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!h.call(n,r)&&r!==t&&u(n,r,{get:()=>e[r],enumerable:!(i=l(e,r))||i.enumerable});return n};var f=n=>d(u({},"__esModule",{value:!0}),n);var S={};g(S,{generateRouteModule:()=>m});module.exports=f(S);function m(n,e){let t=[];return t.push("// Auto-generated by fluixi route plugin"),t.push("// Do not edit manually"),t.push(""),t.push("import { lazy } from '@fluixi/core/router';"),t.push(""),t.push(`export const routes = ${s(n,e,0)};`),t.push(""),t.join(`
2
- `)}function s(n,e,t){if(n.length===0)return"[]";let i=" ".repeat(t);return`[
3
- ${n.map(o=>$(o,e,t+1)).join(`,
4
- `)}
5
- ${i}]`}function $(n,e,t){let i=" ".repeat(t),r=[],o=y(n.filePath,e),a=R(n);if(r.push(`${i} path: ${JSON.stringify(a)}`),r.push(`${i} component: lazy(() => import(${JSON.stringify(o)}))`),n.hasRouteData&&r.push(`${i} data: (args, __owner, __isCancelled) => import(${JSON.stringify(o)}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`),n.children.length>0){let c=s(n.children,e,t+1);r.push(`${i} children: ${c}`)}return`${i}{
6
- ${r.join(`,
7
- `)}
8
- ${i}}`}function R(n){return n.urlPath}function y(n,e){return`${e.replace(/\\/g,"/").replace(/\/$/,"")}/${n}`}
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/plugins/route-codegen.ts
21
+ var route_codegen_exports = {};
22
+ __export(route_codegen_exports, {
23
+ generateRouteModule: () => generateRouteModule
24
+ });
25
+ module.exports = __toCommonJS(route_codegen_exports);
26
+ function generateRouteModule(routes, routesDir) {
27
+ const lines = [];
28
+ lines.push(`// Auto-generated by fluixi route plugin`);
29
+ lines.push(`// Do not edit manually`);
30
+ lines.push(``);
31
+ lines.push(`import { lazy } from '@fluixi/core/router';`);
32
+ lines.push(``);
33
+ lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
34
+ lines.push(``);
35
+ return lines.join("\n");
36
+ }
37
+ function generateRouteArray(routes, routesDir, depth) {
38
+ if (routes.length === 0) return "[]";
39
+ const indent = " ".repeat(depth);
40
+ const items = routes.map((route) => generateRouteObject(route, routesDir, depth + 1));
41
+ return `[
42
+ ${items.join(",\n")}
43
+ ${indent}]`;
44
+ }
45
+ function generateRouteObject(route, routesDir, depth) {
46
+ const indent = " ".repeat(depth);
47
+ const props = [];
48
+ const importPath = buildImportPath(route.filePath, routesDir);
49
+ const routePath = computeRoutePath(route);
50
+ props.push(`${indent} path: ${JSON.stringify(routePath)}`);
51
+ props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
52
+ if (route.hasRouteData) {
53
+ props.push(
54
+ `${indent} data: (args, __owner, __isCancelled) => import(${JSON.stringify(
55
+ importPath
56
+ )}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`
57
+ );
58
+ }
59
+ if (route.children.length > 0) {
60
+ const childArray = generateRouteArray(route.children, routesDir, depth + 1);
61
+ props.push(`${indent} children: ${childArray}`);
62
+ }
63
+ return `${indent}{
64
+ ${props.join(",\n")}
65
+ ${indent}}`;
66
+ }
67
+ function computeRoutePath(route) {
68
+ return route.urlPath;
69
+ }
70
+ function buildImportPath(filePath, routesDir) {
71
+ const base = routesDir.replace(/\\/g, "/").replace(/\/$/, "");
72
+ return `${base}/${filePath}`;
73
+ }
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @fileoverview Route code generator
3
2
  * @module @fluixi/core/plugins/route-codegen
4
3
  *
5
4
  * Generates an ES module from a ScannedRoute tree.
@@ -1 +1 @@
1
- {"version":3,"file":"route-codegen.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/route-codegen.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAevD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EAAE,EACtB,SAAS,EAAE,MAAM,GAChB,MAAM,CAeR"}
1
+ {"version":3,"file":"route-codegen.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/route-codegen.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAevD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EAAE,EACtB,SAAS,EAAE,MAAM,GAChB,MAAM,CAeR"}
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @fileoverview Route code generator
3
2
  * @module @fluixi/core/plugins/route-codegen
4
3
  *
5
4
  * Generates an ES module from a ScannedRoute tree.
@@ -27,7 +26,7 @@ export function generateRouteModule(routes, routesDir) {
27
26
  lines.push(``);
28
27
  // router is lit-free; the old './router' barrel imported @fluixi/lit (extends
29
28
  // HTMLElement at module init) which crashed SSR/prod server bundles. (runWithOwner was
30
- // imported here but never used in the generated output dropped.)
29
+ // imported here but never used in the generated output: dropped.)
31
30
  lines.push(`import { lazy } from '@fluixi/core/router';`);
32
31
  lines.push(``);
33
32
  lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
@@ -48,9 +47,9 @@ function generateRouteObject(route, routesDir, depth) {
48
47
  // Path
49
48
  const routePath = computeRoutePath(route);
50
49
  props.push(`${indent} path: ${JSON.stringify(routePath)}`);
51
- // Component lazy-loaded via dynamic import + Suspense
50
+ // Component: lazy-loaded via dynamic import + Suspense
52
51
  props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
53
- // Data loader only generated for routes that export `routeData`
52
+ // Data loader, only generated for routes that export `routeData`
54
53
  // This prevents unnecessary async imports and avoids calling d.data() for
55
54
  // levels that have no data, which kept the router's if (d.data) check clean.
56
55
  if (route.hasRouteData) {
@@ -67,7 +66,7 @@ function generateRouteObject(route, routesDir, depth) {
67
66
  /**
68
67
  * Compute the route path for a RouteDefinition.
69
68
  * The scanner already resolves groups, dynamic segments, and index paths
70
- * into the correct urlPath just use it directly.
69
+ * into the correct urlPath, just use it directly.
71
70
  */
72
71
  function computeRoutePath(route) {
73
72
  return route.urlPath;
@@ -1,8 +1,52 @@
1
- function h(t,e){let n=[];return n.push("// Auto-generated by fluixi route plugin"),n.push("// Do not edit manually"),n.push(""),n.push("import { lazy } from '@fluixi/core/router';"),n.push(""),n.push(`export const routes = ${u(t,e,0)};`),n.push(""),n.join(`
2
- `)}function u(t,e,n){if(t.length===0)return"[]";let r=" ".repeat(n);return`[
3
- ${t.map(o=>c(o,e,n+1)).join(`,
4
- `)}
5
- ${r}]`}function c(t,e,n){let r=" ".repeat(n),i=[],o=p(t.filePath,e),s=l(t);if(i.push(`${r} path: ${JSON.stringify(s)}`),i.push(`${r} component: lazy(() => import(${JSON.stringify(o)}))`),t.hasRouteData&&i.push(`${r} data: (args, __owner, __isCancelled) => import(${JSON.stringify(o)}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`),t.children.length>0){let a=u(t.children,e,n+1);i.push(`${r} children: ${a}`)}return`${r}{
6
- ${i.join(`,
7
- `)}
8
- ${r}}`}function l(t){return t.urlPath}function p(t,e){return`${e.replace(/\\/g,"/").replace(/\/$/,"")}/${t}`}export{h as generateRouteModule};
1
+ // src/lib/plugins/route-codegen.ts
2
+ function generateRouteModule(routes, routesDir) {
3
+ const lines = [];
4
+ lines.push(`// Auto-generated by fluixi route plugin`);
5
+ lines.push(`// Do not edit manually`);
6
+ lines.push(``);
7
+ lines.push(`import { lazy } from '@fluixi/core/router';`);
8
+ lines.push(``);
9
+ lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
10
+ lines.push(``);
11
+ return lines.join("\n");
12
+ }
13
+ function generateRouteArray(routes, routesDir, depth) {
14
+ if (routes.length === 0) return "[]";
15
+ const indent = " ".repeat(depth);
16
+ const items = routes.map((route) => generateRouteObject(route, routesDir, depth + 1));
17
+ return `[
18
+ ${items.join(",\n")}
19
+ ${indent}]`;
20
+ }
21
+ function generateRouteObject(route, routesDir, depth) {
22
+ const indent = " ".repeat(depth);
23
+ const props = [];
24
+ const importPath = buildImportPath(route.filePath, routesDir);
25
+ const routePath = computeRoutePath(route);
26
+ props.push(`${indent} path: ${JSON.stringify(routePath)}`);
27
+ props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
28
+ if (route.hasRouteData) {
29
+ props.push(
30
+ `${indent} data: (args, __owner, __isCancelled) => import(${JSON.stringify(
31
+ importPath
32
+ )}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`
33
+ );
34
+ }
35
+ if (route.children.length > 0) {
36
+ const childArray = generateRouteArray(route.children, routesDir, depth + 1);
37
+ props.push(`${indent} children: ${childArray}`);
38
+ }
39
+ return `${indent}{
40
+ ${props.join(",\n")}
41
+ ${indent}}`;
42
+ }
43
+ function computeRoutePath(route) {
44
+ return route.urlPath;
45
+ }
46
+ function buildImportPath(filePath, routesDir) {
47
+ const base = routesDir.replace(/\\/g, "/").replace(/\/$/, "");
48
+ return `${base}/${filePath}`;
49
+ }
50
+ export {
51
+ generateRouteModule
52
+ };