@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.
- package/dist/cdn/core.global.js +2 -1
- package/dist/cli/generate.cjs +4117 -292
- package/dist/cli/generate.mjs +4122 -292
- package/dist/cli/index.cjs +4117 -292
- package/dist/cli/index.mjs +4122 -292
- package/dist/cli/run.cjs +63 -1
- package/dist/cli/run.mjs +39 -1
- package/dist/src/cdn/chunk-MDJLC3PE.mjs +830 -0
- package/dist/src/cdn/core.cjs +1365 -1
- package/dist/src/cdn/core.d.ts +3 -3
- package/dist/src/cdn/core.js +3 -3
- package/dist/src/cdn/core.mjs +642 -1
- package/dist/src/cdn/router-JYFZP3EZ.mjs +70 -0
- package/dist/src/index.cjs +1280 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -11
- package/dist/src/index.mjs +1393 -1
- package/dist/src/jsx-dev-runtime.cjs +26 -1
- package/dist/src/jsx-dev-runtime.mjs +24 -1
- package/dist/src/jsx-runtime.cjs +26 -1
- package/dist/src/jsx-runtime.js +0 -9
- package/dist/src/jsx-runtime.mjs +24 -1
- package/dist/src/lib/client/chunk-7IUN2FLI.mjs +133 -0
- package/dist/src/lib/client/index.cjs +956 -1
- package/dist/src/lib/client/index.d.ts +17 -6
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +26 -19
- package/dist/src/lib/client/index.mjs +222 -1
- package/dist/src/lib/client/router-NOFEMOEH.mjs +631 -0
- package/dist/src/lib/context/context.cjs +118 -1
- package/dist/src/lib/context/context.d.ts +19 -37
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +8 -45
- package/dist/src/lib/context/context.mjs +99 -1
- package/dist/src/lib/context/index.cjs +120 -1
- package/dist/src/lib/context/index.mjs +99 -1
- package/dist/src/lib/control-flow.cjs +35 -1
- package/dist/src/lib/control-flow.mjs +25 -1
- package/dist/src/lib/core.cjs +1279 -1
- package/dist/src/lib/core.d.ts +0 -2
- package/dist/src/lib/core.d.ts.map +1 -1
- package/dist/src/lib/core.js +14 -48
- package/dist/src/lib/core.mjs +1393 -1
- package/dist/src/lib/env/index.cjs +60 -1
- package/dist/src/lib/env/index.d.ts +5 -5
- package/dist/src/lib/env/index.js +5 -5
- package/dist/src/lib/env/index.mjs +39 -1
- package/dist/src/lib/i18n/index.cjs +108 -1
- package/dist/src/lib/i18n/index.d.ts +31 -10
- package/dist/src/lib/i18n/index.d.ts.map +1 -1
- package/dist/src/lib/i18n/index.js +31 -10
- package/dist/src/lib/i18n/index.mjs +88 -1
- package/dist/src/lib/index.cjs +633 -1
- package/dist/src/lib/index.d.ts +0 -2
- package/dist/src/lib/index.d.ts.map +1 -1
- package/dist/src/lib/index.js +5 -11
- package/dist/src/lib/index.mjs +721 -1
- package/dist/src/lib/isomorphic.cjs +85 -1
- package/dist/src/lib/isomorphic.d.ts +41 -8
- package/dist/src/lib/isomorphic.d.ts.map +1 -1
- package/dist/src/lib/isomorphic.js +38 -5
- package/dist/src/lib/isomorphic.mjs +64 -1
- package/dist/src/lib/jsx-runtime/index.cjs +21 -1
- package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
- package/dist/src/lib/jsx-runtime/index.js +1 -11
- package/dist/src/lib/jsx-runtime/index.mjs +4 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
- package/dist/src/lib/plugins/index.cjs +311 -8
- package/dist/src/lib/plugins/index.mjs +279 -8
- package/dist/src/lib/plugins/route-codegen.cjs +73 -8
- package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
- package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-codegen.js +4 -5
- package/dist/src/lib/plugins/route-codegen.mjs +52 -8
- package/dist/src/lib/plugins/route-scanner.cjs +189 -1
- package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
- package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-scanner.js +7 -8
- package/dist/src/lib/plugins/route-scanner.mjs +158 -1
- package/dist/src/lib/plugins/vite.cjs +27 -1
- package/dist/src/lib/plugins/vite.mjs +6 -1
- package/dist/src/lib/render/await.cjs +38 -1
- package/dist/src/lib/render/await.d.ts +18 -0
- package/dist/src/lib/render/await.d.ts.map +1 -1
- package/dist/src/lib/render/await.js +20 -2
- package/dist/src/lib/render/await.mjs +17 -1
- package/dist/src/lib/render/component.cjs +221 -1
- package/dist/src/lib/render/component.d.ts +3 -44
- package/dist/src/lib/render/component.d.ts.map +1 -1
- package/dist/src/lib/render/component.js +23 -55
- package/dist/src/lib/render/component.mjs +214 -1
- package/dist/src/lib/render/deferred.cjs +175 -1
- package/dist/src/lib/render/deferred.js +5 -5
- package/dist/src/lib/render/deferred.mjs +158 -1
- package/dist/src/lib/render/index.cjs +573 -1
- package/dist/src/lib/render/index.d.ts +3 -17
- package/dist/src/lib/render/index.d.ts.map +1 -1
- package/dist/src/lib/render/index.js +8 -22
- package/dist/src/lib/render/index.mjs +590 -1
- package/dist/src/lib/render/lazy.cjs +67 -1
- package/dist/src/lib/render/lazy.d.ts +22 -1
- package/dist/src/lib/render/lazy.d.ts.map +1 -1
- package/dist/src/lib/render/lazy.js +26 -5
- package/dist/src/lib/render/lazy.mjs +50 -1
- package/dist/src/lib/render/suspense.cjs +141 -1
- package/dist/src/lib/render/suspense.d.ts +40 -0
- package/dist/src/lib/render/suspense.d.ts.map +1 -1
- package/dist/src/lib/render/suspense.js +46 -6
- package/dist/src/lib/render/suspense.mjs +136 -1
- package/dist/src/lib/render/versions.cjs +35 -1
- package/dist/src/lib/render/versions.js +6 -6
- package/dist/src/lib/render/versions.mjs +14 -1
- package/dist/src/lib/router/data.cjs +230 -1
- package/dist/src/lib/router/data.d.ts +1 -13
- package/dist/src/lib/router/data.d.ts.map +1 -1
- package/dist/src/lib/router/data.js +0 -12
- package/dist/src/lib/router/data.mjs +214 -1
- package/dist/src/lib/router/index.cjs +709 -1
- package/dist/src/lib/router/index.d.ts +78 -23
- package/dist/src/lib/router/index.d.ts.map +1 -1
- package/dist/src/lib/router/index.js +161 -37
- package/dist/src/lib/router/index.mjs +722 -1
- package/dist/src/lib/router/transition.cjs +75 -0
- package/dist/src/lib/router/transition.d.ts +81 -0
- package/dist/src/lib/router/transition.d.ts.map +1 -0
- package/dist/src/lib/router/transition.js +136 -0
- package/dist/src/lib/router/transition.mjs +54 -0
- package/dist/src/lib/server/hydration.cjs +169 -1
- package/dist/src/lib/server/hydration.d.ts +15 -55
- package/dist/src/lib/server/hydration.d.ts.map +1 -1
- package/dist/src/lib/server/hydration.js +23 -62
- package/dist/src/lib/server/hydration.mjs +148 -1
- package/dist/src/lib/server/index.cjs +401 -11
- package/dist/src/lib/server/index.d.ts +30 -6
- package/dist/src/lib/server/index.d.ts.map +1 -1
- package/dist/src/lib/server/index.js +34 -11
- package/dist/src/lib/server/index.mjs +379 -11
- package/dist/src/lib/server/reactive.cjs +197 -1
- package/dist/src/lib/server/reactive.d.ts +18 -77
- package/dist/src/lib/server/reactive.d.ts.map +1 -1
- package/dist/src/lib/server/reactive.js +19 -78
- package/dist/src/lib/server/reactive.mjs +176 -1
- package/dist/src/lib/theme/index.cjs +110 -1
- package/dist/src/lib/theme/index.d.ts +19 -4
- package/dist/src/lib/theme/index.d.ts.map +1 -1
- package/dist/src/lib/theme/index.js +17 -2
- package/dist/src/lib/theme/index.mjs +89 -1
- package/dist/src/lib/utils/index.cjs +209 -1
- package/dist/src/lib/utils/index.d.ts +0 -93
- package/dist/src/lib/utils/index.d.ts.map +1 -1
- package/dist/src/lib/utils/index.js +0 -93
- package/dist/src/lib/utils/index.mjs +188 -1
- package/dist/src/routes.cjs +37 -1
- package/dist/src/routes.d.ts +1 -1
- package/dist/src/routes.js +2 -2
- package/dist/src/routes.mjs +17 -1
- package/dist/src/server.cjs +400 -11
- package/dist/src/server.d.ts +0 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +0 -1
- package/dist/src/server.mjs +377 -11
- package/dist/src/utils.cjs +21 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.mjs +4 -1
- package/dist/src/version.generated.cjs +26 -1
- package/dist/src/version.generated.d.ts +1 -1
- package/dist/src/version.generated.js +2 -2
- package/dist/src/version.generated.mjs +5 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/index.ts +2 -14
- package/dist/src/cdn/chunk-55BT3H6E.mjs +0 -1
- package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
- package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
- package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
|
@@ -1 +1,110 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
|
3
|
-
* theme workflow (detect
|
|
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
|
|
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
|
|
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;;;;;;;;GAQG;AACH,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGtE,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM;IAC5C,uEAAuE;IACvE,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;IACrB,6EAA6E;IAC7E,OAAO,EAAE,CAAC,CAAC;IACX,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,CAAC;IACzC,2FAA2F;IAC3F,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,sCAAsC;IACtC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,CAAC;IAClD,oDAAoD;IACpD,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC/B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,MAAM;IACrC,8BAA8B;IAC9B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/theme/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGtE,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM;IAC5C,uEAAuE;IACvE,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;IACrB,6EAA6E;IAC7E,OAAO,EAAE,CAAC,CAAC;IACX,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,CAAC;IACzC,2FAA2F;IAC3F,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,sCAAsC;IACtC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,CAAC;IAClD,oDAAoD;IACpD,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC/B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,MAAM;IACrC,8BAA8B;IAC9B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnB,uDAAuD;IACvD,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC7B,mEAAmE;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
|
|
3
|
-
* theme workflow (detect
|
|
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
|
-
|
|
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";
|
|
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
|
+
}
|