@fluixi/core 1.0.0-alpha.92 → 1.0.0-alpha.93
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 -2
- package/dist/src/cdn/{chunk-MDJLC3PE.mjs → chunk-7XM7Q5VR.mjs} +271 -229
- package/dist/src/cdn/core.cjs +360 -253
- package/dist/src/cdn/core.mjs +92 -20
- package/dist/src/cdn/{router-JYFZP3EZ.mjs → router-VOY43YNM.mjs} +7 -3
- package/dist/src/index.cjs +547 -232
- package/dist/src/index.mjs +547 -223
- package/dist/src/lib/client/chunk-QT3RFKH6.mjs +53 -0
- package/dist/src/lib/client/index.cjs +310 -176
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +33 -18
- package/dist/src/lib/client/index.mjs +86 -15
- package/dist/src/lib/client/{router-PHLUYVQU.mjs → router-ADTS55OP.mjs} +244 -99
- package/dist/src/lib/context/context.cjs +35 -72
- package/dist/src/lib/context/context.d.ts +45 -291
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +65 -397
- package/dist/src/lib/context/context.mjs +38 -73
- package/dist/src/lib/context/index.cjs +35 -72
- package/dist/src/lib/context/index.d.ts +2 -2
- package/dist/src/lib/context/index.d.ts.map +1 -1
- package/dist/src/lib/context/index.js +1 -5
- package/dist/src/lib/context/index.mjs +38 -73
- package/dist/src/lib/core.cjs +546 -231
- package/dist/src/lib/core.d.ts +3 -1
- package/dist/src/lib/core.d.ts.map +1 -1
- package/dist/src/lib/core.js +5 -3
- package/dist/src/lib/core.mjs +546 -222
- package/dist/src/lib/env/index.cjs +1 -17
- package/dist/src/lib/env/index.d.ts +2 -14
- package/dist/src/lib/env/index.d.ts.map +1 -1
- package/dist/src/lib/env/index.js +2 -26
- package/dist/src/lib/env/index.mjs +1 -17
- package/dist/src/lib/i18n/index.cjs +17 -2
- package/dist/src/lib/i18n/index.d.ts +10 -0
- package/dist/src/lib/i18n/index.d.ts.map +1 -1
- package/dist/src/lib/i18n/index.js +17 -1
- package/dist/src/lib/i18n/index.mjs +17 -2
- package/dist/src/lib/index.cjs +64 -99
- package/dist/src/lib/index.mjs +43 -76
- package/dist/src/lib/isomorphic.cjs +9 -4
- package/dist/src/lib/isomorphic.d.ts +9 -2
- package/dist/src/lib/isomorphic.d.ts.map +1 -1
- package/dist/src/lib/isomorphic.js +11 -4
- package/dist/src/lib/isomorphic.mjs +9 -4
- package/dist/src/lib/jsx-runtime/index.cjs +1 -1
- package/dist/src/lib/jsx-runtime/index.mjs +1 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +1 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +1 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +2 -2
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +2 -2
- package/dist/src/lib/plugins/index.cjs +3 -3
- package/dist/src/lib/plugins/index.mjs +3 -3
- package/dist/src/lib/plugins/route-codegen.cjs +2 -2
- package/dist/src/lib/plugins/route-codegen.js +1 -1
- package/dist/src/lib/plugins/route-codegen.mjs +2 -2
- package/dist/src/lib/render/index.cjs +1 -1
- package/dist/src/lib/render/index.mjs +1 -1
- package/dist/src/lib/render/versions.cjs +1 -1
- package/dist/src/lib/render/versions.mjs +1 -1
- package/dist/src/lib/router/data.cjs +113 -115
- package/dist/src/lib/router/data.d.ts +63 -10
- package/dist/src/lib/router/data.d.ts.map +1 -1
- package/dist/src/lib/router/data.js +158 -68
- package/dist/src/lib/router/data.mjs +112 -112
- package/dist/src/lib/router/index.cjs +260 -163
- package/dist/src/lib/router/index.d.ts +22 -2
- package/dist/src/lib/router/index.d.ts.map +1 -1
- package/dist/src/lib/router/index.js +165 -22
- package/dist/src/lib/router/index.mjs +244 -143
- package/dist/src/lib/server/index.cjs +1 -1
- package/dist/src/lib/server/index.mjs +1 -1
- package/dist/src/lib/storage/cache.cjs +51 -0
- package/dist/src/lib/storage/cache.d.ts +18 -0
- package/dist/src/lib/storage/cache.d.ts.map +1 -0
- package/dist/src/lib/storage/cache.js +42 -0
- package/dist/src/lib/storage/cache.mjs +30 -0
- package/dist/src/lib/storage/index.cjs +246 -0
- package/dist/src/lib/storage/index.d.ts +83 -0
- package/dist/src/lib/storage/index.d.ts.map +1 -0
- package/dist/src/lib/storage/index.js +179 -0
- package/dist/src/lib/storage/index.mjs +231 -0
- package/dist/src/lib/storage/persisted.cjs +91 -0
- package/dist/src/lib/storage/persisted.d.ts +53 -0
- package/dist/src/lib/storage/persisted.d.ts.map +1 -0
- package/dist/src/lib/storage/persisted.js +75 -0
- package/dist/src/lib/storage/persisted.mjs +70 -0
- package/dist/src/lib/theme/color-scheme.cjs +281 -0
- package/dist/src/lib/theme/color-scheme.d.ts +61 -0
- package/dist/src/lib/theme/color-scheme.d.ts.map +1 -0
- package/dist/src/lib/theme/color-scheme.js +120 -0
- package/dist/src/lib/theme/color-scheme.mjs +265 -0
- package/dist/src/lib/theme/index.cjs +194 -37
- package/dist/src/lib/theme/index.d.ts +23 -11
- package/dist/src/lib/theme/index.d.ts.map +1 -1
- package/dist/src/lib/theme/index.js +73 -32
- package/dist/src/lib/theme/index.mjs +197 -35
- package/dist/src/lib/theme/provider.cjs +346 -0
- package/dist/src/lib/theme/provider.d.ts +34 -0
- package/dist/src/lib/theme/provider.d.ts.map +1 -0
- package/dist/src/lib/theme/provider.js +60 -0
- package/dist/src/lib/theme/provider.mjs +332 -0
- package/dist/src/routes.cjs +1 -1
- package/dist/src/routes.mjs +1 -1
- package/dist/src/utils.cjs +1 -1
- package/dist/src/utils.mjs +1 -1
- package/dist/src/version.generated.cjs +1 -1
- package/dist/src/version.generated.d.ts +1 -1
- package/dist/src/version.generated.js +1 -1
- package/dist/src/version.generated.mjs +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +18 -11
- package/dist/src/lib/client/chunk-VB567ABU.mjs +0 -133
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// src/lib/context/context.ts
|
|
2
|
+
import { asProvider } from "@fluixi/dom";
|
|
3
|
+
import {
|
|
4
|
+
createContext as createReactiveContext,
|
|
5
|
+
getOwner,
|
|
6
|
+
useContext as useReactiveContext
|
|
7
|
+
} from "@fluixi/reactive/signal";
|
|
8
|
+
function createContext(defaultValue, name) {
|
|
9
|
+
const context = createReactiveContext(defaultValue, name);
|
|
10
|
+
const Provider = (props) => (
|
|
11
|
+
// Children stay a getter: the reactive Provider reads them after stamping the value on
|
|
12
|
+
// its owner. Reading `props.children` here would render them, and any <Outlet/> in them,
|
|
13
|
+
// before the context exists.
|
|
14
|
+
context.Provider({
|
|
15
|
+
value: props.value,
|
|
16
|
+
get children() {
|
|
17
|
+
return props.children;
|
|
18
|
+
},
|
|
19
|
+
debug: props.debug
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
return {
|
|
23
|
+
id: context.id,
|
|
24
|
+
Provider: asProvider(Provider),
|
|
25
|
+
defaultValue
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function useContext(context) {
|
|
29
|
+
const value = useReactiveContext(context);
|
|
30
|
+
return value !== void 0 ? value : context.defaultValue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/lib/theme/color-scheme.ts
|
|
34
|
+
import { getActiveHead as getActiveHead2, useHead as useHead2 } from "@fluixi/head";
|
|
35
|
+
import { createEffect, createSignal as createSignal2, getOwner as getOwner3, onCleanup as onCleanup2 } from "@fluixi/reactive/signal";
|
|
36
|
+
|
|
37
|
+
// src/lib/env/index.ts
|
|
38
|
+
import { isServer } from "@fluixi/dom";
|
|
39
|
+
import { isServer as onServer } from "@fluixi/dom";
|
|
40
|
+
var env = {
|
|
41
|
+
get window() {
|
|
42
|
+
return typeof window !== "undefined" ? window : void 0;
|
|
43
|
+
},
|
|
44
|
+
get document() {
|
|
45
|
+
return typeof document !== "undefined" ? document : void 0;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/lib/storage/persisted.ts
|
|
50
|
+
import { getOwner as getOwner2, onCleanup, signal, untrack } from "@fluixi/reactive/signal";
|
|
51
|
+
var isAsync = (storage) => "encryption" in storage;
|
|
52
|
+
function persisted(storage, key, options = {}) {
|
|
53
|
+
const fallback = options.fallback ?? null;
|
|
54
|
+
const name = options.name ?? `storage:${storage.keyPrefix}${key}`;
|
|
55
|
+
const state = signal(isAsync(storage) ? fallback : storage.get(key) ?? fallback, { name });
|
|
56
|
+
const put = (value) => state.set(() => value);
|
|
57
|
+
const resolve = (next) => typeof next === "function" ? next(untrack(state)) : next;
|
|
58
|
+
const writeOptions = (extra) => ({
|
|
59
|
+
...options.ttl !== void 0 ? { ttl: options.ttl } : {},
|
|
60
|
+
...options.encrypt ? { encrypt: true } : {},
|
|
61
|
+
...extra
|
|
62
|
+
});
|
|
63
|
+
if (!isAsync(storage)) {
|
|
64
|
+
const off2 = storage.subscribe(key, (event) => {
|
|
65
|
+
if (event.type !== "set") return put(fallback);
|
|
66
|
+
if (event.value !== void 0) put(event.value);
|
|
67
|
+
});
|
|
68
|
+
if (getOwner2()) onCleanup(off2);
|
|
69
|
+
return Object.assign(() => state(), {
|
|
70
|
+
set(next, extra) {
|
|
71
|
+
const value = resolve(next);
|
|
72
|
+
storage.set(key, value, writeOptions(extra));
|
|
73
|
+
put(value);
|
|
74
|
+
},
|
|
75
|
+
remove() {
|
|
76
|
+
storage.remove(key);
|
|
77
|
+
put(fallback);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
let written = false;
|
|
82
|
+
const reread = () => storage.get(key).then(
|
|
83
|
+
(value) => put(value ?? fallback),
|
|
84
|
+
() => void 0
|
|
85
|
+
);
|
|
86
|
+
const off = storage.subscribe(key, (event) => {
|
|
87
|
+
if (event.type !== "set") return put(fallback);
|
|
88
|
+
if (event.value !== void 0) put(event.value);
|
|
89
|
+
else void reread();
|
|
90
|
+
});
|
|
91
|
+
if (getOwner2()) onCleanup(off);
|
|
92
|
+
const ready = storage.get(key).then((value) => {
|
|
93
|
+
if (!written) put(value ?? fallback);
|
|
94
|
+
});
|
|
95
|
+
return Object.assign(() => state(), {
|
|
96
|
+
ready,
|
|
97
|
+
async set(next, extra) {
|
|
98
|
+
const previous = untrack(state);
|
|
99
|
+
const value = resolve(next);
|
|
100
|
+
written = true;
|
|
101
|
+
put(value);
|
|
102
|
+
try {
|
|
103
|
+
await storage.set(key, value, writeOptions(extra));
|
|
104
|
+
} catch (error) {
|
|
105
|
+
put(previous);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
async remove() {
|
|
110
|
+
written = true;
|
|
111
|
+
await storage.remove(key);
|
|
112
|
+
put(fallback);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/lib/theme/index.ts
|
|
118
|
+
import { getActiveHead, useHead } from "@fluixi/head";
|
|
119
|
+
import { createSignal } from "@fluixi/reactive/signal";
|
|
120
|
+
import { StorageUnavailableError as StorageUnavailableError2 } from "@fluixi/storage";
|
|
121
|
+
|
|
122
|
+
// src/lib/storage/index.ts
|
|
123
|
+
import { appendResponseHeader, getRequestContext, getServerData } from "@fluixi/dom";
|
|
124
|
+
import { createContext as createContext2, useContext as useContext2 } from "@fluixi/reactive/signal";
|
|
125
|
+
import {
|
|
126
|
+
createAsyncStorage,
|
|
127
|
+
createSyncStorage,
|
|
128
|
+
memoryStorage,
|
|
129
|
+
StorageUnavailableError
|
|
130
|
+
} from "@fluixi/storage";
|
|
131
|
+
import { documentCookieAdapter, localStorageAdapter, sessionStorageAdapter } from "@fluixi/storage/browser";
|
|
132
|
+
import { cookieStorage, requestStorage, toStorageRequest } from "@fluixi/storage/server";
|
|
133
|
+
var StorageContext = createContext2(void 0, "storage");
|
|
134
|
+
var AsyncStorageContext = createContext2(void 0, "asyncStorage");
|
|
135
|
+
var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
|
|
136
|
+
var perRequest = /* @__PURE__ */ new WeakMap();
|
|
137
|
+
var perPage = /* @__PURE__ */ new Map();
|
|
138
|
+
function cached(scope, id, make) {
|
|
139
|
+
let adapter = scope.get(id);
|
|
140
|
+
if (!adapter) scope.set(id, adapter = make());
|
|
141
|
+
return adapter;
|
|
142
|
+
}
|
|
143
|
+
function requestRequired(scope) {
|
|
144
|
+
throw new StorageUnavailableError(
|
|
145
|
+
`useStorage({ scope: '${scope}' }) on the server needs a request: call it during a render, a loader or a server function, or provide a storage with <StorageProvider>.`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
function adapterFor(scope, cookie = {}) {
|
|
149
|
+
const ctx = getRequestContext();
|
|
150
|
+
const options = { httpOnly: false, ...cookie };
|
|
151
|
+
switch (scope) {
|
|
152
|
+
case "local":
|
|
153
|
+
return localStorageAdapter();
|
|
154
|
+
case "session":
|
|
155
|
+
return sessionStorageAdapter();
|
|
156
|
+
case "request":
|
|
157
|
+
if (isBrowser()) return cached(perPage, "request", memoryStorage);
|
|
158
|
+
if (!ctx) requestRequired(scope);
|
|
159
|
+
return cached(perRequest.get(ctx) ?? perRequest.set(ctx, /* @__PURE__ */ new Map()).get(ctx), "request", requestStorage);
|
|
160
|
+
case "cookie": {
|
|
161
|
+
const id = `cookie:${JSON.stringify(options)}`;
|
|
162
|
+
if (isBrowser()) {
|
|
163
|
+
const { httpOnly: _ignored, ...browser } = options;
|
|
164
|
+
return cached(perPage, id, () => documentCookieAdapter(browser));
|
|
165
|
+
}
|
|
166
|
+
if (!ctx) requestRequired(scope);
|
|
167
|
+
const raw = ctx.event.request;
|
|
168
|
+
const target = raw && typeof raw === "object" ? raw : void 0;
|
|
169
|
+
return cached(
|
|
170
|
+
perRequest.get(ctx) ?? perRequest.set(ctx, /* @__PURE__ */ new Map()).get(ctx),
|
|
171
|
+
id,
|
|
172
|
+
() => cookieStorage({
|
|
173
|
+
...options,
|
|
174
|
+
request: raw && typeof raw === "object" && ("headers" in raw || "getHeader" in raw) ? toStorageRequest(raw) : void 0,
|
|
175
|
+
response: {
|
|
176
|
+
appendHeader(name, value) {
|
|
177
|
+
if (!appendResponseHeader(name, value, target)) {
|
|
178
|
+
throw new StorageUnavailableError("The response headers were already sent, so this cookie cannot reach the browser. Write it before the page head goes out: in middleware, a loader, a server function or the render before its first chunk.");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function useStorage(options = {}) {
|
|
188
|
+
const { scope = "auto", cookie, ...storageOptions } = options;
|
|
189
|
+
if (scope === "auto") {
|
|
190
|
+
const provided = useContext2(StorageContext);
|
|
191
|
+
if (provided) return options.namespace ? provided.namespace(options.namespace) : provided;
|
|
192
|
+
}
|
|
193
|
+
return createSyncStorage({ ...storageOptions, adapter: resolveAdapter(scope, cookie) });
|
|
194
|
+
}
|
|
195
|
+
function resolveAdapter(scope, cookie) {
|
|
196
|
+
if (scope !== "auto") return adapterFor(scope, cookie);
|
|
197
|
+
if (isBrowser()) return adapterFor("local");
|
|
198
|
+
if (!getRequestContext()) requestRequired(scope);
|
|
199
|
+
return adapterFor("request");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/lib/theme/index.ts
|
|
203
|
+
var YEAR = 60 * 60 * 24 * 365;
|
|
204
|
+
function defaultStorage() {
|
|
205
|
+
try {
|
|
206
|
+
return useStorage({ scope: "cookie", cookie: { maxAge: YEAR, sameSite: "lax" } });
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (error instanceof StorageUnavailableError2) return null;
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function storedLookup(storage, key) {
|
|
213
|
+
if (!storage) return null;
|
|
214
|
+
const full = storage.keyPrefix + key;
|
|
215
|
+
if (storage.scope === "cookie") {
|
|
216
|
+
return { from: "cookie", name: encodeURIComponent(full).replace(/[()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`) };
|
|
217
|
+
}
|
|
218
|
+
if (storage.scope === "local") return { from: "local", name: full };
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/lib/theme/color-scheme.ts
|
|
223
|
+
var CHOICES = ["system", "light", "dark"];
|
|
224
|
+
var DARK = "(prefers-color-scheme: dark)";
|
|
225
|
+
function createColorScheme(options = {}) {
|
|
226
|
+
const storageKey = options.storageKey ?? "color-scheme";
|
|
227
|
+
const attribute = options.attribute ?? "data-theme";
|
|
228
|
+
const systemAs = options.systemAs ?? "resolved";
|
|
229
|
+
const storage = options.storage === void 0 ? defaultStorage() : options.storage;
|
|
230
|
+
const saved = storage ? persisted(storage, storageKey) : null;
|
|
231
|
+
const [unsaved, setUnsaved] = createSignal2(null);
|
|
232
|
+
const value = () => {
|
|
233
|
+
const local = unsaved();
|
|
234
|
+
if (local) return local;
|
|
235
|
+
const stored = saved?.();
|
|
236
|
+
return CHOICES.includes(stored) ? stored : "system";
|
|
237
|
+
};
|
|
238
|
+
const media = env.window?.matchMedia?.(DARK);
|
|
239
|
+
const [osDark, setOsDark] = createSignal2(media?.matches ?? false);
|
|
240
|
+
if (media) {
|
|
241
|
+
const onChange = () => setOsDark(media.matches);
|
|
242
|
+
media.addEventListener?.("change", onChange);
|
|
243
|
+
if (getOwner3()) onCleanup2(() => media.removeEventListener?.("change", onChange));
|
|
244
|
+
}
|
|
245
|
+
const resolved = () => {
|
|
246
|
+
const choice = value();
|
|
247
|
+
return choice === "system" ? osDark() ? "dark" : "light" : choice;
|
|
248
|
+
};
|
|
249
|
+
const shown = () => systemAs === "system" && value() === "system" ? "system" : resolved();
|
|
250
|
+
const apply = () => {
|
|
251
|
+
env.document?.documentElement.setAttribute(attribute, shown());
|
|
252
|
+
};
|
|
253
|
+
const set = (choice) => {
|
|
254
|
+
if (!CHOICES.includes(choice)) return;
|
|
255
|
+
if (!saved) setUnsaved(choice);
|
|
256
|
+
else {
|
|
257
|
+
try {
|
|
258
|
+
saved.set(choice);
|
|
259
|
+
setUnsaved(null);
|
|
260
|
+
} catch {
|
|
261
|
+
setUnsaved(choice);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
apply();
|
|
265
|
+
options.onChange?.(choice);
|
|
266
|
+
};
|
|
267
|
+
const scriptBody = () => {
|
|
268
|
+
const cfg = JSON.stringify({ s: storedLookup(storage, storageKey), a: attribute, sys: systemAs === "system", tc: options.themeColor ?? null, cs: options.colorSchemeMeta !== false }).replace(/</g, "\\u003c");
|
|
269
|
+
return `(function(){try{var c=${cfg},t=null,s=c.s,r=null;if(s&&s.from==='local')r=localStorage.getItem(s.name);if(s&&s.from==='cookie')document.cookie.split('; ').forEach(function(p){var i=p.indexOf('=');if(p.slice(0,i)===s.name)r=decodeURIComponent(p.slice(i+1));});if(r){var e=JSON.parse(r);t=e&&e.v===1?e.value:e;}var chosen=t==='light'||t==='dark'?t:null;if(!chosen)t=c.sys?'system':(matchMedia('${DARK}').matches?'dark':'light');document.documentElement.setAttribute(c.a,t);if(chosen&&c.tc)document.querySelectorAll('meta[name="theme-color"]').forEach(function(m){m.setAttribute('content',c.tc[chosen]);m.removeAttribute('media');});if(chosen&&c.cs){var m=document.querySelector('meta[name="color-scheme"]');if(m)m.setAttribute('content',chosen);}}catch(e){}})();`;
|
|
270
|
+
};
|
|
271
|
+
if (getActiveHead2()) {
|
|
272
|
+
const colors = options.themeColor;
|
|
273
|
+
useHead2({
|
|
274
|
+
htmlAttrs: { [attribute]: shown },
|
|
275
|
+
...colors ? {
|
|
276
|
+
themeColor: () => value() === "system" ? [
|
|
277
|
+
{ color: colors.light, media: "(prefers-color-scheme: light)" },
|
|
278
|
+
{ color: colors.dark, media: DARK }
|
|
279
|
+
] : colors[resolved()]
|
|
280
|
+
} : {},
|
|
281
|
+
...options.colorSchemeMeta === false ? {} : { colorScheme: () => value() === "system" ? "light dark" : resolved() },
|
|
282
|
+
...options.script === false ? {} : { script: [{ children: scriptBody() }] }
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
if (env.document && getOwner3()) createEffect(apply);
|
|
286
|
+
return {
|
|
287
|
+
value,
|
|
288
|
+
resolved,
|
|
289
|
+
set,
|
|
290
|
+
toggle: () => set(resolved() === "dark" ? "light" : "dark"),
|
|
291
|
+
init: apply,
|
|
292
|
+
headScript: () => `<script>${scriptBody()}<\/script>`
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/lib/theme/provider.ts
|
|
297
|
+
var ThemesContext = createContext(void 0, "themes");
|
|
298
|
+
function ThemeProvider(props) {
|
|
299
|
+
const outer = useContext(ThemesContext);
|
|
300
|
+
return ThemesContext.Provider({
|
|
301
|
+
// A nested provider adds to the axes above it rather than hiding them.
|
|
302
|
+
value: outer ? { ...outer, ...props.themes } : props.themes,
|
|
303
|
+
get children() {
|
|
304
|
+
return props.children;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
function useTheme(name) {
|
|
309
|
+
const themes = useContext(ThemesContext);
|
|
310
|
+
if (!themes || !(name in themes)) {
|
|
311
|
+
throw new Error(`[fluixi] No theme named "${name}" above this component: provide it with <ThemeProvider> or <ColorSchemeProvider>.`);
|
|
312
|
+
}
|
|
313
|
+
return themes[name];
|
|
314
|
+
}
|
|
315
|
+
function ColorSchemeProvider(props) {
|
|
316
|
+
const scheme = createColorScheme(props);
|
|
317
|
+
return ThemeProvider({
|
|
318
|
+
themes: { scheme },
|
|
319
|
+
get children() {
|
|
320
|
+
return props.children;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
function useColorScheme() {
|
|
325
|
+
return useTheme("scheme");
|
|
326
|
+
}
|
|
327
|
+
export {
|
|
328
|
+
ColorSchemeProvider,
|
|
329
|
+
ThemeProvider,
|
|
330
|
+
useColorScheme,
|
|
331
|
+
useTheme
|
|
332
|
+
};
|
package/dist/src/routes.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fluixi/core v1.0.0-alpha.
|
|
1
|
+
/*! @fluixi/core v1.0.0-alpha.93 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
package/dist/src/routes.mjs
CHANGED
package/dist/src/utils.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fluixi/core v1.0.0-alpha.
|
|
1
|
+
/*! @fluixi/core v1.0.0-alpha.93 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
package/dist/src/utils.mjs
CHANGED