@farm.js/core 0.1.0-beta.22 → 0.1.0-beta.24
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/agent-runtime.d.mts +2 -1
- package/dist/agent-runtime.d.ts +2 -1
- package/dist/{app-DwsTpyNZ.d.mts → app-DrFCUMHY.d.mts} +6 -3
- package/dist/app-markdown.d.mts +2 -1
- package/dist/app-markdown.d.ts +2 -1
- package/dist/{app-BB8GCH1g.d.ts → app-pwvKG2B1.d.ts} +6 -3
- package/dist/chunk-4IVNW5QD.mjs +82 -0
- package/dist/chunk-4IVNW5QD.mjs.map +1 -0
- package/dist/chunk-D42BNPZH.mjs +79 -0
- package/dist/chunk-D42BNPZH.mjs.map +1 -0
- package/dist/{chunk-LLPN5SEZ.mjs → chunk-DVPRBMU2.mjs} +2 -2
- package/dist/chunk-GQVQESLY.mjs +25 -0
- package/dist/chunk-GQVQESLY.mjs.map +1 -0
- package/dist/chunk-H53KVQUU.mjs +48 -0
- package/dist/chunk-H53KVQUU.mjs.map +1 -0
- package/dist/chunk-HCGQYYHI.mjs +1 -0
- package/dist/chunk-HCGQYYHI.mjs.map +1 -0
- package/dist/{chunk-XBKXKJX5.mjs → chunk-HVJHNKSP.mjs} +220 -63
- package/dist/chunk-HVJHNKSP.mjs.map +1 -0
- package/dist/{chunk-ZP73P4VR.mjs → chunk-HXE4VGH2.mjs} +79 -20
- package/dist/chunk-HXE4VGH2.mjs.map +1 -0
- package/dist/{chunk-UCYWGN2P.mjs → chunk-OHNSROHS.mjs} +1 -1
- package/dist/{chunk-FRPWCMMG.mjs → chunk-SBWOTAX4.mjs} +63 -2
- package/dist/chunk-SBWOTAX4.mjs.map +1 -0
- package/dist/{chunk-DAUR3WUZ.mjs → chunk-WO466YX5.mjs} +2 -2
- package/dist/chunk-WO466YX5.mjs.map +1 -0
- package/dist/{chunk-CEVMYGDL.mjs → chunk-YD5IRKVS.mjs} +13 -9
- package/dist/chunk-YD5IRKVS.mjs.map +1 -0
- package/dist/{client-plugins-QQntVkrv.d.mts → client-plugins-CCilIb_G.d.mts} +6 -2
- package/dist/{client-plugins-CbRum1fj.d.ts → client-plugins-DuuleQKk.d.ts} +6 -2
- package/dist/client-plugins.d.mts +2 -1
- package/dist/client-plugins.d.ts +2 -1
- package/dist/client.cjs +122 -35
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.mts +2 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.mjs +13 -2
- package/dist/config.d.mts +2 -1
- package/dist/config.d.ts +2 -1
- package/dist/{devtools-52FYXIEK.mjs → devtools-326RBQCN.mjs} +7 -6
- package/dist/{devtools-52FYXIEK.mjs.map → devtools-326RBQCN.mjs.map} +1 -1
- package/dist/docs.cjs.map +1 -1
- package/dist/docs.mjs +6 -5
- package/dist/index.cjs +910 -414
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.mjs +66 -49
- package/dist/index.mjs.map +1 -1
- package/dist/integrations.d.mts +2 -1
- package/dist/integrations.d.ts +2 -1
- package/dist/internal/build-runtime.cjs +720 -297
- package/dist/internal/build-runtime.cjs.map +1 -1
- package/dist/internal/build-runtime.d.mts +4 -3
- package/dist/internal/build-runtime.d.ts +4 -3
- package/dist/internal/build-runtime.mjs +15 -12
- package/dist/internal/config-runtime.cjs +41 -0
- package/dist/internal/config-runtime.cjs.map +1 -1
- package/dist/internal/config-runtime.d.mts +3 -2
- package/dist/internal/config-runtime.d.ts +3 -2
- package/dist/internal/config-runtime.mjs +5 -4
- package/dist/internal/production-runtime.cjs +178 -0
- package/dist/internal/production-runtime.cjs.map +1 -1
- package/dist/internal/production-runtime.d.mts +20 -6
- package/dist/internal/production-runtime.d.ts +20 -6
- package/dist/internal/production-runtime.mjs +13 -1
- package/dist/internal/production-runtime.mjs.map +1 -1
- package/dist/{metadata-B5jBJHq1.d.ts → metadata-DyPRG0wX.d.ts} +1 -1
- package/dist/{metadata-BxOJ4FJl.d.mts → metadata-_GHcAySx.d.mts} +1 -1
- package/dist/middleware.d.mts +4 -3
- package/dist/middleware.d.ts +4 -3
- package/dist/plugin.cjs +461 -155
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.mts +2 -1
- package/dist/plugin.d.ts +2 -1
- package/dist/plugin.mjs +11 -8
- package/dist/{production-runtime-Bxua86uR.d.mts → production-runtime-C4cO3esK.d.mts} +1 -1
- package/dist/{production-runtime-CZqXjRVi.d.ts → production-runtime-DrEy8kBO.d.ts} +1 -1
- package/dist/{request-7V0GaZK_.d.mts → request-B2PpOxYK.d.mts} +1 -1
- package/dist/{request-B5XYBv5a.d.ts → request-D40lt6aN.d.ts} +1 -1
- package/dist/request.d.mts +3 -2
- package/dist/request.d.ts +3 -2
- package/dist/routes.d.mts +2 -1
- package/dist/routes.d.ts +2 -1
- package/dist/server-plugins.d.mts +3 -2
- package/dist/server-plugins.d.ts +3 -2
- package/dist/server.cjs +490 -167
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.mts +8 -6
- package/dist/server.d.ts +8 -6
- package/dist/server.mjs +20 -11
- package/dist/server.mjs.map +1 -1
- package/dist/testing.d.mts +2 -1
- package/dist/testing.d.ts +2 -1
- package/dist/theme/client.cjs +115 -0
- package/dist/theme/client.cjs.map +1 -0
- package/dist/theme/client.d.mts +17 -0
- package/dist/theme/client.d.ts +17 -0
- package/dist/theme/client.mjs +16 -0
- package/dist/theme/client.mjs.map +1 -0
- package/dist/theme/index.cjs +71 -0
- package/dist/theme/index.cjs.map +1 -0
- package/dist/theme/index.d.mts +6 -0
- package/dist/theme/index.d.ts +6 -0
- package/dist/theme/index.mjs +9 -0
- package/dist/theme/index.mjs.map +1 -0
- package/dist/theme/server.cjs +191 -0
- package/dist/theme/server.cjs.map +1 -0
- package/dist/theme/server.d.mts +8 -0
- package/dist/theme/server.d.ts +8 -0
- package/dist/theme/server.mjs +18 -0
- package/dist/theme/server.mjs.map +1 -0
- package/dist/types-CsR8fpgF.d.mts +30 -0
- package/dist/types-CsR8fpgF.d.ts +30 -0
- package/dist/{utils-xTFxzu47.d.ts → utils-3sQgfkya.d.ts} +1 -1
- package/dist/{utils-s9pN0Yep.d.mts → utils-Bop7bly-.d.mts} +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +485 -157
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.mts +2 -1
- package/dist/vite.d.ts +2 -1
- package/dist/vite.mjs +11 -8
- package/package.json +25 -1
- package/dist/chunk-CEVMYGDL.mjs.map +0 -1
- package/dist/chunk-DAUR3WUZ.mjs.map +0 -1
- package/dist/chunk-FRPWCMMG.mjs.map +0 -1
- package/dist/chunk-XBKXKJX5.mjs.map +0 -1
- package/dist/chunk-ZP73P4VR.mjs.map +0 -1
- /package/dist/{chunk-LLPN5SEZ.mjs.map → chunk-DVPRBMU2.mjs.map} +0 -0
- /package/dist/{chunk-UCYWGN2P.mjs.map → chunk-OHNSROHS.mjs.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { ai as loadConfig, ah as resolveConfig, aj as resolveDeployConfig } from '../client-plugins-
|
|
1
|
+
export { ai as loadConfig, ah as resolveConfig, aj as resolveDeployConfig } from '../client-plugins-CCilIb_G.mjs';
|
|
2
2
|
import { build, createServer, loadEnv } from 'vite';
|
|
3
|
-
export { l as logger } from '../utils-
|
|
3
|
+
export { l as logger } from '../utils-Bop7bly-.mjs';
|
|
4
4
|
import '../plugin-BJDf43dc.mjs';
|
|
5
5
|
import 'react';
|
|
6
6
|
import 'http';
|
|
@@ -21,6 +21,7 @@ import '../server-fn-error-DDh14a0V.mjs';
|
|
|
21
21
|
import '../image-config-Duob7wER.mjs';
|
|
22
22
|
import '../types-BMxWr97v.mjs';
|
|
23
23
|
import '../cache.mjs';
|
|
24
|
+
import '../types-CsR8fpgF.mjs';
|
|
24
25
|
import '../route-runtime-DoOHzCAD.mjs';
|
|
25
26
|
import '../font.mjs';
|
|
26
27
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { ai as loadConfig, ah as resolveConfig, aj as resolveDeployConfig } from '../client-plugins-
|
|
1
|
+
export { ai as loadConfig, ah as resolveConfig, aj as resolveDeployConfig } from '../client-plugins-DuuleQKk.js';
|
|
2
2
|
import { build, createServer, loadEnv } from 'vite';
|
|
3
|
-
export { l as logger } from '../utils-
|
|
3
|
+
export { l as logger } from '../utils-3sQgfkya.js';
|
|
4
4
|
import '../plugin-BJDf43dc.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
import 'http';
|
|
@@ -21,6 +21,7 @@ import '../server-fn-error-DDh14a0V.js';
|
|
|
21
21
|
import '../image-config-Duob7wER.js';
|
|
22
22
|
import '../types-BMxWr97v.js';
|
|
23
23
|
import '../cache.js';
|
|
24
|
+
import '../types-CsR8fpgF.js';
|
|
24
25
|
import '../route-runtime-DoOHzCAD.js';
|
|
25
26
|
import '../font.js';
|
|
26
27
|
|
|
@@ -5,20 +5,21 @@ import {
|
|
|
5
5
|
loadConfig,
|
|
6
6
|
resolveConfig,
|
|
7
7
|
resolveDeployConfig
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-YD5IRKVS.mjs";
|
|
9
9
|
import "../chunk-UVCIEUJC.mjs";
|
|
10
10
|
import "../chunk-RQ633A5I.mjs";
|
|
11
11
|
import "../chunk-E257KFBU.mjs";
|
|
12
12
|
import "../chunk-7MABZJIM.mjs";
|
|
13
13
|
import "../chunk-YW7OBE6Q.mjs";
|
|
14
14
|
import "../chunk-74YTBPTY.mjs";
|
|
15
|
-
import "../chunk-7ZVN3YZI.mjs";
|
|
16
15
|
import "../chunk-GY2STC2S.mjs";
|
|
16
|
+
import "../chunk-7ZVN3YZI.mjs";
|
|
17
|
+
import "../chunk-4E6VRJ6P.mjs";
|
|
18
|
+
import "../chunk-GXASWWJU.mjs";
|
|
17
19
|
import "../chunk-WORFTBLU.mjs";
|
|
20
|
+
import "../chunk-H53KVQUU.mjs";
|
|
18
21
|
import "../chunk-ZVWA4ZQ3.mjs";
|
|
19
22
|
import "../chunk-7FBJLMQH.mjs";
|
|
20
|
-
import "../chunk-4E6VRJ6P.mjs";
|
|
21
|
-
import "../chunk-GXASWWJU.mjs";
|
|
22
23
|
import "../chunk-CRN3AH35.mjs";
|
|
23
24
|
import "../chunk-QGOHVJ6J.mjs";
|
|
24
25
|
import "../chunk-FQYDHKKU.mjs";
|
|
@@ -25,8 +25,10 @@ __export(production_runtime_exports, {
|
|
|
25
25
|
_runWithCurrentRequest: () => _runWithCurrentRequest,
|
|
26
26
|
_runWithMiddlewareContext: () => _runWithMiddlewareContext,
|
|
27
27
|
_runWithMiddlewareData: () => _runWithMiddlewareData,
|
|
28
|
+
_setDefaultFarmThemeConfig: () => _setDefaultFarmThemeConfig,
|
|
28
29
|
addMetadataImageReference: () => addMetadataImageReference,
|
|
29
30
|
appendFarmLinkHeader: () => appendFarmLinkHeader,
|
|
31
|
+
applyFarmThemeDocument: () => applyFarmThemeDocument,
|
|
30
32
|
applyProductionMiddlewareHeaders: () => applyProductionMiddlewareHeaders,
|
|
31
33
|
bufferFarmRequestBody: () => bufferFarmRequestBody,
|
|
32
34
|
configureFarmCache: () => configureFarmCache,
|
|
@@ -35,12 +37,14 @@ __export(production_runtime_exports, {
|
|
|
35
37
|
createFarmLocaleCookie: () => createFarmLocaleCookie,
|
|
36
38
|
createFarmProductionLifecycle: () => createFarmProductionLifecycle,
|
|
37
39
|
createFarmRequestBodyErrorResponse: () => createFarmRequestBodyErrorResponse,
|
|
40
|
+
createFarmThemeDocumentParts: () => createFarmThemeDocumentParts,
|
|
38
41
|
createProductionMiddlewareRunner: () => createProductionMiddlewareRunner,
|
|
39
42
|
emitFarmEvent: () => emitFarmEvent,
|
|
40
43
|
getCurrentRequest: () => getCurrentRequest,
|
|
41
44
|
getFarmDataCache: () => getFarmDataCache,
|
|
42
45
|
getFarmLocaleVaryHeaders: () => getFarmLocaleVaryHeaders,
|
|
43
46
|
getFarmRedirectError: () => getFarmRedirectError,
|
|
47
|
+
getTheme: () => getTheme,
|
|
44
48
|
isFarmNotFoundError: () => isFarmNotFoundError,
|
|
45
49
|
isFarmRedirectError: () => isFarmRedirectError,
|
|
46
50
|
localizeFarmHref: () => localizeFarmHref,
|
|
@@ -2631,6 +2635,176 @@ function withFarmRouteContext(props, context) {
|
|
|
2631
2635
|
}
|
|
2632
2636
|
__name(withFarmRouteContext, "withFarmRouteContext");
|
|
2633
2637
|
|
|
2638
|
+
// src/theme/bridge.ts
|
|
2639
|
+
var FALLBACK_SERVER_SNAPSHOT = Object.freeze({
|
|
2640
|
+
theme: "system",
|
|
2641
|
+
resolvedTheme: void 0,
|
|
2642
|
+
mounted: false
|
|
2643
|
+
});
|
|
2644
|
+
var FARM_THEME_SERVER_SNAPSHOT_RESOLVER = /* @__PURE__ */ Symbol.for("farm.js.theme.server-snapshot-resolver");
|
|
2645
|
+
function _setFarmThemeServerSnapshotResolver(resolver) {
|
|
2646
|
+
globalThis[FARM_THEME_SERVER_SNAPSHOT_RESOLVER] = resolver;
|
|
2647
|
+
}
|
|
2648
|
+
__name(_setFarmThemeServerSnapshotResolver, "_setFarmThemeServerSnapshotResolver");
|
|
2649
|
+
|
|
2650
|
+
// src/theme/config.ts
|
|
2651
|
+
var DEFAULT_FARM_THEME_STORAGE_KEY = "farm-theme";
|
|
2652
|
+
var STORAGE_KEY_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
2653
|
+
function resolveFarmThemeConfig(config, basePath = "/") {
|
|
2654
|
+
if (config && "enabled" in config) {
|
|
2655
|
+
return config;
|
|
2656
|
+
}
|
|
2657
|
+
if (!config) {
|
|
2658
|
+
return {
|
|
2659
|
+
enabled: false,
|
|
2660
|
+
default: "system",
|
|
2661
|
+
storageKey: DEFAULT_FARM_THEME_STORAGE_KEY,
|
|
2662
|
+
cookiePath: normalizeCookiePath(basePath)
|
|
2663
|
+
};
|
|
2664
|
+
}
|
|
2665
|
+
const storageKey = config.storageKey?.trim() || DEFAULT_FARM_THEME_STORAGE_KEY;
|
|
2666
|
+
if (!STORAGE_KEY_PATTERN.test(storageKey)) {
|
|
2667
|
+
throw new Error(
|
|
2668
|
+
"theme.storageKey may only contain letters, numbers, dots, underscores, and hyphens."
|
|
2669
|
+
);
|
|
2670
|
+
}
|
|
2671
|
+
const defaultTheme = config.default ?? "system";
|
|
2672
|
+
if (defaultTheme !== "light" && defaultTheme !== "dark" && defaultTheme !== "system") {
|
|
2673
|
+
throw new Error('theme.default must be "light", "dark", or "system".');
|
|
2674
|
+
}
|
|
2675
|
+
return {
|
|
2676
|
+
enabled: true,
|
|
2677
|
+
default: defaultTheme,
|
|
2678
|
+
storageKey,
|
|
2679
|
+
cookiePath: normalizeCookiePath(basePath)
|
|
2680
|
+
};
|
|
2681
|
+
}
|
|
2682
|
+
__name(resolveFarmThemeConfig, "resolveFarmThemeConfig");
|
|
2683
|
+
function normalizeCookiePath(basePath) {
|
|
2684
|
+
const normalized = `/${basePath}`.replace(/\/{2,}/g, "/");
|
|
2685
|
+
if (normalized === "/") return normalized;
|
|
2686
|
+
return normalized.replace(/\/$/, "");
|
|
2687
|
+
}
|
|
2688
|
+
__name(normalizeCookiePath, "normalizeCookiePath");
|
|
2689
|
+
|
|
2690
|
+
// src/theme/server.ts
|
|
2691
|
+
var defaultThemeConfig = resolveFarmThemeConfig(void 0);
|
|
2692
|
+
function _setDefaultFarmThemeConfig(config, basePath = "/") {
|
|
2693
|
+
defaultThemeConfig = resolveFarmThemeConfig(config, basePath);
|
|
2694
|
+
}
|
|
2695
|
+
__name(_setDefaultFarmThemeConfig, "_setDefaultFarmThemeConfig");
|
|
2696
|
+
function getTheme(request = getCurrentRequest()) {
|
|
2697
|
+
return readFarmThemePreference(request, defaultThemeConfig);
|
|
2698
|
+
}
|
|
2699
|
+
__name(getTheme, "getTheme");
|
|
2700
|
+
function getThemeSnapshot(request = getCurrentRequest()) {
|
|
2701
|
+
const theme = readFarmThemePreference(request, defaultThemeConfig);
|
|
2702
|
+
return {
|
|
2703
|
+
theme,
|
|
2704
|
+
resolvedTheme: theme === "system" ? void 0 : theme,
|
|
2705
|
+
mounted: false
|
|
2706
|
+
};
|
|
2707
|
+
}
|
|
2708
|
+
__name(getThemeSnapshot, "getThemeSnapshot");
|
|
2709
|
+
function readFarmThemePreference(request, config) {
|
|
2710
|
+
if (!config.enabled) return config.default;
|
|
2711
|
+
const stored = readCookie(request.headers.get("cookie"), config.storageKey);
|
|
2712
|
+
return isFarmThemePreference(stored) ? stored : config.default;
|
|
2713
|
+
}
|
|
2714
|
+
__name(readFarmThemePreference, "readFarmThemePreference");
|
|
2715
|
+
function readCookie(cookieHeader, name) {
|
|
2716
|
+
if (!cookieHeader) return void 0;
|
|
2717
|
+
for (const entry of cookieHeader.split(";")) {
|
|
2718
|
+
const separator = entry.indexOf("=");
|
|
2719
|
+
if (separator < 0) continue;
|
|
2720
|
+
const key = decodeCookieValue(entry.slice(0, separator).trim());
|
|
2721
|
+
if (key !== name) continue;
|
|
2722
|
+
return decodeCookieValue(entry.slice(separator + 1).trim());
|
|
2723
|
+
}
|
|
2724
|
+
return void 0;
|
|
2725
|
+
}
|
|
2726
|
+
__name(readCookie, "readCookie");
|
|
2727
|
+
function decodeCookieValue(value) {
|
|
2728
|
+
try {
|
|
2729
|
+
return decodeURIComponent(value);
|
|
2730
|
+
} catch {
|
|
2731
|
+
return value;
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
__name(decodeCookieValue, "decodeCookieValue");
|
|
2735
|
+
function isFarmThemePreference(value) {
|
|
2736
|
+
return value === "light" || value === "dark" || value === "system";
|
|
2737
|
+
}
|
|
2738
|
+
__name(isFarmThemePreference, "isFarmThemePreference");
|
|
2739
|
+
_setFarmThemeServerSnapshotResolver(() => {
|
|
2740
|
+
try {
|
|
2741
|
+
return getThemeSnapshot();
|
|
2742
|
+
} catch {
|
|
2743
|
+
const theme = defaultThemeConfig.default;
|
|
2744
|
+
return {
|
|
2745
|
+
theme,
|
|
2746
|
+
resolvedTheme: theme === "system" ? void 0 : theme,
|
|
2747
|
+
mounted: false
|
|
2748
|
+
};
|
|
2749
|
+
}
|
|
2750
|
+
});
|
|
2751
|
+
|
|
2752
|
+
// src/theme/server-runtime.ts
|
|
2753
|
+
var THEME_SCRIPT_ID = "farm-theme-script";
|
|
2754
|
+
var THEME_STYLE_ID = "farm-theme-style";
|
|
2755
|
+
function createFarmThemeDocumentParts(input, basePath = "/", serverTheme) {
|
|
2756
|
+
const config = resolveFarmThemeConfig(input, basePath);
|
|
2757
|
+
if (!config.enabled) return { attributes: "", head: "" };
|
|
2758
|
+
const hydrationTheme = serverTheme ?? config.default;
|
|
2759
|
+
const initialTheme = hydrationTheme === "system" ? "light" : hydrationTheme;
|
|
2760
|
+
const script = createFarmThemeBootstrapScript(config, hydrationTheme);
|
|
2761
|
+
return {
|
|
2762
|
+
attributes: ` data-theme="${initialTheme}"`,
|
|
2763
|
+
head: `<style id="${THEME_STYLE_ID}">:root[data-theme="light"]{color-scheme:light}:root[data-theme="dark"]{color-scheme:dark}</style><script id="${THEME_SCRIPT_ID}">${script}</script>`
|
|
2764
|
+
};
|
|
2765
|
+
}
|
|
2766
|
+
__name(createFarmThemeDocumentParts, "createFarmThemeDocumentParts");
|
|
2767
|
+
function createFarmThemeBootstrapScript(config, serverTheme = config.default) {
|
|
2768
|
+
return `(function(config,serverTheme){
|
|
2769
|
+
var isTheme=function(value){return value==="light"||value==="dark"||value==="system";};
|
|
2770
|
+
var decode=function(value){try{return decodeURIComponent(value);}catch(_error){return value;}};
|
|
2771
|
+
var readCookie=function(){var entries=document.cookie.split(";");for(var index=0;index<entries.length;index++){var entry=entries[index];var separator=entry.indexOf("=");if(separator<0)continue;if(decode(entry.slice(0,separator).trim())===config.storageKey)return decode(entry.slice(separator+1).trim());}};
|
|
2772
|
+
var media=window.matchMedia("(prefers-color-scheme: dark)");
|
|
2773
|
+
var resolveTheme=function(theme){return theme==="system"?(media.matches?"dark":"light"):theme;};
|
|
2774
|
+
var storedTheme=readCookie();
|
|
2775
|
+
var preference=isTheme(storedTheme)?storedTheme:config.default;
|
|
2776
|
+
var serverSnapshot={theme:serverTheme,resolvedTheme:serverTheme==="system"?undefined:serverTheme,mounted:false};
|
|
2777
|
+
var apply=function(){var resolvedTheme=resolveTheme(preference);document.documentElement.dataset.theme=resolvedTheme;var snapshot={theme:preference,resolvedTheme:resolvedTheme,mounted:true};if(window.__FARM_THEME__)window.__FARM_THEME__.snapshot=snapshot;return snapshot;};
|
|
2778
|
+
var emit=function(){var snapshot=apply();window.dispatchEvent(new CustomEvent("farm:themechange",{detail:snapshot}));};
|
|
2779
|
+
var persist=function(theme){var secure=window.location.protocol==="https:"?"; Secure":"";document.cookie=encodeURIComponent(config.storageKey)+"="+encodeURIComponent(theme)+"; Path="+config.cookiePath+"; Max-Age=31536000; SameSite=Lax"+secure;try{localStorage.setItem(config.storageKey,theme);}catch(_error){}};
|
|
2780
|
+
var setTheme=function(theme){if(!isTheme(theme))throw new TypeError("Unknown FARMJS theme: "+String(theme));preference=theme;persist(theme);emit();};
|
|
2781
|
+
var initialSnapshot={theme:preference,resolvedTheme:resolveTheme(preference),mounted:true};
|
|
2782
|
+
window.__FARM_THEME__={config:config,serverSnapshot:serverSnapshot,snapshot:initialSnapshot,setTheme:setTheme};
|
|
2783
|
+
document.documentElement.dataset.theme=initialSnapshot.resolvedTheme;
|
|
2784
|
+
var handleSystemChange=function(){if(preference==="system")emit();};
|
|
2785
|
+
if(typeof media.addEventListener==="function")media.addEventListener("change",handleSystemChange);else if(typeof media.addListener==="function")media.addListener(handleSystemChange);
|
|
2786
|
+
window.addEventListener("storage",function(event){if(event.key!==config.storageKey||!isTheme(event.newValue))return;preference=event.newValue;persist(preference);emit();});
|
|
2787
|
+
})(${serializeInlineValue(config)},${serializeInlineValue(serverTheme)});`;
|
|
2788
|
+
}
|
|
2789
|
+
__name(createFarmThemeBootstrapScript, "createFarmThemeBootstrapScript");
|
|
2790
|
+
function applyFarmThemeDocument(html, input, basePath = "/", serverTheme) {
|
|
2791
|
+
const parts = createFarmThemeDocumentParts(input, basePath, serverTheme);
|
|
2792
|
+
if (!parts.head) return html;
|
|
2793
|
+
let output = html.replace(/<html([^>]*)>/i, (_match, attributes) => {
|
|
2794
|
+
const nextAttributes = attributes.replace(/\sdata-theme=(?:"[^"]*"|'[^']*'|[^\s>]+)/i, "");
|
|
2795
|
+
return `<html${nextAttributes}${parts.attributes}>`;
|
|
2796
|
+
});
|
|
2797
|
+
if (!output.includes(`id="${THEME_SCRIPT_ID}"`)) {
|
|
2798
|
+
output = output.replace(/<head([^>]*)>/i, `<head$1>${parts.head}`);
|
|
2799
|
+
}
|
|
2800
|
+
return output;
|
|
2801
|
+
}
|
|
2802
|
+
__name(applyFarmThemeDocument, "applyFarmThemeDocument");
|
|
2803
|
+
function serializeInlineValue(value) {
|
|
2804
|
+
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
2805
|
+
}
|
|
2806
|
+
__name(serializeInlineValue, "serializeInlineValue");
|
|
2807
|
+
|
|
2634
2808
|
// src/preload.ts
|
|
2635
2809
|
var reportedWarnings = /* @__PURE__ */ new Map();
|
|
2636
2810
|
var PRELOAD_WARNING_TTL_MS = 6e4;
|
|
@@ -2951,8 +3125,10 @@ __name(appendFarmLinkHeader, "appendFarmLinkHeader");
|
|
|
2951
3125
|
_runWithCurrentRequest,
|
|
2952
3126
|
_runWithMiddlewareContext,
|
|
2953
3127
|
_runWithMiddlewareData,
|
|
3128
|
+
_setDefaultFarmThemeConfig,
|
|
2954
3129
|
addMetadataImageReference,
|
|
2955
3130
|
appendFarmLinkHeader,
|
|
3131
|
+
applyFarmThemeDocument,
|
|
2956
3132
|
applyProductionMiddlewareHeaders,
|
|
2957
3133
|
bufferFarmRequestBody,
|
|
2958
3134
|
configureFarmCache,
|
|
@@ -2961,12 +3137,14 @@ __name(appendFarmLinkHeader, "appendFarmLinkHeader");
|
|
|
2961
3137
|
createFarmLocaleCookie,
|
|
2962
3138
|
createFarmProductionLifecycle,
|
|
2963
3139
|
createFarmRequestBodyErrorResponse,
|
|
3140
|
+
createFarmThemeDocumentParts,
|
|
2964
3141
|
createProductionMiddlewareRunner,
|
|
2965
3142
|
emitFarmEvent,
|
|
2966
3143
|
getCurrentRequest,
|
|
2967
3144
|
getFarmDataCache,
|
|
2968
3145
|
getFarmLocaleVaryHeaders,
|
|
2969
3146
|
getFarmRedirectError,
|
|
3147
|
+
getTheme,
|
|
2970
3148
|
isFarmNotFoundError,
|
|
2971
3149
|
isFarmRedirectError,
|
|
2972
3150
|
localizeFarmHref,
|