@epilot/spark-ui 0.30.0 → 0.30.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/components/attachment.d.cts +1 -1
  2. package/dist/components/attachment.d.ts +1 -1
  3. package/dist/components/autocomplete.cjs +9 -2
  4. package/dist/components/autocomplete.cjs.map +1 -1
  5. package/dist/components/autocomplete.js +10 -3
  6. package/dist/components/autocomplete.js.map +1 -1
  7. package/dist/components/bubble.d.cts +1 -1
  8. package/dist/components/bubble.d.ts +1 -1
  9. package/dist/components/button.d.cts +2 -2
  10. package/dist/components/button.d.ts +2 -2
  11. package/dist/components/combobox.cjs +2 -1
  12. package/dist/components/combobox.cjs.map +1 -1
  13. package/dist/components/combobox.js +3 -2
  14. package/dist/components/combobox.js.map +1 -1
  15. package/dist/components/empty-state.d.cts +1 -1
  16. package/dist/components/empty-state.d.ts +1 -1
  17. package/dist/components/field.cjs +25 -7
  18. package/dist/components/field.cjs.map +1 -1
  19. package/dist/components/field.d.cts +3 -1
  20. package/dist/components/field.d.ts +3 -1
  21. package/dist/components/field.js +25 -8
  22. package/dist/components/field.js.map +1 -1
  23. package/dist/components/info-block.d.cts +1 -1
  24. package/dist/components/info-block.d.ts +1 -1
  25. package/dist/components/input-date.cjs +11 -1
  26. package/dist/components/input-date.cjs.map +1 -1
  27. package/dist/components/input-date.js +11 -1
  28. package/dist/components/input-date.js.map +1 -1
  29. package/dist/components/input-otp.cjs +1 -0
  30. package/dist/components/input-otp.cjs.map +1 -1
  31. package/dist/components/input-otp.js +2 -1
  32. package/dist/components/input-otp.js.map +1 -1
  33. package/dist/components/marker.d.cts +1 -1
  34. package/dist/components/marker.d.ts +1 -1
  35. package/dist/components/theme.cjs +2 -0
  36. package/dist/components/theme.cjs.map +1 -1
  37. package/dist/components/theme.js +2 -0
  38. package/dist/components/theme.js.map +1 -1
  39. package/dist/hooks/use-focus-modality.cjs +55 -0
  40. package/dist/hooks/use-focus-modality.cjs.map +1 -0
  41. package/dist/hooks/use-focus-modality.d.cts +8 -0
  42. package/dist/hooks/use-focus-modality.d.ts +8 -0
  43. package/dist/hooks/use-focus-modality.js +53 -0
  44. package/dist/hooks/use-focus-modality.js.map +1 -0
  45. package/dist/styles/theme.css +45 -3
  46. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"theme.cjs","names":["React","isParsableColor","generateAccentScale","resolveAutoNeutral","isSparkNeutralFamily","getMatchingNeutral","CURATED_ACCENTS","appearanceForBackground","accentSparkVars","neutralSparkVars","invertAccentScale","neutralFamilyVars"],"sources":["../../src/components/theme.tsx"],"sourcesContent":["'use client'\n\nimport { mergeProps } from '@base-ui/react/merge-props'\nimport { useRender } from '@base-ui/react/use-render'\nimport * as React from 'react'\nimport {\n CURATED_ACCENTS,\n accentSparkVars,\n appearanceForBackground,\n generateAccentScale,\n getMatchingNeutral,\n invertAccentScale,\n isParsableColor,\n neutralFamilyVars,\n neutralSparkVars,\n resolveAutoNeutral,\n type Appearance,\n type SparkAccentScale,\n} from '../lib/accent-theme'\nimport {\n isSparkNeutralFamily,\n type SparkButtonColor,\n type SparkButtonDesignColor,\n type SparkButtonDesignVariant,\n type SparkButtonRole,\n type SparkButtonRoles,\n type SparkCardColor,\n type SparkCardVariant,\n type SparkInputColor,\n type SparkInputStyle,\n type SparkLabelPosition,\n type SparkNeutral,\n type SparkRadius,\n type SparkScaling,\n type SparkSpacing,\n type SparkStyle,\n} from '../lib/theme-types'\nimport { cn } from '../utils/cn'\n\nexport type {\n SparkButtonColor,\n SparkButtonDesignVariant,\n SparkButtonRole,\n SparkButtonRoles,\n SparkCardColor,\n SparkCardVariant,\n SparkInputColor,\n SparkInputStyle,\n SparkLabelPosition,\n SparkNeutral,\n SparkNeutralFamily,\n SparkRadius,\n SparkScaling,\n SparkSpacing,\n SparkStyle,\n} from '../lib/theme-types'\n\n/** The epilot brand accent — the scale `spark-default.css` ships statically. */\nconst DEFAULT_ACCENT = '#005EB4'\n\nexport interface ThemeValue {\n /** Curated accent name or a custom hex. */\n accentColor?: string\n /**\n * Page canvas as a custom hex. Regenerates BOTH the accent and neutral scales against\n * it (each alpha step is composited against the canvas, so a saturated colour needs\n * the neutral ramp regenerated too, not just the accent). Unset → the fixed\n * `#ffffff` / `#000000` default, and neutrals stay on the static Radix families.\n */\n backgroundColor?: string\n /**\n * A curated family name, an arbitrary color to seed the neutral scale, or `'auto'` to\n * resolve one — preferring `backgroundColor`'s own hue when it's perceptibly tinted,\n * else pairing with the accent (Radix's `grayColor=\"auto\"`). A custom seed (from `auto`\n * or set directly) only regenerates the scale alongside a `backgroundColor`; without\n * one, `data-neutral-color` falls back to the accent-matched family and that's what\n * actually paints.\n */\n neutralColor?: SparkNeutral\n radius?: SparkRadius\n scaling?: SparkScaling\n spacing?: SparkSpacing\n styleVariant?: SparkStyle\n /** Orthogonal to `styleVariant`: shifts any style toward higher-contrast steps. */\n highContrast?: boolean\n /**\n * Orthogonal to `styleVariant`: re-casts the accent scale for use ON its own solid fill,\n * for controls sitting on a solid accent surface (a `<Card variant=\"solid\" color=\"accent\">`),\n * where a solid control would otherwise paint the same `--spark-9` as the card and vanish.\n * Swaps step 9 with its contrast ink, so the fill/ink pair stays WCAG-safe for any accent.\n */\n inverted?: boolean\n labelPosition?: SparkLabelPosition\n inputStyle?: SparkInputStyle\n inputColor?: SparkInputColor\n /** App-level default `<Card>` chrome; a per-card `variant` prop overrides it. */\n cardVariant?: SparkCardVariant\n /** App-level default `<Card>` palette; a per-card `color` prop overrides it. */\n cardColor?: SparkCardColor\n /** Looks of the `primary`, `secondary` and `tertiary` `<Button variant>`. */\n buttons?: SparkButtonRoles\n appearance?: Appearance\n /** Font stack for `h1`–`h6`. Any valid CSS `font-family` value. */\n fontHeading?: string\n /** Font stack for everything else. Any valid CSS `font-family` value. */\n fontBody?: string\n}\n\nconst ThemeContext = React.createContext<ThemeValue>({})\n\n/** What a Theme actually wrote to the DOM, merged over its ancestors (nearest wins). */\ninterface ThemeOutput {\n attrs: Record<string, string>\n vars: Record<string, string>\n scopes: string[]\n}\n\nfunction roleOf(\n style: SparkStyle | undefined,\n color: SparkButtonRole['color'],\n) {\n if (style === undefined && color === undefined) return undefined\n return {\n ...(style !== undefined && { style }),\n ...(color !== undefined && { color }),\n }\n}\n\nconst DESIGN_VARIANTS = [\n 'primary',\n 'secondary',\n 'tertiary',\n] as const satisfies readonly SparkButtonDesignVariant[]\n\nexport function isDesignColor(value: unknown): value is SparkButtonDesignColor {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as SparkButtonDesignColor).light === 'string'\n )\n}\n\nconst colorKey = (color: SparkButtonRole['color']) =>\n isDesignColor(color)\n ? JSON.stringify({ light: color.light, dark: color.dark })\n : color\n\nconst colorFromKey = (key: string | undefined): SparkButtonRole['color'] =>\n key?.startsWith('{')\n ? (JSON.parse(key) as SparkButtonDesignColor)\n : (key as SparkButtonColor | undefined)\n\nfunction parsableColor(\n variant: SparkButtonDesignVariant,\n color: SparkButtonRole['color'],\n): SparkButtonRole['color'] {\n if (!isDesignColor(color)) return color\n if (!isParsableColor(color.light)) {\n console.warn(\n `[Theme] Ignoring invalid buttons.${variant}.color \"${color.light}\".`,\n )\n return undefined\n }\n if (color.dark !== undefined && !isParsableColor(color.dark)) {\n console.warn(\n `[Theme] Ignoring invalid buttons.${variant}.color dark \"${color.dark}\".`,\n )\n return { light: color.light }\n }\n return color.dark === undefined ? { light: color.light } : color\n}\n\nfunction useButtonRoles(buttons: SparkButtonRoles | undefined) {\n const isSet = buttons !== undefined\n const { primary, secondary, tertiary } = buttons ?? {}\n const primaryStyle = primary?.style\n const primaryColor = colorKey(primary?.color)\n const secondaryStyle = secondary?.style\n const secondaryColor = colorKey(secondary?.color)\n const tertiaryStyle = tertiary?.style\n const tertiaryColor = colorKey(tertiary?.color)\n return React.useMemo<SparkButtonRoles | undefined>(() => {\n if (!isSet) return undefined\n const roles: SparkButtonRoles = {}\n const primaryRole = roleOf(\n primaryStyle,\n parsableColor('primary', colorFromKey(primaryColor)),\n )\n const secondaryRole = roleOf(\n secondaryStyle,\n parsableColor('secondary', colorFromKey(secondaryColor)),\n )\n const tertiaryRole = roleOf(\n tertiaryStyle,\n parsableColor('tertiary', colorFromKey(tertiaryColor)),\n )\n if (primaryRole) roles.primary = primaryRole\n if (secondaryRole) roles.secondary = secondaryRole\n if (tertiaryRole) roles.tertiary = tertiaryRole\n return roles\n }, [\n isSet,\n primaryStyle,\n primaryColor,\n secondaryStyle,\n secondaryColor,\n tertiaryStyle,\n tertiaryColor,\n ])\n}\n\nfunction mergeRoles(\n parent: SparkButtonRoles | undefined,\n own: SparkButtonRoles,\n): SparkButtonRoles {\n const merged: SparkButtonRoles = { ...parent }\n for (const variant of DESIGN_VARIANTS) {\n if (own[variant])\n merged[variant] = { ...parent?.[variant], ...own[variant] }\n }\n return merged\n}\n\nfunction buttonColorDecls(\n roles: SparkButtonRoles | undefined,\n appearance: Appearance,\n): string[] {\n const decls: string[] = []\n for (const variant of DESIGN_VARIANTS) {\n const color = roles?.[variant]?.color\n if (!isDesignColor(color)) continue\n const hex =\n appearance === 'dark' ? (color.dark ?? color.light) : color.light\n const scale = generateAccentScale(hex, appearance)\n const prefix = `--spark-button-${variant}`\n decls.push(\n ...scale.accentScale.map((c, i) => `${prefix}-${i + 1}: ${c};`),\n ...scale.accentScaleAlpha.map((c, i) => `${prefix}-a${i + 1}: ${c};`),\n `${prefix}-contrast: ${scale.accentContrast};`,\n `${prefix}-on-solid: ${scale.accentOnSolid};`,\n `${prefix}-surface: ${scale.accentSurface};`,\n )\n }\n return decls\n}\n\nfunction declsToVars(decls: string[]): Record<string, string> {\n return Object.fromEntries(\n decls.map((decl) => {\n const i = decl.indexOf(':')\n return [decl.slice(0, i).trim(), decl.slice(i + 1, -1).trim()]\n }),\n )\n}\n\nconst ThemeOutputContext = React.createContext<ThemeOutput | null>(null)\n\n/** Merged theme values from enclosing `<Theme>` providers. */\nexport function useTheme(): ThemeValue {\n return React.useContext(ThemeContext)\n}\n\nexport interface ThemeProps\n extends useRender.ComponentProps<'div'>, ThemeValue {}\n\n/** Optional sugar: writes the theming `data-*` attrs + accent `--spark-*` vars onto a wrapper. */\nexport const Theme = React.forwardRef<HTMLDivElement, ThemeProps>(\n function Theme(\n {\n accentColor,\n backgroundColor,\n neutralColor,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n inverted,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n buttons: buttonsProp,\n appearance,\n fontHeading,\n fontBody,\n render,\n className,\n style,\n children,\n ...rest\n },\n ref,\n ) {\n const parent = useTheme()\n const buttons = useButtonRoles(buttonsProp)\n const parentOutput = React.useContext(ThemeOutputContext)\n\n const value = React.useMemo<ThemeValue>(\n () => ({\n accentColor: accentColor ?? parent.accentColor,\n backgroundColor: backgroundColor ?? parent.backgroundColor,\n neutralColor: neutralColor ?? parent.neutralColor,\n radius: radius ?? parent.radius,\n scaling: scaling ?? parent.scaling,\n spacing: spacing ?? parent.spacing,\n styleVariant: styleVariant ?? parent.styleVariant,\n highContrast: highContrast ?? parent.highContrast,\n inverted: inverted ?? parent.inverted,\n labelPosition: labelPosition ?? parent.labelPosition,\n inputStyle: inputStyle ?? parent.inputStyle,\n inputColor: inputColor ?? parent.inputColor,\n cardVariant: cardVariant ?? parent.cardVariant,\n cardColor: cardColor ?? parent.cardColor,\n buttons: buttons ? mergeRoles(parent.buttons, buttons) : parent.buttons,\n appearance: appearance ?? parent.appearance,\n fontHeading: fontHeading ?? parent.fontHeading,\n fontBody: fontBody ?? parent.fontBody,\n }),\n [\n accentColor,\n backgroundColor,\n neutralColor,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n inverted,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n buttons,\n appearance,\n fontHeading,\n fontBody,\n parent,\n ],\n )\n\n // Scope id for the ambient-appearance case (both scales emitted in a <style>).\n const scopeId = React.useId()\n\n // 'auto' pairs a neutral with the canvas's own tint when it has one, else the\n // effective accent (Radix's grayColor=\"auto\") — see resolveAutoNeutral. Reads the\n // OWN backgroundColor, not the merged value.backgroundColor: optsFor (below) only\n // ever regenerates against a scope's own canvas too, so preferring an inherited one\n // here would resolve a seed that then gets silently discarded.\n const rawNeutralColor =\n neutralColor === 'auto'\n ? resolveAutoNeutral(\n value.accentColor ?? DEFAULT_ACCENT,\n backgroundColor,\n )\n : neutralColor\n\n // A custom neutral that isn't a recognized family must be a real, parseable color —\n // reject invalid input here (e.g. a typo'd family name like \"slat\") so it can't throw\n // deep inside the shared generator, where the catch below would otherwise blame\n // accentColor/backgroundColor without ever naming neutralColor as the actual cause.\n const neutralColorIsValid =\n rawNeutralColor === undefined ||\n isSparkNeutralFamily(rawNeutralColor) ||\n isParsableColor(rawNeutralColor)\n if (!neutralColorIsValid) {\n console.warn(\n `[Theme] Ignoring invalid neutralColor \"${rawNeutralColor}\" — falling back to the accent-matched family.`,\n )\n }\n const resolvedNeutralColor = neutralColorIsValid\n ? rawNeutralColor\n : getMatchingNeutral(value.accentColor ?? DEFAULT_ACCENT)\n\n // The DOM attribute stays one of the 6 static families `[data-neutral-color]` has CSS\n // for — a raw color (from the canvas-tinted auto path, or an arbitrary neutralColor\n // prop) falls back to its accent-matched family here instead, so the attribute is\n // always CSS-selectable/debuggable rather than a sentinel nothing matches.\n // generateAccentScale still gets the real resolvedNeutralColor for generation, below —\n // this substitution is display-only, and doesn't by itself guarantee the *other*\n // appearance's neutrals in ambient (no explicit `appearance`) mode: that's a\n // pre-existing cross-appearance leak in the same family as review-findings.md #5, not\n // something this attribute fallback fixes or regresses.\n const neutralColorAttr =\n resolvedNeutralColor === undefined\n ? undefined\n : isSparkNeutralFamily(resolvedNeutralColor)\n ? resolvedNeutralColor\n : getMatchingNeutral(value.accentColor ?? DEFAULT_ACCENT)\n\n const accent = React.useMemo(() => {\n const empty = {\n inlineVars: {} as React.CSSProperties,\n portalVars: {} as React.CSSProperties,\n portalScope: undefined as string | undefined,\n css: '',\n scoped: false,\n }\n // A custom canvas generates even with no accent of its own: the neutral ramp is\n // composited against it, and --spark-background has to carry it.\n if (!accentColor && !backgroundColor) return empty\n\n const toVars = (decls: string[]) =>\n Object.fromEntries(\n decls\n .filter((decl) => decl.includes(':'))\n .map((decl) => {\n const i = decl.indexOf(':')\n return [\n decl.slice(0, i).trim(),\n decl\n .slice(i + 1)\n .replace(/;$/, '')\n .trim(),\n ]\n }),\n ) as React.CSSProperties\n\n try {\n const source = value.accentColor ?? DEFAULT_ACCENT\n const hex = CURATED_ACCENTS[source] ?? source\n\n // A canvas has a polarity, unlike an accent hue: a yellow page is a *light*\n // page, and reusing it for the dark scale yields light ink on a light canvas\n // (measured 1.16:1). So the custom canvas applies to the appearance it actually\n // belongs to, and the other keeps its default. One knob still covers the common\n // case — a tenant wanting both sets an explicit appearance per scope.\n const bgAppearance = backgroundColor\n ? appearanceForBackground(backgroundColor)\n : undefined\n\n // Honouring a mismatched canvas would paint light ink on a light page, so it's\n // dropped — but say so, or the prop looks broken.\n if (\n backgroundColor &&\n value.appearance &&\n bgAppearance !== value.appearance\n ) {\n console.warn(\n `[Theme] Ignoring backgroundColor \"${backgroundColor}\": it reads as a ${bgAppearance} canvas on an appearance=\"${value.appearance}\" scope. Pass a ${value.appearance} colour, or set it on a scope whose appearance matches.`,\n )\n }\n\n // Default to slate so a regenerated neutral stays in the family the static\n // `:root` default already points at, rather than the generator's ECP gray seed.\n const optsFor = (appearance: Appearance) =>\n backgroundColor && bgAppearance === appearance\n ? {\n background: backgroundColor,\n neutral: resolvedNeutralColor ?? ('slate' as const),\n }\n : undefined\n\n // Neutrals are only worth regenerating against a custom canvas — see\n // neutralSparkVars. Without one the static Radix families are already correct.\n const emit = (scale: SparkAccentScale, custom: boolean) =>\n custom\n ? [...accentSparkVars(scale), ...neutralSparkVars(scale)]\n : accentSparkVars(scale)\n\n const build = (appearance: Appearance) => {\n const opts = optsFor(appearance)\n const scale = generateAccentScale(hex, appearance, opts)\n // `inverted` re-casts the accent for a solid-accent surface; the neutral ramp is\n // unrelated to that swap, so it passes through untouched.\n const rendered = emit(\n inverted ? invertAccentScale(scale) : scale,\n opts != null,\n )\n // Popups sit on their own surface, so they get the scale before the inverted re-cast.\n const plain = inverted ? emit(scale, opts != null) : rendered\n return { rendered, plain }\n }\n\n // Explicit appearance → single-scale inline vars. Correct for a light\n // island inside a dark page (which must NOT pick up the dark scale).\n if (value.appearance) {\n const { rendered, plain } = build(value.appearance)\n const inlineVars = toVars(rendered)\n return {\n inlineVars,\n portalVars: inverted ? toVars(plain) : inlineVars,\n portalScope: undefined,\n css: '',\n scoped: false,\n }\n }\n\n // Ambient appearance → emit BOTH scales in a scoped <style> so the\n // `.dark` class selects the right one. Without this, a single-appearance\n // inline scale (default light) breaks components in dark mode.\n //\n // Both blocks must declare the SAME tokens. A custom canvas only regenerates\n // neutrals for its own appearance (see optsFor), and a custom property the other\n // block leaves undeclared keeps its sibling's value rather than falling back — so\n // the off-canvas appearance would paint this one's canvas-tinted neutrals, and\n // being unlayered they'd beat `[data-neutral-color]`'s @layer base mapping too.\n // Point it at the static family instead: the same seed the canvas side was given,\n // so the two appearances agree on family and differ only in canvas.\n const offCanvasNeutrals = backgroundColor\n ? neutralFamilyVars(resolvedNeutralColor ?? 'slate')\n : []\n const scaleFor = (appearance: Appearance) => {\n const { rendered, plain } = build(appearance)\n const extra = bgAppearance === appearance ? [] : offCanvasNeutrals\n return {\n rendered: [...rendered, ...extra],\n plain: [...plain, ...extra],\n }\n }\n const light = scaleFor('light')\n const dark = scaleFor('dark')\n const rule = (\n id: string,\n lightDecls: string[],\n darkDecls: string[],\n ) => {\n const sel = `[data-spark-scope~=\"${id}\"]`\n return `${sel}{${lightDecls.join('')}}:is(.dark,.dark-theme) ${sel}{${darkDecls.join('')}}`\n }\n const portalScope = inverted ? `${scopeId}p` : scopeId\n const css =\n rule(scopeId, light.rendered, dark.rendered) +\n (inverted ? rule(portalScope, light.plain, dark.plain) : '')\n return {\n inlineVars: {} as React.CSSProperties,\n portalVars: {} as React.CSSProperties,\n portalScope,\n css,\n scoped: true,\n }\n } catch (error) {\n // A bad accentColor/backgroundColor must not throw through render — fall back\n // to the default theme.\n console.warn(\n `[Theme] Ignoring invalid accentColor \"${accentColor}\" / backgroundColor \"${backgroundColor}\".`,\n error,\n )\n return empty\n }\n }, [\n accentColor,\n backgroundColor,\n inverted,\n resolvedNeutralColor,\n value.accentColor,\n value.appearance,\n scopeId,\n ])\n\n const attrs = React.useMemo(\n () => ({\n 'data-neutral-color': neutralColorAttr,\n 'data-radius': radius,\n 'data-scaling': scaling,\n 'data-spacing': spacing,\n 'data-style': styleVariant,\n 'data-high-contrast': highContrast ? '' : undefined,\n 'data-label-position': labelPosition,\n 'data-input-style': inputStyle,\n 'data-input-color': inputColor,\n 'data-card-variant': cardVariant,\n 'data-card-color': cardColor,\n }),\n [\n neutralColorAttr,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n ],\n )\n const fontVars = React.useMemo(\n () => ({\n ...(fontHeading ? { '--spark-font-heading': fontHeading } : null),\n ...(fontBody ? { '--spark-font-body': fontBody } : null),\n }),\n [fontHeading, fontBody],\n )\n\n const buttonVars = React.useMemo(() => {\n if (value.appearance) {\n const decls = buttonColorDecls(buttons, value.appearance)\n return { vars: declsToVars(decls), scope: undefined, css: '' }\n }\n const light = buttonColorDecls(buttons, 'light')\n const dark = buttonColorDecls(buttons, 'dark')\n if (!light.length) return { vars: {}, scope: undefined, css: '' }\n const scope = `${scopeId}b`\n const sel = `[data-spark-scope~=\"${scope}\"]`\n return {\n vars: {},\n scope,\n css: `${sel}{${light.join('')}}:is(.dark,.dark-theme) ${sel}{${dark.join('')}}`,\n }\n }, [buttons, value.appearance, scopeId])\n\n const ownScopes = [\n ...(accent.scoped ? [scopeId] : []),\n ...(buttonVars.scope ? [buttonVars.scope] : []),\n ]\n\n const element = useRender({\n defaultTagName: 'div',\n render,\n ref,\n props: mergeProps<'div'>(\n {\n className: cn('spark-theme', appearance, className),\n ...attrs,\n 'data-inverted': inverted ? '' : undefined,\n 'data-spark-scope': ownScopes.length\n ? ownScopes.join(' ')\n : undefined,\n style: {\n ...accent.inlineVars,\n // Paint the canvas we were handed, else the prop emits a token and visibly\n // does nothing. Reads the var (not the raw prop) so the scoped <style>'s\n // per-appearance value still wins under ambient appearance.\n ...(backgroundColor\n ? { backgroundColor: 'var(--spark-background)' }\n : null),\n ...fontVars,\n ...buttonVars.vars,\n ...style,\n } as React.CSSProperties,\n children,\n } as React.ComponentProps<'div'>,\n rest,\n ),\n })\n\n const output = React.useMemo<ThemeOutput>(() => {\n // An unset own knob must not blank out the ancestor's value it inherits.\n const own = Object.fromEntries(\n Object.entries(attrs).filter(\n (entry): entry is [string, string] => entry[1] !== undefined,\n ),\n )\n const parentScopes = parentOutput?.scopes ?? []\n return {\n attrs: { ...parentOutput?.attrs, ...own },\n vars: {\n ...parentOutput?.vars,\n ...(accent.portalVars as Record<string, string>),\n ...fontVars,\n ...buttonVars.vars,\n },\n scopes: [\n ...parentScopes,\n ...(accent.portalScope ? [accent.portalScope] : []),\n ...(buttonVars.scope ? [buttonVars.scope] : []),\n ],\n }\n }, [parentOutput, attrs, accent, fontVars, buttonVars])\n\n return (\n <ThemeContext.Provider value={value}>\n <ThemeOutputContext.Provider value={output}>\n {accent.css ? <style>{accent.css}</style> : null}\n {buttonVars.css ? <style>{buttonVars.css}</style> : null}\n {element}\n </ThemeOutputContext.Provider>\n </ThemeContext.Provider>\n )\n },\n)\n\n/** Re-emits what the enclosing Themes rendered inside a portal, where CSS inheritance from them stops. */\nexport function PortalTheme({ children }: { children: React.ReactNode }) {\n const output = React.useContext(ThemeOutputContext)\n const theme = useTheme()\n // A popup sits on its own surface, never on the solid accent `inverted` is for.\n const value = React.useMemo(() => ({ ...theme, inverted: false }), [theme])\n if (!output) return <>{children}</>\n return (\n <ThemeContext.Provider value={value}>\n <div\n data-slot=\"portal-theme\"\n className={cn('spark-theme', theme.appearance)}\n {...output.attrs}\n data-spark-scope={\n output.scopes.length ? output.scopes.join(' ') : undefined\n }\n style={{ display: 'contents', ...output.vars }}\n >\n {children}\n </div>\n </ThemeContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AA0DA,MAAM,iBAAiB;AAkDvB,MAAM,eAAeA,MAAM,cAA0B,CAAC,CAAC;AASvD,SAAS,OACP,OACA,OACA;CACA,IAAI,UAAU,KAAA,KAAa,UAAU,KAAA,GAAW,OAAO,KAAA;CACvD,OAAO;EACL,GAAI,UAAU,KAAA,KAAa,EAAE,MAAM;EACnC,GAAI,UAAU,KAAA,KAAa,EAAE,MAAM;CACrC;AACF;AAEA,MAAM,kBAAkB;CACtB;CACA;CACA;AACF;AAEA,SAAgB,cAAc,OAAiD;CAC7E,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAiC,UAAU;AAEvD;AAEA,MAAM,YAAY,UAChB,cAAc,KAAK,IACf,KAAK,UAAU;CAAE,OAAO,MAAM;CAAO,MAAM,MAAM;AAAK,CAAC,IACvD;AAEN,MAAM,gBAAgB,QACpB,KAAK,WAAW,GAAG,IACd,KAAK,MAAM,GAAG,IACd;AAEP,SAAS,cACP,SACA,OAC0B;CAC1B,IAAI,CAAC,cAAc,KAAK,GAAG,OAAO;CAClC,IAAI,CAACC,yBAAAA,gBAAgB,MAAM,KAAK,GAAG;EACjC,QAAQ,KACN,oCAAoC,QAAQ,UAAU,MAAM,MAAM,GACpE;EACA;CACF;CACA,IAAI,MAAM,SAAS,KAAA,KAAa,CAACA,yBAAAA,gBAAgB,MAAM,IAAI,GAAG;EAC5D,QAAQ,KACN,oCAAoC,QAAQ,eAAe,MAAM,KAAK,GACxE;EACA,OAAO,EAAE,OAAO,MAAM,MAAM;CAC9B;CACA,OAAO,MAAM,SAAS,KAAA,IAAY,EAAE,OAAO,MAAM,MAAM,IAAI;AAC7D;AAEA,SAAS,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","CURATED_ACCENTS","appearanceForBackground","accentSparkVars","neutralSparkVars","invertAccentScale","neutralFamilyVars"],"sources":["../../src/components/theme.tsx"],"sourcesContent":["'use client'\n\nimport { mergeProps } from '@base-ui/react/merge-props'\nimport { useRender } from '@base-ui/react/use-render'\nimport * as React from 'react'\nimport { useFocusModality } from '../hooks/use-focus-modality'\nimport {\n CURATED_ACCENTS,\n accentSparkVars,\n appearanceForBackground,\n generateAccentScale,\n getMatchingNeutral,\n invertAccentScale,\n isParsableColor,\n neutralFamilyVars,\n neutralSparkVars,\n resolveAutoNeutral,\n type Appearance,\n type SparkAccentScale,\n} from '../lib/accent-theme'\nimport {\n isSparkNeutralFamily,\n type SparkButtonColor,\n type SparkButtonDesignColor,\n type SparkButtonDesignVariant,\n type SparkButtonRole,\n type SparkButtonRoles,\n type SparkCardColor,\n type SparkCardVariant,\n type SparkInputColor,\n type SparkInputStyle,\n type SparkLabelPosition,\n type SparkNeutral,\n type SparkRadius,\n type SparkScaling,\n type SparkSpacing,\n type SparkStyle,\n} from '../lib/theme-types'\nimport { cn } from '../utils/cn'\n\nexport type {\n SparkButtonColor,\n SparkButtonDesignVariant,\n SparkButtonRole,\n SparkButtonRoles,\n SparkCardColor,\n SparkCardVariant,\n SparkInputColor,\n SparkInputStyle,\n SparkLabelPosition,\n SparkNeutral,\n SparkNeutralFamily,\n SparkRadius,\n SparkScaling,\n SparkSpacing,\n SparkStyle,\n} from '../lib/theme-types'\n\n/** The epilot brand accent — the scale `spark-default.css` ships statically. */\nconst DEFAULT_ACCENT = '#005EB4'\n\nexport interface ThemeValue {\n /** Curated accent name or a custom hex. */\n accentColor?: string\n /**\n * Page canvas as a custom hex. Regenerates BOTH the accent and neutral scales against\n * it (each alpha step is composited against the canvas, so a saturated colour needs\n * the neutral ramp regenerated too, not just the accent). Unset → the fixed\n * `#ffffff` / `#000000` default, and neutrals stay on the static Radix families.\n */\n backgroundColor?: string\n /**\n * A curated family name, an arbitrary color to seed the neutral scale, or `'auto'` to\n * resolve one — preferring `backgroundColor`'s own hue when it's perceptibly tinted,\n * else pairing with the accent (Radix's `grayColor=\"auto\"`). A custom seed (from `auto`\n * or set directly) only regenerates the scale alongside a `backgroundColor`; without\n * one, `data-neutral-color` falls back to the accent-matched family and that's what\n * actually paints.\n */\n neutralColor?: SparkNeutral\n radius?: SparkRadius\n scaling?: SparkScaling\n spacing?: SparkSpacing\n styleVariant?: SparkStyle\n /** Orthogonal to `styleVariant`: shifts any style toward higher-contrast steps. */\n highContrast?: boolean\n /**\n * Orthogonal to `styleVariant`: re-casts the accent scale for use ON its own solid fill,\n * for controls sitting on a solid accent surface (a `<Card variant=\"solid\" color=\"accent\">`),\n * where a solid control would otherwise paint the same `--spark-9` as the card and vanish.\n * Swaps step 9 with its contrast ink, so the fill/ink pair stays WCAG-safe for any accent.\n */\n inverted?: boolean\n labelPosition?: SparkLabelPosition\n inputStyle?: SparkInputStyle\n inputColor?: SparkInputColor\n /** App-level default `<Card>` chrome; a per-card `variant` prop overrides it. */\n cardVariant?: SparkCardVariant\n /** App-level default `<Card>` palette; a per-card `color` prop overrides it. */\n cardColor?: SparkCardColor\n /** Looks of the `primary`, `secondary` and `tertiary` `<Button variant>`. */\n buttons?: SparkButtonRoles\n appearance?: Appearance\n /** Font stack for `h1`–`h6`. Any valid CSS `font-family` value. */\n fontHeading?: string\n /** Font stack for everything else. Any valid CSS `font-family` value. */\n fontBody?: string\n}\n\nconst ThemeContext = React.createContext<ThemeValue>({})\n\n/** What a Theme actually wrote to the DOM, merged over its ancestors (nearest wins). */\ninterface ThemeOutput {\n attrs: Record<string, string>\n vars: Record<string, string>\n scopes: string[]\n}\n\nfunction roleOf(\n style: SparkStyle | undefined,\n color: SparkButtonRole['color'],\n) {\n if (style === undefined && color === undefined) return undefined\n return {\n ...(style !== undefined && { style }),\n ...(color !== undefined && { color }),\n }\n}\n\nconst DESIGN_VARIANTS = [\n 'primary',\n 'secondary',\n 'tertiary',\n] as const satisfies readonly SparkButtonDesignVariant[]\n\nexport function isDesignColor(value: unknown): value is SparkButtonDesignColor {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as SparkButtonDesignColor).light === 'string'\n )\n}\n\nconst colorKey = (color: SparkButtonRole['color']) =>\n isDesignColor(color)\n ? JSON.stringify({ light: color.light, dark: color.dark })\n : color\n\nconst colorFromKey = (key: string | undefined): SparkButtonRole['color'] =>\n key?.startsWith('{')\n ? (JSON.parse(key) as SparkButtonDesignColor)\n : (key as SparkButtonColor | undefined)\n\nfunction parsableColor(\n variant: SparkButtonDesignVariant,\n color: SparkButtonRole['color'],\n): SparkButtonRole['color'] {\n if (!isDesignColor(color)) return color\n if (!isParsableColor(color.light)) {\n console.warn(\n `[Theme] Ignoring invalid buttons.${variant}.color \"${color.light}\".`,\n )\n return undefined\n }\n if (color.dark !== undefined && !isParsableColor(color.dark)) {\n console.warn(\n `[Theme] Ignoring invalid buttons.${variant}.color dark \"${color.dark}\".`,\n )\n return { light: color.light }\n }\n return color.dark === undefined ? { light: color.light } : color\n}\n\nfunction useButtonRoles(buttons: SparkButtonRoles | undefined) {\n const isSet = buttons !== undefined\n const { primary, secondary, tertiary } = buttons ?? {}\n const primaryStyle = primary?.style\n const primaryColor = colorKey(primary?.color)\n const secondaryStyle = secondary?.style\n const secondaryColor = colorKey(secondary?.color)\n const tertiaryStyle = tertiary?.style\n const tertiaryColor = colorKey(tertiary?.color)\n return React.useMemo<SparkButtonRoles | undefined>(() => {\n if (!isSet) return undefined\n const roles: SparkButtonRoles = {}\n const primaryRole = roleOf(\n primaryStyle,\n parsableColor('primary', colorFromKey(primaryColor)),\n )\n const secondaryRole = roleOf(\n secondaryStyle,\n parsableColor('secondary', colorFromKey(secondaryColor)),\n )\n const tertiaryRole = roleOf(\n tertiaryStyle,\n parsableColor('tertiary', colorFromKey(tertiaryColor)),\n )\n if (primaryRole) roles.primary = primaryRole\n if (secondaryRole) roles.secondary = secondaryRole\n if (tertiaryRole) roles.tertiary = tertiaryRole\n return roles\n }, [\n isSet,\n primaryStyle,\n primaryColor,\n secondaryStyle,\n secondaryColor,\n tertiaryStyle,\n tertiaryColor,\n ])\n}\n\nfunction mergeRoles(\n parent: SparkButtonRoles | undefined,\n own: SparkButtonRoles,\n): SparkButtonRoles {\n const merged: SparkButtonRoles = { ...parent }\n for (const variant of DESIGN_VARIANTS) {\n if (own[variant])\n merged[variant] = { ...parent?.[variant], ...own[variant] }\n }\n return merged\n}\n\nfunction buttonColorDecls(\n roles: SparkButtonRoles | undefined,\n appearance: Appearance,\n): string[] {\n const decls: string[] = []\n for (const variant of DESIGN_VARIANTS) {\n const color = roles?.[variant]?.color\n if (!isDesignColor(color)) continue\n const hex =\n appearance === 'dark' ? (color.dark ?? color.light) : color.light\n const scale = generateAccentScale(hex, appearance)\n const prefix = `--spark-button-${variant}`\n decls.push(\n ...scale.accentScale.map((c, i) => `${prefix}-${i + 1}: ${c};`),\n ...scale.accentScaleAlpha.map((c, i) => `${prefix}-a${i + 1}: ${c};`),\n `${prefix}-contrast: ${scale.accentContrast};`,\n `${prefix}-on-solid: ${scale.accentOnSolid};`,\n `${prefix}-surface: ${scale.accentSurface};`,\n )\n }\n return decls\n}\n\nfunction declsToVars(decls: string[]): Record<string, string> {\n return Object.fromEntries(\n decls.map((decl) => {\n const i = decl.indexOf(':')\n return [decl.slice(0, i).trim(), decl.slice(i + 1, -1).trim()]\n }),\n )\n}\n\nconst ThemeOutputContext = React.createContext<ThemeOutput | null>(null)\n\n/** Merged theme values from enclosing `<Theme>` providers. */\nexport function useTheme(): ThemeValue {\n return React.useContext(ThemeContext)\n}\n\nexport interface ThemeProps\n extends useRender.ComponentProps<'div'>, ThemeValue {}\n\n/** Optional sugar: writes the theming `data-*` attrs + accent `--spark-*` vars onto a wrapper. */\nexport const Theme = React.forwardRef<HTMLDivElement, ThemeProps>(\n function Theme(\n {\n accentColor,\n backgroundColor,\n neutralColor,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n inverted,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n buttons: buttonsProp,\n appearance,\n fontHeading,\n fontBody,\n render,\n className,\n style,\n children,\n ...rest\n },\n ref,\n ) {\n useFocusModality()\n const parent = useTheme()\n const buttons = useButtonRoles(buttonsProp)\n const parentOutput = React.useContext(ThemeOutputContext)\n\n const value = React.useMemo<ThemeValue>(\n () => ({\n accentColor: accentColor ?? parent.accentColor,\n backgroundColor: backgroundColor ?? parent.backgroundColor,\n neutralColor: neutralColor ?? parent.neutralColor,\n radius: radius ?? parent.radius,\n scaling: scaling ?? parent.scaling,\n spacing: spacing ?? parent.spacing,\n styleVariant: styleVariant ?? parent.styleVariant,\n highContrast: highContrast ?? parent.highContrast,\n inverted: inverted ?? parent.inverted,\n labelPosition: labelPosition ?? parent.labelPosition,\n inputStyle: inputStyle ?? parent.inputStyle,\n inputColor: inputColor ?? parent.inputColor,\n cardVariant: cardVariant ?? parent.cardVariant,\n cardColor: cardColor ?? parent.cardColor,\n buttons: buttons ? mergeRoles(parent.buttons, buttons) : parent.buttons,\n appearance: appearance ?? parent.appearance,\n fontHeading: fontHeading ?? parent.fontHeading,\n fontBody: fontBody ?? parent.fontBody,\n }),\n [\n accentColor,\n backgroundColor,\n neutralColor,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n inverted,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n buttons,\n appearance,\n fontHeading,\n fontBody,\n parent,\n ],\n )\n\n // Scope id for the ambient-appearance case (both scales emitted in a <style>).\n const scopeId = React.useId()\n\n // 'auto' pairs a neutral with the canvas's own tint when it has one, else the\n // effective accent (Radix's grayColor=\"auto\") — see resolveAutoNeutral. Reads the\n // OWN backgroundColor, not the merged value.backgroundColor: optsFor (below) only\n // ever regenerates against a scope's own canvas too, so preferring an inherited one\n // here would resolve a seed that then gets silently discarded.\n const rawNeutralColor =\n neutralColor === 'auto'\n ? resolveAutoNeutral(\n value.accentColor ?? DEFAULT_ACCENT,\n backgroundColor,\n )\n : neutralColor\n\n // A custom neutral that isn't a recognized family must be a real, parseable color —\n // reject invalid input here (e.g. a typo'd family name like \"slat\") so it can't throw\n // deep inside the shared generator, where the catch below would otherwise blame\n // accentColor/backgroundColor without ever naming neutralColor as the actual cause.\n const neutralColorIsValid =\n rawNeutralColor === undefined ||\n isSparkNeutralFamily(rawNeutralColor) ||\n isParsableColor(rawNeutralColor)\n if (!neutralColorIsValid) {\n console.warn(\n `[Theme] Ignoring invalid neutralColor \"${rawNeutralColor}\" — falling back to the accent-matched family.`,\n )\n }\n const resolvedNeutralColor = neutralColorIsValid\n ? rawNeutralColor\n : getMatchingNeutral(value.accentColor ?? DEFAULT_ACCENT)\n\n // The DOM attribute stays one of the 6 static families `[data-neutral-color]` has CSS\n // for — a raw color (from the canvas-tinted auto path, or an arbitrary neutralColor\n // prop) falls back to its accent-matched family here instead, so the attribute is\n // always CSS-selectable/debuggable rather than a sentinel nothing matches.\n // generateAccentScale still gets the real resolvedNeutralColor for generation, below —\n // this substitution is display-only, and doesn't by itself guarantee the *other*\n // appearance's neutrals in ambient (no explicit `appearance`) mode: that's a\n // pre-existing cross-appearance leak in the same family as review-findings.md #5, not\n // something this attribute fallback fixes or regresses.\n const neutralColorAttr =\n resolvedNeutralColor === undefined\n ? undefined\n : isSparkNeutralFamily(resolvedNeutralColor)\n ? resolvedNeutralColor\n : getMatchingNeutral(value.accentColor ?? DEFAULT_ACCENT)\n\n const accent = React.useMemo(() => {\n const empty = {\n inlineVars: {} as React.CSSProperties,\n portalVars: {} as React.CSSProperties,\n portalScope: undefined as string | undefined,\n css: '',\n scoped: false,\n }\n // A custom canvas generates even with no accent of its own: the neutral ramp is\n // composited against it, and --spark-background has to carry it.\n if (!accentColor && !backgroundColor) return empty\n\n const toVars = (decls: string[]) =>\n Object.fromEntries(\n decls\n .filter((decl) => decl.includes(':'))\n .map((decl) => {\n const i = decl.indexOf(':')\n return [\n decl.slice(0, i).trim(),\n decl\n .slice(i + 1)\n .replace(/;$/, '')\n .trim(),\n ]\n }),\n ) as React.CSSProperties\n\n try {\n const source = value.accentColor ?? DEFAULT_ACCENT\n const hex = CURATED_ACCENTS[source] ?? source\n\n // A canvas has a polarity, unlike an accent hue: a yellow page is a *light*\n // page, and reusing it for the dark scale yields light ink on a light canvas\n // (measured 1.16:1). So the custom canvas applies to the appearance it actually\n // belongs to, and the other keeps its default. One knob still covers the common\n // case — a tenant wanting both sets an explicit appearance per scope.\n const bgAppearance = backgroundColor\n ? appearanceForBackground(backgroundColor)\n : undefined\n\n // Honouring a mismatched canvas would paint light ink on a light page, so it's\n // dropped — but say so, or the prop looks broken.\n if (\n backgroundColor &&\n value.appearance &&\n bgAppearance !== value.appearance\n ) {\n console.warn(\n `[Theme] Ignoring backgroundColor \"${backgroundColor}\": it reads as a ${bgAppearance} canvas on an appearance=\"${value.appearance}\" scope. Pass a ${value.appearance} colour, or set it on a scope whose appearance matches.`,\n )\n }\n\n // Default to slate so a regenerated neutral stays in the family the static\n // `:root` default already points at, rather than the generator's ECP gray seed.\n const optsFor = (appearance: Appearance) =>\n backgroundColor && bgAppearance === appearance\n ? {\n background: backgroundColor,\n neutral: resolvedNeutralColor ?? ('slate' as const),\n }\n : undefined\n\n // Neutrals are only worth regenerating against a custom canvas — see\n // neutralSparkVars. Without one the static Radix families are already correct.\n const emit = (scale: SparkAccentScale, custom: boolean) =>\n custom\n ? [...accentSparkVars(scale), ...neutralSparkVars(scale)]\n : accentSparkVars(scale)\n\n const build = (appearance: Appearance) => {\n const opts = optsFor(appearance)\n const scale = generateAccentScale(hex, appearance, opts)\n // `inverted` re-casts the accent for a solid-accent surface; the neutral ramp is\n // unrelated to that swap, so it passes through untouched.\n const rendered = emit(\n inverted ? invertAccentScale(scale) : scale,\n opts != null,\n )\n // Popups sit on their own surface, so they get the scale before the inverted re-cast.\n const plain = inverted ? emit(scale, opts != null) : rendered\n return { rendered, plain }\n }\n\n // Explicit appearance → single-scale inline vars. Correct for a light\n // island inside a dark page (which must NOT pick up the dark scale).\n if (value.appearance) {\n const { rendered, plain } = build(value.appearance)\n const inlineVars = toVars(rendered)\n return {\n inlineVars,\n portalVars: inverted ? toVars(plain) : inlineVars,\n portalScope: undefined,\n css: '',\n scoped: false,\n }\n }\n\n // Ambient appearance → emit BOTH scales in a scoped <style> so the\n // `.dark` class selects the right one. Without this, a single-appearance\n // inline scale (default light) breaks components in dark mode.\n //\n // Both blocks must declare the SAME tokens. A custom canvas only regenerates\n // neutrals for its own appearance (see optsFor), and a custom property the other\n // block leaves undeclared keeps its sibling's value rather than falling back — so\n // the off-canvas appearance would paint this one's canvas-tinted neutrals, and\n // being unlayered they'd beat `[data-neutral-color]`'s @layer base mapping too.\n // Point it at the static family instead: the same seed the canvas side was given,\n // so the two appearances agree on family and differ only in canvas.\n const offCanvasNeutrals = backgroundColor\n ? neutralFamilyVars(resolvedNeutralColor ?? 'slate')\n : []\n const scaleFor = (appearance: Appearance) => {\n const { rendered, plain } = build(appearance)\n const extra = bgAppearance === appearance ? [] : offCanvasNeutrals\n return {\n rendered: [...rendered, ...extra],\n plain: [...plain, ...extra],\n }\n }\n const light = scaleFor('light')\n const dark = scaleFor('dark')\n const rule = (\n id: string,\n lightDecls: string[],\n darkDecls: string[],\n ) => {\n const sel = `[data-spark-scope~=\"${id}\"]`\n return `${sel}{${lightDecls.join('')}}:is(.dark,.dark-theme) ${sel}{${darkDecls.join('')}}`\n }\n const portalScope = inverted ? `${scopeId}p` : scopeId\n const css =\n rule(scopeId, light.rendered, dark.rendered) +\n (inverted ? rule(portalScope, light.plain, dark.plain) : '')\n return {\n inlineVars: {} as React.CSSProperties,\n portalVars: {} as React.CSSProperties,\n portalScope,\n css,\n scoped: true,\n }\n } catch (error) {\n // A bad accentColor/backgroundColor must not throw through render — fall back\n // to the default theme.\n console.warn(\n `[Theme] Ignoring invalid accentColor \"${accentColor}\" / backgroundColor \"${backgroundColor}\".`,\n error,\n )\n return empty\n }\n }, [\n accentColor,\n backgroundColor,\n inverted,\n resolvedNeutralColor,\n value.accentColor,\n value.appearance,\n scopeId,\n ])\n\n const attrs = React.useMemo(\n () => ({\n 'data-neutral-color': neutralColorAttr,\n 'data-radius': radius,\n 'data-scaling': scaling,\n 'data-spacing': spacing,\n 'data-style': styleVariant,\n 'data-high-contrast': highContrast ? '' : undefined,\n 'data-label-position': labelPosition,\n 'data-input-style': inputStyle,\n 'data-input-color': inputColor,\n 'data-card-variant': cardVariant,\n 'data-card-color': cardColor,\n }),\n [\n neutralColorAttr,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n ],\n )\n const fontVars = React.useMemo(\n () => ({\n ...(fontHeading ? { '--spark-font-heading': fontHeading } : null),\n ...(fontBody ? { '--spark-font-body': fontBody } : null),\n }),\n [fontHeading, fontBody],\n )\n\n const buttonVars = React.useMemo(() => {\n if (value.appearance) {\n const decls = buttonColorDecls(buttons, value.appearance)\n return { vars: declsToVars(decls), scope: undefined, css: '' }\n }\n const light = buttonColorDecls(buttons, 'light')\n const dark = buttonColorDecls(buttons, 'dark')\n if (!light.length) return { vars: {}, scope: undefined, css: '' }\n const scope = `${scopeId}b`\n const sel = `[data-spark-scope~=\"${scope}\"]`\n return {\n vars: {},\n scope,\n css: `${sel}{${light.join('')}}:is(.dark,.dark-theme) ${sel}{${dark.join('')}}`,\n }\n }, [buttons, value.appearance, scopeId])\n\n const ownScopes = [\n ...(accent.scoped ? [scopeId] : []),\n ...(buttonVars.scope ? [buttonVars.scope] : []),\n ]\n\n const element = useRender({\n defaultTagName: 'div',\n render,\n ref,\n props: mergeProps<'div'>(\n {\n className: cn('spark-theme', appearance, className),\n ...attrs,\n 'data-inverted': inverted ? '' : undefined,\n 'data-spark-scope': ownScopes.length\n ? ownScopes.join(' ')\n : undefined,\n style: {\n ...accent.inlineVars,\n // Paint the canvas we were handed, else the prop emits a token and visibly\n // does nothing. Reads the var (not the raw prop) so the scoped <style>'s\n // per-appearance value still wins under ambient appearance.\n ...(backgroundColor\n ? { backgroundColor: 'var(--spark-background)' }\n : null),\n ...fontVars,\n ...buttonVars.vars,\n ...style,\n } as React.CSSProperties,\n children,\n } as React.ComponentProps<'div'>,\n rest,\n ),\n })\n\n const output = React.useMemo<ThemeOutput>(() => {\n // An unset own knob must not blank out the ancestor's value it inherits.\n const own = Object.fromEntries(\n Object.entries(attrs).filter(\n (entry): entry is [string, string] => entry[1] !== undefined,\n ),\n )\n const parentScopes = parentOutput?.scopes ?? []\n return {\n attrs: { ...parentOutput?.attrs, ...own },\n vars: {\n ...parentOutput?.vars,\n ...(accent.portalVars as Record<string, string>),\n ...fontVars,\n ...buttonVars.vars,\n },\n scopes: [\n ...parentScopes,\n ...(accent.portalScope ? [accent.portalScope] : []),\n ...(buttonVars.scope ? [buttonVars.scope] : []),\n ],\n }\n }, [parentOutput, attrs, accent, fontVars, buttonVars])\n\n return (\n <ThemeContext.Provider value={value}>\n <ThemeOutputContext.Provider value={output}>\n {accent.css ? <style>{accent.css}</style> : null}\n {buttonVars.css ? <style>{buttonVars.css}</style> : null}\n {element}\n </ThemeOutputContext.Provider>\n </ThemeContext.Provider>\n )\n },\n)\n\n/** Re-emits what the enclosing Themes rendered inside a portal, where CSS inheritance from them stops. */\nexport function PortalTheme({ children }: { children: React.ReactNode }) {\n const output = React.useContext(ThemeOutputContext)\n const theme = useTheme()\n // A popup sits on its own surface, never on the solid accent `inverted` is for.\n const value = React.useMemo(() => ({ ...theme, inverted: false }), [theme])\n if (!output) return <>{children}</>\n return (\n <ThemeContext.Provider value={value}>\n <div\n data-slot=\"portal-theme\"\n className={cn('spark-theme', theme.appearance)}\n {...output.attrs}\n data-spark-scope={\n output.scopes.length ? output.scopes.join(' ') : undefined\n }\n style={{ display: 'contents', ...output.vars }}\n >\n {children}\n </div>\n </ThemeContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2DA,MAAM,iBAAiB;AAkDvB,MAAM,eAAeA,MAAM,cAA0B,CAA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,aAAa,UAAd;EAA8B;YAC5B,iBAAA,GAAA,kBAAA,MAAC,mBAAmB,UAApB;GAA6B,OAAO;aAApC;IACG,OAAO,MAAM,iBAAA,GAAA,kBAAA,KAAC,SAAD,EAAA,UAAQ,OAAO,IAAW,CAAA,IAAI;IAC3C,WAAW,MAAM,iBAAA,GAAA,kBAAA,KAAC,SAAD,EAAA,UAAQ,WAAW,IAAW,CAAA,IAAI;IACnD;GAC0B;;CACR,CAAA;AAE3B,CACF;;AAGA,SAAgB,YAAY,EAAE,YAA2C;CACvE,MAAM,SAASA,MAAM,WAAW,kBAAkB;CAClD,MAAM,QAAQ,SAAS;CAEvB,MAAM,QAAQA,MAAM,eAAe;EAAE,GAAG;EAAO,UAAU;CAAM,IAAI,CAAC,KAAK,CAAC;CAC1E,IAAI,CAAC,QAAQ,OAAO,iBAAA,GAAA,kBAAA,KAAA,kBAAA,UAAA,EAAG,SAAW,CAAA;CAClC,OACE,iBAAA,GAAA,kBAAA,KAAC,aAAa,UAAd;EAA8B;YAC5B,iBAAA,GAAA,kBAAA,KAAC,OAAD;GACE,aAAU;GACV,YAAA,GAAA,GAAA,IAAc,eAAe,MAAM,UAAU;GAC7C,GAAI,OAAO;GACX,oBACE,OAAO,OAAO,SAAS,OAAO,OAAO,KAAK,GAAG,IAAI,KAAA;GAEnD,OAAO;IAAE,SAAS;IAAY,GAAG,OAAO;GAAK;GAE5C;EACE,CAAA;CACgB,CAAA;AAE3B"}
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  "use client";
3
+ import { useFocusModality } from "../hooks/use-focus-modality.js";
3
4
  import { isSparkNeutralFamily } from "../lib/theme-types.js";
4
5
  import { CURATED_ACCENTS, accentSparkVars, appearanceForBackground, generateAccentScale, getMatchingNeutral, invertAccentScale, isParsableColor, neutralFamilyVars, neutralSparkVars, resolveAutoNeutral } from "../lib/accent-theme.js";
5
6
  import { cn } from "../utils/cn.js";
@@ -104,6 +105,7 @@ function useTheme() {
104
105
  }
105
106
  /** Optional sugar: writes the theming `data-*` attrs + accent `--spark-*` vars onto a wrapper. */
106
107
  const Theme = React$1.forwardRef(function Theme({ accentColor, backgroundColor, neutralColor, radius, scaling, spacing, styleVariant, highContrast, inverted, labelPosition, inputStyle, inputColor, cardVariant, cardColor, buttons: buttonsProp, appearance, fontHeading, fontBody, render, className, style, children, ...rest }, ref) {
108
+ useFocusModality();
107
109
  const parent = useTheme();
108
110
  const buttons = useButtonRoles(buttonsProp);
109
111
  const parentOutput = React$1.useContext(ThemeOutputContext);
@@ -1 +1 @@
1
- {"version":3,"file":"theme.js","names":["React"],"sources":["../../src/components/theme.tsx"],"sourcesContent":["'use client'\n\nimport { mergeProps } from '@base-ui/react/merge-props'\nimport { useRender } from '@base-ui/react/use-render'\nimport * as React from 'react'\nimport {\n CURATED_ACCENTS,\n accentSparkVars,\n appearanceForBackground,\n generateAccentScale,\n getMatchingNeutral,\n invertAccentScale,\n isParsableColor,\n neutralFamilyVars,\n neutralSparkVars,\n resolveAutoNeutral,\n type Appearance,\n type SparkAccentScale,\n} from '../lib/accent-theme'\nimport {\n isSparkNeutralFamily,\n type SparkButtonColor,\n type SparkButtonDesignColor,\n type SparkButtonDesignVariant,\n type SparkButtonRole,\n type SparkButtonRoles,\n type SparkCardColor,\n type SparkCardVariant,\n type SparkInputColor,\n type SparkInputStyle,\n type SparkLabelPosition,\n type SparkNeutral,\n type SparkRadius,\n type SparkScaling,\n type SparkSpacing,\n type SparkStyle,\n} from '../lib/theme-types'\nimport { cn } from '../utils/cn'\n\nexport type {\n SparkButtonColor,\n SparkButtonDesignVariant,\n SparkButtonRole,\n SparkButtonRoles,\n SparkCardColor,\n SparkCardVariant,\n SparkInputColor,\n SparkInputStyle,\n SparkLabelPosition,\n SparkNeutral,\n SparkNeutralFamily,\n SparkRadius,\n SparkScaling,\n SparkSpacing,\n SparkStyle,\n} from '../lib/theme-types'\n\n/** The epilot brand accent — the scale `spark-default.css` ships statically. */\nconst DEFAULT_ACCENT = '#005EB4'\n\nexport interface ThemeValue {\n /** Curated accent name or a custom hex. */\n accentColor?: string\n /**\n * Page canvas as a custom hex. Regenerates BOTH the accent and neutral scales against\n * it (each alpha step is composited against the canvas, so a saturated colour needs\n * the neutral ramp regenerated too, not just the accent). Unset → the fixed\n * `#ffffff` / `#000000` default, and neutrals stay on the static Radix families.\n */\n backgroundColor?: string\n /**\n * A curated family name, an arbitrary color to seed the neutral scale, or `'auto'` to\n * resolve one — preferring `backgroundColor`'s own hue when it's perceptibly tinted,\n * else pairing with the accent (Radix's `grayColor=\"auto\"`). A custom seed (from `auto`\n * or set directly) only regenerates the scale alongside a `backgroundColor`; without\n * one, `data-neutral-color` falls back to the accent-matched family and that's what\n * actually paints.\n */\n neutralColor?: SparkNeutral\n radius?: SparkRadius\n scaling?: SparkScaling\n spacing?: SparkSpacing\n styleVariant?: SparkStyle\n /** Orthogonal to `styleVariant`: shifts any style toward higher-contrast steps. */\n highContrast?: boolean\n /**\n * Orthogonal to `styleVariant`: re-casts the accent scale for use ON its own solid fill,\n * for controls sitting on a solid accent surface (a `<Card variant=\"solid\" color=\"accent\">`),\n * where a solid control would otherwise paint the same `--spark-9` as the card and vanish.\n * Swaps step 9 with its contrast ink, so the fill/ink pair stays WCAG-safe for any accent.\n */\n inverted?: boolean\n labelPosition?: SparkLabelPosition\n inputStyle?: SparkInputStyle\n inputColor?: SparkInputColor\n /** App-level default `<Card>` chrome; a per-card `variant` prop overrides it. */\n cardVariant?: SparkCardVariant\n /** App-level default `<Card>` palette; a per-card `color` prop overrides it. */\n cardColor?: SparkCardColor\n /** Looks of the `primary`, `secondary` and `tertiary` `<Button variant>`. */\n buttons?: SparkButtonRoles\n appearance?: Appearance\n /** Font stack for `h1`–`h6`. Any valid CSS `font-family` value. */\n fontHeading?: string\n /** Font stack for everything else. Any valid CSS `font-family` value. */\n fontBody?: string\n}\n\nconst ThemeContext = React.createContext<ThemeValue>({})\n\n/** What a Theme actually wrote to the DOM, merged over its ancestors (nearest wins). */\ninterface ThemeOutput {\n attrs: Record<string, string>\n vars: Record<string, string>\n scopes: string[]\n}\n\nfunction roleOf(\n style: SparkStyle | undefined,\n color: SparkButtonRole['color'],\n) {\n if (style === undefined && color === undefined) return undefined\n return {\n ...(style !== undefined && { style }),\n ...(color !== undefined && { color }),\n }\n}\n\nconst DESIGN_VARIANTS = [\n 'primary',\n 'secondary',\n 'tertiary',\n] as const satisfies readonly SparkButtonDesignVariant[]\n\nexport function isDesignColor(value: unknown): value is SparkButtonDesignColor {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as SparkButtonDesignColor).light === 'string'\n )\n}\n\nconst colorKey = (color: SparkButtonRole['color']) =>\n isDesignColor(color)\n ? JSON.stringify({ light: color.light, dark: color.dark })\n : color\n\nconst colorFromKey = (key: string | undefined): SparkButtonRole['color'] =>\n key?.startsWith('{')\n ? (JSON.parse(key) as SparkButtonDesignColor)\n : (key as SparkButtonColor | undefined)\n\nfunction parsableColor(\n variant: SparkButtonDesignVariant,\n color: SparkButtonRole['color'],\n): SparkButtonRole['color'] {\n if (!isDesignColor(color)) return color\n if (!isParsableColor(color.light)) {\n console.warn(\n `[Theme] Ignoring invalid buttons.${variant}.color \"${color.light}\".`,\n )\n return undefined\n }\n if (color.dark !== undefined && !isParsableColor(color.dark)) {\n console.warn(\n `[Theme] Ignoring invalid buttons.${variant}.color dark \"${color.dark}\".`,\n )\n return { light: color.light }\n }\n return color.dark === undefined ? { light: color.light } : color\n}\n\nfunction useButtonRoles(buttons: SparkButtonRoles | undefined) {\n const isSet = buttons !== undefined\n const { primary, secondary, tertiary } = buttons ?? {}\n const primaryStyle = primary?.style\n const primaryColor = colorKey(primary?.color)\n const secondaryStyle = secondary?.style\n const secondaryColor = colorKey(secondary?.color)\n const tertiaryStyle = tertiary?.style\n const tertiaryColor = colorKey(tertiary?.color)\n return React.useMemo<SparkButtonRoles | undefined>(() => {\n if (!isSet) return undefined\n const roles: SparkButtonRoles = {}\n const primaryRole = roleOf(\n primaryStyle,\n parsableColor('primary', colorFromKey(primaryColor)),\n )\n const secondaryRole = roleOf(\n secondaryStyle,\n parsableColor('secondary', colorFromKey(secondaryColor)),\n )\n const tertiaryRole = roleOf(\n tertiaryStyle,\n parsableColor('tertiary', colorFromKey(tertiaryColor)),\n )\n if (primaryRole) roles.primary = primaryRole\n if (secondaryRole) roles.secondary = secondaryRole\n if (tertiaryRole) roles.tertiary = tertiaryRole\n return roles\n }, [\n isSet,\n primaryStyle,\n primaryColor,\n secondaryStyle,\n secondaryColor,\n tertiaryStyle,\n tertiaryColor,\n ])\n}\n\nfunction mergeRoles(\n parent: SparkButtonRoles | undefined,\n own: SparkButtonRoles,\n): SparkButtonRoles {\n const merged: SparkButtonRoles = { ...parent }\n for (const variant of DESIGN_VARIANTS) {\n if (own[variant])\n merged[variant] = { ...parent?.[variant], ...own[variant] }\n }\n return merged\n}\n\nfunction buttonColorDecls(\n roles: SparkButtonRoles | undefined,\n appearance: Appearance,\n): string[] {\n const decls: string[] = []\n for (const variant of DESIGN_VARIANTS) {\n const color = roles?.[variant]?.color\n if (!isDesignColor(color)) continue\n const hex =\n appearance === 'dark' ? (color.dark ?? color.light) : color.light\n const scale = generateAccentScale(hex, appearance)\n const prefix = `--spark-button-${variant}`\n decls.push(\n ...scale.accentScale.map((c, i) => `${prefix}-${i + 1}: ${c};`),\n ...scale.accentScaleAlpha.map((c, i) => `${prefix}-a${i + 1}: ${c};`),\n `${prefix}-contrast: ${scale.accentContrast};`,\n `${prefix}-on-solid: ${scale.accentOnSolid};`,\n `${prefix}-surface: ${scale.accentSurface};`,\n )\n }\n return decls\n}\n\nfunction declsToVars(decls: string[]): Record<string, string> {\n return Object.fromEntries(\n decls.map((decl) => {\n const i = decl.indexOf(':')\n return [decl.slice(0, i).trim(), decl.slice(i + 1, -1).trim()]\n }),\n )\n}\n\nconst ThemeOutputContext = React.createContext<ThemeOutput | null>(null)\n\n/** Merged theme values from enclosing `<Theme>` providers. */\nexport function useTheme(): ThemeValue {\n return React.useContext(ThemeContext)\n}\n\nexport interface ThemeProps\n extends useRender.ComponentProps<'div'>, ThemeValue {}\n\n/** Optional sugar: writes the theming `data-*` attrs + accent `--spark-*` vars onto a wrapper. */\nexport const Theme = React.forwardRef<HTMLDivElement, ThemeProps>(\n function Theme(\n {\n accentColor,\n backgroundColor,\n neutralColor,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n inverted,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n buttons: buttonsProp,\n appearance,\n fontHeading,\n fontBody,\n render,\n className,\n style,\n children,\n ...rest\n },\n ref,\n ) {\n const parent = useTheme()\n const buttons = useButtonRoles(buttonsProp)\n const parentOutput = React.useContext(ThemeOutputContext)\n\n const value = React.useMemo<ThemeValue>(\n () => ({\n accentColor: accentColor ?? parent.accentColor,\n backgroundColor: backgroundColor ?? parent.backgroundColor,\n neutralColor: neutralColor ?? parent.neutralColor,\n radius: radius ?? parent.radius,\n scaling: scaling ?? parent.scaling,\n spacing: spacing ?? parent.spacing,\n styleVariant: styleVariant ?? parent.styleVariant,\n highContrast: highContrast ?? parent.highContrast,\n inverted: inverted ?? parent.inverted,\n labelPosition: labelPosition ?? parent.labelPosition,\n inputStyle: inputStyle ?? parent.inputStyle,\n inputColor: inputColor ?? parent.inputColor,\n cardVariant: cardVariant ?? parent.cardVariant,\n cardColor: cardColor ?? parent.cardColor,\n buttons: buttons ? mergeRoles(parent.buttons, buttons) : parent.buttons,\n appearance: appearance ?? parent.appearance,\n fontHeading: fontHeading ?? parent.fontHeading,\n fontBody: fontBody ?? parent.fontBody,\n }),\n [\n accentColor,\n backgroundColor,\n neutralColor,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n inverted,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n buttons,\n appearance,\n fontHeading,\n fontBody,\n parent,\n ],\n )\n\n // Scope id for the ambient-appearance case (both scales emitted in a <style>).\n const scopeId = React.useId()\n\n // 'auto' pairs a neutral with the canvas's own tint when it has one, else the\n // effective accent (Radix's grayColor=\"auto\") — see resolveAutoNeutral. Reads the\n // OWN backgroundColor, not the merged value.backgroundColor: optsFor (below) only\n // ever regenerates against a scope's own canvas too, so preferring an inherited one\n // here would resolve a seed that then gets silently discarded.\n const rawNeutralColor =\n neutralColor === 'auto'\n ? resolveAutoNeutral(\n value.accentColor ?? DEFAULT_ACCENT,\n backgroundColor,\n )\n : neutralColor\n\n // A custom neutral that isn't a recognized family must be a real, parseable color —\n // reject invalid input here (e.g. a typo'd family name like \"slat\") so it can't throw\n // deep inside the shared generator, where the catch below would otherwise blame\n // accentColor/backgroundColor without ever naming neutralColor as the actual cause.\n const neutralColorIsValid =\n rawNeutralColor === undefined ||\n isSparkNeutralFamily(rawNeutralColor) ||\n isParsableColor(rawNeutralColor)\n if (!neutralColorIsValid) {\n console.warn(\n `[Theme] Ignoring invalid neutralColor \"${rawNeutralColor}\" — falling back to the accent-matched family.`,\n )\n }\n const resolvedNeutralColor = neutralColorIsValid\n ? rawNeutralColor\n : getMatchingNeutral(value.accentColor ?? DEFAULT_ACCENT)\n\n // The DOM attribute stays one of the 6 static families `[data-neutral-color]` has CSS\n // for — a raw color (from the canvas-tinted auto path, or an arbitrary neutralColor\n // prop) falls back to its accent-matched family here instead, so the attribute is\n // always CSS-selectable/debuggable rather than a sentinel nothing matches.\n // generateAccentScale still gets the real resolvedNeutralColor for generation, below —\n // this substitution is display-only, and doesn't by itself guarantee the *other*\n // appearance's neutrals in ambient (no explicit `appearance`) mode: that's a\n // pre-existing cross-appearance leak in the same family as review-findings.md #5, not\n // something this attribute fallback fixes or regresses.\n const neutralColorAttr =\n resolvedNeutralColor === undefined\n ? undefined\n : isSparkNeutralFamily(resolvedNeutralColor)\n ? resolvedNeutralColor\n : getMatchingNeutral(value.accentColor ?? DEFAULT_ACCENT)\n\n const accent = React.useMemo(() => {\n const empty = {\n inlineVars: {} as React.CSSProperties,\n portalVars: {} as React.CSSProperties,\n portalScope: undefined as string | undefined,\n css: '',\n scoped: false,\n }\n // A custom canvas generates even with no accent of its own: the neutral ramp is\n // composited against it, and --spark-background has to carry it.\n if (!accentColor && !backgroundColor) return empty\n\n const toVars = (decls: string[]) =>\n Object.fromEntries(\n decls\n .filter((decl) => decl.includes(':'))\n .map((decl) => {\n const i = decl.indexOf(':')\n return [\n decl.slice(0, i).trim(),\n decl\n .slice(i + 1)\n .replace(/;$/, '')\n .trim(),\n ]\n }),\n ) as React.CSSProperties\n\n try {\n const source = value.accentColor ?? DEFAULT_ACCENT\n const hex = CURATED_ACCENTS[source] ?? source\n\n // A canvas has a polarity, unlike an accent hue: a yellow page is a *light*\n // page, and reusing it for the dark scale yields light ink on a light canvas\n // (measured 1.16:1). So the custom canvas applies to the appearance it actually\n // belongs to, and the other keeps its default. One knob still covers the common\n // case — a tenant wanting both sets an explicit appearance per scope.\n const bgAppearance = backgroundColor\n ? appearanceForBackground(backgroundColor)\n : undefined\n\n // Honouring a mismatched canvas would paint light ink on a light page, so it's\n // dropped — but say so, or the prop looks broken.\n if (\n backgroundColor &&\n value.appearance &&\n bgAppearance !== value.appearance\n ) {\n console.warn(\n `[Theme] Ignoring backgroundColor \"${backgroundColor}\": it reads as a ${bgAppearance} canvas on an appearance=\"${value.appearance}\" scope. Pass a ${value.appearance} colour, or set it on a scope whose appearance matches.`,\n )\n }\n\n // Default to slate so a regenerated neutral stays in the family the static\n // `:root` default already points at, rather than the generator's ECP gray seed.\n const optsFor = (appearance: Appearance) =>\n backgroundColor && bgAppearance === appearance\n ? {\n background: backgroundColor,\n neutral: resolvedNeutralColor ?? ('slate' as const),\n }\n : undefined\n\n // Neutrals are only worth regenerating against a custom canvas — see\n // neutralSparkVars. Without one the static Radix families are already correct.\n const emit = (scale: SparkAccentScale, custom: boolean) =>\n custom\n ? [...accentSparkVars(scale), ...neutralSparkVars(scale)]\n : accentSparkVars(scale)\n\n const build = (appearance: Appearance) => {\n const opts = optsFor(appearance)\n const scale = generateAccentScale(hex, appearance, opts)\n // `inverted` re-casts the accent for a solid-accent surface; the neutral ramp is\n // unrelated to that swap, so it passes through untouched.\n const rendered = emit(\n inverted ? invertAccentScale(scale) : scale,\n opts != null,\n )\n // Popups sit on their own surface, so they get the scale before the inverted re-cast.\n const plain = inverted ? emit(scale, opts != null) : rendered\n return { rendered, plain }\n }\n\n // Explicit appearance → single-scale inline vars. Correct for a light\n // island inside a dark page (which must NOT pick up the dark scale).\n if (value.appearance) {\n const { rendered, plain } = build(value.appearance)\n const inlineVars = toVars(rendered)\n return {\n inlineVars,\n portalVars: inverted ? toVars(plain) : inlineVars,\n portalScope: undefined,\n css: '',\n scoped: false,\n }\n }\n\n // Ambient appearance → emit BOTH scales in a scoped <style> so the\n // `.dark` class selects the right one. Without this, a single-appearance\n // inline scale (default light) breaks components in dark mode.\n //\n // Both blocks must declare the SAME tokens. A custom canvas only regenerates\n // neutrals for its own appearance (see optsFor), and a custom property the other\n // block leaves undeclared keeps its sibling's value rather than falling back — so\n // the off-canvas appearance would paint this one's canvas-tinted neutrals, and\n // being unlayered they'd beat `[data-neutral-color]`'s @layer base mapping too.\n // Point it at the static family instead: the same seed the canvas side was given,\n // so the two appearances agree on family and differ only in canvas.\n const offCanvasNeutrals = backgroundColor\n ? neutralFamilyVars(resolvedNeutralColor ?? 'slate')\n : []\n const scaleFor = (appearance: Appearance) => {\n const { rendered, plain } = build(appearance)\n const extra = bgAppearance === appearance ? [] : offCanvasNeutrals\n return {\n rendered: [...rendered, ...extra],\n plain: [...plain, ...extra],\n }\n }\n const light = scaleFor('light')\n const dark = scaleFor('dark')\n const rule = (\n id: string,\n lightDecls: string[],\n darkDecls: string[],\n ) => {\n const sel = `[data-spark-scope~=\"${id}\"]`\n return `${sel}{${lightDecls.join('')}}:is(.dark,.dark-theme) ${sel}{${darkDecls.join('')}}`\n }\n const portalScope = inverted ? `${scopeId}p` : scopeId\n const css =\n rule(scopeId, light.rendered, dark.rendered) +\n (inverted ? rule(portalScope, light.plain, dark.plain) : '')\n return {\n inlineVars: {} as React.CSSProperties,\n portalVars: {} as React.CSSProperties,\n portalScope,\n css,\n scoped: true,\n }\n } catch (error) {\n // A bad accentColor/backgroundColor must not throw through render — fall back\n // to the default theme.\n console.warn(\n `[Theme] Ignoring invalid accentColor \"${accentColor}\" / backgroundColor \"${backgroundColor}\".`,\n error,\n )\n return empty\n }\n }, [\n accentColor,\n backgroundColor,\n inverted,\n resolvedNeutralColor,\n value.accentColor,\n value.appearance,\n scopeId,\n ])\n\n const attrs = React.useMemo(\n () => ({\n 'data-neutral-color': neutralColorAttr,\n 'data-radius': radius,\n 'data-scaling': scaling,\n 'data-spacing': spacing,\n 'data-style': styleVariant,\n 'data-high-contrast': highContrast ? '' : undefined,\n 'data-label-position': labelPosition,\n 'data-input-style': inputStyle,\n 'data-input-color': inputColor,\n 'data-card-variant': cardVariant,\n 'data-card-color': cardColor,\n }),\n [\n neutralColorAttr,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n ],\n )\n const fontVars = React.useMemo(\n () => ({\n ...(fontHeading ? { '--spark-font-heading': fontHeading } : null),\n ...(fontBody ? { '--spark-font-body': fontBody } : null),\n }),\n [fontHeading, fontBody],\n )\n\n const buttonVars = React.useMemo(() => {\n if (value.appearance) {\n const decls = buttonColorDecls(buttons, value.appearance)\n return { vars: declsToVars(decls), scope: undefined, css: '' }\n }\n const light = buttonColorDecls(buttons, 'light')\n const dark = buttonColorDecls(buttons, 'dark')\n if (!light.length) return { vars: {}, scope: undefined, css: '' }\n const scope = `${scopeId}b`\n const sel = `[data-spark-scope~=\"${scope}\"]`\n return {\n vars: {},\n scope,\n css: `${sel}{${light.join('')}}:is(.dark,.dark-theme) ${sel}{${dark.join('')}}`,\n }\n }, [buttons, value.appearance, scopeId])\n\n const ownScopes = [\n ...(accent.scoped ? [scopeId] : []),\n ...(buttonVars.scope ? [buttonVars.scope] : []),\n ]\n\n const element = useRender({\n defaultTagName: 'div',\n render,\n ref,\n props: mergeProps<'div'>(\n {\n className: cn('spark-theme', appearance, className),\n ...attrs,\n 'data-inverted': inverted ? '' : undefined,\n 'data-spark-scope': ownScopes.length\n ? ownScopes.join(' ')\n : undefined,\n style: {\n ...accent.inlineVars,\n // Paint the canvas we were handed, else the prop emits a token and visibly\n // does nothing. Reads the var (not the raw prop) so the scoped <style>'s\n // per-appearance value still wins under ambient appearance.\n ...(backgroundColor\n ? { backgroundColor: 'var(--spark-background)' }\n : null),\n ...fontVars,\n ...buttonVars.vars,\n ...style,\n } as React.CSSProperties,\n children,\n } as React.ComponentProps<'div'>,\n rest,\n ),\n })\n\n const output = React.useMemo<ThemeOutput>(() => {\n // An unset own knob must not blank out the ancestor's value it inherits.\n const own = Object.fromEntries(\n Object.entries(attrs).filter(\n (entry): entry is [string, string] => entry[1] !== undefined,\n ),\n )\n const parentScopes = parentOutput?.scopes ?? []\n return {\n attrs: { ...parentOutput?.attrs, ...own },\n vars: {\n ...parentOutput?.vars,\n ...(accent.portalVars as Record<string, string>),\n ...fontVars,\n ...buttonVars.vars,\n },\n scopes: [\n ...parentScopes,\n ...(accent.portalScope ? [accent.portalScope] : []),\n ...(buttonVars.scope ? [buttonVars.scope] : []),\n ],\n }\n }, [parentOutput, attrs, accent, fontVars, buttonVars])\n\n return (\n <ThemeContext.Provider value={value}>\n <ThemeOutputContext.Provider value={output}>\n {accent.css ? <style>{accent.css}</style> : null}\n {buttonVars.css ? <style>{buttonVars.css}</style> : null}\n {element}\n </ThemeOutputContext.Provider>\n </ThemeContext.Provider>\n )\n },\n)\n\n/** Re-emits what the enclosing Themes rendered inside a portal, where CSS inheritance from them stops. */\nexport function PortalTheme({ children }: { children: React.ReactNode }) {\n const output = React.useContext(ThemeOutputContext)\n const theme = useTheme()\n // A popup sits on its own surface, never on the solid accent `inverted` is for.\n const value = React.useMemo(() => ({ ...theme, inverted: false }), [theme])\n if (!output) return <>{children}</>\n return (\n <ThemeContext.Provider value={value}>\n <div\n data-slot=\"portal-theme\"\n className={cn('spark-theme', theme.appearance)}\n {...output.attrs}\n data-spark-scope={\n output.scopes.length ? output.scopes.join(' ') : undefined\n }\n style={{ display: 'contents', ...output.vars }}\n >\n {children}\n </div>\n </ThemeContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;AA0DA,MAAM,iBAAiB;AAkDvB,MAAM,eAAeA,QAAM,cAA0B,CAAC,CAAC;AASvD,SAAS,OACP,OACA,OACA;CACA,IAAI,UAAU,KAAA,KAAa,UAAU,KAAA,GAAW,OAAO,KAAA;CACvD,OAAO;EACL,GAAI,UAAU,KAAA,KAAa,EAAE,MAAM;EACnC,GAAI,UAAU,KAAA,KAAa,EAAE,MAAM;CACrC;AACF;AAEA,MAAM,kBAAkB;CACtB;CACA;CACA;AACF;AAEA,SAAgB,cAAc,OAAiD;CAC7E,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAiC,UAAU;AAEvD;AAEA,MAAM,YAAY,UAChB,cAAc,KAAK,IACf,KAAK,UAAU;CAAE,OAAO,MAAM;CAAO,MAAM,MAAM;AAAK,CAAC,IACvD;AAEN,MAAM,gBAAgB,QACpB,KAAK,WAAW,GAAG,IACd,KAAK,MAAM,GAAG,IACd;AAEP,SAAS,cACP,SACA,OAC0B;CAC1B,IAAI,CAAC,cAAc,KAAK,GAAG,OAAO;CAClC,IAAI,CAAC,gBAAgB,MAAM,KAAK,GAAG;EACjC,QAAQ,KACN,oCAAoC,QAAQ,UAAU,MAAM,MAAM,GACpE;EACA;CACF;CACA,IAAI,MAAM,SAAS,KAAA,KAAa,CAAC,gBAAgB,MAAM,IAAI,GAAG;EAC5D,QAAQ,KACN,oCAAoC,QAAQ,eAAe,MAAM,KAAK,GACxE;EACA,OAAO,EAAE,OAAO,MAAM,MAAM;CAC9B;CACA,OAAO,MAAM,SAAS,KAAA,IAAY,EAAE,OAAO,MAAM,MAAM,IAAI;AAC7D;AAEA,SAAS,eAAe,SAAuC;CAC7D,MAAM,QAAQ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E,oBAAC,aAAa,UAAd;EAA8B;YAC5B,qBAAC,mBAAmB,UAApB;GAA6B,OAAO;aAApC;IACG,OAAO,MAAM,oBAAC,SAAD,EAAA,UAAQ,OAAO,IAAW,CAAA,IAAI;IAC3C,WAAW,MAAM,oBAAC,SAAD,EAAA,UAAQ,WAAW,IAAW,CAAA,IAAI;IACnD;GAC0B;;CACR,CAAA;AAE3B,CACF;;AAGA,SAAgB,YAAY,EAAE,YAA2C;CACvE,MAAM,SAASA,QAAM,WAAW,kBAAkB;CAClD,MAAM,QAAQ,SAAS;CAEvB,MAAM,QAAQA,QAAM,eAAe;EAAE,GAAG;EAAO,UAAU;CAAM,IAAI,CAAC,KAAK,CAAC;CAC1E,IAAI,CAAC,QAAQ,OAAO,oBAAA,UAAA,EAAG,SAAW,CAAA;CAClC,OACE,oBAAC,aAAa,UAAd;EAA8B;YAC5B,oBAAC,OAAD;GACE,aAAU;GACV,WAAW,GAAG,eAAe,MAAM,UAAU;GAC7C,GAAI,OAAO;GACX,oBACE,OAAO,OAAO,SAAS,OAAO,OAAO,KAAK,GAAG,IAAI,KAAA;GAEnD,OAAO;IAAE,SAAS;IAAY,GAAG,OAAO;GAAK;GAE5C;EACE,CAAA;CACgB,CAAA;AAE3B"}
1
+ {"version":3,"file":"theme.js","names":["React"],"sources":["../../src/components/theme.tsx"],"sourcesContent":["'use client'\n\nimport { mergeProps } from '@base-ui/react/merge-props'\nimport { useRender } from '@base-ui/react/use-render'\nimport * as React from 'react'\nimport { useFocusModality } from '../hooks/use-focus-modality'\nimport {\n CURATED_ACCENTS,\n accentSparkVars,\n appearanceForBackground,\n generateAccentScale,\n getMatchingNeutral,\n invertAccentScale,\n isParsableColor,\n neutralFamilyVars,\n neutralSparkVars,\n resolveAutoNeutral,\n type Appearance,\n type SparkAccentScale,\n} from '../lib/accent-theme'\nimport {\n isSparkNeutralFamily,\n type SparkButtonColor,\n type SparkButtonDesignColor,\n type SparkButtonDesignVariant,\n type SparkButtonRole,\n type SparkButtonRoles,\n type SparkCardColor,\n type SparkCardVariant,\n type SparkInputColor,\n type SparkInputStyle,\n type SparkLabelPosition,\n type SparkNeutral,\n type SparkRadius,\n type SparkScaling,\n type SparkSpacing,\n type SparkStyle,\n} from '../lib/theme-types'\nimport { cn } from '../utils/cn'\n\nexport type {\n SparkButtonColor,\n SparkButtonDesignVariant,\n SparkButtonRole,\n SparkButtonRoles,\n SparkCardColor,\n SparkCardVariant,\n SparkInputColor,\n SparkInputStyle,\n SparkLabelPosition,\n SparkNeutral,\n SparkNeutralFamily,\n SparkRadius,\n SparkScaling,\n SparkSpacing,\n SparkStyle,\n} from '../lib/theme-types'\n\n/** The epilot brand accent — the scale `spark-default.css` ships statically. */\nconst DEFAULT_ACCENT = '#005EB4'\n\nexport interface ThemeValue {\n /** Curated accent name or a custom hex. */\n accentColor?: string\n /**\n * Page canvas as a custom hex. Regenerates BOTH the accent and neutral scales against\n * it (each alpha step is composited against the canvas, so a saturated colour needs\n * the neutral ramp regenerated too, not just the accent). Unset → the fixed\n * `#ffffff` / `#000000` default, and neutrals stay on the static Radix families.\n */\n backgroundColor?: string\n /**\n * A curated family name, an arbitrary color to seed the neutral scale, or `'auto'` to\n * resolve one — preferring `backgroundColor`'s own hue when it's perceptibly tinted,\n * else pairing with the accent (Radix's `grayColor=\"auto\"`). A custom seed (from `auto`\n * or set directly) only regenerates the scale alongside a `backgroundColor`; without\n * one, `data-neutral-color` falls back to the accent-matched family and that's what\n * actually paints.\n */\n neutralColor?: SparkNeutral\n radius?: SparkRadius\n scaling?: SparkScaling\n spacing?: SparkSpacing\n styleVariant?: SparkStyle\n /** Orthogonal to `styleVariant`: shifts any style toward higher-contrast steps. */\n highContrast?: boolean\n /**\n * Orthogonal to `styleVariant`: re-casts the accent scale for use ON its own solid fill,\n * for controls sitting on a solid accent surface (a `<Card variant=\"solid\" color=\"accent\">`),\n * where a solid control would otherwise paint the same `--spark-9` as the card and vanish.\n * Swaps step 9 with its contrast ink, so the fill/ink pair stays WCAG-safe for any accent.\n */\n inverted?: boolean\n labelPosition?: SparkLabelPosition\n inputStyle?: SparkInputStyle\n inputColor?: SparkInputColor\n /** App-level default `<Card>` chrome; a per-card `variant` prop overrides it. */\n cardVariant?: SparkCardVariant\n /** App-level default `<Card>` palette; a per-card `color` prop overrides it. */\n cardColor?: SparkCardColor\n /** Looks of the `primary`, `secondary` and `tertiary` `<Button variant>`. */\n buttons?: SparkButtonRoles\n appearance?: Appearance\n /** Font stack for `h1`–`h6`. Any valid CSS `font-family` value. */\n fontHeading?: string\n /** Font stack for everything else. Any valid CSS `font-family` value. */\n fontBody?: string\n}\n\nconst ThemeContext = React.createContext<ThemeValue>({})\n\n/** What a Theme actually wrote to the DOM, merged over its ancestors (nearest wins). */\ninterface ThemeOutput {\n attrs: Record<string, string>\n vars: Record<string, string>\n scopes: string[]\n}\n\nfunction roleOf(\n style: SparkStyle | undefined,\n color: SparkButtonRole['color'],\n) {\n if (style === undefined && color === undefined) return undefined\n return {\n ...(style !== undefined && { style }),\n ...(color !== undefined && { color }),\n }\n}\n\nconst DESIGN_VARIANTS = [\n 'primary',\n 'secondary',\n 'tertiary',\n] as const satisfies readonly SparkButtonDesignVariant[]\n\nexport function isDesignColor(value: unknown): value is SparkButtonDesignColor {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as SparkButtonDesignColor).light === 'string'\n )\n}\n\nconst colorKey = (color: SparkButtonRole['color']) =>\n isDesignColor(color)\n ? JSON.stringify({ light: color.light, dark: color.dark })\n : color\n\nconst colorFromKey = (key: string | undefined): SparkButtonRole['color'] =>\n key?.startsWith('{')\n ? (JSON.parse(key) as SparkButtonDesignColor)\n : (key as SparkButtonColor | undefined)\n\nfunction parsableColor(\n variant: SparkButtonDesignVariant,\n color: SparkButtonRole['color'],\n): SparkButtonRole['color'] {\n if (!isDesignColor(color)) return color\n if (!isParsableColor(color.light)) {\n console.warn(\n `[Theme] Ignoring invalid buttons.${variant}.color \"${color.light}\".`,\n )\n return undefined\n }\n if (color.dark !== undefined && !isParsableColor(color.dark)) {\n console.warn(\n `[Theme] Ignoring invalid buttons.${variant}.color dark \"${color.dark}\".`,\n )\n return { light: color.light }\n }\n return color.dark === undefined ? { light: color.light } : color\n}\n\nfunction useButtonRoles(buttons: SparkButtonRoles | undefined) {\n const isSet = buttons !== undefined\n const { primary, secondary, tertiary } = buttons ?? {}\n const primaryStyle = primary?.style\n const primaryColor = colorKey(primary?.color)\n const secondaryStyle = secondary?.style\n const secondaryColor = colorKey(secondary?.color)\n const tertiaryStyle = tertiary?.style\n const tertiaryColor = colorKey(tertiary?.color)\n return React.useMemo<SparkButtonRoles | undefined>(() => {\n if (!isSet) return undefined\n const roles: SparkButtonRoles = {}\n const primaryRole = roleOf(\n primaryStyle,\n parsableColor('primary', colorFromKey(primaryColor)),\n )\n const secondaryRole = roleOf(\n secondaryStyle,\n parsableColor('secondary', colorFromKey(secondaryColor)),\n )\n const tertiaryRole = roleOf(\n tertiaryStyle,\n parsableColor('tertiary', colorFromKey(tertiaryColor)),\n )\n if (primaryRole) roles.primary = primaryRole\n if (secondaryRole) roles.secondary = secondaryRole\n if (tertiaryRole) roles.tertiary = tertiaryRole\n return roles\n }, [\n isSet,\n primaryStyle,\n primaryColor,\n secondaryStyle,\n secondaryColor,\n tertiaryStyle,\n tertiaryColor,\n ])\n}\n\nfunction mergeRoles(\n parent: SparkButtonRoles | undefined,\n own: SparkButtonRoles,\n): SparkButtonRoles {\n const merged: SparkButtonRoles = { ...parent }\n for (const variant of DESIGN_VARIANTS) {\n if (own[variant])\n merged[variant] = { ...parent?.[variant], ...own[variant] }\n }\n return merged\n}\n\nfunction buttonColorDecls(\n roles: SparkButtonRoles | undefined,\n appearance: Appearance,\n): string[] {\n const decls: string[] = []\n for (const variant of DESIGN_VARIANTS) {\n const color = roles?.[variant]?.color\n if (!isDesignColor(color)) continue\n const hex =\n appearance === 'dark' ? (color.dark ?? color.light) : color.light\n const scale = generateAccentScale(hex, appearance)\n const prefix = `--spark-button-${variant}`\n decls.push(\n ...scale.accentScale.map((c, i) => `${prefix}-${i + 1}: ${c};`),\n ...scale.accentScaleAlpha.map((c, i) => `${prefix}-a${i + 1}: ${c};`),\n `${prefix}-contrast: ${scale.accentContrast};`,\n `${prefix}-on-solid: ${scale.accentOnSolid};`,\n `${prefix}-surface: ${scale.accentSurface};`,\n )\n }\n return decls\n}\n\nfunction declsToVars(decls: string[]): Record<string, string> {\n return Object.fromEntries(\n decls.map((decl) => {\n const i = decl.indexOf(':')\n return [decl.slice(0, i).trim(), decl.slice(i + 1, -1).trim()]\n }),\n )\n}\n\nconst ThemeOutputContext = React.createContext<ThemeOutput | null>(null)\n\n/** Merged theme values from enclosing `<Theme>` providers. */\nexport function useTheme(): ThemeValue {\n return React.useContext(ThemeContext)\n}\n\nexport interface ThemeProps\n extends useRender.ComponentProps<'div'>, ThemeValue {}\n\n/** Optional sugar: writes the theming `data-*` attrs + accent `--spark-*` vars onto a wrapper. */\nexport const Theme = React.forwardRef<HTMLDivElement, ThemeProps>(\n function Theme(\n {\n accentColor,\n backgroundColor,\n neutralColor,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n inverted,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n buttons: buttonsProp,\n appearance,\n fontHeading,\n fontBody,\n render,\n className,\n style,\n children,\n ...rest\n },\n ref,\n ) {\n useFocusModality()\n const parent = useTheme()\n const buttons = useButtonRoles(buttonsProp)\n const parentOutput = React.useContext(ThemeOutputContext)\n\n const value = React.useMemo<ThemeValue>(\n () => ({\n accentColor: accentColor ?? parent.accentColor,\n backgroundColor: backgroundColor ?? parent.backgroundColor,\n neutralColor: neutralColor ?? parent.neutralColor,\n radius: radius ?? parent.radius,\n scaling: scaling ?? parent.scaling,\n spacing: spacing ?? parent.spacing,\n styleVariant: styleVariant ?? parent.styleVariant,\n highContrast: highContrast ?? parent.highContrast,\n inverted: inverted ?? parent.inverted,\n labelPosition: labelPosition ?? parent.labelPosition,\n inputStyle: inputStyle ?? parent.inputStyle,\n inputColor: inputColor ?? parent.inputColor,\n cardVariant: cardVariant ?? parent.cardVariant,\n cardColor: cardColor ?? parent.cardColor,\n buttons: buttons ? mergeRoles(parent.buttons, buttons) : parent.buttons,\n appearance: appearance ?? parent.appearance,\n fontHeading: fontHeading ?? parent.fontHeading,\n fontBody: fontBody ?? parent.fontBody,\n }),\n [\n accentColor,\n backgroundColor,\n neutralColor,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n inverted,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n buttons,\n appearance,\n fontHeading,\n fontBody,\n parent,\n ],\n )\n\n // Scope id for the ambient-appearance case (both scales emitted in a <style>).\n const scopeId = React.useId()\n\n // 'auto' pairs a neutral with the canvas's own tint when it has one, else the\n // effective accent (Radix's grayColor=\"auto\") — see resolveAutoNeutral. Reads the\n // OWN backgroundColor, not the merged value.backgroundColor: optsFor (below) only\n // ever regenerates against a scope's own canvas too, so preferring an inherited one\n // here would resolve a seed that then gets silently discarded.\n const rawNeutralColor =\n neutralColor === 'auto'\n ? resolveAutoNeutral(\n value.accentColor ?? DEFAULT_ACCENT,\n backgroundColor,\n )\n : neutralColor\n\n // A custom neutral that isn't a recognized family must be a real, parseable color —\n // reject invalid input here (e.g. a typo'd family name like \"slat\") so it can't throw\n // deep inside the shared generator, where the catch below would otherwise blame\n // accentColor/backgroundColor without ever naming neutralColor as the actual cause.\n const neutralColorIsValid =\n rawNeutralColor === undefined ||\n isSparkNeutralFamily(rawNeutralColor) ||\n isParsableColor(rawNeutralColor)\n if (!neutralColorIsValid) {\n console.warn(\n `[Theme] Ignoring invalid neutralColor \"${rawNeutralColor}\" — falling back to the accent-matched family.`,\n )\n }\n const resolvedNeutralColor = neutralColorIsValid\n ? rawNeutralColor\n : getMatchingNeutral(value.accentColor ?? DEFAULT_ACCENT)\n\n // The DOM attribute stays one of the 6 static families `[data-neutral-color]` has CSS\n // for — a raw color (from the canvas-tinted auto path, or an arbitrary neutralColor\n // prop) falls back to its accent-matched family here instead, so the attribute is\n // always CSS-selectable/debuggable rather than a sentinel nothing matches.\n // generateAccentScale still gets the real resolvedNeutralColor for generation, below —\n // this substitution is display-only, and doesn't by itself guarantee the *other*\n // appearance's neutrals in ambient (no explicit `appearance`) mode: that's a\n // pre-existing cross-appearance leak in the same family as review-findings.md #5, not\n // something this attribute fallback fixes or regresses.\n const neutralColorAttr =\n resolvedNeutralColor === undefined\n ? undefined\n : isSparkNeutralFamily(resolvedNeutralColor)\n ? resolvedNeutralColor\n : getMatchingNeutral(value.accentColor ?? DEFAULT_ACCENT)\n\n const accent = React.useMemo(() => {\n const empty = {\n inlineVars: {} as React.CSSProperties,\n portalVars: {} as React.CSSProperties,\n portalScope: undefined as string | undefined,\n css: '',\n scoped: false,\n }\n // A custom canvas generates even with no accent of its own: the neutral ramp is\n // composited against it, and --spark-background has to carry it.\n if (!accentColor && !backgroundColor) return empty\n\n const toVars = (decls: string[]) =>\n Object.fromEntries(\n decls\n .filter((decl) => decl.includes(':'))\n .map((decl) => {\n const i = decl.indexOf(':')\n return [\n decl.slice(0, i).trim(),\n decl\n .slice(i + 1)\n .replace(/;$/, '')\n .trim(),\n ]\n }),\n ) as React.CSSProperties\n\n try {\n const source = value.accentColor ?? DEFAULT_ACCENT\n const hex = CURATED_ACCENTS[source] ?? source\n\n // A canvas has a polarity, unlike an accent hue: a yellow page is a *light*\n // page, and reusing it for the dark scale yields light ink on a light canvas\n // (measured 1.16:1). So the custom canvas applies to the appearance it actually\n // belongs to, and the other keeps its default. One knob still covers the common\n // case — a tenant wanting both sets an explicit appearance per scope.\n const bgAppearance = backgroundColor\n ? appearanceForBackground(backgroundColor)\n : undefined\n\n // Honouring a mismatched canvas would paint light ink on a light page, so it's\n // dropped — but say so, or the prop looks broken.\n if (\n backgroundColor &&\n value.appearance &&\n bgAppearance !== value.appearance\n ) {\n console.warn(\n `[Theme] Ignoring backgroundColor \"${backgroundColor}\": it reads as a ${bgAppearance} canvas on an appearance=\"${value.appearance}\" scope. Pass a ${value.appearance} colour, or set it on a scope whose appearance matches.`,\n )\n }\n\n // Default to slate so a regenerated neutral stays in the family the static\n // `:root` default already points at, rather than the generator's ECP gray seed.\n const optsFor = (appearance: Appearance) =>\n backgroundColor && bgAppearance === appearance\n ? {\n background: backgroundColor,\n neutral: resolvedNeutralColor ?? ('slate' as const),\n }\n : undefined\n\n // Neutrals are only worth regenerating against a custom canvas — see\n // neutralSparkVars. Without one the static Radix families are already correct.\n const emit = (scale: SparkAccentScale, custom: boolean) =>\n custom\n ? [...accentSparkVars(scale), ...neutralSparkVars(scale)]\n : accentSparkVars(scale)\n\n const build = (appearance: Appearance) => {\n const opts = optsFor(appearance)\n const scale = generateAccentScale(hex, appearance, opts)\n // `inverted` re-casts the accent for a solid-accent surface; the neutral ramp is\n // unrelated to that swap, so it passes through untouched.\n const rendered = emit(\n inverted ? invertAccentScale(scale) : scale,\n opts != null,\n )\n // Popups sit on their own surface, so they get the scale before the inverted re-cast.\n const plain = inverted ? emit(scale, opts != null) : rendered\n return { rendered, plain }\n }\n\n // Explicit appearance → single-scale inline vars. Correct for a light\n // island inside a dark page (which must NOT pick up the dark scale).\n if (value.appearance) {\n const { rendered, plain } = build(value.appearance)\n const inlineVars = toVars(rendered)\n return {\n inlineVars,\n portalVars: inverted ? toVars(plain) : inlineVars,\n portalScope: undefined,\n css: '',\n scoped: false,\n }\n }\n\n // Ambient appearance → emit BOTH scales in a scoped <style> so the\n // `.dark` class selects the right one. Without this, a single-appearance\n // inline scale (default light) breaks components in dark mode.\n //\n // Both blocks must declare the SAME tokens. A custom canvas only regenerates\n // neutrals for its own appearance (see optsFor), and a custom property the other\n // block leaves undeclared keeps its sibling's value rather than falling back — so\n // the off-canvas appearance would paint this one's canvas-tinted neutrals, and\n // being unlayered they'd beat `[data-neutral-color]`'s @layer base mapping too.\n // Point it at the static family instead: the same seed the canvas side was given,\n // so the two appearances agree on family and differ only in canvas.\n const offCanvasNeutrals = backgroundColor\n ? neutralFamilyVars(resolvedNeutralColor ?? 'slate')\n : []\n const scaleFor = (appearance: Appearance) => {\n const { rendered, plain } = build(appearance)\n const extra = bgAppearance === appearance ? [] : offCanvasNeutrals\n return {\n rendered: [...rendered, ...extra],\n plain: [...plain, ...extra],\n }\n }\n const light = scaleFor('light')\n const dark = scaleFor('dark')\n const rule = (\n id: string,\n lightDecls: string[],\n darkDecls: string[],\n ) => {\n const sel = `[data-spark-scope~=\"${id}\"]`\n return `${sel}{${lightDecls.join('')}}:is(.dark,.dark-theme) ${sel}{${darkDecls.join('')}}`\n }\n const portalScope = inverted ? `${scopeId}p` : scopeId\n const css =\n rule(scopeId, light.rendered, dark.rendered) +\n (inverted ? rule(portalScope, light.plain, dark.plain) : '')\n return {\n inlineVars: {} as React.CSSProperties,\n portalVars: {} as React.CSSProperties,\n portalScope,\n css,\n scoped: true,\n }\n } catch (error) {\n // A bad accentColor/backgroundColor must not throw through render — fall back\n // to the default theme.\n console.warn(\n `[Theme] Ignoring invalid accentColor \"${accentColor}\" / backgroundColor \"${backgroundColor}\".`,\n error,\n )\n return empty\n }\n }, [\n accentColor,\n backgroundColor,\n inverted,\n resolvedNeutralColor,\n value.accentColor,\n value.appearance,\n scopeId,\n ])\n\n const attrs = React.useMemo(\n () => ({\n 'data-neutral-color': neutralColorAttr,\n 'data-radius': radius,\n 'data-scaling': scaling,\n 'data-spacing': spacing,\n 'data-style': styleVariant,\n 'data-high-contrast': highContrast ? '' : undefined,\n 'data-label-position': labelPosition,\n 'data-input-style': inputStyle,\n 'data-input-color': inputColor,\n 'data-card-variant': cardVariant,\n 'data-card-color': cardColor,\n }),\n [\n neutralColorAttr,\n radius,\n scaling,\n spacing,\n styleVariant,\n highContrast,\n labelPosition,\n inputStyle,\n inputColor,\n cardVariant,\n cardColor,\n ],\n )\n const fontVars = React.useMemo(\n () => ({\n ...(fontHeading ? { '--spark-font-heading': fontHeading } : null),\n ...(fontBody ? { '--spark-font-body': fontBody } : null),\n }),\n [fontHeading, fontBody],\n )\n\n const buttonVars = React.useMemo(() => {\n if (value.appearance) {\n const decls = buttonColorDecls(buttons, value.appearance)\n return { vars: declsToVars(decls), scope: undefined, css: '' }\n }\n const light = buttonColorDecls(buttons, 'light')\n const dark = buttonColorDecls(buttons, 'dark')\n if (!light.length) return { vars: {}, scope: undefined, css: '' }\n const scope = `${scopeId}b`\n const sel = `[data-spark-scope~=\"${scope}\"]`\n return {\n vars: {},\n scope,\n css: `${sel}{${light.join('')}}:is(.dark,.dark-theme) ${sel}{${dark.join('')}}`,\n }\n }, [buttons, value.appearance, scopeId])\n\n const ownScopes = [\n ...(accent.scoped ? [scopeId] : []),\n ...(buttonVars.scope ? [buttonVars.scope] : []),\n ]\n\n const element = useRender({\n defaultTagName: 'div',\n render,\n ref,\n props: mergeProps<'div'>(\n {\n className: cn('spark-theme', appearance, className),\n ...attrs,\n 'data-inverted': inverted ? '' : undefined,\n 'data-spark-scope': ownScopes.length\n ? ownScopes.join(' ')\n : undefined,\n style: {\n ...accent.inlineVars,\n // Paint the canvas we were handed, else the prop emits a token and visibly\n // does nothing. Reads the var (not the raw prop) so the scoped <style>'s\n // per-appearance value still wins under ambient appearance.\n ...(backgroundColor\n ? { backgroundColor: 'var(--spark-background)' }\n : null),\n ...fontVars,\n ...buttonVars.vars,\n ...style,\n } as React.CSSProperties,\n children,\n } as React.ComponentProps<'div'>,\n rest,\n ),\n })\n\n const output = React.useMemo<ThemeOutput>(() => {\n // An unset own knob must not blank out the ancestor's value it inherits.\n const own = Object.fromEntries(\n Object.entries(attrs).filter(\n (entry): entry is [string, string] => entry[1] !== undefined,\n ),\n )\n const parentScopes = parentOutput?.scopes ?? []\n return {\n attrs: { ...parentOutput?.attrs, ...own },\n vars: {\n ...parentOutput?.vars,\n ...(accent.portalVars as Record<string, string>),\n ...fontVars,\n ...buttonVars.vars,\n },\n scopes: [\n ...parentScopes,\n ...(accent.portalScope ? [accent.portalScope] : []),\n ...(buttonVars.scope ? [buttonVars.scope] : []),\n ],\n }\n }, [parentOutput, attrs, accent, fontVars, buttonVars])\n\n return (\n <ThemeContext.Provider value={value}>\n <ThemeOutputContext.Provider value={output}>\n {accent.css ? <style>{accent.css}</style> : null}\n {buttonVars.css ? <style>{buttonVars.css}</style> : null}\n {element}\n </ThemeOutputContext.Provider>\n </ThemeContext.Provider>\n )\n },\n)\n\n/** Re-emits what the enclosing Themes rendered inside a portal, where CSS inheritance from them stops. */\nexport function PortalTheme({ children }: { children: React.ReactNode }) {\n const output = React.useContext(ThemeOutputContext)\n const theme = useTheme()\n // A popup sits on its own surface, never on the solid accent `inverted` is for.\n const value = React.useMemo(() => ({ ...theme, inverted: false }), [theme])\n if (!output) return <>{children}</>\n return (\n <ThemeContext.Provider value={value}>\n <div\n data-slot=\"portal-theme\"\n className={cn('spark-theme', theme.appearance)}\n {...output.attrs}\n data-spark-scope={\n output.scopes.length ? output.scopes.join(' ') : undefined\n }\n style={{ display: 'contents', ...output.vars }}\n >\n {children}\n </div>\n </ThemeContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;AA2DA,MAAM,iBAAiB;AAkDvB,MAAM,eAAeA,QAAM,cAA0B,CAAC,CAAC;AASvD,SAAS,OACP,OACA,OACA;CACA,IAAI,UAAU,KAAA,KAAa,UAAU,KAAA,GAAW,OAAO,KAAA;CACvD,OAAO;EACL,GAAI,UAAU,KAAA,KAAa,EAAE,MAAM;EACnC,GAAI,UAAU,KAAA,KAAa,EAAE,MAAM;CACrC;AACF;AAEA,MAAM,kBAAkB;CACtB;CACA;CACA;AACF;AAEA,SAAgB,cAAc,OAAiD;CAC7E,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAiC,UAAU;AAEvD;AAEA,MAAM,YAAY,UAChB,cAAc,KAAK,IACf,KAAK,UAAU;CAAE,OAAO,MAAM;CAAO,MAAM,MAAM;AAAK,CAAC,IACvD;AAEN,MAAM,gBAAgB,QACpB,KAAK,WAAW,GAAG,IACd,KAAK,M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K;GAE5C;EACE,CAAA;CACgB,CAAA;AAE3B"}
@@ -0,0 +1,55 @@
1
+ "use client";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ let react = require("react");
4
+ //#region src/hooks/use-focus-modality.ts
5
+ const FOCUS_MODALITY_ATTRIBUTE = "data-spark-focus";
6
+ const TEXT_ENTRY_INPUT_TYPES = new Set([
7
+ "text",
8
+ "search",
9
+ "email",
10
+ "url",
11
+ "tel",
12
+ "password",
13
+ "number",
14
+ "date",
15
+ "datetime-local",
16
+ "month",
17
+ "week",
18
+ "time"
19
+ ]);
20
+ function isTextEntry(target) {
21
+ if (!(target instanceof HTMLElement)) return false;
22
+ if (target instanceof HTMLTextAreaElement) return true;
23
+ if (target instanceof HTMLInputElement) return TEXT_ENTRY_INPUT_TYPES.has(target.type);
24
+ return target.isContentEditable;
25
+ }
26
+ function onPointerDown() {
27
+ document.documentElement.setAttribute(FOCUS_MODALITY_ATTRIBUTE, "pointer");
28
+ }
29
+ function onKeyDown(event) {
30
+ if (event.metaKey || event.ctrlKey || event.altKey) return;
31
+ if (event.key !== "Tab" && isTextEntry(event.target)) return;
32
+ document.documentElement.removeAttribute(FOCUS_MODALITY_ATTRIBUTE);
33
+ }
34
+ let subscribers = 0;
35
+ function subscribe() {
36
+ if (subscribers++ === 0) {
37
+ document.addEventListener("pointerdown", onPointerDown, true);
38
+ document.addEventListener("keydown", onKeyDown, true);
39
+ }
40
+ return () => {
41
+ if (--subscribers === 0) {
42
+ document.removeEventListener("pointerdown", onPointerDown, true);
43
+ document.removeEventListener("keydown", onKeyDown, true);
44
+ document.documentElement.removeAttribute(FOCUS_MODALITY_ATTRIBUTE);
45
+ }
46
+ };
47
+ }
48
+ function useFocusModality() {
49
+ (0, react.useEffect)(subscribe, []);
50
+ }
51
+ //#endregion
52
+ exports.FOCUS_MODALITY_ATTRIBUTE = FOCUS_MODALITY_ATTRIBUTE;
53
+ exports.useFocusModality = useFocusModality;
54
+
55
+ //# sourceMappingURL=use-focus-modality.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-focus-modality.cjs","names":[],"sources":["../../src/hooks/use-focus-modality.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const FOCUS_MODALITY_ATTRIBUTE = 'data-spark-focus'\n\nconst TEXT_ENTRY_INPUT_TYPES = new Set([\n 'text',\n 'search',\n 'email',\n 'url',\n 'tel',\n 'password',\n 'number',\n 'date',\n 'datetime-local',\n 'month',\n 'week',\n 'time',\n])\n\nfunction isTextEntry(target: EventTarget | null) {\n if (!(target instanceof HTMLElement)) return false\n if (target instanceof HTMLTextAreaElement) return true\n if (target instanceof HTMLInputElement)\n return TEXT_ENTRY_INPUT_TYPES.has(target.type)\n return target.isContentEditable\n}\n\nfunction onPointerDown() {\n document.documentElement.setAttribute(FOCUS_MODALITY_ATTRIBUTE, 'pointer')\n}\n\nfunction onKeyDown(event: KeyboardEvent) {\n if (event.metaKey || event.ctrlKey || event.altKey) return\n if (event.key !== 'Tab' && isTextEntry(event.target)) return\n document.documentElement.removeAttribute(FOCUS_MODALITY_ATTRIBUTE)\n}\n\nlet subscribers = 0\n\nfunction subscribe() {\n if (subscribers++ === 0) {\n document.addEventListener('pointerdown', onPointerDown, true)\n document.addEventListener('keydown', onKeyDown, true)\n }\n return () => {\n if (--subscribers === 0) {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('keydown', onKeyDown, true)\n document.documentElement.removeAttribute(FOCUS_MODALITY_ATTRIBUTE)\n }\n }\n}\n\nfunction useFocusModality() {\n useEffect(subscribe, [])\n}\n\nexport { useFocusModality }\n"],"mappings":";;;;AAEA,MAAa,2BAA2B;AAExC,MAAM,yBAAyB,IAAI,IAAI;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,YAAY,QAA4B;CAC/C,IAAI,EAAE,kBAAkB,cAAc,OAAO;CAC7C,IAAI,kBAAkB,qBAAqB,OAAO;CAClD,IAAI,kBAAkB,kBACpB,OAAO,uBAAuB,IAAI,OAAO,IAAI;CAC/C,OAAO,OAAO;AAChB;AAEA,SAAS,gBAAgB;CACvB,SAAS,gBAAgB,aAAa,0BAA0B,SAAS;AAC3E;AAEA,SAAS,UAAU,OAAsB;CACvC,IAAI,MAAM,WAAW,MAAM,WAAW,MAAM,QAAQ;CACpD,IAAI,MAAM,QAAQ,SAAS,YAAY,MAAM,MAAM,GAAG;CACtD,SAAS,gBAAgB,gBAAgB,wBAAwB;AACnE;AAEA,IAAI,cAAc;AAElB,SAAS,YAAY;CACnB,IAAI,kBAAkB,GAAG;EACvB,SAAS,iBAAiB,eAAe,eAAe,IAAI;EAC5D,SAAS,iBAAiB,WAAW,WAAW,IAAI;CACtD;CACA,aAAa;EACX,IAAI,EAAE,gBAAgB,GAAG;GACvB,SAAS,oBAAoB,eAAe,eAAe,IAAI;GAC/D,SAAS,oBAAoB,WAAW,WAAW,IAAI;GACvD,SAAS,gBAAgB,gBAAgB,wBAAwB;EACnE;CACF;AACF;AAEA,SAAS,mBAAmB;CAC1B,CAAA,GAAA,MAAA,WAAU,WAAW,CAAC,CAAC;AACzB"}
@@ -0,0 +1,8 @@
1
+ "use client";
2
+
3
+ //#region src/hooks/use-focus-modality.d.ts
4
+ declare const FOCUS_MODALITY_ATTRIBUTE = "data-spark-focus";
5
+ declare function useFocusModality(): void;
6
+ //#endregion
7
+ export { FOCUS_MODALITY_ATTRIBUTE, useFocusModality };
8
+ //# sourceMappingURL=use-focus-modality.d.cts.map
@@ -0,0 +1,8 @@
1
+ "use client";
2
+
3
+ //#region src/hooks/use-focus-modality.d.ts
4
+ declare const FOCUS_MODALITY_ATTRIBUTE = "data-spark-focus";
5
+ declare function useFocusModality(): void;
6
+ //#endregion
7
+ export { FOCUS_MODALITY_ATTRIBUTE, useFocusModality };
8
+ //# sourceMappingURL=use-focus-modality.d.ts.map
@@ -0,0 +1,53 @@
1
+ "use client";
2
+ import { useEffect } from "react";
3
+ //#region src/hooks/use-focus-modality.ts
4
+ const FOCUS_MODALITY_ATTRIBUTE = "data-spark-focus";
5
+ const TEXT_ENTRY_INPUT_TYPES = new Set([
6
+ "text",
7
+ "search",
8
+ "email",
9
+ "url",
10
+ "tel",
11
+ "password",
12
+ "number",
13
+ "date",
14
+ "datetime-local",
15
+ "month",
16
+ "week",
17
+ "time"
18
+ ]);
19
+ function isTextEntry(target) {
20
+ if (!(target instanceof HTMLElement)) return false;
21
+ if (target instanceof HTMLTextAreaElement) return true;
22
+ if (target instanceof HTMLInputElement) return TEXT_ENTRY_INPUT_TYPES.has(target.type);
23
+ return target.isContentEditable;
24
+ }
25
+ function onPointerDown() {
26
+ document.documentElement.setAttribute(FOCUS_MODALITY_ATTRIBUTE, "pointer");
27
+ }
28
+ function onKeyDown(event) {
29
+ if (event.metaKey || event.ctrlKey || event.altKey) return;
30
+ if (event.key !== "Tab" && isTextEntry(event.target)) return;
31
+ document.documentElement.removeAttribute(FOCUS_MODALITY_ATTRIBUTE);
32
+ }
33
+ let subscribers = 0;
34
+ function subscribe() {
35
+ if (subscribers++ === 0) {
36
+ document.addEventListener("pointerdown", onPointerDown, true);
37
+ document.addEventListener("keydown", onKeyDown, true);
38
+ }
39
+ return () => {
40
+ if (--subscribers === 0) {
41
+ document.removeEventListener("pointerdown", onPointerDown, true);
42
+ document.removeEventListener("keydown", onKeyDown, true);
43
+ document.documentElement.removeAttribute(FOCUS_MODALITY_ATTRIBUTE);
44
+ }
45
+ };
46
+ }
47
+ function useFocusModality() {
48
+ useEffect(subscribe, []);
49
+ }
50
+ //#endregion
51
+ export { FOCUS_MODALITY_ATTRIBUTE, useFocusModality };
52
+
53
+ //# sourceMappingURL=use-focus-modality.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-focus-modality.js","names":[],"sources":["../../src/hooks/use-focus-modality.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const FOCUS_MODALITY_ATTRIBUTE = 'data-spark-focus'\n\nconst TEXT_ENTRY_INPUT_TYPES = new Set([\n 'text',\n 'search',\n 'email',\n 'url',\n 'tel',\n 'password',\n 'number',\n 'date',\n 'datetime-local',\n 'month',\n 'week',\n 'time',\n])\n\nfunction isTextEntry(target: EventTarget | null) {\n if (!(target instanceof HTMLElement)) return false\n if (target instanceof HTMLTextAreaElement) return true\n if (target instanceof HTMLInputElement)\n return TEXT_ENTRY_INPUT_TYPES.has(target.type)\n return target.isContentEditable\n}\n\nfunction onPointerDown() {\n document.documentElement.setAttribute(FOCUS_MODALITY_ATTRIBUTE, 'pointer')\n}\n\nfunction onKeyDown(event: KeyboardEvent) {\n if (event.metaKey || event.ctrlKey || event.altKey) return\n if (event.key !== 'Tab' && isTextEntry(event.target)) return\n document.documentElement.removeAttribute(FOCUS_MODALITY_ATTRIBUTE)\n}\n\nlet subscribers = 0\n\nfunction subscribe() {\n if (subscribers++ === 0) {\n document.addEventListener('pointerdown', onPointerDown, true)\n document.addEventListener('keydown', onKeyDown, true)\n }\n return () => {\n if (--subscribers === 0) {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('keydown', onKeyDown, true)\n document.documentElement.removeAttribute(FOCUS_MODALITY_ATTRIBUTE)\n }\n }\n}\n\nfunction useFocusModality() {\n useEffect(subscribe, [])\n}\n\nexport { useFocusModality }\n"],"mappings":";;;AAEA,MAAa,2BAA2B;AAExC,MAAM,yBAAyB,IAAI,IAAI;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,YAAY,QAA4B;CAC/C,IAAI,EAAE,kBAAkB,cAAc,OAAO;CAC7C,IAAI,kBAAkB,qBAAqB,OAAO;CAClD,IAAI,kBAAkB,kBACpB,OAAO,uBAAuB,IAAI,OAAO,IAAI;CAC/C,OAAO,OAAO;AAChB;AAEA,SAAS,gBAAgB;CACvB,SAAS,gBAAgB,aAAa,0BAA0B,SAAS;AAC3E;AAEA,SAAS,UAAU,OAAsB;CACvC,IAAI,MAAM,WAAW,MAAM,WAAW,MAAM,QAAQ;CACpD,IAAI,MAAM,QAAQ,SAAS,YAAY,MAAM,MAAM,GAAG;CACtD,SAAS,gBAAgB,gBAAgB,wBAAwB;AACnE;AAEA,IAAI,cAAc;AAElB,SAAS,YAAY;CACnB,IAAI,kBAAkB,GAAG;EACvB,SAAS,iBAAiB,eAAe,eAAe,IAAI;EAC5D,SAAS,iBAAiB,WAAW,WAAW,IAAI;CACtD;CACA,aAAa;EACX,IAAI,EAAE,gBAAgB,GAAG;GACvB,SAAS,oBAAoB,eAAe,eAAe,IAAI;GAC/D,SAAS,oBAAoB,WAAW,WAAW,IAAI;GACvD,SAAS,gBAAgB,gBAAgB,wBAAwB;EACnE;CACF;AACF;AAEA,SAAS,mBAAmB;CAC1B,UAAU,WAAW,CAAC,CAAC;AACzB"}
@@ -15,11 +15,18 @@
15
15
  :is([data-slot='input'], [data-slot='textarea']):not(:placeholder-shown)
16
16
  ),
17
17
  :has(
18
- :is([data-slot='input'], [data-slot='textarea']):not([placeholder=' '])
18
+ :is([data-slot='input'], [data-slot='textarea']):not(
19
+ [placeholder=' '],
20
+ [data-focus-placeholder]
21
+ )
19
22
  ),
20
23
  :has(:is([data-slot='input'], [data-slot='textarea']):autofill),
21
- :has([data-slot='select-trigger']:not([data-placeholder])),
22
- :has([data-slot='select-trigger'][data-popup-open])
24
+ :has(
25
+ :is([data-slot='select-trigger'], [data-slot='combobox-trigger']):not(
26
+ [data-placeholder]
27
+ )
28
+ ),
29
+ :has([data-popup-open])
23
30
  )
24
31
  & {
25
32
  @slot;
@@ -623,6 +630,41 @@
623
630
  }
624
631
  }
625
632
 
633
+ :root[data-spark-focus='pointer']
634
+ :is(
635
+ input:not(
636
+ [type='checkbox'],
637
+ [type='radio'],
638
+ [type='range'],
639
+ [type='button'],
640
+ [type='submit'],
641
+ [type='reset'],
642
+ [type='color'],
643
+ [type='file']
644
+ ),
645
+ textarea,
646
+ [contenteditable]
647
+ ):focus-visible,
648
+ :root[data-spark-focus='pointer']
649
+ :is([data-slot='input-group'], [data-slot='field']):has(
650
+ :is(
651
+ input:not(
652
+ [type='checkbox'],
653
+ [type='radio'],
654
+ [type='range'],
655
+ [type='button'],
656
+ [type='submit'],
657
+ [type='reset'],
658
+ [type='color'],
659
+ [type='file']
660
+ ),
661
+ textarea,
662
+ [contenteditable]
663
+ ):focus-visible
664
+ ) {
665
+ outline: none;
666
+ }
667
+
626
668
  /* The focus indicator, for wrappers that draw it when focus lands on an inner control (contract §12). */
627
669
  @utility focus-outline {
628
670
  outline: 2px solid var(--color-focus-root);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epilot/spark-ui",
3
- "version": "0.30.0",
3
+ "version": "0.30.2",
4
4
  "description": "React UI component library from Spark SDK",
5
5
  "homepage": "https://spark-ui.epilot.io/docs/ui",
6
6
  "license": "Apache-2.0",