@fluixi/core 1.0.0-alpha.53

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 (198) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +611 -0
  3. package/dist/cdn/core.global.js +3 -0
  4. package/dist/cli/generate.cjs +1814 -0
  5. package/dist/cli/generate.d.ts +7 -0
  6. package/dist/cli/generate.d.ts.map +1 -0
  7. package/dist/cli/generate.js +2580 -0
  8. package/dist/cli/generate.mjs +1814 -0
  9. package/dist/cli/index.cjs +1814 -0
  10. package/dist/cli/index.d.ts +7 -0
  11. package/dist/cli/index.d.ts.map +1 -0
  12. package/dist/cli/index.js +2580 -0
  13. package/dist/cli/index.mjs +1814 -0
  14. package/dist/cli/run.cjs +2 -0
  15. package/dist/cli/run.d.ts +3 -0
  16. package/dist/cli/run.d.ts.map +1 -0
  17. package/dist/cli/run.js +62 -0
  18. package/dist/cli/run.mjs +2 -0
  19. package/dist/fluixi.d.ts +5 -0
  20. package/dist/src/cdn/chunk-PFM5O5UE.mjs +1 -0
  21. package/dist/src/cdn/core.cjs +1 -0
  22. package/dist/src/cdn/core.d.ts +16 -0
  23. package/dist/src/cdn/core.d.ts.map +1 -0
  24. package/dist/src/cdn/core.js +15 -0
  25. package/dist/src/cdn/core.mjs +1 -0
  26. package/dist/src/cdn/router-next-WNWCFVC2.mjs +1 -0
  27. package/dist/src/index.cjs +1 -0
  28. package/dist/src/index.d.ts +7 -0
  29. package/dist/src/index.d.ts.map +1 -0
  30. package/dist/src/index.js +26 -0
  31. package/dist/src/index.mjs +1 -0
  32. package/dist/src/jsx-dev-runtime.cjs +1 -0
  33. package/dist/src/jsx-dev-runtime.d.ts +2 -0
  34. package/dist/src/jsx-dev-runtime.d.ts.map +1 -0
  35. package/dist/src/jsx-dev-runtime.js +1 -0
  36. package/dist/src/jsx-dev-runtime.mjs +1 -0
  37. package/dist/src/jsx-runtime.cjs +1 -0
  38. package/dist/src/jsx-runtime.d.ts +7 -0
  39. package/dist/src/jsx-runtime.d.ts.map +1 -0
  40. package/dist/src/jsx-runtime.js +17 -0
  41. package/dist/src/jsx-runtime.mjs +1 -0
  42. package/dist/src/lib/client/chunk-D3VTWVNJ.mjs +1 -0
  43. package/dist/src/lib/client/index.cjs +1 -0
  44. package/dist/src/lib/client/index.d.ts +54 -0
  45. package/dist/src/lib/client/index.d.ts.map +1 -0
  46. package/dist/src/lib/client/index.js +142 -0
  47. package/dist/src/lib/client/index.mjs +1 -0
  48. package/dist/src/lib/client/router-next-UYIYMRJL.mjs +1 -0
  49. package/dist/src/lib/context/context.cjs +1 -0
  50. package/dist/src/lib/context/context.d.ts +337 -0
  51. package/dist/src/lib/context/context.d.ts.map +1 -0
  52. package/dist/src/lib/context/context.js +462 -0
  53. package/dist/src/lib/context/context.mjs +1 -0
  54. package/dist/src/lib/context/index.cjs +1 -0
  55. package/dist/src/lib/context/index.d.ts +3 -0
  56. package/dist/src/lib/context/index.d.ts.map +1 -0
  57. package/dist/src/lib/context/index.js +5 -0
  58. package/dist/src/lib/context/index.mjs +1 -0
  59. package/dist/src/lib/control-flow.cjs +1 -0
  60. package/dist/src/lib/control-flow.d.ts +4 -0
  61. package/dist/src/lib/control-flow.d.ts.map +1 -0
  62. package/dist/src/lib/control-flow.js +1 -0
  63. package/dist/src/lib/control-flow.mjs +1 -0
  64. package/dist/src/lib/core.cjs +1 -0
  65. package/dist/src/lib/core.d.ts +90 -0
  66. package/dist/src/lib/core.d.ts.map +1 -0
  67. package/dist/src/lib/core.js +181 -0
  68. package/dist/src/lib/core.mjs +1 -0
  69. package/dist/src/lib/directives/lit.cjs +1 -0
  70. package/dist/src/lib/directives/lit.d.ts +2 -0
  71. package/dist/src/lib/directives/lit.d.ts.map +1 -0
  72. package/dist/src/lib/directives/lit.js +31 -0
  73. package/dist/src/lib/directives/lit.mjs +0 -0
  74. package/dist/src/lib/env/index.cjs +1 -0
  75. package/dist/src/lib/env/index.d.ts +39 -0
  76. package/dist/src/lib/env/index.d.ts.map +1 -0
  77. package/dist/src/lib/env/index.js +50 -0
  78. package/dist/src/lib/env/index.mjs +1 -0
  79. package/dist/src/lib/i18n/index.cjs +1 -0
  80. package/dist/src/lib/i18n/index.d.ts +79 -0
  81. package/dist/src/lib/i18n/index.d.ts.map +1 -0
  82. package/dist/src/lib/i18n/index.js +127 -0
  83. package/dist/src/lib/i18n/index.mjs +1 -0
  84. package/dist/src/lib/index.cjs +1 -0
  85. package/dist/src/lib/index.d.ts +83 -0
  86. package/dist/src/lib/index.d.ts.map +1 -0
  87. package/dist/src/lib/index.js +147 -0
  88. package/dist/src/lib/index.mjs +1 -0
  89. package/dist/src/lib/isomorphic.cjs +1 -0
  90. package/dist/src/lib/isomorphic.d.ts +69 -0
  91. package/dist/src/lib/isomorphic.d.ts.map +1 -0
  92. package/dist/src/lib/isomorphic.js +92 -0
  93. package/dist/src/lib/isomorphic.mjs +1 -0
  94. package/dist/src/lib/jsx-runtime/index.cjs +1 -0
  95. package/dist/src/lib/jsx-runtime/index.d.ts +13 -0
  96. package/dist/src/lib/jsx-runtime/index.d.ts.map +1 -0
  97. package/dist/src/lib/jsx-runtime/index.js +23 -0
  98. package/dist/src/lib/jsx-runtime/index.mjs +1 -0
  99. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +1 -0
  100. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts +2 -0
  101. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts.map +1 -0
  102. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.js +1 -0
  103. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +1 -0
  104. package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +13 -0
  105. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +21 -0
  106. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -0
  107. package/dist/src/lib/plugins/fluixi-routes-plugin.js +102 -0
  108. package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +13 -0
  109. package/dist/src/lib/plugins/index.cjs +13 -0
  110. package/dist/src/lib/plugins/index.d.ts +4 -0
  111. package/dist/src/lib/plugins/index.d.ts.map +1 -0
  112. package/dist/src/lib/plugins/index.js +3 -0
  113. package/dist/src/lib/plugins/index.mjs +13 -0
  114. package/dist/src/lib/plugins/route-codegen.cjs +8 -0
  115. package/dist/src/lib/plugins/route-codegen.d.ts +13 -0
  116. package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -0
  117. package/dist/src/lib/plugins/route-codegen.js +81 -0
  118. package/dist/src/lib/plugins/route-codegen.mjs +8 -0
  119. package/dist/src/lib/plugins/route-scanner.cjs +1 -0
  120. package/dist/src/lib/plugins/route-scanner.d.ts +39 -0
  121. package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -0
  122. package/dist/src/lib/plugins/route-scanner.js +216 -0
  123. package/dist/src/lib/plugins/route-scanner.mjs +1 -0
  124. package/dist/src/lib/plugins/vite.cjs +1 -0
  125. package/dist/src/lib/plugins/vite.d.ts +3 -0
  126. package/dist/src/lib/plugins/vite.d.ts.map +1 -0
  127. package/dist/src/lib/plugins/vite.js +1 -0
  128. package/dist/src/lib/plugins/vite.mjs +1 -0
  129. package/dist/src/lib/render/component.cjs +1 -0
  130. package/dist/src/lib/render/component.d.ts +328 -0
  131. package/dist/src/lib/render/component.d.ts.map +1 -0
  132. package/dist/src/lib/render/component.js +520 -0
  133. package/dist/src/lib/render/component.mjs +1 -0
  134. package/dist/src/lib/render/index.cjs +1 -0
  135. package/dist/src/lib/render/index.d.ts +113 -0
  136. package/dist/src/lib/render/index.d.ts.map +1 -0
  137. package/dist/src/lib/render/index.js +201 -0
  138. package/dist/src/lib/render/index.mjs +1 -0
  139. package/dist/src/lib/render/lazy.cjs +1 -0
  140. package/dist/src/lib/render/lazy.d.ts +28 -0
  141. package/dist/src/lib/render/lazy.d.ts.map +1 -0
  142. package/dist/src/lib/render/lazy.js +62 -0
  143. package/dist/src/lib/render/lazy.mjs +1 -0
  144. package/dist/src/lib/render/suspense.cjs +1 -0
  145. package/dist/src/lib/render/suspense.d.ts +25 -0
  146. package/dist/src/lib/render/suspense.d.ts.map +1 -0
  147. package/dist/src/lib/render/suspense.js +139 -0
  148. package/dist/src/lib/render/suspense.mjs +1 -0
  149. package/dist/src/lib/router-next/data.cjs +1 -0
  150. package/dist/src/lib/router-next/data.d.ts +101 -0
  151. package/dist/src/lib/router-next/data.d.ts.map +1 -0
  152. package/dist/src/lib/router-next/data.js +179 -0
  153. package/dist/src/lib/router-next/data.mjs +1 -0
  154. package/dist/src/lib/router-next/index.cjs +1 -0
  155. package/dist/src/lib/router-next/index.d.ts +156 -0
  156. package/dist/src/lib/router-next/index.d.ts.map +1 -0
  157. package/dist/src/lib/router-next/index.js +464 -0
  158. package/dist/src/lib/router-next/index.mjs +1 -0
  159. package/dist/src/lib/server/hydration.cjs +1 -0
  160. package/dist/src/lib/server/hydration.d.ts +238 -0
  161. package/dist/src/lib/server/hydration.d.ts.map +1 -0
  162. package/dist/src/lib/server/hydration.js +384 -0
  163. package/dist/src/lib/server/hydration.mjs +1 -0
  164. package/dist/src/lib/server/index.cjs +16 -0
  165. package/dist/src/lib/server/index.d.ts +91 -0
  166. package/dist/src/lib/server/index.d.ts.map +1 -0
  167. package/dist/src/lib/server/index.js +141 -0
  168. package/dist/src/lib/server/index.mjs +16 -0
  169. package/dist/src/lib/server/reactive.cjs +1 -0
  170. package/dist/src/lib/server/reactive.d.ts +298 -0
  171. package/dist/src/lib/server/reactive.d.ts.map +1 -0
  172. package/dist/src/lib/server/reactive.js +472 -0
  173. package/dist/src/lib/server/reactive.mjs +1 -0
  174. package/dist/src/lib/theme/index.cjs +1 -0
  175. package/dist/src/lib/theme/index.d.ts +51 -0
  176. package/dist/src/lib/theme/index.d.ts.map +1 -0
  177. package/dist/src/lib/theme/index.js +79 -0
  178. package/dist/src/lib/theme/index.mjs +1 -0
  179. package/dist/src/lib/utils/index.cjs +1 -0
  180. package/dist/src/lib/utils/index.d.ts +379 -0
  181. package/dist/src/lib/utils/index.d.ts.map +1 -0
  182. package/dist/src/lib/utils/index.js +527 -0
  183. package/dist/src/lib/utils/index.mjs +1 -0
  184. package/dist/src/rx.cjs +1 -0
  185. package/dist/src/rx.d.ts +2 -0
  186. package/dist/src/rx.d.ts.map +1 -0
  187. package/dist/src/rx.js +101 -0
  188. package/dist/src/rx.mjs +0 -0
  189. package/dist/src/server.cjs +16 -0
  190. package/dist/src/server.d.ts +64 -0
  191. package/dist/src/server.d.ts.map +1 -0
  192. package/dist/src/server.js +63 -0
  193. package/dist/src/server.mjs +16 -0
  194. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  195. package/package.json +128 -0
  196. package/src/index.ts +31 -0
  197. package/types/fluixi.d.ts +5 -0
  198. package/types/vinxi.d.ts +50 -0
@@ -0,0 +1,527 @@
1
+ /**
2
+ * @fileoverview General utilities for Fluixi
3
+ * @module @fluixi/core/utils
4
+ *
5
+ * This module provides general utility functions for common operations.
6
+ */
7
+ /**
8
+ * Debounces a function call
9
+ *
10
+ * @template T - Function type
11
+ * @param {T} fn - Function to debounce
12
+ * @param {number} delay - Delay in milliseconds
13
+ * @returns {(...args: Parameters<T>) => void} Debounced function
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { debounce } from '@fluixi/core/utils';
18
+ *
19
+ * const handleInput = debounce((value: string) => {
20
+ * console.log('Input:', value);
21
+ * }, 300);
22
+ * ```
23
+ */
24
+ export function debounce(fn, delay) {
25
+ let timeoutId;
26
+ return (...args) => {
27
+ clearTimeout(timeoutId);
28
+ timeoutId = setTimeout(() => fn(...args), delay);
29
+ };
30
+ }
31
+ /**
32
+ * Throttles a function call
33
+ *
34
+ * @template T - Function type
35
+ * @param {T} fn - Function to throttle
36
+ * @param {number} limit - Time limit in milliseconds
37
+ * @returns {(...args: Parameters<T>) => void} Throttled function
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * import { throttle } from '@fluixi/core/utils';
42
+ *
43
+ * const handleScroll = throttle(() => {
44
+ * console.log('Scrolled');
45
+ * }, 100);
46
+ * ```
47
+ */
48
+ export function throttle(fn, limit) {
49
+ let inThrottle;
50
+ return (...args) => {
51
+ if (!inThrottle) {
52
+ fn(...args);
53
+ inThrottle = true;
54
+ setTimeout(() => (inThrottle = false), limit);
55
+ }
56
+ };
57
+ }
58
+ /**
59
+ * Creates a memoized version of a function
60
+ *
61
+ * @template T - Function type
62
+ * @param {T} fn - Function to memoize
63
+ * @returns {T} Memoized function
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * import { memoize } from '@fluixi/core/utils';
68
+ *
69
+ * const expensiveCalc = memoize((n: number) => {
70
+ * return n * n;
71
+ * });
72
+ * ```
73
+ */
74
+ export function memoize(fn) {
75
+ const cache = new Map();
76
+ return ((...args) => {
77
+ const key = JSON.stringify(args);
78
+ if (cache.has(key)) {
79
+ return cache.get(key);
80
+ }
81
+ const result = fn(...args);
82
+ cache.set(key, result);
83
+ return result;
84
+ });
85
+ }
86
+ /**
87
+ * Deep clones an object
88
+ *
89
+ * @template T - Object type
90
+ * @param {T} obj - Object to clone
91
+ * @returns {T} Cloned object
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * import { deepClone } from '@fluixi/core/utils';
96
+ *
97
+ * const original = { a: 1, b: { c: 2 } };
98
+ * const copy = deepClone(original);
99
+ * ```
100
+ */
101
+ export function deepClone(obj) {
102
+ if (obj === null || typeof obj !== 'object') {
103
+ return obj;
104
+ }
105
+ if (obj instanceof Date) {
106
+ return new Date(obj.getTime());
107
+ }
108
+ if (obj instanceof Array) {
109
+ return Array.from(obj).map((item) => deepClone(item));
110
+ }
111
+ if (obj instanceof Set) {
112
+ return new Set(Array.from(obj).map((item) => deepClone(item)));
113
+ }
114
+ if (obj instanceof Map) {
115
+ return new Map(Array.from(obj.entries()).map(([key, value]) => [
116
+ deepClone(key),
117
+ deepClone(value),
118
+ ]));
119
+ }
120
+ const clonedObj = {};
121
+ for (const key in obj) {
122
+ if (obj.hasOwnProperty(key)) {
123
+ clonedObj[key] = deepClone(obj[key]);
124
+ }
125
+ }
126
+ return clonedObj;
127
+ }
128
+ /**
129
+ * Deep merges multiple objects
130
+ *
131
+ * @template T - Object type
132
+ * @param {...Partial<T>[]} objects - Objects to merge
133
+ * @returns {T} Merged object
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * import { deepMerge } from '@fluixi/core/utils';
138
+ *
139
+ * const result = deepMerge(
140
+ * { a: 1, b: { c: 2 } },
141
+ * { b: { d: 3 } }
142
+ * );
143
+ * // { a: 1, b: { c: 2, d: 3 } }
144
+ * ```
145
+ */
146
+ export function deepMerge(...objects) {
147
+ const result = {};
148
+ for (const obj of objects) {
149
+ for (const key in obj) {
150
+ if (obj.hasOwnProperty(key)) {
151
+ const value = obj[key];
152
+ if (value !== null &&
153
+ typeof value === 'object' &&
154
+ !Array.isArray(value)) {
155
+ result[key] = deepMerge(result[key] || {}, value);
156
+ }
157
+ else {
158
+ result[key] = value;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ return result;
164
+ }
165
+ /**
166
+ * Generates a unique ID
167
+ *
168
+ * @param {string} prefix - Optional prefix
169
+ * @returns {string} Unique ID
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * import { uniqueId } from '@fluixi/core/utils';
174
+ *
175
+ * const id = uniqueId('component-');
176
+ * // 'component-abc123def456'
177
+ * ```
178
+ */
179
+ export function uniqueId(prefix = '') {
180
+ return prefix + Math.random().toString(36).substr(2, 9);
181
+ }
182
+ /**
183
+ * Formats a number with commas
184
+ *
185
+ * @param {number} num - Number to format
186
+ * @returns {string} Formatted number
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * import { formatNumber } from '@fluixi/core/utils';
191
+ *
192
+ * formatNumber(1234567); // '1,234,567'
193
+ * ```
194
+ */
195
+ export function formatNumber(num) {
196
+ return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
197
+ }
198
+ /**
199
+ * Formats bytes to human readable string
200
+ *
201
+ * @param {number} bytes - Number of bytes
202
+ * @param {number} decimals - Decimal places (default: 2)
203
+ * @returns {string} Formatted string
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * import { formatBytes } from '@fluixi/core/utils';
208
+ *
209
+ * formatBytes(1024); // '1 KB'
210
+ * formatBytes(1048576); // '1 MB'
211
+ * ```
212
+ */
213
+ export function formatBytes(bytes, decimals = 2) {
214
+ if (bytes === 0)
215
+ return '0 Bytes';
216
+ const k = 1024;
217
+ const dm = decimals < 0 ? 0 : decimals;
218
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
219
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
220
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
221
+ }
222
+ /**
223
+ * Capitalizes first letter of a string
224
+ *
225
+ * @param {string} str - String to capitalize
226
+ * @returns {string} Capitalized string
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * import { capitalize } from '@fluixi/core/utils';
231
+ *
232
+ * capitalize('hello'); // 'Hello'
233
+ * ```
234
+ */
235
+ export function capitalize(str) {
236
+ return str.charAt(0).toUpperCase() + str.slice(1);
237
+ }
238
+ /**
239
+ * Converts string to kebab-case
240
+ *
241
+ * @param {string} str - String to convert
242
+ * @returns {string} Kebab-case string
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * import { kebabCase } from '@fluixi/core/utils';
247
+ *
248
+ * kebabCase('HelloWorld'); // 'hello-world'
249
+ * ```
250
+ */
251
+ export function kebabCase(str) {
252
+ return str
253
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
254
+ .replace(/[\s_]+/g, '-')
255
+ .toLowerCase();
256
+ }
257
+ /**
258
+ * Converts string to camelCase
259
+ *
260
+ * @param {string} str - String to convert
261
+ * @returns {string} CamelCase string
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * import { camelCase } from '@fluixi/core/utils';
266
+ *
267
+ * camelCase('hello-world'); // 'helloWorld'
268
+ * ```
269
+ */
270
+ export function camelCase(str) {
271
+ return str.replace(/[-_\s](.)/g, (_, char) => char.toUpperCase());
272
+ }
273
+ /**
274
+ * Clamps a number between min and max
275
+ *
276
+ * @param {number} value - Value to clamp
277
+ * @param {number} min - Minimum value
278
+ * @param {number} max - Maximum value
279
+ * @returns {number} Clamped value
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * import { clamp } from '@fluixi/core/utils';
284
+ *
285
+ * clamp(5, 0, 10); // 5
286
+ * clamp(-5, 0, 10); // 0
287
+ * clamp(15, 0, 10); // 10
288
+ * ```
289
+ */
290
+ export function clamp(value, min, max) {
291
+ return Math.min(Math.max(value, min), max);
292
+ }
293
+ /**
294
+ * Generates a random number between min and max
295
+ *
296
+ * @param {number} min - Minimum value
297
+ * @param {number} max - Maximum value
298
+ * @returns {number} Random number
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * import { random } from '@fluixi/core/utils';
303
+ *
304
+ * const num = random(1, 100);
305
+ * ```
306
+ */
307
+ export function random(min, max) {
308
+ return Math.floor(Math.random() * (max - min + 1)) + min;
309
+ }
310
+ /**
311
+ * Checks if a value is empty
312
+ *
313
+ * @param {any} value - Value to check
314
+ * @returns {boolean} True if empty
315
+ *
316
+ * @example
317
+ * ```typescript
318
+ * import { isEmpty } from '@fluixi/core/utils';
319
+ *
320
+ * isEmpty(''); // true
321
+ * isEmpty([]); // true
322
+ * isEmpty({}); // true
323
+ * isEmpty(null); // true
324
+ * isEmpty('text'); // false
325
+ * ```
326
+ */
327
+ export function isEmpty(value) {
328
+ if (value === null || value === undefined)
329
+ return true;
330
+ if (typeof value === 'string')
331
+ return value.trim().length === 0;
332
+ if (Array.isArray(value))
333
+ return value.length === 0;
334
+ if (typeof value === 'object')
335
+ return Object.keys(value).length === 0;
336
+ return false;
337
+ }
338
+ /**
339
+ * Picks specific keys from an object
340
+ *
341
+ * @template T - Object type
342
+ * @template K - Keys to pick
343
+ * @param {T} obj - Source object
344
+ * @param {...K[]} keys - Keys to pick
345
+ * @returns {Pick<T, K>} Object with picked keys
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * import { pick } from '@fluixi/core/utils';
350
+ *
351
+ * const obj = { a: 1, b: 2, c: 3 };
352
+ * pick(obj, 'a', 'c'); // { a: 1, c: 3 }
353
+ * ```
354
+ */
355
+ export function pick(obj, ...keys) {
356
+ const result = {};
357
+ keys.forEach((key) => {
358
+ if (key in obj) {
359
+ result[key] = obj[key];
360
+ }
361
+ });
362
+ return result;
363
+ }
364
+ /**
365
+ * Omits specific keys from an object
366
+ *
367
+ * @template T - Object type
368
+ * @template K - Keys to omit
369
+ * @param {T} obj - Source object
370
+ * @param {...K[]} keys - Keys to omit
371
+ * @returns {Omit<T, K>} Object without omitted keys
372
+ *
373
+ * @example
374
+ * ```typescript
375
+ * import { omit } from '@fluixi/core/utils';
376
+ *
377
+ * const obj = { a: 1, b: 2, c: 3 };
378
+ * omit(obj, 'b'); // { a: 1, c: 3 }
379
+ * ```
380
+ */
381
+ export function omit(obj, ...keys) {
382
+ const result = { ...obj };
383
+ keys.forEach((key) => {
384
+ delete result[key];
385
+ });
386
+ return result;
387
+ }
388
+ /**
389
+ * Groups array items by a key
390
+ *
391
+ * @template T - Array item type
392
+ * @template K - Key type
393
+ * @param {T[]} array - Array to group
394
+ * @param {(item: T) => K} fn - Key extraction function
395
+ * @returns {Map<K, T[]>} Grouped items
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * import { groupBy } from '@fluixi/core/utils';
400
+ *
401
+ * const users = [
402
+ * { name: 'Alice', role: 'admin' },
403
+ * { name: 'Bob', role: 'user' },
404
+ * { name: 'Charlie', role: 'admin' }
405
+ * ];
406
+ * const grouped = groupBy(users, u => u.role);
407
+ * // Map { 'admin' => [...], 'user' => [...] }
408
+ * ```
409
+ */
410
+ export function groupBy(array, fn) {
411
+ return array.reduce((acc, item) => {
412
+ const key = fn(item);
413
+ const group = acc.get(key) || [];
414
+ group.push(item);
415
+ acc.set(key, group);
416
+ return acc;
417
+ }, new Map());
418
+ }
419
+ /**
420
+ * Creates an array of numbers from start to end
421
+ *
422
+ * @param {number} start - Start number
423
+ * @param {number} end - End number
424
+ * @param {number} step - Step size (default: 1)
425
+ * @returns {number[]} Array of numbers
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * import { range } from '@fluixi/core/utils';
430
+ *
431
+ * range(0, 5); // [0, 1, 2, 3, 4, 5]
432
+ * range(0, 10, 2); // [0, 2, 4, 6, 8, 10]
433
+ * ```
434
+ */
435
+ export function range(start, end, step = 1) {
436
+ const result = [];
437
+ for (let i = start; i <= end; i += step) {
438
+ result.push(i);
439
+ }
440
+ return result;
441
+ }
442
+ /**
443
+ * Retries an async function
444
+ *
445
+ * @template T - Return type
446
+ * @param {() => Promise<T>} fn - Async function to retry
447
+ * @param {number} retries - Number of retries (default: 3)
448
+ * @param {number} delay - Delay between retries in ms (default: 1000)
449
+ * @returns {Promise<T>} Promise that resolves with the result
450
+ *
451
+ * @example
452
+ * ```typescript
453
+ * import { retry } from '@fluixi/core/utils';
454
+ *
455
+ * const data = await retry(
456
+ * () => fetch('/api/data').then(r => r.json()),
457
+ * 3,
458
+ * 1000
459
+ * );
460
+ * ```
461
+ */
462
+ export async function retry(fn, retries = 3, delay = 1000) {
463
+ try {
464
+ return await fn();
465
+ }
466
+ catch (error) {
467
+ if (retries <= 0)
468
+ throw error;
469
+ await new Promise((resolve) => setTimeout(resolve, delay));
470
+ return retry(fn, retries - 1, delay);
471
+ }
472
+ }
473
+ /**
474
+ * Sleep for specified milliseconds
475
+ *
476
+ * @param {number} ms - Milliseconds to sleep
477
+ * @returns {Promise<void>} Promise that resolves after delay
478
+ *
479
+ * @example
480
+ * ```typescript
481
+ * import { sleep } from '@fluixi/core/utils';
482
+ *
483
+ * await sleep(1000); // Wait 1 second
484
+ * ```
485
+ */
486
+ export function sleep(ms) {
487
+ return new Promise((resolve) => setTimeout(resolve, ms));
488
+ }
489
+ /**
490
+ * Type guard to check if value is defined
491
+ *
492
+ * @template T - Value type
493
+ * @param {T | null | undefined} value - Value to check
494
+ * @returns {value is T} True if value is defined
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * import { isDefined } from '@fluixi/core/utils';
499
+ *
500
+ * const values = [1, null, 2, undefined, 3];
501
+ * const defined = values.filter(isDefined); // [1, 2, 3]
502
+ * ```
503
+ */
504
+ export function isDefined(value) {
505
+ return value !== null && value !== undefined;
506
+ }
507
+ /**
508
+ * Creates a chainable pipe function
509
+ *
510
+ * @param {...Function[]} fns - Functions to chain
511
+ * @returns {Function} Piped function
512
+ *
513
+ * @example
514
+ * ```typescript
515
+ * import { pipe } from '@fluixi/core/utils';
516
+ *
517
+ * const transform = pipe(
518
+ * (x: number) => x * 2,
519
+ * (x: number) => x + 1,
520
+ * (x: number) => x.toString()
521
+ * );
522
+ * transform(5); // '11'
523
+ * ```
524
+ */
525
+ export function pipe(...fns) {
526
+ return (arg) => fns.reduce((acc, fn) => fn(acc), arg);
527
+ }
@@ -0,0 +1 @@
1
+ function c(e,t){let r;return(...n)=>{clearTimeout(r),r=setTimeout(()=>e(...n),t)}}function f(e,t){let r;return(...n)=>{r||(e(...n),r=!0,setTimeout(()=>r=!1,t))}}function T(e){let t=new Map;return((...r)=>{let n=JSON.stringify(r);if(t.has(n))return t.get(n);let o=e(...r);return t.set(n,o),o})}function a(e){if(e===null||typeof e!="object")return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof Array)return Array.from(e).map(r=>a(r));if(e instanceof Set)return new Set(Array.from(e).map(r=>a(r)));if(e instanceof Map)return new Map(Array.from(e.entries()).map(([r,n])=>[a(r),a(n)]));let t={};for(let r in e)e.hasOwnProperty(r)&&(t[r]=a(e[r]));return t}function i(...e){let t={};for(let r of e)for(let n in r)if(r.hasOwnProperty(n)){let o=r[n];o!==null&&typeof o=="object"&&!Array.isArray(o)?t[n]=i(t[n]||{},o):t[n]=o}return t}function p(e=""){return e+Math.random().toString(36).substr(2,9)}function m(e){return e.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}function y(e,t=2){if(e===0)return"0 Bytes";let r=1024,n=t<0?0:t,o=["Bytes","KB","MB","GB","TB","PB"],s=Math.floor(Math.log(e)/Math.log(r));return parseFloat((e/Math.pow(r,s)).toFixed(n))+" "+o[s]}function g(e){return e.charAt(0).toUpperCase()+e.slice(1)}function l(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}function x(e){return e.replace(/[-_\s](.)/g,(t,r)=>r.toUpperCase())}function d(e,t,r){return Math.min(Math.max(e,t),r)}function h(e,t){return Math.floor(Math.random()*(t-e+1))+e}function b(e){return e==null?!0:typeof e=="string"?e.trim().length===0:Array.isArray(e)?e.length===0:typeof e=="object"?Object.keys(e).length===0:!1}function M(e,...t){let r={};return t.forEach(n=>{n in e&&(r[n]=e[n])}),r}function P(e,...t){let r={...e};return t.forEach(n=>{delete r[n]}),r}function w(e,t){return e.reduce((r,n)=>{let o=t(n),s=r.get(o)||[];return s.push(n),r.set(o,s),r},new Map)}function K(e,t,r=1){let n=[];for(let o=e;o<=t;o+=r)n.push(o);return n}async function u(e,t=3,r=1e3){try{return await e()}catch(n){if(t<=0)throw n;return await new Promise(o=>setTimeout(o,r)),u(e,t-1,r)}}function k(e){return new Promise(t=>setTimeout(t,e))}function A(e){return e!=null}function B(...e){return t=>e.reduce((r,n)=>n(r),t)}export{x as camelCase,g as capitalize,d as clamp,c as debounce,a as deepClone,i as deepMerge,y as formatBytes,m as formatNumber,w as groupBy,A as isDefined,b as isEmpty,l as kebabCase,T as memoize,P as omit,M as pick,B as pipe,h as random,K as range,u as retry,k as sleep,f as throttle,p as uniqueId};
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rx.d.ts","sourceRoot":"","sources":["../../src/rx.ts"],"names":[],"mappings":""}
package/dist/src/rx.js ADDED
@@ -0,0 +1,101 @@
1
+ // /**
2
+ // * @fileoverview Reactive Primitives Export for Fluixi
3
+ // * @module @fluixi/core/rx
4
+ // *
5
+ // * This module provides a convenient alias for importing reactive primitives.
6
+ // * It re-exports all reactive functions from @fluixi/reactive/signal.
7
+ // *
8
+ // * Usage:
9
+ // * ```typescript
10
+ // * import { createSignal, createEffect, createMemo } from '@fluixi/core/rx';
11
+ // * ```
12
+ // *
13
+ // * This is equivalent to:
14
+ // * ```typescript
15
+ // * import { createSignal, createEffect, createMemo } from '@fluixi/reactive/signal';
16
+ // * ```
17
+ // *
18
+ // * Note: The Babel plugin automatically transforms '@fluixi/core/rx' imports
19
+ // * to '@fluixi/reactive/signal' for optimal bundling.
20
+ // */
21
+ export {};
22
+ // // Re-export all reactive primitives from @fluixi/reactive/signal
23
+ // export {
24
+ // // Core signals
25
+ // createSignal,
26
+ // createEffect,
27
+ // createMemo,
28
+ // createRoot,
29
+ // // Batching and tracking
30
+ // batch,
31
+ // untrack,
32
+ // // Ownership
33
+ // getOwner,
34
+ // runWithOwner,
35
+ // // Cleanup
36
+ // onCleanup,
37
+ // // Context
38
+ // createContext,
39
+ // useContext,
40
+ // // Additional reactive primitives
41
+ // createComputed,
42
+ // createRenderEffect,
43
+ // createDeferred,
44
+ // createSelector,
45
+ // // Utilities
46
+ // from,
47
+ // observable,
48
+ // mapArray,
49
+ // indexArray,
50
+ // } from '@fluixi/reactive/signal';
51
+ // // Re-export types
52
+ // export type {
53
+ // Signal,
54
+ // Accessor,
55
+ // Setter,
56
+ // SignalOptions,
57
+ // Owner,
58
+ // Context,
59
+ // Effect,
60
+ // EffectOptions,
61
+ // Memo,
62
+ // MemoOptions,
63
+ // } from '@fluixi/reactive/signal';
64
+ // /**
65
+ // * Default export for convenience
66
+ // */
67
+ // export default {
68
+ // createSignal,
69
+ // createEffect,
70
+ // createMemo,
71
+ // createRoot,
72
+ // batch,
73
+ // untrack,
74
+ // getOwner,
75
+ // runWithOwner,
76
+ // onCleanup,
77
+ // createContext,
78
+ // useContext,
79
+ // };
80
+ // // Note: Import from '@fluixi/reactive/signal' directly
81
+ // import {
82
+ // createSignal,
83
+ // createEffect,
84
+ // createMemo,
85
+ // createRoot,
86
+ // batch,
87
+ // untrack,
88
+ // getOwner,
89
+ // runWithOwner,
90
+ // onCleanup,
91
+ // createContext,
92
+ // useContext,
93
+ // createComputed,
94
+ // createRenderEffect,
95
+ // createDeferred,
96
+ // createSelector,
97
+ // from,
98
+ // observable,
99
+ // mapArray,
100
+ // indexArray,
101
+ // } from '@fluixi/reactive/signal';
File without changes
@@ -0,0 +1,16 @@
1
+ "use strict";var T=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var dt=(t,e)=>{for(var n in e)T(t,n,{get:e[n],enumerable:!0})},lt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ct(e))!ut.call(t,o)&&o!==n&&T(t,o,{get:()=>e[o],enumerable:!(r=st(e,o))||r.enumerable});return t};var pt=t=>lt(T({},"__esModule",{value:!0}),t);var St={};dt(St,{batch:()=>I,cleanupHydration:()=>m,clearHydrationData:()=>g,clearHydrationDataKey:()=>H,createComputed:()=>P,createContext:()=>U,createDeferred:()=>X,createEffect:()=>f,createHtmlDocument:()=>tt,createHydratableResource:()=>k,createMemo:()=>S,createRenderEffect:()=>V,createResource:()=>J,createRoot:()=>F,createSelector:()=>B,createSignal:()=>K,deserializeHydrationData:()=>b,getHydrationData:()=>d,getOwner:()=>W,getSSRContext:()=>ft,hasHydrationData:()=>R,hydrationMarker:()=>O,hydrationMarkerEnd:()=>A,hydrationMarkerStart:()=>E,isClient:()=>nt,isClientEnvironment:()=>M,isClientReactive:()=>Q,isHydrating:()=>x,isServer:()=>et,isServerEnvironment:()=>j,isServerReactive:()=>G,onCleanup:()=>z,onClient:()=>gt,onServer:()=>xt,renderToPage:()=>Z,renderToStream:()=>rt,renderToString:()=>h,runWithOwner:()=>L,serializeHydrationData:()=>l,setHydrating:()=>D,setHydrationData:()=>u,setSSRContext:()=>yt,startServer:()=>mt,startTransition:()=>q,untrack:()=>N,useContext:()=>Y,useHydrationData:()=>_,withSSRContext:()=>Tt});module.exports=pt(St);var C=!1,a=new Map;function x(){return C}function D(t){C=t}function u(t,e){a.set(t,e)}function d(t){return a.get(t)}function R(t){return a.has(t)}function g(){a.clear()}function H(t){a.delete(t)}function l(){if(a.size===0)return"";let t=Object.fromEntries(a);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 e=t.textContent||"{}",n=JSON.parse(e);for(let[r,o]of Object.entries(n))a.set(r,o);return!0}catch(e){return console.error("Failed to deserialize hydration data:",e),!1}}function O(t){return`<!--#${t}-->`}function E(t){return`<!--#${t}-->`}function A(t){return`<!--/${t}-->`}function k(t,e){return async()=>{if(x()||typeof window<"u"){let r=d(t);if(r!==void 0)return r}let n=await e();return typeof window>"u"&&u(t,n),n}}function _(t,e){let n=d(t);if(n!==void 0)return n;let r=typeof e=="function"?e():e;return typeof window>"u"&&u(t,r),r}function m(){if(typeof window>"u")return;let t=document.getElementById("__FLUIXI_HYDRATION__");t&&t.remove();let e=document.createTreeWalker(document.body,NodeFilter.SHOW_COMMENT,null),n=[],r;for(;r=e.nextNode();){let o=r,i=o.nodeValue||"";(i.startsWith("#")||i.startsWith("/"))&&n.push(o)}n.forEach(o=>o.remove()),g()}typeof window<"u"&&window.addEventListener("load",()=>{setTimeout(m,100)});function j(){return typeof window>"u"}function M(){return typeof window<"u"}var v=require("@fluixi/server");function K(t,e){let n=t;return[(()=>n),i=>(typeof i=="function"?n=i(n):n=i,n)]}function f(t,e,n){try{t(e)}catch(r){console.error("[Fluixi Server] Effect error:",r)}return{dispose:()=>{}}}function S(t,e,n){let r=t(e);return(()=>r)}function F(t){let e=[],n=()=>{e.forEach(r=>{try{r()}catch(o){console.error("[Fluixi Server] Cleanup error:",o)}}),e.length=0};try{return t(n)}catch(r){throw n(),r}}function I(t){return t()}function N(t){return t()}var $=null;function z(t){$&&$.push(t)}var p=null;function W(){return p}function L(t,e){let n=p;p=t;try{return e()}finally{p=n}}var s=new Map;function U(t){let e=Symbol("context");return{id:e,Provider:r=>{let o=s.get(e);s.set(e,r.value);try{return r.children}finally{o!==void 0?s.set(e,o):s.delete(e)}},defaultValue:t}}function Y(t){let e=s.get(t.id);return e!==void 0?e:t.defaultValue}function P(t){return f(t)}function V(t){return f(t)}function X(t){return S(t)}function B(t){let e=t();return n=>n===e}function J(t,e,n){return[()=>{},{mutate:r=>r,refetch:()=>{}}]}function q(t){t()}var G=!0,Q=!1;var c=null;function ft(){return c}function yt(t){c=t}function Tt(t,e){let n=c;c=t;try{return e()}finally{c=n}}async function Z(t,e={}){let n=await h(t);return tt(n,e)}function tt(t,e={}){let{title:n="Fluixi App",lang:r="en",stylesheets:o=[],scripts:i=[],head:ot="",bodyAttributes:w=""}=e,it=o.map(y=>`<link rel="stylesheet" href="${y}">`).join(`
2
+ `),at=i.map(y=>`<script type="module" src="${y}"><\/script>`).join(`
3
+ `);return`<!DOCTYPE html>
4
+ <html lang="${r}">
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
+ <title>${n}</title>
9
+ ${it}
10
+ ${ot}
11
+ </head>
12
+ <body${w?" "+w:""}>
13
+ ${t}
14
+ ${at}
15
+ </body>
16
+ </html>`}function et(){return typeof window>"u"}function nt(){return typeof window<"u"}function xt(t,e){return et()?t():e}function gt(t,e){return nt()?t():e}async function h(t){let e=await(0,v.renderToString)(t),n=l();return e+n}async function rt(t){let e=await(0,v.renderToString)(t),n=l();return e+n}function mt(t){return{render:e=>h(()=>t({url:e})),stream:e=>rt(()=>t({url:e})),page:(e,n)=>Z(()=>t({url:e}),n)}}