Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat(theme): Halloween turns itself on for October 31, and nobody picks it
naveenkash8a053df24154
diff --git a/.ai/lessons.md b/.ai/lessons.mdindex c47638a660..bc5ff1559d 100644--- a/.ai/lessons.md+++ b/.ai/lessons.md@@ -4056,6 +4056,6 @@ The write was then removed (nothing reads it), so the rail always starts collaps**Problem:** Undoing it meant rewriting three deleted cookie reads from memory, and nothing pointed at them: deleting `halloween-theme.ts` would just break the imports. The mesh colors in `MeshGradientBackground.tsx` (a `Record<string, …>`, so no compile error) and a test that imported the theme directly had the same shape. The removal checklist went stale twice as pieces were added.-**Rule:** Put a seasonal or temporary behaviour on the removable unit itself (`forced`, `mesh` on the `SeasonalTheme`, read by the shared resolver) and keep callers generic, so deleting the unit turns the behaviour off. Test the mechanism on a fixture, not on the instance. Keep ONE removal checklist, next to the code, and make every other comment point to it.+**Rule:** Put a seasonal or temporary behaviour on the removable unit itself (its `available` window and `mesh` on the `SeasonalTheme`, read by the shared resolver) and keep callers generic, so deleting the unit turns the behaviour off. Test the mechanism on a fixture, not on the instance. Keep ONE removal checklist, next to the code, and make every other comment point to it.**Applies to:** `packages/utils/src/themes.ts` seasonal themes, `packages/react/src/Halloween/`, any feature flag, promo or seasonal UI.diff --git a/.claude/rules/coding-conventions.md b/.claude/rules/coding-conventions.mdindex 085c6f47b0..93decf92bb 100644--- a/.claude/rules/coding-conventions.md+++ b/.claude/rules/coding-conventions.md@@ -226,23 +226,20 @@ variables (`--primary`, `--background`, `--foreground`, `--card`, `--popover`,The choice is a `theme` cookie per browser, never a database column. Each app's`getTheme` (`services/theme.server.ts`) resolves through `resolveTheme`, whichreturns the default for a name no longer in `themes`, so removing a theme-needs no migration and breaks no browser that still holds it. A seasonal-theme marked `forced` wins over any stored name while in season, so every-browser renders it; the pickers still write the cookie, and it takes effect-again once the season ends.--A seasonal theme lives in `seasonalThemes`, not `themes`, and carries an-`available` window (`ThemeWindow`, month and day, inside one calendar year).-The server has no time zone for the user, so the window is open while it is in-season anywhere on Earth (UTC+14 reaches `from`, UTC-12 has not left `to`); a-fixed UTC check opened it hours late east of UTC. `themes` stays the everyday-list every picker shows (avatar menu, mobile profile, onboarding); only-Account settings → Appearance lists `selectableThemes()`, the everyday themes-plus any seasonal one in its window. Outside the window `themeColorValidator`-refuses it and `resolveTheme` (which every app's `Document` renders from)-falls back to the default. A seasonal theme lives in its own file+needs no migration and breaks no browser that still holds it.++A seasonal theme (`seasonalThemes`, never in `themes`) is not a choice: while+it is in season it replaces every theme for everyone, and when the season+ends everyone is back on their own cookie. No picker lists it and+`themeColorValidator` refuses it. Its season is the `available` window on the+theme (`ThemeWindow`, month and day inside one calendar year; Halloween is+October 31 only), and that window is the only switch: no flag, no deploy on+the day. The server has no time zone for the user, so `isInSeason` is true+while it is the season anywhere on Earth (UTC+14 reaches `from`, UTC-12 has+not left `to`); a fixed UTC check turned it on hours late east of UTC. To+preview one locally, widen its window. A seasonal theme lives in its own file(`halloween-theme.ts`) and declares everything about itself on the-`SeasonalTheme` object (`forced`, its `mesh` colors, read through+`SeasonalTheme` object (its window, its `mesh` colors read through`seasonalMeshColors`), so no other code names it: removing it is that file,its `seasonalThemes` entry and its `index.ts` export. `themes.test.ts` teststhe window on a fixture and loops over `seasonalThemes`, so it survives thediff --git a/apps/erp/app/services/theme.server.ts b/apps/erp/app/services/theme.server.tsindex a4264e7a37..e3e437bfca 100644--- a/apps/erp/app/services/theme.server.ts+++ b/apps/erp/app/services/theme.server.ts@@ -10,8 +10,8 @@ import * as cookie from "cookie";const cookieName = "theme";/**- * The theme to render: the cookie's, unless a seasonal theme is forced, or- * the default when it names none we offer now (`resolveTheme`).+ * The theme to render: a seasonal theme while in season, for everyone;+ * otherwise the cookie's, or the default (`resolveTheme`).*/export function getTheme(request: Request): ThemeName {const cookieHeader = request.headers.get("cookie");diff --git a/apps/mes/app/services/theme.server.ts b/apps/mes/app/services/theme.server.tsindex 93840d7ad8..a138f5df19 100644--- a/apps/mes/app/services/theme.server.ts+++ b/apps/mes/app/services/theme.server.ts@@ -10,8 +10,8 @@ import * as cookie from "cookie";const cookieName = "theme";/**- * The theme to render: the cookie's, unless a seasonal theme is forced, or- * the default when it names none we offer now (`resolveTheme`).+ * The theme to render: a seasonal theme while in season, for everyone;+ * otherwise the cookie's, or the default (`resolveTheme`).*/export function getTheme(request: Request): ThemeName {const cookieHeader = request.headers.get("cookie");diff --git a/apps/starter/app/services/theme.server.ts b/apps/starter/app/services/theme.server.tsindex a78da01919..21d97cc8fa 100644--- a/apps/starter/app/services/theme.server.ts+++ b/apps/starter/app/services/theme.server.ts@@ -9,8 +9,8 @@ import * as cookie from "cookie";const cookieName = "theme";/**- * The theme to render: the cookie's, unless a seasonal theme is forced, or- * the default when it names none we offer now (`resolveTheme`).+ * The theme to render: a seasonal theme while in season, for everyone;+ * otherwise the cookie's, or the default (`resolveTheme`).*/export function getTheme(request: Request): ThemeName {const cookieHeader = request.headers.get("cookie");diff --git a/packages/account/AGENTS.md b/packages/account/AGENTS.mdindex 01445f4770..e83cb6de1d 100644--- a/packages/account/AGENTS.md+++ b/packages/account/AGENTS.md@@ -28,8 +28,8 @@ and the starter. Each app mounts it once in its shell; it opens over any page.root action (`/`), which every app's `root.tsx` handles (`modeValidator` /`themeColorValidator` from `@carbon/utils`). `useOptimisticMode` only counts a `/`submission carrying `mode`, so the two never read each other's in-flight value.- The theme grid lists `selectableThemes()`: the everyday themes plus any seasonal one in its- window. While a `forced` seasonal theme is in season it renders whatever is picked here.+ The theme grid lists the everyday `themes`. A seasonal theme is never offered; while one is+ in season it renders for everyone, whatever is picked here.- Panes read with `useLoaderQuery` (`@carbon/query`), so the host app needs a`QueryClientProvider`, `window.clientCache` and `createInvalidationMiddleware` in its root.Strings use Lingui macros, so it also needs a `LocaleProvider`; the package is in the erpdiff --git a/packages/account/src/ui/AppearanceSettings.tsx b/packages/account/src/ui/AppearanceSettings.tsxindex 9413834a81..307bf29cdd 100644--- a/packages/account/src/ui/AppearanceSettings.tsx+++ b/packages/account/src/ui/AppearanceSettings.tsx@@ -11,11 +11,7 @@ import {useModePreference,useRouteData} from "@carbon/react";-import {- modeValidator,- selectableThemes,- themeColorValidator-} from "@carbon/utils";+import { modeValidator, themeColorValidator, themes } from "@carbon/utils";import { Trans, useLingui } from "@lingui/react/macro";import type { CSSProperties } from "react";import { useEffect, useRef } from "react";@@ -104,9 +100,7 @@ export default function AppearanceSettings() {};const onThemeChange = (value: string) => {- const next = selectableThemes().find(- (candidate) => candidate.name === value- );+ const next = themes.find((candidate) => candidate.name === value);if (!next || next.name === theme) return;// Preview at once, until the root loader applies it from the cookie.const variables = mode === "dark" ? next.cssVars.dark : next.cssVars.light;@@ -173,7 +167,7 @@ export default function AppearanceSettings() {aria-label={t`Theme color`}className="grid grid-cols-2 gap-2 sm:grid-cols-4">- {selectableThemes().map((option) => {+ {themes.map((option) => {const active = option.name === theme;const swatch = option.activeColor[mode];return (diff --git a/packages/react/src/Halloween/HalloweenLayer.tsx b/packages/react/src/Halloween/HalloweenLayer.tsxindex 0429f74fa9..2854b5bcef 100644--- a/packages/react/src/Halloween/HalloweenLayer.tsx+++ b/packages/react/src/Halloween/HalloweenLayer.tsx@@ -19,8 +19,9 @@ import { useHalloween } from "./season";import { BatFlyby, SuccessBats } from "./Visitors";// Seasonal decoration, shared by the ERP and the MES (`@carbon/react/Halloween`).-// Everything renders only while the Halloween theme is on (`useHalloween`,-// season.ts); for everyone else this returns nothing.+// Everything renders only on Halloween, when the theme is on for everyone+// (`useHalloween`, season.ts); on any other day this returns nothing. The+// day is `available` in packages/utils/src/halloween-theme.ts.//// To remove Halloween, the theme and every decoration:// 1. Delete this folder and the `./Halloween` export in@@ -31,7 +32,7 @@ import { BatFlyby, SuccessBats } from "./Visitors";// 3. Delete packages/utils/src/halloween-theme.ts, its export in// packages/utils/src/index.ts and its entry in `seasonalThemes`// (packages/utils/src/themes.ts). The theme carries everything else-// (forced for everyone, its mesh colors), so nothing reads it by name.+// (its day, its mesh colors), so nothing reads it by name.// 4. Run `pnpm run lingui:extract` to drop its strings from the catalogs.// Typecheck flags any mount or import left behind. The `data-user-menu`,// `data-date` and `data-app-card` attributes the styles hang off, anddiff --git a/packages/react/src/Halloween/season.ts b/packages/react/src/Halloween/season.tsindex e25c4e7ec1..885cba1513 100644--- a/packages/react/src/Halloween/season.ts+++ b/packages/react/src/Halloween/season.ts@@ -4,14 +4,14 @@import { halloweenTheme } from "@carbon/utils";import { useSyncExternalStore } from "react";-import { useFetchers } from "react-router";import { useRouteData } from "../hooks/useRouteData";-// The one check every Halloween decoration sits behind: the root loader's-// theme is Halloween. While it is in season the theme is forced for everyone-// (`forced` on `halloweenTheme`); out of season the server renders the-// stored or default theme instead (`resolveTheme`), so everything switches-// itself off on time and nothing is rendered, styled or listened to.+// The one check every Halloween decoration sits behind, the sign-in page's+// Night Shift included: the root loader's theme is Halloween. That is the+// case for everyone on Halloween (`available` on `halloweenTheme`, applied by+// `resolveTheme`) and for no one on any other day, so everything switches on+// and off by itself, and the rest of the year nothing is rendered, styled or+// listened to.// Hydration never reverses, so there is nothing to listen to.function subscribe() {@@ -26,15 +26,10 @@ function subscribe() {*/export function useHalloween() {const root = useRouteData<{ theme?: string }>("/");- // A theme being saved from the Appearance pane counts at once.- const pending = useFetchers()- .find((fetcher) => fetcher.formData?.has("theme"))- ?.formData?.get("theme");- const theme = typeof pending === "string" ? pending : root?.theme;const hydrated = useSyncExternalStore(subscribe,() => true,() => false);- return hydrated && theme === halloweenTheme.name;+ return hydrated && root?.theme === halloweenTheme.name;}diff --git a/packages/utils/AGENTS.md b/packages/utils/AGENTS.mdindex 783af810f1..a4d1ecab7f 100644--- a/packages/utils/AGENTS.md+++ b/packages/utils/AGENTS.md@@ -64,7 +64,7 @@ pnpm --filter @carbon/utils typecheck| `planning-sizing` | `computePlanningOrders` — reorder-quantity sizing for the four reordering policies (`ComputePlanningOrdersInput` — `{ reorderingPolicy, periods, projections, todayDate, params: PlanningSizingParams }` — in, `PlanningOrderSuggestion[]` out). Pure and clock-free (`todayDate` is injected). Also `orderSizingRules(policyName, params)` — how ONE order of a policy is sized (per-order quantity, daily vs spread, maximum, minimum, multiples) — shared by MRP's change actions and the planning pages: `splitIntoOrders` (a week's summed action back into its orders; `lotSizeBatches` is the batch case) and `reducedOrderQuantity` (a Decrease's floor and multiples). Shared by the MRP engine and the item planning tab's `ItemReorderPolicy`, so both size an order the same way; `planning-sizing.test.ts` pins it against hand-computed results of the SQL `calculate_quantity_to_order` || `precision` | The whole numeric-precision API (re-exported from `@carbon/database/precision`): `SCALE`, `EPSILON`, `RoundingMode`, `round`, `distributeRoundingResidual`, `scrapAllowance`, `applyRate`, `deriveRate`, `isBalanced`, `assertBalanced` || `format` | The ONLY place display/input digit counts are chosen: `moneyFormatOptions` (settlement — the currency's decimals are floor AND ceiling), `rateFormatOptions` (per-unit RATE — those decimals are only the floor, ceiling is `SCALE`), the `PERCENT_FORMAT` / `PERCENT_POINTS_FORMAT` / `SCALE_FORMAT` constants, `cldrCurrencyDecimals`, their `format*` helpers, and `INPUT_FORMAT` / `INPUT_STEP` for editable fields. Call sites pick a KIND, never a digit count |-| `themes` | The everyday `themes` (every picker lists them) and `seasonalThemes` (each in its own file, e.g. `halloween-theme.ts`, typed `SeasonalTheme`: an `available` window, optionally `forced` for everyone in season and its own `mesh` colors). `resolveTheme` (what to render for a stored name, falling back to `DEFAULT_THEME_NAME`), `selectableThemes` (the Appearance pane), `isThemeAvailable`, `seasonalMeshColors`. A seasonal theme declares everything about itself, so removing it touches no caller |+| `themes` | The everyday `themes` (every picker lists them, and only them) and `seasonalThemes` (each in its own file, e.g. `halloween-theme.ts`, typed `SeasonalTheme`: an `available` window and optionally its own `mesh` colors). In season a seasonal theme replaces every theme for everyone; no one can pick it. `resolveTheme` (what to render for a stored name, falling back to `DEFAULT_THEME_NAME`), `isInSeason`, `seasonalMeshColors`. A seasonal theme declares everything about itself, so removing it touches no caller || `string` | Slugify, truncate, camelCase/titleCase conversions || `items` | Item lookups and `getReadableIdWithRevision` (`readableId.revision`) || `revalidate` | `shouldRevalidate` predicates: `isSearchParamOnlyNavigation` (the root loader only; layouts do not skip their loaders, see `coding-conventions.md` → Routes) |diff --git a/packages/utils/src/halloween-theme.ts b/packages/utils/src/halloween-theme.tsindex 9f06bcd0ec..a5477625c6 100644--- a/packages/utils/src/halloween-theme.ts+++ b/packages/utils/src/halloween-theme.ts@@ -4,19 +4,19 @@import type { SeasonalTheme } from "./themes";-// Seasonal theme, forced for everyone while in season. It goes together with-// its decorations: the removal checklist is at the top of-// packages/react/src/Halloween/HalloweenLayer.tsx. A browser still holding-// its cookie falls back to the default theme, as it does out of season.+// Seasonal theme: on October 31 it replaces every theme, for everyone, and+// the sign-in page's Night Shift and the app decorations come with it+// (packages/react/src/Halloween/). Nobody can pick it. To change the day or+// widen it to a few, edit `available`; nothing else is needed. The removal+// checklist is at the top of packages/react/src/Halloween/HalloweenLayer.tsx.export const halloweenTheme = {name: "halloween",label: "Halloween",available: {- from: { month: 10, day: 20 },- to: { month: 11, day: 1 }+ from: { month: 10, day: 31 },+ to: { month: 10, day: 31 }},- forced: true,mesh: {light: ["#fdf0e4", "#f6f0fa", "#fffaf5", "#fbefe6"],dark: ["#2d1205", "#14081f", "#0D0D0D", "#050505"]diff --git a/packages/utils/src/themes.test.ts b/packages/utils/src/themes.test.tsindex a1ce5dcfec..d50ac586a9 100644--- a/packages/utils/src/themes.test.ts+++ b/packages/utils/src/themes.test.ts@@ -2,89 +2,80 @@// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,// including ports, remain AGPLv3; serving them over a network requires releasing their source.-// The season window is tested on a fixture, and the registry on whatever-// seasonal themes exist, so removing one (Halloween) leaves this file as is.+// The season is tested on a fixture, and the registry on whatever seasonal+// themes exist, so removing one (Halloween) leaves this file as it is.import { CalendarDate } from "@internationalized/date";import { afterEach, describe, expect, it, vi } from "vitest";import {DEFAULT_THEME_NAME,- isThemeAvailable,+ isInSeason,resolveTheme,type SeasonalTheme,seasonalMeshColors,seasonalThemes,- selectableThemes,type ThemeWindow,themes} from "./themes";+import { themeColorValidator } from "./types";// Typed by what a seasonal theme may declare, so it compiles when empty.const seasonal: readonly SeasonalTheme[] = seasonalThemes;-const spooky: { name: string; available: ThemeWindow } = {- name: "spooky",+const spooky: { available: ThemeWindow } = {available: { from: { month: 10, day: 20 }, to: { month: 11, day: 1 } }};-describe("isThemeAvailable", () => {- it("always offers a theme with no window", () => {- expect(isThemeAvailable(themes[0], new CalendarDate(2026, 3, 15))).toBe(- true- );- });-- it("offers a seasonal theme inside its window, both ends included", () => {- expect(isThemeAvailable(spooky, new CalendarDate(2026, 10, 20))).toBe(true);- expect(isThemeAvailable(spooky, new CalendarDate(2026, 10, 31))).toBe(true);- expect(isThemeAvailable(spooky, new CalendarDate(2026, 11, 1))).toBe(true);+describe("isInSeason", () => {+ it("is on inside the window, both ends included", () => {+ expect(isInSeason(spooky, new CalendarDate(2026, 10, 20))).toBe(true);+ expect(isInSeason(spooky, new CalendarDate(2026, 10, 31))).toBe(true);+ expect(isInSeason(spooky, new CalendarDate(2026, 11, 1))).toBe(true);});- it("withholds a seasonal theme outside its window", () => {- expect(isThemeAvailable(spooky, new CalendarDate(2026, 10, 19))).toBe(- false- );- expect(isThemeAvailable(spooky, new CalendarDate(2026, 11, 2))).toBe(false);+ it("is off outside it", () => {+ expect(isInSeason(spooky, new CalendarDate(2026, 10, 19))).toBe(false);+ expect(isInSeason(spooky, new CalendarDate(2026, 11, 2))).toBe(false);});});-describe("isThemeAvailable with no date", () => {+describe("isInSeason with no date", () => {afterEach(() => {vi.useRealTimers();});- const availableAt = (instant: string) => {+ const onAt = (instant: string) => {vi.useFakeTimers();vi.setSystemTime(instant);- return isThemeAvailable(spooky);+ return isInSeason(spooky);};- it("opens once the first time zone reaches the first day", () => {+ it("turns on once the first time zone reaches the first day", () => {// Oct 19 in UTC, Oct 20 in India and on Kiritimati (UTC+14).- expect(availableAt("2026-10-19T23:03:00Z")).toBe(true);+ expect(onAt("2026-10-19T23:03:00Z")).toBe(true);// Still Oct 19 everywhere, Kiritimati included.- expect(availableAt("2026-10-19T09:00:00Z")).toBe(false);+ expect(onAt("2026-10-19T09:00:00Z")).toBe(false);});- it("closes once the last time zone leaves the last day", () => {+ it("turns off once the last time zone leaves the last day", () => {// Nov 2 in UTC, still Nov 1 at UTC-12.- expect(availableAt("2026-11-02T11:00:00Z")).toBe(true);+ expect(onAt("2026-11-02T11:00:00Z")).toBe(true);// Nov 2 everywhere.- expect(availableAt("2026-11-02T13:00:00Z")).toBe(false);+ expect(onAt("2026-11-02T13:00:00Z")).toBe(false);});});-// A day no seasonal theme is in season.+// A day no seasonal theme is on.const ordinaryDay = new CalendarDate(2026, 3, 15);describe("resolveTheme on an ordinary day", () => {it("is a day with no theme in season", () => {for (const theme of seasonal) {- expect(isThemeAvailable(theme, ordinaryDay)).toBe(false);+ expect(isInSeason(theme, ordinaryDay)).toBe(false);}});- it("returns the stored theme when it is offered", () => {+ it("returns the stored theme", () => {expect(resolveTheme("violet", ordinaryDay).name).toBe("violet");});@@ -95,41 +86,32 @@ describe("resolveTheme on an ordinary day", () => {expect(resolveTheme(undefined, ordinaryDay).name).toBe(DEFAULT_THEME_NAME);expect(resolveTheme(null, ordinaryDay).name).toBe(DEFAULT_THEME_NAME);});-- it("offers only the everyday themes", () => {- expect(selectableThemes(ordinaryDay)).toEqual([...themes]);- });});for (const theme of seasonal) {const { from, to } = theme.available;const firstDay = new CalendarDate(2026, from.month, from.day);- const dayAfter = new CalendarDate(2026, to.month, to.day).add({ days: 1 });+ const lastDay = new CalendarDate(2026, to.month, to.day);+ const dayAfter = lastDay.add({ days: 1 });describe(`seasonal theme "${theme.name}"`, () => {- it("is never one of the everyday themes", () => {+ it("is in no picker", () => {expect(themes.map((t) => t.name)).not.toContain(theme.name);- });-- it("is offered in season and withdrawn after it", () => {- expect(selectableThemes(firstDay).map((t) => t.name)).toContain(- theme.name- );- expect(selectableThemes(dayAfter).map((t) => t.name)).not.toContain(- theme.name+ expect(themeColorValidator.safeParse({ theme: theme.name }).success).toBe(+ false);});- it("renders in season, for everyone when forced", () => {- expect(resolveTheme(theme.name, firstDay).name).toBe(theme.name);- expect(resolveTheme("violet", firstDay).name).toBe(- theme.forced ? theme.name : "violet"- );+ it("replaces every theme for everyone while in season", () => {+ for (const day of [firstDay, lastDay]) {+ expect(resolveTheme("violet", day).name).toBe(theme.name);+ expect(resolveTheme(undefined, day).name).toBe(theme.name);+ }});- it("gives way after its season, to the stored theme or the default", () => {- expect(resolveTheme(theme.name, dayAfter).name).toBe(DEFAULT_THEME_NAME);+ it("hands everyone back their own theme after its season", () => {expect(resolveTheme("violet", dayAfter).name).toBe("violet");+ expect(resolveTheme(theme.name, dayAfter).name).toBe(DEFAULT_THEME_NAME);});it("brings its own mesh colors", () => {diff --git a/packages/utils/src/themes.ts b/packages/utils/src/themes.tsindex 169501ee88..e82a6ea95e 100644--- a/packages/utils/src/themes.ts+++ b/packages/utils/src/themes.ts@@ -7,7 +7,7 @@ import { today } from "@internationalized/date";import template from "lodash.template";import { halloweenTheme } from "./halloween-theme";-/** The everyday themes: what every theme picker offers. */+/** The everyday themes: what every theme picker offers, and all it offers. */export const themes = [{name: "zinc",@@ -497,8 +497,8 @@ export const themes = [type MonthDay = { month: number; day: number };/**- * The days of the year a seasonal theme can be picked, both ends included,- * within one calendar year (`from` before `to`).+ * The days of the year a seasonal theme is on, both ends included, within+ * one calendar year (`from` on or before `to`).*/export type ThemeWindow = { from: MonthDay; to: MonthDay };@@ -509,26 +509,23 @@ export type MeshColors = {};/**- * What a seasonal theme declares. Everything about it lives on the theme, so- * removing one is deleting its file and its `seasonalThemes` entry.+ * A theme that takes over for a few days a year: while in season every+ * browser renders it, whatever theme was picked, and when the season ends+ * everyone is back on their own. No picker ever lists one. Everything about+ * it lives on the theme, so removing one is deleting its file and its+ * `seasonalThemes` entry.*/export type SeasonalTheme = {name: string;label: string;+ /** When it is on. The only switch: no flag, no deploy on the day. */available: ThemeWindow;- /** While in season, every browser renders it, whatever theme it picked. */- forced?: boolean;/** Its mesh-gradient colors (`seasonalMeshColors`). */mesh?: MeshColors;activeColor: { light: string; dark: string };cssVars: { light: Record<string, string>; dark: Record<string, string> };};-/**- * Themes offered only for a while each year, and only in Account settings →- * Appearance (`selectableThemes`). Every other picker lists `themes`, so it- * never shows one.- */export const seasonalThemes = [halloweenTheme] as const;// The same list, typed by what a seasonal theme may declare; still compiles@@ -556,22 +553,21 @@ const EARLIEST_TIME_ZONE = "Pacific/Kiritimati";const LATEST_TIME_ZONE = "Etc/GMT+12";/**- * Whether a theme can be used. A theme with no window always can.+ * Whether a seasonal theme is on.** Given a `date`, the window is checked against that day. Without one it is- * open while it is in season anywhere on Earth: the server has no time zone- * for the user, and checking one fixed zone (UTC) opened Halloween five and a- * half hours late in India. This way the server and the browser agree, and a- * user sees the theme at most a day before or after their own dates.+ * on while it is in season anywhere on Earth: the server has no time zone+ * for the user, and checking one fixed zone (UTC) turned Halloween on five+ * and a half hours late in India. So the server and the browser agree, and a+ * user sees it from at most a day before their own first day to at most a+ * day after their last.*/-export function isThemeAvailable(- theme: { name: string; available?: ThemeWindow },+export function isInSeason(+ theme: { available: ThemeWindow },date?: CalendarDate) {- const window = theme.available;- if (!window) return true;- const from = dayOfYear(window.from);- const to = dayOfYear(window.to);+ const from = dayOfYear(theme.available.from);+ const to = dayOfYear(theme.available.to);if (date) {const current = dayOfYear(date);return current >= from && current <= to;@@ -582,37 +578,25 @@ export function isThemeAvailable();}-/**- * The themes the Appearance pane offers now: the everyday ones and any- * seasonal one in its window.- */-export function selectableThemes(date?: CalendarDate): Theme[] {- return allThemes.filter((theme) => isThemeAvailable(theme, date));-}--/** The seasonal theme every browser renders now, if one is forced and in season. */-function forcedTheme(date?: CalendarDate): Theme | undefined {- const forced = seasonal.find(- (theme) => theme.forced && isThemeAvailable(theme, date)- );- return forced && allThemes.find((theme) => theme.name === forced.name);+/** The seasonal theme on now, if any. */+function seasonalThemeNow(date?: CalendarDate): Theme | undefined {+ const now = seasonal.find((theme) => isInSeason(theme, date));+ return now && allThemes.find((theme) => theme.name === now.name);}/**- * The theme to render for a stored name. A forced seasonal theme in season- * wins over any stored name. An unknown name (a theme since removed) or a- * seasonal theme out of season falls back to the default, so removing a+ * The theme to render for a stored name: a seasonal theme in season, for+ * everyone; otherwise the stored everyday theme. An unknown name (a theme+ * since removed, or a seasonal one) falls back to the default, so removing a* theme never breaks a browser that still holds its cookie.*/export function resolveTheme(name: string | null | undefined,date?: CalendarDate): Theme {- const forced = forcedTheme(date);- if (forced) return forced;- const theme = allThemes.find((candidate) => candidate.name === name);- if (theme && isThemeAvailable(theme, date)) return theme;- return defaultTheme;+ const season = seasonalThemeNow(date);+ if (season) return season;+ return themes.find((candidate) => candidate.name === name) ?? defaultTheme;}/** A seasonal theme's mesh-gradient colors, if it declares them. */diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.tsindex cbbc0cc7bb..8dd6fe6781 100644--- a/packages/utils/src/types.ts+++ b/packages/utils/src/types.ts@@ -3,7 +3,7 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { z } from "zod";-import { selectableThemes } from "./themes";+import { themes } from "./themes";export enum Edition {Cloud = "cloud",@@ -21,16 +21,11 @@ export const modeValidator = z.object({mode: z.enum(["light", "dark", "system"])});-/**- * A theme color by name — one the user can pick now (`selectableThemes`).- * Stored per browser, like the mode.- */+/** A theme color by name — one of `themes`. Stored per browser, like the mode. */export const themeColorValidator = z.object({- theme: z- .string()- .refine((name) => selectableThemes().some((t) => t.name === name), {- message: "Invalid theme"- })+ theme: z.string().refine((name) => themes.some((t) => t.name === name), {+ message: "Invalid theme"+ })});export enum Plan {