@aglyn/shared-ui-theme 1.0.0-beta.247 → 1.0.0-beta.250

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/shared-ui-theme",
3
- "version": "1.0.0-beta.247",
3
+ "version": "1.0.0-beta.250",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,9 +25,9 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/shared-data-types": "1.0.0-beta.247",
29
- "@aglyn/shared-util-tools": "1.0.0-beta.247",
30
- "@aglyn/shared-util-vendor": "1.0.0-beta.247",
28
+ "@aglyn/shared-data-types": "1.0.0-beta.250",
29
+ "@aglyn/shared-util-tools": "1.0.0-beta.250",
30
+ "@aglyn/shared-util-vendor": "1.0.0-beta.250",
31
31
  "@emotion/cache": "^11.14.0",
32
32
  "@emotion/react": "11.14.0",
33
33
  "@swc/helpers": "0.5.23",
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import type { HostTheme, HostThemeFont, HostThemeScheme } from '@aglyn/shared-data-types';
18
- import type { ThemeOptions } from '../../vendor/mui';
18
+ import { type PaletteOptions, type ThemeOptions } from '../../vendor/mui';
19
19
  /**
20
20
  * Components a host theme may override. Persisted overrides are plain JSON;
21
21
  * anything outside this list is dropped by {@link sanitizeHostTheme} so a
@@ -63,6 +63,11 @@ export declare function sanitizeHostTheme(theme: HostTheme | undefined): HostThe
63
63
  * with at most one breakpoint rule per object.
64
64
  */
65
65
  export declare function orderMediaWidths<T>(value: T): T;
66
+ /**
67
+ * A tint is a wash of its accent, so it is derived from `main` the way MUI
68
+ * derives `light` and `dark`: with its own `lighten`/`darken`.
69
+ */
70
+ export declare function accentTint(main: string, mode: PaletteOptions['mode']): string;
66
71
  /**
67
72
  * Converts a persisted {@link HostTheme} document into MUI `ThemeOptions`
68
73
  * for one color scheme. The result is meant to be passed through
@@ -15,6 +15,7 @@
15
15
  * limitations under the License.
16
16
  */ import { _ as _extends } from "@swc/helpers/_/_extends";
17
17
  import { objectDeepMergeReplaceArrays } from "@aglyn/shared-util-vendor";
18
+ import { darken, lighten } from "../../vendor/mui.js";
18
19
  /**
19
20
  * Components a host theme may override. Persisted overrides are plain JSON;
20
21
  * anything outside this list is dropped by {@link sanitizeHostTheme} so a
@@ -353,6 +354,38 @@ function sanitizeComponents(components) {
353
354
  }
354
355
  return moved ? next : value;
355
356
  }
357
+ /**
358
+ * A tint is a wash of its accent, so it is derived from `main` the way MUI
359
+ * derives `light` and `dark`: with its own `lighten`/`darken`.
360
+ */ export function accentTint(main, mode) {
361
+ return mode === 'dark' ? darken(main, 0.7) : lighten(main, 0.9);
362
+ }
363
+ /**
364
+ * The tints a site renders: the base's, each replaced by the site's own where
365
+ * it sets one, or washed from the site's accent where it sets the accent
366
+ * without one, so a recolored brand never keeps the theme's old wash.
367
+ */ function mergeTints(base, overrides) {
368
+ if (!(overrides == null ? void 0 : overrides.tint) && !(overrides == null ? void 0 : overrides.primary) && !(overrides == null ? void 0 : overrides.secondary) && !(overrides == null ? void 0 : overrides.tertiary)) {
369
+ return undefined;
370
+ }
371
+ const tint = _extends({}, base == null ? void 0 : base.tint, overrides.tint);
372
+ for (const key of [
373
+ 'primary',
374
+ 'secondary',
375
+ 'tertiary'
376
+ ]){
377
+ var _overrides_key, _overrides_tint;
378
+ const main = (_overrides_key = overrides[key]) == null ? void 0 : _overrides_key.main;
379
+ if (((_overrides_tint = overrides.tint) == null ? void 0 : _overrides_tint[key]) || typeof main !== 'string') continue;
380
+ try {
381
+ var _overrides_mode;
382
+ tint[key] = accentTint(main, (_overrides_mode = overrides.mode) != null ? _overrides_mode : base == null ? void 0 : base.mode);
383
+ } catch (unused) {
384
+ // Not a color MUI can parse (a CSS variable): keep the inherited tint.
385
+ }
386
+ }
387
+ return tint;
388
+ }
356
389
  /**
357
390
  * Converts a persisted {@link HostTheme} document into MUI `ThemeOptions`
358
391
  * for one color scheme. The result is meant to be passed through
@@ -425,6 +458,8 @@ function sanitizeComponents(components) {
425
458
  // the partial-palette behaviour the converter is written for. Overriding
426
459
  // `primary` still must not disturb `secondary`, hence the level.
427
460
  merged.palette = _extends({}, base.palette, overrides.palette);
461
+ const tint = mergeTints(base.palette, overrides.palette);
462
+ if (tint) merged.palette.tint = tint;
428
463
  merged.shape = _extends({}, base.shape, overrides.shape);
429
464
  // Same reasoning as `palette`: setting `toolbar` must not drop any other
430
465
  // mixin the base defines.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/shared/ui/theme/src/lib/util/host-theme.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n HostTheme,\n HostThemeComponentOverride,\n HostThemeComponentVariant,\n HostThemeFont,\n HostThemePaletteColor,\n HostThemeScheme,\n HostThemeSchemeColors,\n} from '@aglyn/shared-data-types'\nimport { objectDeepMergeReplaceArrays } from '@aglyn/shared-util-vendor'\nimport type { PaletteOptions, ThemeOptions } from '../../vendor/mui'\n\n/**\n * Components a host theme may override. Persisted overrides are plain JSON;\n * anything outside this list is dropped by {@link sanitizeHostTheme} so a\n * tampered document can't restyle console-internal or portal-critical\n * components.\n *\n * The list is what a site actually renders — its elements, the forms, booking\n * and commerce surfaces, and the dialogs and menus they open — so a theme can\n * restyle a whole site rather than its buttons alone (AGL-3403). Layout\n * primitives (`MuiContainer`, `MuiGrid`, `MuiStack`, `MuiBox`) are absent on\n * purpose: they carry the page structure, and a theme that reflowed them\n * would break layouts the Besigner drew.\n */\nexport const HOST_THEME_COMPONENT_WHITELIST = [\n 'MuiAccordion',\n 'MuiAccordionDetails',\n 'MuiAccordionSummary',\n 'MuiAlert',\n 'MuiAlertTitle',\n 'MuiAppBar',\n 'MuiAvatar',\n 'MuiBadge',\n 'MuiBreadcrumbs',\n 'MuiButton',\n 'MuiButtonBase',\n 'MuiButtonGroup',\n 'MuiCard',\n 'MuiCardActions',\n 'MuiCardContent',\n 'MuiCardHeader',\n 'MuiCheckbox',\n 'MuiChip',\n 'MuiCircularProgress',\n 'MuiDialog',\n 'MuiDialogActions',\n 'MuiDialogContent',\n 'MuiDialogTitle',\n 'MuiDivider',\n 'MuiDrawer',\n 'MuiFab',\n 'MuiFilledInput',\n 'MuiFormControlLabel',\n 'MuiFormHelperText',\n 'MuiFormLabel',\n 'MuiIconButton',\n 'MuiInput',\n 'MuiInputBase',\n 'MuiInputLabel',\n 'MuiLinearProgress',\n 'MuiLink',\n 'MuiList',\n 'MuiListItem',\n 'MuiListItemButton',\n 'MuiMenu',\n 'MuiMenuItem',\n 'MuiOutlinedInput',\n 'MuiPagination',\n 'MuiPaginationItem',\n 'MuiPaper',\n 'MuiRadio',\n 'MuiRating',\n 'MuiSelect',\n 'MuiSlider',\n 'MuiSnackbarContent',\n 'MuiSwitch',\n 'MuiTab',\n 'MuiTable',\n 'MuiTableCell',\n 'MuiTableHead',\n 'MuiTableRow',\n 'MuiTabs',\n 'MuiTextField',\n 'MuiToggleButton',\n 'MuiToggleButtonGroup',\n 'MuiToolbar',\n 'MuiTooltip',\n 'MuiTypography',\n] as const\n\nexport type HostThemeComponentKey =\n (typeof HOST_THEME_COMPONENT_WHITELIST)[number]\n\nconst componentWhitelist: ReadonlySet<string> = new Set(\n HOST_THEME_COMPONENT_WHITELIST,\n)\n\nfunction pickPaletteColor(color: HostThemePaletteColor | undefined) {\n if (!color?.main) return undefined\n const picked: HostThemePaletteColor = { main: color.main }\n if (color.light) picked.light = color.light\n if (color.dark) picked.dark = color.dark\n if (color.contrastText) picked.contrastText = color.contrastText\n return picked\n}\n\nfunction schemeColorsToPaletteOptions(\n scheme: HostThemeScheme,\n colors: HostThemeSchemeColors | undefined,\n): PaletteOptions {\n const palette: PaletteOptions = { mode: scheme }\n if (!colors) return palette\n\n const colorKeys = [\n 'primary',\n 'secondary',\n 'tertiary',\n 'surface',\n 'error',\n 'warning',\n 'info',\n 'success',\n ] as const\n for (const key of colorKeys) {\n const color = pickPaletteColor(colors[key])\n if (color) (palette as Record<string, unknown>)[key] = color\n }\n\n if (colors.background?.default || colors.background?.paper) {\n palette.background = {\n ...(colors.background.default && { default: colors.background.default }),\n ...(colors.background.paper && { paper: colors.background.paper }),\n }\n }\n if (\n colors.text?.primary ||\n colors.text?.secondary ||\n colors.text?.disabled\n ) {\n palette.text = {\n ...(colors.text.primary && { primary: colors.text.primary }),\n ...(colors.text.secondary && { secondary: colors.text.secondary }),\n ...(colors.text.disabled && { disabled: colors.text.disabled }),\n }\n }\n // Tints are string leaves, not a PaletteColor, so they pass through the\n // same \"copy what was set\" path as `background`/`text` rather than\n // `pickPaletteColor` — which requires a `main` a tint does not have\n // (AGL-1244).\n if (colors.tint?.primary || colors.tint?.secondary || colors.tint?.tertiary) {\n palette.tint = {\n ...(colors.tint.primary && { primary: colors.tint.primary }),\n ...(colors.tint.secondary && { secondary: colors.tint.secondary }),\n ...(colors.tint.tertiary && { tertiary: colors.tint.tertiary }),\n }\n }\n if (colors.divider) palette.divider = colors.divider\n\n return palette\n}\n\nfunction sanitizeComponents(\n components: Record<string, HostThemeComponentOverride> | undefined,\n) {\n if (!components) return undefined\n const sanitized: Record<string, HostThemeComponentOverride> = {}\n for (const [key, override] of Object.entries(components)) {\n if (!componentWhitelist.has(key) || !override) continue\n const entry: HostThemeComponentOverride = {}\n if (override.defaultProps) entry.defaultProps = override.defaultProps\n if (override.styleOverrides) entry.styleOverrides = override.styleOverrides\n const sx = sanitizeSlotStyles(override.sx)\n if (sx) entry.sx = sx\n const variants = sanitizeVariants(override.variants)\n if (variants) entry.variants = variants\n if (Object.keys(entry).length) sanitized[key] = entry\n }\n return Object.keys(sanitized).length ? sanitized : undefined\n}\n\n/** `sx` slots: each a style object, anything else dropped. */\nfunction sanitizeSlotStyles(\n slots: unknown,\n): Record<string, Record<string, unknown>> | undefined {\n if (!isPlainObject(slots)) return undefined\n const kept: Record<string, Record<string, unknown>> = {}\n for (const [slot, style] of Object.entries(slots)) {\n if (isPlainObject(style)) kept[slot] = style\n }\n return Object.keys(kept).length ? kept : undefined\n}\n\n/**\n * Variants that can match and style something: a props object of scalars\n * and a style or an `sx`. A malformed entry is dropped rather than handed to\n * MUI, whose variant loop reads `props` and would throw on a missing one.\n */\nfunction sanitizeVariants(\n variants: unknown,\n): HostThemeComponentVariant[] | undefined {\n if (!Array.isArray(variants)) return undefined\n const kept: HostThemeComponentVariant[] = []\n for (const variant of variants) {\n if (!isPlainObject(variant) || !isPlainObject(variant['props'])) continue\n const props = variant['props'] as Record<string, unknown>\n if (\n Object.values(props).some(\n (value) =>\n value !== null &&\n !['string', 'number', 'boolean'].includes(typeof value),\n )\n ) {\n continue\n }\n const entry: HostThemeComponentVariant = {\n props: props as HostThemeComponentVariant['props'],\n }\n if (isPlainObject(variant['style'])) entry.style = variant['style']\n if (isPlainObject(variant['sx'])) entry.sx = variant['sx']\n if (entry.style || entry.sx) kept.push(entry)\n }\n return kept.length ? kept : undefined\n}\n\n/** The theme a style function is handed, as far as `sx` needs it. */\ntype SxTheme = { unstable_sx?: (style: unknown) => unknown }\n\n/**\n * An `sx` object as a style function of the theme it renders under.\n *\n * `components` are read against the BUILT theme of each scheme, so a palette\n * path resolves to that scheme's color: `borderColor: 'divider'` is the light\n * divider on light and the dark one on dark, which is the thing a literal\n * override cannot say.\n */\nfunction sxStyle(sx: Record<string, unknown>) {\n return ({ theme }: { theme: SxTheme }) =>\n theme?.unstable_sx ? theme.unstable_sx(sx) : sx\n}\n\n/**\n * The stored (JSON) components as MUI reads them: each `sx` slot joins its\n * literal `styleOverrides` slot, literal first, and each variant's `sx`\n * becomes a style function.\n */\nfunction componentsToThemeOptions(\n components: Record<string, HostThemeComponentOverride>,\n): NonNullable<ThemeOptions['components']> {\n const converted: Record<string, Record<string, unknown>> = {}\n for (const [key, override] of Object.entries(components)) {\n const entry: Record<string, unknown> = {}\n if (override.defaultProps) entry['defaultProps'] = override.defaultProps\n const slots = new Set([\n ...Object.keys(override.styleOverrides ?? {}),\n ...Object.keys(override.sx ?? {}),\n ])\n if (slots.size) {\n const styleOverrides: Record<string, unknown> = {}\n for (const slot of slots) {\n const literal = override.styleOverrides?.[slot]\n const sx = override.sx?.[slot]\n styleOverrides[slot] =\n sx && literal !== undefined\n ? [literal, sxStyle(sx)]\n : sx\n ? sxStyle(sx)\n : literal\n }\n entry['styleOverrides'] = styleOverrides\n }\n if (override.variants?.length) {\n entry['variants'] = override.variants.map(({ props, style, sx }) => ({\n props,\n style: sx\n ? (context: { theme: SxTheme }) => [\n style ?? {},\n sxStyle(sx)(context),\n ]\n : style,\n }))\n }\n converted[key] = entry\n }\n return converted as NonNullable<ThemeOptions['components']>\n}\n\n/**\n * Strips unknown component overrides and empty branches from a persisted\n * host theme. Returns a new object; the input is never mutated.\n */\nexport function sanitizeHostTheme(theme: HostTheme | undefined): HostTheme {\n if (!theme) return {}\n const sanitized: HostTheme = { ...theme }\n const components = sanitizeComponents(theme.components)\n if (components) sanitized.components = components\n else delete sanitized.components\n // `mixins.toolbar` must be a CSS object; a scalar would reach\n // `createTheme` and throw while building the Toolbar variant.\n if (isPlainObject(theme.mixins?.toolbar)) {\n sanitized.mixins = { toolbar: theme.mixins.toolbar }\n } else {\n delete sanitized.mixins\n }\n // Absent already means \"follows the visitor\", so only the opt-out is worth\n // persisting; anything else (a stale `'auto'`, junk) is dropped.\n if (theme.darkScheme !== 'off') delete sanitized.darkScheme\n return sanitized\n}\n\n/** An `@media` key that names a `min-width`, and the width it names. */\nconst MIN_WIDTH_AT_RULE = /^@media\\b[^{]*\\bmin-width\\s*:\\s*(\\d+(?:\\.\\d+)?)\\s*px/\n\n/**\n * Re-orders breakpoint at-rules ascending, so STORED key order cannot decide\n * which rule wins (AGL-3146).\n *\n * Two `min-width` rules of equal specificity both match a wide window, so the\n * later one wins — which makes key order a rendering decision. Firestore does\n * not preserve it: one stored toolbar mixin came back sm, landscape, base to\n * the server reader and landscape, base, sm to the browser, so aglyn.com's\n * nav drew 48px live and 72px on the besigner canvas from a single saved\n * document. The editor and the page disagreed about a value neither of them\n * had changed.\n *\n * Ascending is the order MUI writes its own breakpoint styles in and the\n * order the theme editor writes a toolbar mixin in: the wider query is the\n * more specific answer, so it belongs last.\n *\n * Only two things move. Plain declarations are hoisted ahead of the blocks,\n * keeping their order among themselves — which is where the style engine\n * emits them anyway, since a nested block becomes a rule of its own after the\n * base one, and where the shorthand/longhand hazard lives. Breakpoint rules\n * are sorted into the slots the blocks already occupy, so a nested selector\n * or a condition naming no width never changes position against one another.\n *\n * Returns its input by identity when no order changes, which is every theme\n * with at most one breakpoint rule per object.\n */\nexport function orderMediaWidths<T>(value: T): T {\n if (Array.isArray(value)) {\n let moved = false\n const next = value.map((entry) => {\n const ordered = orderMediaWidths(entry)\n if (ordered !== entry) moved = true\n return ordered\n })\n return (moved ? next : value) as T\n }\n if (!isPlainObject(value)) return value\n\n const source = value as Record<string, unknown>\n const keys = Object.keys(source)\n const declarations = keys.filter((key) => !isPlainObject(source[key]))\n const blocks = keys.filter((key) => isPlainObject(source[key]))\n const widthSlots: number[] = []\n const widths: Array<{ key: string; width: number }> = []\n blocks.forEach((key, index) => {\n const match = MIN_WIDTH_AT_RULE.exec(key)\n if (!match) return\n widthSlots.push(index)\n widths.push({ key, width: Number.parseFloat(match[1]) })\n })\n // A stable sort, so two rules at the same width keep the order they were\n // stored in — there is nothing to prefer between them.\n const sorted = [...widths].sort((a, b) => a.width - b.width)\n widthSlots.forEach((slot, position) => {\n blocks[slot] = sorted[position].key\n })\n\n const order = [...declarations, ...blocks]\n let moved = order.some((key, index) => key !== keys[index])\n const next: Record<string, unknown> = {}\n for (const key of order) {\n const child = orderMediaWidths(source[key])\n if (child !== source[key]) moved = true\n next[key] = child\n }\n return (moved ? next : value) as T\n}\n\n/**\n * Converts a persisted {@link HostTheme} document into MUI `ThemeOptions`\n * for one color scheme. The result is meant to be passed through\n * `createResponsiveTheme` (or `createTheme`) by the consumer; shade and\n * contrast-text derivation for partial palettes is MUI's job, so only\n * explicitly set values are forwarded.\n */\nexport function hostThemeToThemeOptions(\n theme: HostTheme | undefined,\n scheme: HostThemeScheme,\n): ThemeOptions {\n const sanitized = sanitizeHostTheme(theme)\n const options: ThemeOptions = {\n palette: schemeColorsToPaletteOptions(\n scheme,\n sanitized.colorSchemes?.[scheme],\n ),\n }\n\n const { typography } = sanitized\n if (typography?.fontFamily || typography?.variants) {\n // HostThemeTypographyVariant is a sanitized subset of MUI's\n // TypographyStyleOptions; the missing index signature is by design.\n options.typography = {\n ...(typography.fontFamily && { fontFamily: typography.fontFamily }),\n ...typography.variants,\n } as ThemeOptions['typography']\n }\n\n if (typeof sanitized.shape?.borderRadius === 'number') {\n options.shape = { borderRadius: sanitized.shape.borderRadius }\n }\n if (typeof sanitized.spacing === 'number') {\n options.spacing = sanitized.spacing\n }\n if (sanitized.components) {\n // Ordered BEFORE conversion: an `sx` object ends up inside a closure,\n // where the pass over the finished options below cannot reach it.\n options.components = componentsToThemeOptions(\n orderMediaWidths(sanitized.components),\n )\n }\n // Toolbar height is only reachable here (AGL-1242). MUI derives the\n // Toolbar's `regular` variant style from `mixins.toolbar` and applies it\n // AFTER `components.MuiToolbar.styleOverrides`, so the slot override loses\n // every time — its nested media queries do not even emit.\n if (sanitized.mixins?.toolbar) {\n options.mixins = { toolbar: sanitized.mixins.toolbar }\n }\n\n // Every surface that renders a site's theme arrives here — the tenant's\n // provider, the besigner canvas, Preview, the theme editor — so this is\n // where a stored document stops being able to resolve differently for\n // different readers (AGL-3146).\n return orderMediaWidths(options)\n}\n\n/**\n * Layers a host's overrides ONTO a base set of theme options (AGL-1180).\n *\n * `hostThemeToThemeOptions` deliberately emits only what the host explicitly\n * set, so building a theme from it alone leaves every other slot to MUI's\n * stock palette. Consumers used to switch — console theme when the document\n * was empty, host document when it was not — which meant setting a single\n * value (the spec's own example is `{ spacing: 8 }`) silently repainted\n * secondary, tertiary, surface, info, success, warning, error, background\n * and paper in MUI blue/purple. Merging instead of switching keeps the brand\n * as the floor no matter how much the host customizes.\n *\n * `palette` merges one level deep so overriding `primary` cannot drop\n * `secondary`. Within a single colour the override replaces the whole record\n * — MUI derives shades and contrast text from `main`, which is exactly the\n * partial-palette behaviour the converter is written for.\n */\nexport function mergeThemeOptions(\n base: ThemeOptions,\n overrides: ThemeOptions,\n): ThemeOptions {\n const merged: ThemeOptions = { ...base, ...overrides }\n\n // Palette merges ONE level: overriding a colour replaces its whole record\n // so MUI re-derives light/dark/contrastText from the new `main`, which is\n // the partial-palette behaviour the converter is written for. Overriding\n // `primary` still must not disturb `secondary`, hence the level.\n merged.palette = { ...base.palette, ...overrides.palette }\n merged.shape = { ...base.shape, ...overrides.shape }\n // Same reasoning as `palette`: setting `toolbar` must not drop any other\n // mixin the base defines.\n merged.mixins = { ...base.mixins, ...overrides.mixins }\n\n // `typography` is an object in every base we ship, but MUI's type also\n // allows a function of the palette — merging into that would silently drop\n // the base, so prefer the override wholesale in that case.\n if (\n isPlainObject(base.typography) &&\n isPlainObject(overrides.typography)\n ) {\n merged.typography = objectDeepMergeReplaceArrays(\n base.typography,\n overrides.typography,\n ) as ThemeOptions['typography']\n }\n\n // Components merge DEEPLY. A host override names one component, and often\n // one property inside it — `MuiButton.defaultProps.color`. A shallow merge\n // would swap out the entire `MuiButton` entry and take the brand's\n // `styleOverrides` with it, and those styles are frequently FUNCTIONS of\n // the theme that JSON cannot express, so the editor could not put them\n // back even in principle. Deep-merging means you override the leaf you\n // named and inherit everything else, functions included.\n merged.components = objectDeepMergeReplaceArrays(\n base.components ?? {},\n overrides.components ?? {},\n ) as ThemeOptions['components']\n composeComponentStyles(merged.components, base.components, overrides.components)\n\n return merged\n}\n\ntype ComponentOptions = {\n styleOverrides?: Record<string, unknown>\n variants?: unknown[]\n}\n\n/** A slot's styles as a list MUI resolves in order (its `processStyle` flattens arrays). */\nfunction styleList(style: unknown): unknown[] {\n return Array.isArray(style) ? style : [style]\n}\n\n/**\n * Where a deep merge would REPLACE styling rather than add to it, composes\n * the two instead (AGL-3403).\n *\n * A deep merge merges two style OBJECTS key by key, which is right. But the\n * base styles several slots with a FUNCTION of the theme — `MuiButton.root`\n * carries the accent-text contrast fix — and merging an object onto a\n * function keeps only the object. So a theme that set one property on the\n * button root silently removed the fix, and nothing JSON can say could put it\n * back. MUI accepts a list per slot and applies it in order, so a function on\n * either side makes the slot `[base, override]`: the override still wins\n * every property it names, and everything else the base did still happens.\n *\n * `variants` concatenate for the same reason: the base's outlined\n * `IconButton` must not disappear because a theme styled its `small` size.\n */\nfunction composeComponentStyles(\n merged: ThemeOptions['components'],\n base: ThemeOptions['components'],\n overrides: ThemeOptions['components'],\n): void {\n if (!merged || !base || !overrides) return\n const target = merged as Record<string, ComponentOptions>\n for (const [name, override] of Object.entries(\n overrides as Record<string, ComponentOptions>,\n )) {\n const from = (base as Record<string, ComponentOptions>)[name]\n if (!from || !override) continue\n for (const [slot, style] of Object.entries(override.styleOverrides ?? {})) {\n const baseStyle = from.styleOverrides?.[slot]\n if (baseStyle === undefined) continue\n if (isPlainObject(baseStyle) && isPlainObject(style)) continue\n target[name].styleOverrides = {\n ...target[name].styleOverrides,\n [slot]: [...styleList(baseStyle), ...styleList(style)],\n }\n }\n if (Array.isArray(from.variants) && Array.isArray(override.variants)) {\n target[name].variants = [...from.variants, ...override.variants]\n }\n }\n}\n\n/** Plain data object — not an array, function, or class instance. */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return (\n typeof value === 'object' && value !== null && !Array.isArray(value)\n )\n}\n\n/** True when the document customizes anything, i.e. consumers should build a theme from it rather than using their default. */\nexport function hasHostTheme(theme: HostTheme | undefined): theme is HostTheme {\n return !!theme && Object.keys(theme).length > 0\n}\n\n/**\n * Builds a Google Fonts CSS2 stylesheet URL for the theme's loadable fonts.\n * Returns undefined when nothing needs loading (system/absent fonts).\n */\nexport function getGoogleFontsUrl(fonts: Array<HostThemeFont> | undefined) {\n const families = (fonts ?? [])\n .filter((font) => font.family && (font.source ?? 'google') === 'google')\n .map((font) => {\n const family = font.family.trim().replace(/\\s+/g, '+')\n const weights = font.weights?.length\n ? `:wght@${[...font.weights].sort((a, b) => a - b).join(';')}`\n : ''\n return `family=${family}${weights}`\n })\n if (!families.length) return undefined\n return `https://fonts.googleapis.com/css2?${families.join('&')}&display=swap`\n}\n\nexport default hostThemeToThemeOptions\n"],"names":["objectDeepMergeReplaceArrays","HOST_THEME_COMPONENT_WHITELIST","componentWhitelist","Set","pickPaletteColor","color","main","undefined","picked","light","dark","contrastText","schemeColorsToPaletteOptions","scheme","colors","palette","mode","colorKeys","key","background","default","paper","text","primary","secondary","disabled","tint","tertiary","divider","sanitizeComponents","components","sanitized","override","Object","entries","has","entry","defaultProps","styleOverrides","sx","sanitizeSlotStyles","variants","sanitizeVariants","keys","length","slots","isPlainObject","kept","slot","style","Array","isArray","variant","props","values","some","value","includes","push","sxStyle","theme","unstable_sx","componentsToThemeOptions","converted","size","literal","map","context","sanitizeHostTheme","mixins","toolbar","darkScheme","MIN_WIDTH_AT_RULE","orderMediaWidths","moved","next","ordered","source","declarations","filter","blocks","widthSlots","widths","forEach","index","match","exec","width","Number","parseFloat","sorted","sort","a","b","position","order","child","hostThemeToThemeOptions","options","colorSchemes","typography","fontFamily","shape","borderRadius","spacing","mergeThemeOptions","base","overrides","merged","composeComponentStyles","styleList","target","name","from","baseStyle","hasHostTheme","getGoogleFontsUrl","fonts","families","font","family","trim","replace","weights","join"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAWD,SAAS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vE,QAAQ,GAAG;mBAAIwE,KAAKxE,QAAQ;mBAAKT,SAASS,QAAQ;aAAC;QAClE;IACF;AACF;AAEA,mEAAmE,GACnE,SAASK,cAAcU,KAAc;IACnC,OACE,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACN,MAAMC,OAAO,CAACK;AAElE;AAEA,6HAA6H,GAC7H,OAAO,SAAS2D,aAAavD,KAA4B;IACvD,OAAO,CAAC,CAACA,SAAS3B,OAAOU,IAAI,CAACiB,OAAOhB,MAAM,GAAG;AAChD;AAEA;;;CAGC,GACD,OAAO,SAASwE,kBAAkBC,KAAuC;IACvE,MAAMC,WAAW,CAACD,gBAAAA,QAAS,EAAE,EAC1BtC,MAAM,CAAC,CAACwC;YAAyBA;eAAhBA,KAAKC,MAAM,IAAI,EAACD,eAAAA,KAAK1C,MAAM,YAAX0C,eAAe,cAAc;OAC9DrD,GAAG,CAAC,CAACqD;YAEYA;QADhB,MAAMC,SAASD,KAAKC,MAAM,CAACC,IAAI,GAAGC,OAAO,CAAC,QAAQ;QAClD,MAAMC,UAAUJ,EAAAA,gBAAAA,KAAKI,OAAO,qBAAZJ,cAAc3E,MAAM,IAChC,CAAC,MAAM,EAAE;eAAI2E,KAAKI,OAAO;SAAC,CAAChC,IAAI,CAAC,CAACC,GAAGC,IAAMD,IAAIC,GAAG+B,IAAI,CAAC,MAAM,GAC5D;QACJ,OAAO,CAAC,OAAO,EAAEJ,SAASG,SAAS;IACrC;IACF,IAAI,CAACL,SAAS1E,MAAM,EAAE,OAAOrC;IAC7B,OAAO,CAAC,kCAAkC,EAAE+G,SAASM,IAAI,CAAC,KAAK,aAAa,CAAC;AAC/E;AAEA,eAAe3B,wBAAuB"}
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/ui/theme/src/lib/util/host-theme.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n HostTheme,\n HostThemeComponentOverride,\n HostThemeComponentVariant,\n HostThemeFont,\n HostThemePaletteColor,\n HostThemeScheme,\n HostThemeSchemeColors,\n} from '@aglyn/shared-data-types'\nimport { objectDeepMergeReplaceArrays } from '@aglyn/shared-util-vendor'\nimport {\n darken,\n lighten,\n type PaletteOptions,\n type ThemeOptions,\n} from '../../vendor/mui'\n\n/**\n * Components a host theme may override. Persisted overrides are plain JSON;\n * anything outside this list is dropped by {@link sanitizeHostTheme} so a\n * tampered document can't restyle console-internal or portal-critical\n * components.\n *\n * The list is what a site actually renders — its elements, the forms, booking\n * and commerce surfaces, and the dialogs and menus they open — so a theme can\n * restyle a whole site rather than its buttons alone (AGL-3403). Layout\n * primitives (`MuiContainer`, `MuiGrid`, `MuiStack`, `MuiBox`) are absent on\n * purpose: they carry the page structure, and a theme that reflowed them\n * would break layouts the Besigner drew.\n */\nexport const HOST_THEME_COMPONENT_WHITELIST = [\n 'MuiAccordion',\n 'MuiAccordionDetails',\n 'MuiAccordionSummary',\n 'MuiAlert',\n 'MuiAlertTitle',\n 'MuiAppBar',\n 'MuiAvatar',\n 'MuiBadge',\n 'MuiBreadcrumbs',\n 'MuiButton',\n 'MuiButtonBase',\n 'MuiButtonGroup',\n 'MuiCard',\n 'MuiCardActions',\n 'MuiCardContent',\n 'MuiCardHeader',\n 'MuiCheckbox',\n 'MuiChip',\n 'MuiCircularProgress',\n 'MuiDialog',\n 'MuiDialogActions',\n 'MuiDialogContent',\n 'MuiDialogTitle',\n 'MuiDivider',\n 'MuiDrawer',\n 'MuiFab',\n 'MuiFilledInput',\n 'MuiFormControlLabel',\n 'MuiFormHelperText',\n 'MuiFormLabel',\n 'MuiIconButton',\n 'MuiInput',\n 'MuiInputBase',\n 'MuiInputLabel',\n 'MuiLinearProgress',\n 'MuiLink',\n 'MuiList',\n 'MuiListItem',\n 'MuiListItemButton',\n 'MuiMenu',\n 'MuiMenuItem',\n 'MuiOutlinedInput',\n 'MuiPagination',\n 'MuiPaginationItem',\n 'MuiPaper',\n 'MuiRadio',\n 'MuiRating',\n 'MuiSelect',\n 'MuiSlider',\n 'MuiSnackbarContent',\n 'MuiSwitch',\n 'MuiTab',\n 'MuiTable',\n 'MuiTableCell',\n 'MuiTableHead',\n 'MuiTableRow',\n 'MuiTabs',\n 'MuiTextField',\n 'MuiToggleButton',\n 'MuiToggleButtonGroup',\n 'MuiToolbar',\n 'MuiTooltip',\n 'MuiTypography',\n] as const\n\nexport type HostThemeComponentKey =\n (typeof HOST_THEME_COMPONENT_WHITELIST)[number]\n\nconst componentWhitelist: ReadonlySet<string> = new Set(\n HOST_THEME_COMPONENT_WHITELIST,\n)\n\nfunction pickPaletteColor(color: HostThemePaletteColor | undefined) {\n if (!color?.main) return undefined\n const picked: HostThemePaletteColor = { main: color.main }\n if (color.light) picked.light = color.light\n if (color.dark) picked.dark = color.dark\n if (color.contrastText) picked.contrastText = color.contrastText\n return picked\n}\n\nfunction schemeColorsToPaletteOptions(\n scheme: HostThemeScheme,\n colors: HostThemeSchemeColors | undefined,\n): PaletteOptions {\n const palette: PaletteOptions = { mode: scheme }\n if (!colors) return palette\n\n const colorKeys = [\n 'primary',\n 'secondary',\n 'tertiary',\n 'surface',\n 'error',\n 'warning',\n 'info',\n 'success',\n ] as const\n for (const key of colorKeys) {\n const color = pickPaletteColor(colors[key])\n if (color) (palette as Record<string, unknown>)[key] = color\n }\n\n if (colors.background?.default || colors.background?.paper) {\n palette.background = {\n ...(colors.background.default && { default: colors.background.default }),\n ...(colors.background.paper && { paper: colors.background.paper }),\n }\n }\n if (\n colors.text?.primary ||\n colors.text?.secondary ||\n colors.text?.disabled\n ) {\n palette.text = {\n ...(colors.text.primary && { primary: colors.text.primary }),\n ...(colors.text.secondary && { secondary: colors.text.secondary }),\n ...(colors.text.disabled && { disabled: colors.text.disabled }),\n }\n }\n // Tints are string leaves, not a PaletteColor, so they pass through the\n // same \"copy what was set\" path as `background`/`text` rather than\n // `pickPaletteColor` — which requires a `main` a tint does not have\n // (AGL-1244).\n if (colors.tint?.primary || colors.tint?.secondary || colors.tint?.tertiary) {\n palette.tint = {\n ...(colors.tint.primary && { primary: colors.tint.primary }),\n ...(colors.tint.secondary && { secondary: colors.tint.secondary }),\n ...(colors.tint.tertiary && { tertiary: colors.tint.tertiary }),\n }\n }\n if (colors.divider) palette.divider = colors.divider\n\n return palette\n}\n\nfunction sanitizeComponents(\n components: Record<string, HostThemeComponentOverride> | undefined,\n) {\n if (!components) return undefined\n const sanitized: Record<string, HostThemeComponentOverride> = {}\n for (const [key, override] of Object.entries(components)) {\n if (!componentWhitelist.has(key) || !override) continue\n const entry: HostThemeComponentOverride = {}\n if (override.defaultProps) entry.defaultProps = override.defaultProps\n if (override.styleOverrides) entry.styleOverrides = override.styleOverrides\n const sx = sanitizeSlotStyles(override.sx)\n if (sx) entry.sx = sx\n const variants = sanitizeVariants(override.variants)\n if (variants) entry.variants = variants\n if (Object.keys(entry).length) sanitized[key] = entry\n }\n return Object.keys(sanitized).length ? sanitized : undefined\n}\n\n/** `sx` slots: each a style object, anything else dropped. */\nfunction sanitizeSlotStyles(\n slots: unknown,\n): Record<string, Record<string, unknown>> | undefined {\n if (!isPlainObject(slots)) return undefined\n const kept: Record<string, Record<string, unknown>> = {}\n for (const [slot, style] of Object.entries(slots)) {\n if (isPlainObject(style)) kept[slot] = style\n }\n return Object.keys(kept).length ? kept : undefined\n}\n\n/**\n * Variants that can match and style something: a props object of scalars\n * and a style or an `sx`. A malformed entry is dropped rather than handed to\n * MUI, whose variant loop reads `props` and would throw on a missing one.\n */\nfunction sanitizeVariants(\n variants: unknown,\n): HostThemeComponentVariant[] | undefined {\n if (!Array.isArray(variants)) return undefined\n const kept: HostThemeComponentVariant[] = []\n for (const variant of variants) {\n if (!isPlainObject(variant) || !isPlainObject(variant['props'])) continue\n const props = variant['props'] as Record<string, unknown>\n if (\n Object.values(props).some(\n (value) =>\n value !== null &&\n !['string', 'number', 'boolean'].includes(typeof value),\n )\n ) {\n continue\n }\n const entry: HostThemeComponentVariant = {\n props: props as HostThemeComponentVariant['props'],\n }\n if (isPlainObject(variant['style'])) entry.style = variant['style']\n if (isPlainObject(variant['sx'])) entry.sx = variant['sx']\n if (entry.style || entry.sx) kept.push(entry)\n }\n return kept.length ? kept : undefined\n}\n\n/** The theme a style function is handed, as far as `sx` needs it. */\ntype SxTheme = { unstable_sx?: (style: unknown) => unknown }\n\n/**\n * An `sx` object as a style function of the theme it renders under.\n *\n * `components` are read against the BUILT theme of each scheme, so a palette\n * path resolves to that scheme's color: `borderColor: 'divider'` is the light\n * divider on light and the dark one on dark, which is the thing a literal\n * override cannot say.\n */\nfunction sxStyle(sx: Record<string, unknown>) {\n return ({ theme }: { theme: SxTheme }) =>\n theme?.unstable_sx ? theme.unstable_sx(sx) : sx\n}\n\n/**\n * The stored (JSON) components as MUI reads them: each `sx` slot joins its\n * literal `styleOverrides` slot, literal first, and each variant's `sx`\n * becomes a style function.\n */\nfunction componentsToThemeOptions(\n components: Record<string, HostThemeComponentOverride>,\n): NonNullable<ThemeOptions['components']> {\n const converted: Record<string, Record<string, unknown>> = {}\n for (const [key, override] of Object.entries(components)) {\n const entry: Record<string, unknown> = {}\n if (override.defaultProps) entry['defaultProps'] = override.defaultProps\n const slots = new Set([\n ...Object.keys(override.styleOverrides ?? {}),\n ...Object.keys(override.sx ?? {}),\n ])\n if (slots.size) {\n const styleOverrides: Record<string, unknown> = {}\n for (const slot of slots) {\n const literal = override.styleOverrides?.[slot]\n const sx = override.sx?.[slot]\n styleOverrides[slot] =\n sx && literal !== undefined\n ? [literal, sxStyle(sx)]\n : sx\n ? sxStyle(sx)\n : literal\n }\n entry['styleOverrides'] = styleOverrides\n }\n if (override.variants?.length) {\n entry['variants'] = override.variants.map(({ props, style, sx }) => ({\n props,\n style: sx\n ? (context: { theme: SxTheme }) => [\n style ?? {},\n sxStyle(sx)(context),\n ]\n : style,\n }))\n }\n converted[key] = entry\n }\n return converted as NonNullable<ThemeOptions['components']>\n}\n\n/**\n * Strips unknown component overrides and empty branches from a persisted\n * host theme. Returns a new object; the input is never mutated.\n */\nexport function sanitizeHostTheme(theme: HostTheme | undefined): HostTheme {\n if (!theme) return {}\n const sanitized: HostTheme = { ...theme }\n const components = sanitizeComponents(theme.components)\n if (components) sanitized.components = components\n else delete sanitized.components\n // `mixins.toolbar` must be a CSS object; a scalar would reach\n // `createTheme` and throw while building the Toolbar variant.\n if (isPlainObject(theme.mixins?.toolbar)) {\n sanitized.mixins = { toolbar: theme.mixins.toolbar }\n } else {\n delete sanitized.mixins\n }\n // Absent already means \"follows the visitor\", so only the opt-out is worth\n // persisting; anything else (a stale `'auto'`, junk) is dropped.\n if (theme.darkScheme !== 'off') delete sanitized.darkScheme\n return sanitized\n}\n\n/** An `@media` key that names a `min-width`, and the width it names. */\nconst MIN_WIDTH_AT_RULE = /^@media\\b[^{]*\\bmin-width\\s*:\\s*(\\d+(?:\\.\\d+)?)\\s*px/\n\n/**\n * Re-orders breakpoint at-rules ascending, so STORED key order cannot decide\n * which rule wins (AGL-3146).\n *\n * Two `min-width` rules of equal specificity both match a wide window, so the\n * later one wins — which makes key order a rendering decision. Firestore does\n * not preserve it: one stored toolbar mixin came back sm, landscape, base to\n * the server reader and landscape, base, sm to the browser, so aglyn.com's\n * nav drew 48px live and 72px on the besigner canvas from a single saved\n * document. The editor and the page disagreed about a value neither of them\n * had changed.\n *\n * Ascending is the order MUI writes its own breakpoint styles in and the\n * order the theme editor writes a toolbar mixin in: the wider query is the\n * more specific answer, so it belongs last.\n *\n * Only two things move. Plain declarations are hoisted ahead of the blocks,\n * keeping their order among themselves — which is where the style engine\n * emits them anyway, since a nested block becomes a rule of its own after the\n * base one, and where the shorthand/longhand hazard lives. Breakpoint rules\n * are sorted into the slots the blocks already occupy, so a nested selector\n * or a condition naming no width never changes position against one another.\n *\n * Returns its input by identity when no order changes, which is every theme\n * with at most one breakpoint rule per object.\n */\nexport function orderMediaWidths<T>(value: T): T {\n if (Array.isArray(value)) {\n let moved = false\n const next = value.map((entry) => {\n const ordered = orderMediaWidths(entry)\n if (ordered !== entry) moved = true\n return ordered\n })\n return (moved ? next : value) as T\n }\n if (!isPlainObject(value)) return value\n\n const source = value as Record<string, unknown>\n const keys = Object.keys(source)\n const declarations = keys.filter((key) => !isPlainObject(source[key]))\n const blocks = keys.filter((key) => isPlainObject(source[key]))\n const widthSlots: number[] = []\n const widths: Array<{ key: string; width: number }> = []\n blocks.forEach((key, index) => {\n const match = MIN_WIDTH_AT_RULE.exec(key)\n if (!match) return\n widthSlots.push(index)\n widths.push({ key, width: Number.parseFloat(match[1]) })\n })\n // A stable sort, so two rules at the same width keep the order they were\n // stored in — there is nothing to prefer between them.\n const sorted = [...widths].sort((a, b) => a.width - b.width)\n widthSlots.forEach((slot, position) => {\n blocks[slot] = sorted[position].key\n })\n\n const order = [...declarations, ...blocks]\n let moved = order.some((key, index) => key !== keys[index])\n const next: Record<string, unknown> = {}\n for (const key of order) {\n const child = orderMediaWidths(source[key])\n if (child !== source[key]) moved = true\n next[key] = child\n }\n return (moved ? next : value) as T\n}\n\n/**\n * A tint is a wash of its accent, so it is derived from `main` the way MUI\n * derives `light` and `dark`: with its own `lighten`/`darken`.\n */\nexport function accentTint(main: string, mode: PaletteOptions['mode']): string {\n return mode === 'dark' ? darken(main, 0.7) : lighten(main, 0.9)\n}\n\n/**\n * The tints a site renders: the base's, each replaced by the site's own where\n * it sets one, or washed from the site's accent where it sets the accent\n * without one, so a recolored brand never keeps the theme's old wash.\n */\nfunction mergeTints(\n base: PaletteOptions | undefined,\n overrides: PaletteOptions | undefined,\n): PaletteOptions['tint'] {\n if (!overrides?.tint && !overrides?.primary && !overrides?.secondary && !overrides?.tertiary) {\n return undefined\n }\n const tint: Record<string, string> = { ...base?.tint, ...overrides.tint }\n for (const key of ['primary', 'secondary', 'tertiary'] as const) {\n const main = (overrides[key] as { main?: unknown } | undefined)?.main\n if (overrides.tint?.[key] || typeof main !== 'string') continue\n try {\n tint[key] = accentTint(main, overrides.mode ?? base?.mode)\n } catch {\n // Not a color MUI can parse (a CSS variable): keep the inherited tint.\n }\n }\n return tint\n}\n\n/**\n * Converts a persisted {@link HostTheme} document into MUI `ThemeOptions`\n * for one color scheme. The result is meant to be passed through\n * `createResponsiveTheme` (or `createTheme`) by the consumer; shade and\n * contrast-text derivation for partial palettes is MUI's job, so only\n * explicitly set values are forwarded.\n */\nexport function hostThemeToThemeOptions(\n theme: HostTheme | undefined,\n scheme: HostThemeScheme,\n): ThemeOptions {\n const sanitized = sanitizeHostTheme(theme)\n const options: ThemeOptions = {\n palette: schemeColorsToPaletteOptions(\n scheme,\n sanitized.colorSchemes?.[scheme],\n ),\n }\n\n const { typography } = sanitized\n if (typography?.fontFamily || typography?.variants) {\n // HostThemeTypographyVariant is a sanitized subset of MUI's\n // TypographyStyleOptions; the missing index signature is by design.\n options.typography = {\n ...(typography.fontFamily && { fontFamily: typography.fontFamily }),\n ...typography.variants,\n } as ThemeOptions['typography']\n }\n\n if (typeof sanitized.shape?.borderRadius === 'number') {\n options.shape = { borderRadius: sanitized.shape.borderRadius }\n }\n if (typeof sanitized.spacing === 'number') {\n options.spacing = sanitized.spacing\n }\n if (sanitized.components) {\n // Ordered BEFORE conversion: an `sx` object ends up inside a closure,\n // where the pass over the finished options below cannot reach it.\n options.components = componentsToThemeOptions(\n orderMediaWidths(sanitized.components),\n )\n }\n // Toolbar height is only reachable here (AGL-1242). MUI derives the\n // Toolbar's `regular` variant style from `mixins.toolbar` and applies it\n // AFTER `components.MuiToolbar.styleOverrides`, so the slot override loses\n // every time — its nested media queries do not even emit.\n if (sanitized.mixins?.toolbar) {\n options.mixins = { toolbar: sanitized.mixins.toolbar }\n }\n\n // Every surface that renders a site's theme arrives here — the tenant's\n // provider, the besigner canvas, Preview, the theme editor — so this is\n // where a stored document stops being able to resolve differently for\n // different readers (AGL-3146).\n return orderMediaWidths(options)\n}\n\n/**\n * Layers a host's overrides ONTO a base set of theme options (AGL-1180).\n *\n * `hostThemeToThemeOptions` deliberately emits only what the host explicitly\n * set, so building a theme from it alone leaves every other slot to MUI's\n * stock palette. Consumers used to switch — console theme when the document\n * was empty, host document when it was not — which meant setting a single\n * value (the spec's own example is `{ spacing: 8 }`) silently repainted\n * secondary, tertiary, surface, info, success, warning, error, background\n * and paper in MUI blue/purple. Merging instead of switching keeps the brand\n * as the floor no matter how much the host customizes.\n *\n * `palette` merges one level deep so overriding `primary` cannot drop\n * `secondary`. Within a single colour the override replaces the whole record\n * — MUI derives shades and contrast text from `main`, which is exactly the\n * partial-palette behaviour the converter is written for.\n */\nexport function mergeThemeOptions(\n base: ThemeOptions,\n overrides: ThemeOptions,\n): ThemeOptions {\n const merged: ThemeOptions = { ...base, ...overrides }\n\n // Palette merges ONE level: overriding a colour replaces its whole record\n // so MUI re-derives light/dark/contrastText from the new `main`, which is\n // the partial-palette behaviour the converter is written for. Overriding\n // `primary` still must not disturb `secondary`, hence the level.\n merged.palette = { ...base.palette, ...overrides.palette }\n const tint = mergeTints(base.palette, overrides.palette)\n if (tint) merged.palette.tint = tint\n merged.shape = { ...base.shape, ...overrides.shape }\n // Same reasoning as `palette`: setting `toolbar` must not drop any other\n // mixin the base defines.\n merged.mixins = { ...base.mixins, ...overrides.mixins }\n\n // `typography` is an object in every base we ship, but MUI's type also\n // allows a function of the palette — merging into that would silently drop\n // the base, so prefer the override wholesale in that case.\n if (\n isPlainObject(base.typography) &&\n isPlainObject(overrides.typography)\n ) {\n merged.typography = objectDeepMergeReplaceArrays(\n base.typography,\n overrides.typography,\n ) as ThemeOptions['typography']\n }\n\n // Components merge DEEPLY. A host override names one component, and often\n // one property inside it — `MuiButton.defaultProps.color`. A shallow merge\n // would swap out the entire `MuiButton` entry and take the brand's\n // `styleOverrides` with it, and those styles are frequently FUNCTIONS of\n // the theme that JSON cannot express, so the editor could not put them\n // back even in principle. Deep-merging means you override the leaf you\n // named and inherit everything else, functions included.\n merged.components = objectDeepMergeReplaceArrays(\n base.components ?? {},\n overrides.components ?? {},\n ) as ThemeOptions['components']\n composeComponentStyles(merged.components, base.components, overrides.components)\n\n return merged\n}\n\ntype ComponentOptions = {\n styleOverrides?: Record<string, unknown>\n variants?: unknown[]\n}\n\n/** A slot's styles as a list MUI resolves in order (its `processStyle` flattens arrays). */\nfunction styleList(style: unknown): unknown[] {\n return Array.isArray(style) ? style : [style]\n}\n\n/**\n * Where a deep merge would REPLACE styling rather than add to it, composes\n * the two instead (AGL-3403).\n *\n * A deep merge merges two style OBJECTS key by key, which is right. But the\n * base styles several slots with a FUNCTION of the theme — `MuiButton.root`\n * carries the accent-text contrast fix — and merging an object onto a\n * function keeps only the object. So a theme that set one property on the\n * button root silently removed the fix, and nothing JSON can say could put it\n * back. MUI accepts a list per slot and applies it in order, so a function on\n * either side makes the slot `[base, override]`: the override still wins\n * every property it names, and everything else the base did still happens.\n *\n * `variants` concatenate for the same reason: the base's outlined\n * `IconButton` must not disappear because a theme styled its `small` size.\n */\nfunction composeComponentStyles(\n merged: ThemeOptions['components'],\n base: ThemeOptions['components'],\n overrides: ThemeOptions['components'],\n): void {\n if (!merged || !base || !overrides) return\n const target = merged as Record<string, ComponentOptions>\n for (const [name, override] of Object.entries(\n overrides as Record<string, ComponentOptions>,\n )) {\n const from = (base as Record<string, ComponentOptions>)[name]\n if (!from || !override) continue\n for (const [slot, style] of Object.entries(override.styleOverrides ?? {})) {\n const baseStyle = from.styleOverrides?.[slot]\n if (baseStyle === undefined) continue\n if (isPlainObject(baseStyle) && isPlainObject(style)) continue\n target[name].styleOverrides = {\n ...target[name].styleOverrides,\n [slot]: [...styleList(baseStyle), ...styleList(style)],\n }\n }\n if (Array.isArray(from.variants) && Array.isArray(override.variants)) {\n target[name].variants = [...from.variants, ...override.variants]\n }\n }\n}\n\n/** Plain data object — not an array, function, or class instance. */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return (\n typeof value === 'object' && value !== null && !Array.isArray(value)\n )\n}\n\n/** True when the document customizes anything, i.e. consumers should build a theme from it rather than using their default. */\nexport function hasHostTheme(theme: HostTheme | undefined): theme is HostTheme {\n return !!theme && Object.keys(theme).length > 0\n}\n\n/**\n * Builds a Google Fonts CSS2 stylesheet URL for the theme's loadable fonts.\n * Returns undefined when nothing needs loading (system/absent fonts).\n */\nexport function getGoogleFontsUrl(fonts: Array<HostThemeFont> | undefined) {\n const families = (fonts ?? [])\n .filter((font) => font.family && (font.source ?? 'google') === 'google')\n .map((font) => {\n const family = font.family.trim().replace(/\\s+/g, '+')\n const weights = font.weights?.length\n ? `:wght@${[...font.weights].sort((a, b) => a - b).join(';')}`\n : ''\n return `family=${family}${weights}`\n })\n if (!families.length) return undefined\n return `https://fonts.googleapis.com/css2?${families.join('&')}&display=swap`\n}\n\nexport default hostThemeToThemeOptions\n"],"names":["objectDeepMergeReplaceArrays","darken","lighten","HOST_THEME_COMPONENT_WHITELIST","componentWhitelist","Set","pickPaletteColor","color","main","undefined","picked","light","dark","contrastText","schemeColorsToPaletteOptions","scheme","colors","palette","mode","colorKeys","key","background","default","paper","text","primary","secondary","disabled","tint","tertiary","divider","sanitizeComponents","components","sanitized","override","Object","entries","has","entry","defaultProps","styleOverrides","sx","sanitizeSlotStyles","variants","sanitizeVariants","keys","length","slots","isPlainObject","kept","slot","style","Array","isArray","variant","props","values","some","value","includes","push","sxStyle","theme","unstable_sx","componentsToThemeOptions","converted","size","literal","map","context","sanitizeHostTheme","mixins","toolbar","darkScheme","MIN_WIDTH_AT_RULE","orderMediaWidths","moved","next","ordered","source","declarations","filter","blocks","widthSlots","widths","forEach","index","match","exec","width","Number","parseFloat","sorted","sort","a","b","position","order","child","accentTint","mergeTints","base","overrides","hostThemeToThemeOptions","options","colorSchemes","typography","fontFamily","shape","borderRadius","spacing","mergeThemeOptions","merged","composeComponentStyles","styleList","target","name","from","baseStyle","hasHostTheme","getGoogleFontsUrl","fonts","families","font","family","trim","replace","weights","join"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAWD,SAASA,4BAA4B,QAAQ,4BAA2B;AACxE,SACEC,MAAM,EACNC,OAAO,QAGF,sBAAkB;AAEzB;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,iCAAiC;IAC5C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AAKV,MAAMC,qBAA0C,IAAIC,IAClDF;AAGF,SAASG,iBAAiBC,KAAwC;IAChE,IAAI,EAACA,yBAAAA,MAAOC,IAAI,GAAE,OAAOC;IACzB,MAAMC,SAAgC;QAAEF,MAAMD,MAAMC,IAAI;IAAC;IACzD,IAAID,MAAMI,KAAK,EAAED,OAAOC,KAAK,GAAGJ,MAAMI,KAAK;IAC3C,IAAIJ,MAAMK,IAAI,EAAEF,OAAOE,IAAI,GAAGL,MAAMK,IAAI;IACxC,IAAIL,MAAMM,YAAY,EAAEH,OAAOG,YAAY,GAAGN,MAAMM,YAAY;IAChE,OAAOH;AACT;AAEA,SAASI,6BACPC,MAAuB,EACvBC,MAAyC;QAoBrCA,oBAA8BA,qBAOhCA,cACAA,eACAA,eAYEA,cAAwBA,eAA0BA;IAvCtD,MAAMC,UAA0B;QAAEC,MAAMH;IAAO;IAC/C,IAAI,CAACC,QAAQ,OAAOC;IAEpB,MAAME,YAAY;QAChB;QACA;QACA;QACA;QACA;QACA;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,GAAG;mBAAI0E,KAAK1E,QAAQ;mBAAKT,SAASS,QAAQ;aAAC;QAClE;IACF;AACF;AAEA,mEAAmE,GACnE,SAASK,cAAcU,KAAc;IACnC,OACE,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACN,MAAMC,OAAO,CAACK;AAElE;AAEA,6HAA6H,GAC7H,OAAO,SAAS6D,aAAazD,KAA4B;IACvD,OAAO,CAAC,CAACA,SAAS3B,OAAOU,IAAI,CAACiB,OAAOhB,MAAM,GAAG;AAChD;AAEA;;;CAGC,GACD,OAAO,SAAS0E,kBAAkBC,KAAuC;IACvE,MAAMC,WAAW,CAACD,gBAAAA,QAAS,EAAE,EAC1BxC,MAAM,CAAC,CAAC0C;YAAyBA;eAAhBA,KAAKC,MAAM,IAAI,EAACD,eAAAA,KAAK5C,MAAM,YAAX4C,eAAe,cAAc;OAC9DvD,GAAG,CAAC,CAACuD;YAEYA;QADhB,MAAMC,SAASD,KAAKC,MAAM,CAACC,IAAI,GAAGC,OAAO,CAAC,QAAQ;QAClD,MAAMC,UAAUJ,EAAAA,gBAAAA,KAAKI,OAAO,qBAAZJ,cAAc7E,MAAM,IAChC,CAAC,MAAM,EAAE;eAAI6E,KAAKI,OAAO;SAAC,CAAClC,IAAI,CAAC,CAACC,GAAGC,IAAMD,IAAIC,GAAGiC,IAAI,CAAC,MAAM,GAC5D;QACJ,OAAO,CAAC,OAAO,EAAEJ,SAASG,SAAS;IACrC;IACF,IAAI,CAACL,SAAS5E,MAAM,EAAE,OAAOrC;IAC7B,OAAO,CAAC,kCAAkC,EAAEiH,SAASM,IAAI,CAAC,KAAK,aAAa,CAAC;AAC/E;AAEA,eAAezB,wBAAuB"}
@@ -567,6 +567,15 @@ export const FONT_FAMILY_FIELD = {
567
567
  main: hex
568
568
  };
569
569
  else delete next[paletteKey];
570
+ // An accent's tint is a wash of its old `main` for the same reason, so
571
+ // it goes too and the theme washes one from the new color.
572
+ const tint = next.tint;
573
+ if (tint && paletteKey in tint) {
574
+ const rest = _extends({}, tint);
575
+ delete rest[paletteKey];
576
+ if (Object.keys(rest).length) next.tint = rest;
577
+ else delete next.tint;
578
+ }
570
579
  return next;
571
580
  }
572
581
  const groupKey = group;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/shared/ui/theme/src/lib/util/theme-editor-fields.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n HostTheme,\n HostThemeComponentOverride,\n HostThemeFont,\n HostThemeFontCategory,\n HostThemeTypographyVariantKey,\n HostThemeScheme,\n HostThemeSchemeColors,\n} from '@aglyn/shared-data-types'\nimport {\n HOST_THEME_COMPONENT_WHITELIST,\n type HostThemeComponentKey,\n} from './host-theme'\n\n/**\n * The host theme editor's field catalog (AGL-2938): every control the editor\n * renders, the range each one accepts, the token it writes, and the write\n * itself.\n *\n * It lives here rather than beside the editor because the editor is not the\n * only thing that changes a site's theme. Anything that proposes a theme\n * change has to offer exactly the controls the editor offers, with the same\n * bounds, and has to write each one the way the editor writes it. A copy of\n * this list anywhere else is a second answer to \"what can a theme hold\" that\n * drifts from the first the day a control is added, so the editor renders\n * from this module and every other writer reads it.\n *\n * Pure data and pure functions over `HostTheme`: no MUI, no React and no\n * brand theme. What a control resolves to when the site sets nothing is the\n * brand theme's business, in `theme-editor-defaults.ts`.\n *\n * Deliberately NOT re-exported from this library's index: the index reaches\n * every published page, and nothing a visitor renders needs the catalog.\n * Reach it as `@aglyn/shared-ui-theme/util/theme-editor-fields`.\n */\n\n/**\n * MUI's own toolbar breakpoint. `mixins.toolbar` has to carry this exact\n * query, because the rule it competes with is MUI's `@media (min-width:600px)\n * { min-height: 64px }` (AGL-1242).\n */\nexport const TOOLBAR_SM_MIN_WIDTH = 600\nexport const TOOLBAR_SM_QUERY = `@media (min-width:${TOOLBAR_SM_MIN_WIDTH}px)`\n/** MUI's stock Toolbar heights, shown when the host has set none. */\nexport const DEFAULT_TOOLBAR_XS = 56\nexport const DEFAULT_TOOLBAR_SM = 64\n/**\n * `createMixins` spreads `...mixins` AFTER its default, so anything we write\n * REPLACES the stock toolbar wholesale — including its short-landscape rule.\n * Carrying it forward keeps that behavior instead of dropping it silently.\n */\nexport const TOOLBAR_LANDSCAPE_QUERY = '@media (min-width:0px)'\nexport const TOOLBAR_LANDSCAPE_RULE = {\n '@media (orientation: landscape)': { minHeight: 48 },\n}\n\n/** Reads a px `minHeight` out of `mixins.toolbar` for one breakpoint. */\nexport function readToolbarHeight(theme: HostTheme, breakpoint: 'xs' | 'sm') {\n const toolbar = theme.mixins?.toolbar\n if (!toolbar) return undefined\n const raw =\n breakpoint === 'xs'\n ? toolbar.minHeight\n : (toolbar[TOOLBAR_SM_QUERY] as { minHeight?: unknown } | undefined)\n ?.minHeight\n const value = parseFloat(String(raw ?? ''))\n return Number.isFinite(value) ? value : undefined\n}\n\n/**\n * Builds a COMPLETE `mixins.toolbar`, in the order MUI emits it.\n *\n * Two things this exists to get right, both because `mixins.toolbar` replaces\n * MUI's default wholesale rather than merging into it (AGL-1242):\n *\n * - **Completeness.** Anything omitted is simply gone. Writing only a desktop\n * height left portrait phones with no `min-height` at all, so unset\n * breakpoints fall back to MUI's own 56 / 64.\n * - **Key order.** These land in one CSS rule, so the last matching\n * declaration wins. MUI emits the landscape clause BEFORE the sm height;\n * emitting it after makes a wide landscape window — i.e. every desktop —\n * 48px tall.\n */\nexport function buildToolbarMixin(xs: number | undefined, sm: number | undefined) {\n return {\n minHeight: `${xs ?? DEFAULT_TOOLBAR_XS}px`,\n [TOOLBAR_LANDSCAPE_QUERY]: TOOLBAR_LANDSCAPE_RULE,\n [TOOLBAR_SM_QUERY]: { minHeight: `${sm ?? DEFAULT_TOOLBAR_SM}px` },\n }\n}\n\n/**\n * Serializes the branches whose KEY ORDER changes what renders.\n *\n * `deepEqual` is order-INsensitive on purpose (AGL-56: Firestore hands the\n * palette back in a different key order than the editor builds it, and a\n * string compare left Save enabled forever), so on its own it cannot see a\n * reorder of `mixins.toolbar` — a change that really does alter the CSS.\n *\n * Deliberately narrow: only `mixins`. `components.*.styleOverrides` are CSS\n * objects too, but widening this would re-expose the AGL-56 failure for every\n * host with component overrides, and order-sensitivity has only actually been\n * demonstrated here.\n *\n * Firestore does NOT hand a map back in the order it was written, and it\n * hands different readers different orders (AGL-3146) — which is why what\n * renders is canonicalized in `hostThemeToThemeOptions` rather than trusted\n * from storage. A freshly-loaded document is still not dirty here, because\n * the draft is seeded from the loaded document itself: both sides of this\n * comparison carry whatever order THIS reader was given.\n */\nexport function orderSensitiveKey(theme: HostTheme): string {\n return JSON.stringify(theme.mixins ?? {})\n}\n\nexport type PaletteColorKey =\n | 'primary'\n | 'secondary'\n | 'tertiary'\n | 'surface'\n | 'error'\n | 'warning'\n | 'info'\n | 'success'\n\nexport const PALETTE_COLOR_FIELDS: Array<{\n key: PaletteColorKey\n label: string\n}> = [\n { key: 'primary', label: 'Primary' },\n { key: 'secondary', label: 'Secondary' },\n { key: 'tertiary', label: 'Tertiary' },\n { key: 'surface', label: 'Surface' },\n { key: 'error', label: 'Error' },\n { key: 'warning', label: 'Warning' },\n { key: 'info', label: 'Info' },\n { key: 'success', label: 'Success' },\n]\n\nexport type SurfaceColorPath =\n | ['background', 'default']\n | ['background', 'paper']\n | ['text', 'primary']\n | ['text', 'secondary']\n | ['text', 'disabled']\n | ['tint', 'primary']\n | ['tint', 'secondary']\n | ['tint', 'tertiary']\n\nexport const SURFACE_COLOR_FIELDS: Array<{\n path: SurfaceColorPath\n label: string\n}> = [\n { path: ['background', 'default'], label: 'Background' },\n { path: ['background', 'paper'], label: 'Paper' },\n { path: ['text', 'primary'], label: 'Text' },\n { path: ['text', 'secondary'], label: 'Secondary text' },\n { path: ['text', 'disabled'], label: 'Disabled text' },\n]\n\n/**\n * Pale accent washes (AGL-1244).\n *\n * Separate from {@link PALETTE_COLOR_FIELDS} because a tint is a STRING LEAF,\n * not a `{ main }` record — the palette fields all write `main`, and a tint has\n * none. It rides the same `SurfaceColorPath` machinery as `background`/`text`\n * for exactly that reason, and is listed apart only so the editor can head it\n * \"Tints\" instead of filing it under \"Background & text\".\n */\nexport const TINT_COLOR_FIELDS: Array<{\n path: SurfaceColorPath\n label: string\n}> = [\n { path: ['tint', 'primary'], label: 'Primary tint' },\n { path: ['tint', 'secondary'], label: 'Secondary tint' },\n { path: ['tint', 'tertiary'], label: 'Tertiary tint' },\n]\n\n/** The one color leaf that is neither a palette color nor a member of a group. */\nexport const DIVIDER_COLOR_FIELD = { key: 'divider', label: 'Divider' } as const\n\n/** Curated Google Fonts choices for the font family selector. */\nexport const GOOGLE_FONT_OPTIONS: Array<{\n family: string\n category: 'sans-serif' | 'serif' | 'monospace' | 'display'\n weights: Array<number>\n}> = [\n { family: 'Inter', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Roboto', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Open Sans', category: 'sans-serif', weights: [400, 600, 700] },\n { family: 'Lato', category: 'sans-serif', weights: [400, 700] },\n { family: 'Montserrat', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Poppins', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Nunito', category: 'sans-serif', weights: [400, 600, 700] },\n { family: 'Work Sans', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Raleway', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Merriweather', category: 'serif', weights: [400, 700] },\n { family: 'Playfair Display', category: 'serif', weights: [400, 700] },\n { family: 'Lora', category: 'serif', weights: [400, 700] },\n { family: 'Source Serif 4', category: 'serif', weights: [400, 700] },\n { family: 'JetBrains Mono', category: 'monospace', weights: [400, 700] },\n { family: 'Bebas Neue', category: 'display', weights: [400] },\n]\n\nexport function fontFamilyStack(\n family: string,\n category: HostThemeFontCategory,\n) {\n const fallback = category === 'monospace' ? 'monospace' : category === 'serif' ? 'serif' : 'sans-serif'\n return `\"${family}\", ${fallback}`\n}\n\nexport function getSchemeColor(\n colors: HostThemeSchemeColors | undefined,\n path: SurfaceColorPath,\n): string | undefined {\n const [group, key] = path\n return (colors?.[group] as Record<string, string> | undefined)?.[key]\n}\n\n/* ------------------------------------------------------------------------ *\n * The controls, as one catalog\n * ------------------------------------------------------------------------ */\n\n/** The two color schemes the editor edits, in tab order. */\nexport const THEME_EDITOR_SCHEMES: readonly HostThemeScheme[] = ['light', 'dark']\n\n/**\n * Every color the editor edits per scheme, named the way a diff names it: a\n * palette key (`primary`), a group path joined with a dot\n * (`background.default`, `tint.primary`), or `divider`.\n */\nexport type ThemeColorToken =\n | PaletteColorKey\n | 'background.default'\n | 'background.paper'\n | 'text.primary'\n | 'text.secondary'\n | 'text.disabled'\n | 'tint.primary'\n | 'tint.secondary'\n | 'tint.tertiary'\n | 'divider'\n\n/** Where a color control sits in the editor's Color scheme card. */\nexport type ThemeColorGroup = 'palette' | 'surface' | 'tint' | 'divider'\n\n/** Every color field the editor renders, in the order it renders them. */\nexport const THEME_COLOR_FIELDS: ReadonlyArray<{\n token: ThemeColorToken\n label: string\n group: ThemeColorGroup\n}> = [\n ...PALETTE_COLOR_FIELDS.map(({ key, label }) => ({\n token: key,\n label,\n group: 'palette' as const,\n })),\n ...SURFACE_COLOR_FIELDS.map(({ path, label }) => ({\n token: path.join('.') as ThemeColorToken,\n label,\n group: 'surface' as const,\n })),\n ...TINT_COLOR_FIELDS.map(({ path, label }) => ({\n token: path.join('.') as ThemeColorToken,\n label,\n group: 'tint' as const,\n })),\n {\n token: DIVIDER_COLOR_FIELD.key,\n label: DIVIDER_COLOR_FIELD.label,\n group: 'divider' as const,\n },\n]\n\n/** Whether visitors get a dark scheme; absent from the document means `auto`. */\nexport type ThemeDarkSchemeValue = 'auto' | 'off'\n\nexport const DARK_SCHEME_FIELD = {\n label: 'Dark scheme',\n options: [\n { value: 'auto', label: 'Follows the visitor' },\n { value: 'off', label: 'Off — always light' },\n ],\n} as const\n\n/**\n * The font select's value for \"no font of the site's own\": the theme's\n * default stack, with nothing to load.\n */\nexport const SYSTEM_FONT_VALUE = '__system__'\n\nexport const FONT_FAMILY_FIELD = { label: 'Font family' } as const\n\n/** The corner radius slider, in px. */\nexport const BORDER_RADIUS_FIELD = {\n label: 'Border radius',\n min: 0,\n max: 24,\n step: 1,\n} as const\n\n/** The spacing unit MUI multiplies every `spacing(n)` by, in px. */\nexport const SPACING_FIELD = {\n label: 'Spacing unit (px)',\n min: 2,\n max: 16,\n step: 1,\n} as const\n\n/** The two nav heights, either side of MUI's toolbar breakpoint, in px. */\nexport const TOOLBAR_HEIGHT_FIELDS = {\n xs: { label: 'Nav height, mobile (px)', min: 40, max: 160, step: 1 },\n sm: { label: 'Nav height, desktop (px)', min: 40, max: 160, step: 1 },\n} as const\n\n/**\n * The site-wide look of components: the click-only fields in\n * {@link THEME_COMPONENT_LOOK_FIELDS}, with the full override set behind\n * them limited to the sanitizer's whitelist.\n */\nexport const COMPONENT_OVERRIDES_FIELD = {\n label: 'Style components',\n components: HOST_THEME_COMPONENT_WHITELIST,\n} as const\n\n/**\n * The media queries a component override may scope a style to: either side\n * of MUI's own toolbar breakpoint, the one breakpoint the editor already\n * names. MUI's `down('sm')` stops a twentieth of a pixel short of it.\n */\nexport const THEME_EDITOR_MEDIA_QUERIES = {\n mobile: `@media (max-width:${TOOLBAR_SM_MIN_WIDTH - 0.05}px)`,\n desktop: TOOLBAR_SM_QUERY,\n} as const\n\nexport type ThemeEditorMedia = keyof typeof THEME_EDITOR_MEDIA_QUERIES\n\nexport type ThemeEditorControlId =\n | `color.${ThemeColorToken}`\n | 'darkScheme'\n | 'fontFamily'\n | 'borderRadius'\n | 'spacing'\n | 'navHeight.xs'\n | 'navHeight.sm'\n | 'components'\n\n/** One control the editor renders, described well enough to be offered elsewhere. */\nexport interface ThemeEditorControl {\n /** Stable id: what a diff row, a proposal and a spec name the control by. */\n id: ThemeEditorControlId\n /** The label the editor shows. */\n label: string\n kind: 'color' | 'select' | 'number' | 'components'\n /** Edited once per scheme, under the Light and Dark tabs. */\n perScheme: boolean\n /** A color control's token. */\n token?: ThemeColorToken\n /** A select's values, or the components a components control may style. */\n options?: readonly string[]\n /** A number control's inclusive bounds and its step. */\n min?: number\n max?: number\n step?: number\n}\n\n/**\n * Every value-bearing control the editor renders, in the order it renders\n * them. The buttons that act on these values rather than hold one — Copy\n * from light, Reset to default, Discard, Save — are not controls: a reset is\n * a control set back to nothing, and a copy is every color control of one\n * scheme written from the other.\n */\nexport const THEME_EDITOR_CONTROLS: readonly ThemeEditorControl[] = [\n {\n id: 'darkScheme',\n label: DARK_SCHEME_FIELD.label,\n kind: 'select',\n perScheme: false,\n options: DARK_SCHEME_FIELD.options.map((option) => option.value),\n },\n ...THEME_COLOR_FIELDS.map(({ token, label }) => ({\n id: `color.${token}` as const,\n label,\n kind: 'color' as const,\n perScheme: true,\n token,\n })),\n {\n id: 'fontFamily',\n label: FONT_FAMILY_FIELD.label,\n kind: 'select',\n perScheme: false,\n options: [SYSTEM_FONT_VALUE, ...GOOGLE_FONT_OPTIONS.map((option) => option.family)],\n },\n {\n id: 'borderRadius',\n label: BORDER_RADIUS_FIELD.label,\n kind: 'number',\n perScheme: false,\n min: BORDER_RADIUS_FIELD.min,\n max: BORDER_RADIUS_FIELD.max,\n step: BORDER_RADIUS_FIELD.step,\n },\n {\n id: 'spacing',\n label: SPACING_FIELD.label,\n kind: 'number',\n perScheme: false,\n min: SPACING_FIELD.min,\n max: SPACING_FIELD.max,\n step: SPACING_FIELD.step,\n },\n {\n id: 'navHeight.xs',\n label: TOOLBAR_HEIGHT_FIELDS.xs.label,\n kind: 'number',\n perScheme: false,\n min: TOOLBAR_HEIGHT_FIELDS.xs.min,\n max: TOOLBAR_HEIGHT_FIELDS.xs.max,\n step: TOOLBAR_HEIGHT_FIELDS.xs.step,\n },\n {\n id: 'navHeight.sm',\n label: TOOLBAR_HEIGHT_FIELDS.sm.label,\n kind: 'number',\n perScheme: false,\n min: TOOLBAR_HEIGHT_FIELDS.sm.min,\n max: TOOLBAR_HEIGHT_FIELDS.sm.max,\n step: TOOLBAR_HEIGHT_FIELDS.sm.step,\n },\n {\n id: 'components',\n label: COMPONENT_OVERRIDES_FIELD.label,\n kind: 'components',\n perScheme: false,\n options: COMPONENT_OVERRIDES_FIELD.components,\n },\n]\n\n/** The catalog entry for a control id. */\nexport function themeEditorControl(id: ThemeEditorControlId): ThemeEditorControl {\n const control = THEME_EDITOR_CONTROLS.find((entry) => entry.id === id)\n if (!control) throw new Error(`unknown theme editor control ${id}`)\n return control\n}\n\n/* ------------------------------------------------------------------------ *\n * Reads and writes, exactly as the editor performs them\n * ------------------------------------------------------------------------ */\n\nfunction setSchemeValue(\n theme: HostTheme,\n scheme: HostThemeScheme,\n update: (colors: HostThemeSchemeColors) => HostThemeSchemeColors,\n): HostTheme {\n const colors = theme.colorSchemes?.[scheme] ?? {}\n return {\n ...theme,\n colorSchemes: { ...theme.colorSchemes, [scheme]: update(colors) },\n }\n}\n\n/** A color the site set for one scheme; `undefined` when the slot inherits. */\nexport function readThemeColor(\n theme: HostTheme | undefined,\n scheme: HostThemeScheme,\n token: ThemeColorToken,\n): string | undefined {\n const colors = theme?.colorSchemes?.[scheme]\n if (token === 'divider') return colors?.divider\n const [group, key] = token.split('.')\n if (!key) return colors?.[group as PaletteColorKey]?.main\n return getSchemeColor(colors, [group, key] as SurfaceColorPath)\n}\n\n/**\n * Sets one color for one scheme, or clears it with `undefined` so the slot\n * inherits again. A palette color writes a record of `main` alone: its\n * `light`, `dark` and `contrastText` were derived from (or authored for) the\n * old `main`, and the editor offers no control for them, so a kept shade\n * would go on painting the old color (an outlined button reads `dark`) with\n * no way for the owner to see or change it. Dropped, the theme derives them\n * from the new `main`. Clearing it drops the record; a group member that\n * leaves its group empty drops the group.\n */\nexport function writeThemeColor(\n theme: HostTheme,\n scheme: HostThemeScheme,\n token: ThemeColorToken,\n hex: string | undefined,\n): HostTheme {\n return setSchemeValue(theme, scheme, (colors) => {\n const next: HostThemeSchemeColors = { ...colors }\n if (token === 'divider') {\n if (hex) next.divider = hex\n else delete next.divider\n return next\n }\n const [group, key] = token.split('.')\n if (!key) {\n const paletteKey = group as PaletteColorKey\n if (hex) next[paletteKey] = { main: hex }\n else delete next[paletteKey]\n return next\n }\n const groupKey = group as 'background' | 'text' | 'tint'\n const groupValue = {\n ...(colors[groupKey] as Record<string, string> | undefined),\n }\n if (hex) groupValue[key] = hex\n else delete groupValue[key]\n const grouped = { ...next, [groupKey]: groupValue } as HostThemeSchemeColors\n if (!Object.keys(groupValue).length) delete grouped[groupKey]\n return grouped\n })\n}\n\n/** Replaces one scheme's colors with a copy of the other's. */\nexport function copyThemeSchemeColors(\n theme: HostTheme,\n from: HostThemeScheme,\n to: HostThemeScheme,\n): HostTheme {\n const source = theme.colorSchemes?.[from]\n if (!source) return theme\n return {\n ...theme,\n colorSchemes: {\n ...theme.colorSchemes,\n [to]: JSON.parse(JSON.stringify(source)),\n },\n }\n}\n\n/** The dark scheme switch as the select shows it. */\nexport function readDarkScheme(theme: HostTheme | undefined): ThemeDarkSchemeValue {\n return theme?.darkScheme === 'off' ? 'off' : 'auto'\n}\n\n/**\n * Absent means \"follows the visitor\"; only the opt-out is written, so the\n * saved document stays empty for the common case.\n */\nexport function writeDarkScheme(\n theme: HostTheme,\n value: ThemeDarkSchemeValue,\n): HostTheme {\n const next: HostTheme = { ...theme }\n if (value === 'off') next.darkScheme = 'off'\n else delete next.darkScheme\n return next\n}\n\n/** The font select's value: the site's font, or {@link SYSTEM_FONT_VALUE}. */\nexport function readFontFamily(theme: HostTheme | undefined): string {\n return readThemeFonts(theme).body?.family ?? SYSTEM_FONT_VALUE\n}\n\n/**\n * Picks a font from {@link GOOGLE_FONT_OPTIONS}, loading it and naming it as\n * the typography's stack, or {@link SYSTEM_FONT_VALUE} to go back to the\n * theme default. A family outside the curated list changes nothing.\n */\nexport function writeFontFamily(theme: HostTheme, value: string): HostTheme {\n // Through writeThemeFonts (AGL-3656), so a heading font and the site's own\n // uploaded fonts survive a body font picked from the short list or by the\n // AI theme step; replacing `fonts` wholesale dropped both.\n const current = readThemeFonts(theme)\n if (value === SYSTEM_FONT_VALUE) {\n return writeThemeFonts(theme, { body: null, heading: current.heading })\n }\n const option = GOOGLE_FONT_OPTIONS.find((entry) => entry.family === value)\n if (!option) return theme\n return writeThemeFonts(theme, {\n body: {\n family: option.family,\n category: option.category,\n weights: option.weights,\n source: 'google',\n },\n heading: current.heading,\n })\n}\n\n/**\n * The text styles a separate heading font is set on: `h1`…`h6`, and\n * `displayXl`, the platform's rung above `h1`, which a heading font left off\n * would draw in the body font — and load the body font's heaviest weight for.\n */\nexport const THEME_HEADING_VARIANTS: readonly HostThemeTypographyVariantKey[] = [\n 'displayXl',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n]\n\n/**\n * One family a theme sets text in, as the font picker shows and writes it\n * (AGL-3656): a `fonts` entry and the role it plays.\n */\nexport interface ThemeFontChoice {\n family: string\n category: HostThemeFontCategory\n /** Upright weights to load, ascending. */\n weights: number[]\n /** Italic weights to load, ascending; absent or empty for none. */\n italics?: number[]\n source: 'google' | 'custom'\n}\n\n/**\n * The theme's body font and, when it differs, its heading font. `null` is the\n * theme default: the base stack, nothing loaded.\n */\nexport interface ThemeFontSelection {\n body: ThemeFontChoice | null\n heading: ThemeFontChoice | null\n}\n\n/** The first family a CSS font-family stack names, unquoted. */\nexport function firstStackFamily(stack: unknown): string | undefined {\n if (typeof stack !== 'string') return undefined\n const first = stack.split(',')[0]?.trim().replace(/^[\"']|[\"']$/g, '').trim()\n return first || undefined\n}\n\n/** The category a stack's generic keyword names, for a font that records none. */\nfunction stackCategory(stack: unknown): HostThemeFontCategory {\n if (typeof stack !== 'string') return 'sans-serif'\n if (/\\bmonospace\\b/i.test(stack)) return 'monospace'\n if (/(^|,)\\s*serif\\b/i.test(stack)) return 'serif'\n return 'sans-serif'\n}\n\nfunction sortedWeights(values: readonly unknown[] | undefined): number[] {\n return [\n ...new Set(\n (values ?? [])\n .map((value) => Math.round(Number(value)))\n .filter((value) => Number.isFinite(value) && value >= 1 && value <= 1000),\n ),\n ].sort((a, b) => a - b)\n}\n\nfunction choiceOf(font: HostThemeFont, stack: unknown): ThemeFontChoice {\n const italics = sortedWeights(font.italics)\n return {\n family: font.family.trim(),\n category: font.category ?? stackCategory(stack),\n weights: sortedWeights(font.weights).length ? sortedWeights(font.weights) : [400],\n ...(italics.length ? { italics } : {}),\n source: font.source === 'custom' ? 'custom' : 'google',\n }\n}\n\nfunction findFont(theme: HostTheme | undefined, family: string | undefined) {\n if (!family) return undefined\n const wanted = family.toLowerCase()\n return theme?.fonts?.find(\n (font) =>\n font.family?.trim().toLowerCase() === wanted && (font.source ?? 'google') !== 'system',\n )\n}\n\n/**\n * The body and heading fonts a theme sets text in (AGL-3656).\n *\n * The body font is the family the theme-wide stack names first, when the\n * theme loads it: a font the theme lists that no stack names draws nothing,\n * which is what the theme default is. The heading font is the family `h1`\n * names, when that is a loaded font other than the body's.\n */\nexport function readThemeFonts(theme: HostTheme | undefined): ThemeFontSelection {\n const stack = theme?.typography?.fontFamily\n const bodyFont = findFont(theme, firstStackFamily(stack))\n const headingStack = theme?.typography?.variants?.h1?.fontFamily\n const headingFont = findFont(theme, firstStackFamily(headingStack))\n return {\n body: bodyFont ? choiceOf(bodyFont, stack) : null,\n heading:\n headingFont && headingFont !== bodyFont ? choiceOf(headingFont, headingStack) : null,\n }\n}\n\nfunction fontEntry(choice: ThemeFontChoice): HostThemeFont {\n const italics = sortedWeights(choice.italics)\n return {\n family: choice.family.trim(),\n weights: sortedWeights(choice.weights).length ? sortedWeights(choice.weights) : [400],\n ...(italics.length ? { italics } : {}),\n source: choice.source,\n category: choice.category,\n }\n}\n\n/**\n * Sets the theme's body and heading fonts (AGL-3656): the `fonts` entries the\n * page loads, the theme-wide stack, and the stack of each style in\n * {@link THEME_HEADING_VARIANTS} for a heading font of its own. `null` goes\n * back to the theme default for that role.\n *\n * An uploaded (`custom`) font the theme lists but no longer sets text in is\n * kept, because it is the site's own and is picked again from the list; a\n * Google font nothing sets text in any more is dropped, so the page stops\n * loading it. Everything else in the typography — sizes, weights, a variant's own\n * family that is not a heading — is left as it was.\n */\nexport function writeThemeFonts(theme: HostTheme, selection: ThemeFontSelection): HostTheme {\n const body = selection.body\n const heading =\n selection.heading &&\n (!body || selection.heading.family.toLowerCase() !== body.family.toLowerCase())\n ? selection.heading\n : null\n const previous = readThemeFonts(theme)\n const previousHeadingStack = previous.heading\n ? theme.typography?.variants?.h1?.fontFamily\n : undefined\n\n const chosen = [body, heading].filter((entry): entry is ThemeFontChoice => !!entry)\n const chosenKeys = new Set(chosen.map((entry) => entry.family.trim().toLowerCase()))\n // Families a text style other than a heading still names, by hand or by\n // an earlier editor: they keep loading, as their style keeps drawing them.\n const otherStyles = new Set(\n Object.entries(theme.typography?.variants ?? {})\n .filter(([key]) => !(THEME_HEADING_VARIANTS as readonly string[]).includes(key))\n .map(([, variant]) => firstStackFamily(variant?.fontFamily)?.toLowerCase())\n .filter((family): family is string => !!family),\n )\n const kept = (theme.fonts ?? []).filter((font) => {\n const key = font.family?.trim().toLowerCase() ?? ''\n if (!key || chosenKeys.has(key)) return false\n return font.source === 'custom' || otherStyles.has(key)\n })\n const fonts = [...chosen.map(fontEntry), ...kept]\n\n const typography = { ...theme.typography }\n if (body) typography.fontFamily = fontFamilyStack(body.family.trim(), body.category)\n else delete typography.fontFamily\n\n const variants = { ...typography.variants }\n for (const key of THEME_HEADING_VARIANTS) {\n const variant = { ...variants[key] }\n if (heading) {\n variant.fontFamily = fontFamilyStack(heading.family.trim(), heading.category)\n } else if (\n variant.fontFamily !== undefined &&\n (variant.fontFamily === previousHeadingStack ||\n !findFont({ fonts }, firstStackFamily(variant.fontFamily)))\n ) {\n // The heading font this theme had, or a family it no longer loads.\n delete variant.fontFamily\n }\n if (Object.keys(variant).length) variants[key] = variant\n else delete variants[key]\n }\n if (Object.keys(variants).length) typography.variants = variants\n else delete typography.variants\n\n const next: HostTheme = { ...theme }\n if (fonts.length) next.fonts = fonts\n else delete next.fonts\n if (Object.keys(typography).length) next.typography = typography\n else delete next.typography\n return next\n}\n\n/** Sets the corner radius, or clears it with `undefined` so it inherits. */\nexport function writeBorderRadius(\n theme: HostTheme,\n value: number | undefined,\n): HostTheme {\n if (value !== undefined && Number.isFinite(value)) {\n return { ...theme, shape: { ...theme.shape, borderRadius: value } }\n }\n const next = { ...theme }\n const shape = { ...next.shape }\n delete shape.borderRadius\n if (Object.keys(shape).length) next.shape = shape\n else delete next.shape\n return next\n}\n\n/** Sets the spacing unit; anything but a positive number clears it. */\nexport function writeSpacing(theme: HostTheme, value: number | undefined): HostTheme {\n const next = { ...theme }\n if (value !== undefined && Number.isFinite(value) && value > 0) next.spacing = value\n else delete next.spacing\n return next\n}\n\n/**\n * Sets one nav height — anything but a positive number clears it — and\n * rebuilds the whole toolbar mixin around both, because `mixins.toolbar`\n * replaces MUI's default rather than merging into it (AGL-1242).\n */\nexport function writeToolbarHeight(\n theme: HostTheme,\n breakpoint: 'xs' | 'sm',\n value: number | undefined,\n): HostTheme {\n const valid = value !== undefined && Number.isFinite(value) && value > 0\n const edited = valid ? value : undefined\n const xs = breakpoint === 'xs' ? edited : readToolbarHeight(theme, 'xs')\n const sm = breakpoint === 'sm' ? edited : readToolbarHeight(theme, 'sm')\n const next = { ...theme }\n if (xs === undefined && sm === undefined) {\n delete next.mixins\n return next\n }\n next.mixins = { toolbar: buildToolbarMixin(xs, sm) }\n return next\n}\n\n/**\n * Drops the site's component overrides. With nothing stored the site renders\n * the brand's own component styles, which is what the editor's \"Reset to\n * theme defaults\" means.\n */\nexport function resetComponentOverrides(theme: HostTheme): HostTheme {\n const next = { ...theme }\n delete next.components\n return next\n}\n\n/** One leaf of a component override, as a writer names it. */\nexport interface ThemeComponentOverrideLeaf {\n component: HostThemeComponentKey\n /**\n * `styleOverrides` styles a slot in literal CSS; `sx` styles it in theme\n * terms, so a value may name a palette path (`primary.main`) or a spacing\n * unit (AGL-3403); `defaultProps` sets a prop's default.\n */\n target: 'styleOverrides' | 'sx' | 'defaultProps'\n /** The style slot (`root`, `contained`, `h1`); `null` for a default prop. */\n slot: string | null\n /** A camelCase CSS property, or the prop's name. */\n property: string\n /** Scopes a style to one side of the toolbar breakpoint; `null` for every width. */\n media: ThemeEditorMedia | null\n value: string | number | boolean\n}\n\n/**\n * Sets one leaf inside the site's component overrides and keeps every other\n * override the site has. The stored overrides are deep-merged over the\n * brand's own at render time, so naming one property changes that property\n * and inherits the rest of the component.\n */\nexport function writeComponentOverride(\n theme: HostTheme,\n leaf: ThemeComponentOverrideLeaf,\n): HostTheme {\n const components = { ...theme.components }\n const entry: HostThemeComponentOverride = { ...components[leaf.component] }\n if (leaf.target === 'defaultProps') {\n entry.defaultProps = { ...entry.defaultProps, [leaf.property]: leaf.value }\n } else {\n const slot = leaf.slot ?? 'root'\n const styles: Record<string, unknown> = {\n ...(leaf.target === 'sx' ? entry.sx : entry.styleOverrides),\n }\n const slotStyles = { ...(styles[slot] as Record<string, unknown> | undefined) }\n if (leaf.media) {\n const query = THEME_EDITOR_MEDIA_QUERIES[leaf.media]\n slotStyles[query] = {\n ...(slotStyles[query] as Record<string, unknown> | undefined),\n [leaf.property]: leaf.value,\n }\n } else {\n slotStyles[leaf.property] = leaf.value\n }\n styles[slot] = slotStyles\n if (leaf.target === 'sx') {\n entry.sx = styles as HostThemeComponentOverride['sx']\n } else {\n entry.styleOverrides = styles\n }\n }\n components[leaf.component] = entry\n return { ...theme, components }\n}\n\n/** Where one leaf lives, without the value it holds. */\nexport type ThemeComponentOverrideTarget = Omit<ThemeComponentOverrideLeaf, 'value'>\n\n/**\n * Removes one leaf from the site's component overrides, and every slot,\n * branch and component it leaves empty, so a field set back to \"Theme\n * default\" stores nothing and the site inherits that property again.\n */\nexport function clearComponentOverride(\n theme: HostTheme,\n target: ThemeComponentOverrideTarget,\n): HostTheme {\n const existing = theme.components?.[target.component]\n if (!existing) return theme\n const entry: HostThemeComponentOverride = { ...existing }\n if (target.target === 'defaultProps') {\n const props = { ...entry.defaultProps }\n delete props[target.property]\n if (Object.keys(props).length) entry.defaultProps = props\n else delete entry.defaultProps\n } else {\n const branch = target.target === 'sx' ? 'sx' : 'styleOverrides'\n const styles: Record<string, unknown> = { ...entry[branch] }\n const slot = target.slot ?? 'root'\n const slotStyles = { ...(styles[slot] as Record<string, unknown> | undefined) }\n if (target.media) {\n const query = THEME_EDITOR_MEDIA_QUERIES[target.media]\n const scoped = { ...(slotStyles[query] as Record<string, unknown> | undefined) }\n delete scoped[target.property]\n if (Object.keys(scoped).length) slotStyles[query] = scoped\n else delete slotStyles[query]\n } else {\n delete slotStyles[target.property]\n }\n if (Object.keys(slotStyles).length) styles[slot] = slotStyles\n else delete styles[slot]\n if (Object.keys(styles).length) {\n if (branch === 'sx') entry.sx = styles as HostThemeComponentOverride['sx']\n else entry.styleOverrides = styles\n } else {\n delete entry[branch]\n }\n }\n const components = { ...theme.components }\n if (Object.keys(entry).length) components[target.component] = entry\n else delete components[target.component]\n const next: HostTheme = { ...theme }\n if (Object.keys(components).length) next.components = components\n else delete next.components\n return next\n}\n\n/** The value one override leaf holds; `undefined` when the site does not set it. */\nexport function readComponentOverride(\n theme: HostTheme | undefined,\n target: ThemeComponentOverrideTarget,\n): unknown {\n const entry = theme?.components?.[target.component]\n if (!entry) return undefined\n if (target.target === 'defaultProps') return entry.defaultProps?.[target.property]\n const styles = (target.target === 'sx' ? entry.sx : entry.styleOverrides) as\n | Record<string, unknown>\n | undefined\n const slotStyles = styles?.[target.slot ?? 'root'] as Record<string, unknown> | undefined\n if (!target.media) return slotStyles?.[target.property]\n const query = THEME_EDITOR_MEDIA_QUERIES[target.media]\n return (slotStyles?.[query] as Record<string, unknown> | undefined)?.[target.property]\n}\n\n/* ------------------------------------------------------------------------ *\n * The look of components, as click-only fields\n * ------------------------------------------------------------------------ */\n\n/** The components the Style components card sets a site-wide look for. */\nexport type ThemeComponentLookGroup = 'button' | 'input' | 'card'\n\nexport const THEME_COMPONENT_LOOK_GROUPS: ReadonlyArray<{\n group: ThemeComponentLookGroup\n label: string\n}> = [\n { group: 'button', label: 'Buttons' },\n { group: 'input', label: 'Form inputs' },\n { group: 'card', label: 'Cards' },\n]\n\nexport type ThemeComponentLookId =\n | 'button.variant'\n | 'button.corners'\n | 'button.textCase'\n | 'button.weight'\n | 'button.padding'\n | 'input.variant'\n | 'input.corners'\n | 'input.background'\n | 'input.border'\n | 'card.variant'\n | 'card.elevation'\n | 'card.corners'\n\n/** One choice a look field offers. */\nexport interface ThemeComponentLookOption {\n /** What the select holds. */\n value: string\n label: string\n /**\n * What each of the field's targets stores, in target order; one value\n * stands for every target.\n */\n stored: string | number | ReadonlyArray<string | number>\n /** A theme color this choice draws in, for its swatch. */\n token?: ThemeColorToken\n}\n\n/**\n * A click-only field over the site's component overrides. Each choice writes\n * the same leaves the Advanced overrides hold, so the two are one setting\n * seen two ways, and anything that writes override leaves can set it.\n */\nexport interface ThemeComponentLookField {\n id: ThemeComponentLookId\n group: ThemeComponentLookGroup\n label: string\n /** `color` choices are theme colors, shown as swatches of the scheme in view. */\n kind: 'select' | 'color'\n /** The leaves a choice sets, read back from the first. */\n targets: readonly ThemeComponentOverrideTarget[]\n /** Leaves set alongside any choice and cleared with it: what makes the choice draw right. */\n companions?: readonly ThemeComponentOverrideLeaf[]\n options: readonly ThemeComponentLookOption[]\n}\n\n/** The select's value for a field the site does not set: the theme's own look. */\nexport const THEME_LOOK_DEFAULT = ''\n/** The select's value for a leaf set to something no choice names, by hand or by AI. */\nexport const THEME_LOOK_CUSTOM = '__custom__'\n\nfunction lookTarget(\n component: HostThemeComponentKey,\n target: ThemeComponentOverrideLeaf['target'],\n property: string,\n slot: string | null = target === 'defaultProps' ? null : 'root',\n): ThemeComponentOverrideTarget {\n return { component, target, slot, property, media: null }\n}\n\n/**\n * Corner choices, as multiples of the site's Border radius (an `sx`\n * `borderRadius` number is one), so a component follows the Shape & spacing\n * slider instead of freezing a pixel value.\n */\nconst CORNER_OPTIONS: readonly ThemeComponentLookOption[] = [\n { value: 'square', label: 'Square', stored: 0 },\n { value: 'subtle', label: 'Half the site radius', stored: 0.5 },\n { value: 'site', label: 'The site radius', stored: 1 },\n { value: 'rounded', label: 'Twice the site radius', stored: 2 },\n { value: 'extra', label: 'Three times the site radius', stored: 3 },\n]\nconst PILL_OPTION: ThemeComponentLookOption = { value: 'pill', label: 'Pill', stored: '999px' }\n\n/**\n * Every component look field, in the order the card shows them.\n *\n * Inputs style both of MUI's boxes: `MuiOutlinedInput` and `MuiFilledInput`,\n * because the Input style choice picks between them and the other choices\n * have to hold whichever is in use. A border color sets the outlined box's\n * own border, which the Besigner's Input element draws, and the notched\n * outline a stock text field draws.\n */\nexport const THEME_COMPONENT_LOOK_FIELDS: readonly ThemeComponentLookField[] = [\n {\n id: 'button.variant',\n group: 'button',\n label: 'Button style',\n kind: 'select',\n targets: [lookTarget('MuiButton', 'defaultProps', 'variant')],\n options: [\n { value: 'contained', label: 'Filled', stored: 'contained' },\n { value: 'outlined', label: 'Outlined', stored: 'outlined' },\n { value: 'text', label: 'Text only', stored: 'text' },\n ],\n },\n {\n id: 'button.corners',\n group: 'button',\n label: 'Button corners',\n kind: 'select',\n targets: [lookTarget('MuiButton', 'sx', 'borderRadius')],\n options: [...CORNER_OPTIONS, PILL_OPTION],\n },\n {\n id: 'button.textCase',\n group: 'button',\n label: 'Button text case',\n kind: 'select',\n targets: [lookTarget('MuiButton', 'styleOverrides', 'textTransform')],\n options: [\n { value: 'none', label: 'As typed', stored: 'none' },\n { value: 'uppercase', label: 'UPPERCASE', stored: 'uppercase' },\n { value: 'capitalize', label: 'Capitalize Each Word', stored: 'capitalize' },\n ],\n },\n {\n id: 'button.weight',\n group: 'button',\n label: 'Button text weight',\n kind: 'select',\n targets: [lookTarget('MuiButton', 'styleOverrides', 'fontWeight')],\n options: [\n { value: '400', label: 'Regular', stored: 400 },\n { value: '500', label: 'Medium', stored: 500 },\n { value: '600', label: 'Semibold', stored: 600 },\n { value: '700', label: 'Bold', stored: 700 },\n ],\n },\n {\n id: 'button.padding',\n group: 'button',\n label: 'Button padding',\n kind: 'select',\n // Spacing units, so padding follows the site's Spacing unit.\n targets: [lookTarget('MuiButton', 'sx', 'px'), lookTarget('MuiButton', 'sx', 'py')],\n options: [\n { value: 'compact', label: 'Compact', stored: [1.5, 0.5] },\n { value: 'comfortable', label: 'Comfortable', stored: [2, 0.75] },\n { value: 'roomy', label: 'Roomy', stored: [3, 1] },\n { value: 'wide', label: 'Wide', stored: [4, 1.25] },\n ],\n },\n {\n id: 'input.variant',\n group: 'input',\n label: 'Input style',\n kind: 'select',\n targets: [lookTarget('MuiTextField', 'defaultProps', 'variant')],\n options: [\n { value: 'outlined', label: 'Outlined', stored: 'outlined' },\n { value: 'filled', label: 'Filled', stored: 'filled' },\n ],\n },\n {\n id: 'input.corners',\n group: 'input',\n label: 'Input corners',\n kind: 'select',\n targets: [\n lookTarget('MuiOutlinedInput', 'sx', 'borderRadius'),\n lookTarget('MuiFilledInput', 'sx', 'borderRadius'),\n ],\n // A filled box's underline runs edge to edge; clipping it to the corners\n // keeps it inside a rounded box.\n companions: [{ ...lookTarget('MuiFilledInput', 'styleOverrides', 'overflow'), value: 'hidden' }],\n options: [...CORNER_OPTIONS, PILL_OPTION],\n },\n {\n id: 'input.background',\n group: 'input',\n label: 'Input background',\n kind: 'color',\n targets: [\n lookTarget('MuiOutlinedInput', 'sx', 'bgcolor'),\n lookTarget('MuiFilledInput', 'sx', 'bgcolor'),\n ],\n options: [\n { value: 'transparent', label: 'None', stored: 'transparent' },\n { value: 'paper', label: 'Paper', stored: 'background.paper', token: 'background.paper' },\n {\n value: 'background',\n label: 'Background',\n stored: 'background.default',\n token: 'background.default',\n },\n { value: 'tintPrimary', label: 'Primary tint', stored: 'tint.primary', token: 'tint.primary' },\n {\n value: 'tintSecondary',\n label: 'Secondary tint',\n stored: 'tint.secondary',\n token: 'tint.secondary',\n },\n {\n value: 'tintTertiary',\n label: 'Tertiary tint',\n stored: 'tint.tertiary',\n token: 'tint.tertiary',\n },\n ],\n },\n {\n id: 'input.border',\n group: 'input',\n label: 'Input border color',\n kind: 'color',\n targets: [\n lookTarget('MuiOutlinedInput', 'sx', 'borderColor'),\n lookTarget('MuiOutlinedInput', 'sx', 'borderColor', 'notchedOutline'),\n ],\n options: [\n { value: 'divider', label: 'Divider', stored: 'divider', token: 'divider' },\n {\n value: 'textSecondary',\n label: 'Secondary text',\n stored: 'text.secondary',\n token: 'text.secondary',\n },\n { value: 'text', label: 'Text', stored: 'text.primary', token: 'text.primary' },\n { value: 'primary', label: 'Primary', stored: 'primary.main', token: 'primary' },\n { value: 'secondary', label: 'Secondary', stored: 'secondary.main', token: 'secondary' },\n { value: 'tertiary', label: 'Tertiary', stored: 'tertiary.main', token: 'tertiary' },\n ],\n },\n {\n id: 'card.variant',\n group: 'card',\n label: 'Card style',\n kind: 'select',\n targets: [lookTarget('MuiCard', 'defaultProps', 'variant')],\n options: [\n { value: 'elevation', label: 'Shadow', stored: 'elevation' },\n { value: 'outlined', label: 'Outline', stored: 'outlined' },\n ],\n },\n {\n id: 'card.elevation',\n group: 'card',\n label: 'Card shadow depth',\n kind: 'select',\n targets: [lookTarget('MuiCard', 'defaultProps', 'elevation')],\n options: [\n { value: '0', label: 'Flat', stored: 0 },\n { value: '1', label: 'Soft', stored: 1 },\n { value: '3', label: 'Medium', stored: 3 },\n { value: '8', label: 'Strong', stored: 8 },\n ],\n },\n {\n id: 'card.corners',\n group: 'card',\n label: 'Card corners',\n kind: 'select',\n targets: [lookTarget('MuiCard', 'sx', 'borderRadius')],\n options: CORNER_OPTIONS,\n },\n]\n\n/** The catalog entry for a look field id. */\nexport function themeComponentLookField(id: ThemeComponentLookId): ThemeComponentLookField {\n const field = THEME_COMPONENT_LOOK_FIELDS.find((entry) => entry.id === id)\n if (!field) throw new Error(`unknown component look field ${id}`)\n return field\n}\n\nfunction storedFor(option: ThemeComponentLookOption, index: number) {\n return Array.isArray(option.stored)\n ? (option.stored as ReadonlyArray<string | number>)[index]\n : (option.stored as string | number)\n}\n\n/**\n * A look field as its select shows it: the choice the site's overrides hold,\n * {@link THEME_LOOK_DEFAULT} when they set nothing, or\n * {@link THEME_LOOK_CUSTOM} when they set a value no choice names.\n */\nexport function readComponentLook(\n theme: HostTheme | undefined,\n field: ThemeComponentLookField,\n): string {\n const values = field.targets.map((target) => readComponentOverride(theme, target))\n if (values.every((value) => value === undefined)) return THEME_LOOK_DEFAULT\n const match = field.options.find((option) =>\n values.every((value, index) => value === storedFor(option, index)),\n )\n return match ? match.value : THEME_LOOK_CUSTOM\n}\n\n/**\n * Sets a look field to one of its choices, or back to the theme's own look\n * with {@link THEME_LOOK_DEFAULT}, which clears every leaf it sets. Any other\n * value changes nothing.\n */\nexport function writeComponentLook(\n theme: HostTheme,\n field: ThemeComponentLookField,\n value: string,\n): HostTheme {\n if (value === THEME_LOOK_DEFAULT) {\n let next = theme\n for (const target of [...field.targets, ...(field.companions ?? [])]) {\n next = clearComponentOverride(next, target)\n }\n return next\n }\n const option = field.options.find((entry) => entry.value === value)\n if (!option) return theme\n let next = theme\n field.targets.forEach((target, index) => {\n next = writeComponentOverride(next, { ...target, value: storedFor(option, index) })\n })\n for (const companion of field.companions ?? []) next = writeComponentOverride(next, companion)\n return next\n}\n"],"names":["HOST_THEME_COMPONENT_WHITELIST","TOOLBAR_SM_MIN_WIDTH","TOOLBAR_SM_QUERY","DEFAULT_TOOLBAR_XS","DEFAULT_TOOLBAR_SM","TOOLBAR_LANDSCAPE_QUERY","TOOLBAR_LANDSCAPE_RULE","minHeight","readToolbarHeight","theme","breakpoint","toolbar","mixins","undefined","raw","value","parseFloat","String","Number","isFinite","buildToolbarMixin","xs","sm","orderSensitiveKey","JSON","stringify","PALETTE_COLOR_FIELDS","key","label","SURFACE_COLOR_FIELDS","path","TINT_COLOR_FIELDS","DIVIDER_COLOR_FIELD","GOOGLE_FONT_OPTIONS","family","category","weights","fontFamilyStack","fallback","getSchemeColor","colors","group","THEME_EDITOR_SCHEMES","THEME_COLOR_FIELDS","map","token","join","DARK_SCHEME_FIELD","options","SYSTEM_FONT_VALUE","FONT_FAMILY_FIELD","BORDER_RADIUS_FIELD","min","max","step","SPACING_FIELD","TOOLBAR_HEIGHT_FIELDS","COMPONENT_OVERRIDES_FIELD","components","THEME_EDITOR_MEDIA_QUERIES","mobile","desktop","THEME_EDITOR_CONTROLS","id","kind","perScheme","option","themeEditorControl","control","find","entry","Error","setSchemeValue","scheme","update","colorSchemes","readThemeColor","divider","split","main","writeThemeColor","hex","next","paletteKey","groupKey","groupValue","grouped","Object","keys","length","copyThemeSchemeColors","from","to","source","parse","readDarkScheme","darkScheme","writeDarkScheme","readFontFamily","readThemeFonts","body","writeFontFamily","current","writeThemeFonts","heading","THEME_HEADING_VARIANTS","firstStackFamily","stack","first","trim","replace","stackCategory","test","sortedWeights","values","Set","Math","round","filter","sort","a","b","choiceOf","font","italics","findFont","wanted","toLowerCase","fonts","typography","fontFamily","bodyFont","headingStack","variants","h1","headingFont","fontEntry","choice","selection","previous","previousHeadingStack","chosen","chosenKeys","otherStyles","entries","includes","variant","kept","has","writeBorderRadius","shape","borderRadius","writeSpacing","spacing","writeToolbarHeight","valid","edited","resetComponentOverrides","writeComponentOverride","leaf","component","target","defaultProps","property","slot","styles","sx","styleOverrides","slotStyles","media","query","clearComponentOverride","existing","props","branch","scoped","readComponentOverride","THEME_COMPONENT_LOOK_GROUPS","THEME_LOOK_DEFAULT","THEME_LOOK_CUSTOM","lookTarget","CORNER_OPTIONS","stored","PILL_OPTION","THEME_COMPONENT_LOOK_FIELDS","targets","companions","themeComponentLookField","field","storedFor","index","Array","isArray","readComponentLook","every","match","writeComponentLook","forEach","companion"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAWD,SACEA,8BAA8B,QAEzB,kBAAc;AAErB;;;;;;;;;;;;;;;;;;;;CAoBC,GAED;;;;CAIC,GACD,OAAO,MAAMC,uBAAuB,IAAG;AACvC,OAAO,MAAMC,mBAAmB,CAAC,kBAAkB,EAAED,qBAAqB,GAAG,CAAC,CAAA;AAC9E,mEAAmE,GACnE,OAAO,MAAME,qBAAqB,GAAE;AACpC,OAAO,MAAMC,qBAAqB,GAAE;AACpC;;;;CAIC,GACD,OAAO,MAAMC,0BAA0B,yBAAwB;AAC/D,OAAO,MAAMC,yBAAyB;IACpC,mCAAmC;QAAEC,WAAW;IAAG;AACrD,EAAC;AAED,uEAAuE,GACvE,OAAO,SAASC,kBAAkBC,KAAgB,EAAEC,UAAuB;QACzDD,eAKTE;IALP,MAAMA,WAAUF,gBAAAA,MAAMG,MAAM,qBAAZH,cAAcE,OAAO;IACrC,IAAI,CAACA,SAAS,OAAOE;IACrB,MAAMC,MACJJ,eAAe,OACXC,QAAQJ,SAAS,IAChBI,4BAAAA,OAAO,CAACT,iBAAiB,qBAA1B,AAACS,0BACGJ,SAAS;IACnB,MAAMQ,QAAQC,WAAWC,OAAOH,cAAAA,MAAO;IACvC,OAAOI,OAAOC,QAAQ,CAACJ,SAASA,QAAQF;AAC1C;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASO,kBAAkBC,EAAsB,EAAEC,EAAsB;IAC9E,OAAO;QACLf,WAAW,GAAGc,aAAAA,KAAMlB,mBAAmB,EAAE,CAAC;QAC1C,CAACE,wBAAwB,EAAEC;QAC3B,CAACJ,iBAAiB,EAAE;YAAEK,WAAW,GAAGe,aAAAA,KAAMlB,mBAAmB,EAAE,CAAC;QAAC;IACnE;AACF;AAEA;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASmB,kBAAkBd,KAAgB;QAC1B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K,UAAUmK,oBAAoB;YAEYU;QAD5C,IAAI1G,OAAOzE;QACX,KAAK,MAAMwJ,UAAU;eAAI2B,MAAMH,OAAO;gBAAMG,qBAAAA,MAAMF,UAAU,YAAhBE,qBAAoB,EAAE;SAAE,CAAE;YACpE1G,OAAOyF,uBAAuBzF,MAAM+E;QACtC;QACA,OAAO/E;IACT;IACA,MAAMhB,SAAS0H,MAAM5I,OAAO,CAACqB,IAAI,CAAC,CAACC,QAAUA,MAAMvD,KAAK,KAAKA;IAC7D,IAAI,CAACmD,QAAQ,OAAOzD;IACpB,IAAIyE,OAAOzE;IACXmL,MAAMH,OAAO,CAACY,OAAO,CAAC,CAACpC,QAAQ6B;QAC7B5G,OAAO4E,uBAAuB5E,MAAM,aAAK+E;YAAQlJ,OAAO8K,UAAU3H,QAAQ4H;;IAC5E;IACA,KAAK,MAAMQ,cAAaV,oBAAAA,MAAMF,UAAU,YAAhBE,oBAAoB,EAAE,CAAE1G,OAAO4E,uBAAuB5E,MAAMoH;IACpF,OAAOpH;AACT"}
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/ui/theme/src/lib/util/theme-editor-fields.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n HostTheme,\n HostThemeComponentOverride,\n HostThemeFont,\n HostThemeFontCategory,\n HostThemeTypographyVariantKey,\n HostThemeScheme,\n HostThemeSchemeColors,\n} from '@aglyn/shared-data-types'\nimport {\n HOST_THEME_COMPONENT_WHITELIST,\n type HostThemeComponentKey,\n} from './host-theme'\n\n/**\n * The host theme editor's field catalog (AGL-2938): every control the editor\n * renders, the range each one accepts, the token it writes, and the write\n * itself.\n *\n * It lives here rather than beside the editor because the editor is not the\n * only thing that changes a site's theme. Anything that proposes a theme\n * change has to offer exactly the controls the editor offers, with the same\n * bounds, and has to write each one the way the editor writes it. A copy of\n * this list anywhere else is a second answer to \"what can a theme hold\" that\n * drifts from the first the day a control is added, so the editor renders\n * from this module and every other writer reads it.\n *\n * Pure data and pure functions over `HostTheme`: no MUI, no React and no\n * brand theme. What a control resolves to when the site sets nothing is the\n * brand theme's business, in `theme-editor-defaults.ts`.\n *\n * Deliberately NOT re-exported from this library's index: the index reaches\n * every published page, and nothing a visitor renders needs the catalog.\n * Reach it as `@aglyn/shared-ui-theme/util/theme-editor-fields`.\n */\n\n/**\n * MUI's own toolbar breakpoint. `mixins.toolbar` has to carry this exact\n * query, because the rule it competes with is MUI's `@media (min-width:600px)\n * { min-height: 64px }` (AGL-1242).\n */\nexport const TOOLBAR_SM_MIN_WIDTH = 600\nexport const TOOLBAR_SM_QUERY = `@media (min-width:${TOOLBAR_SM_MIN_WIDTH}px)`\n/** MUI's stock Toolbar heights, shown when the host has set none. */\nexport const DEFAULT_TOOLBAR_XS = 56\nexport const DEFAULT_TOOLBAR_SM = 64\n/**\n * `createMixins` spreads `...mixins` AFTER its default, so anything we write\n * REPLACES the stock toolbar wholesale — including its short-landscape rule.\n * Carrying it forward keeps that behavior instead of dropping it silently.\n */\nexport const TOOLBAR_LANDSCAPE_QUERY = '@media (min-width:0px)'\nexport const TOOLBAR_LANDSCAPE_RULE = {\n '@media (orientation: landscape)': { minHeight: 48 },\n}\n\n/** Reads a px `minHeight` out of `mixins.toolbar` for one breakpoint. */\nexport function readToolbarHeight(theme: HostTheme, breakpoint: 'xs' | 'sm') {\n const toolbar = theme.mixins?.toolbar\n if (!toolbar) return undefined\n const raw =\n breakpoint === 'xs'\n ? toolbar.minHeight\n : (toolbar[TOOLBAR_SM_QUERY] as { minHeight?: unknown } | undefined)\n ?.minHeight\n const value = parseFloat(String(raw ?? ''))\n return Number.isFinite(value) ? value : undefined\n}\n\n/**\n * Builds a COMPLETE `mixins.toolbar`, in the order MUI emits it.\n *\n * Two things this exists to get right, both because `mixins.toolbar` replaces\n * MUI's default wholesale rather than merging into it (AGL-1242):\n *\n * - **Completeness.** Anything omitted is simply gone. Writing only a desktop\n * height left portrait phones with no `min-height` at all, so unset\n * breakpoints fall back to MUI's own 56 / 64.\n * - **Key order.** These land in one CSS rule, so the last matching\n * declaration wins. MUI emits the landscape clause BEFORE the sm height;\n * emitting it after makes a wide landscape window — i.e. every desktop —\n * 48px tall.\n */\nexport function buildToolbarMixin(xs: number | undefined, sm: number | undefined) {\n return {\n minHeight: `${xs ?? DEFAULT_TOOLBAR_XS}px`,\n [TOOLBAR_LANDSCAPE_QUERY]: TOOLBAR_LANDSCAPE_RULE,\n [TOOLBAR_SM_QUERY]: { minHeight: `${sm ?? DEFAULT_TOOLBAR_SM}px` },\n }\n}\n\n/**\n * Serializes the branches whose KEY ORDER changes what renders.\n *\n * `deepEqual` is order-INsensitive on purpose (AGL-56: Firestore hands the\n * palette back in a different key order than the editor builds it, and a\n * string compare left Save enabled forever), so on its own it cannot see a\n * reorder of `mixins.toolbar` — a change that really does alter the CSS.\n *\n * Deliberately narrow: only `mixins`. `components.*.styleOverrides` are CSS\n * objects too, but widening this would re-expose the AGL-56 failure for every\n * host with component overrides, and order-sensitivity has only actually been\n * demonstrated here.\n *\n * Firestore does NOT hand a map back in the order it was written, and it\n * hands different readers different orders (AGL-3146) — which is why what\n * renders is canonicalized in `hostThemeToThemeOptions` rather than trusted\n * from storage. A freshly-loaded document is still not dirty here, because\n * the draft is seeded from the loaded document itself: both sides of this\n * comparison carry whatever order THIS reader was given.\n */\nexport function orderSensitiveKey(theme: HostTheme): string {\n return JSON.stringify(theme.mixins ?? {})\n}\n\nexport type PaletteColorKey =\n | 'primary'\n | 'secondary'\n | 'tertiary'\n | 'surface'\n | 'error'\n | 'warning'\n | 'info'\n | 'success'\n\nexport const PALETTE_COLOR_FIELDS: Array<{\n key: PaletteColorKey\n label: string\n}> = [\n { key: 'primary', label: 'Primary' },\n { key: 'secondary', label: 'Secondary' },\n { key: 'tertiary', label: 'Tertiary' },\n { key: 'surface', label: 'Surface' },\n { key: 'error', label: 'Error' },\n { key: 'warning', label: 'Warning' },\n { key: 'info', label: 'Info' },\n { key: 'success', label: 'Success' },\n]\n\nexport type SurfaceColorPath =\n | ['background', 'default']\n | ['background', 'paper']\n | ['text', 'primary']\n | ['text', 'secondary']\n | ['text', 'disabled']\n | ['tint', 'primary']\n | ['tint', 'secondary']\n | ['tint', 'tertiary']\n\nexport const SURFACE_COLOR_FIELDS: Array<{\n path: SurfaceColorPath\n label: string\n}> = [\n { path: ['background', 'default'], label: 'Background' },\n { path: ['background', 'paper'], label: 'Paper' },\n { path: ['text', 'primary'], label: 'Text' },\n { path: ['text', 'secondary'], label: 'Secondary text' },\n { path: ['text', 'disabled'], label: 'Disabled text' },\n]\n\n/**\n * Pale accent washes (AGL-1244).\n *\n * Separate from {@link PALETTE_COLOR_FIELDS} because a tint is a STRING LEAF,\n * not a `{ main }` record — the palette fields all write `main`, and a tint has\n * none. It rides the same `SurfaceColorPath` machinery as `background`/`text`\n * for exactly that reason, and is listed apart only so the editor can head it\n * \"Tints\" instead of filing it under \"Background & text\".\n */\nexport const TINT_COLOR_FIELDS: Array<{\n path: SurfaceColorPath\n label: string\n}> = [\n { path: ['tint', 'primary'], label: 'Primary tint' },\n { path: ['tint', 'secondary'], label: 'Secondary tint' },\n { path: ['tint', 'tertiary'], label: 'Tertiary tint' },\n]\n\n/** The one color leaf that is neither a palette color nor a member of a group. */\nexport const DIVIDER_COLOR_FIELD = { key: 'divider', label: 'Divider' } as const\n\n/** Curated Google Fonts choices for the font family selector. */\nexport const GOOGLE_FONT_OPTIONS: Array<{\n family: string\n category: 'sans-serif' | 'serif' | 'monospace' | 'display'\n weights: Array<number>\n}> = [\n { family: 'Inter', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Roboto', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Open Sans', category: 'sans-serif', weights: [400, 600, 700] },\n { family: 'Lato', category: 'sans-serif', weights: [400, 700] },\n { family: 'Montserrat', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Poppins', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Nunito', category: 'sans-serif', weights: [400, 600, 700] },\n { family: 'Work Sans', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Raleway', category: 'sans-serif', weights: [400, 500, 700] },\n { family: 'Merriweather', category: 'serif', weights: [400, 700] },\n { family: 'Playfair Display', category: 'serif', weights: [400, 700] },\n { family: 'Lora', category: 'serif', weights: [400, 700] },\n { family: 'Source Serif 4', category: 'serif', weights: [400, 700] },\n { family: 'JetBrains Mono', category: 'monospace', weights: [400, 700] },\n { family: 'Bebas Neue', category: 'display', weights: [400] },\n]\n\nexport function fontFamilyStack(\n family: string,\n category: HostThemeFontCategory,\n) {\n const fallback = category === 'monospace' ? 'monospace' : category === 'serif' ? 'serif' : 'sans-serif'\n return `\"${family}\", ${fallback}`\n}\n\nexport function getSchemeColor(\n colors: HostThemeSchemeColors | undefined,\n path: SurfaceColorPath,\n): string | undefined {\n const [group, key] = path\n return (colors?.[group] as Record<string, string> | undefined)?.[key]\n}\n\n/* ------------------------------------------------------------------------ *\n * The controls, as one catalog\n * ------------------------------------------------------------------------ */\n\n/** The two color schemes the editor edits, in tab order. */\nexport const THEME_EDITOR_SCHEMES: readonly HostThemeScheme[] = ['light', 'dark']\n\n/**\n * Every color the editor edits per scheme, named the way a diff names it: a\n * palette key (`primary`), a group path joined with a dot\n * (`background.default`, `tint.primary`), or `divider`.\n */\nexport type ThemeColorToken =\n | PaletteColorKey\n | 'background.default'\n | 'background.paper'\n | 'text.primary'\n | 'text.secondary'\n | 'text.disabled'\n | 'tint.primary'\n | 'tint.secondary'\n | 'tint.tertiary'\n | 'divider'\n\n/** Where a color control sits in the editor's Color scheme card. */\nexport type ThemeColorGroup = 'palette' | 'surface' | 'tint' | 'divider'\n\n/** Every color field the editor renders, in the order it renders them. */\nexport const THEME_COLOR_FIELDS: ReadonlyArray<{\n token: ThemeColorToken\n label: string\n group: ThemeColorGroup\n}> = [\n ...PALETTE_COLOR_FIELDS.map(({ key, label }) => ({\n token: key,\n label,\n group: 'palette' as const,\n })),\n ...SURFACE_COLOR_FIELDS.map(({ path, label }) => ({\n token: path.join('.') as ThemeColorToken,\n label,\n group: 'surface' as const,\n })),\n ...TINT_COLOR_FIELDS.map(({ path, label }) => ({\n token: path.join('.') as ThemeColorToken,\n label,\n group: 'tint' as const,\n })),\n {\n token: DIVIDER_COLOR_FIELD.key,\n label: DIVIDER_COLOR_FIELD.label,\n group: 'divider' as const,\n },\n]\n\n/** Whether visitors get a dark scheme; absent from the document means `auto`. */\nexport type ThemeDarkSchemeValue = 'auto' | 'off'\n\nexport const DARK_SCHEME_FIELD = {\n label: 'Dark scheme',\n options: [\n { value: 'auto', label: 'Follows the visitor' },\n { value: 'off', label: 'Off — always light' },\n ],\n} as const\n\n/**\n * The font select's value for \"no font of the site's own\": the theme's\n * default stack, with nothing to load.\n */\nexport const SYSTEM_FONT_VALUE = '__system__'\n\nexport const FONT_FAMILY_FIELD = { label: 'Font family' } as const\n\n/** The corner radius slider, in px. */\nexport const BORDER_RADIUS_FIELD = {\n label: 'Border radius',\n min: 0,\n max: 24,\n step: 1,\n} as const\n\n/** The spacing unit MUI multiplies every `spacing(n)` by, in px. */\nexport const SPACING_FIELD = {\n label: 'Spacing unit (px)',\n min: 2,\n max: 16,\n step: 1,\n} as const\n\n/** The two nav heights, either side of MUI's toolbar breakpoint, in px. */\nexport const TOOLBAR_HEIGHT_FIELDS = {\n xs: { label: 'Nav height, mobile (px)', min: 40, max: 160, step: 1 },\n sm: { label: 'Nav height, desktop (px)', min: 40, max: 160, step: 1 },\n} as const\n\n/**\n * The site-wide look of components: the click-only fields in\n * {@link THEME_COMPONENT_LOOK_FIELDS}, with the full override set behind\n * them limited to the sanitizer's whitelist.\n */\nexport const COMPONENT_OVERRIDES_FIELD = {\n label: 'Style components',\n components: HOST_THEME_COMPONENT_WHITELIST,\n} as const\n\n/**\n * The media queries a component override may scope a style to: either side\n * of MUI's own toolbar breakpoint, the one breakpoint the editor already\n * names. MUI's `down('sm')` stops a twentieth of a pixel short of it.\n */\nexport const THEME_EDITOR_MEDIA_QUERIES = {\n mobile: `@media (max-width:${TOOLBAR_SM_MIN_WIDTH - 0.05}px)`,\n desktop: TOOLBAR_SM_QUERY,\n} as const\n\nexport type ThemeEditorMedia = keyof typeof THEME_EDITOR_MEDIA_QUERIES\n\nexport type ThemeEditorControlId =\n | `color.${ThemeColorToken}`\n | 'darkScheme'\n | 'fontFamily'\n | 'borderRadius'\n | 'spacing'\n | 'navHeight.xs'\n | 'navHeight.sm'\n | 'components'\n\n/** One control the editor renders, described well enough to be offered elsewhere. */\nexport interface ThemeEditorControl {\n /** Stable id: what a diff row, a proposal and a spec name the control by. */\n id: ThemeEditorControlId\n /** The label the editor shows. */\n label: string\n kind: 'color' | 'select' | 'number' | 'components'\n /** Edited once per scheme, under the Light and Dark tabs. */\n perScheme: boolean\n /** A color control's token. */\n token?: ThemeColorToken\n /** A select's values, or the components a components control may style. */\n options?: readonly string[]\n /** A number control's inclusive bounds and its step. */\n min?: number\n max?: number\n step?: number\n}\n\n/**\n * Every value-bearing control the editor renders, in the order it renders\n * them. The buttons that act on these values rather than hold one — Copy\n * from light, Reset to default, Discard, Save — are not controls: a reset is\n * a control set back to nothing, and a copy is every color control of one\n * scheme written from the other.\n */\nexport const THEME_EDITOR_CONTROLS: readonly ThemeEditorControl[] = [\n {\n id: 'darkScheme',\n label: DARK_SCHEME_FIELD.label,\n kind: 'select',\n perScheme: false,\n options: DARK_SCHEME_FIELD.options.map((option) => option.value),\n },\n ...THEME_COLOR_FIELDS.map(({ token, label }) => ({\n id: `color.${token}` as const,\n label,\n kind: 'color' as const,\n perScheme: true,\n token,\n })),\n {\n id: 'fontFamily',\n label: FONT_FAMILY_FIELD.label,\n kind: 'select',\n perScheme: false,\n options: [SYSTEM_FONT_VALUE, ...GOOGLE_FONT_OPTIONS.map((option) => option.family)],\n },\n {\n id: 'borderRadius',\n label: BORDER_RADIUS_FIELD.label,\n kind: 'number',\n perScheme: false,\n min: BORDER_RADIUS_FIELD.min,\n max: BORDER_RADIUS_FIELD.max,\n step: BORDER_RADIUS_FIELD.step,\n },\n {\n id: 'spacing',\n label: SPACING_FIELD.label,\n kind: 'number',\n perScheme: false,\n min: SPACING_FIELD.min,\n max: SPACING_FIELD.max,\n step: SPACING_FIELD.step,\n },\n {\n id: 'navHeight.xs',\n label: TOOLBAR_HEIGHT_FIELDS.xs.label,\n kind: 'number',\n perScheme: false,\n min: TOOLBAR_HEIGHT_FIELDS.xs.min,\n max: TOOLBAR_HEIGHT_FIELDS.xs.max,\n step: TOOLBAR_HEIGHT_FIELDS.xs.step,\n },\n {\n id: 'navHeight.sm',\n label: TOOLBAR_HEIGHT_FIELDS.sm.label,\n kind: 'number',\n perScheme: false,\n min: TOOLBAR_HEIGHT_FIELDS.sm.min,\n max: TOOLBAR_HEIGHT_FIELDS.sm.max,\n step: TOOLBAR_HEIGHT_FIELDS.sm.step,\n },\n {\n id: 'components',\n label: COMPONENT_OVERRIDES_FIELD.label,\n kind: 'components',\n perScheme: false,\n options: COMPONENT_OVERRIDES_FIELD.components,\n },\n]\n\n/** The catalog entry for a control id. */\nexport function themeEditorControl(id: ThemeEditorControlId): ThemeEditorControl {\n const control = THEME_EDITOR_CONTROLS.find((entry) => entry.id === id)\n if (!control) throw new Error(`unknown theme editor control ${id}`)\n return control\n}\n\n/* ------------------------------------------------------------------------ *\n * Reads and writes, exactly as the editor performs them\n * ------------------------------------------------------------------------ */\n\nfunction setSchemeValue(\n theme: HostTheme,\n scheme: HostThemeScheme,\n update: (colors: HostThemeSchemeColors) => HostThemeSchemeColors,\n): HostTheme {\n const colors = theme.colorSchemes?.[scheme] ?? {}\n return {\n ...theme,\n colorSchemes: { ...theme.colorSchemes, [scheme]: update(colors) },\n }\n}\n\n/** A color the site set for one scheme; `undefined` when the slot inherits. */\nexport function readThemeColor(\n theme: HostTheme | undefined,\n scheme: HostThemeScheme,\n token: ThemeColorToken,\n): string | undefined {\n const colors = theme?.colorSchemes?.[scheme]\n if (token === 'divider') return colors?.divider\n const [group, key] = token.split('.')\n if (!key) return colors?.[group as PaletteColorKey]?.main\n return getSchemeColor(colors, [group, key] as SurfaceColorPath)\n}\n\n/**\n * Sets one color for one scheme, or clears it with `undefined` so the slot\n * inherits again. A palette color writes a record of `main` alone: its\n * `light`, `dark` and `contrastText` were derived from (or authored for) the\n * old `main`, and the editor offers no control for them, so a kept shade\n * would go on painting the old color (an outlined button reads `dark`) with\n * no way for the owner to see or change it. Dropped, the theme derives them\n * from the new `main`. Clearing it drops the record; a group member that\n * leaves its group empty drops the group.\n */\nexport function writeThemeColor(\n theme: HostTheme,\n scheme: HostThemeScheme,\n token: ThemeColorToken,\n hex: string | undefined,\n): HostTheme {\n return setSchemeValue(theme, scheme, (colors) => {\n const next: HostThemeSchemeColors = { ...colors }\n if (token === 'divider') {\n if (hex) next.divider = hex\n else delete next.divider\n return next\n }\n const [group, key] = token.split('.')\n if (!key) {\n const paletteKey = group as PaletteColorKey\n if (hex) next[paletteKey] = { main: hex }\n else delete next[paletteKey]\n // An accent's tint is a wash of its old `main` for the same reason, so\n // it goes too and the theme washes one from the new color.\n const tint = next.tint as Record<string, string> | undefined\n if (tint && paletteKey in tint) {\n const rest = { ...tint }\n delete rest[paletteKey]\n if (Object.keys(rest).length) next.tint = rest as HostThemeSchemeColors['tint']\n else delete next.tint\n }\n return next\n }\n const groupKey = group as 'background' | 'text' | 'tint'\n const groupValue = {\n ...(colors[groupKey] as Record<string, string> | undefined),\n }\n if (hex) groupValue[key] = hex\n else delete groupValue[key]\n const grouped = { ...next, [groupKey]: groupValue } as HostThemeSchemeColors\n if (!Object.keys(groupValue).length) delete grouped[groupKey]\n return grouped\n })\n}\n\n/** Replaces one scheme's colors with a copy of the other's. */\nexport function copyThemeSchemeColors(\n theme: HostTheme,\n from: HostThemeScheme,\n to: HostThemeScheme,\n): HostTheme {\n const source = theme.colorSchemes?.[from]\n if (!source) return theme\n return {\n ...theme,\n colorSchemes: {\n ...theme.colorSchemes,\n [to]: JSON.parse(JSON.stringify(source)),\n },\n }\n}\n\n/** The dark scheme switch as the select shows it. */\nexport function readDarkScheme(theme: HostTheme | undefined): ThemeDarkSchemeValue {\n return theme?.darkScheme === 'off' ? 'off' : 'auto'\n}\n\n/**\n * Absent means \"follows the visitor\"; only the opt-out is written, so the\n * saved document stays empty for the common case.\n */\nexport function writeDarkScheme(\n theme: HostTheme,\n value: ThemeDarkSchemeValue,\n): HostTheme {\n const next: HostTheme = { ...theme }\n if (value === 'off') next.darkScheme = 'off'\n else delete next.darkScheme\n return next\n}\n\n/** The font select's value: the site's font, or {@link SYSTEM_FONT_VALUE}. */\nexport function readFontFamily(theme: HostTheme | undefined): string {\n return readThemeFonts(theme).body?.family ?? SYSTEM_FONT_VALUE\n}\n\n/**\n * Picks a font from {@link GOOGLE_FONT_OPTIONS}, loading it and naming it as\n * the typography's stack, or {@link SYSTEM_FONT_VALUE} to go back to the\n * theme default. A family outside the curated list changes nothing.\n */\nexport function writeFontFamily(theme: HostTheme, value: string): HostTheme {\n // Through writeThemeFonts (AGL-3656), so a heading font and the site's own\n // uploaded fonts survive a body font picked from the short list or by the\n // AI theme step; replacing `fonts` wholesale dropped both.\n const current = readThemeFonts(theme)\n if (value === SYSTEM_FONT_VALUE) {\n return writeThemeFonts(theme, { body: null, heading: current.heading })\n }\n const option = GOOGLE_FONT_OPTIONS.find((entry) => entry.family === value)\n if (!option) return theme\n return writeThemeFonts(theme, {\n body: {\n family: option.family,\n category: option.category,\n weights: option.weights,\n source: 'google',\n },\n heading: current.heading,\n })\n}\n\n/**\n * The text styles a separate heading font is set on: `h1`…`h6`, and\n * `displayXl`, the platform's rung above `h1`, which a heading font left off\n * would draw in the body font — and load the body font's heaviest weight for.\n */\nexport const THEME_HEADING_VARIANTS: readonly HostThemeTypographyVariantKey[] = [\n 'displayXl',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n]\n\n/**\n * One family a theme sets text in, as the font picker shows and writes it\n * (AGL-3656): a `fonts` entry and the role it plays.\n */\nexport interface ThemeFontChoice {\n family: string\n category: HostThemeFontCategory\n /** Upright weights to load, ascending. */\n weights: number[]\n /** Italic weights to load, ascending; absent or empty for none. */\n italics?: number[]\n source: 'google' | 'custom'\n}\n\n/**\n * The theme's body font and, when it differs, its heading font. `null` is the\n * theme default: the base stack, nothing loaded.\n */\nexport interface ThemeFontSelection {\n body: ThemeFontChoice | null\n heading: ThemeFontChoice | null\n}\n\n/** The first family a CSS font-family stack names, unquoted. */\nexport function firstStackFamily(stack: unknown): string | undefined {\n if (typeof stack !== 'string') return undefined\n const first = stack.split(',')[0]?.trim().replace(/^[\"']|[\"']$/g, '').trim()\n return first || undefined\n}\n\n/** The category a stack's generic keyword names, for a font that records none. */\nfunction stackCategory(stack: unknown): HostThemeFontCategory {\n if (typeof stack !== 'string') return 'sans-serif'\n if (/\\bmonospace\\b/i.test(stack)) return 'monospace'\n if (/(^|,)\\s*serif\\b/i.test(stack)) return 'serif'\n return 'sans-serif'\n}\n\nfunction sortedWeights(values: readonly unknown[] | undefined): number[] {\n return [\n ...new Set(\n (values ?? [])\n .map((value) => Math.round(Number(value)))\n .filter((value) => Number.isFinite(value) && value >= 1 && value <= 1000),\n ),\n ].sort((a, b) => a - b)\n}\n\nfunction choiceOf(font: HostThemeFont, stack: unknown): ThemeFontChoice {\n const italics = sortedWeights(font.italics)\n return {\n family: font.family.trim(),\n category: font.category ?? stackCategory(stack),\n weights: sortedWeights(font.weights).length ? sortedWeights(font.weights) : [400],\n ...(italics.length ? { italics } : {}),\n source: font.source === 'custom' ? 'custom' : 'google',\n }\n}\n\nfunction findFont(theme: HostTheme | undefined, family: string | undefined) {\n if (!family) return undefined\n const wanted = family.toLowerCase()\n return theme?.fonts?.find(\n (font) =>\n font.family?.trim().toLowerCase() === wanted && (font.source ?? 'google') !== 'system',\n )\n}\n\n/**\n * The body and heading fonts a theme sets text in (AGL-3656).\n *\n * The body font is the family the theme-wide stack names first, when the\n * theme loads it: a font the theme lists that no stack names draws nothing,\n * which is what the theme default is. The heading font is the family `h1`\n * names, when that is a loaded font other than the body's.\n */\nexport function readThemeFonts(theme: HostTheme | undefined): ThemeFontSelection {\n const stack = theme?.typography?.fontFamily\n const bodyFont = findFont(theme, firstStackFamily(stack))\n const headingStack = theme?.typography?.variants?.h1?.fontFamily\n const headingFont = findFont(theme, firstStackFamily(headingStack))\n return {\n body: bodyFont ? choiceOf(bodyFont, stack) : null,\n heading:\n headingFont && headingFont !== bodyFont ? choiceOf(headingFont, headingStack) : null,\n }\n}\n\nfunction fontEntry(choice: ThemeFontChoice): HostThemeFont {\n const italics = sortedWeights(choice.italics)\n return {\n family: choice.family.trim(),\n weights: sortedWeights(choice.weights).length ? sortedWeights(choice.weights) : [400],\n ...(italics.length ? { italics } : {}),\n source: choice.source,\n category: choice.category,\n }\n}\n\n/**\n * Sets the theme's body and heading fonts (AGL-3656): the `fonts` entries the\n * page loads, the theme-wide stack, and the stack of each style in\n * {@link THEME_HEADING_VARIANTS} for a heading font of its own. `null` goes\n * back to the theme default for that role.\n *\n * An uploaded (`custom`) font the theme lists but no longer sets text in is\n * kept, because it is the site's own and is picked again from the list; a\n * Google font nothing sets text in any more is dropped, so the page stops\n * loading it. Everything else in the typography — sizes, weights, a variant's own\n * family that is not a heading — is left as it was.\n */\nexport function writeThemeFonts(theme: HostTheme, selection: ThemeFontSelection): HostTheme {\n const body = selection.body\n const heading =\n selection.heading &&\n (!body || selection.heading.family.toLowerCase() !== body.family.toLowerCase())\n ? selection.heading\n : null\n const previous = readThemeFonts(theme)\n const previousHeadingStack = previous.heading\n ? theme.typography?.variants?.h1?.fontFamily\n : undefined\n\n const chosen = [body, heading].filter((entry): entry is ThemeFontChoice => !!entry)\n const chosenKeys = new Set(chosen.map((entry) => entry.family.trim().toLowerCase()))\n // Families a text style other than a heading still names, by hand or by\n // an earlier editor: they keep loading, as their style keeps drawing them.\n const otherStyles = new Set(\n Object.entries(theme.typography?.variants ?? {})\n .filter(([key]) => !(THEME_HEADING_VARIANTS as readonly string[]).includes(key))\n .map(([, variant]) => firstStackFamily(variant?.fontFamily)?.toLowerCase())\n .filter((family): family is string => !!family),\n )\n const kept = (theme.fonts ?? []).filter((font) => {\n const key = font.family?.trim().toLowerCase() ?? ''\n if (!key || chosenKeys.has(key)) return false\n return font.source === 'custom' || otherStyles.has(key)\n })\n const fonts = [...chosen.map(fontEntry), ...kept]\n\n const typography = { ...theme.typography }\n if (body) typography.fontFamily = fontFamilyStack(body.family.trim(), body.category)\n else delete typography.fontFamily\n\n const variants = { ...typography.variants }\n for (const key of THEME_HEADING_VARIANTS) {\n const variant = { ...variants[key] }\n if (heading) {\n variant.fontFamily = fontFamilyStack(heading.family.trim(), heading.category)\n } else if (\n variant.fontFamily !== undefined &&\n (variant.fontFamily === previousHeadingStack ||\n !findFont({ fonts }, firstStackFamily(variant.fontFamily)))\n ) {\n // The heading font this theme had, or a family it no longer loads.\n delete variant.fontFamily\n }\n if (Object.keys(variant).length) variants[key] = variant\n else delete variants[key]\n }\n if (Object.keys(variants).length) typography.variants = variants\n else delete typography.variants\n\n const next: HostTheme = { ...theme }\n if (fonts.length) next.fonts = fonts\n else delete next.fonts\n if (Object.keys(typography).length) next.typography = typography\n else delete next.typography\n return next\n}\n\n/** Sets the corner radius, or clears it with `undefined` so it inherits. */\nexport function writeBorderRadius(\n theme: HostTheme,\n value: number | undefined,\n): HostTheme {\n if (value !== undefined && Number.isFinite(value)) {\n return { ...theme, shape: { ...theme.shape, borderRadius: value } }\n }\n const next = { ...theme }\n const shape = { ...next.shape }\n delete shape.borderRadius\n if (Object.keys(shape).length) next.shape = shape\n else delete next.shape\n return next\n}\n\n/** Sets the spacing unit; anything but a positive number clears it. */\nexport function writeSpacing(theme: HostTheme, value: number | undefined): HostTheme {\n const next = { ...theme }\n if (value !== undefined && Number.isFinite(value) && value > 0) next.spacing = value\n else delete next.spacing\n return next\n}\n\n/**\n * Sets one nav height — anything but a positive number clears it — and\n * rebuilds the whole toolbar mixin around both, because `mixins.toolbar`\n * replaces MUI's default rather than merging into it (AGL-1242).\n */\nexport function writeToolbarHeight(\n theme: HostTheme,\n breakpoint: 'xs' | 'sm',\n value: number | undefined,\n): HostTheme {\n const valid = value !== undefined && Number.isFinite(value) && value > 0\n const edited = valid ? value : undefined\n const xs = breakpoint === 'xs' ? edited : readToolbarHeight(theme, 'xs')\n const sm = breakpoint === 'sm' ? edited : readToolbarHeight(theme, 'sm')\n const next = { ...theme }\n if (xs === undefined && sm === undefined) {\n delete next.mixins\n return next\n }\n next.mixins = { toolbar: buildToolbarMixin(xs, sm) }\n return next\n}\n\n/**\n * Drops the site's component overrides. With nothing stored the site renders\n * the brand's own component styles, which is what the editor's \"Reset to\n * theme defaults\" means.\n */\nexport function resetComponentOverrides(theme: HostTheme): HostTheme {\n const next = { ...theme }\n delete next.components\n return next\n}\n\n/** One leaf of a component override, as a writer names it. */\nexport interface ThemeComponentOverrideLeaf {\n component: HostThemeComponentKey\n /**\n * `styleOverrides` styles a slot in literal CSS; `sx` styles it in theme\n * terms, so a value may name a palette path (`primary.main`) or a spacing\n * unit (AGL-3403); `defaultProps` sets a prop's default.\n */\n target: 'styleOverrides' | 'sx' | 'defaultProps'\n /** The style slot (`root`, `contained`, `h1`); `null` for a default prop. */\n slot: string | null\n /** A camelCase CSS property, or the prop's name. */\n property: string\n /** Scopes a style to one side of the toolbar breakpoint; `null` for every width. */\n media: ThemeEditorMedia | null\n value: string | number | boolean\n}\n\n/**\n * Sets one leaf inside the site's component overrides and keeps every other\n * override the site has. The stored overrides are deep-merged over the\n * brand's own at render time, so naming one property changes that property\n * and inherits the rest of the component.\n */\nexport function writeComponentOverride(\n theme: HostTheme,\n leaf: ThemeComponentOverrideLeaf,\n): HostTheme {\n const components = { ...theme.components }\n const entry: HostThemeComponentOverride = { ...components[leaf.component] }\n if (leaf.target === 'defaultProps') {\n entry.defaultProps = { ...entry.defaultProps, [leaf.property]: leaf.value }\n } else {\n const slot = leaf.slot ?? 'root'\n const styles: Record<string, unknown> = {\n ...(leaf.target === 'sx' ? entry.sx : entry.styleOverrides),\n }\n const slotStyles = { ...(styles[slot] as Record<string, unknown> | undefined) }\n if (leaf.media) {\n const query = THEME_EDITOR_MEDIA_QUERIES[leaf.media]\n slotStyles[query] = {\n ...(slotStyles[query] as Record<string, unknown> | undefined),\n [leaf.property]: leaf.value,\n }\n } else {\n slotStyles[leaf.property] = leaf.value\n }\n styles[slot] = slotStyles\n if (leaf.target === 'sx') {\n entry.sx = styles as HostThemeComponentOverride['sx']\n } else {\n entry.styleOverrides = styles\n }\n }\n components[leaf.component] = entry\n return { ...theme, components }\n}\n\n/** Where one leaf lives, without the value it holds. */\nexport type ThemeComponentOverrideTarget = Omit<ThemeComponentOverrideLeaf, 'value'>\n\n/**\n * Removes one leaf from the site's component overrides, and every slot,\n * branch and component it leaves empty, so a field set back to \"Theme\n * default\" stores nothing and the site inherits that property again.\n */\nexport function clearComponentOverride(\n theme: HostTheme,\n target: ThemeComponentOverrideTarget,\n): HostTheme {\n const existing = theme.components?.[target.component]\n if (!existing) return theme\n const entry: HostThemeComponentOverride = { ...existing }\n if (target.target === 'defaultProps') {\n const props = { ...entry.defaultProps }\n delete props[target.property]\n if (Object.keys(props).length) entry.defaultProps = props\n else delete entry.defaultProps\n } else {\n const branch = target.target === 'sx' ? 'sx' : 'styleOverrides'\n const styles: Record<string, unknown> = { ...entry[branch] }\n const slot = target.slot ?? 'root'\n const slotStyles = { ...(styles[slot] as Record<string, unknown> | undefined) }\n if (target.media) {\n const query = THEME_EDITOR_MEDIA_QUERIES[target.media]\n const scoped = { ...(slotStyles[query] as Record<string, unknown> | undefined) }\n delete scoped[target.property]\n if (Object.keys(scoped).length) slotStyles[query] = scoped\n else delete slotStyles[query]\n } else {\n delete slotStyles[target.property]\n }\n if (Object.keys(slotStyles).length) styles[slot] = slotStyles\n else delete styles[slot]\n if (Object.keys(styles).length) {\n if (branch === 'sx') entry.sx = styles as HostThemeComponentOverride['sx']\n else entry.styleOverrides = styles\n } else {\n delete entry[branch]\n }\n }\n const components = { ...theme.components }\n if (Object.keys(entry).length) components[target.component] = entry\n else delete components[target.component]\n const next: HostTheme = { ...theme }\n if (Object.keys(components).length) next.components = components\n else delete next.components\n return next\n}\n\n/** The value one override leaf holds; `undefined` when the site does not set it. */\nexport function readComponentOverride(\n theme: HostTheme | undefined,\n target: ThemeComponentOverrideTarget,\n): unknown {\n const entry = theme?.components?.[target.component]\n if (!entry) return undefined\n if (target.target === 'defaultProps') return entry.defaultProps?.[target.property]\n const styles = (target.target === 'sx' ? entry.sx : entry.styleOverrides) as\n | Record<string, unknown>\n | undefined\n const slotStyles = styles?.[target.slot ?? 'root'] as Record<string, unknown> | undefined\n if (!target.media) return slotStyles?.[target.property]\n const query = THEME_EDITOR_MEDIA_QUERIES[target.media]\n return (slotStyles?.[query] as Record<string, unknown> | undefined)?.[target.property]\n}\n\n/* ------------------------------------------------------------------------ *\n * The look of components, as click-only fields\n * ------------------------------------------------------------------------ */\n\n/** The components the Style components card sets a site-wide look for. */\nexport type ThemeComponentLookGroup = 'button' | 'input' | 'card'\n\nexport const THEME_COMPONENT_LOOK_GROUPS: ReadonlyArray<{\n group: ThemeComponentLookGroup\n label: string\n}> = [\n { group: 'button', label: 'Buttons' },\n { group: 'input', label: 'Form inputs' },\n { group: 'card', label: 'Cards' },\n]\n\nexport type ThemeComponentLookId =\n | 'button.variant'\n | 'button.corners'\n | 'button.textCase'\n | 'button.weight'\n | 'button.padding'\n | 'input.variant'\n | 'input.corners'\n | 'input.background'\n | 'input.border'\n | 'card.variant'\n | 'card.elevation'\n | 'card.corners'\n\n/** One choice a look field offers. */\nexport interface ThemeComponentLookOption {\n /** What the select holds. */\n value: string\n label: string\n /**\n * What each of the field's targets stores, in target order; one value\n * stands for every target.\n */\n stored: string | number | ReadonlyArray<string | number>\n /** A theme color this choice draws in, for its swatch. */\n token?: ThemeColorToken\n}\n\n/**\n * A click-only field over the site's component overrides. Each choice writes\n * the same leaves the Advanced overrides hold, so the two are one setting\n * seen two ways, and anything that writes override leaves can set it.\n */\nexport interface ThemeComponentLookField {\n id: ThemeComponentLookId\n group: ThemeComponentLookGroup\n label: string\n /** `color` choices are theme colors, shown as swatches of the scheme in view. */\n kind: 'select' | 'color'\n /** The leaves a choice sets, read back from the first. */\n targets: readonly ThemeComponentOverrideTarget[]\n /** Leaves set alongside any choice and cleared with it: what makes the choice draw right. */\n companions?: readonly ThemeComponentOverrideLeaf[]\n options: readonly ThemeComponentLookOption[]\n}\n\n/** The select's value for a field the site does not set: the theme's own look. */\nexport const THEME_LOOK_DEFAULT = ''\n/** The select's value for a leaf set to something no choice names, by hand or by AI. */\nexport const THEME_LOOK_CUSTOM = '__custom__'\n\nfunction lookTarget(\n component: HostThemeComponentKey,\n target: ThemeComponentOverrideLeaf['target'],\n property: string,\n slot: string | null = target === 'defaultProps' ? null : 'root',\n): ThemeComponentOverrideTarget {\n return { component, target, slot, property, media: null }\n}\n\n/**\n * Corner choices, as multiples of the site's Border radius (an `sx`\n * `borderRadius` number is one), so a component follows the Shape & spacing\n * slider instead of freezing a pixel value.\n */\nconst CORNER_OPTIONS: readonly ThemeComponentLookOption[] = [\n { value: 'square', label: 'Square', stored: 0 },\n { value: 'subtle', label: 'Half the site radius', stored: 0.5 },\n { value: 'site', label: 'The site radius', stored: 1 },\n { value: 'rounded', label: 'Twice the site radius', stored: 2 },\n { value: 'extra', label: 'Three times the site radius', stored: 3 },\n]\nconst PILL_OPTION: ThemeComponentLookOption = { value: 'pill', label: 'Pill', stored: '999px' }\n\n/**\n * Every component look field, in the order the card shows them.\n *\n * Inputs style both of MUI's boxes: `MuiOutlinedInput` and `MuiFilledInput`,\n * because the Input style choice picks between them and the other choices\n * have to hold whichever is in use. A border color sets the outlined box's\n * own border, which the Besigner's Input element draws, and the notched\n * outline a stock text field draws.\n */\nexport const THEME_COMPONENT_LOOK_FIELDS: readonly ThemeComponentLookField[] = [\n {\n id: 'button.variant',\n group: 'button',\n label: 'Button style',\n kind: 'select',\n targets: [lookTarget('MuiButton', 'defaultProps', 'variant')],\n options: [\n { value: 'contained', label: 'Filled', stored: 'contained' },\n { value: 'outlined', label: 'Outlined', stored: 'outlined' },\n { value: 'text', label: 'Text only', stored: 'text' },\n ],\n },\n {\n id: 'button.corners',\n group: 'button',\n label: 'Button corners',\n kind: 'select',\n targets: [lookTarget('MuiButton', 'sx', 'borderRadius')],\n options: [...CORNER_OPTIONS, PILL_OPTION],\n },\n {\n id: 'button.textCase',\n group: 'button',\n label: 'Button text case',\n kind: 'select',\n targets: [lookTarget('MuiButton', 'styleOverrides', 'textTransform')],\n options: [\n { value: 'none', label: 'As typed', stored: 'none' },\n { value: 'uppercase', label: 'UPPERCASE', stored: 'uppercase' },\n { value: 'capitalize', label: 'Capitalize Each Word', stored: 'capitalize' },\n ],\n },\n {\n id: 'button.weight',\n group: 'button',\n label: 'Button text weight',\n kind: 'select',\n targets: [lookTarget('MuiButton', 'styleOverrides', 'fontWeight')],\n options: [\n { value: '400', label: 'Regular', stored: 400 },\n { value: '500', label: 'Medium', stored: 500 },\n { value: '600', label: 'Semibold', stored: 600 },\n { value: '700', label: 'Bold', stored: 700 },\n ],\n },\n {\n id: 'button.padding',\n group: 'button',\n label: 'Button padding',\n kind: 'select',\n // Spacing units, so padding follows the site's Spacing unit.\n targets: [lookTarget('MuiButton', 'sx', 'px'), lookTarget('MuiButton', 'sx', 'py')],\n options: [\n { value: 'compact', label: 'Compact', stored: [1.5, 0.5] },\n { value: 'comfortable', label: 'Comfortable', stored: [2, 0.75] },\n { value: 'roomy', label: 'Roomy', stored: [3, 1] },\n { value: 'wide', label: 'Wide', stored: [4, 1.25] },\n ],\n },\n {\n id: 'input.variant',\n group: 'input',\n label: 'Input style',\n kind: 'select',\n targets: [lookTarget('MuiTextField', 'defaultProps', 'variant')],\n options: [\n { value: 'outlined', label: 'Outlined', stored: 'outlined' },\n { value: 'filled', label: 'Filled', stored: 'filled' },\n ],\n },\n {\n id: 'input.corners',\n group: 'input',\n label: 'Input corners',\n kind: 'select',\n targets: [\n lookTarget('MuiOutlinedInput', 'sx', 'borderRadius'),\n lookTarget('MuiFilledInput', 'sx', 'borderRadius'),\n ],\n // A filled box's underline runs edge to edge; clipping it to the corners\n // keeps it inside a rounded box.\n companions: [{ ...lookTarget('MuiFilledInput', 'styleOverrides', 'overflow'), value: 'hidden' }],\n options: [...CORNER_OPTIONS, PILL_OPTION],\n },\n {\n id: 'input.background',\n group: 'input',\n label: 'Input background',\n kind: 'color',\n targets: [\n lookTarget('MuiOutlinedInput', 'sx', 'bgcolor'),\n lookTarget('MuiFilledInput', 'sx', 'bgcolor'),\n ],\n options: [\n { value: 'transparent', label: 'None', stored: 'transparent' },\n { value: 'paper', label: 'Paper', stored: 'background.paper', token: 'background.paper' },\n {\n value: 'background',\n label: 'Background',\n stored: 'background.default',\n token: 'background.default',\n },\n { value: 'tintPrimary', label: 'Primary tint', stored: 'tint.primary', token: 'tint.primary' },\n {\n value: 'tintSecondary',\n label: 'Secondary tint',\n stored: 'tint.secondary',\n token: 'tint.secondary',\n },\n {\n value: 'tintTertiary',\n label: 'Tertiary tint',\n stored: 'tint.tertiary',\n token: 'tint.tertiary',\n },\n ],\n },\n {\n id: 'input.border',\n group: 'input',\n label: 'Input border color',\n kind: 'color',\n targets: [\n lookTarget('MuiOutlinedInput', 'sx', 'borderColor'),\n lookTarget('MuiOutlinedInput', 'sx', 'borderColor', 'notchedOutline'),\n ],\n options: [\n { value: 'divider', label: 'Divider', stored: 'divider', token: 'divider' },\n {\n value: 'textSecondary',\n label: 'Secondary text',\n stored: 'text.secondary',\n token: 'text.secondary',\n },\n { value: 'text', label: 'Text', stored: 'text.primary', token: 'text.primary' },\n { value: 'primary', label: 'Primary', stored: 'primary.main', token: 'primary' },\n { value: 'secondary', label: 'Secondary', stored: 'secondary.main', token: 'secondary' },\n { value: 'tertiary', label: 'Tertiary', stored: 'tertiary.main', token: 'tertiary' },\n ],\n },\n {\n id: 'card.variant',\n group: 'card',\n label: 'Card style',\n kind: 'select',\n targets: [lookTarget('MuiCard', 'defaultProps', 'variant')],\n options: [\n { value: 'elevation', label: 'Shadow', stored: 'elevation' },\n { value: 'outlined', label: 'Outline', stored: 'outlined' },\n ],\n },\n {\n id: 'card.elevation',\n group: 'card',\n label: 'Card shadow depth',\n kind: 'select',\n targets: [lookTarget('MuiCard', 'defaultProps', 'elevation')],\n options: [\n { value: '0', label: 'Flat', stored: 0 },\n { value: '1', label: 'Soft', stored: 1 },\n { value: '3', label: 'Medium', stored: 3 },\n { value: '8', label: 'Strong', stored: 8 },\n ],\n },\n {\n id: 'card.corners',\n group: 'card',\n label: 'Card corners',\n kind: 'select',\n targets: [lookTarget('MuiCard', 'sx', 'borderRadius')],\n options: CORNER_OPTIONS,\n },\n]\n\n/** The catalog entry for a look field id. */\nexport function themeComponentLookField(id: ThemeComponentLookId): ThemeComponentLookField {\n const field = THEME_COMPONENT_LOOK_FIELDS.find((entry) => entry.id === id)\n if (!field) throw new Error(`unknown component look field ${id}`)\n return field\n}\n\nfunction storedFor(option: ThemeComponentLookOption, index: number) {\n return Array.isArray(option.stored)\n ? (option.stored as ReadonlyArray<string | number>)[index]\n : (option.stored as string | number)\n}\n\n/**\n * A look field as its select shows it: the choice the site's overrides hold,\n * {@link THEME_LOOK_DEFAULT} when they set nothing, or\n * {@link THEME_LOOK_CUSTOM} when they set a value no choice names.\n */\nexport function readComponentLook(\n theme: HostTheme | undefined,\n field: ThemeComponentLookField,\n): string {\n const values = field.targets.map((target) => readComponentOverride(theme, target))\n if (values.every((value) => value === undefined)) return THEME_LOOK_DEFAULT\n const match = field.options.find((option) =>\n values.every((value, index) => value === storedFor(option, index)),\n )\n return match ? match.value : THEME_LOOK_CUSTOM\n}\n\n/**\n * Sets a look field to one of its choices, or back to the theme's own look\n * with {@link THEME_LOOK_DEFAULT}, which clears every leaf it sets. Any other\n * value changes nothing.\n */\nexport function writeComponentLook(\n theme: HostTheme,\n field: ThemeComponentLookField,\n value: string,\n): HostTheme {\n if (value === THEME_LOOK_DEFAULT) {\n let next = theme\n for (const target of [...field.targets, ...(field.companions ?? [])]) {\n next = clearComponentOverride(next, target)\n }\n return next\n }\n const option = field.options.find((entry) => entry.value === value)\n if (!option) return theme\n let next = theme\n field.targets.forEach((target, index) => {\n next = writeComponentOverride(next, { ...target, value: storedFor(option, index) })\n })\n for (const companion of field.companions ?? []) next = writeComponentOverride(next, companion)\n return next\n}\n"],"names":["HOST_THEME_COMPONENT_WHITELIST","TOOLBAR_SM_MIN_WIDTH","TOOLBAR_SM_QUERY","DEFAULT_TOOLBAR_XS","DEFAULT_TOOLBAR_SM","TOOLBAR_LANDSCAPE_QUERY","TOOLBAR_LANDSCAPE_RULE","minHeight","readToolbarHeight","theme","breakpoint","toolbar","mixins","undefined","raw","value","parseFloat","String","Number","isFinite","buildToolbarMixin","xs","sm","orderSensitiveKey","JSON","stringify","PALETTE_COLOR_FIELDS","key","label","SURFACE_COLOR_FIELDS","path","TINT_COLOR_FIELDS","DIVIDER_COLOR_FIELD","GOOGLE_FONT_OPTIONS","family","category","weights","fontFamilyStack","fallback","getSchemeColor","colors","group","THEME_EDITOR_SCHEMES","THEME_COLOR_FIELDS","map","token","join","DARK_SCHEME_FIELD","options","SYSTEM_FONT_VALUE","FONT_FAMILY_FIELD","BORDER_RADIUS_FIELD","min","max","step","SPACING_FIELD","TOOLBAR_HEIGHT_FIELDS","COMPONENT_OVERRIDES_FIELD","components","THEME_EDITOR_MEDIA_QUERIES","mobile","desktop","THEME_EDITOR_CONTROLS","id","kind","perScheme","option","themeEditorControl","control","find","entry","Error","setSchemeValue","scheme","update","colorSchemes","readThemeColor","divider","split","main","writeThemeColor","hex","next","paletteKey","tint","rest","Object","keys","length","groupKey","groupValue","grouped","copyThemeSchemeColors","from","to","source","parse","readDarkScheme","darkScheme","writeDarkScheme","readFontFamily","readThemeFonts","body","writeFontFamily","current","writeThemeFonts","heading","THEME_HEADING_VARIANTS","firstStackFamily","stack","first","trim","replace","stackCategory","test","sortedWeights","values","Set","Math","round","filter","sort","a","b","choiceOf","font","italics","findFont","wanted","toLowerCase","fonts","typography","fontFamily","bodyFont","headingStack","variants","h1","headingFont","fontEntry","choice","selection","previous","previousHeadingStack","chosen","chosenKeys","otherStyles","entries","includes","variant","kept","has","writeBorderRadius","shape","borderRadius","writeSpacing","spacing","writeToolbarHeight","valid","edited","resetComponentOverrides","writeComponentOverride","leaf","component","target","defaultProps","property","slot","styles","sx","styleOverrides","slotStyles","media","query","clearComponentOverride","existing","props","branch","scoped","readComponentOverride","THEME_COMPONENT_LOOK_GROUPS","THEME_LOOK_DEFAULT","THEME_LOOK_CUSTOM","lookTarget","CORNER_OPTIONS","stored","PILL_OPTION","THEME_COMPONENT_LOOK_FIELDS","targets","companions","themeComponentLookField","field","storedFor","index","Array","isArray","readComponentLook","every","match","writeComponentLook","forEach","companion"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAWD,SACEA,8BAA8B,QAEzB,kBAAc;AAErB;;;;;;;;;;;;;;;;;;;;CAoBC,GAED;;;;CAIC,GACD,OAAO,MAAMC,uBAAuB,IAAG;AACvC,OAAO,MAAMC,mBAAmB,CAAC,kBAAkB,EAAED,qBAAqB,GAAG,CAAC,CAAA;AAC9E,mEAAmE,GACnE,OAAO,MAAME,qBAAqB,GAAE;AACpC,OAAO,MAAMC,qBAAqB,GAAE;AACpC;;;;CAIC,GACD,OAAO,MAAMC,0BAA0B,yBAAwB;AAC/D,OAAO,MAAMC,yBAAyB;IACpC,mCAAmC;QAAEC,WAAW;IAAG;AACrD,EAAC;AAED,uEAAuE,GACvE,OAAO,SAASC,kBAAk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