@fluixi/core 1.0.0-alpha.82 → 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 (179) 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 +10 -14
  26. package/dist/src/lib/client/index.d.ts.map +1 -1
  27. package/dist/src/lib/client/index.js +36 -21
  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 +20 -38
  32. package/dist/src/lib/context/context.d.ts.map +1 -1
  33. package/dist/src/lib/context/context.js +10 -47
  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 +7 -8
  46. package/dist/src/lib/env/index.d.ts.map +1 -1
  47. package/dist/src/lib/env/index.js +14 -9
  48. package/dist/src/lib/env/index.mjs +39 -1
  49. package/dist/src/lib/i18n/index.cjs +108 -1
  50. package/dist/src/lib/i18n/index.d.ts +31 -10
  51. package/dist/src/lib/i18n/index.d.ts.map +1 -1
  52. package/dist/src/lib/i18n/index.js +31 -10
  53. package/dist/src/lib/i18n/index.mjs +88 -1
  54. package/dist/src/lib/index.cjs +633 -1
  55. package/dist/src/lib/index.d.ts +0 -2
  56. package/dist/src/lib/index.d.ts.map +1 -1
  57. package/dist/src/lib/index.js +5 -11
  58. package/dist/src/lib/index.mjs +721 -1
  59. package/dist/src/lib/isomorphic.cjs +85 -1
  60. package/dist/src/lib/isomorphic.d.ts +41 -8
  61. package/dist/src/lib/isomorphic.d.ts.map +1 -1
  62. package/dist/src/lib/isomorphic.js +38 -5
  63. package/dist/src/lib/isomorphic.mjs +64 -1
  64. package/dist/src/lib/jsx-runtime/index.cjs +21 -1
  65. package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
  66. package/dist/src/lib/jsx-runtime/index.js +1 -11
  67. package/dist/src/lib/jsx-runtime/index.mjs +4 -1
  68. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
  69. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
  70. package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
  71. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
  72. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
  73. package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
  74. package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
  75. package/dist/src/lib/plugins/index.cjs +311 -8
  76. package/dist/src/lib/plugins/index.mjs +279 -8
  77. package/dist/src/lib/plugins/route-codegen.cjs +73 -8
  78. package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
  79. package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
  80. package/dist/src/lib/plugins/route-codegen.js +4 -5
  81. package/dist/src/lib/plugins/route-codegen.mjs +52 -8
  82. package/dist/src/lib/plugins/route-scanner.cjs +189 -1
  83. package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
  84. package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
  85. package/dist/src/lib/plugins/route-scanner.js +7 -8
  86. package/dist/src/lib/plugins/route-scanner.mjs +158 -1
  87. package/dist/src/lib/plugins/vite.cjs +27 -1
  88. package/dist/src/lib/plugins/vite.mjs +6 -1
  89. package/dist/src/lib/render/await.cjs +38 -1
  90. package/dist/src/lib/render/await.d.ts +18 -0
  91. package/dist/src/lib/render/await.d.ts.map +1 -1
  92. package/dist/src/lib/render/await.js +20 -2
  93. package/dist/src/lib/render/await.mjs +17 -1
  94. package/dist/src/lib/render/component.cjs +221 -1
  95. package/dist/src/lib/render/component.d.ts +3 -44
  96. package/dist/src/lib/render/component.d.ts.map +1 -1
  97. package/dist/src/lib/render/component.js +32 -59
  98. package/dist/src/lib/render/component.mjs +214 -1
  99. package/dist/src/lib/render/deferred.cjs +175 -1
  100. package/dist/src/lib/render/deferred.d.ts.map +1 -1
  101. package/dist/src/lib/render/deferred.js +8 -8
  102. package/dist/src/lib/render/deferred.mjs +158 -1
  103. package/dist/src/lib/render/index.cjs +573 -1
  104. package/dist/src/lib/render/index.d.ts +3 -17
  105. package/dist/src/lib/render/index.d.ts.map +1 -1
  106. package/dist/src/lib/render/index.js +12 -26
  107. package/dist/src/lib/render/index.mjs +590 -1
  108. package/dist/src/lib/render/lazy.cjs +67 -1
  109. package/dist/src/lib/render/lazy.d.ts +22 -1
  110. package/dist/src/lib/render/lazy.d.ts.map +1 -1
  111. package/dist/src/lib/render/lazy.js +47 -8
  112. package/dist/src/lib/render/lazy.mjs +50 -1
  113. package/dist/src/lib/render/suspense.cjs +141 -1
  114. package/dist/src/lib/render/suspense.d.ts +40 -0
  115. package/dist/src/lib/render/suspense.d.ts.map +1 -1
  116. package/dist/src/lib/render/suspense.js +47 -7
  117. package/dist/src/lib/render/suspense.mjs +136 -1
  118. package/dist/src/lib/render/versions.cjs +35 -1
  119. package/dist/src/lib/render/versions.js +6 -6
  120. package/dist/src/lib/render/versions.mjs +14 -1
  121. package/dist/src/lib/router/data.cjs +230 -1
  122. package/dist/src/lib/router/data.d.ts +1 -13
  123. package/dist/src/lib/router/data.d.ts.map +1 -1
  124. package/dist/src/lib/router/data.js +1 -13
  125. package/dist/src/lib/router/data.mjs +214 -1
  126. package/dist/src/lib/router/index.cjs +627 -1
  127. package/dist/src/lib/router/index.d.ts +62 -10
  128. package/dist/src/lib/router/index.d.ts.map +1 -1
  129. package/dist/src/lib/router/index.js +90 -39
  130. package/dist/src/lib/router/index.mjs +639 -1
  131. package/dist/src/lib/server/hydration.cjs +169 -1
  132. package/dist/src/lib/server/hydration.d.ts +15 -55
  133. package/dist/src/lib/server/hydration.d.ts.map +1 -1
  134. package/dist/src/lib/server/hydration.js +23 -62
  135. package/dist/src/lib/server/hydration.mjs +148 -1
  136. package/dist/src/lib/server/index.cjs +401 -11
  137. package/dist/src/lib/server/index.d.ts +30 -6
  138. package/dist/src/lib/server/index.d.ts.map +1 -1
  139. package/dist/src/lib/server/index.js +34 -11
  140. package/dist/src/lib/server/index.mjs +379 -11
  141. package/dist/src/lib/server/reactive.cjs +197 -1
  142. package/dist/src/lib/server/reactive.d.ts +18 -77
  143. package/dist/src/lib/server/reactive.d.ts.map +1 -1
  144. package/dist/src/lib/server/reactive.js +19 -78
  145. package/dist/src/lib/server/reactive.mjs +176 -1
  146. package/dist/src/lib/theme/index.cjs +110 -1
  147. package/dist/src/lib/theme/index.d.ts +19 -4
  148. package/dist/src/lib/theme/index.d.ts.map +1 -1
  149. package/dist/src/lib/theme/index.js +17 -2
  150. package/dist/src/lib/theme/index.mjs +89 -1
  151. package/dist/src/lib/utils/index.cjs +209 -1
  152. package/dist/src/lib/utils/index.d.ts +0 -93
  153. package/dist/src/lib/utils/index.d.ts.map +1 -1
  154. package/dist/src/lib/utils/index.js +0 -93
  155. package/dist/src/lib/utils/index.mjs +188 -1
  156. package/dist/src/routes.cjs +37 -1
  157. package/dist/src/routes.d.ts +1 -1
  158. package/dist/src/routes.js +2 -2
  159. package/dist/src/routes.mjs +17 -1
  160. package/dist/src/server.cjs +400 -11
  161. package/dist/src/server.d.ts +0 -1
  162. package/dist/src/server.d.ts.map +1 -1
  163. package/dist/src/server.js +0 -1
  164. package/dist/src/server.mjs +377 -11
  165. package/dist/src/utils.cjs +21 -1
  166. package/dist/src/utils.d.ts +1 -1
  167. package/dist/src/utils.js +1 -1
  168. package/dist/src/utils.mjs +4 -1
  169. package/dist/src/version.generated.cjs +26 -1
  170. package/dist/src/version.generated.d.ts +1 -1
  171. package/dist/src/version.generated.js +2 -2
  172. package/dist/src/version.generated.mjs +5 -1
  173. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  174. package/package.json +17 -16
  175. package/src/index.ts +2 -14
  176. package/dist/src/cdn/chunk-RN7C7HNS.mjs +0 -1
  177. package/dist/src/cdn/router-QB3W43UQ.mjs +0 -1
  178. package/dist/src/lib/client/chunk-FT22BLCQ.mjs +0 -1
  179. package/dist/src/lib/client/router-IH7JYMRU.mjs +0 -1
@@ -1 +1,169 @@
1
- "use strict";var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var w=(t,n)=>{for(var e in n)a(t,e,{get:n[e],enumerable:!0})},x=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of g(n))!m.call(t,o)&&o!==e&&a(t,o,{get:()=>n[o],enumerable:!(r=l(n,o))||r.enumerable});return t};var h=t=>x(a({},"__esModule",{value:!0}),t);var F={};w(F,{cleanupHydration:()=>y,clearHydrationData:()=>p,clearHydrationDataKey:()=>D,createHydratableResource:()=>M,deserializeHydrationData:()=>b,generateMarkerID:()=>v,getHydrationData:()=>s,hasHydrationData:()=>_,hydrationMarker:()=>E,hydrationMarkerEnd:()=>O,hydrationMarkerStart:()=>N,isClientEnvironment:()=>C,isHydrating:()=>f,isServerEnvironment:()=>k,serializeHydrationData:()=>I,setHydrating:()=>T,setHydrationData:()=>d,useHydrationData:()=>j});module.exports=h(F);var c=!1,i=new Map,H=0;function f(){return c}function T(t){c=t}function d(t,n){i.set(t,n)}function s(t){return i.get(t)}function _(t){return i.has(t)}function p(){i.clear()}function D(t){i.delete(t)}function I(){if(i.size===0)return"";let t=Object.fromEntries(i);return`<script type="application/json" id="__FLUIXI_HYDRATION__">${JSON.stringify(t)}<\/script>`}function b(){if(typeof window>"u")return!1;let t=document.getElementById("__FLUIXI_HYDRATION__");if(!t||t.getAttribute("type")!=="application/json")return!1;try{let n=t.textContent||"{}",e=JSON.parse(n);for(let[r,o]of Object.entries(e))i.set(r,o);return!0}catch(n){return console.error("Failed to deserialize hydration data:",n),!1}}function v(){return`h${H++}`}function E(t){return`<!--#${t}-->`}function N(t){return`<!--#${t}-->`}function O(t){return`<!--/${t}-->`}function M(t,n){return async()=>{if(f()||typeof window<"u"){let r=s(t);if(r!==void 0)return r}let e=await n();return typeof window>"u"&&d(t,e),e}}function j(t,n){let e=s(t);if(e!==void 0)return e;let r=typeof n=="function"?n():n;return typeof window>"u"&&d(t,r),r}function y(){if(typeof window>"u")return;let t=document.getElementById("__FLUIXI_HYDRATION__");t&&t.remove();let n=document.createTreeWalker(document.body,NodeFilter.SHOW_COMMENT,null),e=[],r;for(;r=n.nextNode();){let o=r,u=o.nodeValue||"";(u.startsWith("#")||u.startsWith("/"))&&e.push(o)}e.forEach(o=>o.remove()),p()}typeof window<"u"&&window.addEventListener("load",()=>{setTimeout(y,100)});function k(){return typeof window>"u"}function C(){return typeof window<"u"}
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/server/hydration.ts
21
+ var hydration_exports = {};
22
+ __export(hydration_exports, {
23
+ cleanupHydration: () => cleanupHydration,
24
+ clearHydrationData: () => clearHydrationData,
25
+ clearHydrationDataKey: () => clearHydrationDataKey,
26
+ createHydratableResource: () => createHydratableResource,
27
+ deserializeHydrationData: () => deserializeHydrationData,
28
+ generateMarkerID: () => generateMarkerID,
29
+ getHydrationData: () => getHydrationData,
30
+ hasHydrationData: () => hasHydrationData,
31
+ hydrationMarker: () => hydrationMarker,
32
+ hydrationMarkerEnd: () => hydrationMarkerEnd,
33
+ hydrationMarkerStart: () => hydrationMarkerStart,
34
+ isClientEnvironment: () => isClientEnvironment,
35
+ isHydrating: () => isHydrating,
36
+ isServerEnvironment: () => isServerEnvironment,
37
+ serializeHydrationData: () => serializeHydrationData,
38
+ setHydrating: () => setHydrating,
39
+ setHydrationData: () => setHydrationData,
40
+ useHydrationData: () => useHydrationData
41
+ });
42
+ module.exports = __toCommonJS(hydration_exports);
43
+ var import_dom = require("@fluixi/dom");
44
+ var hydrating = false;
45
+ var hydrationDataMap = /* @__PURE__ */ new Map();
46
+ var markerCounter = 0;
47
+ function isHydrating() {
48
+ return hydrating;
49
+ }
50
+ function setHydrating(state) {
51
+ hydrating = state;
52
+ }
53
+ function setHydrationData(key, data) {
54
+ hydrationDataMap.set(key, data);
55
+ }
56
+ function getHydrationData(key) {
57
+ return hydrationDataMap.get(key);
58
+ }
59
+ function hasHydrationData(key) {
60
+ return hydrationDataMap.has(key);
61
+ }
62
+ function clearHydrationData() {
63
+ hydrationDataMap.clear();
64
+ }
65
+ function clearHydrationDataKey(key) {
66
+ hydrationDataMap.delete(key);
67
+ }
68
+ function serializeHydrationData() {
69
+ if (hydrationDataMap.size === 0) {
70
+ return "";
71
+ }
72
+ const data = Object.fromEntries(hydrationDataMap);
73
+ const json = JSON.stringify(data);
74
+ return `<script type="application/json" id="__FLUIXI_HYDRATION__">${json}<\/script>`;
75
+ }
76
+ function deserializeHydrationData() {
77
+ if (typeof window === "undefined") {
78
+ return false;
79
+ }
80
+ const script = document.getElementById("__FLUIXI_HYDRATION__");
81
+ if (!script || script.getAttribute("type") !== "application/json") {
82
+ return false;
83
+ }
84
+ try {
85
+ const json = script.textContent || "{}";
86
+ const data = JSON.parse(json);
87
+ for (const [key, value] of Object.entries(data)) {
88
+ hydrationDataMap.set(key, value);
89
+ }
90
+ return true;
91
+ } catch (error) {
92
+ console.error("Failed to deserialize hydration data:", error);
93
+ return false;
94
+ }
95
+ }
96
+ function generateMarkerID() {
97
+ return `h${markerCounter++}`;
98
+ }
99
+ function hydrationMarker(id) {
100
+ return `<!--#${id}-->`;
101
+ }
102
+ function hydrationMarkerStart(id) {
103
+ return `<!--#${id}-->`;
104
+ }
105
+ function hydrationMarkerEnd(id) {
106
+ return `<!--/${id}-->`;
107
+ }
108
+ function createHydratableResource(key, fetcher) {
109
+ return async () => {
110
+ if (isHydrating() || typeof window !== "undefined") {
111
+ const cached = getHydrationData(key);
112
+ if (cached !== void 0) {
113
+ return cached;
114
+ }
115
+ }
116
+ const data = await fetcher();
117
+ if (typeof window === "undefined") {
118
+ setHydrationData(key, data);
119
+ }
120
+ return data;
121
+ };
122
+ }
123
+ function useHydrationData(key, value) {
124
+ const hydrationData = getHydrationData(key);
125
+ if (hydrationData !== void 0) {
126
+ return hydrationData;
127
+ }
128
+ const computedValue = typeof value === "function" ? value() : value;
129
+ if (typeof window === "undefined") {
130
+ setHydrationData(key, computedValue);
131
+ }
132
+ return computedValue;
133
+ }
134
+ function cleanupHydration() {
135
+ if (typeof window === "undefined") {
136
+ return;
137
+ }
138
+ const script = document.getElementById("__FLUIXI_HYDRATION__");
139
+ if (script) {
140
+ script.remove();
141
+ }
142
+ const walker = document.createTreeWalker(
143
+ document.body,
144
+ NodeFilter.SHOW_COMMENT,
145
+ null
146
+ );
147
+ const comments = [];
148
+ let node;
149
+ while (node = walker.nextNode()) {
150
+ const comment = node;
151
+ const text = comment.nodeValue || "";
152
+ if (text.startsWith("#") || text.startsWith("/")) {
153
+ comments.push(comment);
154
+ }
155
+ }
156
+ comments.forEach((comment) => comment.remove());
157
+ clearHydrationData();
158
+ }
159
+ if (typeof window !== "undefined") {
160
+ window.addEventListener("load", () => {
161
+ setTimeout(cleanupHydration, 100);
162
+ });
163
+ }
164
+ function isServerEnvironment() {
165
+ return (0, import_dom.isServer)();
166
+ }
167
+ function isClientEnvironment() {
168
+ return !(0, import_dom.isServer)();
169
+ }
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @fileoverview Hydration utilities for Fluixi
3
2
  * @module @fluixi/core/server/hydration
4
3
  *
5
4
  * Hydration:
@@ -17,9 +16,7 @@ export interface HydrationData {
17
16
  /**
18
17
  * Check if currently hydrating
19
18
  *
20
- * Section 11: During hydration, DOM is reused, not recreated
21
- *
22
- * @returns {boolean} True if hydrating
19
+ * During hydration, DOM is reused, not recreated
23
20
  *
24
21
  * @example
25
22
  * ```typescript
@@ -34,19 +31,15 @@ export declare function isHydrating(): boolean;
34
31
  /**
35
32
  * Set hydration state
36
33
  *
37
- * @param {boolean} state - Hydration state
38
34
  * @internal
39
35
  */
40
36
  export declare function setHydrating(state: boolean): void;
41
37
  /**
42
38
  * Store data for hydration
43
39
  *
44
- * Section 11: On server, store data to serialize into HTML
40
+ * On server, store data to serialize into HTML
45
41
  * On client during hydration, this data is reused
46
42
  *
47
- * @param {string} key - Unique key
48
- * @param {any} data - Data to store
49
- *
50
43
  * @example
51
44
  * ```typescript
52
45
  * import { setHydrationData } from '@fluixi/core/server';
@@ -59,10 +52,7 @@ export declare function setHydrationData(key: string, data: any): void;
59
52
  /**
60
53
  * Get hydration data
61
54
  *
62
- * Section 11: On client, retrieve data stored on server
63
- *
64
- * @param {string} key - Unique key
65
- * @returns {any} Data or undefined
55
+ * On client, retrieve data stored on server
66
56
  *
67
57
  * @example
68
58
  * ```typescript
@@ -75,9 +65,6 @@ export declare function setHydrationData(key: string, data: any): void;
75
65
  export declare function getHydrationData(key: string): any;
76
66
  /**
77
67
  * Check if hydration data exists
78
- *
79
- * @param {string} key - Unique key
80
- * @returns {boolean} True if exists
81
68
  */
82
69
  export declare function hasHydrationData(key: string): boolean;
83
70
  /**
@@ -88,16 +75,12 @@ export declare function hasHydrationData(key: string): boolean;
88
75
  export declare function clearHydrationData(): void;
89
76
  /**
90
77
  * Clear specific hydration data
91
- *
92
- * @param {string} key - Key to clear
93
78
  */
94
79
  export declare function clearHydrationDataKey(key: string): void;
95
80
  /**
96
81
  * Serialize hydration data to script tag
97
82
  *
98
- * Section 11: Embed data in HTML for client hydration
99
- *
100
- * @returns {string} Script tag with JSON data
83
+ * Embed data in HTML for client hydration
101
84
  *
102
85
  * @example
103
86
  * ```typescript
@@ -112,9 +95,7 @@ export declare function serializeHydrationData(): string;
112
95
  /**
113
96
  * Deserialize hydration data from DOM
114
97
  *
115
- * Section 11: On client, load data from script tag
116
- *
117
- * @returns {boolean} True if data was loaded
98
+ * On client, load data from script tag
118
99
  *
119
100
  * @example
120
101
  * ```typescript
@@ -130,17 +111,13 @@ export declare function deserializeHydrationData(): boolean;
130
111
  /**
131
112
  * Generate unique hydration marker ID
132
113
  *
133
- * @returns {string} Unique marker ID
134
114
  * @internal
135
115
  */
136
116
  export declare function generateMarkerID(): string;
137
117
  /**
138
118
  * Create hydration marker
139
119
  *
140
- * Section 11: Structural markers required for hydration points
141
- *
142
- * @param {string} id - Marker ID
143
- * @returns {string} HTML comment marker
120
+ * Structural markers required for hydration points
144
121
  *
145
122
  * @example
146
123
  * ```typescript
@@ -153,29 +130,18 @@ export declare function generateMarkerID(): string;
153
130
  export declare function hydrationMarker(id: string): string;
154
131
  /**
155
132
  * Create start hydration marker
156
- *
157
- * @param {string} id - Marker ID
158
- * @returns {string} Start marker
159
133
  */
160
134
  export declare function hydrationMarkerStart(id: string): string;
161
135
  /**
162
136
  * Create end hydration marker
163
- *
164
- * @param {string} id - Marker ID
165
- * @returns {string} End marker
166
137
  */
167
138
  export declare function hydrationMarkerEnd(id: string): string;
168
139
  /**
169
140
  * Create hydration-friendly resource
170
141
  *
171
- * Section 11: Resources loaded on server are serialized
142
+ * Resources loaded on server are serialized
172
143
  * On client, reused during hydration (no re-fetch)
173
144
  *
174
- * @template T
175
- * @param {string} key - Unique resource key
176
- * @param {() => Promise<T>} fetcher - Resource fetcher
177
- * @returns {() => Promise<T>} Hydration-aware fetcher
178
- *
179
145
  * @example
180
146
  * ```typescript
181
147
  * import { createHydratableResource } from '@fluixi/core/server';
@@ -190,14 +156,9 @@ export declare function createHydratableResource<T>(key: string, fetcher: () =>
190
156
  /**
191
157
  * Use hydration data in component
192
158
  *
193
- * Section 11: Components use hydration data to restore state
159
+ * Components use hydration data to restore state
194
160
  * without re-execution
195
161
  *
196
- * @template T
197
- * @param {string} key - Data key
198
- * @param {T | (() => T)} value - Value or getter
199
- * @returns {T} Value
200
- *
201
162
  * @example
202
163
  * ```typescript
203
164
  * import { useHydrationData } from '@fluixi/core/server';
@@ -212,7 +173,7 @@ export declare function useHydrationData<T>(key: string, value: T | (() => T)):
212
173
  /**
213
174
  * Cleanup hydration artifacts from DOM
214
175
  *
215
- * Section 11: After hydration, remove markers and serialized data
176
+ * After hydration, remove markers and serialized data
216
177
  *
217
178
  * @example
218
179
  * ```typescript
@@ -224,15 +185,14 @@ export declare function useHydrationData<T>(key: string, value: T | (() => T)):
224
185
  */
225
186
  export declare function cleanupHydration(): void;
226
187
  /**
227
- * Check if on server
188
+ * Whether this is a server render.
228
189
  *
229
- * @returns {boolean} True if server
190
+ * Defers to `@fluixi/dom`, which keeps the flag on a realm singleton that
191
+ * `renderToString` sets. A local `typeof window` test disagrees with it inside a jsdom
192
+ * process, which is where server rendering is usually tested, and `router/data.ts`
193
+ * branches on this to decide whether a loader may touch the client.
230
194
  */
231
195
  export declare function isServerEnvironment(): boolean;
232
- /**
233
- * Check if on client
234
- *
235
- * @returns {boolean} True if client
236
- */
196
+ /** Whether this is running in a browser, the negation of a server render. */
237
197
  export declare function isClientEnvironment(): boolean;
238
198
  //# sourceMappingURL=hydration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hydration.d.ts","sourceRoot":"","sources":["../../../../src/lib/server/hydration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AA2BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAEjD;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI,CAE7D;AAED;;;;;;;;;;;;;;;GAeG;AACH,w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ACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACxB,MAAM,OAAO,CAAC,CAAC,CAAC,CAoBlB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAiBxE;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAiCvC;AAgBD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C;AAED,6EAA6E;AAC7E,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C"}
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @fileoverview Hydration utilities for Fluixi
3
2
  * @module @fluixi/core/server/hydration
4
3
  *
5
4
  * Hydration:
@@ -8,12 +7,13 @@
8
7
  * - Bindings reattached
9
8
  * - Structural markers required
10
9
  */
10
+ import { isServer as domIsServer } from '@fluixi/dom';
11
11
  // ============================================================================
12
12
  // STATE
13
13
  // ============================================================================
14
14
  /**
15
15
  * Global hydration flag
16
- * Section 11: Indicates if we're currently hydrating
16
+ * Indicates if we're currently hydrating
17
17
  */
18
18
  let hydrating = false;
19
19
  /**
@@ -31,9 +31,7 @@ let markerCounter = 0;
31
31
  /**
32
32
  * Check if currently hydrating
33
33
  *
34
- * Section 11: During hydration, DOM is reused, not recreated
35
- *
36
- * @returns {boolean} True if hydrating
34
+ * During hydration, DOM is reused, not recreated
37
35
  *
38
36
  * @example
39
37
  * ```typescript
@@ -50,7 +48,6 @@ export function isHydrating() {
50
48
  /**
51
49
  * Set hydration state
52
50
  *
53
- * @param {boolean} state - Hydration state
54
51
  * @internal
55
52
  */
56
53
  export function setHydrating(state) {
@@ -62,12 +59,9 @@ export function setHydrating(state) {
62
59
  /**
63
60
  * Store data for hydration
64
61
  *
65
- * Section 11: On server, store data to serialize into HTML
62
+ * On server, store data to serialize into HTML
66
63
  * On client during hydration, this data is reused
67
64
  *
68
- * @param {string} key - Unique key
69
- * @param {any} data - Data to store
70
- *
71
65
  * @example
72
66
  * ```typescript
73
67
  * import { setHydrationData } from '@fluixi/core/server';
@@ -82,10 +76,7 @@ export function setHydrationData(key, data) {
82
76
  /**
83
77
  * Get hydration data
84
78
  *
85
- * Section 11: On client, retrieve data stored on server
86
- *
87
- * @param {string} key - Unique key
88
- * @returns {any} Data or undefined
79
+ * On client, retrieve data stored on server
89
80
  *
90
81
  * @example
91
82
  * ```typescript
@@ -100,9 +91,6 @@ export function getHydrationData(key) {
100
91
  }
101
92
  /**
102
93
  * Check if hydration data exists
103
- *
104
- * @param {string} key - Unique key
105
- * @returns {boolean} True if exists
106
94
  */
107
95
  export function hasHydrationData(key) {
108
96
  return hydrationDataMap.has(key);
@@ -117,8 +105,6 @@ export function clearHydrationData() {
117
105
  }
118
106
  /**
119
107
  * Clear specific hydration data
120
- *
121
- * @param {string} key - Key to clear
122
108
  */
123
109
  export function clearHydrationDataKey(key) {
124
110
  hydrationDataMap.delete(key);
@@ -129,9 +115,7 @@ export function clearHydrationDataKey(key) {
129
115
  /**
130
116
  * Serialize hydration data to script tag
131
117
  *
132
- * Section 11: Embed data in HTML for client hydration
133
- *
134
- * @returns {string} Script tag with JSON data
118
+ * Embed data in HTML for client hydration
135
119
  *
136
120
  * @example
137
121
  * ```typescript
@@ -153,9 +137,7 @@ export function serializeHydrationData() {
153
137
  /**
154
138
  * Deserialize hydration data from DOM
155
139
  *
156
- * Section 11: On client, load data from script tag
157
- *
158
- * @returns {boolean} True if data was loaded
140
+ * On client, load data from script tag
159
141
  *
160
142
  * @example
161
143
  * ```typescript
@@ -194,7 +176,6 @@ export function deserializeHydrationData() {
194
176
  /**
195
177
  * Generate unique hydration marker ID
196
178
  *
197
- * @returns {string} Unique marker ID
198
179
  * @internal
199
180
  */
200
181
  export function generateMarkerID() {
@@ -203,10 +184,7 @@ export function generateMarkerID() {
203
184
  /**
204
185
  * Create hydration marker
205
186
  *
206
- * Section 11: Structural markers required for hydration points
207
- *
208
- * @param {string} id - Marker ID
209
- * @returns {string} HTML comment marker
187
+ * Structural markers required for hydration points
210
188
  *
211
189
  * @example
212
190
  * ```typescript
@@ -221,18 +199,12 @@ export function hydrationMarker(id) {
221
199
  }
222
200
  /**
223
201
  * Create start hydration marker
224
- *
225
- * @param {string} id - Marker ID
226
- * @returns {string} Start marker
227
202
  */
228
203
  export function hydrationMarkerStart(id) {
229
204
  return `<!--#${id}-->`;
230
205
  }
231
206
  /**
232
207
  * Create end hydration marker
233
- *
234
- * @param {string} id - Marker ID
235
- * @returns {string} End marker
236
208
  */
237
209
  export function hydrationMarkerEnd(id) {
238
210
  return `<!--/${id}-->`;
@@ -243,14 +215,9 @@ export function hydrationMarkerEnd(id) {
243
215
  /**
244
216
  * Create hydration-friendly resource
245
217
  *
246
- * Section 11: Resources loaded on server are serialized
218
+ * Resources loaded on server are serialized
247
219
  * On client, reused during hydration (no re-fetch)
248
220
  *
249
- * @template T
250
- * @param {string} key - Unique resource key
251
- * @param {() => Promise<T>} fetcher - Resource fetcher
252
- * @returns {() => Promise<T>} Hydration-aware fetcher
253
- *
254
221
  * @example
255
222
  * ```typescript
256
223
  * import { createHydratableResource } from '@fluixi/core/server';
@@ -263,7 +230,7 @@ export function hydrationMarkerEnd(id) {
263
230
  */
264
231
  export function createHydratableResource(key, fetcher) {
265
232
  return async () => {
266
- // Section 11: During hydration or on client, check for cached data
233
+ // During hydration or on client, check for cached data
267
234
  if (isHydrating() || typeof window !== 'undefined') {
268
235
  const cached = getHydrationData(key);
269
236
  if (cached !== undefined) {
@@ -272,7 +239,7 @@ export function createHydratableResource(key, fetcher) {
272
239
  }
273
240
  // Server or no cache: fetch data
274
241
  const data = await fetcher();
275
- // Section 11: On server, store for serialization
242
+ // On server, store for serialization
276
243
  if (typeof window === 'undefined') {
277
244
  setHydrationData(key, data);
278
245
  }
@@ -282,14 +249,9 @@ export function createHydratableResource(key, fetcher) {
282
249
  /**
283
250
  * Use hydration data in component
284
251
  *
285
- * Section 11: Components use hydration data to restore state
252
+ * Components use hydration data to restore state
286
253
  * without re-execution
287
254
  *
288
- * @template T
289
- * @param {string} key - Data key
290
- * @param {T | (() => T)} value - Value or getter
291
- * @returns {T} Value
292
- *
293
255
  * @example
294
256
  * ```typescript
295
257
  * import { useHydrationData } from '@fluixi/core/server';
@@ -301,14 +263,14 @@ export function createHydratableResource(key, fetcher) {
301
263
  * ```
302
264
  */
303
265
  export function useHydrationData(key, value) {
304
- // Section 11: Check for hydration data first
266
+ // Check for hydration data first
305
267
  const hydrationData = getHydrationData(key);
306
268
  if (hydrationData !== undefined) {
307
269
  return hydrationData;
308
270
  }
309
271
  // Compute or use provided value
310
272
  const computedValue = typeof value === 'function' ? value() : value;
311
- // Section 11: On server, store for serialization
273
+ // On server, store for serialization
312
274
  if (typeof window === 'undefined') {
313
275
  setHydrationData(key, computedValue);
314
276
  }
@@ -320,7 +282,7 @@ export function useHydrationData(key, value) {
320
282
  /**
321
283
  * Cleanup hydration artifacts from DOM
322
284
  *
323
- * Section 11: After hydration, remove markers and serialized data
285
+ * After hydration, remove markers and serialized data
324
286
  *
325
287
  * @example
326
288
  * ```typescript
@@ -367,18 +329,17 @@ if (typeof window !== 'undefined') {
367
329
  // ENVIRONMENT HELPERS
368
330
  // ============================================================================
369
331
  /**
370
- * Check if on server
332
+ * Whether this is a server render.
371
333
  *
372
- * @returns {boolean} True if server
334
+ * Defers to `@fluixi/dom`, which keeps the flag on a realm singleton that
335
+ * `renderToString` sets. A local `typeof window` test disagrees with it inside a jsdom
336
+ * process, which is where server rendering is usually tested, and `router/data.ts`
337
+ * branches on this to decide whether a loader may touch the client.
373
338
  */
374
339
  export function isServerEnvironment() {
375
- return typeof window === 'undefined';
340
+ return domIsServer();
376
341
  }
377
- /**
378
- * Check if on client
379
- *
380
- * @returns {boolean} True if client
381
- */
342
+ /** Whether this is running in a browser, the negation of a server render. */
382
343
  export function isClientEnvironment() {
383
- return typeof window !== 'undefined';
344
+ return !domIsServer();
384
345
  }