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

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 (182) 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-MDJLC3PE.mjs +830 -0
  9. package/dist/src/cdn/core.cjs +1365 -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-JYFZP3EZ.mjs +70 -0
  14. package/dist/src/index.cjs +1280 -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 +1393 -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-7IUN2FLI.mjs +133 -0
  24. package/dist/src/lib/client/index.cjs +956 -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-NOFEMOEH.mjs +631 -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 +1279 -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 +1393 -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 +709 -1
  125. package/dist/src/lib/router/index.d.ts +78 -23
  126. package/dist/src/lib/router/index.d.ts.map +1 -1
  127. package/dist/src/lib/router/index.js +161 -37
  128. package/dist/src/lib/router/index.mjs +722 -1
  129. package/dist/src/lib/router/transition.cjs +75 -0
  130. package/dist/src/lib/router/transition.d.ts +81 -0
  131. package/dist/src/lib/router/transition.d.ts.map +1 -0
  132. package/dist/src/lib/router/transition.js +136 -0
  133. package/dist/src/lib/router/transition.mjs +54 -0
  134. package/dist/src/lib/server/hydration.cjs +169 -1
  135. package/dist/src/lib/server/hydration.d.ts +15 -55
  136. package/dist/src/lib/server/hydration.d.ts.map +1 -1
  137. package/dist/src/lib/server/hydration.js +23 -62
  138. package/dist/src/lib/server/hydration.mjs +148 -1
  139. package/dist/src/lib/server/index.cjs +401 -11
  140. package/dist/src/lib/server/index.d.ts +30 -6
  141. package/dist/src/lib/server/index.d.ts.map +1 -1
  142. package/dist/src/lib/server/index.js +34 -11
  143. package/dist/src/lib/server/index.mjs +379 -11
  144. package/dist/src/lib/server/reactive.cjs +197 -1
  145. package/dist/src/lib/server/reactive.d.ts +18 -77
  146. package/dist/src/lib/server/reactive.d.ts.map +1 -1
  147. package/dist/src/lib/server/reactive.js +19 -78
  148. package/dist/src/lib/server/reactive.mjs +176 -1
  149. package/dist/src/lib/theme/index.cjs +110 -1
  150. package/dist/src/lib/theme/index.d.ts +19 -4
  151. package/dist/src/lib/theme/index.d.ts.map +1 -1
  152. package/dist/src/lib/theme/index.js +17 -2
  153. package/dist/src/lib/theme/index.mjs +89 -1
  154. package/dist/src/lib/utils/index.cjs +209 -1
  155. package/dist/src/lib/utils/index.d.ts +0 -93
  156. package/dist/src/lib/utils/index.d.ts.map +1 -1
  157. package/dist/src/lib/utils/index.js +0 -93
  158. package/dist/src/lib/utils/index.mjs +188 -1
  159. package/dist/src/routes.cjs +37 -1
  160. package/dist/src/routes.d.ts +1 -1
  161. package/dist/src/routes.js +2 -2
  162. package/dist/src/routes.mjs +17 -1
  163. package/dist/src/server.cjs +400 -11
  164. package/dist/src/server.d.ts +0 -1
  165. package/dist/src/server.d.ts.map +1 -1
  166. package/dist/src/server.js +0 -1
  167. package/dist/src/server.mjs +377 -11
  168. package/dist/src/utils.cjs +21 -1
  169. package/dist/src/utils.d.ts +1 -1
  170. package/dist/src/utils.js +1 -1
  171. package/dist/src/utils.mjs +4 -1
  172. package/dist/src/version.generated.cjs +26 -1
  173. package/dist/src/version.generated.d.ts +1 -1
  174. package/dist/src/version.generated.js +2 -2
  175. package/dist/src/version.generated.mjs +5 -1
  176. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  177. package/package.json +17 -16
  178. package/src/index.ts +2 -14
  179. package/dist/src/cdn/chunk-55BT3H6E.mjs +0 -1
  180. package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
  181. package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
  182. package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
@@ -1 +1,214 @@
1
- import{isServer as a}from"@fluixi/dom";import{createComponent as y,asComponent as x}from"@fluixi/dom";import{untrack as p,onCleanup as r,getOwner as f,createEffect as s,createMemo as C,createSignal as T,isSignal as E,batch as U,runWithOwner as O,isOwnerDisposed as w}from"@fluixi/reactive/signal";var c={context:null,owner:null};function V(){return c}function F(e){c.owner=e,c.context=e}function I(){return c.context||c.owner}var d=typeof process<"u"&&!1,u=Symbol.for("fluixi-lifecycle");function l(){let e=f();if(!e)return null;if(!e[u]){let t={mounts:[],effects:[],scheduled:!1};e[u]=t}return e[u]}function v(e){if(e.scheduled)return;if(a()){e.mounts=[],e.effects=[];return}e.scheduled=!0;let t=f();queueMicrotask(()=>{if(w(t)){e.mounts=[],e.effects=[];return}O(t,()=>{for(let n of e.mounts)try{let o=n();typeof o=="function"&&r(o)}catch(o){console.error("Error in onMount callback:",o)}for(let n of e.effects){let o;s(()=>{o&&o(),o=n()}),r(()=>{o&&o()})}e.mounts=[],e.effects=[]})})}function N(e){}function $(e,t){return y(e,t)}function q(e,t){let n=typeof e=="function"?p(()=>e(t)):e,o=n!=null&&(typeof n=="function"||typeof n=="object");if(o)try{n.$name=e.name}catch{}return o&&!E(n)?x(n):n}function P(e,t=!0){if(a())return;let n=l();if(n){if(!t){n.scheduled||e();return}n.mounts.push(e),v(n)}else{if(!t){e();return}s(()=>{let o=p(e);typeof o=="function"&&r(o)})}}function Y(e){r(e)}function h(e){let t=l();if(t)t.effects.push(e),v(t);else{let n;s(()=>{n&&n(),n=e()}),r(()=>{n&&n()})}}function z(e){return C(e)}function B(e){let t={current:e};return r(()=>{t.current=null}),t}function G(e,t){let[n,o]=T(t);return[n,m=>{o(e(n(),m))}]}function H(e,t,n,o){h(()=>{let i=e&&"current"in e?e.current:e;if(i)return i.addEventListener(t,n,o),()=>{i.removeEventListener(t,n,o)}})}function J(e){return e}function Q(){return f()!==null}function X(){return d}function Z(e){d&&e()}export{q as $component,d as DEV,U as batch,$ as createComponent,s as createEffect,C as createMemo,Z as devOnly,N as ensureIntegration,I as getContextOwner,f as getOwner,V as getSharedConfig,Q as hasLifecycleContext,X as isDev,r as onCleanup,P as onMount,Y as onUnmount,O as runWithOwner,F as setOwner,J as useCallback,h as useEffect,H as useEventListener,z as useMemo,G as useReducer,B as useRef};
1
+ // src/lib/render/component.ts
2
+ import { isServer } from "@fluixi/dom";
3
+ import {
4
+ createComponent as domCreateComponent,
5
+ asComponent
6
+ } from "@fluixi/dom";
7
+ import {
8
+ untrack,
9
+ onCleanup,
10
+ getOwner,
11
+ createEffect,
12
+ createMemo,
13
+ createSignal,
14
+ isSignal,
15
+ batch,
16
+ runWithOwner,
17
+ isOwnerDisposed
18
+ } from "@fluixi/reactive/signal";
19
+ var sharedConfig = {
20
+ context: null,
21
+ owner: null
22
+ };
23
+ function getSharedConfig() {
24
+ return sharedConfig;
25
+ }
26
+ function setOwner(owner) {
27
+ sharedConfig.owner = owner;
28
+ sharedConfig.context = owner;
29
+ }
30
+ function getContextOwner() {
31
+ return sharedConfig.context || sharedConfig.owner;
32
+ }
33
+ var DEV = typeof process !== "undefined" && false;
34
+ var _LIFECYCLE = /* @__PURE__ */ Symbol.for("fluixi-lifecycle");
35
+ function getOwnerLifecycle() {
36
+ const owner = getOwner();
37
+ if (!owner) return null;
38
+ if (!owner[_LIFECYCLE]) {
39
+ const lc = { mounts: [], effects: [], scheduled: false };
40
+ owner[_LIFECYCLE] = lc;
41
+ }
42
+ return owner[_LIFECYCLE];
43
+ }
44
+ function scheduleLifecycleFlush(lc) {
45
+ if (lc.scheduled) return;
46
+ if (isServer()) {
47
+ lc.mounts = [];
48
+ lc.effects = [];
49
+ return;
50
+ }
51
+ lc.scheduled = true;
52
+ const owner = getOwner();
53
+ queueMicrotask(() => {
54
+ if (isOwnerDisposed(owner)) {
55
+ lc.mounts = [];
56
+ lc.effects = [];
57
+ return;
58
+ }
59
+ runWithOwner(owner, () => {
60
+ for (const cb of lc.mounts) {
61
+ try {
62
+ const cleanup = cb();
63
+ if (typeof cleanup === "function") {
64
+ onCleanup(cleanup);
65
+ }
66
+ } catch (e) {
67
+ console.error("Error in onMount callback:", e);
68
+ }
69
+ }
70
+ for (const cb of lc.effects) {
71
+ let cleanup;
72
+ createEffect(() => {
73
+ if (cleanup) cleanup();
74
+ cleanup = cb();
75
+ });
76
+ onCleanup(() => {
77
+ if (cleanup) cleanup();
78
+ });
79
+ }
80
+ lc.mounts = [];
81
+ lc.effects = [];
82
+ });
83
+ });
84
+ }
85
+ function ensureIntegration(_from) {
86
+ }
87
+ function createComponent(Comp, props) {
88
+ return domCreateComponent(Comp, props);
89
+ }
90
+ function $component(value, props) {
91
+ const component = typeof value === "function" ? untrack(() => value(props)) : value;
92
+ const nameable = component != null && (typeof component === "function" || typeof component === "object");
93
+ if (nameable) {
94
+ try {
95
+ component["$name"] = value.name;
96
+ } catch {
97
+ }
98
+ }
99
+ if (nameable && !isSignal(component)) {
100
+ return asComponent(component);
101
+ }
102
+ return component;
103
+ }
104
+ function onMount(fn, reactive = true) {
105
+ if (isServer()) return;
106
+ const lc = getOwnerLifecycle();
107
+ if (lc) {
108
+ if (!reactive) {
109
+ if (!lc.scheduled) {
110
+ fn();
111
+ }
112
+ return;
113
+ }
114
+ lc.mounts.push(fn);
115
+ scheduleLifecycleFlush(lc);
116
+ } else {
117
+ if (!reactive) {
118
+ fn();
119
+ return;
120
+ }
121
+ createEffect(() => {
122
+ const cleanup = untrack(fn);
123
+ if (typeof cleanup === "function") {
124
+ onCleanup(cleanup);
125
+ }
126
+ });
127
+ }
128
+ }
129
+ function onUnmount(fn) {
130
+ onCleanup(fn);
131
+ }
132
+ function useEffect(callback) {
133
+ const lc = getOwnerLifecycle();
134
+ if (lc) {
135
+ lc.effects.push(callback);
136
+ scheduleLifecycleFlush(lc);
137
+ } else {
138
+ let cleanup;
139
+ createEffect(() => {
140
+ if (cleanup) cleanup();
141
+ cleanup = callback();
142
+ });
143
+ onCleanup(() => {
144
+ if (cleanup) cleanup();
145
+ });
146
+ }
147
+ }
148
+ function useMemo(fn) {
149
+ return createMemo(fn);
150
+ }
151
+ function useRef(initialValue) {
152
+ const ref = { current: initialValue };
153
+ onCleanup(() => {
154
+ ref.current = null;
155
+ });
156
+ return ref;
157
+ }
158
+ function useReducer(reducer, initialState) {
159
+ const [state, setState] = createSignal(initialState);
160
+ const dispatch = (action) => {
161
+ setState(reducer(state(), action));
162
+ };
163
+ return [state, dispatch];
164
+ }
165
+ function useEventListener(target, event, handler, options) {
166
+ useEffect(() => {
167
+ const element = target && "current" in target ? target.current : target;
168
+ if (!element) return;
169
+ element.addEventListener(event, handler, options);
170
+ return () => {
171
+ element.removeEventListener(event, handler, options);
172
+ };
173
+ });
174
+ }
175
+ function useCallback(callback) {
176
+ return callback;
177
+ }
178
+ function hasLifecycleContext() {
179
+ return getOwner() !== null;
180
+ }
181
+ function isDev() {
182
+ return DEV;
183
+ }
184
+ function devOnly(fn) {
185
+ if (DEV) {
186
+ fn();
187
+ }
188
+ }
189
+ export {
190
+ $component,
191
+ DEV,
192
+ batch,
193
+ createComponent,
194
+ createEffect,
195
+ createMemo,
196
+ devOnly,
197
+ ensureIntegration,
198
+ getContextOwner,
199
+ getOwner,
200
+ getSharedConfig,
201
+ hasLifecycleContext,
202
+ isDev,
203
+ onCleanup,
204
+ onMount,
205
+ onUnmount,
206
+ runWithOwner,
207
+ setOwner,
208
+ useCallback,
209
+ useEffect,
210
+ useEventListener,
211
+ useMemo,
212
+ useReducer,
213
+ useRef
214
+ };
@@ -1 +1,175 @@
1
- "use strict";var f=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var a in t)f(e,a,{get:t[a],enumerable:!0})},L=(e,t,a,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!b.call(e,n)&&n!==a&&f(e,n,{get:()=>t[n],enumerable:!(i=g(t,n))||i.enumerable});return e};var x=e=>L(f({},"__esModule",{value:!0}),e);var M={};C(M,{deferred:()=>P});module.exports=x(M);var l=require("@fluixi/dom"),u=require("@fluixi/reactive/signal"),k=require("@fluixi/dom/utils");var y=require("@fluixi/dom"),c=require("@fluixi/reactive/signal");function p(e){if(e!=null&&(typeof e=="object"||typeof e=="function"))try{e.$lazy=!0}catch{}return e}function v(e,t){let a,i,n;function r(){return i||(i=e().then(s=>a=s.default)),i}t?.preload&&r();let o=(s=>{if(a){let d=a;return p((0,c.untrack)(()=>d(s)))}if(!n){let[d]=(0,c.createResource)(()=>r(),{transport:!1});if(n=d,d.error)throw d.error}return(0,c.createMemo)(()=>{let d=n();return d?p((0,y.createComponent)(d,s)):void 0})});return o.preload=()=>r().then(()=>{}),o.$lazy=!0,o.loader=e,o}function P(e,t){let a=t.export??"default",i=v(()=>e().then(r=>{let o=r[a];if(typeof o!="function")throw new Error(`deferred(): module has no '${a}' export (got ${typeof o}).`);return{default:o}}),{fallback:t.fallback});function n(r){if(t.strategy.kind==="never")return(0,l.isServer)()?i(r):null;if((0,l.isServer)()||t.strategy.kind==="eager")return i(r);let[o,s]=(0,u.createSignal)(!1),d=()=>{i.preload().then(()=>s(!0))},m=t.strategy.kind==="visible"?T():void 0;return w(t.strategy,d,m),(0,u.createMemo)(()=>o()?i(r):m??t.fallback??null,void 0,{name:"deferred"})}return n.preload=i.preload,n}function T(){let e=document.createElement("span");return e.setAttribute("data-fx-load","visible"),e.style.display="block",e}function w(e,t,a){let i=!1,n=()=>{i||(i=!0,t())};switch(e.kind){case"idle":{let r=globalThis.requestIdleCallback;r?r(n):setTimeout(n,1);return}case"visible":{if(!a||typeof IntersectionObserver>"u"){n();return}let r=(0,k.observeIntersection)(a,o=>{o&&(r(),n())},{rootMargin:e.rootMargin??"0px"});return}case"interaction":{let r=()=>{for(let o of e.events)document.removeEventListener(o,r,!0);n()};for(let o of e.events)document.addEventListener(o,r,{capture:!0,passive:!0});return}case"media":{if(typeof matchMedia>"u"){n();return}let r=matchMedia(e.query);if(r.matches){n();return}let o=s=>{s.matches&&(r.removeEventListener("change",o),n())};r.addEventListener("change",o);return}default: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/render/deferred.ts
21
+ var deferred_exports = {};
22
+ __export(deferred_exports, {
23
+ deferred: () => deferred
24
+ });
25
+ module.exports = __toCommonJS(deferred_exports);
26
+ var import_dom2 = require("@fluixi/dom");
27
+ var import_signal2 = require("@fluixi/reactive/signal");
28
+ var import_utils = require("@fluixi/dom/utils");
29
+
30
+ // src/lib/render/lazy.ts
31
+ var import_dom = require("@fluixi/dom");
32
+ var import_signal = require("@fluixi/reactive/signal");
33
+ function fromChunk(value) {
34
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
35
+ try {
36
+ value["$lazy"] = true;
37
+ } catch {
38
+ }
39
+ }
40
+ return value;
41
+ }
42
+ function lazy(loader, options) {
43
+ let resolved;
44
+ let promise;
45
+ let component;
46
+ function load() {
47
+ if (!promise) {
48
+ promise = loader().then((mod) => resolved = mod.default);
49
+ }
50
+ return promise;
51
+ }
52
+ if (options?.preload) load();
53
+ const LazyWrapper = ((props) => {
54
+ if (resolved) {
55
+ const C = resolved;
56
+ return fromChunk((0, import_signal.untrack)(() => C(props)));
57
+ }
58
+ if (!component) {
59
+ const [resource] = (0, import_signal.createResource)(() => load(), { transport: false });
60
+ component = resource;
61
+ if (resource.error) throw resource.error;
62
+ }
63
+ return (0, import_signal.createMemo)(() => {
64
+ const C = component();
65
+ return C ? fromChunk((0, import_dom.createComponent)(C, props)) : void 0;
66
+ });
67
+ });
68
+ LazyWrapper.preload = () => load().then(() => void 0);
69
+ LazyWrapper.$lazy = true;
70
+ LazyWrapper.loader = loader;
71
+ return LazyWrapper;
72
+ }
73
+
74
+ // src/lib/render/deferred.ts
75
+ function deferred(loader, options) {
76
+ const exportName = options.export ?? "default";
77
+ const Lazy = lazy(
78
+ () => loader().then((mod) => {
79
+ const component = mod[exportName];
80
+ if (typeof component !== "function") {
81
+ throw new Error(
82
+ `deferred(): module has no '${exportName}' export (got ${typeof component}).`
83
+ );
84
+ }
85
+ return { default: component };
86
+ }),
87
+ { fallback: options.fallback }
88
+ );
89
+ function Deferred(props) {
90
+ if (options.strategy.kind === "never") return (0, import_dom2.isServer)() ? Lazy(props) : null;
91
+ if ((0, import_dom2.isServer)() || options.strategy.kind === "eager") return Lazy(props);
92
+ const [ready, setReady] = (0, import_signal2.createSignal)(false);
93
+ const start = () => {
94
+ void Lazy.preload().then(() => setReady(true));
95
+ };
96
+ const anchor = options.strategy.kind === "visible" ? createAnchor() : void 0;
97
+ schedule(options.strategy, start, anchor);
98
+ return (0, import_signal2.createMemo)(() => ready() ? Lazy(props) : anchor ?? options.fallback ?? null, void 0, {
99
+ name: "deferred"
100
+ });
101
+ }
102
+ Deferred.preload = Lazy.preload;
103
+ return Deferred;
104
+ }
105
+ function createAnchor() {
106
+ const el = document.createElement("span");
107
+ el.setAttribute("data-fx-load", "visible");
108
+ el.style.display = "block";
109
+ return el;
110
+ }
111
+ function schedule(strategy, start, anchor) {
112
+ let fired = false;
113
+ const once = () => {
114
+ if (fired) return;
115
+ fired = true;
116
+ start();
117
+ };
118
+ switch (strategy.kind) {
119
+ case "idle": {
120
+ const ric = globalThis.requestIdleCallback;
121
+ if (ric) ric(once);
122
+ else setTimeout(once, 1);
123
+ return;
124
+ }
125
+ case "visible": {
126
+ if (!anchor || typeof IntersectionObserver === "undefined") {
127
+ once();
128
+ return;
129
+ }
130
+ const stop = (0, import_utils.observeIntersection)(
131
+ anchor,
132
+ (isIntersecting) => {
133
+ if (!isIntersecting) return;
134
+ stop();
135
+ once();
136
+ },
137
+ { rootMargin: strategy.rootMargin ?? "0px" }
138
+ );
139
+ return;
140
+ }
141
+ case "interaction": {
142
+ const handler = () => {
143
+ for (const event of strategy.events) {
144
+ document.removeEventListener(event, handler, true);
145
+ }
146
+ once();
147
+ };
148
+ for (const event of strategy.events) {
149
+ document.addEventListener(event, handler, { capture: true, passive: true });
150
+ }
151
+ return;
152
+ }
153
+ case "media": {
154
+ if (typeof matchMedia === "undefined") {
155
+ once();
156
+ return;
157
+ }
158
+ const query = matchMedia(strategy.query);
159
+ if (query.matches) {
160
+ once();
161
+ return;
162
+ }
163
+ const onChange = (e) => {
164
+ if (!e.matches) return;
165
+ query.removeEventListener("change", onChange);
166
+ once();
167
+ };
168
+ query.addEventListener("change", onChange);
169
+ return;
170
+ }
171
+ /* c8 ignore next 3 */
172
+ default:
173
+ once();
174
+ }
175
+ }
@@ -1,10 +1,10 @@
1
1
  /**
2
- * `deferred(loader, options)` a component whose module is fetched on a schedule.
2
+ * `deferred(loader, options)`, a component whose module is fetched on a schedule.
3
3
  *
4
4
  * This is the runtime half of the `load:` directive. It adds only the *when*: which
5
5
  * browser signal starts the download. Resolution, Suspense integration and the
6
6
  * synchronous-when-preloaded hydration path all come from {@link lazy}, reused unchanged
7
- * so a deferred component behaves exactly like a lazy one once its trigger fires.
7
+ *, so a deferred component behaves exactly like a lazy one once its trigger fires.
8
8
  *
9
9
  * There is no registry and no runtime name lookup. The compiler emits a call with a
10
10
  * literal `import()`, which is what lets the bundler do chunking, hashing and
@@ -33,7 +33,7 @@ export function deferred(loader, options) {
33
33
  }), { fallback: options.fallback });
34
34
  function Deferred(props) {
35
35
  // `never` is server-only: the component renders during SSR and its code is meant to
36
- // stay out of the client bundle entirely. The compiler is what actually drops it
36
+ // stay out of the client bundle entirely. The compiler is what actually drops it
37
37
  // this guard only stops the client from fetching it if one slips through.
38
38
  if (options.strategy.kind === 'never')
39
39
  return isServer() ? Lazy(props) : null;
@@ -65,7 +65,7 @@ function createAnchor() {
65
65
  el.style.display = 'block';
66
66
  return el;
67
67
  }
68
- /** Run `start` when the strategy's trigger fires. Idempotent it fires at most once. */
68
+ /** Run `start` when the strategy's trigger fires. Idempotent, it fires at most once. */
69
69
  function schedule(strategy, start, anchor) {
70
70
  let fired = false;
71
71
  const once = () => {
@@ -88,7 +88,7 @@ function schedule(strategy, start, anchor) {
88
88
  }
89
89
  case 'visible': {
90
90
  // Without an observer there is no signal to wait for, so load rather than never
91
- // rendering a missing capability should degrade to eager, not to broken.
91
+ // rendering, a missing capability should degrade to eager, not to broken.
92
92
  if (!anchor || typeof IntersectionObserver === 'undefined') {
93
93
  once();
94
94
  return;
@@ -1 +1,158 @@
1
- import{isServer as l}from"@fluixi/dom";import{createMemo as k,createSignal as g}from"@fluixi/reactive/signal";import{observeIntersection as h}from"@fluixi/dom/utils";import{createComponent as m}from"@fluixi/dom";import{untrack as p,createMemo as y,createResource as v}from"@fluixi/reactive/signal";function u(n){if(n!=null&&(typeof n=="object"||typeof n=="function"))try{n.$lazy=!0}catch{}return n}function f(n,i){let d,o,r;function e(){return o||(o=n().then(s=>d=s.default)),o}i?.preload&&e();let t=(s=>{if(d){let a=d;return u(p(()=>a(s)))}if(!r){let[a]=v(()=>e(),{transport:!1});if(r=a,a.error)throw a.error}return y(()=>{let a=r();return a?u(m(a,s)):void 0})});return t.preload=()=>e().then(()=>{}),t.$lazy=!0,t.loader=n,t}function O(n,i){let d=i.export??"default",o=f(()=>n().then(e=>{let t=e[d];if(typeof t!="function")throw new Error(`deferred(): module has no '${d}' export (got ${typeof t}).`);return{default:t}}),{fallback:i.fallback});function r(e){if(i.strategy.kind==="never")return l()?o(e):null;if(l()||i.strategy.kind==="eager")return o(e);let[t,s]=g(!1),a=()=>{o.preload().then(()=>s(!0))},c=i.strategy.kind==="visible"?b():void 0;return C(i.strategy,a,c),k(()=>t()?o(e):c??i.fallback??null,void 0,{name:"deferred"})}return r.preload=o.preload,r}function b(){let n=document.createElement("span");return n.setAttribute("data-fx-load","visible"),n.style.display="block",n}function C(n,i,d){let o=!1,r=()=>{o||(o=!0,i())};switch(n.kind){case"idle":{let e=globalThis.requestIdleCallback;e?e(r):setTimeout(r,1);return}case"visible":{if(!d||typeof IntersectionObserver>"u"){r();return}let e=h(d,t=>{t&&(e(),r())},{rootMargin:n.rootMargin??"0px"});return}case"interaction":{let e=()=>{for(let t of n.events)document.removeEventListener(t,e,!0);r()};for(let t of n.events)document.addEventListener(t,e,{capture:!0,passive:!0});return}case"media":{if(typeof matchMedia>"u"){r();return}let e=matchMedia(n.query);if(e.matches){r();return}let t=s=>{s.matches&&(e.removeEventListener("change",t),r())};e.addEventListener("change",t);return}default:r()}}export{O as deferred};
1
+ // src/lib/render/deferred.ts
2
+ import { isServer } from "@fluixi/dom";
3
+ import { createMemo as createMemo2, createSignal } from "@fluixi/reactive/signal";
4
+ import { observeIntersection } from "@fluixi/dom/utils";
5
+
6
+ // src/lib/render/lazy.ts
7
+ import { createComponent } from "@fluixi/dom";
8
+ import {
9
+ untrack,
10
+ createMemo,
11
+ createResource
12
+ } from "@fluixi/reactive/signal";
13
+ function fromChunk(value) {
14
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
15
+ try {
16
+ value["$lazy"] = true;
17
+ } catch {
18
+ }
19
+ }
20
+ return value;
21
+ }
22
+ function lazy(loader, options) {
23
+ let resolved;
24
+ let promise;
25
+ let component;
26
+ function load() {
27
+ if (!promise) {
28
+ promise = loader().then((mod) => resolved = mod.default);
29
+ }
30
+ return promise;
31
+ }
32
+ if (options?.preload) load();
33
+ const LazyWrapper = ((props) => {
34
+ if (resolved) {
35
+ const C = resolved;
36
+ return fromChunk(untrack(() => C(props)));
37
+ }
38
+ if (!component) {
39
+ const [resource] = createResource(() => load(), { transport: false });
40
+ component = resource;
41
+ if (resource.error) throw resource.error;
42
+ }
43
+ return createMemo(() => {
44
+ const C = component();
45
+ return C ? fromChunk(createComponent(C, props)) : void 0;
46
+ });
47
+ });
48
+ LazyWrapper.preload = () => load().then(() => void 0);
49
+ LazyWrapper.$lazy = true;
50
+ LazyWrapper.loader = loader;
51
+ return LazyWrapper;
52
+ }
53
+
54
+ // src/lib/render/deferred.ts
55
+ function deferred(loader, options) {
56
+ const exportName = options.export ?? "default";
57
+ const Lazy = lazy(
58
+ () => loader().then((mod) => {
59
+ const component = mod[exportName];
60
+ if (typeof component !== "function") {
61
+ throw new Error(
62
+ `deferred(): module has no '${exportName}' export (got ${typeof component}).`
63
+ );
64
+ }
65
+ return { default: component };
66
+ }),
67
+ { fallback: options.fallback }
68
+ );
69
+ function Deferred(props) {
70
+ if (options.strategy.kind === "never") return isServer() ? Lazy(props) : null;
71
+ if (isServer() || options.strategy.kind === "eager") return Lazy(props);
72
+ const [ready, setReady] = createSignal(false);
73
+ const start = () => {
74
+ void Lazy.preload().then(() => setReady(true));
75
+ };
76
+ const anchor = options.strategy.kind === "visible" ? createAnchor() : void 0;
77
+ schedule(options.strategy, start, anchor);
78
+ return createMemo2(() => ready() ? Lazy(props) : anchor ?? options.fallback ?? null, void 0, {
79
+ name: "deferred"
80
+ });
81
+ }
82
+ Deferred.preload = Lazy.preload;
83
+ return Deferred;
84
+ }
85
+ function createAnchor() {
86
+ const el = document.createElement("span");
87
+ el.setAttribute("data-fx-load", "visible");
88
+ el.style.display = "block";
89
+ return el;
90
+ }
91
+ function schedule(strategy, start, anchor) {
92
+ let fired = false;
93
+ const once = () => {
94
+ if (fired) return;
95
+ fired = true;
96
+ start();
97
+ };
98
+ switch (strategy.kind) {
99
+ case "idle": {
100
+ const ric = globalThis.requestIdleCallback;
101
+ if (ric) ric(once);
102
+ else setTimeout(once, 1);
103
+ return;
104
+ }
105
+ case "visible": {
106
+ if (!anchor || typeof IntersectionObserver === "undefined") {
107
+ once();
108
+ return;
109
+ }
110
+ const stop = observeIntersection(
111
+ anchor,
112
+ (isIntersecting) => {
113
+ if (!isIntersecting) return;
114
+ stop();
115
+ once();
116
+ },
117
+ { rootMargin: strategy.rootMargin ?? "0px" }
118
+ );
119
+ return;
120
+ }
121
+ case "interaction": {
122
+ const handler = () => {
123
+ for (const event of strategy.events) {
124
+ document.removeEventListener(event, handler, true);
125
+ }
126
+ once();
127
+ };
128
+ for (const event of strategy.events) {
129
+ document.addEventListener(event, handler, { capture: true, passive: true });
130
+ }
131
+ return;
132
+ }
133
+ case "media": {
134
+ if (typeof matchMedia === "undefined") {
135
+ once();
136
+ return;
137
+ }
138
+ const query = matchMedia(strategy.query);
139
+ if (query.matches) {
140
+ once();
141
+ return;
142
+ }
143
+ const onChange = (e) => {
144
+ if (!e.matches) return;
145
+ query.removeEventListener("change", onChange);
146
+ once();
147
+ };
148
+ query.addEventListener("change", onChange);
149
+ return;
150
+ }
151
+ /* c8 ignore next 3 */
152
+ default:
153
+ once();
154
+ }
155
+ }
156
+ export {
157
+ deferred
158
+ };