@sanity/themer 0.8.0 → 0.9.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"legacy.d.ts","names":[],"sources":["../src/legacy/index.ts"],"mappings":";;;;;;;qBAYa,0BAA0B,aAAa;;;;;;;qBASvC,oBAAoB,aAAa;;;;;;;qBAQjC,yBAAyB,aAAa;;;;;;;qBAQtC,aAAa,aAAa;;;;;;;qBAQ1B,cAAc,aAAa;;;;;;;qBAQ3B,gBAAgB,aAAa;;;;;;YAO9B,MAAM,aAAa;;;;;;YAOnB,cAAc,aAAa;;;;;;YAO3B,OAAO,aAAa;;;;;;YAOpB,cAAc,aAAa;;;;;;YAO3B,cAAc,aAAa;;;;;;YAO3B,cAAc,aAAa"}
1
+ {"version":3,"file":"legacy.d.ts","names":[],"sources":["../src/legacy/index.ts"],"mappings":";;;;;;;cAYa,0BAA0B,aAAa;;;;;;;cASvC,oBAAoB,aAAa;;;;;;;cAQjC,yBAAyB,aAAa;;;;;;;cAQtC,aAAa,aAAa;;;;;;;cAQ1B,cAAc,aAAa;;;;;;;cAQ3B,gBAAgB,aAAa;;;;;;KAO9B,MAAM,aAAa;;;;;;KAOnB,cAAc,aAAa;;;;;;KAO3B,OAAO,aAAa;;;;;;KAOpB,cAAc,aAAa;;;;;;KAO3B,cAAc,aAAa;;;;;;KAO3B,cAAc,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"presets-CqBgS3A-.js","names":["buildTheme","buildUITheme"],"sources":["../src/theme/hsl.ts","../src/lib/mix.ts","../src/theme/options.ts","../src/theme/buildPalette.ts","../src/theme/buildTheme.ts","../src/theme/presets.ts"],"sourcesContent":["/**\n * Color math for the palette generator, kept at full float precision: unlike\n * the HSL helpers in `@sanity/ui/theme`, nothing is rounded between the two\n * conversions, so `hslToHex(hexToHsl(hex))` returns `hex` unchanged for every\n * color. `buildTheme` relies on that to reproduce the stock `@sanity/color`\n * palette byte-for-byte when it is called with the stock anchor colors.\n */\n\n/**\n * A color in HSL space: `h` in degrees within `[0, 360)`, `s` and `l` as\n * fractions within `[0, 1]`.\n *\n * @internal\n */\nexport interface Hsl {\n h: number\n s: number\n l: number\n}\n\n/** @internal */\nexport function hexToHsl(hex: string): Hsl {\n const [r, g, b] = parseHex(hex)\n\n const max = Math.max(r, g, b)\n const min = Math.min(r, g, b)\n const delta = max - min\n\n const l = (max + min) / 2\n\n if (delta === 0) {\n return {h: 0, s: 0, l}\n }\n\n const s = delta / (1 - Math.abs(2 * l - 1))\n\n let h: number\n\n if (max === r) {\n h = ((g - b) / delta) % 6\n } else if (max === g) {\n h = (b - r) / delta + 2\n } else {\n h = (r - g) / delta + 4\n }\n\n return {h: normalizeHue(h * 60), s, l}\n}\n\n/** @internal */\nexport function hslToHex(hsl: Hsl): string {\n const h = normalizeHue(hsl.h)\n const s = clamp01(hsl.s)\n const l = clamp01(hsl.l)\n\n const c = (1 - Math.abs(2 * l - 1)) * s\n const x = c * (1 - Math.abs(((h / 60) % 2) - 1))\n const m = l - c / 2\n\n let r = 0\n let g = 0\n let b = 0\n\n if (h < 60) {\n r = c\n g = x\n } else if (h < 120) {\n r = x\n g = c\n } else if (h < 180) {\n g = c\n b = x\n } else if (h < 240) {\n g = x\n b = c\n } else if (h < 300) {\n r = x\n b = c\n } else {\n r = c\n b = x\n }\n\n return `#${channelToHex(r + m)}${channelToHex(g + m)}${channelToHex(b + m)}`\n}\n\n/**\n * Rotates `from` towards `to` along the shortest arc of the hue circle.\n *\n * @internal\n */\nexport function mixHue(from: number, to: number, amount: number): number {\n const delta = ((((to - from) % 360) + 540) % 360) - 180\n\n return normalizeHue(from + delta * amount)\n}\n\n/**\n * The WCAG relative luminance of a hex color, between 0 (black) and 1 (white).\n *\n * @internal\n */\nexport function relativeLuminance(hex: string): number {\n const [r, g, b] = parseHex(hex)\n\n return 0.2126 * linearChannel(r) + 0.7152 * linearChannel(g) + 0.0722 * linearChannel(b)\n}\n\nfunction linearChannel(value: number): number {\n return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4\n}\n\n/** Parses `#abc` and `#aabbcc` hex colors into channel fractions of 1 */\nfunction parseHex(hex: string): [number, number, number] {\n const expanded =\n hex.length === 4 ? `${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}` : hex.slice(1)\n\n return [\n parseInt(expanded.slice(0, 2), 16) / 255,\n parseInt(expanded.slice(2, 4), 16) / 255,\n parseInt(expanded.slice(4, 6), 16) / 255,\n ]\n}\n\nfunction channelToHex(value: number): string {\n return Math.round(clamp01(value) * 255)\n .toString(16)\n .padStart(2, '0')\n}\n\nfunction normalizeHue(hue: number): number {\n return ((hue % 360) + 360) % 360\n}\n\nfunction clamp01(value: number): number {\n return Math.min(1, Math.max(0, value))\n}\n","/**\n * Matches `#abc` and `#aabbcc` hex colors (the only formats the theme\n * generators accept), same as the hosted Themer service did.\n *\n * The `mix` function this module was named for moved to `@sanity/themer-legacy`\n * along with the legacy generator; `isColor` stays here for `theme/options.ts`\n * and `tool/storage.ts`.\n *\n * @internal\n */\nexport function isColor(input: string): boolean {\n return /^#(?:[0-9a-f]{3}){1,2}$/i.test(input)\n}\n","import {black, blue, gray, white} from '@sanity/color'\nimport {type ThemeColorSchemeKey} from '@sanity/ui/theme'\n\nimport {isColor} from '../lib/mix'\nimport {hexToHsl, hslToHex} from './hsl'\n\n/**\n * The colors of one color scheme, for {@link BuildThemeOptions}. Every color\n * is a hex color (`#rgb` or `#rrggbb`), and everything is optional: omitted\n * options fall back to the stock Studio colors, so an empty object reproduces\n * the stock scheme exactly.\n *\n * @public\n */\nexport interface SchemeThemeOptions {\n /**\n * The accent color — the brand color of the scheme. Replaces the `blue`\n * scale of the palette, which Sanity UI uses for primary buttons, focus\n * rings and links.\n *\n * The stock accent is `#556bfc` (`blue/500` of `@sanity/color`).\n */\n accent?: string\n\n /**\n * The background of the scheme — every other color of the scheme is\n * blended onto it. The dark scheme's background replaces `black` in the\n * palette and the light scheme's replaces `white`.\n *\n * It is kept far enough from the text and accent colors to stay usable:\n * a dark background is made darker until it has enough contrast with them\n * (it can never be lighter than either), and a light background can never\n * be darker than either.\n *\n * The stock backgrounds are `#0d0e12` (dark) and `#ffffff` (light).\n */\n background?: string\n\n /**\n * How strongly text and borders separate from the accent color, between 15\n * and 100. The default is 85, which uses the text color as-is. Above 85 the\n * text scale loses its tint until it is fully neutral at 100 — a high\n * contrast scheme with no mixing of the text and accent colors. Below 85\n * more and more of the accent color mixes into the text scale, giving text\n * and borders more color, until the scale fully adopts the accent hue and\n * saturation at 15.\n */\n contrast?: number\n\n /**\n * The text color. Replaces the `gray` scale of the palette, which Sanity UI\n * uses for text, icons, borders and neutral surfaces. When omitted, it is\n * derived from the accent color: a mostly desaturated version of it, the\n * way the stock `gray` scale carries a hint of the stock blue.\n *\n * The stock text color is `#727892` (`gray/500` of `@sanity/color`).\n */\n text?: string\n}\n\n/**\n * Options for {@link buildTheme} and {@link buildPalette}: the colors of the\n * dark and the light scheme, each with its own accent, text, background and\n * contrast — so the two schemes can differ in more than their background.\n * Both schemes are optional, and so is every color: whatever is omitted\n * falls back to the stock Studio colors, so `buildTheme({})` matches\n * `buildTheme()` from `@sanity/ui/theme` exactly.\n *\n * @public\n */\nexport interface BuildThemeOptions {\n /** The colors of the dark scheme */\n dark?: SchemeThemeOptions\n /** The colors of the light scheme */\n light?: SchemeThemeOptions\n}\n\n/**\n * {@link SchemeThemeOptions} with every option filled in: colors normalized\n * to lowercase `#rrggbb`, the text color derived from the accent when it was\n * omitted, and the contrast clamped into its valid range.\n *\n * @internal\n */\nexport interface ResolvedSchemeOptions {\n accent: string\n background: string\n contrast: number\n text: string\n}\n\n/** {@link BuildThemeOptions} with both schemes resolved @internal */\nexport type ResolvedThemeOptions = Record<ThemeColorSchemeKey, ResolvedSchemeOptions>\n\n/** The color schemes, in the order the tool presents them @internal */\nexport const SCHEMES: ThemeColorSchemeKey[] = ['light', 'dark']\n\n/** The stock accent color — `blue/500` of `@sanity/color` @internal */\nexport const DEFAULT_ACCENT: string = blue[500].hex\n\n/** The stock text color — `gray/500` of `@sanity/color` @internal */\nexport const DEFAULT_TEXT: string = gray[500].hex\n\n/** The stock backgrounds — `black` and `white` of `@sanity/color` @internal */\nexport const DEFAULT_BACKGROUND: Record<ThemeColorSchemeKey, string> = {\n dark: black.hex,\n light: white.hex,\n}\n\n/** The contrast that applies the text color as-is @internal */\nexport const DEFAULT_CONTRAST = 85\n\n/** @internal */\nexport const MINIMUM_CONTRAST = 15\n\n/** @internal */\nexport const MAXIMUM_CONTRAST = 100\n\n/** The keys of the options shape before they were grouped by scheme */\nconst FLAT_OPTION_KEYS = ['accent', 'text', 'background', 'contrast']\n\n/** @internal */\nexport function resolveThemeOptions(options: BuildThemeOptions = {}): ResolvedThemeOptions {\n if (FLAT_OPTION_KEYS.some((key) => key in options)) {\n throw new TypeError(\n 'The `buildTheme` options are grouped by color scheme: pass `{light: {accent, text, background, contrast}, dark: {…}}` instead of one set of colors for both',\n )\n }\n\n return {\n dark: resolveSchemeOptions(options.dark ?? {}, 'dark'),\n light: resolveSchemeOptions(options.light ?? {}, 'light'),\n }\n}\n\nfunction resolveSchemeOptions(\n options: SchemeThemeOptions,\n scheme: ThemeColorSchemeKey,\n): ResolvedSchemeOptions {\n const accent =\n options.accent === undefined\n ? DEFAULT_ACCENT\n : normalizeColor(options.accent, `${scheme}.accent`)\n\n return {\n accent,\n background:\n options.background === undefined\n ? DEFAULT_BACKGROUND[scheme]\n : normalizeColor(options.background, `${scheme}.background`),\n contrast: normalizeContrast(options.contrast, scheme),\n text:\n options.text === undefined\n ? deriveTextColor(accent)\n : normalizeColor(options.text, `${scheme}.text`),\n }\n}\n\n/**\n * Derives the text color from an accent color, keeping the relationship the\n * stock palette has between `gray/500` and `blue/500`: the text color takes\n * the accent's hue (offset the way the stock gray is offset from the stock\n * blue), carries about an eighth of its saturation, and keeps the stock text\n * lightness. Deriving from the stock accent returns the stock text color.\n *\n * @internal\n */\nexport function deriveTextColor(accent: string): string {\n const accentHsl = hexToHsl(normalizeColor(accent, 'accent'))\n const defaultAccent = hexToHsl(DEFAULT_ACCENT)\n const defaultText = hexToHsl(DEFAULT_TEXT)\n\n return hslToHex({\n h: defaultText.h + (accentHsl.h - defaultAccent.h),\n s: Math.min(1, defaultText.s * (accentHsl.s / defaultAccent.s)),\n l: defaultText.l,\n })\n}\n\nfunction normalizeColor(value: string, name: string): string {\n if (typeof value !== 'string' || !isColor(value)) {\n throw new TypeError(\n `Invalid \\`${name}\\` color: ${JSON.stringify(value)} — expected a hex color like #556bfc`,\n )\n }\n\n const lower = value.toLowerCase()\n\n return lower.length === 4\n ? `#${lower[1]}${lower[1]}${lower[2]}${lower[2]}${lower[3]}${lower[3]}`\n : lower\n}\n\nfunction normalizeContrast(value: number | undefined, scheme: ThemeColorSchemeKey): number {\n if (value === undefined) {\n return DEFAULT_CONTRAST\n }\n\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new TypeError(\n `Invalid \\`${scheme}.contrast\\`: ${JSON.stringify(value)} — expected a number between ${MINIMUM_CONTRAST} and ${MAXIMUM_CONTRAST}`,\n )\n }\n\n return Math.min(MAXIMUM_CONTRAST, Math.max(MINIMUM_CONTRAST, value))\n}\n","import {color, COLOR_TINTS, ColorHueKey, ColorTintKey, ColorTints} from '@sanity/color'\nimport {type ThemeColorSchemeKey} from '@sanity/ui/theme'\n\nimport {hexToHsl, Hsl, hslToHex, mixHue, relativeLuminance} from './hsl'\nimport {\n BuildThemeOptions,\n DEFAULT_ACCENT,\n DEFAULT_CONTRAST,\n DEFAULT_TEXT,\n MAXIMUM_CONTRAST,\n MINIMUM_CONTRAST,\n ResolvedSchemeOptions,\n resolveThemeOptions,\n} from './options'\n\n/**\n * The lightness band the accent and text colors are clamped into — anchors\n * outside it would squeeze most of their scale's tints into an\n * indistinguishable sliver, messing with the rest of the scale.\n */\nconst MINIMUM_ANCHOR_LIGHTNESS = 0.25\nconst MAXIMUM_ANCHOR_LIGHTNESS = 0.75\n\n/**\n * The contrast ratio the dark background must reach against the 400 tints of\n * the text and accent scales — the tints Sanity UI paints muted text and\n * solid buttons with on dark backgrounds. The stock palette sits at ~6.8.\n */\nconst MINIMUM_DARK_BACKGROUND_CONTRAST = 4.5\n\n/** How much lightness each step of a background adjustment removes or adds */\nconst BACKGROUND_LIGHTNESS_STEP = 0.005\n\n/**\n * A color palette generated by {@link buildPalette}: the `palette` config of\n * `buildTheme` from `@sanity/ui/theme`, with every color as a hex string.\n *\n * @public\n */\nexport type GeneratedColorPalette = {black: string; white: string} & Record<\n ColorHueKey,\n Record<ColorTintKey, string>\n>\n\n/**\n * The palettes generated by {@link buildPalette} — one per color scheme.\n *\n * @public\n */\nexport type GeneratedColorPalettes = Record<ThemeColorSchemeKey, GeneratedColorPalette>\n\n/**\n * Generates a Sanity UI color palette for each color scheme from the theme\n * options: in each palette the scheme's accent color replaces the `blue`\n * scale, its text color the `gray` scale, and the backgrounds replace `black`\n * and `white`. All other hues keep their stock `@sanity/color` values. Called\n * with the stock colors, both palettes come back as the stock palette\n * byte-for-byte.\n *\n * ```ts\n * import {buildPalette} from '@sanity/themer'\n *\n * const {light, dark} = buildPalette({light: {accent: '#556bfc'}})\n * ```\n *\n * @public\n */\nexport function buildPalette(options: BuildThemeOptions = {}): GeneratedColorPalettes {\n const resolved = resolveThemeOptions(options)\n\n return {\n dark: buildSchemePalette('dark', resolved.dark, resolved.light.background),\n light: buildSchemePalette('light', resolved.light, resolved.dark.background),\n }\n}\n\n/**\n * Generates the palette of one scheme. The scheme's own background takes the\n * slot the scheme paints with (`black` for dark, `white` for light), while\n * the other slot — which a scheme only touches for a few inverted details —\n * takes the other scheme's background, so the theme stays one palette.\n */\nfunction buildSchemePalette(\n key: ThemeColorSchemeKey,\n scheme: ResolvedSchemeOptions,\n otherBackground: string,\n): GeneratedColorPalette {\n const accentAnchor = clampAnchorLightness(hexToHsl(scheme.accent))\n const textAnchor = clampAnchorLightness(hexToHsl(scheme.text))\n const grayAnchor = applyContrast(textAnchor, accentAnchor, scheme.contrast)\n\n const blueTints = remapTints(color.blue, hexToHsl(DEFAULT_ACCENT), accentAnchor)\n const grayTints = remapTints(color.gray, hexToHsl(DEFAULT_TEXT), grayAnchor)\n\n const anchorLuminances = [\n relativeLuminance(hslToHex(grayAnchor)),\n relativeLuminance(hslToHex(accentAnchor)),\n ]\n\n const darkBackground = key === 'dark' ? scheme.background : otherBackground\n const lightBackground = key === 'light' ? scheme.background : otherBackground\n\n return {\n black: darkenBackground(darkBackground, {\n anchorLuminances,\n tints: [grayTints['400'], blueTints['400']],\n }),\n white: lightenBackground(lightBackground, anchorLuminances),\n gray: grayTints,\n blue: blueTints,\n purple: tintHexes(color.purple),\n magenta: tintHexes(color.magenta),\n red: tintHexes(color.red),\n orange: tintHexes(color.orange),\n yellow: tintHexes(color.yellow),\n green: tintHexes(color.green),\n cyan: tintHexes(color.cyan),\n }\n}\n\n/**\n * Mixes the accent color into the text color according to the contrast: 85\n * applies the text color as-is, 100 removes its tint entirely, and lower\n * values rotate and saturate it towards the accent.\n */\nfunction applyContrast(text: Hsl, accent: Hsl, contrast: number): Hsl {\n if (contrast === DEFAULT_CONTRAST) {\n return text\n }\n\n if (contrast > DEFAULT_CONTRAST) {\n const amount = (contrast - DEFAULT_CONTRAST) / (MAXIMUM_CONTRAST - DEFAULT_CONTRAST)\n\n return {h: text.h, s: text.s * (1 - amount), l: text.l}\n }\n\n const amount = (DEFAULT_CONTRAST - contrast) / (DEFAULT_CONTRAST - MINIMUM_CONTRAST)\n\n return {\n h: mixHue(text.h, accent.h, amount),\n s: text.s + (accent.s - text.s) * amount,\n l: text.l,\n }\n}\n\n/**\n * Rebuilds a stock tint scale around a new anchor color, where `from` is the\n * scale's stock 500 tint: hues rotate along, saturation scales\n * proportionally, and lightness is remapped piecewise so the anchor takes the\n * new lightness while the scale keeps spanning light to dark. When the anchor\n * matches the stock one, every tint comes back unchanged.\n */\nfunction remapTints(tints: ColorTints, from: Hsl, to: Hsl): Record<ColorTintKey, string> {\n const rotation = to.h - from.h\n const result: Partial<Record<ColorTintKey, string>> = {}\n\n for (const tint of COLOR_TINTS) {\n const value = hexToHsl(tints[tint].hex)\n\n result[tint] = hslToHex({\n h: value.h + rotation,\n s: remapSaturation(value.s, from.s, to.s),\n l: remapLightness(value.l, from.l, to.l),\n })\n }\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- the loop assigns every tint key\n return result as Record<ColorTintKey, string>\n}\n\nfunction remapSaturation(value: number, from: number, to: number): number {\n if (from === to) {\n return value\n }\n\n return Math.min(1, value * (to / from))\n}\n\nfunction remapLightness(value: number, from: number, to: number): number {\n if (from === to) {\n return value\n }\n\n if (value <= from) {\n return value * (to / from)\n }\n\n return to + ((value - from) * (1 - to)) / (1 - from)\n}\n\nfunction clampAnchorLightness(anchor: Hsl): Hsl {\n const l = Math.min(MAXIMUM_ANCHOR_LIGHTNESS, Math.max(MINIMUM_ANCHOR_LIGHTNESS, anchor.l))\n\n return l === anchor.l ? anchor : {...anchor, l}\n}\n\n/**\n * Enforces the dark background rules: it can never be lighter than the text\n * or accent colors, and it must reach enough contrast with the 400 tints of\n * their scales — it is made darker until it does (or bottoms out at black).\n */\nfunction darkenBackground(\n hex: string,\n rules: {anchorLuminances: number[]; tints: string[]},\n): string {\n const maximumLuminance = Math.min(...rules.anchorLuminances)\n const tintLuminances = rules.tints.map((tint) => relativeLuminance(tint))\n\n const isDarkEnough = (background: string): boolean => {\n const luminance = relativeLuminance(background)\n\n return (\n luminance < maximumLuminance &&\n tintLuminances.every(\n (tintLuminance) =>\n (tintLuminance + 0.05) / (luminance + 0.05) >= MINIMUM_DARK_BACKGROUND_CONTRAST,\n )\n )\n }\n\n const {h, s, l} = hexToHsl(hex)\n let lightness = l\n let current = hex\n\n while (!isDarkEnough(current) && lightness > 0) {\n lightness = Math.max(0, lightness - BACKGROUND_LIGHTNESS_STEP)\n current = hslToHex({h, s, l: lightness})\n }\n\n return current\n}\n\n/**\n * Enforces the light background rule: it can never be darker than the text\n * or accent colors — it is made lighter until it is (or tops out at white).\n */\nfunction lightenBackground(hex: string, anchorLuminances: number[]): string {\n const minimumLuminance = Math.max(...anchorLuminances)\n\n const {h, s, l} = hexToHsl(hex)\n let lightness = l\n let current = hex\n\n while (relativeLuminance(current) <= minimumLuminance && lightness < 1) {\n lightness = Math.min(1, lightness + BACKGROUND_LIGHTNESS_STEP)\n current = hslToHex({h, s, l: lightness})\n }\n\n return current\n}\n\nfunction tintHexes(tints: ColorTints): Record<ColorTintKey, string> {\n const result: Partial<Record<ColorTintKey, string>> = {}\n\n for (const tint of COLOR_TINTS) {\n result[tint] = tints[tint].hex\n }\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- the loop assigns every tint key\n return result as Record<ColorTintKey, string>\n}\n","import {\n buildTheme as buildUITheme,\n RootTheme,\n ThemeColorSchemes_v2,\n v0_v2,\n v2_v0,\n} from '@sanity/ui/theme'\n\nimport {buildPalette} from './buildPalette'\nimport {BuildThemeOptions} from './options'\n\n/**\n * Generates a Studio theme from a handful of colors per color scheme, by\n * replacing the color palette that the `buildTheme` from `@sanity/ui/theme`\n * otherwise fills with `@sanity/color`: in each scheme the accent color\n * replaces the `blue` scale (primary buttons, focus rings, links), the\n * optional text color the `gray` scale (text, icons, borders), and the\n * optional background replaces `black` (dark) or `white` (light). The result\n * is the same type of theme that `@sanity/ui/theme` builds, ready for the\n * `theme` property of a Studio config.\n *\n * ```ts\n * import {buildTheme} from '@sanity/themer'\n * import {defineConfig} from 'sanity'\n *\n * export const theme = buildTheme({\n * light: {\n * accent: '#556bfc',\n * text: '#727892', // optional — derived from `accent` when omitted\n * background: '#ffffff', // optional\n * contrast: 85, // optional, 15–100\n * },\n * dark: {\n * accent: '#556bfc',\n * background: '#0d0e12',\n * },\n * })\n *\n * export default defineConfig({\n * theme,\n * // ...rest of the config\n * })\n * ```\n *\n * Every option is optional and falls back to the stock Studio colors: called\n * with the stock colors — like the example — or with no options at all, it\n * returns the exact same colors as `buildTheme()` from `@sanity/ui/theme`.\n *\n * @public\n */\nexport function buildTheme(options: BuildThemeOptions = {}): RootTheme {\n const palettes = buildPalette(options)\n\n // Sanity UI renders both schemes of a theme from one palette, so each\n // scheme gets a theme of its own palette, and the two are composed into one\n // theme that takes its light scheme from the one and its dark scheme from\n // the other. The scheme getters keep Sanity UI's lazy rendering: a scheme is\n // only computed once something reads it.\n const light = v0_v2(buildUITheme({palette: palettes.light}))\n const dark = v0_v2(buildUITheme({palette: palettes.dark}))\n\n const color: ThemeColorSchemes_v2 = {\n get light() {\n return light.color.light\n },\n get dark() {\n return dark.color.dark\n },\n }\n\n return v2_v0({...light, color})\n}\n","import {BuildThemeOptions} from './options'\n\n/**\n * A preset theme: a named set of {@link BuildThemeOptions} ready to pass to\n * `buildTheme`.\n *\n * @public\n */\nexport interface ThemePreset {\n slug: string\n title: string\n /** The preset's theme options, ready to pass to `buildTheme` */\n options: BuildThemeOptions\n}\n\n/**\n * The hosted Themer presets had one accent and one text color for both\n * schemes, and a background per scheme\n */\nfunction scheme(accent: string, text: string, backgrounds: {dark: string; light: string}) {\n return {\n dark: {accent, text, background: backgrounds.dark},\n light: {accent, text, background: backgrounds.light},\n } satisfies BuildThemeOptions\n}\n\n/**\n * Preset themes for `buildTheme`, carried over from the hosted Themer service\n * (themer.sanity.build) presets: each one maps the legacy preset's primary\n * hue to `accent`, its default hue to `text` and its lightest/darkest colors\n * to the backgrounds of the light and dark scheme.\n *\n * ```ts\n * import {buildTheme, presets} from '@sanity/themer'\n *\n * const verdant = presets.find((preset) => preset.slug === 'verdant')\n * const theme = buildTheme(verdant.options)\n * ```\n *\n * @public\n */\nexport const presets: ThemePreset[] = [\n {\n slug: 'studio',\n title: 'Studio',\n options: {},\n },\n {\n slug: 'dew',\n title: 'Dew',\n options: scheme('#d1a308', '#5e63b4', {dark: '#0d0d15', light: '#fcfcfd'}),\n },\n {\n slug: 'pink-synth',\n title: 'Pink Synth',\n options: scheme('#ec4899', '#8b6584', {dark: '#171721', light: '#f7f2f5'}),\n },\n {\n slug: 'pixel-art',\n title: 'Pixel Art',\n options: scheme('#f10784', '#57619c', {dark: '#0d0e15', light: '#fcfcfd'}),\n },\n {\n slug: 'retro-colonial',\n title: 'Retro Colonial',\n options: scheme('#fa7a78', '#8bb9b5', {dark: '#0d1515', light: '#fcfdfd'}),\n },\n {\n slug: 'rosabel',\n title: 'Rosabel',\n options: scheme('#ed2555', '#9d8966', {dark: '#15120d', light: '#fdfdfc'}),\n },\n {\n slug: 'stereofidelic',\n title: 'Stereofidelic',\n options: scheme('#f13009', '#678e9a', {dark: '#0e1315', light: '#fcfdfd'}),\n },\n {\n slug: 'verdant',\n title: 'Verdant',\n options: scheme('#1cb485', '#5c9199', {dark: '#0d1415', light: '#fcfdfd'}),\n },\n]\n"],"mappings":";;;AAqBA,SAAgB,SAAS,KAAkB;CACzC,IAAM,CAAC,GAAG,GAAG,KAAK,SAAS,GAAG,GAExB,MAAM,KAAK,IAAI,GAAG,GAAG,CAAC,GACtB,MAAM,KAAK,IAAI,GAAG,GAAG,CAAC,GACtB,QAAQ,MAAM,KAEd,KAAK,MAAM,OAAO;CAExB,IAAI,UAAU,GACZ,OAAO;EAAC,GAAG;EAAG,GAAG;EAAG;CAAC;CAGvB,IAAM,IAAI,SAAS,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,IAErC;CAUJ,OARA,AAKE,IALE,QAAQ,KACJ,IAAI,KAAK,QAAS,IACf,QAAQ,KACZ,IAAI,KAAK,QAAQ,KAEjB,IAAI,KAAK,QAAQ,GAGjB;EAAC,GAAG,aAAa,IAAI,EAAE;EAAG;EAAG;CAAC;AACvC;;AAGA,SAAgB,SAAS,KAAkB;CACzC,IAAM,IAAI,aAAa,IAAI,CAAC,GACtB,IAAI,QAAQ,IAAI,CAAC,GACjB,IAAI,QAAQ,IAAI,CAAC,GAEjB,KAAK,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,KA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CAAC;CAC3E;CACA;EACE,MAAM;EACN,OAAO;EACP,SAAS,OAAO,WAAW,WAAW;GAAC,MAAM;GAAW,OAAO;EAAS,CAAC;CAC3E;CACA;EACE,MAAM;EACN,OAAO;EACP,SAAS,OAAO,WAAW,WAAW;GAAC,MAAM;GAAW,OAAO;EAAS,CAAC;CAC3E;CACA;EACE,MAAM;EACN,OAAO;EACP,SAAS,OAAO,WAAW,WAAW;GAAC,MAAM;GAAW,OAAO;EAAS,CAAC;CAC3E;CACA;EACE,MAAM;EACN,OAAO;EACP,SAAS,OAAO,WAAW,WAAW;GAAC,MAAM;GAAW,OAAO;EAAS,CAAC;CAC3E;AACF"}
1
+ {"version":3,"file":"presets-CqBgS3A-.js","names":["buildTheme","buildUITheme"],"sources":["../src/theme/hsl.ts","../src/lib/mix.ts","../src/theme/options.ts","../src/theme/buildPalette.ts","../src/theme/buildTheme.ts","../src/theme/presets.ts"],"sourcesContent":["/**\n * Color math for the palette generator, kept at full float precision: unlike\n * the HSL helpers in `@sanity/ui/theme`, nothing is rounded between the two\n * conversions, so `hslToHex(hexToHsl(hex))` returns `hex` unchanged for every\n * color. `buildTheme` relies on that to reproduce the stock `@sanity/color`\n * palette byte-for-byte when it is called with the stock anchor colors.\n */\n\n/**\n * A color in HSL space: `h` in degrees within `[0, 360)`, `s` and `l` as\n * fractions within `[0, 1]`.\n *\n * @internal\n */\nexport interface Hsl {\n h: number\n s: number\n l: number\n}\n\n/** @internal */\nexport function hexToHsl(hex: string): Hsl {\n const [r, g, b] = parseHex(hex)\n\n const max = Math.max(r, g, b)\n const min = Math.min(r, g, b)\n const delta = max - min\n\n const l = (max + min) / 2\n\n if (delta === 0) {\n return {h: 0, s: 0, l}\n }\n\n const s = delta / (1 - Math.abs(2 * l - 1))\n\n let h: number\n\n if (max === r) {\n h = ((g - b) / delta) % 6\n } else if (max === g) {\n h = (b - r) / delta + 2\n } else {\n h = (r - g) / delta + 4\n }\n\n return {h: normalizeHue(h * 60), s, l}\n}\n\n/** @internal */\nexport function hslToHex(hsl: Hsl): string {\n const h = normalizeHue(hsl.h)\n const s = clamp01(hsl.s)\n const l = clamp01(hsl.l)\n\n const c = (1 - Math.abs(2 * l - 1)) * s\n const x = c * (1 - Math.abs(((h / 60) % 2) - 1))\n const m = l - c / 2\n\n let r = 0\n let g = 0\n let b = 0\n\n if (h < 60) {\n r = c\n g = x\n } else if (h < 120) {\n r = x\n g = c\n } else if (h < 180) {\n g = c\n b = x\n } else if (h < 240) {\n g = x\n b = c\n } else if (h < 300) {\n r = x\n b = c\n } else {\n r = c\n b = x\n }\n\n return `#${channelToHex(r + m)}${channelToHex(g + m)}${channelToHex(b + m)}`\n}\n\n/**\n * Rotates `from` towards `to` along the shortest arc of the hue circle.\n *\n * @internal\n */\nexport function mixHue(from: number, to: number, amount: number): number {\n const delta = ((((to - from) % 360) + 540) % 360) - 180\n\n return normalizeHue(from + delta * amount)\n}\n\n/**\n * The WCAG relative luminance of a hex color, between 0 (black) and 1 (white).\n *\n * @internal\n */\nexport function relativeLuminance(hex: string): number {\n const [r, g, b] = parseHex(hex)\n\n return 0.2126 * linearChannel(r) + 0.7152 * linearChannel(g) + 0.0722 * linearChannel(b)\n}\n\nfunction linearChannel(value: number): number {\n return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4\n}\n\n/** Parses `#abc` and `#aabbcc` hex colors into channel fractions of 1 */\nfunction parseHex(hex: string): [number, number, number] {\n const expanded =\n hex.length === 4 ? `${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}` : hex.slice(1)\n\n return [\n parseInt(expanded.slice(0, 2), 16) / 255,\n parseInt(expanded.slice(2, 4), 16) / 255,\n parseInt(expanded.slice(4, 6), 16) / 255,\n ]\n}\n\nfunction channelToHex(value: number): string {\n return Math.round(clamp01(value) * 255)\n .toString(16)\n .padStart(2, '0')\n}\n\nfunction normalizeHue(hue: number): number {\n return ((hue % 360) + 360) % 360\n}\n\nfunction clamp01(value: number): number {\n return Math.min(1, Math.max(0, value))\n}\n","/**\n * Matches `#abc` and `#aabbcc` hex colors (the only formats the theme\n * generators accept), same as the hosted Themer service did.\n *\n * The `mix` function this module was named for moved to `@sanity/themer-legacy`\n * along with the legacy generator; `isColor` stays here for `theme/options.ts`\n * and `tool/storage.ts`.\n *\n * @internal\n */\nexport function isColor(input: string): boolean {\n return /^#(?:[0-9a-f]{3}){1,2}$/i.test(input)\n}\n","import {black, blue, gray, white} from '@sanity/color'\nimport {type ThemeColorSchemeKey} from '@sanity/ui/theme'\n\nimport {isColor} from '../lib/mix'\nimport {hexToHsl, hslToHex} from './hsl'\n\n/**\n * The colors of one color scheme, for {@link BuildThemeOptions}. Every color\n * is a hex color (`#rgb` or `#rrggbb`), and everything is optional: omitted\n * options fall back to the stock Studio colors, so an empty object reproduces\n * the stock scheme exactly.\n *\n * @public\n */\nexport interface SchemeThemeOptions {\n /**\n * The accent color — the brand color of the scheme. Replaces the `blue`\n * scale of the palette, which Sanity UI uses for primary buttons, focus\n * rings and links.\n *\n * The stock accent is `#556bfc` (`blue/500` of `@sanity/color`).\n */\n accent?: string\n\n /**\n * The background of the scheme — every other color of the scheme is\n * blended onto it. The dark scheme's background replaces `black` in the\n * palette and the light scheme's replaces `white`.\n *\n * It is kept far enough from the text and accent colors to stay usable:\n * a dark background is made darker until it has enough contrast with them\n * (it can never be lighter than either), and a light background can never\n * be darker than either.\n *\n * The stock backgrounds are `#0d0e12` (dark) and `#ffffff` (light).\n */\n background?: string\n\n /**\n * How strongly text and borders separate from the accent color, between 15\n * and 100. The default is 85, which uses the text color as-is. Above 85 the\n * text scale loses its tint until it is fully neutral at 100 — a high\n * contrast scheme with no mixing of the text and accent colors. Below 85\n * more and more of the accent color mixes into the text scale, giving text\n * and borders more color, until the scale fully adopts the accent hue and\n * saturation at 15.\n */\n contrast?: number\n\n /**\n * The text color. Replaces the `gray` scale of the palette, which Sanity UI\n * uses for text, icons, borders and neutral surfaces. When omitted, it is\n * derived from the accent color: a mostly desaturated version of it, the\n * way the stock `gray` scale carries a hint of the stock blue.\n *\n * The stock text color is `#727892` (`gray/500` of `@sanity/color`).\n */\n text?: string\n}\n\n/**\n * Options for {@link buildTheme} and {@link buildPalette}: the colors of the\n * dark and the light scheme, each with its own accent, text, background and\n * contrast — so the two schemes can differ in more than their background.\n * Both schemes are optional, and so is every color: whatever is omitted\n * falls back to the stock Studio colors, so `buildTheme({})` matches\n * `buildTheme()` from `@sanity/ui/theme` exactly.\n *\n * @public\n */\nexport interface BuildThemeOptions {\n /** The colors of the dark scheme */\n dark?: SchemeThemeOptions\n /** The colors of the light scheme */\n light?: SchemeThemeOptions\n}\n\n/**\n * {@link SchemeThemeOptions} with every option filled in: colors normalized\n * to lowercase `#rrggbb`, the text color derived from the accent when it was\n * omitted, and the contrast clamped into its valid range.\n *\n * @internal\n */\nexport interface ResolvedSchemeOptions {\n accent: string\n background: string\n contrast: number\n text: string\n}\n\n/** {@link BuildThemeOptions} with both schemes resolved @internal */\nexport type ResolvedThemeOptions = Record<ThemeColorSchemeKey, ResolvedSchemeOptions>\n\n/** The color schemes, in the order the tool presents them @internal */\nexport const SCHEMES: ThemeColorSchemeKey[] = ['light', 'dark']\n\n/** The stock accent color — `blue/500` of `@sanity/color` @internal */\nexport const DEFAULT_ACCENT: string = blue[500].hex\n\n/** The stock text color — `gray/500` of `@sanity/color` @internal */\nexport const DEFAULT_TEXT: string = gray[500].hex\n\n/** The stock backgrounds — `black` and `white` of `@sanity/color` @internal */\nexport const DEFAULT_BACKGROUND: Record<ThemeColorSchemeKey, string> = {\n dark: black.hex,\n light: white.hex,\n}\n\n/** The contrast that applies the text color as-is @internal */\nexport const DEFAULT_CONTRAST = 85\n\n/** @internal */\nexport const MINIMUM_CONTRAST = 15\n\n/** @internal */\nexport const MAXIMUM_CONTRAST = 100\n\n/** The keys of the options shape before they were grouped by scheme */\nconst FLAT_OPTION_KEYS = ['accent', 'text', 'background', 'contrast']\n\n/** @internal */\nexport function resolveThemeOptions(options: BuildThemeOptions = {}): ResolvedThemeOptions {\n if (FLAT_OPTION_KEYS.some((key) => key in options)) {\n throw new TypeError(\n 'The `buildTheme` options are grouped by color scheme: pass `{light: {accent, text, background, contrast}, dark: {…}}` instead of one set of colors for both',\n )\n }\n\n return {\n dark: resolveSchemeOptions(options.dark ?? {}, 'dark'),\n light: resolveSchemeOptions(options.light ?? {}, 'light'),\n }\n}\n\nfunction resolveSchemeOptions(\n options: SchemeThemeOptions,\n scheme: ThemeColorSchemeKey,\n): ResolvedSchemeOptions {\n const accent =\n options.accent === undefined\n ? DEFAULT_ACCENT\n : normalizeColor(options.accent, `${scheme}.accent`)\n\n return {\n accent,\n background:\n options.background === undefined\n ? DEFAULT_BACKGROUND[scheme]\n : normalizeColor(options.background, `${scheme}.background`),\n contrast: normalizeContrast(options.contrast, scheme),\n text:\n options.text === undefined\n ? deriveTextColor(accent)\n : normalizeColor(options.text, `${scheme}.text`),\n }\n}\n\n/**\n * Derives the text color from an accent color, keeping the relationship the\n * stock palette has between `gray/500` and `blue/500`: the text color takes\n * the accent's hue (offset the way the stock gray is offset from the stock\n * blue), carries about an eighth of its saturation, and keeps the stock text\n * lightness. Deriving from the stock accent returns the stock text color.\n *\n * @internal\n */\nexport function deriveTextColor(accent: string): string {\n const accentHsl = hexToHsl(normalizeColor(accent, 'accent'))\n const defaultAccent = hexToHsl(DEFAULT_ACCENT)\n const defaultText = hexToHsl(DEFAULT_TEXT)\n\n return hslToHex({\n h: defaultText.h + (accentHsl.h - defaultAccent.h),\n s: Math.min(1, defaultText.s * (accentHsl.s / defaultAccent.s)),\n l: defaultText.l,\n })\n}\n\nfunction normalizeColor(value: string, name: string): string {\n if (typeof value !== 'string' || !isColor(value)) {\n throw new TypeError(\n `Invalid \\`${name}\\` color: ${JSON.stringify(value)} — expected a hex color like #556bfc`,\n )\n }\n\n const lower = value.toLowerCase()\n\n return lower.length === 4\n ? `#${lower[1]}${lower[1]}${lower[2]}${lower[2]}${lower[3]}${lower[3]}`\n : lower\n}\n\nfunction normalizeContrast(value: number | undefined, scheme: ThemeColorSchemeKey): number {\n if (value === undefined) {\n return DEFAULT_CONTRAST\n }\n\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new TypeError(\n `Invalid \\`${scheme}.contrast\\`: ${JSON.stringify(value)} — expected a number between ${MINIMUM_CONTRAST} and ${MAXIMUM_CONTRAST}`,\n )\n }\n\n return Math.min(MAXIMUM_CONTRAST, Math.max(MINIMUM_CONTRAST, value))\n}\n","import {\n color,\n COLOR_TINTS,\n type ColorHueKey,\n type ColorTintKey,\n type ColorTints,\n} from '@sanity/color'\nimport {type ThemeColorSchemeKey} from '@sanity/ui/theme'\n\nimport {hexToHsl, type Hsl, hslToHex, mixHue, relativeLuminance} from './hsl'\nimport {\n type BuildThemeOptions,\n DEFAULT_ACCENT,\n DEFAULT_CONTRAST,\n DEFAULT_TEXT,\n MAXIMUM_CONTRAST,\n MINIMUM_CONTRAST,\n type ResolvedSchemeOptions,\n resolveThemeOptions,\n} from './options'\n\n/**\n * The lightness band the accent and text colors are clamped into — anchors\n * outside it would squeeze most of their scale's tints into an\n * indistinguishable sliver, messing with the rest of the scale.\n */\nconst MINIMUM_ANCHOR_LIGHTNESS = 0.25\nconst MAXIMUM_ANCHOR_LIGHTNESS = 0.75\n\n/**\n * The contrast ratio the dark background must reach against the 400 tints of\n * the text and accent scales — the tints Sanity UI paints muted text and\n * solid buttons with on dark backgrounds. The stock palette sits at ~6.8.\n */\nconst MINIMUM_DARK_BACKGROUND_CONTRAST = 4.5\n\n/** How much lightness each step of a background adjustment removes or adds */\nconst BACKGROUND_LIGHTNESS_STEP = 0.005\n\n/**\n * A color palette generated by {@link buildPalette}: the `palette` config of\n * `buildTheme` from `@sanity/ui/theme`, with every color as a hex string.\n *\n * @public\n */\nexport type GeneratedColorPalette = {black: string; white: string} & Record<\n ColorHueKey,\n Record<ColorTintKey, string>\n>\n\n/**\n * The palettes generated by {@link buildPalette} — one per color scheme.\n *\n * @public\n */\nexport type GeneratedColorPalettes = Record<ThemeColorSchemeKey, GeneratedColorPalette>\n\n/**\n * Generates a Sanity UI color palette for each color scheme from the theme\n * options: in each palette the scheme's accent color replaces the `blue`\n * scale, its text color the `gray` scale, and the backgrounds replace `black`\n * and `white`. All other hues keep their stock `@sanity/color` values. Called\n * with the stock colors, both palettes come back as the stock palette\n * byte-for-byte.\n *\n * ```ts\n * import {buildPalette} from '@sanity/themer'\n *\n * const {light, dark} = buildPalette({light: {accent: '#556bfc'}})\n * ```\n *\n * @public\n */\nexport function buildPalette(options: BuildThemeOptions = {}): GeneratedColorPalettes {\n const resolved = resolveThemeOptions(options)\n\n return {\n dark: buildSchemePalette('dark', resolved.dark, resolved.light.background),\n light: buildSchemePalette('light', resolved.light, resolved.dark.background),\n }\n}\n\n/**\n * Generates the palette of one scheme. The scheme's own background takes the\n * slot the scheme paints with (`black` for dark, `white` for light), while\n * the other slot — which a scheme only touches for a few inverted details —\n * takes the other scheme's background, so the theme stays one palette.\n */\nfunction buildSchemePalette(\n key: ThemeColorSchemeKey,\n scheme: ResolvedSchemeOptions,\n otherBackground: string,\n): GeneratedColorPalette {\n const accentAnchor = clampAnchorLightness(hexToHsl(scheme.accent))\n const textAnchor = clampAnchorLightness(hexToHsl(scheme.text))\n const grayAnchor = applyContrast(textAnchor, accentAnchor, scheme.contrast)\n\n const blueTints = remapTints(color.blue, hexToHsl(DEFAULT_ACCENT), accentAnchor)\n const grayTints = remapTints(color.gray, hexToHsl(DEFAULT_TEXT), grayAnchor)\n\n const anchorLuminances = [\n relativeLuminance(hslToHex(grayAnchor)),\n relativeLuminance(hslToHex(accentAnchor)),\n ]\n\n const darkBackground = key === 'dark' ? scheme.background : otherBackground\n const lightBackground = key === 'light' ? scheme.background : otherBackground\n\n return {\n black: darkenBackground(darkBackground, {\n anchorLuminances,\n tints: [grayTints['400'], blueTints['400']],\n }),\n white: lightenBackground(lightBackground, anchorLuminances),\n gray: grayTints,\n blue: blueTints,\n purple: tintHexes(color.purple),\n magenta: tintHexes(color.magenta),\n red: tintHexes(color.red),\n orange: tintHexes(color.orange),\n yellow: tintHexes(color.yellow),\n green: tintHexes(color.green),\n cyan: tintHexes(color.cyan),\n }\n}\n\n/**\n * Mixes the accent color into the text color according to the contrast: 85\n * applies the text color as-is, 100 removes its tint entirely, and lower\n * values rotate and saturate it towards the accent.\n */\nfunction applyContrast(text: Hsl, accent: Hsl, contrast: number): Hsl {\n if (contrast === DEFAULT_CONTRAST) {\n return text\n }\n\n if (contrast > DEFAULT_CONTRAST) {\n const amount = (contrast - DEFAULT_CONTRAST) / (MAXIMUM_CONTRAST - DEFAULT_CONTRAST)\n\n return {h: text.h, s: text.s * (1 - amount), l: text.l}\n }\n\n const amount = (DEFAULT_CONTRAST - contrast) / (DEFAULT_CONTRAST - MINIMUM_CONTRAST)\n\n return {\n h: mixHue(text.h, accent.h, amount),\n s: text.s + (accent.s - text.s) * amount,\n l: text.l,\n }\n}\n\n/**\n * Rebuilds a stock tint scale around a new anchor color, where `from` is the\n * scale's stock 500 tint: hues rotate along, saturation scales\n * proportionally, and lightness is remapped piecewise so the anchor takes the\n * new lightness while the scale keeps spanning light to dark. When the anchor\n * matches the stock one, every tint comes back unchanged.\n */\nfunction remapTints(tints: ColorTints, from: Hsl, to: Hsl): Record<ColorTintKey, string> {\n const rotation = to.h - from.h\n const result: Partial<Record<ColorTintKey, string>> = {}\n\n for (const tint of COLOR_TINTS) {\n const value = hexToHsl(tints[tint].hex)\n\n result[tint] = hslToHex({\n h: value.h + rotation,\n s: remapSaturation(value.s, from.s, to.s),\n l: remapLightness(value.l, from.l, to.l),\n })\n }\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- the loop assigns every tint key\n return result as Record<ColorTintKey, string>\n}\n\nfunction remapSaturation(value: number, from: number, to: number): number {\n if (from === to) {\n return value\n }\n\n return Math.min(1, value * (to / from))\n}\n\nfunction remapLightness(value: number, from: number, to: number): number {\n if (from === to) {\n return value\n }\n\n if (value <= from) {\n return value * (to / from)\n }\n\n return to + ((value - from) * (1 - to)) / (1 - from)\n}\n\nfunction clampAnchorLightness(anchor: Hsl): Hsl {\n const l = Math.min(MAXIMUM_ANCHOR_LIGHTNESS, Math.max(MINIMUM_ANCHOR_LIGHTNESS, anchor.l))\n\n return l === anchor.l ? anchor : {...anchor, l}\n}\n\n/**\n * Enforces the dark background rules: it can never be lighter than the text\n * or accent colors, and it must reach enough contrast with the 400 tints of\n * their scales — it is made darker until it does (or bottoms out at black).\n */\nfunction darkenBackground(\n hex: string,\n rules: {anchorLuminances: number[]; tints: string[]},\n): string {\n const maximumLuminance = Math.min(...rules.anchorLuminances)\n const tintLuminances = rules.tints.map((tint) => relativeLuminance(tint))\n\n const isDarkEnough = (background: string): boolean => {\n const luminance = relativeLuminance(background)\n\n return (\n luminance < maximumLuminance &&\n tintLuminances.every(\n (tintLuminance) =>\n (tintLuminance + 0.05) / (luminance + 0.05) >= MINIMUM_DARK_BACKGROUND_CONTRAST,\n )\n )\n }\n\n const {h, s, l} = hexToHsl(hex)\n let lightness = l\n let current = hex\n\n while (!isDarkEnough(current) && lightness > 0) {\n lightness = Math.max(0, lightness - BACKGROUND_LIGHTNESS_STEP)\n current = hslToHex({h, s, l: lightness})\n }\n\n return current\n}\n\n/**\n * Enforces the light background rule: it can never be darker than the text\n * or accent colors — it is made lighter until it is (or tops out at white).\n */\nfunction lightenBackground(hex: string, anchorLuminances: number[]): string {\n const minimumLuminance = Math.max(...anchorLuminances)\n\n const {h, s, l} = hexToHsl(hex)\n let lightness = l\n let current = hex\n\n while (relativeLuminance(current) <= minimumLuminance && lightness < 1) {\n lightness = Math.min(1, lightness + BACKGROUND_LIGHTNESS_STEP)\n current = hslToHex({h, s, l: lightness})\n }\n\n return current\n}\n\nfunction tintHexes(tints: ColorTints): Record<ColorTintKey, string> {\n const result: Partial<Record<ColorTintKey, string>> = {}\n\n for (const tint of COLOR_TINTS) {\n result[tint] = tints[tint].hex\n }\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- the loop assigns every tint key\n return result as Record<ColorTintKey, string>\n}\n","import {\n buildTheme as buildUITheme,\n type RootTheme,\n type ThemeColorSchemes_v2,\n v0_v2,\n v2_v0,\n} from '@sanity/ui/theme'\n\nimport {buildPalette} from './buildPalette'\nimport type {BuildThemeOptions} from './options'\n\n/**\n * Generates a Studio theme from a handful of colors per color scheme, by\n * replacing the color palette that the `buildTheme` from `@sanity/ui/theme`\n * otherwise fills with `@sanity/color`: in each scheme the accent color\n * replaces the `blue` scale (primary buttons, focus rings, links), the\n * optional text color the `gray` scale (text, icons, borders), and the\n * optional background replaces `black` (dark) or `white` (light). The result\n * is the same type of theme that `@sanity/ui/theme` builds, ready for the\n * `theme` property of a Studio config.\n *\n * ```ts\n * import {buildTheme} from '@sanity/themer'\n * import {defineConfig} from 'sanity'\n *\n * export const theme = buildTheme({\n * light: {\n * accent: '#556bfc',\n * text: '#727892', // optional — derived from `accent` when omitted\n * background: '#ffffff', // optional\n * contrast: 85, // optional, 15–100\n * },\n * dark: {\n * accent: '#556bfc',\n * background: '#0d0e12',\n * },\n * })\n *\n * export default defineConfig({\n * theme,\n * // ...rest of the config\n * })\n * ```\n *\n * Every option is optional and falls back to the stock Studio colors: called\n * with the stock colors — like the example — or with no options at all, it\n * returns the exact same colors as `buildTheme()` from `@sanity/ui/theme`.\n *\n * @public\n */\nexport function buildTheme(options: BuildThemeOptions = {}): RootTheme {\n const palettes = buildPalette(options)\n\n // Sanity UI renders both schemes of a theme from one palette, so each\n // scheme gets a theme of its own palette, and the two are composed into one\n // theme that takes its light scheme from the one and its dark scheme from\n // the other. The scheme getters keep Sanity UI's lazy rendering: a scheme is\n // only computed once something reads it.\n const light = v0_v2(buildUITheme({palette: palettes.light}))\n const dark = v0_v2(buildUITheme({palette: palettes.dark}))\n\n const color: ThemeColorSchemes_v2 = {\n get light() {\n return light.color.light\n },\n get dark() {\n return dark.color.dark\n },\n }\n\n return v2_v0({...light, color})\n}\n","import type {BuildThemeOptions} from './options'\n\n/**\n * A preset theme: a named set of {@link BuildThemeOptions} ready to pass to\n * `buildTheme`.\n *\n * @public\n */\nexport interface ThemePreset {\n slug: string\n title: string\n /** The preset's theme options, ready to pass to `buildTheme` */\n options: BuildThemeOptions\n}\n\n/**\n * The hosted Themer presets had one accent and one text color for both\n * schemes, and a background per scheme\n */\nfunction scheme(accent: string, text: string, backgrounds: {dark: string; light: string}) {\n return {\n dark: {accent, text, background: backgrounds.dark},\n light: {accent, text, background: backgrounds.light},\n } satisfies BuildThemeOptions\n}\n\n/**\n * Preset themes for `buildTheme`, carried over from the hosted Themer service\n * (themer.sanity.build) presets: each one maps the legacy preset's primary\n * hue to `accent`, its default hue to `text` and its lightest/darkest colors\n * to the backgrounds of the light and dark scheme.\n *\n * ```ts\n * import {buildTheme, presets} from '@sanity/themer'\n *\n * const verdant = presets.find((preset) => preset.slug === 'verdant')\n * const theme = buildTheme(verdant.options)\n * ```\n *\n * @public\n */\nexport const presets: ThemePreset[] = [\n {\n slug: 'studio',\n title: 'Studio',\n options: {},\n },\n {\n slug: 'dew',\n title: 'Dew',\n options: scheme('#d1a308', '#5e63b4', {dark: '#0d0d15', light: '#fcfcfd'}),\n },\n {\n slug: 'pink-synth',\n title: 'Pink Synth',\n options: scheme('#ec4899', '#8b6584', {dark: '#171721', light: '#f7f2f5'}),\n },\n {\n slug: 'pixel-art',\n title: 'Pixel Art',\n options: scheme('#f10784', '#57619c', {dark: '#0d0e15', light: '#fcfcfd'}),\n },\n {\n slug: 'retro-colonial',\n title: 'Retro Colonial',\n options: scheme('#fa7a78', '#8bb9b5', {dark: '#0d1515', light: '#fcfdfd'}),\n },\n {\n slug: 'rosabel',\n title: 'Rosabel',\n options: scheme('#ed2555', '#9d8966', {dark: '#15120d', light: '#fdfdfc'}),\n },\n {\n slug: 'stereofidelic',\n title: 'Stereofidelic',\n options: scheme('#f13009', '#678e9a', {dark: '#0e1315', light: '#fcfdfd'}),\n },\n {\n slug: 'verdant',\n title: 'Verdant',\n options: sc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";
2
+ import { addTransitionType } from "react";
3
+ /**
4
+ * The Studio navbar's root, the `Card` that draws its bottom border — its
5
+ * test id is stable and unique to the navbar, unlike its `data-ui` name
6
+ */
7
+ const NAVBAR_SELECTOR = "[data-testid=\"studio-navbar\"]";
8
+ var layout = "pcwcs0i", layoutTransitionType = "sanity-themer", viewTransitionClasses = {
9
+ navbarButton: { update: {
10
+ pcwcs02: "none",
11
+ pcwcs03: "none",
12
+ pcwcs00: "pcwcs05",
13
+ pcwcs01: "pcwcs05",
14
+ pcwcs04: "pcwcs05",
15
+ default: "none"
16
+ } },
17
+ navbarButtonTooltip: { update: {
18
+ pcwcs02: "none",
19
+ pcwcs03: "none",
20
+ pcwcs00: "auto",
21
+ pcwcs01: "auto",
22
+ default: "none"
23
+ } },
24
+ sidebar: {
25
+ enter: {
26
+ pcwcs00: "pcwcs0d",
27
+ default: "none"
28
+ },
29
+ update: {
30
+ pcwcs02: "none",
31
+ pcwcs03: "none",
32
+ pcwcs04: "auto",
33
+ default: "none"
34
+ },
35
+ exit: {
36
+ pcwcs01: "pcwcs0f",
37
+ default: "none"
38
+ }
39
+ },
40
+ splitscreen: {
41
+ enter: {
42
+ pcwcs02: "pcwcs0g",
43
+ default: "none"
44
+ },
45
+ update: {
46
+ pcwcs04: "auto",
47
+ default: "none"
48
+ },
49
+ exit: {
50
+ pcwcs03: "pcwcs0h",
51
+ default: "none"
52
+ }
53
+ },
54
+ studio: { update: {
55
+ pcwcs00: "pcwcs06",
56
+ pcwcs01: "pcwcs06",
57
+ pcwcs02: "pcwcs09",
58
+ pcwcs03: "pcwcs09",
59
+ pcwcs04: "auto",
60
+ default: "none"
61
+ } }
62
+ }, viewTransitionTypes = {
63
+ open: "pcwcs00",
64
+ close: "pcwcs01",
65
+ "split-screen:open": "pcwcs02",
66
+ "split-screen:close": "pcwcs03",
67
+ crossfade: "pcwcs04"
68
+ };
69
+ /**
70
+ * Adds the default sanity-themer transition type, which allows custom view transition overrides, as well as customization in userland
71
+ */
72
+ function addThemerTransitionType(type) {
73
+ if (!(type in viewTransitionTypes)) throw Error("Invalid transition type", { cause: { type } });
74
+ addTransitionType(viewTransitionTypes[type]), addTransitionType(layoutTransitionType);
75
+ }
76
+ /** The slug of the theme the Studio config was generated from @internal */
77
+ const CONFIG_SLUG = "config", CONFIG_TITLE = "Studio config", UNTITLED_THEME = "Untitled theme", initialThemerState = {
78
+ active: null,
79
+ custom: [],
80
+ removed: [],
81
+ order: []
82
+ }, presetsWithSource = presets.map((preset) => Object.assign({}, preset, { source: "preset" }));
83
+ /**
84
+ * Resolves the list of themes: the presets, then the user's own themes —
85
+ * rearranged into the order the user dragged them into, with themes that
86
+ * order does not know about kept in that default order after the ones it
87
+ * does. Removed themes are set aside so they can be restored. The configured
88
+ * theme is not in the list — `ThemeList` shows it ahead of it — and it is
89
+ * what applies when no listed theme does: `active` is `undefined` for it, and
90
+ * for an applied slug that no longer resolves.
91
+ *
92
+ * @internal
93
+ */
94
+ function resolveThemes(state) {
95
+ let all = [...presetsWithSource];
96
+ for (let theme of state.custom) all.push({
97
+ slug: theme.slug,
98
+ title: theme.title,
99
+ options: theme.options,
100
+ source: "custom",
101
+ ...theme.palette ? { palette: theme.palette } : {}
102
+ });
103
+ let position = new Map(state.order.map((slug, index) => [slug, index])), rank = (theme) => position.get(theme.slug) ?? state.order.length;
104
+ all.sort((a, b) => rank(a) - rank(b));
105
+ let removedSlugs = new Set(state.removed), themes = all.filter((theme) => !removedSlugs.has(theme.slug));
106
+ return {
107
+ themes,
108
+ removed: all.filter((theme) => removedSlugs.has(theme.slug)),
109
+ active: themes.find((theme) => theme.slug === state.active)
110
+ };
111
+ }
112
+ /**
113
+ * Creates a custom theme with a slug that cannot collide with the presets or
114
+ * the configured theme.
115
+ *
116
+ * @internal
117
+ */
118
+ function createCustomTheme(title, options, palette) {
119
+ return {
120
+ slug: `custom-${randomId()}`,
121
+ title,
122
+ options,
123
+ ...palette ? { palette } : {}
124
+ };
125
+ }
126
+ /** The title of a duplicated theme @internal */
127
+ function duplicateTitle(title) {
128
+ return `${displayTitle(title)} copy`;
129
+ }
130
+ /** The title to show for a theme, falling back when the user cleared it @internal */
131
+ function displayTitle(title) {
132
+ return title.trim() || "Untitled theme";
133
+ }
134
+ function randomId() {
135
+ return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 10)}`;
136
+ }
137
+ export { displayTitle as a, resolveThemes as c, viewTransitionClasses as d, NAVBAR_SELECTOR as f, createCustomTheme as i, addThemerTransitionType as l, CONFIG_TITLE as n, duplicateTitle as o, UNTITLED_THEME as r, initialThemerState as s, CONFIG_SLUG as t, layout as u };
138
+
139
+ //# sourceMappingURL=themes-Bxgltjmb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themes-Bxgltjmb.js","names":["\"default\""],"sources":["../src/tool/constants.ts","../src/tool/ViewTransitions.css.ts","../src/tool/addThemerTransitionType.ts","../src/tool/themes.ts"],"sourcesContent":["export const MIN_MEDIA_INDEX_FOR_SPLIT_SCREEN = 3\n/**\n * The Studio navbar's root, the `Card` that draws its bottom border — its\n * test id is stable and unique to the navbar, unlike its `data-ui` name\n */\nexport const NAVBAR_SELECTOR = '[data-testid=\"studio-navbar\"]'\n","import {\n createViewTransition,\n globalStyle,\n keyframes,\n style,\n type GlobalStyleRule,\n} from '@vanilla-extract/css'\nimport type {ViewTransitionClass} from 'react'\n\nfunction createViewTransitionType(\n rules: Partial<Record<'new' | 'old' | 'group' | 'imagePair', GlobalStyleRule>>,\n debugId?: string,\n) {\n const type = style({}, debugId)\n if (rules.new) {\n globalStyle(`::view-transition-new(.${type})`, rules.new)\n }\n if (rules.old) {\n globalStyle(`::view-transition-old(.${type})`, rules.old)\n }\n if (rules.group) {\n globalStyle(`::view-transition-group(.${type})`, rules.group)\n }\n if (rules.imagePair) {\n globalStyle(`::view-transition-image-pair(.${type})`, rules.imagePair)\n }\n return type\n}\n\n/**\n * The transition type of the layout's motions — what `ThemerLayout` adds to\n * every transition it starts, and React passes on to the view transition.\n * `:active-view-transition-type()` tells the layout's transitions from any\n * other on the page while they run.\n *\n * It's used on all transition types that userland might want to participate in, for example by setting their own:\n * ```tsx\n * <ViewTransition update={{'sanity-themer': 'auto', default: 'none'}}>\n * ```\n */\nexport const layoutTransitionType = 'sanity-themer'\n\n/**\n * Used with addTransitionType, and on `update` props on <ViewTransition> as the object key\n */\nexport const viewTransitionTypes = {\n 'open': createViewTransition('open'),\n 'close': createViewTransition('close'),\n 'split-screen:open': createViewTransition('split-screen-open'),\n 'split-screen:close': createViewTransition('split-screen-close'),\n 'crossfade': createViewTransition('crossfade'),\n}\n\nconst navbarButtonUpdateTransition = createViewTransitionType({\n new: {animation: 'none'},\n old: {display: 'none'},\n})\n\nconst resizeStudioRules = {inlineSize: '100%', blockSize: '100%', objectFit: 'fill'} as const\nconst resizeStudioTransition = createViewTransitionType(\n {old: resizeStudioRules, new: resizeStudioRules},\n 'resizeStudio',\n)\n\nconst splitScreenFilter = 'blur(12px)'\nconst splitStudioTransition = createViewTransitionType({\n old: {\n ...resizeStudioRules,\n animationName: keyframes({to: {opacity: 0, filter: splitScreenFilter}}),\n },\n new: {\n ...resizeStudioRules,\n animationName: keyframes({from: {opacity: 0, filter: splitScreenFilter}}),\n },\n})\n/**\n * The split copy slides in from the side, or out to it — hidden for the first\n * quarter of the way in, and for the last quarter of the way out\n */\nconst splitScreenSlideIn = keyframes({\n 'from': {transform: 'translateX(-100%)', opacity: 0},\n '25%': {opacity: 0},\n})\nconst splitScreenSlideOut = keyframes({\n 'to': {transform: 'translateX(-100%)', opacity: 0},\n '75%': {opacity: 0},\n})\n\nexport const viewTransitionClasses = {\n navbarButton: {\n update: {\n [viewTransitionTypes['split-screen:open']]: 'none',\n [viewTransitionTypes['split-screen:close']]: 'none',\n [viewTransitionTypes.open]: navbarButtonUpdateTransition,\n [viewTransitionTypes.close]: navbarButtonUpdateTransition,\n [viewTransitionTypes.crossfade]: navbarButtonUpdateTransition,\n default: 'none',\n },\n } as const satisfies Record<string, ViewTransitionClass>,\n navbarButtonTooltip: {\n update: {\n [viewTransitionTypes['split-screen:open']]: 'none',\n [viewTransitionTypes['split-screen:close']]: 'none',\n [viewTransitionTypes.open]: 'auto',\n [viewTransitionTypes.close]: 'auto',\n default: 'none',\n },\n } as const satisfies Record<string, ViewTransitionClass>,\n sidebar: {\n enter: {\n [viewTransitionTypes.open]: createViewTransitionType(\n {new: {animationName: keyframes({from: {transform: 'translateX(100%)'}})}},\n 'panelSlideIn',\n ),\n default: 'none',\n },\n update: {\n [viewTransitionTypes['split-screen:open']]: 'none',\n [viewTransitionTypes['split-screen:close']]: 'none',\n [viewTransitionTypes.crossfade]: 'auto',\n default: 'none',\n },\n exit: {\n [viewTransitionTypes.close]: createViewTransitionType(\n {old: {animationName: keyframes({to: {transform: 'translateX(100%)'}})}},\n 'panelSlideOut',\n ),\n default: 'none',\n },\n } as const satisfies Record<string, ViewTransitionClass>,\n splitscreen: {\n enter: {\n [viewTransitionTypes['split-screen:open']]: createViewTransitionType({\n new: {animationName: splitScreenSlideIn},\n }),\n default: 'none',\n },\n update: {\n [viewTransitionTypes.crossfade]: 'auto',\n default: 'none',\n },\n exit: {\n [viewTransitionTypes['split-screen:close']]: createViewTransitionType({\n old: {animationName: splitScreenSlideOut},\n }),\n default: 'none',\n },\n } as const satisfies Record<string, ViewTransitionClass>,\n studio: {\n update: {\n // [viewTransitionTypes.crossfade]: createViewTransitionType(\n // {\n // imagePair: {perspective: '1000px', transformStyle: 'preserve-3d'},\n // group: {animationDuration: '6s !important', animationTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1) !important', animationFillMode: 'both'},\n // old: {animationName: flipOut, backfaceVisibility: 'hidden', },\n // new: {animationName: flipIn, backfaceVisibility: 'hidden', }},\n // 'crossfadeStudio',\n // ),\n [viewTransitionTypes['open']]: resizeStudioTransition,\n [viewTransitionTypes['close']]: resizeStudioTransition,\n [viewTransitionTypes['split-screen:open']]: splitStudioTransition,\n [viewTransitionTypes['split-screen:close']]: splitStudioTransition,\n [viewTransitionTypes.crossfade]: 'auto',\n default: 'none',\n },\n } as const satisfies Record<string, ViewTransitionClass>,\n}\n\n/**\n * Default animation timings for all Themer view transitions\n */\nglobalStyle(\n `:root:active-view-transition-type(${layoutTransitionType})::view-transition-group(*)`,\n {animationDuration: '320ms', animationTimingFunction: 'cubic-bezier(0.65, 0, 0.35, 1)'},\n)\n\nglobalStyle(\n [\n `:root:active-view-transition-type(${viewTransitionTypes['split-screen:open']})::view-transition-group(*)`,\n `:root:active-view-transition-type(${viewTransitionTypes['split-screen:close']})::view-transition-group(*)`,\n ].join(','),\n {animationDuration: '480ms'},\n)\n\n/** The layout's `Flex` positions the sidebar overlay on small screens */\nexport const layout = style({\n position: 'relative',\n})\n\n/**\n * Disable animations automatically for themer view transitions if the user signals to do so\n */\nglobalStyle(\n `:root:active-view-transition-type(${layoutTransitionType})::view-transition-group(*),:root:active-view-transition-type(${layoutTransitionType})::view-transition-old(*),:root:active-view-transition-type(${layoutTransitionType})::view-transition-new(*)`,\n {\n '@media': {\n '(prefers-reduced-motion: reduce)': {\n animation: 'none !important',\n },\n },\n },\n)\n","import {addTransitionType} from 'react'\n\nimport {layoutTransitionType, viewTransitionTypes} from './ViewTransitions.css'\n\n/**\n * Adds the default sanity-themer transition type, which allows custom view transition overrides, as well as customization in userland\n */\nexport function addThemerTransitionType(type: keyof typeof viewTransitionTypes) {\n if (!(type in viewTransitionTypes)) {\n throw new Error(`Invalid transition type`, {cause: {type}})\n }\n addTransitionType(viewTransitionTypes[type])\n // Used to mark that a themer transition is happening, can be styled with vanilla css, but also by setting class props on <ViewTransition>\n addTransitionType(layoutTransitionType)\n}\n","import type {BuildThemeOptions} from '../theme/options'\nimport {presets} from '../theme/presets'\nimport type {ImagePalette} from './imagePalette'\n\n/**\n * Where a theme in the themer list comes from: the theme the Studio config\n * was generated from, one of the presets defined in code, or one the user\n * added in the tool. Only custom themes are editable — the others are\n * duplicated into a custom theme first.\n */\ntype ThemerThemeSource = 'config' | 'preset' | 'custom'\n\n/** A theme the themer tool lists @internal */\nexport interface ThemerTheme {\n slug: string\n title: string\n options: BuildThemeOptions\n source: ThemerThemeSource\n /** The palette of the image the theme's colors were taken from, for custom themes */\n palette?: ImagePalette\n}\n\n/** A theme the user added in the tool, as persisted @internal */\nexport interface CustomTheme {\n slug: string\n title: string\n options: BuildThemeOptions\n /** The palette of the image the theme's colors were taken from */\n palette?: ImagePalette\n}\n\n/** The persisted themer state @internal */\nexport interface ThemerState {\n /**\n * The slug of the applied theme — `null` applies nothing on top of the\n * Studio's configured theme\n */\n active: string | null\n /** The themes the user added */\n custom: CustomTheme[]\n /** The slugs of the themes the user removed from the list */\n removed: string[]\n /**\n * The slugs of the themes in the order the user arranged them — themes not\n * in it (new presets, themes added since) follow in their default order\n */\n order: string[]\n}\n\n/** The slug of the theme the Studio config was generated from @internal */\nexport const CONFIG_SLUG = 'config'\n\n/** The title of the theme the Studio config was generated from */\nexport const CONFIG_TITLE = 'Studio config'\n\n/** The title new themes start out with @internal */\nexport const UNTITLED_THEME = 'Untitled theme'\n\n/** @internal */\nexport const initialThemerState: ThemerState = {active: null, custom: [], removed: [], order: []}\n\n/** The themes the tool works with, derived from the persisted state @internal */\nexport interface ResolvedThemes {\n /** The themes to pick from, in list order */\n themes: ThemerTheme[]\n /** The removed themes, which can be restored */\n removed: ThemerTheme[]\n /** The applied theme */\n active: ThemerTheme | undefined\n}\n\nconst presetsWithSource = presets.map((preset) =>\n Object.assign({}, preset, {source: 'preset' as const}),\n)\n\n/**\n * Resolves the list of themes: the presets, then the user's own themes —\n * rearranged into the order the user dragged them into, with themes that\n * order does not know about kept in that default order after the ones it\n * does. Removed themes are set aside so they can be restored. The configured\n * theme is not in the list — `ThemeList` shows it ahead of it — and it is\n * what applies when no listed theme does: `active` is `undefined` for it, and\n * for an applied slug that no longer resolves.\n *\n * @internal\n */\nexport function resolveThemes(state: ThemerState): ResolvedThemes {\n const all: ThemerTheme[] = [...presetsWithSource]\n\n for (const theme of state.custom) {\n all.push({\n slug: theme.slug,\n title: theme.title,\n options: theme.options,\n source: 'custom',\n ...(theme.palette ? {palette: theme.palette} : {}),\n })\n }\n\n const position = new Map(state.order.map((slug, index) => [slug, index]))\n const rank = (theme: ThemerTheme) => position.get(theme.slug) ?? state.order.length\n\n // A stable sort: the themes the order does not know about keep their default order\n all.sort((a, b) => rank(a) - rank(b))\n\n const removedSlugs = new Set(state.removed)\n const themes = all.filter((theme) => !removedSlugs.has(theme.slug))\n const removed = all.filter((theme) => removedSlugs.has(theme.slug))\n const active = themes.find((theme) => theme.slug === state.active)\n\n return {themes, removed, active}\n}\n\n/**\n * Creates a custom theme with a slug that cannot collide with the presets or\n * the configured theme.\n *\n * @internal\n */\nexport function createCustomTheme(\n title: string,\n options: BuildThemeOptions,\n palette?: ImagePalette,\n): CustomTheme {\n return {slug: `custom-${randomId()}`, title, options, ...(palette ? {palette} : {})}\n}\n\n/** The title of a duplicated theme @internal */\nexport function duplicateTitle(title: string): string {\n return `${displayTitle(title)} copy`\n}\n\n/** The title to show for a theme, falling back when the user cleared it @internal */\nexport function displayTitle(title: string): string {\n return title.trim() || UNTITLED_THEME\n}\n\nfunction randomId(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID()\n }\n\n return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 10)}`\n}\n"],"mappings":";;;;;;AAKA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEE/B,SAAgB,wBAAwB,MAAwC;CAC9E,IAAI,EAAE,QAAQ,sBACZ,MAAU,MAAM,2BAA2B,EAAC,OAAO,EAAC,KAAI,EAAC,CAAC;CAI5D,AAFA,kBAAkB,oBAAoB,KAAK,GAE3C,kBAAkB,oBAAoB;AACxC;;ACoCA,MAAa,cAAc,UAGd,eAAe,i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AS,WAAmB;CAK1B,OAJI,OAAO,SAAW,OAAe,OAAO,OAAO,cAAe,aACzD,OAAO,WAAW,IAGpB,GAAG,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,EAAE;AAC5E"}
package/dist/tool.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { t as BuildThemeOptions } from "./options-CU-emn_p.js";
2
1
  /**
3
2
  * Options for the {@link themerTool} plugin.
4
3
  *
@@ -9,20 +8,10 @@ import { t as BuildThemeOptions } from "./options-CU-emn_p.js";
9
8
  */
10
9
  interface ThemerToolOptions {
11
10
  /**
12
- * The `buildTheme` options that the Studio's configured theme was generated
13
- * from — the themer starts editing from these, so pass the same object that
14
- * the `theme` in the Studio config uses:
15
- *
16
- * ```ts
17
- * const config: BuildThemeOptions = {light: {accent: '#1cb485'}, dark: {accent: '#22fca8'}}
18
- *
19
- * export default defineConfig({
20
- * theme: buildTheme(config),
21
- * plugins: [themerTool({config})],
22
- * })
23
- * ```
11
+ * What the tool goes by in the Studio navbar — the toggle's label and
12
+ * tooltip. Defaults to `Themer`.
24
13
  */
25
- config?: BuildThemeOptions;
14
+ title?: string;
26
15
  }
27
16
  /**
28
17
  * A Studio plugin that adds a themer sidebar for `buildTheme` themes: a
@@ -52,6 +41,6 @@ interface ThemerToolOptions {
52
41
  *
53
42
  * @alpha
54
43
  */
55
- export declare const themerTool: import("sanity").Plugin<void | ThemerToolOptions>;
56
- export type { ThemerToolOptions };
44
+ declare const themerTool: import("sanity").Plugin<void | ThemerToolOptions>;
45
+ export { type ThemerToolOptions, themerTool };
57
46
  //# sourceMappingURL=tool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","names":[],"sources":["../src/tool/plugin.tsx"],"mappings":";;;;;;;;;UAciB;;;;;;;;;;;;;;;EAef,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA+BE,6BAAU,cAAA"}
1
+ {"version":3,"file":"tool.d.ts","names":[],"sources":["../src/tool/plugin.tsx"],"mappings":"AAeA;;;;;;;;UAAiB;;;;;EAKf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+BW,6BAAU,cAAA"}