@farm.js/core 0.1.0-beta.22 → 0.1.0-beta.23

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 (132) hide show
  1. package/dist/agent-runtime.d.mts +2 -1
  2. package/dist/agent-runtime.d.ts +2 -1
  3. package/dist/{app-BB8GCH1g.d.ts → app-CTFnOJaI.d.ts} +5 -3
  4. package/dist/{app-DwsTpyNZ.d.mts → app-DA6ospIq.d.mts} +5 -3
  5. package/dist/app-markdown.d.mts +2 -1
  6. package/dist/app-markdown.d.ts +2 -1
  7. package/dist/chunk-4IVNW5QD.mjs +82 -0
  8. package/dist/chunk-4IVNW5QD.mjs.map +1 -0
  9. package/dist/{chunk-DAUR3WUZ.mjs → chunk-5NOVWCFL.mjs} +2 -2
  10. package/dist/chunk-5NOVWCFL.mjs.map +1 -0
  11. package/dist/chunk-D42BNPZH.mjs +79 -0
  12. package/dist/chunk-D42BNPZH.mjs.map +1 -0
  13. package/dist/{chunk-LLPN5SEZ.mjs → chunk-DVPRBMU2.mjs} +2 -2
  14. package/dist/{chunk-ZP73P4VR.mjs → chunk-FJGTYLCO.mjs} +67 -20
  15. package/dist/chunk-FJGTYLCO.mjs.map +1 -0
  16. package/dist/chunk-GQVQESLY.mjs +25 -0
  17. package/dist/chunk-GQVQESLY.mjs.map +1 -0
  18. package/dist/chunk-H53KVQUU.mjs +48 -0
  19. package/dist/chunk-H53KVQUU.mjs.map +1 -0
  20. package/dist/chunk-HCGQYYHI.mjs +1 -0
  21. package/dist/chunk-HCGQYYHI.mjs.map +1 -0
  22. package/dist/{chunk-UCYWGN2P.mjs → chunk-OHNSROHS.mjs} +1 -1
  23. package/dist/{chunk-FRPWCMMG.mjs → chunk-SBWOTAX4.mjs} +63 -2
  24. package/dist/chunk-SBWOTAX4.mjs.map +1 -0
  25. package/dist/{chunk-XBKXKJX5.mjs → chunk-TX54PXAJ.mjs} +81 -25
  26. package/dist/chunk-TX54PXAJ.mjs.map +1 -0
  27. package/dist/{chunk-CEVMYGDL.mjs → chunk-YD5IRKVS.mjs} +13 -9
  28. package/dist/chunk-YD5IRKVS.mjs.map +1 -0
  29. package/dist/{client-plugins-QQntVkrv.d.mts → client-plugins-CCilIb_G.d.mts} +6 -2
  30. package/dist/{client-plugins-CbRum1fj.d.ts → client-plugins-DuuleQKk.d.ts} +6 -2
  31. package/dist/client-plugins.d.mts +2 -1
  32. package/dist/client-plugins.d.ts +2 -1
  33. package/dist/client.cjs +122 -35
  34. package/dist/client.cjs.map +1 -1
  35. package/dist/client.d.mts +2 -0
  36. package/dist/client.d.ts +2 -0
  37. package/dist/client.mjs +13 -2
  38. package/dist/config.d.mts +2 -1
  39. package/dist/config.d.ts +2 -1
  40. package/dist/{devtools-52FYXIEK.mjs → devtools-326RBQCN.mjs} +7 -6
  41. package/dist/{devtools-52FYXIEK.mjs.map → devtools-326RBQCN.mjs.map} +1 -1
  42. package/dist/docs.cjs.map +1 -1
  43. package/dist/docs.mjs +6 -5
  44. package/dist/index.cjs +431 -55
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.d.mts +10 -7
  47. package/dist/index.d.ts +10 -7
  48. package/dist/index.mjs +66 -49
  49. package/dist/index.mjs.map +1 -1
  50. package/dist/integrations.d.mts +2 -1
  51. package/dist/integrations.d.ts +2 -1
  52. package/dist/internal/build-runtime.cjs +337 -34
  53. package/dist/internal/build-runtime.cjs.map +1 -1
  54. package/dist/internal/build-runtime.d.mts +4 -3
  55. package/dist/internal/build-runtime.d.ts +4 -3
  56. package/dist/internal/build-runtime.mjs +15 -12
  57. package/dist/internal/config-runtime.cjs +41 -0
  58. package/dist/internal/config-runtime.cjs.map +1 -1
  59. package/dist/internal/config-runtime.d.mts +3 -2
  60. package/dist/internal/config-runtime.d.ts +3 -2
  61. package/dist/internal/config-runtime.mjs +5 -4
  62. package/dist/internal/production-runtime.cjs +178 -0
  63. package/dist/internal/production-runtime.cjs.map +1 -1
  64. package/dist/internal/production-runtime.d.mts +20 -6
  65. package/dist/internal/production-runtime.d.ts +20 -6
  66. package/dist/internal/production-runtime.mjs +13 -1
  67. package/dist/internal/production-runtime.mjs.map +1 -1
  68. package/dist/{metadata-B5jBJHq1.d.ts → metadata-DyPRG0wX.d.ts} +1 -1
  69. package/dist/{metadata-BxOJ4FJl.d.mts → metadata-_GHcAySx.d.mts} +1 -1
  70. package/dist/middleware.d.mts +4 -3
  71. package/dist/middleware.d.ts +4 -3
  72. package/dist/plugin.cjs +219 -14
  73. package/dist/plugin.cjs.map +1 -1
  74. package/dist/plugin.d.mts +2 -1
  75. package/dist/plugin.d.ts +2 -1
  76. package/dist/plugin.mjs +11 -8
  77. package/dist/{production-runtime-Bxua86uR.d.mts → production-runtime-C4cO3esK.d.mts} +1 -1
  78. package/dist/{production-runtime-CZqXjRVi.d.ts → production-runtime-DrEy8kBO.d.ts} +1 -1
  79. package/dist/{request-7V0GaZK_.d.mts → request-B2PpOxYK.d.mts} +1 -1
  80. package/dist/{request-B5XYBv5a.d.ts → request-D40lt6aN.d.ts} +1 -1
  81. package/dist/request.d.mts +3 -2
  82. package/dist/request.d.ts +3 -2
  83. package/dist/routes.d.mts +2 -1
  84. package/dist/routes.d.ts +2 -1
  85. package/dist/server-plugins.d.mts +3 -2
  86. package/dist/server-plugins.d.ts +3 -2
  87. package/dist/server.cjs +241 -19
  88. package/dist/server.cjs.map +1 -1
  89. package/dist/server.d.mts +8 -6
  90. package/dist/server.d.ts +8 -6
  91. package/dist/server.mjs +20 -11
  92. package/dist/server.mjs.map +1 -1
  93. package/dist/testing.d.mts +2 -1
  94. package/dist/testing.d.ts +2 -1
  95. package/dist/theme/client.cjs +115 -0
  96. package/dist/theme/client.cjs.map +1 -0
  97. package/dist/theme/client.d.mts +17 -0
  98. package/dist/theme/client.d.ts +17 -0
  99. package/dist/theme/client.mjs +16 -0
  100. package/dist/theme/client.mjs.map +1 -0
  101. package/dist/theme/index.cjs +71 -0
  102. package/dist/theme/index.cjs.map +1 -0
  103. package/dist/theme/index.d.mts +6 -0
  104. package/dist/theme/index.d.ts +6 -0
  105. package/dist/theme/index.mjs +9 -0
  106. package/dist/theme/index.mjs.map +1 -0
  107. package/dist/theme/server.cjs +191 -0
  108. package/dist/theme/server.cjs.map +1 -0
  109. package/dist/theme/server.d.mts +8 -0
  110. package/dist/theme/server.d.ts +8 -0
  111. package/dist/theme/server.mjs +18 -0
  112. package/dist/theme/server.mjs.map +1 -0
  113. package/dist/types-CsR8fpgF.d.mts +30 -0
  114. package/dist/types-CsR8fpgF.d.ts +30 -0
  115. package/dist/{utils-xTFxzu47.d.ts → utils-3sQgfkya.d.ts} +1 -1
  116. package/dist/{utils-s9pN0Yep.d.mts → utils-Bop7bly-.d.mts} +1 -1
  117. package/dist/version.cjs +1 -1
  118. package/dist/version.cjs.map +1 -1
  119. package/dist/version.mjs +1 -1
  120. package/dist/vite.cjs +242 -15
  121. package/dist/vite.cjs.map +1 -1
  122. package/dist/vite.d.mts +2 -1
  123. package/dist/vite.d.ts +2 -1
  124. package/dist/vite.mjs +11 -8
  125. package/package.json +25 -1
  126. package/dist/chunk-CEVMYGDL.mjs.map +0 -1
  127. package/dist/chunk-DAUR3WUZ.mjs.map +0 -1
  128. package/dist/chunk-FRPWCMMG.mjs.map +0 -1
  129. package/dist/chunk-XBKXKJX5.mjs.map +0 -1
  130. package/dist/chunk-ZP73P4VR.mjs.map +0 -1
  131. /package/dist/{chunk-LLPN5SEZ.mjs.map → chunk-DVPRBMU2.mjs.map} +0 -0
  132. /package/dist/{chunk-UCYWGN2P.mjs.map → chunk-OHNSROHS.mjs.map} +0 -0
package/dist/server.cjs CHANGED
@@ -5632,6 +5632,52 @@ var init_config = __esm({
5632
5632
  }
5633
5633
  });
5634
5634
 
5635
+ // src/theme/config.ts
5636
+ function resolveFarmThemeConfig(config, basePath = "/") {
5637
+ if (config && "enabled" in config) {
5638
+ return config;
5639
+ }
5640
+ if (!config) {
5641
+ return {
5642
+ enabled: false,
5643
+ default: "system",
5644
+ storageKey: DEFAULT_FARM_THEME_STORAGE_KEY,
5645
+ cookiePath: normalizeCookiePath(basePath)
5646
+ };
5647
+ }
5648
+ const storageKey = config.storageKey?.trim() || DEFAULT_FARM_THEME_STORAGE_KEY;
5649
+ if (!STORAGE_KEY_PATTERN.test(storageKey)) {
5650
+ throw new Error(
5651
+ "theme.storageKey may only contain letters, numbers, dots, underscores, and hyphens."
5652
+ );
5653
+ }
5654
+ const defaultTheme = config.default ?? "system";
5655
+ if (defaultTheme !== "light" && defaultTheme !== "dark" && defaultTheme !== "system") {
5656
+ throw new Error('theme.default must be "light", "dark", or "system".');
5657
+ }
5658
+ return {
5659
+ enabled: true,
5660
+ default: defaultTheme,
5661
+ storageKey,
5662
+ cookiePath: normalizeCookiePath(basePath)
5663
+ };
5664
+ }
5665
+ function normalizeCookiePath(basePath) {
5666
+ const normalized = `/${basePath}`.replace(/\/{2,}/g, "/");
5667
+ if (normalized === "/") return normalized;
5668
+ return normalized.replace(/\/$/, "");
5669
+ }
5670
+ var DEFAULT_FARM_THEME_STORAGE_KEY, STORAGE_KEY_PATTERN;
5671
+ var init_config2 = __esm({
5672
+ "src/theme/config.ts"() {
5673
+ "use strict";
5674
+ DEFAULT_FARM_THEME_STORAGE_KEY = "farm-theme";
5675
+ STORAGE_KEY_PATTERN = /^[A-Za-z0-9._-]+$/;
5676
+ __name(resolveFarmThemeConfig, "resolveFarmThemeConfig");
5677
+ __name(normalizeCookiePath, "normalizeCookiePath");
5678
+ }
5679
+ });
5680
+
5635
5681
  // src/devtools-config.ts
5636
5682
  function resolveFarmDevtoolsConfig(config, mode = "development") {
5637
5683
  if (mode !== "development" || config === false) {
@@ -10733,6 +10779,7 @@ async function resolveConfig(userConfig, mode) {
10733
10779
  routeRules,
10734
10780
  images: resolveFarmImageConfig(userConfig.images),
10735
10781
  performance: resolveFarmPerformanceConfig(userConfig.performance),
10782
+ theme: resolveFarmThemeConfig(userConfig.theme, userConfig.basePath || "/"),
10736
10783
  publicDir: userConfig.publicDir || "public",
10737
10784
  i18n: resolveFarmI18nConfig(userConfig.i18n, { root, mode }),
10738
10785
  openapi: {
@@ -10810,7 +10857,7 @@ async function loadConfig(rootDir, configPath, mode = process.env.NODE_ENV === "
10810
10857
  return void 0;
10811
10858
  }
10812
10859
  var import_path9, FARM_RESOLVED_CUSTOM_CONTEXT, DOCS_CONFIG_FILENAMES;
10813
- var init_config2 = __esm({
10860
+ var init_config3 = __esm({
10814
10861
  "src/config.ts"() {
10815
10862
  "use strict";
10816
10863
  init_integrations();
@@ -10831,6 +10878,7 @@ var init_config2 = __esm({
10831
10878
  init_auth_config();
10832
10879
  init_preload();
10833
10880
  init_security();
10881
+ init_config2();
10834
10882
  init_config_entry();
10835
10883
  FARM_RESOLVED_CUSTOM_CONTEXT = /* @__PURE__ */ Symbol.for("farm.resolvedCustomContext");
10836
10884
  __name(normalizeDeployTarget, "normalizeDeployTarget");
@@ -11333,7 +11381,7 @@ var init_api = __esm({
11333
11381
  "src/docs/api.ts"() {
11334
11382
  "use strict";
11335
11383
  import_docs2 = require("@farming-labs/docs");
11336
- init_config2();
11384
+ init_config3();
11337
11385
  init_handler();
11338
11386
  __name(isRecord4, "isRecord");
11339
11387
  __name(isResolvedDocsConfig2, "isResolvedDocsConfig");
@@ -12318,7 +12366,7 @@ var init_devtools = __esm({
12318
12366
  "src/devtools.ts"() {
12319
12367
  "use strict";
12320
12368
  import_node_path14 = __toESM(require("path"));
12321
- init_config2();
12369
+ init_config3();
12322
12370
  init_cron();
12323
12371
  init_route_runtime();
12324
12372
  __name(normalizePath, "normalizePath");
@@ -14025,6 +14073,8 @@ __export(server_exports, {
14025
14073
  getServerActionInvalidations: () => getServerActionInvalidations,
14026
14074
  getServerActionSignal: () => getServerActionSignal,
14027
14075
  getStorage: () => getStorage,
14076
+ getTheme: () => getTheme,
14077
+ getThemeSnapshot: () => getThemeSnapshot,
14028
14078
  globFiles: () => globFiles,
14029
14079
  initStorage: () => initStorage,
14030
14080
  invalidate: () => invalidate,
@@ -20671,6 +20721,125 @@ function DefaultNotFoundPage(_props) {
20671
20721
  }
20672
20722
  __name(DefaultNotFoundPage, "DefaultNotFoundPage");
20673
20723
 
20724
+ // src/theme/server-runtime.ts
20725
+ init_config2();
20726
+ var THEME_SCRIPT_ID = "farm-theme-script";
20727
+ var THEME_STYLE_ID = "farm-theme-style";
20728
+ function createFarmThemeDocumentParts(input, basePath = "/", serverTheme) {
20729
+ const config = resolveFarmThemeConfig(input, basePath);
20730
+ if (!config.enabled) return { attributes: "", head: "" };
20731
+ const hydrationTheme = serverTheme ?? config.default;
20732
+ const initialTheme = hydrationTheme === "system" ? "light" : hydrationTheme;
20733
+ const script = createFarmThemeBootstrapScript(config, hydrationTheme);
20734
+ return {
20735
+ attributes: ` data-theme="${initialTheme}"`,
20736
+ 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>`
20737
+ };
20738
+ }
20739
+ __name(createFarmThemeDocumentParts, "createFarmThemeDocumentParts");
20740
+ function createFarmThemeBootstrapScript(config, serverTheme = config.default) {
20741
+ return `(function(config,serverTheme){
20742
+ var isTheme=function(value){return value==="light"||value==="dark"||value==="system";};
20743
+ var decode=function(value){try{return decodeURIComponent(value);}catch(_error){return value;}};
20744
+ 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());}};
20745
+ var media=window.matchMedia("(prefers-color-scheme: dark)");
20746
+ var resolveTheme=function(theme){return theme==="system"?(media.matches?"dark":"light"):theme;};
20747
+ var storedTheme=readCookie();
20748
+ var preference=isTheme(storedTheme)?storedTheme:config.default;
20749
+ var serverSnapshot={theme:serverTheme,resolvedTheme:serverTheme==="system"?undefined:serverTheme,mounted:false};
20750
+ 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;};
20751
+ var emit=function(){var snapshot=apply();window.dispatchEvent(new CustomEvent("farm:themechange",{detail:snapshot}));};
20752
+ 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){}};
20753
+ var setTheme=function(theme){if(!isTheme(theme))throw new TypeError("Unknown FARMJS theme: "+String(theme));preference=theme;persist(theme);emit();};
20754
+ var initialSnapshot={theme:preference,resolvedTheme:resolveTheme(preference),mounted:true};
20755
+ window.__FARM_THEME__={config:config,serverSnapshot:serverSnapshot,snapshot:initialSnapshot,setTheme:setTheme};
20756
+ document.documentElement.dataset.theme=initialSnapshot.resolvedTheme;
20757
+ var handleSystemChange=function(){if(preference==="system")emit();};
20758
+ if(typeof media.addEventListener==="function")media.addEventListener("change",handleSystemChange);else if(typeof media.addListener==="function")media.addListener(handleSystemChange);
20759
+ window.addEventListener("storage",function(event){if(event.key!==config.storageKey||!isTheme(event.newValue))return;preference=event.newValue;persist(preference);emit();});
20760
+ })(${serializeInlineValue(config)},${serializeInlineValue(serverTheme)});`;
20761
+ }
20762
+ __name(createFarmThemeBootstrapScript, "createFarmThemeBootstrapScript");
20763
+ function serializeInlineValue(value) {
20764
+ return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
20765
+ }
20766
+ __name(serializeInlineValue, "serializeInlineValue");
20767
+
20768
+ // src/theme/bridge.ts
20769
+ var FALLBACK_SERVER_SNAPSHOT = Object.freeze({
20770
+ theme: "system",
20771
+ resolvedTheme: void 0,
20772
+ mounted: false
20773
+ });
20774
+ var FARM_THEME_SERVER_SNAPSHOT_RESOLVER = /* @__PURE__ */ Symbol.for("farm.js.theme.server-snapshot-resolver");
20775
+ function _setFarmThemeServerSnapshotResolver(resolver) {
20776
+ globalThis[FARM_THEME_SERVER_SNAPSHOT_RESOLVER] = resolver;
20777
+ }
20778
+ __name(_setFarmThemeServerSnapshotResolver, "_setFarmThemeServerSnapshotResolver");
20779
+
20780
+ // src/theme/server.ts
20781
+ init_config2();
20782
+ var defaultThemeConfig = resolveFarmThemeConfig(void 0);
20783
+ function _setDefaultFarmThemeConfig(config, basePath = "/") {
20784
+ defaultThemeConfig = resolveFarmThemeConfig(config, basePath);
20785
+ }
20786
+ __name(_setDefaultFarmThemeConfig, "_setDefaultFarmThemeConfig");
20787
+ function getTheme(request = getCurrentRequest()) {
20788
+ return readFarmThemePreference(request, defaultThemeConfig);
20789
+ }
20790
+ __name(getTheme, "getTheme");
20791
+ function getThemeSnapshot(request = getCurrentRequest()) {
20792
+ const theme = readFarmThemePreference(request, defaultThemeConfig);
20793
+ return {
20794
+ theme,
20795
+ resolvedTheme: theme === "system" ? void 0 : theme,
20796
+ mounted: false
20797
+ };
20798
+ }
20799
+ __name(getThemeSnapshot, "getThemeSnapshot");
20800
+ function readFarmThemePreference(request, config) {
20801
+ if (!config.enabled) return config.default;
20802
+ const stored = readCookie3(request.headers.get("cookie"), config.storageKey);
20803
+ return isFarmThemePreference(stored) ? stored : config.default;
20804
+ }
20805
+ __name(readFarmThemePreference, "readFarmThemePreference");
20806
+ function readCookie3(cookieHeader, name) {
20807
+ if (!cookieHeader) return void 0;
20808
+ for (const entry of cookieHeader.split(";")) {
20809
+ const separator = entry.indexOf("=");
20810
+ if (separator < 0) continue;
20811
+ const key = decodeCookieValue(entry.slice(0, separator).trim());
20812
+ if (key !== name) continue;
20813
+ return decodeCookieValue(entry.slice(separator + 1).trim());
20814
+ }
20815
+ return void 0;
20816
+ }
20817
+ __name(readCookie3, "readCookie");
20818
+ function decodeCookieValue(value) {
20819
+ try {
20820
+ return decodeURIComponent(value);
20821
+ } catch {
20822
+ return value;
20823
+ }
20824
+ }
20825
+ __name(decodeCookieValue, "decodeCookieValue");
20826
+ function isFarmThemePreference(value) {
20827
+ return value === "light" || value === "dark" || value === "system";
20828
+ }
20829
+ __name(isFarmThemePreference, "isFarmThemePreference");
20830
+ _setFarmThemeServerSnapshotResolver(() => {
20831
+ try {
20832
+ return getThemeSnapshot();
20833
+ } catch {
20834
+ const theme = defaultThemeConfig.default;
20835
+ return {
20836
+ theme,
20837
+ resolvedTheme: theme === "system" ? void 0 : theme,
20838
+ mounted: false
20839
+ };
20840
+ }
20841
+ });
20842
+
20674
20843
  // src/server/renderer.ts
20675
20844
  var cachedClerkProvider = null;
20676
20845
  var importRuntimeModule = new Function("specifier", "return import(specifier);");
@@ -20679,10 +20848,10 @@ function hasRequestHeader(req, name) {
20679
20848
  return Array.isArray(value) ? value.length > 0 : Boolean(value);
20680
20849
  }
20681
20850
  __name(hasRequestHeader, "hasRequestHeader");
20682
- function serializeInlineValue(value) {
20851
+ function serializeInlineValue2(value) {
20683
20852
  return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
20684
20853
  }
20685
- __name(serializeInlineValue, "serializeInlineValue");
20854
+ __name(serializeInlineValue2, "serializeInlineValue");
20686
20855
  function escapeHtmlAttribute2(value) {
20687
20856
  return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
20688
20857
  }
@@ -20776,7 +20945,7 @@ function createDocumentFooter(options) {
20776
20945
  __name(createDocumentFooter, "createDocumentFooter");
20777
20946
  function createDeferredHydrationScript(records) {
20778
20947
  if (records.length === 0) return "";
20779
- return `<script>window.__FARM_DEFERRED_DATA__=${serializeInlineValue(
20948
+ return `<script>window.__FARM_DEFERRED_DATA__=${serializeInlineValue2(
20780
20949
  snapshotDeferredData(records)
20781
20950
  )};</script>`;
20782
20951
  }
@@ -21917,9 +22086,9 @@ var _ServerRenderer = class _ServerRenderer {
21917
22086
  slots: routeSlotPayload
21918
22087
  });
21919
22088
  const propsScript = `<script>
21920
- window.__FARM_PROPS__ = ${serializeInlineValue(deferredProps.data.page)};
21921
- window.__FARM_ROUTE_SLOTS__ = ${serializeInlineValue(deferredProps.data.slots)};
21922
- window.__FARM_DEPLOYMENT_ID__ = ${serializeInlineValue(deploymentId)};
22089
+ window.__FARM_PROPS__ = ${serializeInlineValue2(deferredProps.data.page)};
22090
+ window.__FARM_ROUTE_SLOTS__ = ${serializeInlineValue2(deferredProps.data.slots)};
22091
+ window.__FARM_DEPLOYMENT_ID__ = ${serializeInlineValue2(deploymentId)};
21923
22092
  window.__FARM_PATH__ = ${JSON.stringify(req.__FARM_ROUTE__ || req.url || "/")};
21924
22093
  window.__FARM_IS_CLIENT__ = ${JSON.stringify(isClientComponent)};
21925
22094
  window.__FARM_PAGE_SHOULD_HYDRATE__ = ${JSON.stringify(
@@ -21937,7 +22106,7 @@ window.__FARM_LOADING_MODULE__ = ${JSON.stringify(
21937
22106
  )};
21938
22107
  window.__FARM_MANIFEST__ = ${JSON.stringify(clientManifest)};
21939
22108
  window.__FARM_INTEGRATION_API_MANIFEST__ = ${JSON.stringify(getRegisteredIntegrationAPIManifest())};
21940
- ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue(getFarmI18nClientSnapshot())};` : ""}
22109
+ ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue2(getFarmI18nClientSnapshot())};` : ""}
21941
22110
  </script>`;
21942
22111
  const hydrationClickQueueScript = isClientComponent || req.__FARM_SHOULD_HYDRATE__ === true || req.__FARM_HAS_HYDRATABLE_ROUTE_SLOTS__ === true ? createPreHydrationClickQueueScript() : "";
21943
22112
  const {
@@ -21948,6 +22117,11 @@ ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue(g
21948
22117
  const i18nSnapshot = getFarmI18nClientSnapshot();
21949
22118
  const i18nAlternateTags = i18nSnapshot ? renderI18nAlternateLinks(req.__FARM_ROUTE__ || req.url || "/", i18nSnapshot) : "";
21950
22119
  const fontHead = renderFarmFontDevHead(this.config.root || process.cwd());
22120
+ const themeDocument = createFarmThemeDocumentParts(
22121
+ this.config.theme,
22122
+ this.config.basePath,
22123
+ getTheme()
22124
+ );
21951
22125
  const streamRoot = import_react5.default.createElement("div", { style: { display: "contents" } }, element);
21952
22126
  const { pipe } = (0, import_server2.renderToPipeableStream)(streamRoot, {
21953
22127
  onShellReady() {
@@ -21961,8 +22135,9 @@ ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue(g
21961
22135
  console.log(`[FARM STREAM] onShellReady at ${shellReadyMs}ms`);
21962
22136
  }
21963
22137
  const shell = `<!DOCTYPE html>
21964
- <html lang="${escapeHtmlAttribute2(i18nSnapshot?.locale || "en")}"${i18nSnapshot ? ` dir="${i18nSnapshot.direction}"` : ""}>
22138
+ <html lang="${escapeHtmlAttribute2(i18nSnapshot?.locale || "en")}"${i18nSnapshot ? ` dir="${i18nSnapshot.direction}"` : ""}${themeDocument.attributes}>
21965
22139
  <head>
22140
+ ${themeDocument.head}
21966
22141
  <meta charset="utf-8">
21967
22142
  <meta name="viewport" content="width=device-width, initial-scale=1">
21968
22143
  <meta name="farm-deployment-id" content="${escapeHtmlAttribute2(deploymentId)}">
@@ -22164,15 +22339,21 @@ ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue(g
22164
22339
  const i18nSnapshot = getFarmI18nClientSnapshot();
22165
22340
  const clientScript = isClientComponent ? ` <script type="module" src="/@farm/client.js"></script>` : "";
22166
22341
  const integrationManifestScript = `<script>
22167
- window.__FARM_DEPLOYMENT_ID__ = ${serializeInlineValue(this.getDeploymentId())};
22342
+ window.__FARM_DEPLOYMENT_ID__ = ${serializeInlineValue2(this.getDeploymentId())};
22168
22343
  window.__FARM_INTEGRATION_API_MANIFEST__ = ${JSON.stringify(getRegisteredIntegrationAPIManifest())};
22169
- ${i18nSnapshot ? `window.__FARM_I18N__ = ${serializeInlineValue(i18nSnapshot)};` : ""}
22344
+ ${i18nSnapshot ? `window.__FARM_I18N__ = ${serializeInlineValue2(i18nSnapshot)};` : ""}
22170
22345
  </script>`;
22171
22346
  const alternateLinks = i18nSnapshot ? renderI18nAlternateLinks(requestPath, i18nSnapshot) : "";
22172
22347
  const fontHead = renderFarmFontDevHead(this.config.root || process.cwd());
22348
+ const themeDocument = createFarmThemeDocumentParts(
22349
+ this.config.theme,
22350
+ this.config.basePath,
22351
+ getTheme()
22352
+ );
22173
22353
  return `<!DOCTYPE html>
22174
- <html lang="${escapeHtmlAttribute2(i18nSnapshot?.locale || "en")}"${i18nSnapshot ? ` dir="${i18nSnapshot.direction}"` : ""}>
22354
+ <html lang="${escapeHtmlAttribute2(i18nSnapshot?.locale || "en")}"${i18nSnapshot ? ` dir="${i18nSnapshot.direction}"` : ""}${themeDocument.attributes}>
22175
22355
  <head>
22356
+ ${themeDocument.head}
22176
22357
  <meta charset="utf-8">
22177
22358
  <meta name="viewport" content="width=device-width, initial-scale=1">
22178
22359
  <meta name="farm-deployment-id" content="${escapeHtmlAttribute2(this.getDeploymentId())}">
@@ -22219,6 +22400,7 @@ init_config();
22219
22400
  init_auth_config();
22220
22401
  init_preload();
22221
22402
  init_security();
22403
+ init_config2();
22222
22404
  var defaultDocsConfig = {
22223
22405
  enabled: false,
22224
22406
  entry: "/docs",
@@ -22232,6 +22414,7 @@ var _FarmApp = class _FarmApp {
22232
22414
  constructor(config = {}, viteServer) {
22233
22415
  this.config = this.normalizeConfig(config);
22234
22416
  configureFarmObservability(this.config.observability);
22417
+ _setDefaultFarmThemeConfig(this.config.theme);
22235
22418
  this.i18nRuntime = createFarmI18nRuntime(this.config.i18n);
22236
22419
  _setDefaultFarmI18nRuntime(this.i18nRuntime);
22237
22420
  this.viteServer = viteServer;
@@ -22290,6 +22473,7 @@ var _FarmApp = class _FarmApp {
22290
22473
  security: resolveFarmSecurityConfig(config.security),
22291
22474
  images: resolveFarmImageConfig(config.images),
22292
22475
  performance: resolveFarmPerformanceConfig(config.performance),
22476
+ theme: resolveFarmThemeConfig(config.theme, config.basePath || "/"),
22293
22477
  i18n: isResolvedI18nConfig(config.i18n) ? config.i18n : resolveFarmI18nConfig(config.i18n, {
22294
22478
  root,
22295
22479
  mode: process.env.NODE_ENV === "production" ? "production" : "development"
@@ -24904,7 +25088,7 @@ function transformError(id, message) {
24904
25088
  __name(transformError, "transformError");
24905
25089
 
24906
25090
  // package.json
24907
- var version = "0.1.0-beta.22";
25091
+ var version = "0.1.0-beta.23";
24908
25092
 
24909
25093
  // src/version.ts
24910
25094
  var FARM_VERSION = version;
@@ -25305,6 +25489,32 @@ __name(mergeFarmViteConfig, "mergeFarmViteConfig");
25305
25489
  // src/vite.ts
25306
25490
  init_fonts();
25307
25491
  init_server_http();
25492
+
25493
+ // src/theme/vite.ts
25494
+ init_config2();
25495
+ var FARM_DARK_VARIANT = '@custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *));';
25496
+ function createFarmThemeCssPlugin(input, basePath = "/") {
25497
+ const config = resolveFarmThemeConfig(input, basePath);
25498
+ return {
25499
+ name: "farm:theme-css",
25500
+ enforce: "pre",
25501
+ transform(code, id) {
25502
+ if (!config.enabled || !/\.css(?:\?.*)?$/.test(id) || !/@import\s+["']tailwindcss["']/.test(code) || /@custom-variant\s+dark\b/.test(code)) {
25503
+ return null;
25504
+ }
25505
+ return {
25506
+ code: `${code.trimEnd()}
25507
+
25508
+ ${FARM_DARK_VARIANT}
25509
+ `,
25510
+ map: null
25511
+ };
25512
+ }
25513
+ };
25514
+ }
25515
+ __name(createFarmThemeCssPlugin, "createFarmThemeCssPlugin");
25516
+
25517
+ // src/vite.ts
25308
25518
  var ALL_TYPE_ARTIFACTS = {
25309
25519
  routes: true,
25310
25520
  api: true,
@@ -28691,14 +28901,22 @@ async function renderPage(pageData) {
28691
28901
  if (!doc.documentElement || !doc.body) return false;
28692
28902
 
28693
28903
  resetReactRoots();
28904
+ const activeFarmTheme =
28905
+ window.__FARM_THEME__?.snapshot?.resolvedTheme ||
28906
+ document.documentElement.getAttribute('data-theme');
28694
28907
  Array.from(document.documentElement.attributes).forEach(function(attr) {
28908
+ if (attr.name === 'data-theme') return;
28695
28909
  if (!doc.documentElement.hasAttribute(attr.name)) {
28696
28910
  document.documentElement.removeAttribute(attr.name);
28697
28911
  }
28698
28912
  });
28699
28913
  Array.from(doc.documentElement.attributes).forEach(function(attr) {
28914
+ if (attr.name === 'data-theme') return;
28700
28915
  document.documentElement.setAttribute(attr.name, attr.value);
28701
28916
  });
28917
+ if (activeFarmTheme) {
28918
+ document.documentElement.setAttribute('data-theme', activeFarmTheme);
28919
+ }
28702
28920
 
28703
28921
  document.head.innerHTML = doc.head ? doc.head.innerHTML : '';
28704
28922
  document.body.innerHTML = doc.body.innerHTML;
@@ -28707,6 +28925,7 @@ async function renderPage(pageData) {
28707
28925
 
28708
28926
  setTimeout(function() {
28709
28927
  Array.from(document.querySelectorAll('script')).forEach(function(script) {
28928
+ if (script.id === 'farm-theme-script') return;
28710
28929
  const freshScript = document.createElement('script');
28711
28930
  Array.from(script.attributes).forEach(function(attr) {
28712
28931
  freshScript.setAttribute(attr.name, attr.value);
@@ -29204,6 +29423,7 @@ async function defineConfig2(config = {}) {
29204
29423
  };
29205
29424
  return {
29206
29425
  plugins: [
29426
+ createFarmThemeCssPlugin(config.theme, config.basePath),
29207
29427
  tailwindcss(),
29208
29428
  viteBrowserExternalPlugin,
29209
29429
  farmI18nClientBridgePlugin(),
@@ -29683,8 +29903,8 @@ function assertServerQueryKey(key) {
29683
29903
  __name(assertServerQueryKey, "assertServerQueryKey");
29684
29904
 
29685
29905
  // src/server/create-server.ts
29686
- var import_vite2 = require("vite");
29687
- init_config2();
29906
+ var import_vite3 = require("vite");
29907
+ init_config3();
29688
29908
 
29689
29909
  // src/plugin.ts
29690
29910
  init_env();
@@ -30639,19 +30859,19 @@ async function createServer(config = {}) {
30639
30859
  try {
30640
30860
  const tailwindcss = (await import("@tailwindcss/vite")).default;
30641
30861
  tailwindVitePlugin = tailwindcss();
30642
- logger.info("\u{1F4E6} Enabled built-in Tailwind support (@tailwindcss/vite)");
30643
30862
  } catch (error) {
30644
30863
  logger.warn(
30645
30864
  `Tailwind plugin auto-enable failed; continuing without it: ${error.message}`
30646
30865
  );
30647
30866
  }
30648
30867
  }
30649
- const server = await (0, import_vite2.createServer)(
30868
+ const server = await (0, import_vite3.createServer)(
30650
30869
  mergeFarmViteConfig(
30651
30870
  {
30652
30871
  root: projectRoot,
30653
30872
  css: shouldUseProjectPostcss ? void 0 : { postcss: { plugins: [] } },
30654
30873
  plugins: [
30874
+ createFarmThemeCssPlugin(finalConfig.theme, finalConfig.basePath),
30655
30875
  ...tailwindVitePlugin ? [tailwindVitePlugin] : [],
30656
30876
  createDevDependencyStubsPlugin(),
30657
30877
  farmI18nClientBridgePlugin(),
@@ -30862,6 +31082,8 @@ __name(assertFunction, "assertFunction");
30862
31082
  getServerActionInvalidations,
30863
31083
  getServerActionSignal,
30864
31084
  getStorage,
31085
+ getTheme,
31086
+ getThemeSnapshot,
30865
31087
  globFiles,
30866
31088
  initStorage,
30867
31089
  invalidate,