@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,110 @@
1
- "use strict";var d=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var x=(e,t)=>{for(var r in t)d(e,r,{get:t[r],enumerable:!0})},S=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of v(t))!p.call(e,i)&&i!==r&&d(e,i,{get:()=>t[i],enumerable:!(o=y(t,i))||o.enumerable});return e};var k=e=>S(d({},"__esModule",{value:!0}),e);var A={};x(A,{createTheme:()=>L});module.exports=k(A);var l=require("@fluixi/reactive/signal");var O=require("@fluixi/dom"),b=require("@fluixi/dom");function w(){let e=new Map;return{getItem:t=>e.has(t)?e.get(t):null,setItem:(t,r)=>{e.set(t,String(r))},removeItem:t=>{e.delete(t)},clear:()=>e.clear(),key:t=>Array.from(e.keys())[t]??null,get length(){return e.size}}}var a=typeof localStorage<"u"?localStorage:w(),c={get window(){return typeof window<"u"?window:void 0},get document(){return typeof document<"u"?document:void 0}};function I(e){return e?e===!0?{dark:"dark",light:"light"}:e:null}function L(e){let t=e.storageKey??"theme",r=e.attribute??"data-theme",o=I(e.system),i=()=>{let n=a.getItem(t);return n&&e.themes.includes(n)?n:o&&c.window?.matchMedia?.("(prefers-color-scheme: dark)")?.matches?o.dark:o?o.light:e.default},[s,f]=(0,l.createSignal)(i()),[T,u]=(0,l.createSignal)(!1),m=n=>{c.document?.documentElement.setAttribute(r,n);try{a.setItem(t,n)}catch{}},g=n=>{if(!e.themes.includes(n))return;let h=s();f(()=>n),m(n),e.onChange?.(n,h),e.load&&(u(!0),e.onLoading?.(n),Promise.resolve(e.load(n)).finally(()=>{u(!1),e.onLoaded?.(n)}))};return{value:s,isLoading:T,set:g,toggle:()=>{let n=e.themes.indexOf(s());g(e.themes[(n+1)%e.themes.length])},init:()=>m(s()),headScript:()=>`<script>(function(){try{var c=${JSON.stringify({k:t,a:r,d:e.default,sys:o})},t=localStorage.getItem(c.k);if(!t&&c.sys)t=matchMedia('(prefers-color-scheme: dark)').matches?c.sys.dark:c.sys.light;if(!t)t=c.d;document.documentElement.setAttribute(c.a,t);}catch(e){}})();<\/script>`}}
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/theme/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createTheme: () => createTheme
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_signal = require("@fluixi/reactive/signal");
27
+
28
+ // src/lib/env/index.ts
29
+ var import_dom = require("@fluixi/dom");
30
+ var import_dom2 = require("@fluixi/dom");
31
+ function createMemoryStorage() {
32
+ const mem = /* @__PURE__ */ new Map();
33
+ return {
34
+ getItem: (k) => mem.has(k) ? mem.get(k) : null,
35
+ setItem: (k, v) => void mem.set(k, String(v)),
36
+ removeItem: (k) => void mem.delete(k),
37
+ clear: () => mem.clear(),
38
+ key: (i) => Array.from(mem.keys())[i] ?? null,
39
+ get length() {
40
+ return mem.size;
41
+ }
42
+ };
43
+ }
44
+ var storage = typeof localStorage !== "undefined" ? localStorage : createMemoryStorage();
45
+ var env = {
46
+ get window() {
47
+ return typeof window !== "undefined" ? window : void 0;
48
+ },
49
+ get document() {
50
+ return typeof document !== "undefined" ? document : void 0;
51
+ }
52
+ };
53
+
54
+ // src/lib/theme/index.ts
55
+ function systemMap(system) {
56
+ if (!system) return null;
57
+ if (system === true) return { dark: "dark", light: "light" };
58
+ return system;
59
+ }
60
+ function createTheme(options) {
61
+ const storageKey = options.storageKey ?? "theme";
62
+ const attribute = options.attribute ?? "data-theme";
63
+ const sys = systemMap(options.system);
64
+ const detectInitial = () => {
65
+ const stored = storage.getItem(storageKey);
66
+ if (stored && options.themes.includes(stored)) return stored;
67
+ if (sys && env.window?.matchMedia?.("(prefers-color-scheme: dark)")?.matches) return sys.dark;
68
+ if (sys) return sys.light;
69
+ return options.default;
70
+ };
71
+ const [value, setValue] = (0, import_signal.createSignal)(detectInitial());
72
+ const [isLoading, setLoading] = (0, import_signal.createSignal)(false);
73
+ const apply = (t) => {
74
+ env.document?.documentElement.setAttribute(attribute, t);
75
+ try {
76
+ storage.setItem(storageKey, t);
77
+ } catch {
78
+ }
79
+ };
80
+ const set = (t) => {
81
+ if (!options.themes.includes(t)) return;
82
+ const prev = value();
83
+ setValue(() => t);
84
+ apply(t);
85
+ options.onChange?.(t, prev);
86
+ if (options.load) {
87
+ setLoading(true);
88
+ options.onLoading?.(t);
89
+ Promise.resolve(options.load(t)).finally(() => {
90
+ setLoading(false);
91
+ options.onLoaded?.(t);
92
+ });
93
+ }
94
+ };
95
+ const toggle = () => {
96
+ const i = options.themes.indexOf(value());
97
+ set(options.themes[(i + 1) % options.themes.length]);
98
+ };
99
+ const init = () => apply(value());
100
+ const headScript = () => {
101
+ const cfg = JSON.stringify({
102
+ k: storageKey,
103
+ a: attribute,
104
+ d: options.default,
105
+ sys
106
+ });
107
+ return `<script>(function(){try{var c=${cfg},t=localStorage.getItem(c.k);if(!t&&c.sys)t=matchMedia('(prefers-color-scheme: dark)').matches?c.sys.dark:c.sys.light;if(!t)t=c.d;document.documentElement.setAttribute(c.a,t);}catch(e){}})();<\/script>`;
108
+ };
109
+ return { value, isLoading, set, toggle, init, headScript };
110
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
- * createTheme a reusable, SSR-safe theme store so every Fluixi app gets the whole
3
- * theme workflow (detect persist apply toggle, + the no-flash head script)
2
+ * createTheme, a reusable, SSR-safe theme store so every Fluixi app gets the whole
3
+ * theme workflow (detect -> persist -> apply -> toggle, + the no-flash head script)
4
4
  * without rewriting it. Generic over an arbitrary theme list (not just light/dark),
5
5
  * with optional async theme loading and lifecycle hooks.
6
6
  *
@@ -36,7 +36,7 @@ export interface ThemeOptions<T extends string> {
36
36
  export interface Theme<T extends string> {
37
37
  /** Reactive current theme. */
38
38
  value: Accessor<T>;
39
- /** Reactive true while an async `load` is running. */
39
+ /** Reactive: true while an async `load` is running. */
40
40
  isLoading: Accessor<boolean>;
41
41
  /** Set a specific theme (persists, applies, runs `load`/hooks). */
42
42
  set: (theme: T) => void;
@@ -44,8 +44,23 @@ export interface Theme<T extends string> {
44
44
  toggle: () => void;
45
45
  /** Apply the current theme to the DOM (call once on client mount). */
46
46
  init: () => void;
47
- /** Inline `<script>` for `<head>` that sets the attribute BEFORE first paint (no flash). */
47
+ /** Inline `<script>` for `<head>` that sets the attribute before first paint (no flash). */
48
48
  headScript: () => string;
49
49
  }
50
+ /**
51
+ * A theme controller: a reactive current theme, written to an attribute on the document.
52
+ *
53
+ * The initial value is taken from storage, then from the system preference, then from
54
+ * `options.default`, so a returning visitor keeps their choice and a new one gets what
55
+ * their OS asked for. The attribute defaults to `data-theme`, which is what a CSS
56
+ * `[data-theme="dark"]` block selects on.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const theme = createTheme({ themes: ['light', 'dark'], system: { dark: 'dark' } });
61
+ * theme.set('dark');
62
+ * theme.current(); // 'dark', and the document now carries data-theme="dark"
63
+ * ```
64
+ */
50
65
  export declare function createTheme<T extends string>(options: ThemeOptions<T>): Theme<T>;
51
66
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/theme/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQ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EAAmE;IACnE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACxB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,sEAAsE;IACtE,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,4FAA4F;IAC5F,UAAU,EAAE,MAAM,MAAM,CAAC;CAC1B;AAUD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAiEhF"}
@@ -1,6 +1,6 @@
1
1
  /**
2
- * createTheme a reusable, SSR-safe theme store so every Fluixi app gets the whole
3
- * theme workflow (detect persist apply toggle, + the no-flash head script)
2
+ * createTheme, a reusable, SSR-safe theme store so every Fluixi app gets the whole
3
+ * theme workflow (detect -> persist -> apply -> toggle, + the no-flash head script)
4
4
  * without rewriting it. Generic over an arbitrary theme list (not just light/dark),
5
5
  * with optional async theme loading and lifecycle hooks.
6
6
  *
@@ -16,6 +16,21 @@ function systemMap(system) {
16
16
  return { dark: 'dark', light: 'light' };
17
17
  return system;
18
18
  }
19
+ /**
20
+ * A theme controller: a reactive current theme, written to an attribute on the document.
21
+ *
22
+ * The initial value is taken from storage, then from the system preference, then from
23
+ * `options.default`, so a returning visitor keeps their choice and a new one gets what
24
+ * their OS asked for. The attribute defaults to `data-theme`, which is what a CSS
25
+ * `[data-theme="dark"]` block selects on.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const theme = createTheme({ themes: ['light', 'dark'], system: { dark: 'dark' } });
30
+ * theme.set('dark');
31
+ * theme.current(); // 'dark', and the document now carries data-theme="dark"
32
+ * ```
33
+ */
19
34
  export function createTheme(options) {
20
35
  const storageKey = options.storageKey ?? 'theme';
21
36
  const attribute = options.attribute ?? 'data-theme';
@@ -1 +1,89 @@
1
- import{createSignal as u}from"@fluixi/reactive/signal";import{isServer as O}from"@fluixi/dom";import{isServer as k}from"@fluixi/dom";function h(){let e=new Map;return{getItem:n=>e.has(n)?e.get(n):null,setItem:(n,o)=>{e.set(n,String(o))},removeItem:n=>{e.delete(n)},clear:()=>e.clear(),key:n=>Array.from(e.keys())[n]??null,get length(){return e.size}}}var s=typeof localStorage<"u"?localStorage:h(),d={get window(){return typeof window<"u"?window:void 0},get document(){return typeof document<"u"?document:void 0}};function y(e){return e?e===!0?{dark:"dark",light:"light"}:e:null}function A(e){let n=e.storageKey??"theme",o=e.attribute??"data-theme",r=y(e.system),m=()=>{let t=s.getItem(n);return t&&e.themes.includes(t)?t:r&&d.window?.matchMedia?.("(prefers-color-scheme: dark)")?.matches?r.dark:r?r.light:e.default},[i,g]=u(m()),[f,a]=u(!1),c=t=>{d.document?.documentElement.setAttribute(o,t);try{s.setItem(n,t)}catch{}},l=t=>{if(!e.themes.includes(t))return;let T=i();g(()=>t),c(t),e.onChange?.(t,T),e.load&&(a(!0),e.onLoading?.(t),Promise.resolve(e.load(t)).finally(()=>{a(!1),e.onLoaded?.(t)}))};return{value:i,isLoading:f,set:l,toggle:()=>{let t=e.themes.indexOf(i());l(e.themes[(t+1)%e.themes.length])},init:()=>c(i()),headScript:()=>`<script>(function(){try{var c=${JSON.stringify({k:n,a:o,d:e.default,sys:r})},t=localStorage.getItem(c.k);if(!t&&c.sys)t=matchMedia('(prefers-color-scheme: dark)').matches?c.sys.dark:c.sys.light;if(!t)t=c.d;document.documentElement.setAttribute(c.a,t);}catch(e){}})();<\/script>`}}export{A as createTheme};
1
+ // src/lib/theme/index.ts
2
+ import { createSignal } from "@fluixi/reactive/signal";
3
+
4
+ // src/lib/env/index.ts
5
+ import { isServer } from "@fluixi/dom";
6
+ import { isServer as onServer } from "@fluixi/dom";
7
+ function createMemoryStorage() {
8
+ const mem = /* @__PURE__ */ new Map();
9
+ return {
10
+ getItem: (k) => mem.has(k) ? mem.get(k) : null,
11
+ setItem: (k, v) => void mem.set(k, String(v)),
12
+ removeItem: (k) => void mem.delete(k),
13
+ clear: () => mem.clear(),
14
+ key: (i) => Array.from(mem.keys())[i] ?? null,
15
+ get length() {
16
+ return mem.size;
17
+ }
18
+ };
19
+ }
20
+ var storage = typeof localStorage !== "undefined" ? localStorage : createMemoryStorage();
21
+ var env = {
22
+ get window() {
23
+ return typeof window !== "undefined" ? window : void 0;
24
+ },
25
+ get document() {
26
+ return typeof document !== "undefined" ? document : void 0;
27
+ }
28
+ };
29
+
30
+ // src/lib/theme/index.ts
31
+ function systemMap(system) {
32
+ if (!system) return null;
33
+ if (system === true) return { dark: "dark", light: "light" };
34
+ return system;
35
+ }
36
+ function createTheme(options) {
37
+ const storageKey = options.storageKey ?? "theme";
38
+ const attribute = options.attribute ?? "data-theme";
39
+ const sys = systemMap(options.system);
40
+ const detectInitial = () => {
41
+ const stored = storage.getItem(storageKey);
42
+ if (stored && options.themes.includes(stored)) return stored;
43
+ if (sys && env.window?.matchMedia?.("(prefers-color-scheme: dark)")?.matches) return sys.dark;
44
+ if (sys) return sys.light;
45
+ return options.default;
46
+ };
47
+ const [value, setValue] = createSignal(detectInitial());
48
+ const [isLoading, setLoading] = createSignal(false);
49
+ const apply = (t) => {
50
+ env.document?.documentElement.setAttribute(attribute, t);
51
+ try {
52
+ storage.setItem(storageKey, t);
53
+ } catch {
54
+ }
55
+ };
56
+ const set = (t) => {
57
+ if (!options.themes.includes(t)) return;
58
+ const prev = value();
59
+ setValue(() => t);
60
+ apply(t);
61
+ options.onChange?.(t, prev);
62
+ if (options.load) {
63
+ setLoading(true);
64
+ options.onLoading?.(t);
65
+ Promise.resolve(options.load(t)).finally(() => {
66
+ setLoading(false);
67
+ options.onLoaded?.(t);
68
+ });
69
+ }
70
+ };
71
+ const toggle = () => {
72
+ const i = options.themes.indexOf(value());
73
+ set(options.themes[(i + 1) % options.themes.length]);
74
+ };
75
+ const init = () => apply(value());
76
+ const headScript = () => {
77
+ const cfg = JSON.stringify({
78
+ k: storageKey,
79
+ a: attribute,
80
+ d: options.default,
81
+ sys
82
+ });
83
+ return `<script>(function(){try{var c=${cfg},t=localStorage.getItem(c.k);if(!t&&c.sys)t=matchMedia('(prefers-color-scheme: dark)').matches?c.sys.dark:c.sys.light;if(!t)t=c.d;document.documentElement.setAttribute(c.a,t);}catch(e){}})();<\/script>`;
84
+ };
85
+ return { value, isLoading, set, toggle, init, headScript };
86
+ }
87
+ export {
88
+ createTheme
89
+ };
@@ -1 +1,209 @@
1
- "use strict";var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var r in t)i(e,r,{get:t[r],enumerable:!0})},y=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of T(t))!p.call(e,o)&&o!==r&&i(e,o,{get:()=>t[o],enumerable:!(n=f(t,o))||n.enumerable});return e};var g=e=>y(i({},"__esModule",{value:!0}),e);var _={};m(_,{camelCase:()=>K,capitalize:()=>P,clamp:()=>k,debounce:()=>l,deepClone:()=>s,deepMerge:()=>u,formatBytes:()=>M,formatNumber:()=>b,groupBy:()=>E,isDefined:()=>D,isEmpty:()=>B,kebabCase:()=>w,memoize:()=>d,omit:()=>C,pick:()=>O,pipe:()=>R,random:()=>A,range:()=>S,retry:()=>c,sleep:()=>z,throttle:()=>x,uniqueId:()=>h});module.exports=g(_);function l(e,t){let r;return(...n)=>{clearTimeout(r),r=setTimeout(()=>e(...n),t)}}function x(e,t){let r;return(...n)=>{r||(e(...n),r=!0,setTimeout(()=>r=!1,t))}}function d(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 s(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=>s(r));if(e instanceof Set)return new Set(Array.from(e).map(r=>s(r)));if(e instanceof Map)return new Map(Array.from(e.entries()).map(([r,n])=>[s(r),s(n)]));let t={};for(let r in e)e.hasOwnProperty(r)&&(t[r]=s(e[r]));return t}function u(...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]=u(t[n]||{},o):t[n]=o}return t}function h(e=""){return e+Math.random().toString(36).substr(2,9)}function b(e){return e.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}function M(e,t=2){if(e===0)return"0 Bytes";let r=1024,n=t<0?0:t,o=["Bytes","KB","MB","GB","TB","PB"],a=Math.floor(Math.log(e)/Math.log(r));return parseFloat((e/Math.pow(r,a)).toFixed(n))+" "+o[a]}function P(e){return e.charAt(0).toUpperCase()+e.slice(1)}function w(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}function K(e){return e.replace(/[-_\s](.)/g,(t,r)=>r.toUpperCase())}function k(e,t,r){return Math.min(Math.max(e,t),r)}function A(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 O(e,...t){let r={};return t.forEach(n=>{n in e&&(r[n]=e[n])}),r}function C(e,...t){let r={...e};return t.forEach(n=>{delete r[n]}),r}function E(e,t){return e.reduce((r,n)=>{let o=t(n),a=r.get(o)||[];return a.push(n),r.set(o,a),r},new Map)}function S(e,t,r=1){let n=[];for(let o=e;o<=t;o+=r)n.push(o);return n}async function c(e,t=3,r=1e3){try{return await e()}catch(n){if(t<=0)throw n;return await new Promise(o=>setTimeout(o,r)),c(e,t-1,r)}}function z(e){return new Promise(t=>setTimeout(t,e))}function D(e){return e!=null}function R(...e){return t=>e.reduce((r,n)=>n(r),t)}
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/utils/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ camelCase: () => camelCase,
24
+ capitalize: () => capitalize,
25
+ clamp: () => clamp,
26
+ debounce: () => debounce,
27
+ deepClone: () => deepClone,
28
+ deepMerge: () => deepMerge,
29
+ formatBytes: () => formatBytes,
30
+ formatNumber: () => formatNumber,
31
+ groupBy: () => groupBy,
32
+ isDefined: () => isDefined,
33
+ isEmpty: () => isEmpty,
34
+ kebabCase: () => kebabCase,
35
+ memoize: () => memoize,
36
+ omit: () => omit,
37
+ pick: () => pick,
38
+ pipe: () => pipe,
39
+ random: () => random,
40
+ range: () => range,
41
+ retry: () => retry,
42
+ sleep: () => sleep,
43
+ throttle: () => throttle,
44
+ uniqueId: () => uniqueId
45
+ });
46
+ module.exports = __toCommonJS(index_exports);
47
+ function debounce(fn, delay) {
48
+ let timeoutId;
49
+ return (...args) => {
50
+ clearTimeout(timeoutId);
51
+ timeoutId = setTimeout(() => fn(...args), delay);
52
+ };
53
+ }
54
+ function throttle(fn, limit) {
55
+ let inThrottle;
56
+ return (...args) => {
57
+ if (!inThrottle) {
58
+ fn(...args);
59
+ inThrottle = true;
60
+ setTimeout(() => inThrottle = false, limit);
61
+ }
62
+ };
63
+ }
64
+ function memoize(fn) {
65
+ const cache = /* @__PURE__ */ new Map();
66
+ return ((...args) => {
67
+ const key = JSON.stringify(args);
68
+ if (cache.has(key)) {
69
+ return cache.get(key);
70
+ }
71
+ const result = fn(...args);
72
+ cache.set(key, result);
73
+ return result;
74
+ });
75
+ }
76
+ function deepClone(obj) {
77
+ if (obj === null || typeof obj !== "object") {
78
+ return obj;
79
+ }
80
+ if (obj instanceof Date) {
81
+ return new Date(obj.getTime());
82
+ }
83
+ if (obj instanceof Array) {
84
+ return Array.from(obj).map((item) => deepClone(item));
85
+ }
86
+ if (obj instanceof Set) {
87
+ return new Set(Array.from(obj).map((item) => deepClone(item)));
88
+ }
89
+ if (obj instanceof Map) {
90
+ return new Map(
91
+ Array.from(obj.entries()).map(([key, value]) => [
92
+ deepClone(key),
93
+ deepClone(value)
94
+ ])
95
+ );
96
+ }
97
+ const clonedObj = {};
98
+ for (const key in obj) {
99
+ if (obj.hasOwnProperty(key)) {
100
+ clonedObj[key] = deepClone(obj[key]);
101
+ }
102
+ }
103
+ return clonedObj;
104
+ }
105
+ function deepMerge(...objects) {
106
+ const result = {};
107
+ for (const obj of objects) {
108
+ for (const key in obj) {
109
+ if (obj.hasOwnProperty(key)) {
110
+ const value = obj[key];
111
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
112
+ result[key] = deepMerge(
113
+ result[key] || {},
114
+ value
115
+ );
116
+ } else {
117
+ result[key] = value;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ return result;
123
+ }
124
+ function uniqueId(prefix = "") {
125
+ return prefix + Math.random().toString(36).substr(2, 9);
126
+ }
127
+ function formatNumber(num) {
128
+ return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
129
+ }
130
+ function formatBytes(bytes, decimals = 2) {
131
+ if (bytes === 0) return "0 Bytes";
132
+ const k = 1024;
133
+ const dm = decimals < 0 ? 0 : decimals;
134
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB"];
135
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
136
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
137
+ }
138
+ function capitalize(str) {
139
+ return str.charAt(0).toUpperCase() + str.slice(1);
140
+ }
141
+ function kebabCase(str) {
142
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
143
+ }
144
+ function camelCase(str) {
145
+ return str.replace(/[-_\s](.)/g, (_, char) => char.toUpperCase());
146
+ }
147
+ function clamp(value, min, max) {
148
+ return Math.min(Math.max(value, min), max);
149
+ }
150
+ function random(min, max) {
151
+ return Math.floor(Math.random() * (max - min + 1)) + min;
152
+ }
153
+ function isEmpty(value) {
154
+ if (value === null || value === void 0) return true;
155
+ if (typeof value === "string") return value.trim().length === 0;
156
+ if (Array.isArray(value)) return value.length === 0;
157
+ if (typeof value === "object") return Object.keys(value).length === 0;
158
+ return false;
159
+ }
160
+ function pick(obj, ...keys) {
161
+ const result = {};
162
+ keys.forEach((key) => {
163
+ if (key in obj) {
164
+ result[key] = obj[key];
165
+ }
166
+ });
167
+ return result;
168
+ }
169
+ function omit(obj, ...keys) {
170
+ const result = { ...obj };
171
+ keys.forEach((key) => {
172
+ delete result[key];
173
+ });
174
+ return result;
175
+ }
176
+ function groupBy(array, fn) {
177
+ return array.reduce((acc, item) => {
178
+ const key = fn(item);
179
+ const group = acc.get(key) || [];
180
+ group.push(item);
181
+ acc.set(key, group);
182
+ return acc;
183
+ }, /* @__PURE__ */ new Map());
184
+ }
185
+ function range(start, end, step = 1) {
186
+ const result = [];
187
+ for (let i = start; i <= end; i += step) {
188
+ result.push(i);
189
+ }
190
+ return result;
191
+ }
192
+ async function retry(fn, retries = 3, delay = 1e3) {
193
+ try {
194
+ return await fn();
195
+ } catch (error) {
196
+ if (retries <= 0) throw error;
197
+ await new Promise((resolve) => setTimeout(resolve, delay));
198
+ return retry(fn, retries - 1, delay);
199
+ }
200
+ }
201
+ function sleep(ms) {
202
+ return new Promise((resolve) => setTimeout(resolve, ms));
203
+ }
204
+ function isDefined(value) {
205
+ return value !== null && value !== void 0;
206
+ }
207
+ function pipe(...fns) {
208
+ return (arg) => fns.reduce((acc, fn) => fn(acc), arg);
209
+ }