@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,5 +1,4 @@
1
1
  /**
2
- * @fileoverview Client-Side Rendering for Fluixi
3
2
  * @module @fluixi/core/render
4
3
  *
5
4
  * Client-side rendering:
@@ -13,22 +12,17 @@ import { createRoot } from '@fluixi/reactive/signal';
13
12
  import { stampVersions, warnOnVersionSkew } from './versions.js';
14
13
  import { isDOMNode, delegateEvents, insert, } from '@fluixi/dom';
15
14
  // ============================================================================
16
- // SECTION 7 — RENDERING (CLIENT)
15
+ // RENDERING (CLIENT)
17
16
  // ============================================================================
18
17
  /**
19
18
  * Render a component into a DOM element
20
19
  *
21
- * Section 7 — CLIENT:
20
+ * On the client:
22
21
  * - Real DOM (no Virtual DOM)
23
22
  * - Fine-grained mutation (no reconciliation)
24
23
  *
25
- * Section 1: Component executes once during render
26
- * Section 5: Creates reactive owner (root)
27
- *
28
- * @param {() => any} code - Component or function to render
29
- * @param {HTMLElement} container - Target DOM element
30
- * @param {RenderOptions} options - Render options
31
- * @returns {() => void} Dispose function
24
+ * Component executes once during render
25
+ * Creates reactive owner (root)
32
26
  *
33
27
  * @example
34
28
  * ```typescript
@@ -55,11 +49,11 @@ export function render(code, container, options = {}) {
55
49
  // domRender(code, container)
56
50
  createRoot((dispose) => {
57
51
  disposer = dispose;
58
- // Section 1: Execute code function once Providers run here with Owner = root
52
+ // Execute code function once. Providers run here with Owner = root
59
53
  // so "also stamp" in createProvider sets context on root.contexts, making
60
54
  // it reachable from every render effect created by insert() below.
61
55
  const result = typeof code === 'function' ? code() : code;
62
- // Section 7: Insert into real DOM using the SAME root as code() so that
56
+ // Insert into real DOM using the same root as code() so that
63
57
  // render effects share the Owner chain with Provider context nodes.
64
58
  // Using domRender() would create a second createRoot, severing the chain.
65
59
  container.textContent = '';
@@ -68,8 +62,8 @@ export function render(code, container, options = {}) {
68
62
  stampVersions(container);
69
63
  warnOnVersionSkew();
70
64
  // Wrap the (already-computed) result in a STABLE thunk so insert() creates a
71
- // top-level render effect. Without this, a static array result e.g. the
72
- // imperative backend's `[createMemo(() => createComponent(App)), " "]` is
65
+ // top-level render effect. Without this, a static array result: e.g. the
66
+ // imperative backend's `[createMemo(() => createComponent(App)), " "]`: is
73
67
  // flattened ONCE with no enclosing effect, so the nested memos are read
74
68
  // untracked and reactive boundaries deep in the tree (Suspense fallback ->
75
69
  // content, Outlet, Show/For) never update. The thunk returns the same result
@@ -99,11 +93,6 @@ function isLitTemplateResult(value) {
99
93
  /**
100
94
  * Render into a different part of the DOM tree
101
95
  *
102
- * @param {() => any} code - Component to render
103
- * @param {HTMLElement} target - Target element (outside current tree)
104
- * @param {RenderOptions} options - Render options
105
- * @returns {() => void} Dispose function
106
- *
107
96
  * @example
108
97
  * ```typescript
109
98
  * import { portal } from '@fluixi/core';
@@ -133,9 +122,6 @@ export function portal(code, target, options = {}) {
133
122
  // ============================================================================
134
123
  /**
135
124
  * Check if a value can be rendered
136
- *
137
- * @param {any} value - Value to check
138
- * @returns {boolean} True if renderable
139
125
  */
140
126
  export function isRenderable(value) {
141
127
  if (value == null)
@@ -1 +1,590 @@
1
- import{isServer as w}from"@fluixi/dom";import{createRoot as Fe}from"@fluixi/reactive/signal";import{registerCoreVersion as U}from"@fluixi/dom";var S="1.0.0-alpha.83";import{stampVersions as k,warnOnVersionSkew as g,versions as He}from"@fluixi/dom";U(S);import{isDOMNode as $e,delegateEvents as _,insert as ze}from"@fluixi/dom";import{isServer as T}from"@fluixi/dom";import{createComponent as V,asComponent as W}from"@fluixi/dom";import{untrack as L,onCleanup as u,getOwner as b,createEffect as l,createMemo as E,createSignal as q,isSignal as H,batch as B,runWithOwner as O,isOwnerDisposed as K}from"@fluixi/reactive/signal";var J={context:null,owner:null};function X(){return J}var h=typeof process<"u"&&!1,y=Symbol.for("fluixi-lifecycle");function R(){let e=b();if(!e)return null;if(!e[y]){let t={mounts:[],effects:[],scheduled:!1};e[y]=t}return e[y]}function P(e){if(e.scheduled)return;if(T()){e.mounts=[],e.effects=[];return}e.scheduled=!0;let t=b();queueMicrotask(()=>{if(K(t)){e.mounts=[],e.effects=[];return}O(t,()=>{for(let o of e.mounts)try{let n=o();typeof n=="function"&&u(n)}catch(n){console.error("Error in onMount callback:",n)}for(let o of e.effects){let n;l(()=>{n&&n(),n=o()}),u(()=>{n&&n()})}e.mounts=[],e.effects=[]})})}function Q(e,t){return V(e,t)}function Y(e,t){let o=typeof e=="function"?L(()=>e(t)):e,n=o!=null&&(typeof o=="function"||typeof o=="object");if(n)try{o.$name=e.name}catch{}return n&&!H(o)?W(o):o}function G(e,t=!0){if(T())return;let o=R();if(o){if(!t){o.scheduled||e();return}o.mounts.push(e),P(o)}else{if(!t){e();return}l(()=>{let n=L(e);typeof n=="function"&&u(n)})}}function Z(e){u(e)}function A(e){let t=R();if(t)t.effects.push(e),P(t);else{let o;l(()=>{o&&o(),o=e()}),u(()=>{o&&o()})}}function ee(e){return E(e)}function ne(e){let t={current:e};return u(()=>{t.current=null}),t}function te(e,t){let[o,n]=q(t);return[o,s=>{n(e(o(),s))}]}function oe(e,t,o,n){A(()=>{let i=e&&"current"in e?e.current:e;if(i)return i.addEventListener(t,o,n),()=>{i.removeEventListener(t,o,n)}})}function re(e){return e}function ie(){return h}function se(e){h&&e()}import{createSignal as x,createMemo as ae,createEffect as ce,createRenderEffect as fe,isSignal as M,readChildren as ue,useContext as de,createContext as pe,createSuspenseBoundary as le,provideSuspense as j}from"@fluixi/reactive/signal";import{asSuspense as me,isComponent as ye,createComponent as D,runWithoutHydration as be}from"@fluixi/dom";function he(e){return typeof window>"u"?!1:typeof Node=="function"&&e instanceof Node?!0:!!(e&&typeof e=="object"&&typeof e.nodeType=="number")}function xe(e){return!e||typeof e!="object"?!1:!!(typeof e._$litType$<"u"||typeof e._$litDirective$<"u"||Array.isArray(e.strings)&&Array.isArray(e.values))}function F(e){return!!(e&&typeof e=="object"&&typeof e.then=="function"||e instanceof Promise)}function ve(e){return!!(e&&typeof e=="object"&&"type"in e&&"props"in e)}var $=pe(void 0,"suspense-list");function v(e){return D(Ce,e)}function Ce(e){let t=le(),o=de($),n=o?o.register(t.inFallback):void 0;function i(f){return f==null||typeof f=="boolean"?null:typeof f=="function"&&ye(f)&&!M(f)?f():f}let s=be(()=>i(e.fallback??null)),r=j(t,()=>ue(()=>e.children)),a=(f,m)=>{if(!(m>8))if(Array.isArray(f))for(let I of f)a(I,m+1);else typeof f=="function"&&M(f)&&a(f(),m+1)};j(t,()=>{fe(()=>a(r,0))});let[c,d]=x(void 0),p=F(r);return p&&(t.increment(),r.then(f=>{d(()=>f),t.decrement()},()=>t.decrement())),ae(()=>(n?n.showFallback():t.inFallback())?s:p?c():r)}function we(e){return D(Se,e)}function Se(e){let{revealOrder:t="together",tail:o}=e,n=[];function i(){if(t==="together"){let r=n.every(a=>!a.inFallback());n.forEach(a=>{a.setShowContent(r),a.setShowFallback(!r)})}else{let r=t==="backwards"?[...n].reverse():n,a=!1;for(let c of r)a||c.inFallback()?(a=!0,c.setShowContent(!1),c.setShowFallback(o!=="hidden")):(c.setShowContent(!0),c.setShowFallback(!1))}}let s={register:r=>{let[a,c]=x(!0),[d,p]=x(!1);return n.push({inFallback:r,setShowContent:c,setShowFallback:p}),ce(()=>{r(),i()}),{showContent:a,showFallback:d}}};return $.Provider({value:s,children:e.children})}me(v);Object.defineProperty(v,"__suspense",{value:!0,enumerable:!0});import{createComponent as ke}from"@fluixi/dom";import{untrack as ge,createMemo as Te,createResource as Le}from"@fluixi/reactive/signal";function z(e){if(e!=null&&(typeof e=="object"||typeof e=="function"))try{e.$lazy=!0}catch{}return e}function C(e,t){let o,n,i;function s(){return n||(n=e().then(a=>o=a.default)),n}t?.preload&&s();let r=(a=>{if(o){let c=o;return z(ge(()=>c(a)))}if(!i){let[c]=Le(()=>s(),{transport:!1});if(i=c,c.error)throw c.error}return Te(()=>{let c=i();return c?z(ke(c,a)):void 0})});return r.preload=()=>s().then(()=>{}),r.$lazy=!0,r.loader=e,r}import{isServer as N}from"@fluixi/dom";import{createMemo as Ee,createSignal as Oe}from"@fluixi/reactive/signal";import{observeIntersection as Re}from"@fluixi/dom/utils";function Pe(e,t){let o=t.export??"default",n=C(()=>e().then(s=>{let r=s[o];if(typeof r!="function")throw new Error(`deferred(): module has no '${o}' export (got ${typeof r}).`);return{default:r}}),{fallback:t.fallback});function i(s){if(t.strategy.kind==="never")return N()?n(s):null;if(N()||t.strategy.kind==="eager")return n(s);let[r,a]=Oe(!1),c=()=>{n.preload().then(()=>a(!0))},d=t.strategy.kind==="visible"?Ae():void 0;return Me(t.strategy,c,d),Ee(()=>r()?n(s):d??t.fallback??null,void 0,{name:"deferred"})}return i.preload=n.preload,i}function Ae(){let e=document.createElement("span");return e.setAttribute("data-fx-load","visible"),e.style.display="block",e}function Me(e,t,o){let n=!1,i=()=>{n||(n=!0,t())};switch(e.kind){case"idle":{let s=globalThis.requestIdleCallback;s?s(i):setTimeout(i,1);return}case"visible":{if(!o||typeof IntersectionObserver>"u"){i();return}let s=Re(o,r=>{r&&(s(),i())},{rootMargin:e.rootMargin??"0px"});return}case"interaction":{let s=()=>{for(let r of e.events)document.removeEventListener(r,s,!0);i()};for(let r of e.events)document.addEventListener(r,s,{capture:!0,passive:!0});return}case"media":{if(typeof matchMedia>"u"){i();return}let s=matchMedia(e.query);if(s.matches){i();return}let r=a=>{a.matches&&(s.removeEventListener("change",r),i())};s.addEventListener("change",r);return}default:i()}}import{createResource as je}from"@fluixi/reactive/signal";function De(e){let t=()=>{let n=e.value;return typeof n=="function"?n():n},[o]=je(t);return()=>{if(o.loading)return e.fallback;let n=e.children;return typeof n=="function"?n(o()):n}}function Ne(e,t,o={}){if(_(["click","input","change","submit"]),w())throw new Error("render() is for client-side only. Use renderToString() on server.");if(!t)throw new Error("Container element is required");let n;return Fe(i=>{n=i;let s=typeof e=="function"?e():e;t.textContent="",k(t),g(),ze(t,()=>s)}),()=>{n&&(n(),n=void 0)}}function _e(e){return e&&typeof e=="object"&&(e._$litType$!==void 0||e._$litDirective$!==void 0)}function En(e,t,o={}){let n=document.createElement("div");n.setAttribute("data-portal","true"),t.appendChild(n);let i=Ne(e,n,o);return()=>{i(),t.contains(n)&&t.removeChild(n)}}function On(e){return!!(e==null||typeof e=="function"||$e(e)||_e(e)||Array.isArray(e)||typeof e=="string"||typeof e=="number"||typeof e=="boolean")}function Rn(){w()||_(["click","input","change","submit"])}function Pn(){w()}export{Y as $component,De as Await,h as DEV,v as Suspense,we as SuspenseList,B as batch,Pn as cleanupDelegation,Q as createComponent,l as createEffect,E as createMemo,Pe as deferred,se as devOnly,b as getOwner,X as getSharedConfig,Rn as initDelegation,ie as isDev,ve as isJSXElement,xe as isLitResult,he as isNode,F as isPromise,On as isRenderable,C as lazy,u as onCleanup,G as onMount,Z as onUnmount,En as portal,Ne as render,O as runWithOwner,re as useCallback,A as useEffect,oe as useEventListener,ee as useMemo,te as useReducer,ne as useRef};
1
+ // src/lib/render/index.ts
2
+ import { isServer as isServer3 } from "@fluixi/dom";
3
+ import { createRoot as createRoot2 } from "@fluixi/reactive/signal";
4
+
5
+ // src/lib/render/versions.ts
6
+ import { registerCoreVersion } from "@fluixi/dom";
7
+
8
+ // src/version.generated.ts
9
+ var VERSION = "1.0.0-alpha.84";
10
+
11
+ // src/lib/render/versions.ts
12
+ import { stampVersions, warnOnVersionSkew, versions } from "@fluixi/dom";
13
+ registerCoreVersion(VERSION);
14
+
15
+ // src/lib/render/index.ts
16
+ import {
17
+ isDOMNode,
18
+ delegateEvents,
19
+ insert
20
+ } from "@fluixi/dom";
21
+
22
+ // src/lib/render/component.ts
23
+ import { isServer } from "@fluixi/dom";
24
+ import {
25
+ createComponent as domCreateComponent,
26
+ asComponent
27
+ } from "@fluixi/dom";
28
+ import {
29
+ untrack,
30
+ onCleanup,
31
+ getOwner,
32
+ createEffect,
33
+ createMemo,
34
+ createSignal,
35
+ isSignal,
36
+ batch,
37
+ runWithOwner,
38
+ isOwnerDisposed
39
+ } from "@fluixi/reactive/signal";
40
+ var sharedConfig = {
41
+ context: null,
42
+ owner: null
43
+ };
44
+ function getSharedConfig() {
45
+ return sharedConfig;
46
+ }
47
+ var DEV = typeof process !== "undefined" && false;
48
+ var _LIFECYCLE = /* @__PURE__ */ Symbol.for("fluixi-lifecycle");
49
+ function getOwnerLifecycle() {
50
+ const owner = getOwner();
51
+ if (!owner) return null;
52
+ if (!owner[_LIFECYCLE]) {
53
+ const lc = { mounts: [], effects: [], scheduled: false };
54
+ owner[_LIFECYCLE] = lc;
55
+ }
56
+ return owner[_LIFECYCLE];
57
+ }
58
+ function scheduleLifecycleFlush(lc) {
59
+ if (lc.scheduled) return;
60
+ if (isServer()) {
61
+ lc.mounts = [];
62
+ lc.effects = [];
63
+ return;
64
+ }
65
+ lc.scheduled = true;
66
+ const owner = getOwner();
67
+ queueMicrotask(() => {
68
+ if (isOwnerDisposed(owner)) {
69
+ lc.mounts = [];
70
+ lc.effects = [];
71
+ return;
72
+ }
73
+ runWithOwner(owner, () => {
74
+ for (const cb of lc.mounts) {
75
+ try {
76
+ const cleanup = cb();
77
+ if (typeof cleanup === "function") {
78
+ onCleanup(cleanup);
79
+ }
80
+ } catch (e) {
81
+ console.error("Error in onMount callback:", e);
82
+ }
83
+ }
84
+ for (const cb of lc.effects) {
85
+ let cleanup;
86
+ createEffect(() => {
87
+ if (cleanup) cleanup();
88
+ cleanup = cb();
89
+ });
90
+ onCleanup(() => {
91
+ if (cleanup) cleanup();
92
+ });
93
+ }
94
+ lc.mounts = [];
95
+ lc.effects = [];
96
+ });
97
+ });
98
+ }
99
+ function createComponent(Comp, props) {
100
+ return domCreateComponent(Comp, props);
101
+ }
102
+ function $component(value, props) {
103
+ const component = typeof value === "function" ? untrack(() => value(props)) : value;
104
+ const nameable = component != null && (typeof component === "function" || typeof component === "object");
105
+ if (nameable) {
106
+ try {
107
+ component["$name"] = value.name;
108
+ } catch {
109
+ }
110
+ }
111
+ if (nameable && !isSignal(component)) {
112
+ return asComponent(component);
113
+ }
114
+ return component;
115
+ }
116
+ function onMount(fn, reactive = true) {
117
+ if (isServer()) return;
118
+ const lc = getOwnerLifecycle();
119
+ if (lc) {
120
+ if (!reactive) {
121
+ if (!lc.scheduled) {
122
+ fn();
123
+ }
124
+ return;
125
+ }
126
+ lc.mounts.push(fn);
127
+ scheduleLifecycleFlush(lc);
128
+ } else {
129
+ if (!reactive) {
130
+ fn();
131
+ return;
132
+ }
133
+ createEffect(() => {
134
+ const cleanup = untrack(fn);
135
+ if (typeof cleanup === "function") {
136
+ onCleanup(cleanup);
137
+ }
138
+ });
139
+ }
140
+ }
141
+ function onUnmount(fn) {
142
+ onCleanup(fn);
143
+ }
144
+ function useEffect(callback) {
145
+ const lc = getOwnerLifecycle();
146
+ if (lc) {
147
+ lc.effects.push(callback);
148
+ scheduleLifecycleFlush(lc);
149
+ } else {
150
+ let cleanup;
151
+ createEffect(() => {
152
+ if (cleanup) cleanup();
153
+ cleanup = callback();
154
+ });
155
+ onCleanup(() => {
156
+ if (cleanup) cleanup();
157
+ });
158
+ }
159
+ }
160
+ function useMemo(fn) {
161
+ return createMemo(fn);
162
+ }
163
+ function useRef(initialValue) {
164
+ const ref = { current: initialValue };
165
+ onCleanup(() => {
166
+ ref.current = null;
167
+ });
168
+ return ref;
169
+ }
170
+ function useReducer(reducer, initialState) {
171
+ const [state, setState] = createSignal(initialState);
172
+ const dispatch = (action) => {
173
+ setState(reducer(state(), action));
174
+ };
175
+ return [state, dispatch];
176
+ }
177
+ function useEventListener(target, event, handler, options) {
178
+ useEffect(() => {
179
+ const element = target && "current" in target ? target.current : target;
180
+ if (!element) return;
181
+ element.addEventListener(event, handler, options);
182
+ return () => {
183
+ element.removeEventListener(event, handler, options);
184
+ };
185
+ });
186
+ }
187
+ function useCallback(callback) {
188
+ return callback;
189
+ }
190
+ function isDev() {
191
+ return DEV;
192
+ }
193
+ function devOnly(fn) {
194
+ if (DEV) {
195
+ fn();
196
+ }
197
+ }
198
+
199
+ // src/lib/render/suspense.ts
200
+ import {
201
+ createSignal as createSignal2,
202
+ createMemo as createMemo2,
203
+ createEffect as createEffect2,
204
+ createRenderEffect as createRenderEffect2,
205
+ isSignal as isSignal2,
206
+ readChildren,
207
+ useContext as useContext2,
208
+ createContext as createContext2,
209
+ createSuspenseBoundary,
210
+ provideSuspense
211
+ } from "@fluixi/reactive/signal";
212
+ import {
213
+ asSuspense,
214
+ isComponent,
215
+ createComponent as createComponent2,
216
+ runWithoutHydration
217
+ } from "@fluixi/dom";
218
+ function isNode(value) {
219
+ if (typeof window === "undefined") return false;
220
+ if (typeof Node === "function" && value instanceof Node) return true;
221
+ return !!(value && typeof value === "object" && typeof value.nodeType === "number");
222
+ }
223
+ function isLitResult(value) {
224
+ if (!value || typeof value !== "object") return false;
225
+ return !!(typeof value["_$litType$"] !== "undefined" || typeof value["_$litDirective$"] !== "undefined" || Array.isArray(value.strings) && Array.isArray(value.values));
226
+ }
227
+ function isPromise(value) {
228
+ return !!(value && typeof value === "object" && typeof value.then === "function" || value instanceof Promise);
229
+ }
230
+ function isJSXElement(value) {
231
+ return !!(value && typeof value === "object" && "type" in value && "props" in value);
232
+ }
233
+ var SuspenseListContext = createContext2(void 0, "suspense-list");
234
+ function Suspense(props) {
235
+ return createComponent2(SuspenseImpl, props);
236
+ }
237
+ function SuspenseImpl(props) {
238
+ const boundary = createSuspenseBoundary();
239
+ const listCtx = useContext2(SuspenseListContext);
240
+ const listState = listCtx ? listCtx.register(boundary.inFallback) : void 0;
241
+ function instantiateOnce(val) {
242
+ if (val == null || typeof val === "boolean") return null;
243
+ if (typeof val === "function" && isComponent(val) && !isSignal2(val)) return val();
244
+ return val;
245
+ }
246
+ const fallback = runWithoutHydration(() => instantiateOnce(props.fallback ?? null));
247
+ const children = provideSuspense(boundary, () => readChildren(() => props.children));
248
+ const track = (value, depth) => {
249
+ if (depth > 8) return;
250
+ if (Array.isArray(value)) {
251
+ for (const x of value) track(x, depth + 1);
252
+ } else if (typeof value === "function" && isSignal2(value)) {
253
+ track(value(), depth + 1);
254
+ }
255
+ };
256
+ provideSuspense(boundary, () => {
257
+ createRenderEffect2(() => track(children, 0));
258
+ });
259
+ const [resolved, setResolved] = createSignal2(void 0);
260
+ const childIsPromise = isPromise(children);
261
+ if (childIsPromise) {
262
+ boundary.increment();
263
+ children.then(
264
+ (v) => {
265
+ setResolved(() => v);
266
+ boundary.decrement();
267
+ },
268
+ () => boundary.decrement()
269
+ );
270
+ }
271
+ return createMemo2(() => {
272
+ const showFallback = listState ? listState.showFallback() : boundary.inFallback();
273
+ if (showFallback) return fallback;
274
+ if (childIsPromise) return resolved();
275
+ return children;
276
+ });
277
+ }
278
+ function SuspenseList(props) {
279
+ return createComponent2(SuspenseListImpl, props);
280
+ }
281
+ function SuspenseListImpl(props) {
282
+ const { revealOrder = "together", tail } = props;
283
+ const registrations = [];
284
+ function coordinateReveal() {
285
+ if (revealOrder === "together") {
286
+ const allResolved = registrations.every((r) => !r.inFallback());
287
+ registrations.forEach((r) => {
288
+ r.setShowContent(allResolved);
289
+ r.setShowFallback(!allResolved);
290
+ });
291
+ } else {
292
+ const items = revealOrder === "backwards" ? [...registrations].reverse() : registrations;
293
+ let blocked = false;
294
+ for (const r of items) {
295
+ if (blocked || r.inFallback()) {
296
+ blocked = true;
297
+ r.setShowContent(false);
298
+ r.setShowFallback(tail !== "hidden");
299
+ } else {
300
+ r.setShowContent(true);
301
+ r.setShowFallback(false);
302
+ }
303
+ }
304
+ }
305
+ }
306
+ const coordinator = {
307
+ register: (inFallback) => {
308
+ const [showContent, setShowContent] = createSignal2(true);
309
+ const [showFallback, setShowFallback] = createSignal2(false);
310
+ registrations.push({ inFallback, setShowContent, setShowFallback });
311
+ createEffect2(() => {
312
+ inFallback();
313
+ coordinateReveal();
314
+ });
315
+ return { showContent, showFallback };
316
+ }
317
+ };
318
+ return SuspenseListContext.Provider({
319
+ value: coordinator,
320
+ children: props.children
321
+ });
322
+ }
323
+ asSuspense(Suspense);
324
+ Object.defineProperty(Suspense, "__suspense", { value: true, enumerable: true });
325
+
326
+ // src/lib/render/lazy.ts
327
+ import { createComponent as createComponent3 } from "@fluixi/dom";
328
+ import {
329
+ untrack as untrack2,
330
+ createMemo as createMemo3,
331
+ createResource as createResource2
332
+ } from "@fluixi/reactive/signal";
333
+ function fromChunk(value) {
334
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
335
+ try {
336
+ value["$lazy"] = true;
337
+ } catch {
338
+ }
339
+ }
340
+ return value;
341
+ }
342
+ function lazy(loader, options) {
343
+ let resolved;
344
+ let promise;
345
+ let component;
346
+ function load() {
347
+ if (!promise) {
348
+ promise = loader().then((mod) => resolved = mod.default);
349
+ }
350
+ return promise;
351
+ }
352
+ if (options?.preload) load();
353
+ const LazyWrapper = ((props) => {
354
+ if (resolved) {
355
+ const C = resolved;
356
+ return fromChunk(untrack2(() => C(props)));
357
+ }
358
+ if (!component) {
359
+ const [resource] = createResource2(() => load(), { transport: false });
360
+ component = resource;
361
+ if (resource.error) throw resource.error;
362
+ }
363
+ return createMemo3(() => {
364
+ const C = component();
365
+ return C ? fromChunk(createComponent3(C, props)) : void 0;
366
+ });
367
+ });
368
+ LazyWrapper.preload = () => load().then(() => void 0);
369
+ LazyWrapper.$lazy = true;
370
+ LazyWrapper.loader = loader;
371
+ return LazyWrapper;
372
+ }
373
+
374
+ // src/lib/render/deferred.ts
375
+ import { isServer as isServer2 } from "@fluixi/dom";
376
+ import { createMemo as createMemo4, createSignal as createSignal3 } from "@fluixi/reactive/signal";
377
+ import { observeIntersection } from "@fluixi/dom/utils";
378
+ function deferred(loader, options) {
379
+ const exportName = options.export ?? "default";
380
+ const Lazy = lazy(
381
+ () => loader().then((mod) => {
382
+ const component = mod[exportName];
383
+ if (typeof component !== "function") {
384
+ throw new Error(
385
+ `deferred(): module has no '${exportName}' export (got ${typeof component}).`
386
+ );
387
+ }
388
+ return { default: component };
389
+ }),
390
+ { fallback: options.fallback }
391
+ );
392
+ function Deferred(props) {
393
+ if (options.strategy.kind === "never") return isServer2() ? Lazy(props) : null;
394
+ if (isServer2() || options.strategy.kind === "eager") return Lazy(props);
395
+ const [ready, setReady] = createSignal3(false);
396
+ const start = () => {
397
+ void Lazy.preload().then(() => setReady(true));
398
+ };
399
+ const anchor = options.strategy.kind === "visible" ? createAnchor() : void 0;
400
+ schedule(options.strategy, start, anchor);
401
+ return createMemo4(() => ready() ? Lazy(props) : anchor ?? options.fallback ?? null, void 0, {
402
+ name: "deferred"
403
+ });
404
+ }
405
+ Deferred.preload = Lazy.preload;
406
+ return Deferred;
407
+ }
408
+ function createAnchor() {
409
+ const el = document.createElement("span");
410
+ el.setAttribute("data-fx-load", "visible");
411
+ el.style.display = "block";
412
+ return el;
413
+ }
414
+ function schedule(strategy, start, anchor) {
415
+ let fired = false;
416
+ const once = () => {
417
+ if (fired) return;
418
+ fired = true;
419
+ start();
420
+ };
421
+ switch (strategy.kind) {
422
+ case "idle": {
423
+ const ric = globalThis.requestIdleCallback;
424
+ if (ric) ric(once);
425
+ else setTimeout(once, 1);
426
+ return;
427
+ }
428
+ case "visible": {
429
+ if (!anchor || typeof IntersectionObserver === "undefined") {
430
+ once();
431
+ return;
432
+ }
433
+ const stop = observeIntersection(
434
+ anchor,
435
+ (isIntersecting) => {
436
+ if (!isIntersecting) return;
437
+ stop();
438
+ once();
439
+ },
440
+ { rootMargin: strategy.rootMargin ?? "0px" }
441
+ );
442
+ return;
443
+ }
444
+ case "interaction": {
445
+ const handler = () => {
446
+ for (const event of strategy.events) {
447
+ document.removeEventListener(event, handler, true);
448
+ }
449
+ once();
450
+ };
451
+ for (const event of strategy.events) {
452
+ document.addEventListener(event, handler, { capture: true, passive: true });
453
+ }
454
+ return;
455
+ }
456
+ case "media": {
457
+ if (typeof matchMedia === "undefined") {
458
+ once();
459
+ return;
460
+ }
461
+ const query = matchMedia(strategy.query);
462
+ if (query.matches) {
463
+ once();
464
+ return;
465
+ }
466
+ const onChange = (e) => {
467
+ if (!e.matches) return;
468
+ query.removeEventListener("change", onChange);
469
+ once();
470
+ };
471
+ query.addEventListener("change", onChange);
472
+ return;
473
+ }
474
+ /* c8 ignore next 3 */
475
+ default:
476
+ once();
477
+ }
478
+ }
479
+
480
+ // src/lib/render/await.ts
481
+ import { createResource as createResource3 } from "@fluixi/reactive/signal";
482
+ function Await(props) {
483
+ const fetcher = () => {
484
+ const v = props.value;
485
+ return typeof v === "function" ? v() : v;
486
+ };
487
+ const [data] = createResource3(fetcher);
488
+ return () => {
489
+ if (data.loading) return props.fallback;
490
+ const child = props.children;
491
+ return typeof child === "function" ? child(data()) : child;
492
+ };
493
+ }
494
+
495
+ // src/lib/render/index.ts
496
+ function render(code, container, options = {}) {
497
+ delegateEvents(["click", "input", "change", "submit"]);
498
+ if (isServer3()) {
499
+ throw new Error(
500
+ "render() is for client-side only. Use renderToString() on server."
501
+ );
502
+ }
503
+ if (!container) {
504
+ throw new Error("Container element is required");
505
+ }
506
+ let disposer;
507
+ createRoot2((dispose) => {
508
+ disposer = dispose;
509
+ const result = typeof code === "function" ? code() : code;
510
+ container.textContent = "";
511
+ stampVersions(container);
512
+ warnOnVersionSkew();
513
+ insert(container, () => result);
514
+ });
515
+ return () => {
516
+ if (disposer) {
517
+ disposer();
518
+ disposer = void 0;
519
+ }
520
+ };
521
+ }
522
+ function isLitTemplateResult(value) {
523
+ return value && typeof value === "object" && (value["_$litType$"] !== void 0 || value["_$litDirective$"] !== void 0);
524
+ }
525
+ function portal(code, target, options = {}) {
526
+ const container = document.createElement("div");
527
+ container.setAttribute("data-portal", "true");
528
+ target.appendChild(container);
529
+ const dispose = render(code, container, options);
530
+ return () => {
531
+ dispose();
532
+ if (target.contains(container)) {
533
+ target.removeChild(container);
534
+ }
535
+ };
536
+ }
537
+ function isRenderable(value) {
538
+ if (value == null) return true;
539
+ if (typeof value === "function") return true;
540
+ if (isDOMNode(value)) return true;
541
+ if (isLitTemplateResult(value)) return true;
542
+ if (Array.isArray(value)) return true;
543
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
544
+ return true;
545
+ }
546
+ return false;
547
+ }
548
+ function initDelegation() {
549
+ if (isServer3()) return;
550
+ delegateEvents(["click", "input", "change", "submit"]);
551
+ }
552
+ function cleanupDelegation() {
553
+ if (isServer3()) return;
554
+ }
555
+ export {
556
+ $component,
557
+ Await,
558
+ DEV,
559
+ Suspense,
560
+ SuspenseList,
561
+ batch,
562
+ cleanupDelegation,
563
+ createComponent,
564
+ createEffect,
565
+ createMemo,
566
+ deferred,
567
+ devOnly,
568
+ getOwner,
569
+ getSharedConfig,
570
+ initDelegation,
571
+ isDev,
572
+ isJSXElement,
573
+ isLitResult,
574
+ isNode,
575
+ isPromise,
576
+ isRenderable,
577
+ lazy,
578
+ onCleanup,
579
+ onMount,
580
+ onUnmount,
581
+ portal,
582
+ render,
583
+ runWithOwner,
584
+ useCallback,
585
+ useEffect,
586
+ useEventListener,
587
+ useMemo,
588
+ useReducer,
589
+ useRef
590
+ };