@epilot/spark-ui 0.30.0 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/autocomplete.cjs +9 -2
- package/dist/components/autocomplete.cjs.map +1 -1
- package/dist/components/autocomplete.js +10 -3
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/button.d.cts +2 -2
- package/dist/components/button.d.ts +2 -2
- package/dist/components/combobox.cjs +2 -1
- package/dist/components/combobox.cjs.map +1 -1
- package/dist/components/combobox.js +3 -2
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/field.cjs +18 -3
- package/dist/components/field.cjs.map +1 -1
- package/dist/components/field.d.cts +3 -1
- package/dist/components/field.d.ts +3 -1
- package/dist/components/field.js +18 -4
- package/dist/components/field.js.map +1 -1
- package/dist/components/info-block.d.cts +1 -1
- package/dist/components/info-block.d.ts +1 -1
- package/dist/components/input-date.cjs +11 -1
- package/dist/components/input-date.cjs.map +1 -1
- package/dist/components/input-date.js +11 -1
- package/dist/components/input-date.js.map +1 -1
- package/dist/components/input-otp.cjs +1 -0
- package/dist/components/input-otp.cjs.map +1 -1
- package/dist/components/input-otp.js +2 -1
- package/dist/components/input-otp.js.map +1 -1
- package/dist/components/marker.d.cts +1 -1
- package/dist/components/marker.d.ts +1 -1
- package/dist/components/page-header.d.cts +1 -1
- package/dist/components/page-header.d.ts +1 -1
- package/dist/components/theme.cjs +2 -0
- package/dist/components/theme.cjs.map +1 -1
- package/dist/components/theme.js +2 -0
- package/dist/components/theme.js.map +1 -1
- package/dist/hooks/use-focus-modality.cjs +55 -0
- package/dist/hooks/use-focus-modality.cjs.map +1 -0
- package/dist/hooks/use-focus-modality.d.cts +8 -0
- package/dist/hooks/use-focus-modality.d.ts +8 -0
- package/dist/hooks/use-focus-modality.js +53 -0
- package/dist/hooks/use-focus-modality.js.map +1 -0
- package/dist/styles/theme.css +45 -3
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import { cn } from "../utils/cn.js";
|
|
4
4
|
import { Button } from "./button.js";
|
|
5
|
+
import { useFieldContext } from "./field.js";
|
|
5
6
|
import { InputGroup, InputGroupAddon, InputGroupInput } from "./input-group.js";
|
|
6
7
|
import { Calendar } from "./calendar.js";
|
|
7
8
|
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "./popover.js";
|
|
@@ -18,8 +19,16 @@ function useControllableState({ defaultProp, onChange, prop }) {
|
|
|
18
19
|
onChange?.(next);
|
|
19
20
|
}, [isControlled, onChange])];
|
|
20
21
|
}
|
|
22
|
+
function useMaskHintOnFocus(placeholder) {
|
|
23
|
+
if (!(useFieldContext()?.labelPosition === "floating") || placeholder !== void 0) return {};
|
|
24
|
+
return {
|
|
25
|
+
className: "placeholder:text-transparent focus:placeholder:text-gray-placeholder",
|
|
26
|
+
"data-focus-placeholder": ""
|
|
27
|
+
};
|
|
28
|
+
}
|
|
21
29
|
const InputDate = React$1.forwardRef(function InputDate({ calendarLabel, calendarProps, className, container, defaultOpen = false, defaultValue = "", disabled, id, onDateChange, onKeyDown, onOpenChange, onValueChange, open: openProp, pickerOnly = false, placeholder, separator = ".", value: valueProp, ...props }, ref) {
|
|
22
30
|
const inputRef = React$1.useRef(null);
|
|
31
|
+
const maskHint = useMaskHintOnFocus(placeholder);
|
|
23
32
|
const [text, setText] = useControllableState({
|
|
24
33
|
defaultProp: defaultValue,
|
|
25
34
|
onChange: onValueChange,
|
|
@@ -62,7 +71,8 @@ const InputDate = React$1.forwardRef(function InputDate({ calendarLabel, calenda
|
|
|
62
71
|
children: [/* @__PURE__ */ jsx(InputGroupInput, {
|
|
63
72
|
autoComplete: "off",
|
|
64
73
|
...props,
|
|
65
|
-
className: cn(pickerOnly && "cursor-pointer"),
|
|
74
|
+
className: cn(pickerOnly && "cursor-pointer", maskHint.className),
|
|
75
|
+
"data-focus-placeholder": maskHint["data-focus-placeholder"],
|
|
66
76
|
disabled,
|
|
67
77
|
id,
|
|
68
78
|
inputMode: pickerOnly ? void 0 : "numeric",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-date.js","names":["React"],"sources":["../../src/components/input-date.tsx"],"sourcesContent":["'use client'\n\nimport { CalendarMonth } from '@epilot/spark-icons'\nimport { apply, formatDate, isDateMaskKey, parseDate } from 'ictus'\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport { Button } from './button'\nimport { Calendar, type CalendarProps } from './calendar'\nimport { InputGroup, InputGroupAddon, InputGroupInput } from './input-group'\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from './popover'\n\nfunction useControllableState<T>({\n defaultProp,\n onChange,\n prop,\n}: {\n defaultProp: T\n onChange?: (value: T) => void\n prop?: T\n}) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultProp)\n const isControlled = prop !== undefined\n const value = isControlled ? prop : uncontrolled\n\n const setValue = React.useCallback(\n (next: T) => {\n if (!isControlled) setUncontrolled(next)\n onChange?.(next)\n },\n [isControlled, onChange],\n )\n\n return [value, setValue] as const\n}\n\nexport type InputDateProps = Omit<\n React.ComponentProps<'input'>,\n 'children' | 'defaultValue' | 'onChange' | 'readOnly' | 'type' | 'value'\n> & {\n calendarLabel: string\n calendarProps?: Omit<CalendarProps, 'mode' | 'onSelect' | 'selected'>\n /** Element the calendar popup mounts into, e.g. the drawer it sits in. */\n container?: React.ComponentProps<typeof PopoverContent>['container']\n defaultOpen?: boolean\n defaultValue?: string\n onDateChange?: (date: Date | undefined) => void\n onOpenChange?: (open: boolean) => void\n onValueChange?: (value: string) => void\n open?: boolean\n pickerOnly?: boolean\n separator?: string\n value?: string\n}\n\nconst InputDate = React.forwardRef<HTMLInputElement, InputDateProps>(\n function InputDate(\n {\n calendarLabel,\n calendarProps,\n className,\n container,\n defaultOpen = false,\n defaultValue = '',\n disabled,\n id,\n onDateChange,\n onKeyDown,\n onOpenChange,\n onValueChange,\n open: openProp,\n pickerOnly = false,\n placeholder,\n separator = '.',\n value: valueProp,\n ...props\n },\n ref,\n ) {\n const inputRef = React.useRef<HTMLInputElement>(null)\n const [text, setText] = useControllableState({\n defaultProp: defaultValue,\n onChange: onValueChange,\n prop: valueProp,\n })\n const [open, setOpenState] = useControllableState({\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n prop: openProp,\n })\n const selected = parseDate(text)\n const [month, setMonth] = React.useState<Date | undefined>(\n () => selected ?? calendarProps?.month,\n )\n const setOpen = React.useCallback(\n (next: boolean) => {\n if (next && calendarProps?.month === undefined) {\n setMonth(parseDate(text) ?? new Date())\n }\n setOpenState(next)\n },\n [calendarProps?.month, setOpenState, text],\n )\n\n const commit = React.useCallback(\n (next: string) => {\n if (next === text) return\n setText(next)\n onDateChange?.(parseDate(next))\n },\n [onDateChange, setText, text],\n )\n\n const setInputRef = React.useCallback(\n (node: HTMLInputElement | null) => {\n inputRef.current = node\n if (typeof ref === 'function') ref(node)\n else if (ref) ref.current = node\n },\n [ref],\n )\n\n return (\n <Popover onOpenChange={setOpen} open={open}>\n <PopoverAnchor render={<InputGroup className={className} />}>\n <InputGroupInput\n autoComplete=\"off\"\n {...props}\n className={cn(pickerOnly && 'cursor-pointer')}\n disabled={disabled}\n id={id}\n inputMode={pickerOnly ? undefined : 'numeric'}\n onChange={() => {}}\n onClick={\n pickerOnly && !disabled\n ? (event) => {\n props.onClick?.(event)\n if (!event.defaultPrevented) setOpen(true)\n }\n : props.onClick\n }\n onKeyDown={(event) => {\n onKeyDown?.(event)\n if (event.defaultPrevented) return\n if (event.key === 'ArrowDown') {\n event.preventDefault()\n setOpen(true)\n return\n }\n if (pickerOnly || !isDateMaskKey(event.key)) return\n event.preventDefault()\n const next = apply({\n caret: event.currentTarget.selectionStart ?? 0,\n key: event.key,\n selectionEnd: event.currentTarget.selectionEnd ?? undefined,\n separator,\n value: event.currentTarget.value,\n })\n commit(next.value)\n const caret = next.caret\n const input = inputRef.current\n requestAnimationFrame(() => {\n input?.setSelectionRange(caret, caret)\n })\n }}\n placeholder={placeholder ?? `DD${separator}MM${separator}YYYY`}\n readOnly={pickerOnly}\n ref={setInputRef}\n spellCheck={false}\n value={text}\n />\n <InputGroupAddon align=\"inline-end\">\n <PopoverTrigger\n render={\n <Button\n aria-label={calendarLabel}\n color=\"neutral\"\n disabled={disabled}\n size=\"icon-small\"\n styleVariant=\"ghost\"\n >\n <CalendarMonth />\n </Button>\n }\n />\n </InputGroupAddon>\n </PopoverAnchor>\n <PopoverContent\n align=\"start\"\n aria-label={calendarLabel}\n className=\"w-auto p-0\"\n collisionAvoidance={{ side: 'flip', fallbackAxisSide: 'none' }}\n container={container}\n >\n <Calendar\n {...calendarProps}\n mode=\"single\"\n month={calendarProps?.month ?? month}\n onMonthChange={(next) => {\n calendarProps?.onMonthChange?.(next)\n if (calendarProps?.month === undefined) setMonth(next)\n }}\n onSelect={(next) => {\n commit(next ? formatDate(next, separator) : '')\n setOpen(false)\n }}\n selected={selected}\n />\n </PopoverContent>\n </Popover>\n )\n },\n)\n\nexport { InputDate }\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAS,qBAAwB,EAC/B,aACA,UACA,QAKC;CACD,MAAM,CAAC,cAAc,mBAAmBA,QAAM,SAAS,WAAW;CAClE,MAAM,eAAe,SAAS,KAAA;CAW9B,OAAO,CAVO,eAAe,OAAO,cAEnBA,QAAM,aACpB,SAAY;EACX,IAAI,CAAC,cAAc,gBAAgB,IAAI;EACvC,WAAW,IAAI;CACjB,GACA,CAAC,cAAc,QAAQ,CAGH,CAAC;AACzB;AAqBA,MAAM,YAAYA,QAAM,WACtB,SAAS,UACP,EACE,eACA,eACA,WACA,WACA,cAAc,OACd,eAAe,IACf,UACA,IACA,cACA,WACA,cACA,eACA,MAAM,UACN,aAAa,OACb,aACA,YAAY,KACZ,OAAO,WACP,GAAG,SAEL,KACA;CACA,MAAM,WAAWA,QAAM,OAAyB,IA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AAa;MAC7B,MAAM,eAAe;MACrB,QAAQ,IAAI;MACZ;KACF;KACA,IAAI,cAAc,CAAC,cAAc,MAAM,GAAG,GAAG;KAC7C,MAAM,eAAe;KACrB,MAAM,OAAO,MAAM;MACjB,OAAO,MAAM,cAAc,kBAAkB;MAC7C,KAAK,MAAM;MACX,cAAc,MAAM,cAAc,gBAAgB,KAAA;MAClD;MACA,OAAO,MAAM,cAAc;KAC7B,CAAC;KACD,OAAO,KAAK,KAAK;KACjB,MAAM,QAAQ,KAAK;KACnB,MAAM,QAAQ,SAAS;KACvB,4BAA4B;MAC1B,OAAO,kBAAkB,OAAO,KAAK;KACvC,CAAC;IACH;IACA,aAAa,eAAe,KAAK,UAAU,IAAI,UAAU;IACzD,UAAU;IACV,KAAK;IACL,YAAY;IACZ,OAAO;GACR,CAAA,GACD,oBAAC,iBAAD;IAAiB,OAAM;cACrB,oBAAC,gBAAD,EACE,QACE,oBAAC,QAAD;KACE,cAAY;KACZ,OAAM;KACI;KACV,MAAK;KACL,cAAa;eAEb,oBAAC,eAAD,CAAgB,CAAA;IACV,CAAA,EAEX,CAAA;GACc,CAAA,CACJ;MACf,oBAAC,gBAAD;GACE,OAAM;GACN,cAAY;GACZ,WAAU;GACV,oBAAoB;IAAE,MAAM;IAAQ,kBAAkB;GAAO;GAClD;aAEX,oBAAC,UAAD;IACE,GAAI;IACJ,MAAK;IACL,OAAO,eAAe,SAAS;IAC/B,gBAAgB,SAAS;KACvB,eAAe,gBAAgB,IAAI;KACnC,IAAI,eAAe,UAAU,KAAA,GAAW,SAAS,IAAI;IACvD;IACA,WAAW,SAAS;KAClB,OAAO,OAAO,WAAW,MAAM,SAAS,IAAI,EAAE;KAC9C,QAAQ,KAAK;IACf;IACU;GACX,CAAA;EACa,CAAA,CACT;;AAEb,CACF"}
|
|
1
|
+
{"version":3,"file":"input-date.js","names":["React"],"sources":["../../src/components/input-date.tsx"],"sourcesContent":["'use client'\n\nimport { CalendarMonth } from '@epilot/spark-icons'\nimport { apply, formatDate, isDateMaskKey, parseDate } from 'ictus'\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport { Button } from './button'\nimport { Calendar, type CalendarProps } from './calendar'\nimport { useFieldContext } from './field'\nimport { InputGroup, InputGroupAddon, InputGroupInput } from './input-group'\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from './popover'\n\nfunction useControllableState<T>({\n defaultProp,\n onChange,\n prop,\n}: {\n defaultProp: T\n onChange?: (value: T) => void\n prop?: T\n}) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultProp)\n const isControlled = prop !== undefined\n const value = isControlled ? prop : uncontrolled\n\n const setValue = React.useCallback(\n (next: T) => {\n if (!isControlled) setUncontrolled(next)\n onChange?.(next)\n },\n [isControlled, onChange],\n )\n\n return [value, setValue] as const\n}\n\nfunction useMaskHintOnFocus(placeholder: string | undefined): {\n className?: string\n 'data-focus-placeholder'?: ''\n} {\n const floating = useFieldContext()?.labelPosition === 'floating'\n if (!floating || placeholder !== undefined) return {}\n return {\n className:\n 'placeholder:text-transparent focus:placeholder:text-gray-placeholder',\n 'data-focus-placeholder': '',\n }\n}\n\nexport type InputDateProps = Omit<\n React.ComponentProps<'input'>,\n 'children' | 'defaultValue' | 'onChange' | 'readOnly' | 'type' | 'value'\n> & {\n calendarLabel: string\n calendarProps?: Omit<CalendarProps, 'mode' | 'onSelect' | 'selected'>\n /** Element the calendar popup mounts into, e.g. the drawer it sits in. */\n container?: React.ComponentProps<typeof PopoverContent>['container']\n defaultOpen?: boolean\n defaultValue?: string\n onDateChange?: (date: Date | undefined) => void\n onOpenChange?: (open: boolean) => void\n onValueChange?: (value: string) => void\n open?: boolean\n pickerOnly?: boolean\n separator?: string\n value?: string\n}\n\nconst InputDate = React.forwardRef<HTMLInputElement, InputDateProps>(\n function InputDate(\n {\n calendarLabel,\n calendarProps,\n className,\n container,\n defaultOpen = false,\n defaultValue = '',\n disabled,\n id,\n onDateChange,\n onKeyDown,\n onOpenChange,\n onValueChange,\n open: openProp,\n pickerOnly = false,\n placeholder,\n separator = '.',\n value: valueProp,\n ...props\n },\n ref,\n ) {\n const inputRef = React.useRef<HTMLInputElement>(null)\n const maskHint = useMaskHintOnFocus(placeholder)\n const [text, setText] = useControllableState({\n defaultProp: defaultValue,\n onChange: onValueChange,\n prop: valueProp,\n })\n const [open, setOpenState] = useControllableState({\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n prop: openProp,\n })\n const selected = parseDate(text)\n const [month, setMonth] = React.useState<Date | undefined>(\n () => selected ?? calendarProps?.month,\n )\n const setOpen = React.useCallback(\n (next: boolean) => {\n if (next && calendarProps?.month === undefined) {\n setMonth(parseDate(text) ?? new Date())\n }\n setOpenState(next)\n },\n [calendarProps?.month, setOpenState, text],\n )\n\n const commit = React.useCallback(\n (next: string) => {\n if (next === text) return\n setText(next)\n onDateChange?.(parseDate(next))\n },\n [onDateChange, setText, text],\n )\n\n const setInputRef = React.useCallback(\n (node: HTMLInputElement | null) => {\n inputRef.current = node\n if (typeof ref === 'function') ref(node)\n else if (ref) ref.current = node\n },\n [ref],\n )\n\n return (\n <Popover onOpenChange={setOpen} open={open}>\n <PopoverAnchor render={<InputGroup className={className} />}>\n <InputGroupInput\n autoComplete=\"off\"\n {...props}\n className={cn(pickerOnly && 'cursor-pointer', maskHint.className)}\n data-focus-placeholder={maskHint['data-focus-placeholder']}\n disabled={disabled}\n id={id}\n inputMode={pickerOnly ? undefined : 'numeric'}\n onChange={() => {}}\n onClick={\n pickerOnly && !disabled\n ? (event) => {\n props.onClick?.(event)\n if (!event.defaultPrevented) setOpen(true)\n }\n : props.onClick\n }\n onKeyDown={(event) => {\n onKeyDown?.(event)\n if (event.defaultPrevented) return\n if (event.key === 'ArrowDown') {\n event.preventDefault()\n setOpen(true)\n return\n }\n if (pickerOnly || !isDateMaskKey(event.key)) return\n event.preventDefault()\n const next = apply({\n caret: event.currentTarget.selectionStart ?? 0,\n key: event.key,\n selectionEnd: event.currentTarget.selectionEnd ?? undefined,\n separator,\n value: event.currentTarget.value,\n })\n commit(next.value)\n const caret = next.caret\n const input = inputRef.current\n requestAnimationFrame(() => {\n input?.setSelectionRange(caret, caret)\n })\n }}\n placeholder={placeholder ?? `DD${separator}MM${separator}YYYY`}\n readOnly={pickerOnly}\n ref={setInputRef}\n spellCheck={false}\n value={text}\n />\n <InputGroupAddon align=\"inline-end\">\n <PopoverTrigger\n render={\n <Button\n aria-label={calendarLabel}\n color=\"neutral\"\n disabled={disabled}\n size=\"icon-small\"\n styleVariant=\"ghost\"\n >\n <CalendarMonth />\n </Button>\n }\n />\n </InputGroupAddon>\n </PopoverAnchor>\n <PopoverContent\n align=\"start\"\n aria-label={calendarLabel}\n className=\"w-auto p-0\"\n collisionAvoidance={{ side: 'flip', fallbackAxisSide: 'none' }}\n container={container}\n >\n <Calendar\n {...calendarProps}\n mode=\"single\"\n month={calendarProps?.month ?? month}\n onMonthChange={(next) => {\n calendarProps?.onMonthChange?.(next)\n if (calendarProps?.month === undefined) setMonth(next)\n }}\n onSelect={(next) => {\n commit(next ? formatDate(next, separator) : '')\n setOpen(false)\n }}\n selected={selected}\n />\n </PopoverContent>\n </Popover>\n )\n },\n)\n\nexport { InputDate }\n"],"mappings":";;;;;;;;;;;;;AAiBA,SAAS,qBAAwB,EAC/B,aACA,UACA,QAKC;CACD,MAAM,CAAC,cAAc,mBAAmBA,QAAM,SAAS,WAAW;CAClE,MAAM,eAAe,SAAS,KAAA;CAW9B,OAAO,CAVO,eAAe,OAAO,cAEnBA,QAAM,aACpB,SAAY;EACX,IAAI,CAAC,cAAc,gBAAgB,IAAI;EACvC,WAAW,IAAI;CACjB,GACA,CAAC,cAAc,QAAQ,CAGH,CAAC;AACzB;AAEA,SAAS,mBAAmB,aAG1B;CAEA,IAAI,EADa,gBAAgB,GAAG,kBAAkB,eACrC,gBAAgB,KAAA,GAAW,OAAO,CAAC;CACpD,OAAO;EACL,WACE;EACF,0BAA0B;CAC5B;AACF;AAqBA,MAA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AAW,SAAS,IAAI;IACvD;IACA,WAAW,SAAS;KAClB,OAAO,OAAO,WAAW,MAAM,SAAS,IAAI,EAAE;KAC9C,QAAQ,KAAK;IACf;IACU;GACX,CAAA;EACa,CAAA,CACT;;AAEb,CACF"}
|
|
@@ -87,6 +87,7 @@ const slotVariants = (0, class_variance_authority.cva)("flex w-11 min-w-0 items-
|
|
|
87
87
|
});
|
|
88
88
|
function InputOtp({ length = 6, className, id: idProp, onComplete, slotAriaLabel = (index) => `Character ${index + 1}`, validationType = "alphanumeric", ...props }) {
|
|
89
89
|
const { field, id, ariaDescribedBy, ariaInvalid, inputStyle, inputColor } = require_components_field.useFieldControl({ id: idProp });
|
|
90
|
+
require_components_field.useKeepLabelOutset();
|
|
90
91
|
const chrome = field?.labelPosition === "inset" ? "inset" : "box";
|
|
91
92
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_otp_field.OTPField.Root, {
|
|
92
93
|
"data-slot": "input-otp",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-otp.cjs","names":["INSET_UNDERLINE","boxChrome","useFieldControl","OTPField"],"sources":["../../src/components/input-otp.tsx"],"sourcesContent":["import { OTPField, type OTPFieldRootProps } from '@base-ui/react/otp-field'\nimport { cva } from 'class-variance-authority'\nimport { boxChrome, INSET_UNDERLINE } from '../lib/input-box-variants'\nimport { cn } from '../utils/cn'\nimport { useFieldControl } from './field'\n\n// One code box per slot. Mirrors Input's box/underline carrier model so the\n// slots read like the rest of the input family across every style/color knob.\nconst slotVariants = cva(\n 'flex w-11 min-w-0 items-center justify-center bg-transparent text-center text-base font-medium text-gray tabular-nums transition-[color,background-color,border-color] group-data-[invalid=true]/field:text-error placeholder:text-gray-placeholder disabled:cursor-not-allowed disabled:text-gray-disabled disabled:placeholder:text-gray-disabled aria-invalid:text-error motion-reduce:transition-none',\n {\n variants: {\n chrome: {\n // inside an inset field the shell is the box; slots keep the classic\n // underline (the pre-knob default look)\n inset: INSET_UNDERLINE,\n box: 'h-11 rounded-md',\n },\n inputStyle: { soft: '', surface: '', outlined: '', ghost: '' },\n inputColor: { brand: '', gray: '' },\n },\n compoundVariants: [\n {\n chrome: 'box',\n inputStyle: 'soft',\n inputColor: 'brand',\n class: boxChrome.soft.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'soft',\n inputColor: 'gray',\n class: boxChrome.soft.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'surface',\n inputColor: 'brand',\n class: boxChrome.surface.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'surface',\n inputColor: 'gray',\n class: boxChrome.surface.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'outlined',\n inputColor: 'brand',\n class: boxChrome.outlined.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'outlined',\n inputColor: 'gray',\n class: boxChrome.outlined.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'ghost',\n inputColor: 'brand',\n class: boxChrome.ghost.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'ghost',\n inputColor: 'gray',\n class: boxChrome.ghost.gray,\n },\n { chrome: 'inset', inputColor: 'brand', class: 'border-b-input' },\n { chrome: 'inset', inputColor: 'gray', class: 'border-b-input-gray' },\n ],\n },\n)\n\ninterface InputOtpProps extends Pick<\n OTPFieldRootProps,\n | 'value'\n | 'defaultValue'\n | 'onValueChange'\n | 'disabled'\n | 'className'\n | 'id'\n | 'validationType'\n> {\n /** Number of code slots. */\n length?: number\n /** Fired when every slot is filled. */\n onComplete?: OTPFieldRootProps['onValueComplete']\n /** Accessible name per slot (for localization). */\n slotAriaLabel?: (index: number) => string\n}\n\nfunction InputOtp({\n length = 6,\n className,\n id: idProp,\n onComplete,\n slotAriaLabel = (index) => `Character ${index + 1}`,\n validationType = 'alphanumeric',\n ...props\n}: InputOtpProps) {\n const { field, id, ariaDescribedBy, ariaInvalid, inputStyle, inputColor } =\n useFieldControl({ id: idProp })\n const chrome = field?.labelPosition === 'inset' ? 'inset' : 'box'\n\n return (\n <OTPField.Root\n data-slot=\"input-otp\"\n length={length}\n id={id}\n validationType={validationType}\n onValueComplete={onComplete}\n className={cn('flex items-center gap-2', className)}\n {...props}\n >\n {Array.from({ length }, (_, index) => (\n <OTPField.Input\n key={index}\n data-slot=\"input-otp-slot\"\n // the first slot is named by the Field label (Base UI ignores\n // aria-label there); the rest get a positional name for a11y\n aria-label={index === 0 ? undefined : slotAriaLabel(index)}\n aria-describedby={index === 0 ? ariaDescribedBy : undefined}\n aria-invalid={index === 0 ? ariaInvalid : undefined}\n className={slotVariants({ chrome, inputStyle, inputColor })}\n />\n ))}\n </OTPField.Root>\n )\n}\n\nexport { InputOtp }\nexport type { InputOtpProps }\n"],"mappings":";;;;;;;;;AAQA,MAAM,gBAAA,GAAA,yBAAA,KACJ,6YACA;CACE,UAAU;EACR,QAAQ;GAGN,OAAOA,+BAAAA;GACP,KAAK;EACP;EACA,YAAY;GAAE,MAAM;GAAI,SAAS;GAAI,UAAU;GAAI,OAAO;EAAG;EAC7D,YAAY;GAAE,OAAO;GAAI,MAAM;EAAG;CACpC;CACA,kBAAkB;EAChB;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOC,+BAAAA,UAAU,KAAK;EACxB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOA,+BAAAA,UAAU,KAAK;EACxB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOA,+BAAAA,UAAU,QAAQ;EAC3B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOA,+BAAAA,UAAU,QAAQ;EAC3B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOA,+BAAAA,UAAU,SAAS;EAC5B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOA,+BAAAA,UAAU,SAAS;EAC5B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOA,+BAAAA,UAAU,MAAM;EACzB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOA,+BAAAA,UAAU,MAAM;EACzB;EACA;GAAE,QAAQ;GAAS,YAAY;GAAS,OAAO;EAAiB;EAChE;GAAE,QAAQ;GAAS,YAAY;GAAQ,OAAO;EAAsB;CACtE;AACF,CACF;AAoBA,SAAS,SAAS,EAChB,SAAS,GACT,WACA,IAAI,QACJ,YACA,iBAAiB,UAAU,aAAa,QAAQ,KAChD,iBAAiB,gBACjB,GAAG,SACa;CAChB,MAAM,EAAE,OAAO,IAAI,iBAAiB,aAAa,YAAY,eAC3DC,yBAAAA,gBAAgB,EAAE,IAAI,OAAO,CAAC;CAChC,MAAM,SAAS,OAAO,kBAAkB,UAAU,UAAU;CAE5D,OACE,iBAAA,GAAA,kBAAA,KAACC,yBAAAA,SAAS,MAAV;EACE,aAAU;EACF;EACJ;EACY;EAChB,iBAAiB;EACjB,YAAA,GAAA,GAAA,IAAc,2BAA2B,SAAS;EAClD,GAAI;YAEH,MAAM,KAAK,EAAE,OAAO,IAAI,GAAG,UAC1B,iBAAA,GAAA,kBAAA,KAACA,yBAAAA,SAAS,OAAV;GAEE,aAAU;GAGV,cAAY,UAAU,IAAI,KAAA,IAAY,cAAc,KAAK;GACzD,oBAAkB,UAAU,IAAI,kBAAkB,KAAA;GAClD,gBAAc,UAAU,IAAI,cAAc,KAAA;GAC1C,WAAW,aAAa;IAAE;IAAQ;IAAY;GAAW,CAAC;EAC3D,GARM,KAQN,CACF;CACY,CAAA;AAEnB"}
|
|
1
|
+
{"version":3,"file":"input-otp.cjs","names":["INSET_UNDERLINE","boxChrome","useFieldControl","OTPField"],"sources":["../../src/components/input-otp.tsx"],"sourcesContent":["import { OTPField, type OTPFieldRootProps } from '@base-ui/react/otp-field'\nimport { cva } from 'class-variance-authority'\nimport { boxChrome, INSET_UNDERLINE } from '../lib/input-box-variants'\nimport { cn } from '../utils/cn'\nimport { useFieldControl, useKeepLabelOutset } from './field'\n\n// One code box per slot. Mirrors Input's box/underline carrier model so the\n// slots read like the rest of the input family across every style/color knob.\nconst slotVariants = cva(\n 'flex w-11 min-w-0 items-center justify-center bg-transparent text-center text-base font-medium text-gray tabular-nums transition-[color,background-color,border-color] group-data-[invalid=true]/field:text-error placeholder:text-gray-placeholder disabled:cursor-not-allowed disabled:text-gray-disabled disabled:placeholder:text-gray-disabled aria-invalid:text-error motion-reduce:transition-none',\n {\n variants: {\n chrome: {\n // inside an inset field the shell is the box; slots keep the classic\n // underline (the pre-knob default look)\n inset: INSET_UNDERLINE,\n box: 'h-11 rounded-md',\n },\n inputStyle: { soft: '', surface: '', outlined: '', ghost: '' },\n inputColor: { brand: '', gray: '' },\n },\n compoundVariants: [\n {\n chrome: 'box',\n inputStyle: 'soft',\n inputColor: 'brand',\n class: boxChrome.soft.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'soft',\n inputColor: 'gray',\n class: boxChrome.soft.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'surface',\n inputColor: 'brand',\n class: boxChrome.surface.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'surface',\n inputColor: 'gray',\n class: boxChrome.surface.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'outlined',\n inputColor: 'brand',\n class: boxChrome.outlined.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'outlined',\n inputColor: 'gray',\n class: boxChrome.outlined.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'ghost',\n inputColor: 'brand',\n class: boxChrome.ghost.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'ghost',\n inputColor: 'gray',\n class: boxChrome.ghost.gray,\n },\n { chrome: 'inset', inputColor: 'brand', class: 'border-b-input' },\n { chrome: 'inset', inputColor: 'gray', class: 'border-b-input-gray' },\n ],\n },\n)\n\ninterface InputOtpProps extends Pick<\n OTPFieldRootProps,\n | 'value'\n | 'defaultValue'\n | 'onValueChange'\n | 'disabled'\n | 'className'\n | 'id'\n | 'validationType'\n> {\n /** Number of code slots. */\n length?: number\n /** Fired when every slot is filled. */\n onComplete?: OTPFieldRootProps['onValueComplete']\n /** Accessible name per slot (for localization). */\n slotAriaLabel?: (index: number) => string\n}\n\nfunction InputOtp({\n length = 6,\n className,\n id: idProp,\n onComplete,\n slotAriaLabel = (index) => `Character ${index + 1}`,\n validationType = 'alphanumeric',\n ...props\n}: InputOtpProps) {\n const { field, id, ariaDescribedBy, ariaInvalid, inputStyle, inputColor } =\n useFieldControl({ id: idProp })\n useKeepLabelOutset()\n const chrome = field?.labelPosition === 'inset' ? 'inset' : 'box'\n\n return (\n <OTPField.Root\n data-slot=\"input-otp\"\n length={length}\n id={id}\n validationType={validationType}\n onValueComplete={onComplete}\n className={cn('flex items-center gap-2', className)}\n {...props}\n >\n {Array.from({ length }, (_, index) => (\n <OTPField.Input\n key={index}\n data-slot=\"input-otp-slot\"\n // the first slot is named by the Field label (Base UI ignores\n // aria-label there); the rest get a positional name for a11y\n aria-label={index === 0 ? undefined : slotAriaLabel(index)}\n aria-describedby={index === 0 ? ariaDescribedBy : undefined}\n aria-invalid={index === 0 ? ariaInvalid : undefined}\n className={slotVariants({ chrome, inputStyle, inputColor })}\n />\n ))}\n </OTPField.Root>\n )\n}\n\nexport { InputOtp }\nexport type { InputOtpProps }\n"],"mappings":";;;;;;;;;AAQA,MAAM,gBAAA,GAAA,yBAAA,KACJ,6YACA;CACE,UAAU;EACR,QAAQ;GAGN,OAAOA,+BAAAA;GACP,KAAK;EACP;EACA,YAAY;GAAE,MAAM;GAAI,SAAS;GAAI,UAAU;GAAI,OAAO;EAAG;EAC7D,YAAY;GAAE,OAAO;GAAI,MAAM;EAAG;CACpC;CACA,kBAAkB;EAChB;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOC,+BAAAA,UAAU,KAAK;EACxB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAOA,+BAAAA,UAAU,KAAK;EACxB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GAC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;GAC1C,WAAW,aAAa;IAAE;IAAQ;IAAY;GAAW,CAAC;EAC3D,GARM,KAQN,CACF;CACY,CAAA;AAEnB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../utils/cn.js";
|
|
3
3
|
import { INSET_UNDERLINE, boxChrome } from "../lib/input-box-variants.js";
|
|
4
|
-
import { useFieldControl } from "./field.js";
|
|
4
|
+
import { useFieldControl, useKeepLabelOutset } from "./field.js";
|
|
5
5
|
import { cva } from "class-variance-authority";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
import { OTPField } from "@base-ui/react/otp-field";
|
|
@@ -86,6 +86,7 @@ const slotVariants = cva("flex w-11 min-w-0 items-center justify-center bg-trans
|
|
|
86
86
|
});
|
|
87
87
|
function InputOtp({ length = 6, className, id: idProp, onComplete, slotAriaLabel = (index) => `Character ${index + 1}`, validationType = "alphanumeric", ...props }) {
|
|
88
88
|
const { field, id, ariaDescribedBy, ariaInvalid, inputStyle, inputColor } = useFieldControl({ id: idProp });
|
|
89
|
+
useKeepLabelOutset();
|
|
89
90
|
const chrome = field?.labelPosition === "inset" ? "inset" : "box";
|
|
90
91
|
return /* @__PURE__ */ jsx(OTPField.Root, {
|
|
91
92
|
"data-slot": "input-otp",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-otp.js","names":[],"sources":["../../src/components/input-otp.tsx"],"sourcesContent":["import { OTPField, type OTPFieldRootProps } from '@base-ui/react/otp-field'\nimport { cva } from 'class-variance-authority'\nimport { boxChrome, INSET_UNDERLINE } from '../lib/input-box-variants'\nimport { cn } from '../utils/cn'\nimport { useFieldControl } from './field'\n\n// One code box per slot. Mirrors Input's box/underline carrier model so the\n// slots read like the rest of the input family across every style/color knob.\nconst slotVariants = cva(\n 'flex w-11 min-w-0 items-center justify-center bg-transparent text-center text-base font-medium text-gray tabular-nums transition-[color,background-color,border-color] group-data-[invalid=true]/field:text-error placeholder:text-gray-placeholder disabled:cursor-not-allowed disabled:text-gray-disabled disabled:placeholder:text-gray-disabled aria-invalid:text-error motion-reduce:transition-none',\n {\n variants: {\n chrome: {\n // inside an inset field the shell is the box; slots keep the classic\n // underline (the pre-knob default look)\n inset: INSET_UNDERLINE,\n box: 'h-11 rounded-md',\n },\n inputStyle: { soft: '', surface: '', outlined: '', ghost: '' },\n inputColor: { brand: '', gray: '' },\n },\n compoundVariants: [\n {\n chrome: 'box',\n inputStyle: 'soft',\n inputColor: 'brand',\n class: boxChrome.soft.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'soft',\n inputColor: 'gray',\n class: boxChrome.soft.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'surface',\n inputColor: 'brand',\n class: boxChrome.surface.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'surface',\n inputColor: 'gray',\n class: boxChrome.surface.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'outlined',\n inputColor: 'brand',\n class: boxChrome.outlined.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'outlined',\n inputColor: 'gray',\n class: boxChrome.outlined.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'ghost',\n inputColor: 'brand',\n class: boxChrome.ghost.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'ghost',\n inputColor: 'gray',\n class: boxChrome.ghost.gray,\n },\n { chrome: 'inset', inputColor: 'brand', class: 'border-b-input' },\n { chrome: 'inset', inputColor: 'gray', class: 'border-b-input-gray' },\n ],\n },\n)\n\ninterface InputOtpProps extends Pick<\n OTPFieldRootProps,\n | 'value'\n | 'defaultValue'\n | 'onValueChange'\n | 'disabled'\n | 'className'\n | 'id'\n | 'validationType'\n> {\n /** Number of code slots. */\n length?: number\n /** Fired when every slot is filled. */\n onComplete?: OTPFieldRootProps['onValueComplete']\n /** Accessible name per slot (for localization). */\n slotAriaLabel?: (index: number) => string\n}\n\nfunction InputOtp({\n length = 6,\n className,\n id: idProp,\n onComplete,\n slotAriaLabel = (index) => `Character ${index + 1}`,\n validationType = 'alphanumeric',\n ...props\n}: InputOtpProps) {\n const { field, id, ariaDescribedBy, ariaInvalid, inputStyle, inputColor } =\n useFieldControl({ id: idProp })\n const chrome = field?.labelPosition === 'inset' ? 'inset' : 'box'\n\n return (\n <OTPField.Root\n data-slot=\"input-otp\"\n length={length}\n id={id}\n validationType={validationType}\n onValueComplete={onComplete}\n className={cn('flex items-center gap-2', className)}\n {...props}\n >\n {Array.from({ length }, (_, index) => (\n <OTPField.Input\n key={index}\n data-slot=\"input-otp-slot\"\n // the first slot is named by the Field label (Base UI ignores\n // aria-label there); the rest get a positional name for a11y\n aria-label={index === 0 ? undefined : slotAriaLabel(index)}\n aria-describedby={index === 0 ? ariaDescribedBy : undefined}\n aria-invalid={index === 0 ? ariaInvalid : undefined}\n className={slotVariants({ chrome, inputStyle, inputColor })}\n />\n ))}\n </OTPField.Root>\n )\n}\n\nexport { InputOtp }\nexport type { InputOtpProps }\n"],"mappings":";;;;;;;;AAQA,MAAM,eAAe,IACnB,6YACA;CACE,UAAU;EACR,QAAQ;GAGN,OAAO;GACP,KAAK;EACP;EACA,YAAY;GAAE,MAAM;GAAI,SAAS;GAAI,UAAU;GAAI,OAAO;EAAG;EAC7D,YAAY;GAAE,OAAO;GAAI,MAAM;EAAG;CACpC;CACA,kBAAkB;EAChB;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,KAAK;EACxB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,KAAK;EACxB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,QAAQ;EAC3B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,QAAQ;EAC3B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,SAAS;EAC5B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,SAAS;EAC5B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,MAAM;EACzB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,MAAM;EACzB;EACA;GAAE,QAAQ;GAAS,YAAY;GAAS,OAAO;EAAiB;EAChE;GAAE,QAAQ;GAAS,YAAY;GAAQ,OAAO;EAAsB;CACtE;AACF,CACF;AAoBA,SAAS,SAAS,EAChB,SAAS,GACT,WACA,IAAI,QACJ,YACA,iBAAiB,UAAU,aAAa,QAAQ,KAChD,iBAAiB,gBACjB,GAAG,SACa;CAChB,MAAM,EAAE,OAAO,IAAI,iBAAiB,aAAa,YAAY,eAC3D,gBAAgB,EAAE,IAAI,OAAO,CAAC;CAChC,MAAM,SAAS,OAAO,kBAAkB,UAAU,UAAU;CAE5D,OACE,oBAAC,SAAS,MAAV;EACE,aAAU;EACF;EACJ;EACY;EAChB,iBAAiB;EACjB,WAAW,GAAG,2BAA2B,SAAS;EAClD,GAAI;YAEH,MAAM,KAAK,EAAE,OAAO,IAAI,GAAG,UAC1B,oBAAC,SAAS,OAAV;GAEE,aAAU;GAGV,cAAY,UAAU,IAAI,KAAA,IAAY,cAAc,KAAK;GACzD,oBAAkB,UAAU,IAAI,kBAAkB,KAAA;GAClD,gBAAc,UAAU,IAAI,cAAc,KAAA;GAC1C,WAAW,aAAa;IAAE;IAAQ;IAAY;GAAW,CAAC;EAC3D,GARM,KAQN,CACF;CACY,CAAA;AAEnB"}
|
|
1
|
+
{"version":3,"file":"input-otp.js","names":[],"sources":["../../src/components/input-otp.tsx"],"sourcesContent":["import { OTPField, type OTPFieldRootProps } from '@base-ui/react/otp-field'\nimport { cva } from 'class-variance-authority'\nimport { boxChrome, INSET_UNDERLINE } from '../lib/input-box-variants'\nimport { cn } from '../utils/cn'\nimport { useFieldControl, useKeepLabelOutset } from './field'\n\n// One code box per slot. Mirrors Input's box/underline carrier model so the\n// slots read like the rest of the input family across every style/color knob.\nconst slotVariants = cva(\n 'flex w-11 min-w-0 items-center justify-center bg-transparent text-center text-base font-medium text-gray tabular-nums transition-[color,background-color,border-color] group-data-[invalid=true]/field:text-error placeholder:text-gray-placeholder disabled:cursor-not-allowed disabled:text-gray-disabled disabled:placeholder:text-gray-disabled aria-invalid:text-error motion-reduce:transition-none',\n {\n variants: {\n chrome: {\n // inside an inset field the shell is the box; slots keep the classic\n // underline (the pre-knob default look)\n inset: INSET_UNDERLINE,\n box: 'h-11 rounded-md',\n },\n inputStyle: { soft: '', surface: '', outlined: '', ghost: '' },\n inputColor: { brand: '', gray: '' },\n },\n compoundVariants: [\n {\n chrome: 'box',\n inputStyle: 'soft',\n inputColor: 'brand',\n class: boxChrome.soft.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'soft',\n inputColor: 'gray',\n class: boxChrome.soft.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'surface',\n inputColor: 'brand',\n class: boxChrome.surface.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'surface',\n inputColor: 'gray',\n class: boxChrome.surface.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'outlined',\n inputColor: 'brand',\n class: boxChrome.outlined.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'outlined',\n inputColor: 'gray',\n class: boxChrome.outlined.gray,\n },\n {\n chrome: 'box',\n inputStyle: 'ghost',\n inputColor: 'brand',\n class: boxChrome.ghost.brand,\n },\n {\n chrome: 'box',\n inputStyle: 'ghost',\n inputColor: 'gray',\n class: boxChrome.ghost.gray,\n },\n { chrome: 'inset', inputColor: 'brand', class: 'border-b-input' },\n { chrome: 'inset', inputColor: 'gray', class: 'border-b-input-gray' },\n ],\n },\n)\n\ninterface InputOtpProps extends Pick<\n OTPFieldRootProps,\n | 'value'\n | 'defaultValue'\n | 'onValueChange'\n | 'disabled'\n | 'className'\n | 'id'\n | 'validationType'\n> {\n /** Number of code slots. */\n length?: number\n /** Fired when every slot is filled. */\n onComplete?: OTPFieldRootProps['onValueComplete']\n /** Accessible name per slot (for localization). */\n slotAriaLabel?: (index: number) => string\n}\n\nfunction InputOtp({\n length = 6,\n className,\n id: idProp,\n onComplete,\n slotAriaLabel = (index) => `Character ${index + 1}`,\n validationType = 'alphanumeric',\n ...props\n}: InputOtpProps) {\n const { field, id, ariaDescribedBy, ariaInvalid, inputStyle, inputColor } =\n useFieldControl({ id: idProp })\n useKeepLabelOutset()\n const chrome = field?.labelPosition === 'inset' ? 'inset' : 'box'\n\n return (\n <OTPField.Root\n data-slot=\"input-otp\"\n length={length}\n id={id}\n validationType={validationType}\n onValueComplete={onComplete}\n className={cn('flex items-center gap-2', className)}\n {...props}\n >\n {Array.from({ length }, (_, index) => (\n <OTPField.Input\n key={index}\n data-slot=\"input-otp-slot\"\n // the first slot is named by the Field label (Base UI ignores\n // aria-label there); the rest get a positional name for a11y\n aria-label={index === 0 ? undefined : slotAriaLabel(index)}\n aria-describedby={index === 0 ? ariaDescribedBy : undefined}\n aria-invalid={index === 0 ? ariaInvalid : undefined}\n className={slotVariants({ chrome, inputStyle, inputColor })}\n />\n ))}\n </OTPField.Root>\n )\n}\n\nexport { InputOtp }\nexport type { InputOtpProps }\n"],"mappings":";;;;;;;;AAQA,MAAM,eAAe,IACnB,6YACA;CACE,UAAU;EACR,QAAQ;GAGN,OAAO;GACP,KAAK;EACP;EACA,YAAY;GAAE,MAAM;GAAI,SAAS;GAAI,UAAU;GAAI,OAAO;EAAG;EAC7D,YAAY;GAAE,OAAO;GAAI,MAAM;EAAG;CACpC;CACA,kBAAkB;EAChB;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,KAAK;EACxB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,KAAK;EACxB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,QAAQ;EAC3B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,QAAQ;EAC3B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,SAAS;EAC5B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,SAAS;EAC5B;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,MAAM;EACzB;EACA;GACE,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,OAAO,UAAU,MAAM;EACzB;EACA;GAAE,QAAQ;GAAS,YAAY;GAAS,OAAO;EAAiB;EAChE;GAAE,QAAQ;GAAS,YAAY;GAAQ,OAAO;EAAsB;CACtE;AACF,CACF;AAoBA,SAAS,SAAS,EAChB,SAAS,GACT,WACA,IAAI,QACJ,YACA,iBAAiB,UAAU,aAAa,QAAQ,KAChD,iBAAiB,gBACjB,GAAG,SACa;CAChB,MAAM,EAAE,OAAO,IAAI,iBAAiB,aAAa,YAAY,eAC3D,gBAAgB,EAAE,IAAI,OAAO,CAAC;CAChC,mBAAmB;CACnB,MAAM,SAAS,OAAO,kBAAkB,UAAU,UAAU;CAE5D,OACE,oBAAC,SAAS,MAAV;EACE,aAAU;EACF;EACJ;EACY;EAChB,iBAAiB;EACjB,WAAW,GAAG,2BAA2B,SAAS;EAClD,GAAI;YAEH,MAAM,KAAK,EAAE,OAAO,IAAI,GAAG,UAC1B,oBAAC,SAAS,OAAV;GAEE,aAAU;GAGV,cAAY,UAAU,IAAI,KAAA,IAAY,cAAc,KAAK;GACzD,oBAAkB,UAAU,IAAI,kBAAkB,KAAA;GAClD,gBAAc,UAAU,IAAI,cAAc,KAAA;GAC1C,WAAW,aAAa;IAAE;IAAQ;IAAY;GAAW,CAAC;EAC3D,GARM,KAQN,CACF;CACY,CAAA;AAEnB"}
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/marker.d.ts
|
|
8
8
|
declare const markerVariants: (props?: ({
|
|
9
|
-
variant?: "default" | "
|
|
9
|
+
variant?: "default" | "separator" | "border" | null | undefined;
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
declare function Marker({
|
|
12
12
|
className,
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/marker.d.ts
|
|
8
8
|
declare const markerVariants: (props?: ({
|
|
9
|
-
variant?: "default" | "
|
|
9
|
+
variant?: "default" | "separator" | "border" | null | undefined;
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
declare function Marker({
|
|
12
12
|
className,
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/page-header.d.ts
|
|
8
8
|
declare const PageHeader: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLElement> & React$1.RefAttributes<HTMLElement>>;
|
|
9
|
-
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "
|
|
9
|
+
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "styleVariant" | "color" | "size"> & React$1.RefAttributes<HTMLButtonElement>>;
|
|
10
10
|
declare const PageHeaderTitle: ({
|
|
11
11
|
className,
|
|
12
12
|
...props
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/page-header.d.ts
|
|
8
8
|
declare const PageHeader: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLElement> & React$1.RefAttributes<HTMLElement>>;
|
|
9
|
-
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "
|
|
9
|
+
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "styleVariant" | "color" | "size"> & React$1.RefAttributes<HTMLButtonElement>>;
|
|
10
10
|
declare const PageHeaderTitle: ({
|
|
11
11
|
className,
|
|
12
12
|
...props
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
4
|
const require_chunk = require("../chunk-DY84GLCh.cjs");
|
|
5
|
+
const require_hooks_use_focus_modality = require("../hooks/use-focus-modality.cjs");
|
|
5
6
|
const require_lib_theme_types = require("../lib/theme-types.cjs");
|
|
6
7
|
const require_lib_accent_theme = require("../lib/accent-theme.cjs");
|
|
7
8
|
let react = require("react");
|
|
@@ -107,6 +108,7 @@ function useTheme() {
|
|
|
107
108
|
}
|
|
108
109
|
/** Optional sugar: writes the theming `data-*` attrs + accent `--spark-*` vars onto a wrapper. */
|
|
109
110
|
const Theme = react.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) {
|
|
111
|
+
require_hooks_use_focus_modality.useFocusModality();
|
|
110
112
|
const parent = useTheme();
|
|
111
113
|
const buttons = useButtonRoles(buttonsProp);
|
|
112
114
|
const parentOutput = react.useContext(ThemeOutputContext);
|
|
@@ -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;CAA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AQA,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
|
+
{"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 { 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,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,QA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AA,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"}
|
package/dist/components/theme.js
CHANGED
|
@@ -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;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,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,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,YAAY,KAAA;CAC1B,MAA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