@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 +1,639 @@
1
- import{createSignal as b,createMemo as d,createResource as le,createEffect as A,getOwner as fe,onCleanup as w,untrack as P}from"@fluixi/reactive/signal";import{insert as T,createComponent as V,createNativeElement as g,setAttribute as u}from"@fluixi/dom";import{createContext as v,useContext as p}from"@fluixi/reactive/signal";import{get as pe}from"@fluixi/utils/object";import{deepEqual as ye}from"@fluixi/utils/compare";import{createRouter as me,createBrowserHistory as ge,matchRoutes as he,matchPath as xe}from"@fluixi/router";import{createMemoryHistory as ht,createBrowserHistory as xt,matchRoutes as Tt,matchPath as vt}from"@fluixi/router";import{createResource as G,createSignal as M}from"@fluixi/reactive/signal";var q=!1,C=new Map;function k(){return q}function O(e,r){C.set(e,r)}function L(e){return C.get(e)}function B(){C.clear()}function J(){if(typeof window>"u")return;let e=document.getElementById("__FLUIXI_HYDRATION__");e&&e.remove();let r=document.createTreeWalker(document.body,NodeFilter.SHOW_COMMENT,null),t=[],a;for(;a=r.nextNode();){let o=a,n=o.nodeValue||"";(n.startsWith("#")||n.startsWith("/"))&&t.push(o)}t.forEach(o=>o.remove()),B()}typeof window<"u"&&window.addEventListener("load",()=>{setTimeout(J,100)});function D(){return typeof window>"u"}import{asProvider as X}from"@fluixi/dom";import{createContext as Y,useContext as Oe}from"@fluixi/reactive/signal";import{readChildren as Me}from"@fluixi/reactive/signal";function N(e,r){let t=Y(e,r),a=o=>(o.debug,t.Provider({value:o.value,get children(){return o.children},debug:o.debug}));return typeof Symbol<"u"&&Symbol.for&&(a.$$typeof=Symbol.for("react.provider")),a.$$typeof=Symbol.for("react.provider"),{id:t.id,Provider:X(a),defaultValue:e}}var m=new Map,y=new Map;function Q(e,r){return async(...t)=>{let a=r+":"+JSON.stringify(t);if(k()||typeof window<"u"){let n=L(a);if(n!==void 0)return n}if(m.has(a))return m.get(a);if(y.has(a))return y.get(a);let o=Promise.resolve(e(...t)).then(n=>(m.set(a,n),y.delete(a),D()&&O(a,n),n),n=>{throw y.delete(a),n});return y.set(a,o),o}}var[Ie,Z]=M(0),ee=new Set;function te(e){let r=typeof e=="string"?t=>t.startsWith(e):e;for(let t of m.keys())r(t)&&(m.delete(t),ee.add(t));Z(t=>t+1)}function ne(e,r){let[t]=G(r||(()=>!0),e);return t}var R=new Map;function E(e){return R.has(e)||R.set(e,M(void 0)),R.get(e)}function H(e,r){let t=r||e.name||"action",a=async o=>{let[,n]=E(t),i=()=>n(void 0),s=()=>a(o);n({input:o,pending:!0,clear:i,retry:s});try{let c=await e(o);return n({input:o,result:c,pending:!1,clear:i,retry:s}),c}catch(c){throw n({input:o,error:c,pending:!1,clear:i,retry:s}),c}};return a.url=t,a.with=o=>H((...n)=>e(o,...n),r),a}function re(e){let[r]=E(e.url);return r}function oe(e){return e}var ae=N(void 0,"route-data"),Ke=ae.Provider;import{createComponent as ie}from"@fluixi/dom";import{untrack as se,createMemo as ce,createResource as ue}from"@fluixi/reactive/signal";function _(e){if(e!=null&&(typeof e=="object"||typeof e=="function"))try{e.$lazy=!0}catch{}return e}function de(e,r){let t,a,o;function n(){return a||(a=e().then(s=>t=s.default)),a}r?.preload&&n();let i=(s=>{if(t){let c=t;return _(se(()=>c(s)))}if(!o){let[c]=ue(()=>n(),{transport:!1});if(o=c,c.error)throw c.error}return ce(()=>{let c=o();return c?_(ie(c,s)):void 0})});return i.preload=()=>n().then(()=>{}),i.$lazy=!0,i.loader=e,i}import{runWithOwner as bt}from"@fluixi/reactive/signal";var h=v(void 0,"router"),F=v(void 0,"outlet"),j=v(void 0,"route-params"),I=v(void 0,"route-data");function Te(e,r,t){let a,o=e.route.data;if(typeof o=="function"){let x=!1;w(()=>{x=!0});let $=fe(),[W]=le(()=>o({params:t.params,location:t.location},$,()=>x));a=W}let n=()=>I.Provider({value:a,get children(){return j.Provider({value:e.params,get children(){return F.Provider({value:{depth:r,...t},get children(){return V(e.component,{})}})}})}});if(!a)return n();let i=a,s=()=>i.loading,[c,f]=b(P(()=>!s()));return A(()=>f(!s())),d(()=>c()?n():null)}function K(e){let r=e.depth+1,[t,a]=b(P(()=>e.matched()[r]?.component));return A(()=>{let o=e.matched()[r]?.component;a(()=>o)}),d(()=>{if(!t())return e.notFound?e.notFound():null;let n=P(()=>e.matched())[r];return Te(n,r,{matched:e.matched,params:e.params,location:e.location})})}function ve(e){return e==null?Ce():typeof e=="function"?V(e,{}):e}function Ce(){let e=g("div");u(e,"class","fx-not-found"),u(e,"role","main"),u(e,"style","min-height:60vh;display:grid;place-content:center;gap:.25rem;text-align:center;font-family:system-ui,-apple-system,sans-serif");let r=g("h1");u(r,"style","margin:0;font-size:2.5rem;font-weight:700"),T(r,"404");let t=g("p");return u(t,"style","margin:0;opacity:.7"),T(t,"This page could not be found."),e.appendChild(r),e.appendChild(t),e}function tt(e){let r=e.history??ge(),t=me({routes:e.routes,base:e.base,history:r}),[a,o]=b(t.state()),n=t.subscribe(o);w(()=>{n(),t.destroy()});let i=d(()=>(a().match?.matched??[]).filter(x=>x.component)),s={router:t,location:d(()=>a().location),params:d(()=>a().match?.params??{})},c={depth:-1,matched:i,params:s.params,location:s.location,notFound:()=>ve(e.notFound)},f;return h.Provider({value:s,get children(){return f??=K(c)}})}function nt(){let e=p(F);return e?K(e):null}function rt(e){let r=p(h);if(r&&typeof window<"u"){let t=!1;w(()=>t=!0),queueMicrotask(()=>{t||r.router.navigate(e.to,{replace:e.replace!==!1})})}return null}var Re={router:{navigate:()=>{}},location:()=>({pathname:"",search:"",hash:"",query:{}}),params:()=>({})};function S(){let e=p(h);if(e)return e;if(typeof window>"u")return Re;throw new Error("[router] useRouter must be used within <Router>")}function z(){let e=S().params;return d(()=>e(),{},{equals:(r,t)=>JSON.stringify(r)===JSON.stringify(t)})}function ot(){return p(j)??{}}function at(e){let r=z();return d(()=>r()[e])}function it(e,r){let t=z();return d(()=>e(t()),void 0,r?{equals:r}:void 0)}function st(e){let r=U();return d(()=>xe(typeof e=="function"?e():e,r.pathname))}function ct(){let e=U(),r=Pe();return[d(()=>e.query),(o,n)=>{let i=new URLSearchParams(e.search);for(let[c,f]of Object.entries(o))f===null?i.delete(c):i.set(c,f);let s=i.toString();r(e.pathname+(s?`?${s}`:""),n)}]}function ut(e,r){let t=(a,o)=>ye(a,o);return r!==void 0?d(()=>pe(e(),r),void 0,{equals:t}):d(e,void 0,{equals:t})}function U(){let{location:e}=S();return new Proxy({},{get:(r,t)=>e()[t],has:(r,t)=>t in e(),ownKeys:()=>Reflect.ownKeys(e()),getOwnPropertyDescriptor:(r,t)=>Object.getOwnPropertyDescriptor(e(),t)})}function dt(e={}){let r=p(h);return t=>{if(!r||t.defaultPrevented||t.button!==0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return;let o=t.target?.closest?.("a");if(!o||!o.getAttribute("href")||o.target&&o.target!=="_self"||o.hasAttribute("download")||/(^|\s)external(\s|$)/.test(o.getAttribute("rel")??""))return;let n=new URL(o.href);n.protocol!=="http:"&&n.protocol!=="https:"||n.origin===window.location.origin&&(n.hash&&n.pathname===window.location.pathname&&n.search===window.location.search||e.shouldNavigate&&!e.shouldNavigate(n,o)||(t.preventDefault(),r.router.navigate(n.pathname+n.search+n.hash,{replace:e.replace})))}}function Pe(){let{router:e}=S();return(r,t)=>e.navigate(r,t)}function lt(){return p(I)??(()=>{})}var l=e=>typeof e=="function"?e():e,be=new Set(["href","slot","class","className","active","activeClass","replace","children"]);function Ae(e){let r=p(h),t=()=>r?.router.navigate(l(e.href)??"",{replace:l(e.replace)}),a=g("a");u(a,"href",l(e.href)??""),e.slot&&u(a,"slot",l(e.slot));for(let n of Object.keys(e)){if(be.has(n))continue;let i=e[n];i!=null&&typeof i!="function"&&u(a,n,String(i))}if(typeof a.addEventListener=="function")a.addEventListener("click",n=>{n.metaKey||n.ctrlKey||n.shiftKey||n.altKey||(n.preventDefault(),t())});else{let n=l(e.className??e.class)??"";n&&u(a,"class",n)}typeof a.addEventListener=="function"&&A(()=>{let n=l(e.href)??"";a.setAttribute("href",n);let i=l(e.className??e.class)??"",s=l(e.activeClass)??"",c=l(e.active)??r?.location().pathname===n;a.className=[i,c?s:""].filter(Boolean).join(" ")});let o=e.children;return o!=null&&T(a,o),a}var ft=Ae;function pt(e){let r=e.action,t=e.className??e.class,a=r.url??"",o=g("form");u(o,"method","post"),a&&u(o,"action",a),t&&u(o,"class",t);for(let i of Object.keys(e)){if(i==="action"||i==="children"||i==="class"||i==="className")continue;let s=e[i];s!=null&&typeof s!="function"&&u(o,i,String(s))}typeof o.addEventListener=="function"&&o.addEventListener("submit",i=>{i.preventDefault();let s={};new FormData(o).forEach((c,f)=>{s[f]=c}),Promise.resolve(r(s)).catch(()=>{})});let n=e.children;return n!=null&&T(o,n),o}async function yt(e,r){let t=he(e,r);if(!t)return;let a=[];for(let o of t.matched){let n=o.component;n&&typeof n.preload=="function"&&a.push(n.preload())}await Promise.all(a)}export{ft as A,pt as Form,Ae as Link,nt as Outlet,rt as Redirect,tt as Router,H as action,Q as cache,ne as createAsync,xt as createBrowserHistory,ht as createMemoryHistory,de as lazy,vt as matchPath,Tt as matchRoutes,yt as preloadRoutes,te as revalidate,bt as runWithOwner,ut as select,oe as useAction,ot as useLevelParams,dt as useLinkNavigation,U as useLocation,st as useMatch,Pe as useNavigate,at as useParam,it as useParamSelector,z as useParams,lt as useRouteData,S as useRouter,ct as useSearchParams,re as useSubmission};
1
+ /*! @fluixi/core v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
+
3
+ // src/lib/router/index.ts
4
+ import {
5
+ createSignal as createSignal2,
6
+ createMemo as createMemo2,
7
+ createResource as createResource3,
8
+ createEffect,
9
+ getOwner,
10
+ onCleanup,
11
+ untrack as untrack2
12
+ } from "@fluixi/reactive/signal";
13
+ import {
14
+ insert,
15
+ createComponent as createComponent2,
16
+ createNativeElement,
17
+ setAttribute
18
+ } from "@fluixi/dom";
19
+ import { createContext as createContext2, useContext as useContext2 } from "@fluixi/reactive/signal";
20
+ import { get } from "@fluixi/utils/object";
21
+ import { deepEqual } from "@fluixi/utils/compare";
22
+ import {
23
+ createRouter as createCoreRouter,
24
+ createBrowserHistory,
25
+ matchRoutes,
26
+ matchPath
27
+ } from "@fluixi/router";
28
+ import {
29
+ createMemoryHistory,
30
+ createBrowserHistory as createBrowserHistory2,
31
+ matchRoutes as matchRoutes2,
32
+ matchPath as matchPath2
33
+ } from "@fluixi/router";
34
+
35
+ // src/lib/router/data.ts
36
+ import {
37
+ createResource,
38
+ createSignal
39
+ } from "@fluixi/reactive/signal";
40
+
41
+ // src/lib/server/hydration.ts
42
+ import { isServer as domIsServer } from "@fluixi/dom";
43
+ var hydrating = false;
44
+ var hydrationDataMap = /* @__PURE__ */ new Map();
45
+ function isHydrating() {
46
+ return hydrating;
47
+ }
48
+ function setHydrationData(key, data) {
49
+ hydrationDataMap.set(key, data);
50
+ }
51
+ function getHydrationData(key) {
52
+ return hydrationDataMap.get(key);
53
+ }
54
+ function clearHydrationData() {
55
+ hydrationDataMap.clear();
56
+ }
57
+ function cleanupHydration() {
58
+ if (typeof window === "undefined") {
59
+ return;
60
+ }
61
+ const script = document.getElementById("__FLUIXI_HYDRATION__");
62
+ if (script) {
63
+ script.remove();
64
+ }
65
+ const walker = document.createTreeWalker(
66
+ document.body,
67
+ NodeFilter.SHOW_COMMENT,
68
+ null
69
+ );
70
+ const comments = [];
71
+ let node;
72
+ while (node = walker.nextNode()) {
73
+ const comment = node;
74
+ const text = comment.nodeValue || "";
75
+ if (text.startsWith("#") || text.startsWith("/")) {
76
+ comments.push(comment);
77
+ }
78
+ }
79
+ comments.forEach((comment) => comment.remove());
80
+ clearHydrationData();
81
+ }
82
+ if (typeof window !== "undefined") {
83
+ window.addEventListener("load", () => {
84
+ setTimeout(cleanupHydration, 100);
85
+ });
86
+ }
87
+ function isServerEnvironment() {
88
+ return domIsServer();
89
+ }
90
+
91
+ // src/lib/context/context.ts
92
+ import { asProvider } from "@fluixi/dom";
93
+ import { createContext as createReactiveContext, useContext as useReactiveContext } from "@fluixi/reactive/signal";
94
+ import {
95
+ readChildren
96
+ } from "@fluixi/reactive/signal";
97
+ function createContext(defaultValue, name) {
98
+ const context = createReactiveContext(defaultValue, name);
99
+ const Provider = (props) => {
100
+ if (props.debug === true) {
101
+ }
102
+ return context.Provider({
103
+ value: props.value,
104
+ get children() {
105
+ return props.children;
106
+ },
107
+ debug: props.debug
108
+ });
109
+ };
110
+ if (typeof Symbol !== "undefined" && Symbol.for) {
111
+ Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
112
+ }
113
+ Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
114
+ return {
115
+ id: context.id,
116
+ Provider: asProvider(Provider),
117
+ defaultValue
118
+ };
119
+ }
120
+
121
+ // src/lib/router/data.ts
122
+ var globalCache = /* @__PURE__ */ new Map();
123
+ var inflightRequests = /* @__PURE__ */ new Map();
124
+ function cache(fn, name) {
125
+ return async (...args) => {
126
+ const key = name + ":" + JSON.stringify(args);
127
+ if (isHydrating() || typeof window !== "undefined") {
128
+ const hydrated = getHydrationData(key);
129
+ if (hydrated !== void 0) {
130
+ return hydrated;
131
+ }
132
+ }
133
+ if (globalCache.has(key)) {
134
+ return globalCache.get(key);
135
+ }
136
+ if (inflightRequests.has(key)) {
137
+ return inflightRequests.get(key);
138
+ }
139
+ const promise = Promise.resolve(fn(...args)).then(
140
+ (val) => {
141
+ globalCache.set(key, val);
142
+ inflightRequests.delete(key);
143
+ if (isServerEnvironment()) {
144
+ setHydrationData(key, val);
145
+ }
146
+ return val;
147
+ },
148
+ (err) => {
149
+ inflightRequests.delete(key);
150
+ throw err;
151
+ }
152
+ );
153
+ inflightRequests.set(key, promise);
154
+ return promise;
155
+ };
156
+ }
157
+ var [revalidationVersion, setRevalidationVersion] = createSignal(0);
158
+ var revalidationKeys = /* @__PURE__ */ new Set();
159
+ function revalidate(key) {
160
+ const predicate = typeof key === "string" ? (k) => k.startsWith(key) : key;
161
+ for (const k of globalCache.keys()) {
162
+ if (predicate(k)) {
163
+ globalCache.delete(k);
164
+ revalidationKeys.add(k);
165
+ }
166
+ }
167
+ setRevalidationVersion((v) => v + 1);
168
+ }
169
+ function createAsync(fetcher, source) {
170
+ const [data] = createResource(source || (() => true), fetcher);
171
+ return data;
172
+ }
173
+ var submissionState = /* @__PURE__ */ new Map();
174
+ function getSubmissionSignal(url) {
175
+ if (!submissionState.has(url)) {
176
+ submissionState.set(
177
+ url,
178
+ createSignal(void 0)
179
+ );
180
+ }
181
+ return submissionState.get(url);
182
+ }
183
+ function action(fn, name) {
184
+ const actionUrl = name || fn.name || "action";
185
+ const submit = async (input) => {
186
+ const [, setSubmission] = getSubmissionSignal(actionUrl);
187
+ const clear = () => setSubmission(void 0);
188
+ const retry = () => submit(input);
189
+ setSubmission({
190
+ input,
191
+ // Approximate type for tracking
192
+ pending: true,
193
+ clear,
194
+ retry
195
+ });
196
+ try {
197
+ const result = await fn(input);
198
+ setSubmission({
199
+ input,
200
+ result,
201
+ pending: false,
202
+ clear,
203
+ retry
204
+ });
205
+ return result;
206
+ } catch (error) {
207
+ setSubmission({
208
+ input,
209
+ error,
210
+ pending: false,
211
+ clear,
212
+ retry
213
+ });
214
+ throw error;
215
+ }
216
+ };
217
+ submit.url = actionUrl;
218
+ submit.with = (args) => action((...a) => fn(args, ...a), name);
219
+ return submit;
220
+ }
221
+ function useSubmission(actionFn) {
222
+ const [submission] = getSubmissionSignal(actionFn.url);
223
+ return submission;
224
+ }
225
+ function useAction(actionFn) {
226
+ return actionFn;
227
+ }
228
+ var RouteDataContext = createContext(void 0, "route-data");
229
+ var RouteDataProvider = RouteDataContext.Provider;
230
+
231
+ // src/lib/render/lazy.ts
232
+ import { createComponent } from "@fluixi/dom";
233
+ import {
234
+ untrack,
235
+ createMemo,
236
+ createResource as createResource2
237
+ } from "@fluixi/reactive/signal";
238
+ function fromChunk(value) {
239
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
240
+ try {
241
+ value["$lazy"] = true;
242
+ } catch {
243
+ }
244
+ }
245
+ return value;
246
+ }
247
+ function lazy(loader, options) {
248
+ let resolved;
249
+ let promise;
250
+ let component;
251
+ function load() {
252
+ if (!promise) {
253
+ promise = loader().then((mod) => resolved = mod.default);
254
+ }
255
+ return promise;
256
+ }
257
+ if (options?.preload) load();
258
+ const LazyWrapper = ((props) => {
259
+ if (resolved) {
260
+ const C = resolved;
261
+ return fromChunk(untrack(() => C(props)));
262
+ }
263
+ if (!component) {
264
+ const [resource] = createResource2(() => load(), { transport: false });
265
+ component = resource;
266
+ if (resource.error) throw resource.error;
267
+ }
268
+ return createMemo(() => {
269
+ const C = component();
270
+ return C ? fromChunk(createComponent(C, props)) : void 0;
271
+ });
272
+ });
273
+ LazyWrapper.preload = () => load().then(() => void 0);
274
+ LazyWrapper.$lazy = true;
275
+ LazyWrapper.loader = loader;
276
+ return LazyWrapper;
277
+ }
278
+
279
+ // src/lib/router/index.ts
280
+ import { runWithOwner } from "@fluixi/reactive/signal";
281
+ var RouterContext = createContext2(void 0, "router");
282
+ var OutletContext = createContext2(void 0, "outlet");
283
+ var LevelParamsContext = createContext2(void 0, "route-params");
284
+ var RouteDataContext2 = createContext2(void 0, "route-data");
285
+ function renderLayer(m, depth, base) {
286
+ let data;
287
+ const loader = m.route.data;
288
+ if (typeof loader === "function") {
289
+ let cancelled = false;
290
+ onCleanup(() => {
291
+ cancelled = true;
292
+ });
293
+ const owner = getOwner();
294
+ const [resource] = createResource3(
295
+ () => loader({ params: base.params, location: base.location }, owner, () => cancelled)
296
+ );
297
+ data = resource;
298
+ }
299
+ const buildPage = () => RouteDataContext2.Provider({
300
+ value: data,
301
+ get children() {
302
+ return LevelParamsContext.Provider({
303
+ value: m.params,
304
+ get children() {
305
+ return OutletContext.Provider({
306
+ value: { depth, ...base },
307
+ get children() {
308
+ return createComponent2(m.component, {});
309
+ }
310
+ });
311
+ }
312
+ });
313
+ }
314
+ });
315
+ if (!data) return buildPage();
316
+ const res = data;
317
+ const isLoading = () => res.loading;
318
+ const [ready, setReady] = createSignal2(untrack2(() => !isLoading()));
319
+ createEffect(() => setReady(!isLoading()));
320
+ return createMemo2(() => ready() ? buildPage() : null);
321
+ }
322
+ function renderChild(ctx) {
323
+ const childIdx = ctx.depth + 1;
324
+ const [childComp, setChildComp] = createSignal2(
325
+ untrack2(() => ctx.matched()[childIdx]?.component)
326
+ );
327
+ createEffect(() => {
328
+ const c = ctx.matched()[childIdx]?.component;
329
+ setChildComp(() => c);
330
+ });
331
+ return createMemo2(() => {
332
+ const component = childComp();
333
+ if (!component) {
334
+ return ctx.notFound ? ctx.notFound() : null;
335
+ }
336
+ const m = untrack2(() => ctx.matched())[childIdx];
337
+ return renderLayer(m, childIdx, {
338
+ matched: ctx.matched,
339
+ params: ctx.params,
340
+ location: ctx.location
341
+ });
342
+ });
343
+ }
344
+ function renderNotFound(notFound) {
345
+ if (notFound == null) return buildDefaultNotFound();
346
+ return typeof notFound === "function" ? createComponent2(notFound, {}) : notFound;
347
+ }
348
+ function buildDefaultNotFound() {
349
+ const el = createNativeElement("div");
350
+ setAttribute(el, "class", "fx-not-found");
351
+ setAttribute(el, "role", "main");
352
+ setAttribute(
353
+ el,
354
+ "style",
355
+ "min-height:60vh;display:grid;place-content:center;gap:.25rem;text-align:center;font-family:system-ui,-apple-system,sans-serif"
356
+ );
357
+ const h1 = createNativeElement("h1");
358
+ setAttribute(h1, "style", "margin:0;font-size:2.5rem;font-weight:700");
359
+ insert(h1, "404");
360
+ const p = createNativeElement("p");
361
+ setAttribute(p, "style", "margin:0;opacity:.7");
362
+ insert(p, "This page could not be found.");
363
+ el.appendChild(h1);
364
+ el.appendChild(p);
365
+ return el;
366
+ }
367
+ function Router(props) {
368
+ const history = props.history ?? createBrowserHistory();
369
+ const router = createCoreRouter({
370
+ routes: props.routes,
371
+ base: props.base,
372
+ history
373
+ });
374
+ const [state, setState] = createSignal2(router.state());
375
+ const unsub = router.subscribe(setState);
376
+ onCleanup(() => {
377
+ unsub();
378
+ router.destroy();
379
+ });
380
+ const matched = createMemo2(
381
+ () => (state().match?.matched ?? []).filter((m) => m.component)
382
+ );
383
+ const ctx = {
384
+ router,
385
+ location: createMemo2(() => state().location),
386
+ params: createMemo2(() => state().match?.params ?? {})
387
+ };
388
+ const root = {
389
+ depth: -1,
390
+ matched,
391
+ params: ctx.params,
392
+ location: ctx.location,
393
+ // Only the root carries this: renderChild shows it when the URL matched nothing.
394
+ notFound: () => renderNotFound(props.notFound)
395
+ };
396
+ let rootView;
397
+ return RouterContext.Provider({
398
+ value: ctx,
399
+ get children() {
400
+ return rootView ??= renderChild(root);
401
+ }
402
+ });
403
+ }
404
+ function Outlet() {
405
+ const ctx = useContext2(OutletContext);
406
+ if (!ctx) return null;
407
+ return renderChild(ctx);
408
+ }
409
+ function Redirect(props) {
410
+ const ctx = useContext2(RouterContext);
411
+ if (ctx && typeof window !== "undefined") {
412
+ let cancelled = false;
413
+ onCleanup(() => cancelled = true);
414
+ queueMicrotask(() => {
415
+ if (!cancelled) ctx.router.navigate(props.to, { replace: props.replace !== false });
416
+ });
417
+ }
418
+ return null;
419
+ }
420
+ var _ssrRouterStub = {
421
+ router: { navigate: () => {
422
+ } },
423
+ location: () => ({ pathname: "", search: "", hash: "", query: {} }),
424
+ params: () => ({})
425
+ };
426
+ function useRouter() {
427
+ const ctx = useContext2(RouterContext);
428
+ if (ctx) return ctx;
429
+ if (typeof window === "undefined") return _ssrRouterStub;
430
+ throw new Error("[router] useRouter must be used within <Router>");
431
+ }
432
+ function useParams() {
433
+ const params = useRouter().params;
434
+ return createMemo2(() => params(), {}, {
435
+ equals: (a, b) => JSON.stringify(a) === JSON.stringify(b)
436
+ });
437
+ }
438
+ function useLevelParams() {
439
+ return useContext2(LevelParamsContext) ?? {};
440
+ }
441
+ function useParam(key) {
442
+ const params = useParams();
443
+ return createMemo2(() => params()[key]);
444
+ }
445
+ function useParamSelector(selector, equals) {
446
+ const params = useParams();
447
+ return createMemo2(
448
+ () => selector(params()),
449
+ void 0,
450
+ equals ? { equals } : void 0
451
+ );
452
+ }
453
+ function useMatch(path) {
454
+ const location = useLocation();
455
+ return createMemo2(
456
+ () => matchPath(typeof path === "function" ? path() : path, location.pathname)
457
+ );
458
+ }
459
+ function useSearchParams() {
460
+ const location = useLocation();
461
+ const navigate = useNavigate();
462
+ const params = createMemo2(() => location.query);
463
+ const setParams = (next, options) => {
464
+ const current = new URLSearchParams(location.search);
465
+ for (const [k, v] of Object.entries(next)) {
466
+ if (v === null) current.delete(k);
467
+ else current.set(k, v);
468
+ }
469
+ const search = current.toString();
470
+ navigate(location.pathname + (search ? `?${search}` : ""), options);
471
+ };
472
+ return [params, setParams];
473
+ }
474
+ function select(source, key) {
475
+ const equals = (a, b) => deepEqual(a, b);
476
+ if (key !== void 0) {
477
+ return createMemo2(
478
+ () => get(source(), key),
479
+ void 0,
480
+ { equals }
481
+ );
482
+ }
483
+ return createMemo2(source, void 0, { equals });
484
+ }
485
+ function useLocation() {
486
+ const { location } = useRouter();
487
+ return new Proxy({}, {
488
+ get: (_t, key) => location()[key],
489
+ has: (_t, key) => key in location(),
490
+ ownKeys: () => Reflect.ownKeys(location()),
491
+ getOwnPropertyDescriptor: (_t, key) => Object.getOwnPropertyDescriptor(location(), key)
492
+ });
493
+ }
494
+ function useLinkNavigation(options = {}) {
495
+ const ctx = useContext2(RouterContext);
496
+ return (event) => {
497
+ if (!ctx || event.defaultPrevented || event.button !== 0) return;
498
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
499
+ const target = event.target;
500
+ const anchor = target?.closest?.("a");
501
+ if (!anchor || !anchor.getAttribute("href")) return;
502
+ if (anchor.target && anchor.target !== "_self") return;
503
+ if (anchor.hasAttribute("download")) return;
504
+ if (/(^|\s)external(\s|$)/.test(anchor.getAttribute("rel") ?? "")) return;
505
+ const url = new URL(anchor.href);
506
+ if (url.protocol !== "http:" && url.protocol !== "https:") return;
507
+ if (url.origin !== window.location.origin) return;
508
+ if (url.hash && url.pathname === window.location.pathname && url.search === window.location.search) return;
509
+ if (options.shouldNavigate && !options.shouldNavigate(url, anchor)) return;
510
+ event.preventDefault();
511
+ ctx.router.navigate(url.pathname + url.search + url.hash, { replace: options.replace });
512
+ };
513
+ }
514
+ function useNavigate() {
515
+ const { router } = useRouter();
516
+ return (to, options) => router.navigate(to, options);
517
+ }
518
+ function useRouteData() {
519
+ const acc = useContext2(RouteDataContext2);
520
+ return acc ?? (() => void 0);
521
+ }
522
+ var read = (v) => typeof v === "function" ? v() : v;
523
+ var LINK_OWN_PROPS = /* @__PURE__ */ new Set([
524
+ "href",
525
+ "slot",
526
+ "class",
527
+ "className",
528
+ "active",
529
+ "activeClass",
530
+ "replace",
531
+ "children"
532
+ ]);
533
+ function Link(props) {
534
+ const ctx = useContext2(RouterContext);
535
+ const navigate = () => ctx?.router.navigate(read(props.href) ?? "", { replace: read(props.replace) });
536
+ const a = createNativeElement("a");
537
+ setAttribute(a, "href", read(props.href) ?? "");
538
+ if (props.slot) setAttribute(a, "slot", read(props.slot));
539
+ for (const k of Object.keys(props)) {
540
+ if (LINK_OWN_PROPS.has(k)) continue;
541
+ const v = props[k];
542
+ if (v != null && typeof v !== "function") setAttribute(a, k, String(v));
543
+ }
544
+ if (typeof a.addEventListener === "function") {
545
+ a.addEventListener("click", (e) => {
546
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
547
+ e.preventDefault();
548
+ navigate();
549
+ });
550
+ } else {
551
+ const base = read(props.className ?? props.class) ?? "";
552
+ if (base) setAttribute(a, "class", base);
553
+ }
554
+ if (typeof a.addEventListener === "function") {
555
+ createEffect(() => {
556
+ const href = read(props.href) ?? "";
557
+ a.setAttribute("href", href);
558
+ const base = read(props.className ?? props.class) ?? "";
559
+ const activeClass = read(props.activeClass) ?? "";
560
+ const active = read(props.active) ?? ctx?.location().pathname === href;
561
+ a.className = [base, active ? activeClass : ""].filter(Boolean).join(" ");
562
+ });
563
+ }
564
+ const linkChildren = props.children;
565
+ if (linkChildren != null) insert(a, linkChildren);
566
+ return a;
567
+ }
568
+ var A = Link;
569
+ function Form(props) {
570
+ const action2 = props.action;
571
+ const cls = props.className ?? props.class;
572
+ const url = action2.url ?? "";
573
+ const form = createNativeElement("form");
574
+ setAttribute(form, "method", "post");
575
+ if (url) setAttribute(form, "action", url);
576
+ if (cls) setAttribute(form, "class", cls);
577
+ for (const k of Object.keys(props)) {
578
+ if (k === "action" || k === "children" || k === "class" || k === "className") continue;
579
+ const v = props[k];
580
+ if (v != null && typeof v !== "function") setAttribute(form, k, String(v));
581
+ }
582
+ if (typeof form.addEventListener === "function") {
583
+ form.addEventListener("submit", (e) => {
584
+ e.preventDefault();
585
+ const data = {};
586
+ new FormData(form).forEach((v, k) => {
587
+ data[k] = v;
588
+ });
589
+ Promise.resolve(action2(data)).catch(() => {
590
+ });
591
+ });
592
+ }
593
+ const children = props.children;
594
+ if (children != null) insert(form, children);
595
+ return form;
596
+ }
597
+ async function preloadRoutes(routes, pathname) {
598
+ const match = matchRoutes(routes, pathname);
599
+ if (!match) return;
600
+ const loads = [];
601
+ for (const m of match.matched) {
602
+ const c = m.component;
603
+ if (c && typeof c.preload === "function") loads.push(c.preload());
604
+ }
605
+ await Promise.all(loads);
606
+ }
607
+ export {
608
+ A,
609
+ Form,
610
+ Link,
611
+ Outlet,
612
+ Redirect,
613
+ Router,
614
+ action,
615
+ cache,
616
+ createAsync,
617
+ createBrowserHistory2 as createBrowserHistory,
618
+ createMemoryHistory,
619
+ lazy,
620
+ matchPath2 as matchPath,
621
+ matchRoutes2 as matchRoutes,
622
+ preloadRoutes,
623
+ revalidate,
624
+ runWithOwner,
625
+ select,
626
+ useAction,
627
+ useLevelParams,
628
+ useLinkNavigation,
629
+ useLocation,
630
+ useMatch,
631
+ useNavigate,
632
+ useParam,
633
+ useParamSelector,
634
+ useParams,
635
+ useRouteData,
636
+ useRouter,
637
+ useSearchParams,
638
+ useSubmission
639
+ };