@farm.js/core 0.1.0-beta.21 → 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 (266) hide show
  1. package/dist/after.d.mts +25 -0
  2. package/dist/after.d.ts +25 -0
  3. package/dist/agent-runtime.d.mts +97 -0
  4. package/dist/agent-runtime.d.ts +97 -0
  5. package/dist/api/route-manager.d.mts +68 -0
  6. package/dist/api/route-manager.d.ts +68 -0
  7. package/dist/api/runtime.d.mts +3 -0
  8. package/dist/api/runtime.d.ts +3 -0
  9. package/dist/api.cjs +22 -19
  10. package/dist/api.cjs.map +1 -1
  11. package/dist/api.d.mts +50 -0
  12. package/dist/api.d.ts +50 -0
  13. package/dist/api.mjs +2 -1
  14. package/dist/app-CTFnOJaI.d.ts +308 -0
  15. package/dist/app-DA6ospIq.d.mts +308 -0
  16. package/dist/app-markdown.d.mts +25 -0
  17. package/dist/app-markdown.d.ts +25 -0
  18. package/dist/cache.d.mts +192 -0
  19. package/dist/cache.d.ts +192 -0
  20. package/dist/{chunk-MIUW47JX.mjs → chunk-2PEJGY5V.mjs} +15 -20
  21. package/dist/chunk-2PEJGY5V.mjs.map +1 -0
  22. package/dist/{chunk-RIXKJPGI.mjs → chunk-42325TLU.mjs} +2 -2
  23. package/dist/chunk-4IVNW5QD.mjs +82 -0
  24. package/dist/chunk-4IVNW5QD.mjs.map +1 -0
  25. package/dist/{chunk-I3UWA2P2.mjs → chunk-5NOVWCFL.mjs} +2 -2
  26. package/dist/chunk-5NOVWCFL.mjs.map +1 -0
  27. package/dist/chunk-D42BNPZH.mjs +79 -0
  28. package/dist/chunk-D42BNPZH.mjs.map +1 -0
  29. package/dist/{chunk-LLPN5SEZ.mjs → chunk-DVPRBMU2.mjs} +2 -2
  30. package/dist/{chunk-VIC7NJ77.mjs → chunk-FJGTYLCO.mjs} +67 -20
  31. package/dist/chunk-FJGTYLCO.mjs.map +1 -0
  32. package/dist/chunk-GIELMNBG.mjs +15 -0
  33. package/dist/chunk-GIELMNBG.mjs.map +1 -0
  34. package/dist/chunk-GQVQESLY.mjs +25 -0
  35. package/dist/chunk-GQVQESLY.mjs.map +1 -0
  36. package/dist/chunk-H53KVQUU.mjs +48 -0
  37. package/dist/chunk-H53KVQUU.mjs.map +1 -0
  38. package/dist/chunk-HCGQYYHI.mjs +1 -0
  39. package/dist/chunk-HCGQYYHI.mjs.map +1 -0
  40. package/dist/{chunk-4EATUJFO.mjs → chunk-ICTGDDV4.mjs} +20 -22
  41. package/dist/chunk-ICTGDDV4.mjs.map +1 -0
  42. package/dist/{chunk-UCYWGN2P.mjs → chunk-OHNSROHS.mjs} +1 -1
  43. package/dist/{chunk-FRPWCMMG.mjs → chunk-SBWOTAX4.mjs} +63 -2
  44. package/dist/chunk-SBWOTAX4.mjs.map +1 -0
  45. package/dist/{chunk-FKKM7HVF.mjs → chunk-TX54PXAJ.mjs} +109 -58
  46. package/dist/chunk-TX54PXAJ.mjs.map +1 -0
  47. package/dist/{chunk-CEVMYGDL.mjs → chunk-YD5IRKVS.mjs} +13 -9
  48. package/dist/chunk-YD5IRKVS.mjs.map +1 -0
  49. package/dist/chunk-recovery-lnQFzcQP.d.mts +26 -0
  50. package/dist/chunk-recovery-lnQFzcQP.d.ts +26 -0
  51. package/dist/client-BT1mFQas.d.mts +447 -0
  52. package/dist/client-Nn0q4eO4.d.ts +447 -0
  53. package/dist/client-cache-CIlyBlmx.d.ts +6 -0
  54. package/dist/client-cache-D-EZ7XVW.d.mts +6 -0
  55. package/dist/client-plugins-CCilIb_G.d.mts +2092 -0
  56. package/dist/client-plugins-DuuleQKk.d.ts +2092 -0
  57. package/dist/client-plugins.d.mts +25 -0
  58. package/dist/client-plugins.d.ts +25 -0
  59. package/dist/client.cjs +122 -35
  60. package/dist/client.cjs.map +1 -1
  61. package/dist/client.d.mts +454 -0
  62. package/dist/client.d.ts +454 -0
  63. package/dist/client.mjs +13 -2
  64. package/dist/config.d.mts +32 -0
  65. package/dist/config.d.ts +32 -0
  66. package/dist/cron.d.mts +78 -0
  67. package/dist/cron.d.ts +78 -0
  68. package/dist/deferred.d.mts +42 -0
  69. package/dist/deferred.d.ts +42 -0
  70. package/dist/deployment.d.mts +36 -0
  71. package/dist/deployment.d.ts +36 -0
  72. package/dist/{devtools-52FYXIEK.mjs → devtools-326RBQCN.mjs} +7 -6
  73. package/dist/{devtools-52FYXIEK.mjs.map → devtools-326RBQCN.mjs.map} +1 -1
  74. package/dist/docs.cjs.map +1 -1
  75. package/dist/docs.d.mts +80 -0
  76. package/dist/docs.d.ts +80 -0
  77. package/dist/docs.mjs +6 -5
  78. package/dist/env-types.d.mts +12 -0
  79. package/dist/env-types.d.ts +12 -0
  80. package/dist/env.d.mts +45 -0
  81. package/dist/env.d.ts +45 -0
  82. package/dist/environment/vite.d.mts +22 -0
  83. package/dist/environment/vite.d.ts +22 -0
  84. package/dist/environment.d.mts +18 -0
  85. package/dist/environment.d.ts +18 -0
  86. package/dist/font.d.mts +95 -0
  87. package/dist/font.d.ts +95 -0
  88. package/dist/headers.d.mts +22 -0
  89. package/dist/headers.d.ts +22 -0
  90. package/dist/i18n/client.d.mts +32 -0
  91. package/dist/i18n/client.d.ts +32 -0
  92. package/dist/i18n/index.d.mts +20 -0
  93. package/dist/i18n/index.d.ts +20 -0
  94. package/dist/i18n/server.d.mts +30 -0
  95. package/dist/i18n/server.d.ts +30 -0
  96. package/dist/image/server.d.mts +37 -0
  97. package/dist/image/server.d.ts +37 -0
  98. package/dist/image/sharp.d.mts +7 -0
  99. package/dist/image/sharp.d.ts +7 -0
  100. package/dist/image-config-Duob7wER.d.mts +50 -0
  101. package/dist/image-config-Duob7wER.d.ts +50 -0
  102. package/dist/image.d.mts +39 -0
  103. package/dist/image.d.ts +39 -0
  104. package/dist/index.cjs +496 -123
  105. package/dist/index.cjs.map +1 -1
  106. package/dist/index.d.mts +480 -0
  107. package/dist/index.d.ts +480 -0
  108. package/dist/index.mjs +70 -52
  109. package/dist/index.mjs.map +1 -1
  110. package/dist/integration-api-CHT2OKAf.d.mts +93 -0
  111. package/dist/integration-api-CHT2OKAf.d.ts +93 -0
  112. package/dist/integrations.d.mts +25 -0
  113. package/dist/integrations.d.ts +25 -0
  114. package/dist/internal/build-runtime.cjs +386 -83
  115. package/dist/internal/build-runtime.cjs.map +1 -1
  116. package/dist/internal/build-runtime.d.mts +42 -0
  117. package/dist/internal/build-runtime.d.ts +42 -0
  118. package/dist/internal/build-runtime.mjs +17 -13
  119. package/dist/internal/client-runtime.d.mts +17 -0
  120. package/dist/internal/client-runtime.d.ts +17 -0
  121. package/dist/internal/config-runtime.cjs +41 -0
  122. package/dist/internal/config-runtime.cjs.map +1 -1
  123. package/dist/internal/config-runtime.d.mts +42 -0
  124. package/dist/internal/config-runtime.d.ts +42 -0
  125. package/dist/internal/config-runtime.mjs +5 -4
  126. package/dist/internal/metadata-image-runtime.d.mts +25 -0
  127. package/dist/internal/metadata-image-runtime.d.ts +25 -0
  128. package/dist/internal/production-node-env.d.mts +12 -0
  129. package/dist/internal/production-node-env.d.ts +12 -0
  130. package/dist/internal/production-runtime.cjs +178 -0
  131. package/dist/internal/production-runtime.cjs.map +1 -1
  132. package/dist/internal/production-runtime.d.mts +80 -0
  133. package/dist/internal/production-runtime.d.ts +80 -0
  134. package/dist/internal/production-runtime.mjs +13 -1
  135. package/dist/internal/production-runtime.mjs.map +1 -1
  136. package/dist/island-CfGru1MO.d.mts +9 -0
  137. package/dist/island-CfGru1MO.d.ts +9 -0
  138. package/dist/markdown.d.mts +60 -0
  139. package/dist/markdown.d.ts +60 -0
  140. package/dist/metadata-DyPRG0wX.d.ts +22 -0
  141. package/dist/metadata-_GHcAySx.d.mts +22 -0
  142. package/dist/middleware.cjs +17 -17
  143. package/dist/middleware.cjs.map +1 -1
  144. package/dist/middleware.d.mts +172 -0
  145. package/dist/middleware.d.ts +172 -0
  146. package/dist/middleware.mjs +3 -2
  147. package/dist/navigation-errors-Dvwpzaer.d.mts +13 -0
  148. package/dist/navigation-errors-Dvwpzaer.d.ts +13 -0
  149. package/dist/navigation.d.mts +14 -0
  150. package/dist/navigation.d.ts +14 -0
  151. package/dist/observability.d.mts +335 -0
  152. package/dist/observability.d.ts +335 -0
  153. package/dist/params-BALtrRim.d.ts +15 -0
  154. package/dist/params-ry-lxqmy.d.mts +15 -0
  155. package/dist/plugin-BJDf43dc.d.mts +165 -0
  156. package/dist/plugin-BJDf43dc.d.ts +165 -0
  157. package/dist/plugin.cjs +261 -62
  158. package/dist/plugin.cjs.map +1 -1
  159. package/dist/plugin.d.mts +25 -0
  160. package/dist/plugin.d.ts +25 -0
  161. package/dist/plugin.mjs +13 -9
  162. package/dist/production-runtime-C4cO3esK.d.mts +81 -0
  163. package/dist/production-runtime-DrEy8kBO.d.ts +81 -0
  164. package/dist/query/client.d.mts +61 -0
  165. package/dist/query/client.d.ts +61 -0
  166. package/dist/query/index.d.mts +90 -0
  167. package/dist/query/index.d.ts +90 -0
  168. package/dist/query/parsers.d.mts +25 -0
  169. package/dist/query/parsers.d.ts +25 -0
  170. package/dist/query/server.d.mts +55 -0
  171. package/dist/query/server.d.ts +55 -0
  172. package/dist/request-B2PpOxYK.d.mts +6 -0
  173. package/dist/request-D40lt6aN.d.ts +6 -0
  174. package/dist/request.d.mts +26 -0
  175. package/dist/request.d.ts +26 -0
  176. package/dist/resolver-DJqjLMg_.d.mts +14 -0
  177. package/dist/resolver-IH4RmPEl.d.ts +14 -0
  178. package/dist/route-runtime-DoOHzCAD.d.mts +38 -0
  179. package/dist/route-runtime-DoOHzCAD.d.ts +38 -0
  180. package/dist/router.d.mts +36 -0
  181. package/dist/router.d.ts +36 -0
  182. package/dist/routes.d.mts +227 -0
  183. package/dist/routes.d.ts +227 -0
  184. package/dist/runtime-Bpp-c28k.d.ts +231 -0
  185. package/dist/runtime-Cxpq6xZN.d.mts +27 -0
  186. package/dist/runtime-Q3u74Nbq.d.mts +231 -0
  187. package/dist/runtime-bv63eUiO.d.ts +27 -0
  188. package/dist/server-action-security.d.mts +45 -0
  189. package/dist/server-action-security.d.ts +45 -0
  190. package/dist/server-fn-client.d.mts +33 -0
  191. package/dist/server-fn-client.d.ts +33 -0
  192. package/dist/server-fn-error-DDh14a0V.d.mts +26 -0
  193. package/dist/server-fn-error-DDh14a0V.d.ts +26 -0
  194. package/dist/server-fn.d.mts +121 -0
  195. package/dist/server-fn.d.ts +121 -0
  196. package/dist/server-plugins.d.mts +58 -0
  197. package/dist/server-plugins.d.ts +58 -0
  198. package/dist/server-query-client.d.mts +51 -0
  199. package/dist/server-query-client.d.ts +51 -0
  200. package/dist/server-query.d.mts +37 -0
  201. package/dist/server-query.d.ts +37 -0
  202. package/dist/server.cjs +285 -85
  203. package/dist/server.cjs.map +1 -1
  204. package/dist/server.d.mts +53 -0
  205. package/dist/server.d.ts +53 -0
  206. package/dist/server.mjs +26 -31
  207. package/dist/server.mjs.map +1 -1
  208. package/dist/storage.d.mts +52 -0
  209. package/dist/storage.d.ts +52 -0
  210. package/dist/testing.d.mts +104 -0
  211. package/dist/testing.d.ts +104 -0
  212. package/dist/theme/client.cjs +115 -0
  213. package/dist/theme/client.cjs.map +1 -0
  214. package/dist/theme/client.d.mts +17 -0
  215. package/dist/theme/client.d.ts +17 -0
  216. package/dist/theme/client.mjs +16 -0
  217. package/dist/theme/client.mjs.map +1 -0
  218. package/dist/theme/index.cjs +71 -0
  219. package/dist/theme/index.cjs.map +1 -0
  220. package/dist/theme/index.d.mts +6 -0
  221. package/dist/theme/index.d.ts +6 -0
  222. package/dist/theme/index.mjs +9 -0
  223. package/dist/theme/index.mjs.map +1 -0
  224. package/dist/theme/server.cjs +191 -0
  225. package/dist/theme/server.cjs.map +1 -0
  226. package/dist/theme/server.d.mts +8 -0
  227. package/dist/theme/server.d.ts +8 -0
  228. package/dist/theme/server.mjs +18 -0
  229. package/dist/theme/server.mjs.map +1 -0
  230. package/dist/transport-BmbGTXA5.d.mts +49 -0
  231. package/dist/transport-BmbGTXA5.d.ts +49 -0
  232. package/dist/types-BMxWr97v.d.mts +81 -0
  233. package/dist/types-BMxWr97v.d.ts +81 -0
  234. package/dist/types-CsR8fpgF.d.mts +30 -0
  235. package/dist/types-CsR8fpgF.d.ts +30 -0
  236. package/dist/types-D1A6-XvH.d.mts +73 -0
  237. package/dist/types-D1A6-XvH.d.ts +73 -0
  238. package/dist/types-DTzm4TCl.d.mts +78 -0
  239. package/dist/types-DTzm4TCl.d.ts +78 -0
  240. package/dist/utils-3sQgfkya.d.ts +23 -0
  241. package/dist/utils-Bop7bly-.d.mts +23 -0
  242. package/dist/version.cjs +1 -1
  243. package/dist/version.cjs.map +1 -1
  244. package/dist/version.d.mts +3 -0
  245. package/dist/version.d.ts +3 -0
  246. package/dist/version.mjs +1 -1
  247. package/dist/vite.cjs +285 -64
  248. package/dist/vite.cjs.map +1 -1
  249. package/dist/vite.d.mts +25 -0
  250. package/dist/vite.d.ts +25 -0
  251. package/dist/vite.mjs +13 -9
  252. package/dist/workflows-CusFV6mn.d.mts +153 -0
  253. package/dist/workflows-CusFV6mn.d.ts +153 -0
  254. package/dist/workflows.d.mts +1 -0
  255. package/dist/workflows.d.ts +1 -0
  256. package/package.json +25 -1
  257. package/dist/chunk-4EATUJFO.mjs.map +0 -1
  258. package/dist/chunk-CEVMYGDL.mjs.map +0 -1
  259. package/dist/chunk-FKKM7HVF.mjs.map +0 -1
  260. package/dist/chunk-FRPWCMMG.mjs.map +0 -1
  261. package/dist/chunk-I3UWA2P2.mjs.map +0 -1
  262. package/dist/chunk-MIUW47JX.mjs.map +0 -1
  263. package/dist/chunk-VIC7NJ77.mjs.map +0 -1
  264. /package/dist/{chunk-RIXKJPGI.mjs.map → chunk-42325TLU.mjs.map} +0 -0
  265. /package/dist/{chunk-LLPN5SEZ.mjs.map → chunk-DVPRBMU2.mjs.map} +0 -0
  266. /package/dist/{chunk-UCYWGN2P.mjs.map → chunk-OHNSROHS.mjs.map} +0 -0
@@ -5920,6 +5920,52 @@ var init_security = __esm({
5920
5920
  }
5921
5921
  });
5922
5922
 
5923
+ // src/theme/config.ts
5924
+ function resolveFarmThemeConfig(config, basePath = "/") {
5925
+ if (config && "enabled" in config) {
5926
+ return config;
5927
+ }
5928
+ if (!config) {
5929
+ return {
5930
+ enabled: false,
5931
+ default: "system",
5932
+ storageKey: DEFAULT_FARM_THEME_STORAGE_KEY,
5933
+ cookiePath: normalizeCookiePath(basePath)
5934
+ };
5935
+ }
5936
+ const storageKey = config.storageKey?.trim() || DEFAULT_FARM_THEME_STORAGE_KEY;
5937
+ if (!STORAGE_KEY_PATTERN.test(storageKey)) {
5938
+ throw new Error(
5939
+ "theme.storageKey may only contain letters, numbers, dots, underscores, and hyphens."
5940
+ );
5941
+ }
5942
+ const defaultTheme = config.default ?? "system";
5943
+ if (defaultTheme !== "light" && defaultTheme !== "dark" && defaultTheme !== "system") {
5944
+ throw new Error('theme.default must be "light", "dark", or "system".');
5945
+ }
5946
+ return {
5947
+ enabled: true,
5948
+ default: defaultTheme,
5949
+ storageKey,
5950
+ cookiePath: normalizeCookiePath(basePath)
5951
+ };
5952
+ }
5953
+ function normalizeCookiePath(basePath) {
5954
+ const normalized = `/${basePath}`.replace(/\/{2,}/g, "/");
5955
+ if (normalized === "/") return normalized;
5956
+ return normalized.replace(/\/$/, "");
5957
+ }
5958
+ var DEFAULT_FARM_THEME_STORAGE_KEY, STORAGE_KEY_PATTERN;
5959
+ var init_config2 = __esm({
5960
+ "src/theme/config.ts"() {
5961
+ "use strict";
5962
+ DEFAULT_FARM_THEME_STORAGE_KEY = "farm-theme";
5963
+ STORAGE_KEY_PATTERN = /^[A-Za-z0-9._-]+$/;
5964
+ __name(resolveFarmThemeConfig, "resolveFarmThemeConfig");
5965
+ __name(normalizeCookiePath, "normalizeCookiePath");
5966
+ }
5967
+ });
5968
+
5923
5969
  // src/config-entry.ts
5924
5970
  var init_config_entry = __esm({
5925
5971
  "src/config-entry.ts"() {
@@ -6246,6 +6292,7 @@ async function resolveConfig(userConfig, mode) {
6246
6292
  routeRules,
6247
6293
  images: resolveFarmImageConfig(userConfig.images),
6248
6294
  performance: resolveFarmPerformanceConfig(userConfig.performance),
6295
+ theme: resolveFarmThemeConfig(userConfig.theme, userConfig.basePath || "/"),
6249
6296
  publicDir: userConfig.publicDir || "public",
6250
6297
  i18n: resolveFarmI18nConfig(userConfig.i18n, { root, mode }),
6251
6298
  openapi: {
@@ -6323,7 +6370,7 @@ async function loadConfig(rootDir, configPath, mode = process.env.NODE_ENV === "
6323
6370
  return void 0;
6324
6371
  }
6325
6372
  var import_path2, FARM_RESOLVED_CUSTOM_CONTEXT, DOCS_CONFIG_FILENAMES;
6326
- var init_config2 = __esm({
6373
+ var init_config3 = __esm({
6327
6374
  "src/config.ts"() {
6328
6375
  "use strict";
6329
6376
  init_integrations();
@@ -6344,6 +6391,7 @@ var init_config2 = __esm({
6344
6391
  init_auth_config();
6345
6392
  init_preload();
6346
6393
  init_security();
6394
+ init_config2();
6347
6395
  init_config_entry();
6348
6396
  FARM_RESOLVED_CUSTOM_CONTEXT = /* @__PURE__ */ Symbol.for("farm.resolvedCustomContext");
6349
6397
  __name(hasCustomFarmRouteContext, "hasCustomFarmRouteContext");
@@ -10442,6 +10490,15 @@ function createWebRequestFromFarmRequest(req) {
10442
10490
  async function _runWithCurrentRequest(request, fn) {
10443
10491
  return requestStore.run(request, fn);
10444
10492
  }
10493
+ function getCurrentRequest() {
10494
+ const request = requestStore.getStore();
10495
+ if (!request) {
10496
+ throw new Error(
10497
+ "No current request is available. getCurrentRequest() can only be used during server rendering."
10498
+ );
10499
+ }
10500
+ return request;
10501
+ }
10445
10502
  var import_node_async_hooks2, REQUEST_STORAGE_KEY, requestStore;
10446
10503
  var init_request = __esm({
10447
10504
  "src/server/request.ts"() {
@@ -10454,6 +10511,7 @@ var init_request = __esm({
10454
10511
  _setCurrentRequestResolver(() => requestStore.getStore());
10455
10512
  __name(createWebRequestFromFarmRequest, "createWebRequestFromFarmRequest");
10456
10513
  __name(_runWithCurrentRequest, "_runWithCurrentRequest");
10514
+ __name(getCurrentRequest, "getCurrentRequest");
10457
10515
  }
10458
10516
  });
10459
10517
 
@@ -12961,12 +13019,151 @@ body {
12961
13019
  }
12962
13020
  });
12963
13021
 
13022
+ // src/theme/server-runtime.ts
13023
+ function createFarmThemeDocumentParts(input, basePath = "/", serverTheme) {
13024
+ const config = resolveFarmThemeConfig(input, basePath);
13025
+ if (!config.enabled) return { attributes: "", head: "" };
13026
+ const hydrationTheme = serverTheme ?? config.default;
13027
+ const initialTheme = hydrationTheme === "system" ? "light" : hydrationTheme;
13028
+ const script = createFarmThemeBootstrapScript(config, hydrationTheme);
13029
+ return {
13030
+ attributes: ` data-theme="${initialTheme}"`,
13031
+ 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>`
13032
+ };
13033
+ }
13034
+ function createFarmThemeBootstrapScript(config, serverTheme = config.default) {
13035
+ return `(function(config,serverTheme){
13036
+ var isTheme=function(value){return value==="light"||value==="dark"||value==="system";};
13037
+ var decode=function(value){try{return decodeURIComponent(value);}catch(_error){return value;}};
13038
+ 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());}};
13039
+ var media=window.matchMedia("(prefers-color-scheme: dark)");
13040
+ var resolveTheme=function(theme){return theme==="system"?(media.matches?"dark":"light"):theme;};
13041
+ var storedTheme=readCookie();
13042
+ var preference=isTheme(storedTheme)?storedTheme:config.default;
13043
+ var serverSnapshot={theme:serverTheme,resolvedTheme:serverTheme==="system"?undefined:serverTheme,mounted:false};
13044
+ 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;};
13045
+ var emit=function(){var snapshot=apply();window.dispatchEvent(new CustomEvent("farm:themechange",{detail:snapshot}));};
13046
+ 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){}};
13047
+ var setTheme=function(theme){if(!isTheme(theme))throw new TypeError("Unknown FARMJS theme: "+String(theme));preference=theme;persist(theme);emit();};
13048
+ var initialSnapshot={theme:preference,resolvedTheme:resolveTheme(preference),mounted:true};
13049
+ window.__FARM_THEME__={config:config,serverSnapshot:serverSnapshot,snapshot:initialSnapshot,setTheme:setTheme};
13050
+ document.documentElement.dataset.theme=initialSnapshot.resolvedTheme;
13051
+ var handleSystemChange=function(){if(preference==="system")emit();};
13052
+ if(typeof media.addEventListener==="function")media.addEventListener("change",handleSystemChange);else if(typeof media.addListener==="function")media.addListener(handleSystemChange);
13053
+ window.addEventListener("storage",function(event){if(event.key!==config.storageKey||!isTheme(event.newValue))return;preference=event.newValue;persist(preference);emit();});
13054
+ })(${serializeInlineValue(config)},${serializeInlineValue(serverTheme)});`;
13055
+ }
13056
+ function serializeInlineValue(value) {
13057
+ return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
13058
+ }
13059
+ var THEME_SCRIPT_ID, THEME_STYLE_ID;
13060
+ var init_server_runtime = __esm({
13061
+ "src/theme/server-runtime.ts"() {
13062
+ "use strict";
13063
+ init_config2();
13064
+ THEME_SCRIPT_ID = "farm-theme-script";
13065
+ THEME_STYLE_ID = "farm-theme-style";
13066
+ __name(createFarmThemeDocumentParts, "createFarmThemeDocumentParts");
13067
+ __name(createFarmThemeBootstrapScript, "createFarmThemeBootstrapScript");
13068
+ __name(serializeInlineValue, "serializeInlineValue");
13069
+ }
13070
+ });
13071
+
13072
+ // src/theme/bridge.ts
13073
+ function _setFarmThemeServerSnapshotResolver(resolver) {
13074
+ globalThis[FARM_THEME_SERVER_SNAPSHOT_RESOLVER] = resolver;
13075
+ }
13076
+ var FALLBACK_SERVER_SNAPSHOT, FARM_THEME_SERVER_SNAPSHOT_RESOLVER;
13077
+ var init_bridge2 = __esm({
13078
+ "src/theme/bridge.ts"() {
13079
+ "use strict";
13080
+ FALLBACK_SERVER_SNAPSHOT = Object.freeze({
13081
+ theme: "system",
13082
+ resolvedTheme: void 0,
13083
+ mounted: false
13084
+ });
13085
+ FARM_THEME_SERVER_SNAPSHOT_RESOLVER = /* @__PURE__ */ Symbol.for("farm.js.theme.server-snapshot-resolver");
13086
+ __name(_setFarmThemeServerSnapshotResolver, "_setFarmThemeServerSnapshotResolver");
13087
+ }
13088
+ });
13089
+
13090
+ // src/theme/server.ts
13091
+ function _setDefaultFarmThemeConfig(config, basePath = "/") {
13092
+ defaultThemeConfig = resolveFarmThemeConfig(config, basePath);
13093
+ }
13094
+ function getTheme(request = getCurrentRequest()) {
13095
+ return readFarmThemePreference(request, defaultThemeConfig);
13096
+ }
13097
+ function getThemeSnapshot(request = getCurrentRequest()) {
13098
+ const theme = readFarmThemePreference(request, defaultThemeConfig);
13099
+ return {
13100
+ theme,
13101
+ resolvedTheme: theme === "system" ? void 0 : theme,
13102
+ mounted: false
13103
+ };
13104
+ }
13105
+ function readFarmThemePreference(request, config) {
13106
+ if (!config.enabled) return config.default;
13107
+ const stored = readCookie3(request.headers.get("cookie"), config.storageKey);
13108
+ return isFarmThemePreference(stored) ? stored : config.default;
13109
+ }
13110
+ function readCookie3(cookieHeader, name) {
13111
+ if (!cookieHeader) return void 0;
13112
+ for (const entry of cookieHeader.split(";")) {
13113
+ const separator = entry.indexOf("=");
13114
+ if (separator < 0) continue;
13115
+ const key = decodeCookieValue(entry.slice(0, separator).trim());
13116
+ if (key !== name) continue;
13117
+ return decodeCookieValue(entry.slice(separator + 1).trim());
13118
+ }
13119
+ return void 0;
13120
+ }
13121
+ function decodeCookieValue(value) {
13122
+ try {
13123
+ return decodeURIComponent(value);
13124
+ } catch {
13125
+ return value;
13126
+ }
13127
+ }
13128
+ function isFarmThemePreference(value) {
13129
+ return value === "light" || value === "dark" || value === "system";
13130
+ }
13131
+ var defaultThemeConfig;
13132
+ var init_server3 = __esm({
13133
+ "src/theme/server.ts"() {
13134
+ "use strict";
13135
+ init_request();
13136
+ init_bridge2();
13137
+ init_config2();
13138
+ defaultThemeConfig = resolveFarmThemeConfig(void 0);
13139
+ __name(_setDefaultFarmThemeConfig, "_setDefaultFarmThemeConfig");
13140
+ __name(getTheme, "getTheme");
13141
+ __name(getThemeSnapshot, "getThemeSnapshot");
13142
+ __name(readFarmThemePreference, "readFarmThemePreference");
13143
+ __name(readCookie3, "readCookie");
13144
+ __name(decodeCookieValue, "decodeCookieValue");
13145
+ __name(isFarmThemePreference, "isFarmThemePreference");
13146
+ _setFarmThemeServerSnapshotResolver(() => {
13147
+ try {
13148
+ return getThemeSnapshot();
13149
+ } catch {
13150
+ const theme = defaultThemeConfig.default;
13151
+ return {
13152
+ theme,
13153
+ resolvedTheme: theme === "system" ? void 0 : theme,
13154
+ mounted: false
13155
+ };
13156
+ }
13157
+ });
13158
+ }
13159
+ });
13160
+
12964
13161
  // src/server/renderer.ts
12965
13162
  function hasRequestHeader(req, name) {
12966
13163
  const value = req.headers[name.toLowerCase()];
12967
13164
  return Array.isArray(value) ? value.length > 0 : Boolean(value);
12968
13165
  }
12969
- function serializeInlineValue(value) {
13166
+ function serializeInlineValue2(value) {
12970
13167
  return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
12971
13168
  }
12972
13169
  function escapeHtmlAttribute2(value) {
@@ -13053,7 +13250,7 @@ function createDocumentFooter(options) {
13053
13250
  }
13054
13251
  function createDeferredHydrationScript(records) {
13055
13252
  if (records.length === 0) return "";
13056
- return `<script>window.__FARM_DEFERRED_DATA__=${serializeInlineValue(
13253
+ return `<script>window.__FARM_DEFERRED_DATA__=${serializeInlineValue2(
13057
13254
  snapshotDeferredData(records)
13058
13255
  )};</script>`;
13059
13256
  }
@@ -13146,10 +13343,12 @@ var init_renderer = __esm({
13146
13343
  init_font_vite();
13147
13344
  init_metadata_image();
13148
13345
  init_not_found();
13346
+ init_server_runtime();
13347
+ init_server3();
13149
13348
  cachedClerkProvider = null;
13150
13349
  importRuntimeModule = new Function("specifier", "return import(specifier);");
13151
13350
  __name(hasRequestHeader, "hasRequestHeader");
13152
- __name(serializeInlineValue, "serializeInlineValue");
13351
+ __name(serializeInlineValue2, "serializeInlineValue");
13153
13352
  __name(escapeHtmlAttribute2, "escapeHtmlAttribute");
13154
13353
  __name(appendResponseHeader, "appendResponseHeader");
13155
13354
  __name(appendResponseVary, "appendResponseVary");
@@ -14237,9 +14436,9 @@ var init_renderer = __esm({
14237
14436
  slots: routeSlotPayload
14238
14437
  });
14239
14438
  const propsScript = `<script>
14240
- window.__FARM_PROPS__ = ${serializeInlineValue(deferredProps.data.page)};
14241
- window.__FARM_ROUTE_SLOTS__ = ${serializeInlineValue(deferredProps.data.slots)};
14242
- window.__FARM_DEPLOYMENT_ID__ = ${serializeInlineValue(deploymentId)};
14439
+ window.__FARM_PROPS__ = ${serializeInlineValue2(deferredProps.data.page)};
14440
+ window.__FARM_ROUTE_SLOTS__ = ${serializeInlineValue2(deferredProps.data.slots)};
14441
+ window.__FARM_DEPLOYMENT_ID__ = ${serializeInlineValue2(deploymentId)};
14243
14442
  window.__FARM_PATH__ = ${JSON.stringify(req.__FARM_ROUTE__ || req.url || "/")};
14244
14443
  window.__FARM_IS_CLIENT__ = ${JSON.stringify(isClientComponent)};
14245
14444
  window.__FARM_PAGE_SHOULD_HYDRATE__ = ${JSON.stringify(
@@ -14257,7 +14456,7 @@ window.__FARM_LOADING_MODULE__ = ${JSON.stringify(
14257
14456
  )};
14258
14457
  window.__FARM_MANIFEST__ = ${JSON.stringify(clientManifest)};
14259
14458
  window.__FARM_INTEGRATION_API_MANIFEST__ = ${JSON.stringify(getRegisteredIntegrationAPIManifest())};
14260
- ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue(getFarmI18nClientSnapshot())};` : ""}
14459
+ ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue2(getFarmI18nClientSnapshot())};` : ""}
14261
14460
  </script>`;
14262
14461
  const hydrationClickQueueScript = isClientComponent || req.__FARM_SHOULD_HYDRATE__ === true || req.__FARM_HAS_HYDRATABLE_ROUTE_SLOTS__ === true ? createPreHydrationClickQueueScript() : "";
14263
14462
  const {
@@ -14268,6 +14467,11 @@ ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue(g
14268
14467
  const i18nSnapshot = getFarmI18nClientSnapshot();
14269
14468
  const i18nAlternateTags = i18nSnapshot ? renderI18nAlternateLinks(req.__FARM_ROUTE__ || req.url || "/", i18nSnapshot) : "";
14270
14469
  const fontHead = renderFarmFontDevHead(this.config.root || process.cwd());
14470
+ const themeDocument = createFarmThemeDocumentParts(
14471
+ this.config.theme,
14472
+ this.config.basePath,
14473
+ getTheme()
14474
+ );
14271
14475
  const streamRoot = import_react5.default.createElement("div", { style: { display: "contents" } }, element);
14272
14476
  const { pipe } = (0, import_server2.renderToPipeableStream)(streamRoot, {
14273
14477
  onShellReady() {
@@ -14281,8 +14485,9 @@ ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue(g
14281
14485
  console.log(`[FARM STREAM] onShellReady at ${shellReadyMs}ms`);
14282
14486
  }
14283
14487
  const shell = `<!DOCTYPE html>
14284
- <html lang="${escapeHtmlAttribute2(i18nSnapshot?.locale || "en")}"${i18nSnapshot ? ` dir="${i18nSnapshot.direction}"` : ""}>
14488
+ <html lang="${escapeHtmlAttribute2(i18nSnapshot?.locale || "en")}"${i18nSnapshot ? ` dir="${i18nSnapshot.direction}"` : ""}${themeDocument.attributes}>
14285
14489
  <head>
14490
+ ${themeDocument.head}
14286
14491
  <meta charset="utf-8">
14287
14492
  <meta name="viewport" content="width=device-width, initial-scale=1">
14288
14493
  <meta name="farm-deployment-id" content="${escapeHtmlAttribute2(deploymentId)}">
@@ -14484,15 +14689,21 @@ ${getFarmI18nClientSnapshot() ? `window.__FARM_I18N__ = ${serializeInlineValue(g
14484
14689
  const i18nSnapshot = getFarmI18nClientSnapshot();
14485
14690
  const clientScript = isClientComponent ? ` <script type="module" src="/@farm/client.js"></script>` : "";
14486
14691
  const integrationManifestScript = `<script>
14487
- window.__FARM_DEPLOYMENT_ID__ = ${serializeInlineValue(this.getDeploymentId())};
14692
+ window.__FARM_DEPLOYMENT_ID__ = ${serializeInlineValue2(this.getDeploymentId())};
14488
14693
  window.__FARM_INTEGRATION_API_MANIFEST__ = ${JSON.stringify(getRegisteredIntegrationAPIManifest())};
14489
- ${i18nSnapshot ? `window.__FARM_I18N__ = ${serializeInlineValue(i18nSnapshot)};` : ""}
14694
+ ${i18nSnapshot ? `window.__FARM_I18N__ = ${serializeInlineValue2(i18nSnapshot)};` : ""}
14490
14695
  </script>`;
14491
14696
  const alternateLinks = i18nSnapshot ? renderI18nAlternateLinks(requestPath, i18nSnapshot) : "";
14492
14697
  const fontHead = renderFarmFontDevHead(this.config.root || process.cwd());
14698
+ const themeDocument = createFarmThemeDocumentParts(
14699
+ this.config.theme,
14700
+ this.config.basePath,
14701
+ getTheme()
14702
+ );
14493
14703
  return `<!DOCTYPE html>
14494
- <html lang="${escapeHtmlAttribute2(i18nSnapshot?.locale || "en")}"${i18nSnapshot ? ` dir="${i18nSnapshot.direction}"` : ""}>
14704
+ <html lang="${escapeHtmlAttribute2(i18nSnapshot?.locale || "en")}"${i18nSnapshot ? ` dir="${i18nSnapshot.direction}"` : ""}${themeDocument.attributes}>
14495
14705
  <head>
14706
+ ${themeDocument.head}
14496
14707
  <meta charset="utf-8">
14497
14708
  <meta name="viewport" content="width=device-width, initial-scale=1">
14498
14709
  <meta name="farm-deployment-id" content="${escapeHtmlAttribute2(this.getDeploymentId())}">
@@ -14576,6 +14787,8 @@ var init_app = __esm({
14576
14787
  init_auth_config();
14577
14788
  init_preload();
14578
14789
  init_security();
14790
+ init_config2();
14791
+ init_server3();
14579
14792
  defaultDocsConfig = {
14580
14793
  enabled: false,
14581
14794
  entry: "/docs",
@@ -14586,6 +14799,7 @@ var init_app = __esm({
14586
14799
  constructor(config = {}, viteServer) {
14587
14800
  this.config = this.normalizeConfig(config);
14588
14801
  configureFarmObservability(this.config.observability);
14802
+ _setDefaultFarmThemeConfig(this.config.theme);
14589
14803
  this.i18nRuntime = createFarmI18nRuntime(this.config.i18n);
14590
14804
  _setDefaultFarmI18nRuntime(this.i18nRuntime);
14591
14805
  this.viteServer = viteServer;
@@ -14644,6 +14858,7 @@ var init_app = __esm({
14644
14858
  security: resolveFarmSecurityConfig(config.security),
14645
14859
  images: resolveFarmImageConfig(config.images),
14646
14860
  performance: resolveFarmPerformanceConfig(config.performance),
14861
+ theme: resolveFarmThemeConfig(config.theme, config.basePath || "/"),
14647
14862
  i18n: isResolvedI18nConfig(config.i18n) ? config.i18n : resolveFarmI18nConfig(config.i18n, {
14648
14863
  root,
14649
14864
  mode: process.env.NODE_ENV === "production" ? "production" : "development"
@@ -16409,6 +16624,36 @@ var init_vite_config = __esm({
16409
16624
  }
16410
16625
  });
16411
16626
 
16627
+ // src/theme/vite.ts
16628
+ function createFarmThemeCssPlugin(input, basePath = "/") {
16629
+ const config = resolveFarmThemeConfig(input, basePath);
16630
+ return {
16631
+ name: "farm:theme-css",
16632
+ enforce: "pre",
16633
+ transform(code, id) {
16634
+ if (!config.enabled || !/\.css(?:\?.*)?$/.test(id) || !/@import\s+["']tailwindcss["']/.test(code) || /@custom-variant\s+dark\b/.test(code)) {
16635
+ return null;
16636
+ }
16637
+ return {
16638
+ code: `${code.trimEnd()}
16639
+
16640
+ ${FARM_DARK_VARIANT}
16641
+ `,
16642
+ map: null
16643
+ };
16644
+ }
16645
+ };
16646
+ }
16647
+ var FARM_DARK_VARIANT;
16648
+ var init_vite = __esm({
16649
+ "src/theme/vite.ts"() {
16650
+ "use strict";
16651
+ init_config2();
16652
+ FARM_DARK_VARIANT = '@custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *));';
16653
+ __name(createFarmThemeCssPlugin, "createFarmThemeCssPlugin");
16654
+ }
16655
+ });
16656
+
16412
16657
  // src/default-styles.ts
16413
16658
  var defaultGlobalCSS;
16414
16659
  var init_default_styles = __esm({
@@ -16727,6 +16972,19 @@ var init_module = __esm({
16727
16972
  }
16728
16973
  });
16729
16974
 
16975
+ // src/cli-colors.ts
16976
+ function createCliColors(interactive = process.stdout.isTTY === true) {
16977
+ return import_picocolors.default.createColors(interactive);
16978
+ }
16979
+ var import_picocolors;
16980
+ var init_cli_colors = __esm({
16981
+ "src/cli-colors.ts"() {
16982
+ "use strict";
16983
+ import_picocolors = __toESM(require("picocolors"));
16984
+ __name(createCliColors, "createCliColors");
16985
+ }
16986
+ });
16987
+
16730
16988
  // src/middleware/manager.ts
16731
16989
  function isMiddlewareResponse(value) {
16732
16990
  return value instanceof Response;
@@ -16743,6 +17001,7 @@ var init_manager = __esm({
16743
17001
  init_response();
16744
17002
  init_observability();
16745
17003
  init_routing();
17004
+ init_cli_colors();
16746
17005
  __name(isMiddlewareResponse, "isMiddlewareResponse");
16747
17006
  _MiddlewareManager = class _MiddlewareManager {
16748
17007
  constructor(appDir, viteServer, config, i18n) {
@@ -16896,23 +17155,16 @@ var init_manager = __esm({
16896
17155
  if (applicable.length === 0) {
16897
17156
  return false;
16898
17157
  }
16899
- try {
16900
- const pc = require("picocolors");
16901
- const middlewarePaths = applicable.map(({ mw }) => mw.path).join(", ");
16902
- const log = [
16903
- pc.dim("[") + pc.bold(pc.blue("FARM")) + pc.dim("]"),
16904
- pc.dim("[") + pc.bold(pc.magenta("MIDDLEWARE")) + pc.dim("]"),
16905
- pc.dim("[") + pc.bold(pc.white(method.padEnd(3))) + pc.dim("]"),
16906
- pc.gray("Executing middleware: "),
16907
- pc.gray(pathname),
16908
- pc.dim(` (${(Date.now() - startTime).toFixed(2)}ms)`)
16909
- ].join(" ");
16910
- console.log(log);
16911
- } catch {
16912
- console.log(
16913
- `[FARM] [MIDDLEWARE] [${method}] Executing ${pathname} (${applicable.length} middleware)`
16914
- );
16915
- }
17158
+ const pc = createCliColors();
17159
+ const log = [
17160
+ pc.dim("[") + pc.bold(pc.blue("FARM")) + pc.dim("]"),
17161
+ pc.dim("[") + pc.bold(pc.magenta("MIDDLEWARE")) + pc.dim("]"),
17162
+ pc.dim("[") + pc.bold(pc.white(method.padEnd(3))) + pc.dim("]"),
17163
+ pc.gray("Executing middleware: "),
17164
+ pc.gray(pathname),
17165
+ pc.dim(` (${(Date.now() - startTime).toFixed(2)}ms)`)
17166
+ ].join(" ");
17167
+ console.log(log);
16916
17168
  for (const entry of applicable) {
16917
17169
  const { mw, routeMatch } = entry;
16918
17170
  const configMatch = mw.config ? this.matchesConfig(routePathname, mw.config, ctx) : { matched: true };
@@ -18074,7 +18326,7 @@ var init_type_artifacts = __esm({
18074
18326
  var version;
18075
18327
  var init_package = __esm({
18076
18328
  "package.json"() {
18077
- version = "0.1.0-beta.21";
18329
+ version = "0.1.0-beta.23";
18078
18330
  }
18079
18331
  });
18080
18332
 
@@ -22488,7 +22740,7 @@ var init_api = __esm({
22488
22740
  "src/docs/api.ts"() {
22489
22741
  "use strict";
22490
22742
  import_docs2 = require("@farming-labs/docs");
22491
- init_config2();
22743
+ init_config3();
22492
22744
  init_handler();
22493
22745
  __name(isRecord4, "isRecord");
22494
22746
  __name(isResolvedDocsConfig2, "isResolvedDocsConfig");
@@ -23473,7 +23725,7 @@ var init_devtools = __esm({
23473
23725
  "src/devtools.ts"() {
23474
23726
  "use strict";
23475
23727
  import_node_path14 = __toESM(require("path"));
23476
- init_config2();
23728
+ init_config3();
23477
23729
  init_cron();
23478
23730
  init_route_runtime();
23479
23731
  __name(normalizePath, "normalizePath");
@@ -25375,18 +25627,14 @@ function farmPlugin(options = {}, initialPluginManager) {
25375
25627
  let refreshRouteDiscovery = null;
25376
25628
  let workflowHandler = null;
25377
25629
  const logUpdate = /* @__PURE__ */ __name((tag, message) => {
25378
- try {
25379
- const pc = require("picocolors");
25380
- const log = [
25381
- pc.dim("[") + pc.bold(pc.blue("FARM")) + pc.dim("]"),
25382
- pc.dim("[") + pc.bold(pc.cyan(tag)) + pc.dim("]"),
25383
- pc.dim("[") + pc.bold(pc.yellow("UPDATE")) + pc.dim("]"),
25384
- pc.gray(message)
25385
- ].join(" ");
25386
- console.log(log);
25387
- } catch {
25388
- console.log(`[FARM] [${tag}] [UPDATE] ${message}`);
25389
- }
25630
+ const pc = createCliColors();
25631
+ const log = [
25632
+ pc.dim("[") + pc.bold(pc.blue("FARM")) + pc.dim("]"),
25633
+ pc.dim("[") + pc.bold(pc.cyan(tag)) + pc.dim("]"),
25634
+ pc.dim("[") + pc.bold(pc.yellow("UPDATE")) + pc.dim("]"),
25635
+ pc.gray(message)
25636
+ ].join(" ");
25637
+ console.log(log);
25390
25638
  }, "logUpdate");
25391
25639
  return {
25392
25640
  name: "farm",
@@ -25827,25 +26075,21 @@ window.__FARM_MANIFEST__ = ${inlineValue({
25827
26075
  return;
25828
26076
  }
25829
26077
  logResponse.__last = { key: dedupeKey, ts: now };
25830
- try {
25831
- const pc = require("picocolors");
25832
- let statusColor = pc.green;
25833
- if (status >= 500) statusColor = pc.red;
25834
- else if (status >= 400) statusColor = pc.yellow;
25835
- else if (status >= 300) statusColor = pc.cyan;
25836
- const log = [
25837
- pc.dim("[") + pc.bold(pc.blue("FARM")) + pc.dim("]"),
25838
- pc.dim("[") + pc.bold(pc.cyan(tag)) + pc.dim("]"),
25839
- pc.dim("[") + pc.bold(pc.white(method.padEnd(3))) + pc.dim("]"),
25840
- pc.gray(urlPath),
25841
- pc.dim("-"),
25842
- statusColor(status.toString()),
25843
- pc.dim(`(${duration}ms)`)
25844
- ].join(" ");
25845
- console.log(log);
25846
- } catch {
25847
- console.log(`[FARM] [${tag}] [${method}] ${urlPath} - ${status} (${duration}ms)`);
25848
- }
26078
+ const pc = createCliColors();
26079
+ let statusColor = pc.green;
26080
+ if (status >= 500) statusColor = pc.red;
26081
+ else if (status >= 400) statusColor = pc.yellow;
26082
+ else if (status >= 300) statusColor = pc.cyan;
26083
+ const log = [
26084
+ pc.dim("[") + pc.bold(pc.blue("FARM")) + pc.dim("]"),
26085
+ pc.dim("[") + pc.bold(pc.cyan(tag)) + pc.dim("]"),
26086
+ pc.dim("[") + pc.bold(pc.white(method.padEnd(3))) + pc.dim("]"),
26087
+ pc.gray(urlPath),
26088
+ pc.dim("-"),
26089
+ statusColor(status.toString()),
26090
+ pc.dim(`(${duration}ms)`)
26091
+ ].join(" ");
26092
+ console.log(log);
25849
26093
  }, "logResponse");
25850
26094
  server.middlewares.use(
25851
26095
  _withAfterNodeMiddleware(async (req, res, next) => {
@@ -28459,14 +28703,22 @@ async function renderPage(pageData) {
28459
28703
  if (!doc.documentElement || !doc.body) return false;
28460
28704
 
28461
28705
  resetReactRoots();
28706
+ const activeFarmTheme =
28707
+ window.__FARM_THEME__?.snapshot?.resolvedTheme ||
28708
+ document.documentElement.getAttribute('data-theme');
28462
28709
  Array.from(document.documentElement.attributes).forEach(function(attr) {
28710
+ if (attr.name === 'data-theme') return;
28463
28711
  if (!doc.documentElement.hasAttribute(attr.name)) {
28464
28712
  document.documentElement.removeAttribute(attr.name);
28465
28713
  }
28466
28714
  });
28467
28715
  Array.from(doc.documentElement.attributes).forEach(function(attr) {
28716
+ if (attr.name === 'data-theme') return;
28468
28717
  document.documentElement.setAttribute(attr.name, attr.value);
28469
28718
  });
28719
+ if (activeFarmTheme) {
28720
+ document.documentElement.setAttribute('data-theme', activeFarmTheme);
28721
+ }
28470
28722
 
28471
28723
  document.head.innerHTML = doc.head ? doc.head.innerHTML : '';
28472
28724
  document.body.innerHTML = doc.body.innerHTML;
@@ -28475,6 +28727,7 @@ async function renderPage(pageData) {
28475
28727
 
28476
28728
  setTimeout(function() {
28477
28729
  Array.from(document.querySelectorAll('script')).forEach(function(script) {
28730
+ if (script.id === 'farm-theme-script') return;
28478
28731
  const freshScript = document.createElement('script');
28479
28732
  Array.from(script.attributes).forEach(function(attr) {
28480
28733
  freshScript.setAttribute(attr.name, attr.value);
@@ -28902,7 +29155,7 @@ async function defineConfig2(config = {}) {
28902
29155
  return null;
28903
29156
  }
28904
29157
  };
28905
- const pc = await import("picocolors").then((m) => m.default);
29158
+ const pc = createCliColors();
28906
29159
  let serverStarted = false;
28907
29160
  let startTime = Date.now();
28908
29161
  const farmLogger = {
@@ -28969,6 +29222,7 @@ async function defineConfig2(config = {}) {
28969
29222
  };
28970
29223
  return {
28971
29224
  plugins: [
29225
+ createFarmThemeCssPlugin(config.theme, config.basePath),
28972
29226
  tailwindcss(),
28973
29227
  viteBrowserExternalPlugin,
28974
29228
  farmI18nClientBridgePlugin(),
@@ -29041,7 +29295,7 @@ async function defineConfig2(config = {}) {
29041
29295
  };
29042
29296
  }
29043
29297
  var fs7, path27, ALL_TYPE_ARTIFACTS, createEmptyTypeArtifactSelection, FARM_I18N_CLIENT_BRIDGE_ID, EMPTY_FARM_DOCS_SEARCH_CLIENT_RUNTIME, FARM_CONFIG_FILENAMES;
29044
- var init_vite = __esm({
29298
+ var init_vite2 = __esm({
29045
29299
  "src/vite.ts"() {
29046
29300
  "use strict";
29047
29301
  init_app();
@@ -29077,6 +29331,8 @@ var init_vite = __esm({
29077
29331
  init_vite_config();
29078
29332
  init_fonts();
29079
29333
  init_server_http();
29334
+ init_cli_colors();
29335
+ init_vite();
29080
29336
  ALL_TYPE_ARTIFACTS = {
29081
29337
  routes: true,
29082
29338
  api: true,
@@ -29176,7 +29432,7 @@ var init_plugin = __esm({
29176
29432
  init_env();
29177
29433
  init_request_context();
29178
29434
  init_plugin_integration_context();
29179
- init_vite();
29435
+ init_vite2();
29180
29436
  _FarmRuntimeShutdownError = class _FarmRuntimeShutdownError extends Error {
29181
29437
  constructor(message, errors) {
29182
29438
  super(message);
@@ -30521,7 +30777,7 @@ __export(build_runtime_exports, {
30521
30777
  module.exports = __toCommonJS(build_runtime_exports);
30522
30778
 
30523
30779
  // src/build/index.ts
30524
- init_config2();
30780
+ init_config3();
30525
30781
  var import_path14 = __toESM(require("path"));
30526
30782
  init_utils();
30527
30783
  init_app();
@@ -30529,7 +30785,7 @@ init_route_manager2();
30529
30785
  init_layers();
30530
30786
 
30531
30787
  // src/nitro/universal-build.ts
30532
- init_config2();
30788
+ init_config3();
30533
30789
  init_client_plugin_build();
30534
30790
  var import_os = __toESM(require("os"));
30535
30791
  var import_path12 = __toESM(require("path"));
@@ -31065,6 +31321,7 @@ __name(withVite5TransformContext, "withVite5TransformContext");
31065
31321
  init_font_vite();
31066
31322
  init_vite_config();
31067
31323
  init_not_found();
31324
+ init_vite();
31068
31325
  var import_meta = {};
31069
31326
  function preloadFarmNitroRuntime() {
31070
31327
  return import("nitro").then(
@@ -31737,7 +31994,7 @@ async function validateClientBuildOutput(root, srcDir, outputDir) {
31737
31994
  __name(validateClientBuildOutput, "validateClientBuildOutput");
31738
31995
  async function buildClient(productionVite, config, root, srcDir, outputDir, pageRoutes, layoutRoutes = [], routeSlots = []) {
31739
31996
  const viteBuild = productionVite.build;
31740
- const { farmPlugin: farmPlugin2 } = await Promise.resolve().then(() => (init_vite(), vite_exports));
31997
+ const { farmPlugin: farmPlugin2 } = await Promise.resolve().then(() => (init_vite2(), vite_exports));
31741
31998
  const { PluginManager: PluginManager2 } = await Promise.resolve().then(() => (init_plugin(), plugin_exports));
31742
31999
  const fs8 = await import("fs/promises");
31743
32000
  const pluginManager = new PluginManager2({
@@ -31929,6 +32186,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
31929
32186
  }
31930
32187
  },
31931
32188
  plugins: [
32189
+ createFarmThemeCssPlugin(config.theme, config.basePath),
31932
32190
  ...tailwindVitePlugin ? [tailwindVitePlugin] : [],
31933
32191
  // Plugin to redirect @farm.js/core imports to client-only exports
31934
32192
  {
@@ -33306,7 +33564,7 @@ void hydrate();
33306
33564
  __name(generateClientHydrationEntry, "generateClientHydrationEntry");
33307
33565
  async function buildSSRInMemory(productionVite, config, root, routeManager, apiRouteManager, serverRenderer, preset, collectedPageRoutes, collectedLayoutRoutes, collectedRouteSlots) {
33308
33566
  const viteBuild = productionVite.build;
33309
- const { farmPlugin: farmPlugin2 } = await Promise.resolve().then(() => (init_vite(), vite_exports));
33567
+ const { farmPlugin: farmPlugin2 } = await Promise.resolve().then(() => (init_vite2(), vite_exports));
33310
33568
  const { PluginManager: PluginManager2 } = await Promise.resolve().then(() => (init_plugin(), plugin_exports));
33311
33569
  const fs8 = await import("fs/promises");
33312
33570
  const pluginManager = new PluginManager2({
@@ -33547,6 +33805,7 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
33547
33805
  __FARM_PUBLIC_ENV__: JSON.stringify(config.env?.public || {})
33548
33806
  },
33549
33807
  plugins: [
33808
+ createFarmThemeCssPlugin(config.theme, config.basePath),
33550
33809
  ...tailwindVitePlugin ? [tailwindVitePlugin] : [],
33551
33810
  ...!useExternalMetadataImageRuntime && metadataImageRoutes.some((image) => image.sourceType === "module") ? [createMetadataImageWasmPlugin()] : [],
33552
33811
  {
@@ -33760,15 +34019,19 @@ function generateVirtualEntryCode(apiRoutes, pageRoutes, layoutRoutes, routeSlot
33760
34019
  _runWithCurrentRequest,
33761
34020
  _runWithMiddlewareContext,
33762
34021
  _runWithMiddlewareData,
34022
+ _setDefaultFarmThemeConfig,
33763
34023
  addMetadataImageReference,
34024
+ applyFarmThemeDocument,
33764
34025
  appendFarmLinkHeader,
33765
34026
  applyProductionMiddlewareHeaders,
33766
34027
  configureFarmCache,
33767
34028
  configureFarmObservability,
33768
34029
  createFarmCacheKey,
34030
+ createFarmThemeDocumentParts,
33769
34031
  createFarmLocaleCookie,
33770
34032
  createFarmProductionLifecycle,
33771
34033
  createProductionMiddlewareRunner,
34034
+ getTheme as getFarmTheme,
33772
34035
  emitFarmEvent,
33773
34036
  getFarmDataCache,
33774
34037
  getFarmLocaleVaryHeaders,
@@ -33963,6 +34226,8 @@ configureFarmObservability(farmObservabilityConfig);
33963
34226
  configureFarmCache(farmResolvedRuntimeConfig.cache);
33964
34227
  const farmI18nConfig = ${JSON.stringify(config.i18n)};
33965
34228
  const farmServerConfig = ${JSON.stringify(config.server)};
34229
+ const farmThemeConfig = ${JSON.stringify(config.theme)};
34230
+ _setDefaultFarmThemeConfig(farmThemeConfig);
33966
34231
  export const farmProductionLifecycle = createFarmProductionLifecycle({
33967
34232
  server: farmServerConfig,
33968
34233
  start: () => farmPluginRuntime?.startRuntime(),
@@ -35799,7 +36064,13 @@ async function handleFarmRequestInContext(
35799
36064
  !farmI18nSnapshot &&
35800
36065
  !pprCacheKey
35801
36066
  ) {
36067
+ const farmThemeDocument = createFarmThemeDocumentParts(
36068
+ farmThemeConfig,
36069
+ farmResolvedRuntimeConfig.basePath,
36070
+ getFarmTheme(request)
36071
+ );
35802
36072
  const streamPrefix = '<!DOCTYPE html>\\n<html lang="en">\\n<head>\\n' +
36073
+ farmThemeDocument.head + '\\n' +
35803
36074
  ' <meta charset="utf-8">\\n' +
35804
36075
  ' <meta name="viewport" content="width=device-width, initial-scale=1">\\n' +
35805
36076
  (hasFavicon ? '' : ' <link rel="icon" href="data:,">\\n') +
@@ -35815,9 +36086,13 @@ async function handleFarmRequestInContext(
35815
36086
  ) + '\\n' +
35816
36087
  ' <script type="module" src="/farm-client.js"></script>\\n' +
35817
36088
  '</body>\\n</html>';
36089
+ const themedStreamPrefix = streamPrefix.replace(
36090
+ '<html lang="en">',
36091
+ '<html lang="en"' + farmThemeDocument.attributes + '>'
36092
+ );
35818
36093
  const streamedDocument = createFarmDocumentStream(
35819
36094
  renderedPage.stream,
35820
- streamPrefix,
36095
+ themedStreamPrefix,
35821
36096
  streamSuffix,
35822
36097
  function() {
35823
36098
  if (pprBypassReason === "refresh") {
@@ -35900,6 +36175,12 @@ async function handleFarmRequestInContext(
35900
36175
  </html>\`;
35901
36176
  }
35902
36177
  fullHtml = applyFarmI18nDocument(fullHtml, pathname, farmI18nSnapshot);
36178
+ fullHtml = applyFarmThemeDocument(
36179
+ fullHtml,
36180
+ farmThemeConfig,
36181
+ farmResolvedRuntimeConfig.basePath,
36182
+ getFarmTheme(request)
36183
+ );
35903
36184
 
35904
36185
  if (pageStatus === 200 && pprCacheKey && request.method.toUpperCase() !== "HEAD") {
35905
36186
  await pprShellCache.setAsync(
@@ -36026,10 +36307,15 @@ async function handleFarmRequestInContext(
36026
36307
  const errorHtml = ${hasMiddlewareRuntime ? `await _runWithMiddlewareData(middlewareData, () =>
36027
36308
  _runWithMiddlewareContext(middlewareContext, renderErrorElement)
36028
36309
  )` : "await renderErrorElement()"};
36029
- const errorDocument = applyFarmI18nDocument(
36030
- createFarmErrorDocument(errorHtml, "Application Error"),
36031
- pathname,
36032
- getFarmI18nSnapshot()
36310
+ const errorDocument = applyFarmThemeDocument(
36311
+ applyFarmI18nDocument(
36312
+ createFarmErrorDocument(errorHtml, "Application Error"),
36313
+ pathname,
36314
+ getFarmI18nSnapshot()
36315
+ ),
36316
+ farmThemeConfig,
36317
+ farmResolvedRuntimeConfig.basePath,
36318
+ getFarmTheme(request)
36033
36319
  );
36034
36320
  emitFarmEvent({
36035
36321
  type: "render.complete",
@@ -36054,10 +36340,15 @@ async function handleFarmRequestInContext(
36054
36340
  const errorMessage = "Internal Server Error";
36055
36341
  const fallbackHtml = '<main><h1>Application Error</h1><p>' +
36056
36342
  escapeFarmHtmlAttribute(errorMessage) + '</p></main>';
36057
- const fallbackDocument = applyFarmI18nDocument(
36058
- createFarmErrorDocument(fallbackHtml, "Application Error"),
36059
- pathname,
36060
- getFarmI18nSnapshot()
36343
+ const fallbackDocument = applyFarmThemeDocument(
36344
+ applyFarmI18nDocument(
36345
+ createFarmErrorDocument(fallbackHtml, "Application Error"),
36346
+ pathname,
36347
+ getFarmI18nSnapshot()
36348
+ ),
36349
+ farmThemeConfig,
36350
+ farmResolvedRuntimeConfig.basePath,
36351
+ getFarmTheme(request)
36061
36352
  );
36062
36353
  return applyProductionMiddlewareHeaders(new Response(
36063
36354
  fallbackDocument,
@@ -36155,6 +36446,12 @@ async function handleFarmRequestInContext(
36155
36446
  </html>\`;
36156
36447
  }
36157
36448
  fullHtml = applyFarmI18nDocument(fullHtml, pathname, getFarmI18nSnapshot());
36449
+ fullHtml = applyFarmThemeDocument(
36450
+ fullHtml,
36451
+ farmThemeConfig,
36452
+ farmResolvedRuntimeConfig.basePath,
36453
+ getFarmTheme(request)
36454
+ );
36158
36455
 
36159
36456
  emitFarmEvent({
36160
36457
  type: "render.complete",
@@ -36173,8 +36470,14 @@ async function handleFarmRequestInContext(
36173
36470
  }), middlewareHeaders);
36174
36471
  } catch (error) {
36175
36472
  console.error("404 render error:", error);
36176
- return applyProductionMiddlewareHeaders(new Response(
36473
+ const fallbackDocument = applyFarmThemeDocument(
36177
36474
  \`<!DOCTYPE html><html><head><title>404</title></head><body><h1>404 - Page Not Found</h1><p>The page \${pathname} doesn't exist.</p><a href="/">Go Home</a></body></html>\`,
36475
+ farmThemeConfig,
36476
+ farmResolvedRuntimeConfig.basePath,
36477
+ getFarmTheme(request)
36478
+ );
36479
+ return applyProductionMiddlewareHeaders(new Response(
36480
+ fallbackDocument,
36178
36481
  {
36179
36482
  status: 404,
36180
36483
  headers: { "Content-Type": "text/html", "x-farm-preload-buffered": "1" },
@@ -37401,7 +37704,7 @@ async function createProjectModuleServer(createViteServer, config, root) {
37401
37704
  }
37402
37705
  __name(createProjectModuleServer, "createProjectModuleServer");
37403
37706
  async function buildClient2(viteBuild, config, root, srcDir, outputDir) {
37404
- const { farmI18nClientBridgePlugin: farmI18nClientBridgePlugin2, farmPlugin: farmPlugin2 } = await Promise.resolve().then(() => (init_vite(), vite_exports));
37707
+ const { farmI18nClientBridgePlugin: farmI18nClientBridgePlugin2, farmPlugin: farmPlugin2 } = await Promise.resolve().then(() => (init_vite2(), vite_exports));
37405
37708
  const { PluginManager: PluginManager2 } = await Promise.resolve().then(() => (init_plugin(), plugin_exports));
37406
37709
  const pluginManager = new PluginManager2({
37407
37710
  config,
@@ -37428,7 +37731,7 @@ async function buildClient2(viteBuild, config, root, srcDir, outputDir) {
37428
37731
  }
37429
37732
  __name(buildClient2, "buildClient");
37430
37733
  async function buildSSR(viteBuild, config, root, srcDir, outputDir) {
37431
- const { farmI18nClientBridgePlugin: farmI18nClientBridgePlugin2, farmPlugin: farmPlugin2 } = await Promise.resolve().then(() => (init_vite(), vite_exports));
37734
+ const { farmI18nClientBridgePlugin: farmI18nClientBridgePlugin2, farmPlugin: farmPlugin2 } = await Promise.resolve().then(() => (init_vite2(), vite_exports));
37432
37735
  const { PluginManager: PluginManager2 } = await Promise.resolve().then(() => (init_plugin(), plugin_exports));
37433
37736
  const pluginManager = new PluginManager2({
37434
37737
  config,
@@ -37553,7 +37856,7 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
37553
37856
  __name(buildNitro, "buildNitro");
37554
37857
 
37555
37858
  // src/nitro/build-runtime.ts
37556
- init_config2();
37859
+ init_config3();
37557
37860
  init_utils();
37558
37861
  // Annotate the CommonJS export names for ESM import in node:
37559
37862
  0 && (module.exports = {