@adea-ai/ui 0.156.0 → 0.158.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/components/composites/appearance-editor/appearance-editor.d.ts +1 -1
- package/dist/components/composites/appearance-editor/appearance-editor.d.ts.map +1 -1
- package/dist/components/composites/appearance-editor/appearance-editor.js +305 -172
- package/dist/components/composites/appearance-editor/appearance-editor.js.map +1 -1
- package/dist/components/composites/appearance-editor/appearance-rows.d.ts +6 -0
- package/dist/components/composites/appearance-editor/appearance-rows.d.ts.map +1 -1
- package/dist/components/composites/appearance-editor/appearance-rows.js +2 -2
- package/dist/components/composites/appearance-editor/appearance-rows.js.map +1 -1
- package/dist/components/composites/appearance-editor/appearance-types.d.ts +26 -0
- package/dist/components/composites/appearance-editor/appearance-types.d.ts.map +1 -1
- package/dist/components/composites/appearance-editor/appearance-types.js +10 -0
- package/dist/components/composites/appearance-editor/appearance-types.js.map +1 -0
- package/dist/components/composites/appearance-editor/font-settings-group.d.ts +13 -1
- package/dist/components/composites/appearance-editor/font-settings-group.d.ts.map +1 -1
- package/dist/components/composites/appearance-editor/font-settings-group.js +51 -15
- package/dist/components/composites/appearance-editor/font-settings-group.js.map +1 -1
- package/dist/components/composites/appearance-editor/index.d.ts +2 -1
- package/dist/components/composites/appearance-editor/index.d.ts.map +1 -1
- package/dist/components/composites/appearance-editor/index.js +3 -2
- package/dist/components/theme/theme-document.d.ts +1 -1
- package/dist/components/theme/theme-document.js.map +1 -1
- package/dist/components/theme/theme-provider-value.d.ts +1 -1
- package/dist/components/theme/theme-provider-value.js.map +1 -1
- package/dist/components/ui/button/button.d.ts.map +1 -1
- package/dist/components/ui/button/button.js +3 -3
- package/dist/components/ui/button/button.js.map +1 -1
- package/dist/components/ui/tooltip/tooltip.d.ts.map +1 -1
- package/dist/components/ui/tooltip/tooltip.js +4 -18
- package/dist/components/ui/tooltip/tooltip.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/lib/appearance-font-settings.d.ts +18 -4
- package/dist/lib/appearance-font-settings.d.ts.map +1 -1
- package/dist/lib/appearance-font-settings.js +24 -6
- package/dist/lib/appearance-font-settings.js.map +1 -1
- package/dist/lib/fast-icon.d.ts +2 -1
- package/dist/lib/fast-icon.d.ts.map +1 -1
- package/dist/lib/fast-icon.js +4 -3
- package/dist/lib/fast-icon.js.map +1 -1
- package/dist/lib/font-catalog.d.ts +5 -0
- package/dist/lib/font-catalog.d.ts.map +1 -1
- package/dist/lib/font-catalog.js +10 -5
- package/dist/lib/font-catalog.js.map +1 -1
- package/dist/lib/font-zoom.d.ts +1 -1
- package/dist/lib/font-zoom.d.ts.map +1 -1
- package/dist/lib/font-zoom.js +5 -1
- package/dist/lib/font-zoom.js.map +1 -1
- package/dist/lib/theme-defaults.generated.d.ts.map +1 -1
- package/dist/lib/theme-defaults.generated.js +88 -60
- package/dist/lib/theme-defaults.generated.js.map +1 -1
- package/dist/lib/theme-projection.d.ts +2 -0
- package/dist/lib/theme-projection.d.ts.map +1 -1
- package/dist/lib/theme-projection.js +2 -2
- package/dist/lib/theme-projection.js.map +1 -1
- package/dist/lib/theme-types.d.ts +7 -0
- package/dist/lib/theme-types.d.ts.map +1 -1
- package/dist/lib/theme-types.js +7 -0
- package/dist/lib/theme-types.js.map +1 -1
- package/dist/lib/tokens.d.ts.map +1 -1
- package/dist/lib/tokens.js +17 -2
- package/dist/lib/tokens.js.map +1 -1
- package/dist/r/appearance-editor.json +2 -1
- package/dist/r/lib.json +1 -1
- package/dist/r/registry.json +4 -3
- package/dist/r/src/components/composites/appearance-editor/appearance-editor.tsx +202 -110
- package/dist/r/src/components/composites/appearance-editor/appearance-rows.tsx +11 -1
- package/dist/r/src/components/composites/appearance-editor/appearance-types.ts +27 -0
- package/dist/r/src/components/composites/appearance-editor/font-settings-group.tsx +50 -10
- package/dist/r/src/components/composites/appearance-editor/index.ts +3 -0
- package/dist/r/src/components/theme/theme-document.ts +1 -1
- package/dist/r/src/components/theme/theme-provider-value.ts +1 -1
- package/dist/r/src/components/ui/button/button.tsx +12 -3
- package/dist/r/src/components/ui/tooltip/tooltip.tsx +9 -18
- package/dist/r/src/lib/appearance-font-settings.ts +43 -7
- package/dist/r/src/lib/fast-icon.ts +11 -4
- package/dist/r/src/lib/font-catalog.ts +5 -0
- package/dist/r/src/lib/font-zoom.ts +3 -0
- package/dist/r/src/lib/theme-defaults.generated.ts +88 -60
- package/dist/r/src/lib/theme-projection.ts +2 -0
- package/dist/r/src/lib/theme-types.ts +7 -0
- package/dist/r/src/lib/tokens.ts +17 -2
- package/dist/r/src/styles/appearance-font-settings.css +2 -0
- package/dist/r/src/styles/theme-variants.css +608 -370
- package/dist/r/src/styles/theme.css +4 -4
- package/dist/r/theming.json +1 -1
- package/package.json +2 -2
- package/registry.json +4 -3
- package/src/components/composites/appearance-editor/appearance-editor.tsx +202 -110
- package/src/components/composites/appearance-editor/appearance-rows.tsx +11 -1
- package/src/components/composites/appearance-editor/appearance-types.ts +27 -0
- package/src/components/composites/appearance-editor/font-settings-group.tsx +50 -10
- package/src/components/composites/appearance-editor/index.ts +3 -0
- package/src/components/theme/theme-document.ts +1 -1
- package/src/components/theme/theme-provider-value.ts +1 -1
- package/src/components/ui/button/button.tsx +12 -3
- package/src/components/ui/tooltip/tooltip.tsx +9 -18
- package/src/lib/appearance-font-settings.ts +43 -7
- package/src/lib/fast-icon.ts +11 -4
- package/src/lib/font-catalog.ts +5 -0
- package/src/lib/font-zoom.ts +3 -0
- package/src/lib/theme-defaults.generated.ts +88 -60
- package/src/lib/theme-projection.ts +2 -0
- package/src/lib/theme-types.ts +7 -0
- package/src/lib/tokens.ts +17 -2
- package/src/styles/appearance-font-settings.css +2 -0
- package/src/styles/theme-variants.css +608 -370
- package/src/styles/theme.css +4 -4
- package/src/styles/themes/aardvark-blue.css +7 -0
- package/src/styles/themes/aardvark-ink.css +7 -0
- package/src/styles/themes/adea-dark-colorblind.css +22 -15
- package/src/styles/themes/adea-dark-high-contrast.css +22 -15
- package/src/styles/themes/adea-dark.css +22 -15
- package/src/styles/themes/adea-light-colorblind.css +21 -14
- package/src/styles/themes/adea-light-high-contrast.css +21 -14
- package/src/styles/themes/adea-light.css +22 -15
- package/src/styles/themes/ayu-light.css +20 -13
- package/src/styles/themes/ayu-mirage.css +21 -14
- package/src/styles/themes/ayu.css +22 -15
- package/src/styles/themes/catppuccin-frappe.css +16 -9
- package/src/styles/themes/catppuccin-latte.css +15 -8
- package/src/styles/themes/catppuccin-macchiato.css +16 -9
- package/src/styles/themes/catppuccin-mocha.css +16 -9
- package/src/styles/themes/dracula.css +16 -9
- package/src/styles/themes/everforest-dark.css +19 -12
- package/src/styles/themes/everforest-light.css +21 -14
- package/src/styles/themes/gruvbox-dark.css +21 -14
- package/src/styles/themes/gruvbox-light.css +20 -13
- package/src/styles/themes/kanagawa.css +18 -11
- package/src/styles/themes/monokai.css +19 -12
- package/src/styles/themes/nord-light.css +7 -0
- package/src/styles/themes/nord.css +19 -12
- package/src/styles/themes/one-dark.css +16 -9
- package/src/styles/themes/rosepine-dawn.css +19 -12
- package/src/styles/themes/rosepine-moon.css +20 -13
- package/src/styles/themes/rosepine.css +20 -13
- package/src/styles/themes/solarized-dark.css +19 -12
- package/src/styles/themes/solarized-light.css +19 -12
- package/src/styles/themes/tokyonight-day.css +7 -0
- package/src/styles/themes/tokyonight-night.css +18 -11
- package/src/styles/themes/tokyonight-storm.css +18 -11
- package/src/styles/themes/vesper.css +22 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font-settings-group.js","names":["BookOpen","LucideBookOpen","ChevronDown","LucideChevronDown","Code2","LucideCode2","PanelsTopLeft","LucidePanelsTopLeft","For","createMemo","createSignal","createUniqueId","DEFAULT_FONT_ID","fontOptions","Button","DropdownMenu","DropdownMenuContent","DropdownMenuRadioGroup","DropdownMenuRadioItem","DropdownMenuSeparator","DropdownMenuTrigger","tabStopAt","InputControl","normalizeAppearanceEditorFontSettings","normalizeAppearanceEditorFontSize","fastIcon","settings","menuPortalMount","HTMLElement","onChange","disabled","FONT_ROWS","axis","label","description","icon","catalogFontOptions","filter","option","id","FontFamilyMenu","props","family","onSelect","menuOpen","setMenuOpen","restoreTriggerFocus","setRestoreTriggerFocus","triggerElement","setTriggerElement","selectedLabel","find","_$createComponent","modal","open","onOpenChange","children","ref","as","variant","size","_el$","_tmpl$","_$insert","hideArrow","portalMount","onFocusOutside","event","defaultPrevented","detail","originalEvent","target","preventDefault","contains","onInteractOutside","type","owner","Element","tabKey","onEscapeKeyDown","onCloseAutoFocus","trigger","isConnected","closest","getClientRects","length","focus","preventScroll","value","closeOnSelect","candidate","each","AppearanceFontSettingsGroup","sizeDrafts","setSizeDrafts","sizeHintPrefix","updateAxis","patch","current","commitSize","input","undefined","next","_el$2","_tmpl$2","row","Icon","inputValue","String","sizeHintId","sizeIsInvalid","draft","trim","parsed","Number","isFinite","isInteger","_el$3","_tmpl$3","_el$4","firstChild","_el$5","nextSibling","_el$6","_el$7","_el$8","_el$9","_el$0","_el$1","_el$14","_el$15","min","max","step","onInput","currentTarget","onBlur","onKeyDown","key","_$setAttribute","_$effect"],"sources":["../../../../src/components/composites/appearance-editor/font-settings-group.tsx"],"sourcesContent":["import {\n BookOpen as LucideBookOpen,\n ChevronDown as LucideChevronDown,\n Code2 as LucideCode2,\n PanelsTopLeft as LucidePanelsTopLeft,\n} from 'lucide-solid'\nimport { For, createMemo, createSignal, createUniqueId } from 'solid-js'\nimport { DEFAULT_FONT_ID, fontOptions } from '#lib/font-catalog'\nimport { Button } from '../../ui/button'\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuRadioGroup,\n DropdownMenuRadioItem,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n tabStopAt,\n} from '../../ui/dropdown-menu/dropdown-menu'\nimport { InputControl } from '../../ui/input'\nimport {\n APPEARANCE_EDITOR_FONT_SIZE_MAX,\n APPEARANCE_EDITOR_FONT_SIZE_MIN,\n normalizeAppearanceEditorFontSettings,\n normalizeAppearanceEditorFontSize,\n type AppearanceEditorFontAxis,\n type AppearanceEditorFontFamilyId,\n type AppearanceEditorFontSettings,\n} from '#lib/appearance-font-settings'\nimport { fastIcon } from '#lib/fast-icon'\n\n// lucide icons drawn from a cloned template (see fastIcon).\nconst BookOpen = fastIcon(LucideBookOpen)\nconst ChevronDown = fastIcon(LucideChevronDown)\nconst Code2 = fastIcon(LucideCode2)\nconst PanelsTopLeft = fastIcon(LucidePanelsTopLeft)\n\nexport type AppearanceFontSettingsGroupProps = {\n settings: AppearanceEditorFontSettings\n menuPortalMount?: HTMLElement\n onChange: (settings: AppearanceEditorFontSettings) => void\n disabled?: boolean\n}\n\nconst FONT_ROWS = [\n {\n axis: 'ui',\n label: 'UI',\n description: 'Controls and interface labels.',\n icon: PanelsTopLeft,\n },\n {\n axis: 'content',\n label: 'Content',\n description: 'Reading and long-form text.',\n icon: BookOpen,\n },\n {\n axis: 'code',\n label: 'Code',\n description: 'Code, terminals, and file paths.',\n icon: Code2,\n },\n] as const satisfies readonly {\n axis: AppearanceEditorFontAxis\n label: string\n description: string\n icon: typeof PanelsTopLeft\n}[]\n\nconst catalogFontOptions = fontOptions.filter((option) => option.id !== DEFAULT_FONT_ID)\n\nfunction FontFamilyMenu(props: {\n label: string\n family: AppearanceEditorFontFamilyId\n menuPortalMount?: HTMLElement\n disabled?: boolean\n onSelect: (family: AppearanceEditorFontFamilyId) => void\n}) {\n const [menuOpen, setMenuOpen] = createSignal(false)\n const [restoreTriggerFocus, setRestoreTriggerFocus] = createSignal(false)\n const [triggerElement, setTriggerElement] = createSignal<HTMLButtonElement>()\n\n const selectedLabel = () =>\n fontOptions.find((option) => option.id === props.family)?.label ??\n fontOptions.find((option) => option.id === DEFAULT_FONT_ID)?.label ??\n 'System'\n\n return (\n <DropdownMenu\n modal={false}\n open={menuOpen()}\n onOpenChange={(open) => {\n setMenuOpen(open)\n if (open) setRestoreTriggerFocus(false)\n }}\n >\n <DropdownMenuTrigger\n ref={setTriggerElement}\n as={Button}\n variant=\"outline\"\n size=\"sm\"\n aria-label={`${props.label} font family: ${selectedLabel()}`}\n disabled={props.disabled}\n class=\"w-32 max-w-full justify-between\"\n >\n <span class=\"truncate\">{selectedLabel()}</span>\n <ChevronDown aria-hidden=\"true\" class=\"ms-2 size-4 shrink-0 text-muted-foreground\" />\n </DropdownMenuTrigger>\n <DropdownMenuContent\n hideArrow\n portalMount={props.menuPortalMount}\n class=\"min-w-48\"\n onFocusOutside={(event) => {\n // WebKit may briefly focus the owning Popover root while the menu's\n // focus scope starts. Keep the menu open for that transient target;\n // genuine focus moves to another control still dismiss it.\n if (\n !event.defaultPrevented &&\n props.menuPortalMount &&\n event.detail.originalEvent.target === props.menuPortalMount\n ) {\n setRestoreTriggerFocus(true)\n event.preventDefault()\n } else if (\n event.detail.originalEvent.target instanceof HTMLElement &&\n props.menuPortalMount?.contains(event.detail.originalEvent.target)\n ) {\n setRestoreTriggerFocus(false)\n }\n }}\n onInteractOutside={(event) => {\n if (event.detail.originalEvent.type !== 'pointerdown') return\n const owner = props.menuPortalMount\n const target = event.detail.originalEvent.target\n if (!(target instanceof Element) || !owner?.contains(target)) return\n\n setRestoreTriggerFocus(!tabStopAt(target))\n }}\n tabKey=\"leave\"\n onEscapeKeyDown={() => setRestoreTriggerFocus(true)}\n onCloseAutoFocus={(event) => {\n if (menuOpen()) {\n event.preventDefault()\n return\n }\n if (!restoreTriggerFocus()) return\n\n event.preventDefault()\n setRestoreTriggerFocus(false)\n const trigger = triggerElement()\n if (\n trigger?.isConnected &&\n !trigger.disabled &&\n trigger.closest('[hidden], [inert], [aria-hidden=\"true\"]') === null &&\n trigger.getClientRects().length > 0\n ) {\n trigger.focus({ preventScroll: true })\n }\n }}\n >\n <DropdownMenuRadioGroup\n value={props.family}\n aria-label={`${props.label} system font`}\n onChange={(family) => {\n if (family === DEFAULT_FONT_ID) props.onSelect(DEFAULT_FONT_ID)\n }}\n >\n <DropdownMenuRadioItem value={DEFAULT_FONT_ID} closeOnSelect>\n System\n </DropdownMenuRadioItem>\n </DropdownMenuRadioGroup>\n <DropdownMenuSeparator />\n <DropdownMenuRadioGroup\n value={props.family}\n aria-label={`${props.label} available fonts`}\n onChange={(family) => {\n const option = fontOptions.find((candidate) => candidate.id === family)\n if (option && option.id !== DEFAULT_FONT_ID) props.onSelect(option.id)\n }}\n >\n <For each={catalogFontOptions}>\n {(option) => (\n <DropdownMenuRadioItem value={option.id} closeOnSelect>\n {option.label}\n </DropdownMenuRadioItem>\n )}\n </For>\n </DropdownMenuRadioGroup>\n </DropdownMenuContent>\n </DropdownMenu>\n )\n}\n\n/** Controlled font controls shared by AppearanceEditor and host-owned settings. */\nexport function AppearanceFontSettingsGroup(props: AppearanceFontSettingsGroupProps) {\n const [sizeDrafts, setSizeDrafts] = createSignal<\n Partial<Record<AppearanceEditorFontAxis, string>>\n >({})\n const sizeHintPrefix = createUniqueId()\n const settings = createMemo(() => normalizeAppearanceEditorFontSettings(props.settings).settings)\n\n const updateAxis = (\n axis: AppearanceEditorFontAxis,\n patch: { family?: AppearanceEditorFontFamilyId; size?: number }\n ) => {\n const current = settings()\n props.onChange({\n ...current,\n [axis]: {\n ...current[axis],\n ...patch,\n },\n })\n }\n\n const commitSize = (axis: AppearanceEditorFontAxis) => {\n const input = sizeDrafts()[axis]\n if (input === undefined) return\n const size = normalizeAppearanceEditorFontSize(input, settings()[axis].size)\n setSizeDrafts((current) => {\n const next = { ...current }\n delete next[axis]\n return next\n })\n if (size !== settings()[axis].size) updateAxis(axis, { size })\n }\n\n return (\n <div class=\"global-appearance-font-settings\">\n <For each={FONT_ROWS}>\n {(row) => {\n const Icon = row.icon\n const value = () => settings()[row.axis]\n const inputValue = () => sizeDrafts()[row.axis] ?? String(value().size)\n const sizeHintId = `${sizeHintPrefix}-${row.axis}-font-size-help`\n const sizeIsInvalid = () => {\n const draft = sizeDrafts()[row.axis]\n if (draft === undefined || draft.trim() === '') return false\n const parsed = Number(draft)\n return (\n !Number.isFinite(parsed) ||\n !Number.isInteger(parsed) ||\n parsed < APPEARANCE_EDITOR_FONT_SIZE_MIN ||\n parsed > APPEARANCE_EDITOR_FONT_SIZE_MAX\n )\n }\n return (\n <section class=\"flex items-center gap-3 px-4 py-4\" data-font-settings-row={row.axis}>\n <span\n class=\"flex size-9 shrink-0 items-center justify-center rounded-lg border bg-foreground/5 text-muted-foreground [&_svg]:size-4\"\n aria-hidden=\"true\"\n >\n <Icon />\n </span>\n {/* One line, always: the copy truncates rather than wrapping the\n controls to a second line, so the family menu, the size field\n and the title/subtitle stay aligned. The compact widths keep\n that true at the appearance sheet's own width. */}\n <div class=\"min-w-0 flex-1\">\n <h3 class=\"text-sm font-medium\">{row.label}</h3>\n <div class=\"mt-0.5 truncate text-xs text-muted-foreground\">{row.description}</div>\n </div>\n <div class=\"flex shrink-0 items-center gap-2\">\n <FontFamilyMenu\n label={row.label}\n family={value().family}\n menuPortalMount={props.menuPortalMount}\n disabled={props.disabled}\n onSelect={(family) => updateAxis(row.axis, { family })}\n />\n <div class=\"flex items-center gap-1\">\n <InputControl\n type=\"number\"\n min={APPEARANCE_EDITOR_FONT_SIZE_MIN}\n max={APPEARANCE_EDITOR_FONT_SIZE_MAX}\n step={1}\n value={inputValue()}\n disabled={props.disabled}\n aria-label={`${row.label} font size in pixels`}\n aria-describedby={sizeHintId}\n aria-invalid={sizeIsInvalid()}\n class=\"w-12\"\n onInput={(event) =>\n setSizeDrafts((current) => ({\n ...current,\n [row.axis]: event.currentTarget.value,\n }))\n }\n onBlur={() => commitSize(row.axis)}\n onKeyDown={(event) => {\n if (event.key !== 'Enter') return\n event.preventDefault()\n commitSize(row.axis)\n }}\n />\n <span aria-hidden=\"true\" class=\"text-xs text-muted-foreground\">\n px\n </span>\n </div>\n <span id={sizeHintId} class=\"sr-only\">\n Enter a whole number from {APPEARANCE_EDITOR_FONT_SIZE_MIN} to{' '}\n {APPEARANCE_EDITOR_FONT_SIZE_MAX} pixels.\n </span>\n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pB,IAAIA,MAAMuE,QAAQ,SAAS;OAC3BvE,MAAMK,eAAe;OACrB2B,WAAWM,IAAIzE,IAAI;MACrB;KAAC,CAAA,GAAA+F,KAAA;KAAAY,aAAAX,OAAA,MAMKnB,UAAU;KAAA9C,OAAAiE,OAAAA,IACwCC,MAAA;KAAAlE,OAAAiE,OAAAA,IAC1BE,MAAA;KAAAU,aAAAD,aAAAtB,OAAA,0BAtDqCZ,IAAIzE,IAAI,CAAA;KAAA,OAAAqF;IAAA,EAAA,CAAA;GA2DvF;EAAC,CAAA,CAAA;EAAA,OAAAd;CAAA,EAAA,CAAA;AAIT"}
|
|
1
|
+
{"version":3,"file":"font-settings-group.js","names":["BookOpen","LucideBookOpen","ChevronDown","LucideChevronDown","Code2","LucideCode2","PanelsTopLeft","LucidePanelsTopLeft","SquareTerminal","LucideSquareTerminal","For","Show","createMemo","createSignal","createUniqueId","DEFAULT_FONT_ID","fontOptions","Button","DropdownMenu","DropdownMenuContent","DropdownMenuRadioGroup","DropdownMenuRadioItem","DropdownMenuSeparator","DropdownMenuTrigger","tabStopAt","InputControl","normalizeAppearanceEditorFontSettings","normalizeAppearanceEditorFontSize","resolveAppearanceEditorFontSettings","fastIcon","settings","menuPortalMount","HTMLElement","onChange","disabled","axes","sectioned","DEFAULT_FONT_ROW_AXES","FONT_ROWS","axis","label","description","icon","catalogFontOptions","filter","option","id","FontFamilyMenu","props","family","onSelect","menuOpen","setMenuOpen","restoreTriggerFocus","setRestoreTriggerFocus","triggerElement","setTriggerElement","selectedLabel","find","selectedFamilyVariable","familyVariables","_$createComponent","modal","open","onOpenChange","children","ref","as","variant","size","_el$","_tmpl$","_$insert","_$effect","_$p","_$setStyleProperty","hideArrow","portalMount","onFocusOutside","event","defaultPrevented","detail","originalEvent","target","preventDefault","contains","onInteractOutside","type","owner","Element","tabKey","onEscapeKeyDown","onCloseAutoFocus","trigger","isConnected","closest","getClientRects","length","focus","preventScroll","value","closeOnSelect","candidate","each","AppearanceFontSettingsGroup","sizeDrafts","setSizeDrafts","sizeHintPrefix","resolved","rows","row","includes","updateAxis","patch","current","commitSize","input","undefined","next","_el$2","_tmpl$2","Icon","inputValue","String","sizeHintId","sizeIsInvalid","draft","trim","parsed","Number","isFinite","isInteger","_el$3","_tmpl$4","_el$4","firstChild","_el$5","nextSibling","_el$6","_el$8","_el$9","_el$0","_el$1","_el$14","_el$15","_c$","_$memo","when","_el$7","_tmpl$3","min","max","step","onInput","currentTarget","onBlur","onKeyDown","key","_$setAttribute"],"sources":["../../../../src/components/composites/appearance-editor/font-settings-group.tsx"],"sourcesContent":["import {\n BookOpen as LucideBookOpen,\n ChevronDown as LucideChevronDown,\n Code2 as LucideCode2,\n PanelsTopLeft as LucidePanelsTopLeft,\n SquareTerminal as LucideSquareTerminal,\n} from 'lucide-solid'\nimport { For, Show, createMemo, createSignal, createUniqueId } from 'solid-js'\nimport { DEFAULT_FONT_ID, fontOptions } from '#lib/font-catalog'\nimport { Button } from '../../ui/button'\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuRadioGroup,\n DropdownMenuRadioItem,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n tabStopAt,\n} from '../../ui/dropdown-menu/dropdown-menu'\nimport { InputControl } from '../../ui/input'\nimport {\n APPEARANCE_EDITOR_FONT_SIZE_MAX,\n APPEARANCE_EDITOR_FONT_SIZE_MIN,\n normalizeAppearanceEditorFontSettings,\n normalizeAppearanceEditorFontSize,\n resolveAppearanceEditorFontSettings,\n type AppearanceEditorFontAxis,\n type AppearanceEditorFontFamilyId,\n type AppearanceEditorFontSettings,\n} from '#lib/appearance-font-settings'\nimport { fastIcon } from '#lib/fast-icon'\n\n// lucide icons drawn from a cloned template (see fastIcon).\nconst BookOpen = fastIcon(LucideBookOpen)\nconst ChevronDown = fastIcon(LucideChevronDown)\nconst Code2 = fastIcon(LucideCode2)\nconst PanelsTopLeft = fastIcon(LucidePanelsTopLeft)\nconst SquareTerminal = fastIcon(LucideSquareTerminal)\n\nexport type AppearanceFontSettingsGroupProps = {\n settings: AppearanceEditorFontSettings\n menuPortalMount?: HTMLElement\n onChange: (settings: AppearanceEditorFontSettings) => void\n disabled?: boolean\n /**\n * The axes to draw, in the catalogue's order. The default is UI, Content and\n * Code: with no terminal row the terminal keeps following Code. A host that\n * lists `terminal` lets it be set apart; until it is, the row shows Code's value.\n */\n axes?: readonly AppearanceEditorFontAxis[]\n /**\n * The rows sit under a tab that already names their subject: each is titled\n * \"Font\" and carries no description. Controls keep the axis in their\n * accessible names.\n */\n sectioned?: boolean\n}\n\nconst DEFAULT_FONT_ROW_AXES: readonly AppearanceEditorFontAxis[] = ['ui', 'content', 'code']\n\nconst FONT_ROWS = [\n {\n axis: 'ui',\n label: 'UI',\n description: 'Controls and interface labels.',\n icon: PanelsTopLeft,\n },\n {\n axis: 'content',\n label: 'Content',\n description: 'Reading and long-form text.',\n icon: BookOpen,\n },\n {\n axis: 'code',\n label: 'Code',\n description: 'Code, diffs, and file paths.',\n icon: Code2,\n },\n {\n axis: 'terminal',\n label: 'Terminal',\n description: 'Terminals and agent CLIs.',\n icon: SquareTerminal,\n },\n] as const satisfies readonly {\n axis: AppearanceEditorFontAxis\n label: string\n description: string\n icon: typeof PanelsTopLeft\n}[]\n\nconst catalogFontOptions = fontOptions.filter((option) => option.id !== DEFAULT_FONT_ID)\n\nfunction FontFamilyMenu(props: {\n label: string\n axis: AppearanceEditorFontAxis\n family: AppearanceEditorFontFamilyId\n menuPortalMount?: HTMLElement\n disabled?: boolean\n onSelect: (family: AppearanceEditorFontFamilyId) => void\n}) {\n const [menuOpen, setMenuOpen] = createSignal(false)\n const [restoreTriggerFocus, setRestoreTriggerFocus] = createSignal(false)\n const [triggerElement, setTriggerElement] = createSignal<HTMLButtonElement>()\n\n const selectedLabel = () =>\n fontOptions.find((option) => option.id === props.family)?.label ??\n fontOptions.find((option) => option.id === DEFAULT_FONT_ID)?.label ??\n 'System'\n\n const selectedFamilyVariable = () =>\n (\n fontOptions.find((option) => option.id === props.family) ??\n fontOptions.find((option) => option.id === DEFAULT_FONT_ID)\n )?.familyVariables[props.axis] ?? '--font-family-system'\n\n return (\n <DropdownMenu\n modal={false}\n open={menuOpen()}\n onOpenChange={(open) => {\n setMenuOpen(open)\n if (open) setRestoreTriggerFocus(false)\n }}\n >\n <DropdownMenuTrigger\n ref={setTriggerElement}\n as={Button}\n variant=\"outline\"\n size=\"sm\"\n aria-label={`${props.label} font family: ${selectedLabel()}`}\n disabled={props.disabled}\n class=\"w-32 max-w-full justify-between\"\n >\n {/* The choice is drawn in its own face: a preview, and the face is fetched as soon as\n it is picked even when nothing else on screen uses this axis yet. */}\n <span class=\"truncate\" style={{ 'font-family': `var(${selectedFamilyVariable()})` }}>\n {selectedLabel()}\n </span>\n <ChevronDown aria-hidden=\"true\" class=\"ms-2 size-4 shrink-0 text-muted-foreground\" />\n </DropdownMenuTrigger>\n <DropdownMenuContent\n hideArrow\n portalMount={props.menuPortalMount}\n class=\"min-w-48\"\n onFocusOutside={(event) => {\n // WebKit may briefly focus the owning Popover root while the menu's\n // focus scope starts. Keep the menu open for that transient target;\n // genuine focus moves to another control still dismiss it.\n if (\n !event.defaultPrevented &&\n props.menuPortalMount &&\n event.detail.originalEvent.target === props.menuPortalMount\n ) {\n setRestoreTriggerFocus(true)\n event.preventDefault()\n } else if (\n event.detail.originalEvent.target instanceof HTMLElement &&\n props.menuPortalMount?.contains(event.detail.originalEvent.target)\n ) {\n setRestoreTriggerFocus(false)\n }\n }}\n onInteractOutside={(event) => {\n if (event.detail.originalEvent.type !== 'pointerdown') return\n const owner = props.menuPortalMount\n const target = event.detail.originalEvent.target\n if (!(target instanceof Element) || !owner?.contains(target)) return\n\n setRestoreTriggerFocus(!tabStopAt(target))\n }}\n tabKey=\"leave\"\n onEscapeKeyDown={() => setRestoreTriggerFocus(true)}\n onCloseAutoFocus={(event) => {\n if (menuOpen()) {\n event.preventDefault()\n return\n }\n if (!restoreTriggerFocus()) return\n\n event.preventDefault()\n setRestoreTriggerFocus(false)\n const trigger = triggerElement()\n if (\n trigger?.isConnected &&\n !trigger.disabled &&\n trigger.closest('[hidden], [inert], [aria-hidden=\"true\"]') === null &&\n trigger.getClientRects().length > 0\n ) {\n trigger.focus({ preventScroll: true })\n }\n }}\n >\n <DropdownMenuRadioGroup\n value={props.family}\n aria-label={`${props.label} system font`}\n onChange={(family) => {\n if (family === DEFAULT_FONT_ID) props.onSelect(DEFAULT_FONT_ID)\n }}\n >\n <DropdownMenuRadioItem value={DEFAULT_FONT_ID} closeOnSelect>\n System\n </DropdownMenuRadioItem>\n </DropdownMenuRadioGroup>\n <DropdownMenuSeparator />\n <DropdownMenuRadioGroup\n value={props.family}\n aria-label={`${props.label} available fonts`}\n onChange={(family) => {\n const option = fontOptions.find((candidate) => candidate.id === family)\n if (option && option.id !== DEFAULT_FONT_ID) props.onSelect(option.id)\n }}\n >\n <For each={catalogFontOptions}>\n {(option) => (\n <DropdownMenuRadioItem value={option.id} closeOnSelect>\n {option.label}\n </DropdownMenuRadioItem>\n )}\n </For>\n </DropdownMenuRadioGroup>\n </DropdownMenuContent>\n </DropdownMenu>\n )\n}\n\n/** Controlled font controls shared by AppearanceEditor and host-owned settings. */\nexport function AppearanceFontSettingsGroup(props: AppearanceFontSettingsGroupProps) {\n const [sizeDrafts, setSizeDrafts] = createSignal<\n Partial<Record<AppearanceEditorFontAxis, string>>\n >({})\n const sizeHintPrefix = createUniqueId()\n const settings = createMemo(() => normalizeAppearanceEditorFontSettings(props.settings).settings)\n const resolved = createMemo(() => resolveAppearanceEditorFontSettings(settings()))\n const axes = () => props.axes ?? DEFAULT_FONT_ROW_AXES\n const rows = createMemo(() => FONT_ROWS.filter((row) => axes().includes(row.axis)))\n\n const updateAxis = (\n axis: AppearanceEditorFontAxis,\n patch: { family?: AppearanceEditorFontFamilyId; size?: number }\n ) => {\n const current = settings()\n props.onChange({\n ...current,\n [axis]: {\n ...resolved()[axis],\n ...patch,\n },\n })\n }\n\n const commitSize = (axis: AppearanceEditorFontAxis) => {\n const input = sizeDrafts()[axis]\n if (input === undefined) return\n const size = normalizeAppearanceEditorFontSize(input, resolved()[axis].size)\n setSizeDrafts((current) => {\n const next = { ...current }\n delete next[axis]\n return next\n })\n if (size !== resolved()[axis].size) updateAxis(axis, { size })\n }\n\n return (\n <div class=\"global-appearance-font-settings\">\n <For each={rows()}>\n {(row) => {\n const Icon = row.icon\n const value = () => resolved()[row.axis]\n const inputValue = () => sizeDrafts()[row.axis] ?? String(value().size)\n const sizeHintId = `${sizeHintPrefix}-${row.axis}-font-size-help`\n const sizeIsInvalid = () => {\n const draft = sizeDrafts()[row.axis]\n if (draft === undefined || draft.trim() === '') return false\n const parsed = Number(draft)\n return (\n !Number.isFinite(parsed) ||\n !Number.isInteger(parsed) ||\n parsed < APPEARANCE_EDITOR_FONT_SIZE_MIN ||\n parsed > APPEARANCE_EDITOR_FONT_SIZE_MAX\n )\n }\n return (\n <section class=\"flex items-center gap-3 px-4 py-4\" data-font-settings-row={row.axis}>\n <span\n class=\"flex size-9 shrink-0 items-center justify-center rounded-lg border bg-foreground/5 text-muted-foreground [&_svg]:size-4\"\n aria-hidden=\"true\"\n >\n <Icon />\n </span>\n {/* One line, always: the copy truncates rather than wrapping the\n controls to a second line, so the family menu, the size field\n and the title/subtitle stay aligned. The compact widths keep\n that true at the appearance sheet's own width. */}\n <div class=\"min-w-0 flex-1\">\n <h3 class=\"text-sm font-medium\">{props.sectioned ? 'Font' : row.label}</h3>\n <Show when={!props.sectioned}>\n <div class=\"mt-0.5 truncate text-xs text-muted-foreground\">{row.description}</div>\n </Show>\n </div>\n <div class=\"flex shrink-0 items-center gap-2\">\n <FontFamilyMenu\n label={row.label}\n axis={row.axis}\n family={value().family}\n menuPortalMount={props.menuPortalMount}\n disabled={props.disabled}\n onSelect={(family) => updateAxis(row.axis, { family })}\n />\n <div class=\"flex items-center gap-1\">\n <InputControl\n type=\"number\"\n min={APPEARANCE_EDITOR_FONT_SIZE_MIN}\n max={APPEARANCE_EDITOR_FONT_SIZE_MAX}\n step={1}\n value={inputValue()}\n disabled={props.disabled}\n aria-label={`${row.label} font size in pixels`}\n aria-describedby={sizeHintId}\n aria-invalid={sizeIsInvalid()}\n class=\"w-12\"\n onInput={(event) =>\n setSizeDrafts((current) => ({\n ...current,\n [row.axis]: event.currentTarget.value,\n }))\n }\n onBlur={() => commitSize(row.axis)}\n onKeyDown={(event) => {\n if (event.key !== 'Enter') return\n event.preventDefault()\n commitSize(row.axis)\n }}\n />\n <span aria-hidden=\"true\" class=\"text-xs text-muted-foreground\">\n px\n </span>\n </div>\n <span id={sizeHintId} class=\"sr-only\">\n Enter a whole number from {APPEARANCE_EDITOR_FONT_SIZE_MIN} to{' '}\n {APPEARANCE_EDITOR_FONT_SIZE_MAX} pixels.\n </span>\n </div>\n </section>\n )\n }}\n </For>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAiCA,IAAMA,aAAW6B,SAAS5B,QAAc;AACxC,IAAMC,gBAAc2B,SAAS1B,WAAiB;AAC9C,IAAMC,UAAQyB,SAASxB,KAAW;AAClC,IAAMC,kBAAgBuB,SAAStB,aAAmB;AAClD,IAAMC,mBAAiBqB,SAASpB,cAAoB;AAqBpD,IAAM4B,wBAA6D;CAAC;CAAM;CAAW;AAAM;AAE3F,IAAMC,YAAY;CAChB;EACEC,MAAM;EACNC,OAAO;EACPC,aAAa;EACbC,MAAMpC;CACR;CACA;EACEiC,MAAM;EACNC,OAAO;EACPC,aAAa;EACbC,MAAM1C;CACR;CACA;EACEuC,MAAM;EACNC,OAAO;EACPC,aAAa;EACbC,MAAMtC;CACR;CACA;EACEmC,MAAM;EACNC,OAAO;EACPC,aAAa;EACbC,MAAMlC;CACR;AAAC;AAQH,IAAMmC,qBAAqB3B,YAAY4B,QAAQC,WAAWA,OAAOC,OAAO/B,eAAe;AAEvF,SAASgC,eAAeC,OAOrB;CACD,MAAM,CAACG,UAAUC,eAAevC,aAAa,KAAK;CAClD,MAAM,CAACwC,qBA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AItE,MAAK;MAAsB;MAAA,oBAC5BoF;MAAU,KAAA,kBAAA;OAAA,OACdC,cAAc;MAAC;MAAA,SAAA;MAE7B4B,UAAU1E,UACR2B,eAAeQ,aAAa;OAC1B,GAAGA;QACFJ,IAAIvE,OAAOwC,MAAM2E,cAActD;MAClC,EAAE;MAEJuD,cAAcxC,WAAWL,IAAIvE,IAAI;MACjCqH,YAAY7E,UAAU;OACpB,IAAIA,MAAM8E,QAAQ,SAAS;OAC3B9E,MAAMK,eAAe;OACrB+B,WAAWL,IAAIvE,IAAI;MACrB;KAAC,CAAA,GAAAsG,KAAA;KAAAiB,aAAAhB,OAAA,MAMKlB,UAAU;KAAApD,OAAAsE,OAAAA,IACwCC,MAAA;KAAAvE,OAAAsE,OAAAA,IAC1BE,MAAA;KAAAvE,aAAAqF,aAAA1B,OAAA,0BAzDqCtB,IAAIvE,IAAI,CAAA;KAAA,OAAA6F;IAAA,EAAA,CAAA;GA8DvF;EAAC,CAAA,CAAA;EAAA,OAAAb;CAAA,EAAA,CAAA;AAIT"}
|
|
@@ -2,7 +2,8 @@ export { SettingsRow as AppearanceSettingsRow } from './appearance-rows';
|
|
|
2
2
|
export { AccentSwatchGroups, type AccentSwatchGroupsProps } from './accent-swatch-groups';
|
|
3
3
|
export { AppearanceEditor, AppearanceEditorActions, AppearancePopover } from './appearance-editor';
|
|
4
4
|
export { AppearanceFontSettingsGroup, type AppearanceFontSettingsGroupProps, } from './font-settings-group';
|
|
5
|
-
export { APPEARANCE_EDITOR_FONT_AXES, APPEARANCE_EDITOR_FONT_SIZE_MAX, APPEARANCE_EDITOR_FONT_SIZE_MIN, DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS, applyAppearanceFontSettings, fontSettingsBootstrapScript, normalizeAppearanceEditorFontSettings, normalizeAppearanceEditorFontSize, type AppearanceEditorFontAxis, type AppearanceEditorFontFamilyId, type AppearanceEditorFontSetting, type AppearanceEditorFontSettings, type NormalizedAppearanceEditorFontSettings, } from '#lib/appearance-font-settings';
|
|
5
|
+
export { APPEARANCE_EDITOR_FONT_AXES, APPEARANCE_EDITOR_FONT_SIZE_MAX, APPEARANCE_EDITOR_FONT_SIZE_MIN, DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS, applyAppearanceFontSettings, fontSettingsBootstrapScript, normalizeAppearanceEditorFontSettings, normalizeAppearanceEditorFontSize, resolveAppearanceEditorFontSettings, type AppearanceEditorFontAxis, type AppearanceEditorFontFamilyId, type AppearanceEditorFontSetting, type AppearanceEditorFontSettings, type NormalizedAppearanceEditorFontSettings, type ResolvedAppearanceEditorFontSettings, } from '#lib/appearance-font-settings';
|
|
6
|
+
export { APPEARANCE_EDITOR_TABS, type AppearanceEditorTab } from './appearance-types';
|
|
6
7
|
export type { AppearanceDraft, AppearanceEditorProps, AppearancePopoverProps, } from './appearance-types';
|
|
7
8
|
export { ThemeMiniature, ThemeMiniatureSplit, PalettePreview, type ThemeMiniatureProps, } from './theme-preview';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/appearance-editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AACzF,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAClG,OAAO,EACL,2BAA2B,EAC3B,KAAK,gCAAgC,GACtC,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,EAC/B,uCAAuC,EACvC,2BAA2B,EAC3B,2BAA2B,EAC3B,qCAAqC,EACrC,iCAAiC,EACjC,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,sCAAsC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/appearance-editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AACzF,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAClG,OAAO,EACL,2BAA2B,EAC3B,KAAK,gCAAgC,GACtC,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,EAC/B,uCAAuC,EACvC,2BAA2B,EAC3B,2BAA2B,EAC3B,qCAAqC,EACrC,iCAAiC,EACjC,mCAAmC,EACnC,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,sCAAsC,EAC3C,KAAK,oCAAoC,GAC1C,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,sBAAsB,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACrF,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,KAAK,mBAAmB,GACzB,MAAM,iBAAiB,CAAA"}
|
|
@@ -2,6 +2,7 @@ import { SettingsRow } from "./appearance-rows.js";
|
|
|
2
2
|
import { AccentSwatchGroups } from "./accent-swatch-groups.js";
|
|
3
3
|
import { AppearanceEditor, AppearanceEditorActions, AppearancePopover } from "./appearance-editor.js";
|
|
4
4
|
import { AppearanceFontSettingsGroup } from "./font-settings-group.js";
|
|
5
|
-
import { APPEARANCE_EDITOR_FONT_AXES, APPEARANCE_EDITOR_FONT_SIZE_MAX, APPEARANCE_EDITOR_FONT_SIZE_MIN, DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS, applyAppearanceFontSettings, fontSettingsBootstrapScript, normalizeAppearanceEditorFontSettings, normalizeAppearanceEditorFontSize } from "../../../lib/appearance-font-settings.js";
|
|
5
|
+
import { APPEARANCE_EDITOR_FONT_AXES, APPEARANCE_EDITOR_FONT_SIZE_MAX, APPEARANCE_EDITOR_FONT_SIZE_MIN, DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS, applyAppearanceFontSettings, fontSettingsBootstrapScript, normalizeAppearanceEditorFontSettings, normalizeAppearanceEditorFontSize, resolveAppearanceEditorFontSettings } from "../../../lib/appearance-font-settings.js";
|
|
6
|
+
import { APPEARANCE_EDITOR_TABS } from "./appearance-types.js";
|
|
6
7
|
import { PalettePreview, ThemeMiniature, ThemeMiniatureSplit } from "./theme-preview.js";
|
|
7
|
-
export { APPEARANCE_EDITOR_FONT_AXES, APPEARANCE_EDITOR_FONT_SIZE_MAX, APPEARANCE_EDITOR_FONT_SIZE_MIN, AccentSwatchGroups, AppearanceEditor, AppearanceEditorActions, AppearanceFontSettingsGroup, AppearancePopover, SettingsRow as AppearanceSettingsRow, DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS, PalettePreview, ThemeMiniature, ThemeMiniatureSplit, applyAppearanceFontSettings, fontSettingsBootstrapScript, normalizeAppearanceEditorFontSettings, normalizeAppearanceEditorFontSize };
|
|
8
|
+
export { APPEARANCE_EDITOR_FONT_AXES, APPEARANCE_EDITOR_FONT_SIZE_MAX, APPEARANCE_EDITOR_FONT_SIZE_MIN, APPEARANCE_EDITOR_TABS, AccentSwatchGroups, AppearanceEditor, AppearanceEditorActions, AppearanceFontSettingsGroup, AppearancePopover, SettingsRow as AppearanceSettingsRow, DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS, PalettePreview, ThemeMiniature, ThemeMiniatureSplit, applyAppearanceFontSettings, fontSettingsBootstrapScript, normalizeAppearanceEditorFontSettings, normalizeAppearanceEditorFontSize, resolveAppearanceEditorFontSettings };
|
|
@@ -65,7 +65,7 @@ export type ThemeDocumentOptions = {
|
|
|
65
65
|
*
|
|
66
66
|
* With `palette: 'stylesheet'`, `floor` is the one palette write a catalogue
|
|
67
67
|
* variant still gets: the stylesheet is generated for the default projection, so
|
|
68
|
-
* the
|
|
68
|
+
* the `--editor-*` properties are written inline over it. The rest of the
|
|
69
69
|
* palette stays in the stylesheet.
|
|
70
70
|
*/
|
|
71
71
|
editorRoles?: EditorRolesMode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-document.js","names":[],"sources":["../../../src/components/theme/theme-document.ts"],"sourcesContent":["import {\n applyAppearanceFontSettings,\n normalizeAppearanceEditorFontSettings,\n} from '#lib/appearance-font-settings'\nimport { terminalCssVariables } from '#lib/theme-css'\nimport type { ThemeTokenProjectionOptions } from './token-projection'\nimport { assertThemeTokenProjectionConfig } from './token-projection-options'\nimport type { ThemeEngine } from '#lib/theme-engine'\nimport type { EditorRolesMode, ThemeAppearance, ThemeVariant } from '#lib/theme-types'\nimport { isCustomAccent } from '#lib/accent-roles'\nimport { surfaceAlpha, type SurfaceState } from '#lib/theme-surface'\nimport { resolvedDensity, type ThemeSelection } from './theme-state'\n\n/**\n * The document half of the theme provider: the single writer of `<html>`.\n *\n * Written against the few members of an element it uses, so the rules can be tested\n * on a stand-in. Every question the catalogue answers goes through the\n * {@link ThemeEngine} it is given, so it imports no catalogue code or data.\n */\nexport type ThemeRoot = Pick<\n HTMLElement,\n 'classList' | 'dataset' | 'style' | 'removeAttribute' | 'setAttribute'\n>\n\nexport type ThemeDocumentState = {\n /** What the document shows: the committed selection, or a preview laid over it. */\n selection: ThemeSelection\n appearance: ThemeAppearance\n variant: ThemeVariant\n /**\n * The variant whose terminal palette is pinned over the interface variant's.\n * Absent, the terminal follows the interface theme.\n */\n terminalVariant?: ThemeVariant\n /**\n * The variant whose syntax palette, and the canvas it was measured on, is pinned\n * over the interface variant's `--editor-*` ramp. Absent, code follows the\n * interface theme and no `--editor-background` family is written.\n */\n codeVariant?: ThemeVariant\n /**\n * The resolved surface axis. Absent, the axis is off: no attribute and no\n * `--surface-alpha` is written, and any this writer wrote before is removed.\n */\n surface?: SurfaceState\n}\n\nexport type ThemeDocumentOptions = {\n /**\n * Rewrites the custom properties just before they are written: the variant's\n * roles with the accent laid over them. It sees every property of the pass and\n * must return the full map; a name it drops is not written.\n */\n transformTokens?: (tokens: Record<string, string>) => Record<string, string>\n /**\n * The contrast an accent is held to against the variant's background. Absent, a\n * preset is painted verbatim (the catalogue measured it for its own themes) and\n * only a custom `#rrggbb` is held to the default floor of 3:1.\n */\n accentContrastFloor?: number\n /**\n * Where a catalogue variant's palette comes from. `inline` (the default) writes\n * every role onto the root. `stylesheet` writes none for a catalogue variant,\n * because the host loads a stylesheet that carries a `[data-theme]` block for it;\n * a variant the catalogue does not hold (a host's imported theme) is still written\n * inline, since no stylesheet can know it. The accent, the terminal pin, the\n * surface alpha and the fonts are written the same in both.\n *\n * Switching from an imported variant back to a catalogue one removes what the\n * imported one wrote, so nothing inline outlives it to beat the stylesheet.\n */\n palette?: 'inline' | 'stylesheet'\n /**\n * The `--editor-*` projection. `syntax` (the default) is the catalogue's quiet\n * syntax roles, which is what `theme-variants.css` carries; `floor` holds every\n * editor role to 4.5:1 on the canvas, as hex.\n *\n * With `palette: 'stylesheet'`, `floor` is the one palette write a catalogue\n * variant still gets: the stylesheet is generated for the default projection, so\n * the sixteen `--editor-*` properties are written inline over it. The rest of the\n * palette stays in the stylesheet.\n */\n editorRoles?: EditorRolesMode\n} & ThemeTokenProjectionOptions\n\n/**\n * What a catalogue variant still writes inline when its palette is the stylesheet's:\n * nothing, unless the editor projection is not the one the stylesheet was generated\n * for.\n */\nfunction stylesheetOverrides(\n engine: ThemeEngine,\n variant: ThemeVariant,\n editorRoles: EditorRolesMode | undefined\n): Record<string, string> {\n if (editorRoles !== 'floor') return {}\n return Object.fromEntries(\n Object.entries(engine.themeCssVariables(variant, { editor: 'floor' })).filter(([name]) =>\n name.startsWith('--editor-')\n )\n )\n}\n\n/**\n * The properties a pinned code theme writes: its `--editor-*` syntax ramp under the\n * host's projection, and the four canvas roles that ramp was measured against. Code\n * surfaces read the canvas as `var(--editor-background, var(--background))`, so the\n * interface canvas is the fallback whenever nothing is pinned.\n */\nexport function codeCssVariables(\n engine: ThemeEngine,\n variant: ThemeVariant,\n editorRoles?: EditorRolesMode\n): Record<string, string> {\n const all = engine.themeCssVariables(variant, { editor: editorRoles })\n const properties: Record<string, string> = {}\n for (const [name, value] of Object.entries(all)) {\n if (name.startsWith('--editor-')) properties[name] = value\n }\n properties['--editor-background'] = all['--background'] ?? variant.colors.background\n properties['--editor-foreground'] = all['--foreground'] ?? variant.colors.foreground\n properties['--editor-muted-foreground'] =\n all['--muted-foreground'] ?? variant.colors.mutedForeground\n properties['--editor-border'] = all['--border'] ?? variant.colors.border\n return properties\n}\n\n/**\n * The custom properties a state paints: the variant's roles, an optional projection\n * from the raw host map, the accent, the pinned terminal and code palettes, the surface alpha,\n * then `transformTokens`.\n *\n * The accent is applied *here* rather than left to the `[data-accent]` blocks in\n * `theme.css`, because the properties are written inline and an inline declaration\n * outranks every stylesheet selector however specific it is. The blocks still exist\n * and are still correct — they are what styles the window before this runs — but\n * they cannot win from here, so leaving the accent to them meant the attribute was\n * set, the rules were present, and nothing changed on screen.\n */\nexport function themeDocumentTokens(\n engine: ThemeEngine,\n state: ThemeDocumentState,\n options: ThemeDocumentOptions = {}\n): { tokens: Record<string, string>; accented: boolean } {\n assertThemeTokenProjectionConfig(options.tokenProjection)\n const fromStylesheet =\n options.palette === 'stylesheet' && engine.isCatalogueVariant(state.variant)\n const properties = fromStylesheet\n ? stylesheetOverrides(engine, state.variant, options.editorRoles)\n : { ...engine.themeCssVariables(state.variant, { editor: options.editorRoles }) }\n if (options.tokenProjection && !engine.isCatalogueVariant(state.variant)) {\n const rawTokens = state.variant.tokens ?? {}\n const projected = options.tokenProjection.project(rawTokens, options.tokenProjection.rules)\n for (const rule of options.tokenProjection.rules) {\n if (!rule || typeof rule.target !== 'string') continue\n if (Object.hasOwn(projected, rule.target)) {\n properties[rule.target] = projected[rule.target]!\n }\n }\n }\n const accent = engine.accentVariables(state.selection.accent, state.appearance, state.selection, {\n background: state.variant.colors.background,\n floor: options.accentContrastFloor,\n variantId: state.variant.id,\n })\n if (accent) Object.assign(properties, accent)\n // Written after the variant and the accent, so it wins over the interface\n // variant's own terminal ramp (and over the stylesheet's, which it outranks as an\n // inline declaration). Dropping the pin needs no removal of its own: the ramp is\n // then rewritten by the variant, or swept back to the stylesheet.\n if (state.terminalVariant) Object.assign(properties, terminalCssVariables(state.terminalVariant))\n // The same rule for code: the pinned ramp wins over the interface variant's, and its\n // canvas comes with it. Unpinning drops the canvas properties from this pass, so the\n // previous-set sweep removes them and code falls back to the interface canvas.\n if (state.codeVariant)\n Object.assign(properties, codeCssVariables(engine, state.codeVariant, options.editorRoles))\n if (state.surface) properties['--surface-alpha'] = surfaceAlpha[state.surface.surface]\n return {\n tokens: options.transformTokens ? options.transformTokens(properties) : properties,\n accented: accent !== undefined,\n }\n}\n\n/**\n * Write a state onto a root and report which custom properties it owns.\n *\n * Pass the previous call's return as `previous` and any palette property that pass\n * wrote and this one does not is removed. For the catalogue the two sets are the\n * same, so nothing is ever removed; it matters for a host variant that carries\n * `tokens` the catalogue does not, which would otherwise stay inline, beating the\n * stylesheet, after the user switched away from it.\n */\nexport function applyThemeToRoot(\n engine: ThemeEngine,\n root: ThemeRoot,\n state: ThemeDocumentState,\n options: ThemeDocumentOptions = {},\n previous?: ReadonlySet<string>\n): ReadonlySet<string> {\n const { tokens, accented } = themeDocumentTokens(engine, state, options)\n\n // Every pass recomputes the whole token set (an accent or font step included);\n // only the values that changed are written, so an unchanged palette does not\n // dirty the document's style. Custom property values read back as written.\n for (const [name, value] of Object.entries(tokens)) {\n if (root.style.getPropertyValue(name) !== value) root.style.setProperty(name, value)\n }\n if (previous) {\n for (const name of previous) {\n if (!(name in tokens)) root.style.removeProperty(name)\n }\n }\n\n root.classList.toggle('dark', state.appearance === 'dark')\n setData(root, 'theme', state.variant.id)\n setData(root, 'appearance', state.appearance)\n if (root.style.colorScheme !== state.appearance) root.style.colorScheme = state.appearance\n\n // A custom colour has no stylesheet block to select, and its value is the\n // attribute's worst possible content, so it is reported as `custom`.\n if (!accented) root.removeAttribute('data-accent')\n else\n setData(\n root,\n 'accent',\n isCustomAccent(state.selection.accent) ? 'custom' : state.selection.accent\n )\n\n // The surface axis is opt-in, so its absence removes rather than defaults: a host\n // that never enables it keeps an `<html>` with neither attribute, and one that\n // turns it off leaves nothing behind. (`--surface-alpha` is swept with the tokens.)\n if (state.surface) {\n setData(root, 'surface', state.surface.surface)\n setData(root, 'reduceTransparency', state.surface.reduceTransparencyActive ? 'true' : 'false')\n } else {\n root.removeAttribute('data-surface')\n root.removeAttribute('data-reduce-transparency')\n }\n\n applyAppearanceFontSettings(\n root,\n normalizeAppearanceEditorFontSettings(state.selection.fonts, state.selection.font).settings\n )\n\n const density = resolvedDensity(state.selection)\n if (density === 'comfortable') root.removeAttribute('data-density')\n else setData(root, 'density', density)\n\n return new Set(Object.keys(tokens))\n}\n\n/** Rewriting an attribute with its own value still queues a mutation and a style check. */\nfunction setData(root: ThemeRoot, key: string, value: string) {\n if (root.dataset[key] !== value) root.dataset[key] = value\n}\n\n/** What {@link applyWithoutTransitions} needs of a document. */\nexport type TransitionDocument = {\n head: { appendChild(node: unknown): unknown }\n createElement(tag: 'style'): {\n textContent: string | null\n offsetHeight?: number\n remove(): void\n }\n}\n\n/**\n * Run `apply` with every CSS transition switched off for the frame that carries\n * it, so a theme switch cannot animate page-wide.\n *\n * Without this, flipping the custom properties on `<html>` starts a transition on\n * every element that declares one, and each fades from the old palette to the new\n * over its own duration: a theme change that looks like a rendering fault. The\n * rule is removed two frames later, after the browser has committed the new styles\n * with transitions off, and `restore` runs it early (the provider calls it when it\n * is disposed mid-switch).\n *\n * `schedule` is the frame source; it defaults to `requestAnimationFrame` and falls\n * back to running at once where there is none, which leaves transitions on rather\n * than off.\n */\nexport function applyWithoutTransitions(\n doc: TransitionDocument,\n apply: () => void,\n schedule: (callback: () => void) => void = defaultSchedule\n): () => void {\n const style = doc.createElement('style')\n style.textContent = '*{transition:none !important}'\n doc.head.appendChild(style)\n // Reading a layout property forces the browser to commit the rule before the\n // properties change; without it the two can be batched into one style recalc.\n void style.offsetHeight\n let removed = false\n const restore = () => {\n if (removed) return\n removed = true\n style.remove()\n }\n try {\n apply()\n } catch (error) {\n restore()\n throw error\n }\n schedule(() => schedule(restore))\n return restore\n}\n\nfunction defaultSchedule(callback: () => void): void {\n if (typeof requestAnimationFrame === 'function') requestAnimationFrame(callback)\n else callback()\n}\n"],"mappings":";;;;;;;;;;;;AA2FA,SAAS,oBACP,QACA,SACA,aACwB;CACxB,IAAI,gBAAgB,SAAS,OAAO,CAAC;CACrC,OAAO,OAAO,YACZ,OAAO,QAAQ,OAAO,kBAAkB,SAAS,EAAE,QAAQ,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAC9E,KAAK,WAAW,WAAW,CAC7B,CACF;AACF;;;;;;;AAQA,SAAgB,iBACd,QACA,SACA,aACwB;CACxB,MAAM,MAAM,OAAO,kBAAkB,SAAS,EAAE,QAAQ,YAAY,CAAC;CACrE,MAAM,aAAqC,CAAC;CAC5C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,GAAG,GAC5C,IAAI,KAAK,WAAW,WAAW,GAAG,WAAW,QAAQ;CAEvD,WAAW,yBAAyB,IAAI,mBAAmB,QAAQ,OAAO;CAC1E,WAAW,yBAAyB,IAAI,mBAAmB,QAAQ,OAAO;CAC1E,WAAW,+BACT,IAAI,yBAAyB,QAAQ,OAAO;CAC9C,WAAW,qBAAqB,IAAI,eAAe,QAAQ,OAAO;CAClE,OAAO;AACT;;;;;;;;;;;;;AAcA,S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2C,iBAC/B;CACZ,MAAM,QAAQ,IAAI,cAAc,OAAO;CACvC,MAAM,cAAc;CACpB,IAAI,KAAK,YAAY,KAAK;CAG1B,MAAW;CACX,IAAI,UAAU;CACd,MAAM,gBAAgB;EACpB,IAAI,SAAS;EACb,UAAU;EACV,MAAM,OAAO;CACf;CACA,IAAI;EACF,MAAM;CACR,SAAS,OAAO;EACd,QAAQ;EACR,MAAM;CACR;CACA,eAAe,SAAS,OAAO,CAAC;CAChC,OAAO;AACT;AAEA,SAAS,gBAAgB,UAA4B;CACnD,IAAI,OAAO,0BAA0B,YAAY,sBAAsB,QAAQ;MAC1E,SAAS;AAChB"}
|
|
1
|
+
{"version":3,"file":"theme-document.js","names":[],"sources":["../../../src/components/theme/theme-document.ts"],"sourcesContent":["import {\n applyAppearanceFontSettings,\n normalizeAppearanceEditorFontSettings,\n} from '#lib/appearance-font-settings'\nimport { terminalCssVariables } from '#lib/theme-css'\nimport type { ThemeTokenProjectionOptions } from './token-projection'\nimport { assertThemeTokenProjectionConfig } from './token-projection-options'\nimport type { ThemeEngine } from '#lib/theme-engine'\nimport type { EditorRolesMode, ThemeAppearance, ThemeVariant } from '#lib/theme-types'\nimport { isCustomAccent } from '#lib/accent-roles'\nimport { surfaceAlpha, type SurfaceState } from '#lib/theme-surface'\nimport { resolvedDensity, type ThemeSelection } from './theme-state'\n\n/**\n * The document half of the theme provider: the single writer of `<html>`.\n *\n * Written against the few members of an element it uses, so the rules can be tested\n * on a stand-in. Every question the catalogue answers goes through the\n * {@link ThemeEngine} it is given, so it imports no catalogue code or data.\n */\nexport type ThemeRoot = Pick<\n HTMLElement,\n 'classList' | 'dataset' | 'style' | 'removeAttribute' | 'setAttribute'\n>\n\nexport type ThemeDocumentState = {\n /** What the document shows: the committed selection, or a preview laid over it. */\n selection: ThemeSelection\n appearance: ThemeAppearance\n variant: ThemeVariant\n /**\n * The variant whose terminal palette is pinned over the interface variant's.\n * Absent, the terminal follows the interface theme.\n */\n terminalVariant?: ThemeVariant\n /**\n * The variant whose syntax palette, and the canvas it was measured on, is pinned\n * over the interface variant's `--editor-*` ramp. Absent, code follows the\n * interface theme and no `--editor-background` family is written.\n */\n codeVariant?: ThemeVariant\n /**\n * The resolved surface axis. Absent, the axis is off: no attribute and no\n * `--surface-alpha` is written, and any this writer wrote before is removed.\n */\n surface?: SurfaceState\n}\n\nexport type ThemeDocumentOptions = {\n /**\n * Rewrites the custom properties just before they are written: the variant's\n * roles with the accent laid over them. It sees every property of the pass and\n * must return the full map; a name it drops is not written.\n */\n transformTokens?: (tokens: Record<string, string>) => Record<string, string>\n /**\n * The contrast an accent is held to against the variant's background. Absent, a\n * preset is painted verbatim (the catalogue measured it for its own themes) and\n * only a custom `#rrggbb` is held to the default floor of 3:1.\n */\n accentContrastFloor?: number\n /**\n * Where a catalogue variant's palette comes from. `inline` (the default) writes\n * every role onto the root. `stylesheet` writes none for a catalogue variant,\n * because the host loads a stylesheet that carries a `[data-theme]` block for it;\n * a variant the catalogue does not hold (a host's imported theme) is still written\n * inline, since no stylesheet can know it. The accent, the terminal pin, the\n * surface alpha and the fonts are written the same in both.\n *\n * Switching from an imported variant back to a catalogue one removes what the\n * imported one wrote, so nothing inline outlives it to beat the stylesheet.\n */\n palette?: 'inline' | 'stylesheet'\n /**\n * The `--editor-*` projection. `syntax` (the default) is the catalogue's quiet\n * syntax roles, which is what `theme-variants.css` carries; `floor` holds every\n * editor role to 4.5:1 on the canvas, as hex.\n *\n * With `palette: 'stylesheet'`, `floor` is the one palette write a catalogue\n * variant still gets: the stylesheet is generated for the default projection, so\n * the `--editor-*` properties are written inline over it. The rest of the\n * palette stays in the stylesheet.\n */\n editorRoles?: EditorRolesMode\n} & ThemeTokenProjectionOptions\n\n/**\n * What a catalogue variant still writes inline when its palette is the stylesheet's:\n * nothing, unless the editor projection is not the one the stylesheet was generated\n * for.\n */\nfunction stylesheetOverrides(\n engine: ThemeEngine,\n variant: ThemeVariant,\n editorRoles: EditorRolesMode | undefined\n): Record<string, string> {\n if (editorRoles !== 'floor') return {}\n return Object.fromEntries(\n Object.entries(engine.themeCssVariables(variant, { editor: 'floor' })).filter(([name]) =>\n name.startsWith('--editor-')\n )\n )\n}\n\n/**\n * The properties a pinned code theme writes: its `--editor-*` syntax ramp under the\n * host's projection, and the four canvas roles that ramp was measured against. Code\n * surfaces read the canvas as `var(--editor-background, var(--background))`, so the\n * interface canvas is the fallback whenever nothing is pinned.\n */\nexport function codeCssVariables(\n engine: ThemeEngine,\n variant: ThemeVariant,\n editorRoles?: EditorRolesMode\n): Record<string, string> {\n const all = engine.themeCssVariables(variant, { editor: editorRoles })\n const properties: Record<string, string> = {}\n for (const [name, value] of Object.entries(all)) {\n if (name.startsWith('--editor-')) properties[name] = value\n }\n properties['--editor-background'] = all['--background'] ?? variant.colors.background\n properties['--editor-foreground'] = all['--foreground'] ?? variant.colors.foreground\n properties['--editor-muted-foreground'] =\n all['--muted-foreground'] ?? variant.colors.mutedForeground\n properties['--editor-border'] = all['--border'] ?? variant.colors.border\n return properties\n}\n\n/**\n * The custom properties a state paints: the variant's roles, an optional projection\n * from the raw host map, the accent, the pinned terminal and code palettes, the surface alpha,\n * then `transformTokens`.\n *\n * The accent is applied *here* rather than left to the `[data-accent]` blocks in\n * `theme.css`, because the properties are written inline and an inline declaration\n * outranks every stylesheet selector however specific it is. The blocks still exist\n * and are still correct — they are what styles the window before this runs — but\n * they cannot win from here, so leaving the accent to them meant the attribute was\n * set, the rules were present, and nothing changed on screen.\n */\nexport function themeDocumentTokens(\n engine: ThemeEngine,\n state: ThemeDocumentState,\n options: ThemeDocumentOptions = {}\n): { tokens: Record<string, string>; accented: boolean } {\n assertThemeTokenProjectionConfig(options.tokenProjection)\n const fromStylesheet =\n options.palette === 'stylesheet' && engine.isCatalogueVariant(state.variant)\n const properties = fromStylesheet\n ? stylesheetOverrides(engine, state.variant, options.editorRoles)\n : { ...engine.themeCssVariables(state.variant, { editor: options.editorRoles }) }\n if (options.tokenProjection && !engine.isCatalogueVariant(state.variant)) {\n const rawTokens = state.variant.tokens ?? {}\n const projected = options.tokenProjection.project(rawTokens, options.tokenProjection.rules)\n for (const rule of options.tokenProjection.rules) {\n if (!rule || typeof rule.target !== 'string') continue\n if (Object.hasOwn(projected, rule.target)) {\n properties[rule.target] = projected[rule.target]!\n }\n }\n }\n const accent = engine.accentVariables(state.selection.accent, state.appearance, state.selection, {\n background: state.variant.colors.background,\n floor: options.accentContrastFloor,\n variantId: state.variant.id,\n })\n if (accent) Object.assign(properties, accent)\n // Written after the variant and the accent, so it wins over the interface\n // variant's own terminal ramp (and over the stylesheet's, which it outranks as an\n // inline declaration). Dropping the pin needs no removal of its own: the ramp is\n // then rewritten by the variant, or swept back to the stylesheet.\n if (state.terminalVariant) Object.assign(properties, terminalCssVariables(state.terminalVariant))\n // The same rule for code: the pinned ramp wins over the interface variant's, and its\n // canvas comes with it. Unpinning drops the canvas properties from this pass, so the\n // previous-set sweep removes them and code falls back to the interface canvas.\n if (state.codeVariant)\n Object.assign(properties, codeCssVariables(engine, state.codeVariant, options.editorRoles))\n if (state.surface) properties['--surface-alpha'] = surfaceAlpha[state.surface.surface]\n return {\n tokens: options.transformTokens ? options.transformTokens(properties) : properties,\n accented: accent !== undefined,\n }\n}\n\n/**\n * Write a state onto a root and report which custom properties it owns.\n *\n * Pass the previous call's return as `previous` and any palette property that pass\n * wrote and this one does not is removed. For the catalogue the two sets are the\n * same, so nothing is ever removed; it matters for a host variant that carries\n * `tokens` the catalogue does not, which would otherwise stay inline, beating the\n * stylesheet, after the user switched away from it.\n */\nexport function applyThemeToRoot(\n engine: ThemeEngine,\n root: ThemeRoot,\n state: ThemeDocumentState,\n options: ThemeDocumentOptions = {},\n previous?: ReadonlySet<string>\n): ReadonlySet<string> {\n const { tokens, accented } = themeDocumentTokens(engine, state, options)\n\n // Every pass recomputes the whole token set (an accent or font step included);\n // only the values that changed are written, so an unchanged palette does not\n // dirty the document's style. Custom property values read back as written.\n for (const [name, value] of Object.entries(tokens)) {\n if (root.style.getPropertyValue(name) !== value) root.style.setProperty(name, value)\n }\n if (previous) {\n for (const name of previous) {\n if (!(name in tokens)) root.style.removeProperty(name)\n }\n }\n\n root.classList.toggle('dark', state.appearance === 'dark')\n setData(root, 'theme', state.variant.id)\n setData(root, 'appearance', state.appearance)\n if (root.style.colorScheme !== state.appearance) root.style.colorScheme = state.appearance\n\n // A custom colour has no stylesheet block to select, and its value is the\n // attribute's worst possible content, so it is reported as `custom`.\n if (!accented) root.removeAttribute('data-accent')\n else\n setData(\n root,\n 'accent',\n isCustomAccent(state.selection.accent) ? 'custom' : state.selection.accent\n )\n\n // The surface axis is opt-in, so its absence removes rather than defaults: a host\n // that never enables it keeps an `<html>` with neither attribute, and one that\n // turns it off leaves nothing behind. (`--surface-alpha` is swept with the tokens.)\n if (state.surface) {\n setData(root, 'surface', state.surface.surface)\n setData(root, 'reduceTransparency', state.surface.reduceTransparencyActive ? 'true' : 'false')\n } else {\n root.removeAttribute('data-surface')\n root.removeAttribute('data-reduce-transparency')\n }\n\n applyAppearanceFontSettings(\n root,\n normalizeAppearanceEditorFontSettings(state.selection.fonts, state.selection.font).settings\n )\n\n const density = resolvedDensity(state.selection)\n if (density === 'comfortable') root.removeAttribute('data-density')\n else setData(root, 'density', density)\n\n return new Set(Object.keys(tokens))\n}\n\n/** Rewriting an attribute with its own value still queues a mutation and a style check. */\nfunction setData(root: ThemeRoot, key: string, value: string) {\n if (root.dataset[key] !== value) root.dataset[key] = value\n}\n\n/** What {@link applyWithoutTransitions} needs of a document. */\nexport type TransitionDocument = {\n head: { appendChild(node: unknown): unknown }\n createElement(tag: 'style'): {\n textContent: string | null\n offsetHeight?: number\n remove(): void\n }\n}\n\n/**\n * Run `apply` with every CSS transition switched off for the frame that carries\n * it, so a theme switch cannot animate page-wide.\n *\n * Without this, flipping the custom properties on `<html>` starts a transition on\n * every element that declares one, and each fades from the old palette to the new\n * over its own duration: a theme change that looks like a rendering fault. The\n * rule is removed two frames later, after the browser has committed the new styles\n * with transitions off, and `restore` runs it early (the provider calls it when it\n * is disposed mid-switch).\n *\n * `schedule` is the frame source; it defaults to `requestAnimationFrame` and falls\n * back to running at once where there is none, which leaves transitions on rather\n * than off.\n */\nexport function applyWithoutTransitions(\n doc: TransitionDocument,\n apply: () => void,\n schedule: (callback: () => void) => void = defaultSchedule\n): () => void {\n const style = doc.createElement('style')\n style.textContent = '*{transition:none !important}'\n doc.head.appendChild(style)\n // Reading a layout property forces the browser to commit the rule before the\n // properties change; without it the two can be batched into one style recalc.\n void style.offsetHeight\n let removed = false\n const restore = () => {\n if (removed) return\n removed = true\n style.remove()\n }\n try {\n apply()\n } catch (error) {\n restore()\n throw error\n }\n schedule(() => schedule(restore))\n return restore\n}\n\nfunction defaultSchedule(callback: () => void): void {\n if (typeof requestAnimationFrame === 'function') requestAnimationFrame(callback)\n else callback()\n}\n"],"mappings":";;;;;;;;;;;;AA2FA,SAAS,oBACP,QACA,SACA,aACwB;CACxB,IAAI,gBAAgB,SAAS,OAAO,CAAC;CACrC,OAAO,OAAO,YACZ,OAAO,QAAQ,OAAO,kBAAkB,SAAS,EAAE,QAAQ,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAC9E,KAAK,WAAW,WAAW,CAC7B,CACF;AACF;;;;;;;AAQA,SAAgB,iBACd,QACA,SACA,aACwB;CACxB,MAAM,MAAM,OAAO,kBAAkB,SAAS,EAAE,QAAQ,YAAY,CAAC;CACrE,MAAM,aAAqC,CAAC;CAC5C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,GAAG,GAC5C,IAAI,KAAK,WAAW,WAAW,GAAG,WAAW,QAAQ;CAEvD,WAAW,yBAAyB,IAAI,mBAAmB,QAAQ,OAAO;CAC1E,WAAW,yBAAyB,IAAI,mBAAmB,QAAQ,OAAO;CAC1E,WAAW,+BACT,IAAI,yBAAyB,QAAQ,OAAO;CAC9C,WAAW,qBAAqB,IAAI,eAAe,QAAQ,OAAO;CAClE,OAAO;AACT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gB,wBACd,KACA,OACA,WAA2C,iBAC/B;CACZ,MAAM,QAAQ,IAAI,cAAc,OAAO;CACvC,MAAM,cAAc;CACpB,IAAI,KAAK,YAAY,KAAK;CAG1B,MAAW;CACX,IAAI,UAAU;CACd,MAAM,gBAAgB;EACpB,IAAI,SAAS;EACb,UAAU;EACV,MAAM,OAAO;CACf;CACA,IAAI;EACF,MAAM;CACR,SAAS,OAAO;EACd,QAAQ;EACR,MAAM;CACR;CACA,eAAe,SAAS,OAAO,CAAC;CAChC,OAAO;AACT;AAEA,SAAS,gBAAgB,UAA4B;CACnD,IAAI,OAAO,0BAA0B,YAAY,sBAAsB,QAAQ;MAC1E,SAAS;AAChB"}
|
|
@@ -117,7 +117,7 @@ export type ThemeProviderProps = {
|
|
|
117
117
|
/**
|
|
118
118
|
* The projection behind the `--editor-*` ramp. `syntax` (the default) is the
|
|
119
119
|
* catalogue's quiet syntax roles, a comment among them deliberately below
|
|
120
|
-
* body-text contrast. `floor` holds
|
|
120
|
+
* body-text contrast. `floor` holds every role to 4.5:1 on the canvas, as
|
|
121
121
|
* hex, for a host that renders code as content (a diff, a file view) rather than
|
|
122
122
|
* as decoration.
|
|
123
123
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-provider-value.js","names":[],"sources":["../../../src/components/theme/theme-provider-value.ts"],"sourcesContent":["import type { JSX } from 'solid-js'\nimport {\n createComponent,\n createEffect,\n createMemo,\n createSignal,\n onCleanup,\n splitProps,\n untrack,\n} from 'solid-js'\nimport type { ThemeTokenProjectionOptions } from './token-projection'\nimport { assertThemeTokenProjectionConfig } from './token-projection-options'\nimport { fontZoomShortcut, type FontZoomIntent } from '#lib/font-zoom'\nimport { DEFAULT_THEME_STORAGE_KEY } from '#lib/theme-defaults'\nimport { REDUCED_TRANSPARENCY_QUERY, resolveSurfaceState } from '#lib/theme-surface'\nimport { needsCatalogue, pairNeedsData, type ThemeEngine } from '#lib/theme-engine'\nimport type { EditorRolesMode, ThemeAppearance, ThemeVariant } from '#lib/theme-types'\nimport { themeContext } from './theme-context'\nimport { applyThemeToRoot, applyWithoutTransitions } from './theme-document'\nimport {\n localStoragePersistence,\n readPersisted,\n writePersisted,\n type ThemePersistence,\n} from './theme-persistence'\nimport {\n accentRolesForState,\n initialThemeSelection,\n mergeRegistry,\n mergeThemeSelection,\n resolveCodeVariant,\n resolveTerminalVariant,\n resolveThemeState,\n zoomedFontSettings,\n type ThemeContextValue,\n type ThemeSelection,\n} from './theme-state'\n\n/**\n * The props both `ThemeProvider`s take.\n *\n * ## What a preference is\n *\n * Four independent choices (`ThemeSelection`), and keeping them independent is the\n * point: appearance, a theme per appearance, an accent and fonts. They compose: a\n * user who wants Nord with a violet accent and the system font should not need\n * someone to author that combination.\n *\n * ## Where the rules live\n *\n * The provider is wiring. What a selection merges to and resolves to is\n * `theme-state.ts`; what lands on `<html>` is `theme-document.ts`; where the\n * preference is kept is `theme-persistence.ts`.\n *\n * ## Why the variants are applied as inline properties\n *\n * The catalogue is data, and a theme is applied by writing its roles onto\n * `<html>` as custom properties. That is what makes an imported palette work\n * without a hand-written `[data-theme]` block per theme, and it is why a settings\n * UI can show a preview by reading the same object rather than by loading a\n * stylesheet. `theme.css` keeps the default theme's values so the first paint is\n * correct before any script runs.\n */\nexport type ThemeProviderProps = {\n children?: JSX.Element\n /** Where the preference is persisted. Distinct per application. */\n storageKey?: string\n /** Start from this instead of the stored preference. */\n initial?: Partial<ThemeSelection>\n /**\n * The selection, owned by the caller.\n *\n * For a consumer that keeps the state itself — a settings store, or a workshop\n * whose selection lives in Storybook globals — rather than handing it to this\n * provider's signal. Each change lands here and the document follows; nothing is\n * written to the store, because the caller is the one who persists. A picker\n * below the provider still works, and its change is the caller's to read back.\n *\n * Absent, the provider is the whole owner: it reads `storageKey` on mount,\n * seeds from `initial`, and persists every `setSelection`.\n */\n selection?: Partial<ThemeSelection>\n /**\n * Where the preference is kept, in place of `localStorage` under `storageKey`.\n *\n * Read once when the provider is created, so changing the prop later does not\n * move the store. `storageKey` is ignored when this is given.\n */\n persistence?: ThemePersistence\n /**\n * Variants the host adds to the built-in catalogue — themes a user imported.\n *\n * A function is read inside the provider's reactive scope, so one that reads a\n * signal keeps the picker and the document current when the set changes. A\n * stored id that names no variant, built in or added, paints the default of its\n * appearance and stays in the selection untouched.\n */\n themes?: readonly ThemeVariant[] | (() => readonly ThemeVariant[])\n /**\n * Rewrites the custom properties of each pass before they are written to\n * `<html>`: the variant's roles with the accent over them. `tokensAsHex` from\n * `lib/themes` is the one the system ships.\n */\n transformTokens?: (tokens: Record<string, string>) => Record<string, string>\n /**\n * Switch CSS transitions off for the frame that carries a change, so a theme\n * switch cannot animate the whole page. Off by default: it adds a `<style>`\n * element to `<head>` for two frames on every change.\n */\n disableTransitionOnChange?: boolean\n /**\n * The contrast ratio an accent is held to against the variant's background,\n * repaired to the nearest passing colour when it falls short. Absent, presets\n * are painted verbatim — the catalogue measured them for its own themes — and\n * only a custom `#rrggbb` is held to 3:1. A host that adds themes the catalogue\n * never measured passes 3 to hold the presets to it as well; for the catalogue's\n * own themes the floor changes no preset.\n */\n accentContrastFloor?: number\n /**\n * Turns the surface axis on: `selection.surface` and `selection.reduceTransparency`\n * are resolved against the operating system's Reduce Transparency setting and the\n * host's capability, and `data-surface`, `data-reduce-transparency` and\n * `--surface-alpha` are written to `<html>` (the frost rule in `theme.css` reads\n * them). Off by default: a provider that never opts in writes none of them, adds no\n * media-query listener, and stores nothing new.\n *\n * An object also states the host's capability. `nativeTranslucency` is whether the\n * window can render the OS's own translucency; without it a `translucent`\n * preference paints the tokenized `frosted` surface instead of pretending to\n * vibrancy. A function is read inside the provider's reactive scope, for a\n * capability that is learned after mount.\n *\n * A selection that already carries a `surface` turns the axis on for itself, so a\n * host that stores the field gets the same document without the prop.\n */\n surface?: boolean | { nativeTranslucency?: boolean | (() => boolean) }\n /**\n * Where a catalogue variant's palette comes from. `inline` (the default) writes\n * every role onto `<html>`. `stylesheet` leaves a catalogue variant to the host's\n * `[data-theme]` stylesheet and writes inline only what no stylesheet can know: a\n * host's own `themes`, the accent, the pinned terminal palette, the surface alpha\n * and the fonts. Switching from a host variant back to a catalogue one removes the\n * properties the host variant wrote.\n */\n palette?: 'inline' | 'stylesheet'\n /**\n * The projection behind the `--editor-*` ramp. `syntax` (the default) is the\n * catalogue's quiet syntax roles, a comment among them deliberately below\n * body-text contrast. `floor` holds all sixteen roles to 4.5:1 on the canvas, as\n * hex, for a host that renders code as content (a diff, a file view) rather than\n * as decoration.\n *\n * Applies to catalogue variants; a host's own `themes` keep their `editor` and\n * their `tokens`. With `palette=\"stylesheet\"` it is the one palette property a\n * catalogue variant still writes inline, because `theme-variants.css` is generated\n * for `syntax`. Absent, nothing changes.\n */\n editorRoles?: EditorRolesMode\n /**\n * Bind the platform zoom chords (Cmd or Ctrl with `=`, `+`, `-`, `0`) to the three\n * text sizes instead of the browser's page zoom: stepping them together is zoom\n * inside the persisted type system. Off by default: it adds a capturing `keydown`\n * listener to `window`, and an event already handled elsewhere is left alone.\n * `zoomFonts` on the context does the same from a menu or a host's own binding.\n */\n fontZoom?: boolean\n} & ThemeTokenProjectionOptions\n\n/**\n * Where the provider's catalogue questions are answered, and whether the whole\n * catalogue is available yet.\n *\n * The eager provider's source is the full catalogue and is always loaded. The lazy\n * provider's source starts on the default pair that ships with it and swaps to the\n * full catalogue when {@link ThemeCatalogueSource.load} resolves. Both read the same\n * way in the provider: `engine()` is reactive, so everything derived from it follows\n * the swap.\n */\nexport type ThemeCatalogueSource = {\n /** The engine answering catalogue questions now. Changes once, when loading completes. */\n engine: () => ThemeEngine\n /** True when `engine()` is the full catalogue. */\n loaded: () => boolean\n /** True when loading failed; the provider then paints what it can without the rest. */\n failed: () => boolean\n /** Start loading the full catalogue (idempotent). Resolves when `loaded()` is true. */\n load: () => Promise<void>\n}\n\n/** The operating system's Reduce Transparency query, where there is a window to ask. */\nfunction reducedTransparencyMedia(): MediaQueryList | undefined {\n return typeof window !== 'undefined' && typeof window.matchMedia === 'function'\n ? window.matchMedia(REDUCED_TRANSPARENCY_QUERY)\n : undefined\n}\n\n/**\n * The provider, parameterised by where its catalogue comes from: the eager\n * `ThemeProvider` passes the whole catalogue, the lazy one a source that loads it.\n * Nothing here imports catalogue code or data, which is what lets the lazy entry keep\n * them out of a consumer's start-up chunk.\n */\n\n/** Selections are small plain records built in one key order, so this is exact. */\nfunction sameThemeSelection(a: ThemeSelection, b: ThemeSelection) {\n return a === b || JSON.stringify(a) === JSON.stringify(b)\n}\n\nexport function ThemeProviderWith(\n props: ThemeProviderProps & { catalogue: ThemeCatalogueSource }\n): JSX.Element {\n const value = createThemeContextValue(props)\n return createComponent(themeContext().Provider, {\n value,\n get children() {\n return props.children\n },\n })\n}\n\n/**\n * Everything the provider is, as a value: the context object, with its effects and\n * listeners created in the caller's reactive scope.\n */\nexport function createThemeContextValue(\n props: ThemeProviderProps & { catalogue: ThemeCatalogueSource }\n): ThemeContextValue {\n assertThemeTokenProjectionConfig(props.tokenProjection)\n const [local] = splitProps(props, [\n 'catalogue',\n 'storageKey',\n 'initial',\n 'selection',\n 'persistence',\n 'themes',\n 'transformTokens',\n 'tokenProjection',\n 'disableTransitionOnChange',\n 'accentContrastFloor',\n 'surface',\n 'palette',\n 'editorRoles',\n 'fontZoom',\n ])\n const storageKey = () => local.storageKey ?? DEFAULT_THEME_STORAGE_KEY\n const persistence = local.persistence ?? localStoragePersistence(storageKey)\n\n // Read before the first resolution and before the store is, so a persistence whose\n // answer depends on the extras (an id it only accepts if the theme exists) sees\n // them.\n const extraThemes = createMemo(() =>\n typeof local.themes === 'function' ? local.themes() : (local.themes ?? [])\n )\n const source = () => local.catalogue\n const engine = () => source().engine()\n const registry = createMemo(() => mergeRegistry(engine().builtinThemes, extraThemes()))\n\n // A patch that changes nothing (pressing the current toggle again, a font step\n // that clamps) leaves the signal alone, so the document pass and the store write\n // that follow every change do not run for it.\n const [selection, setSelectionState] = createSignal<ThemeSelection>(\n initialThemeSelection(readPersisted(persistence), local.initial),\n { equals: sameThemeSelection }\n )\n\n // The controlled half of the contract. A patch from the owner replaces the\n // matching axes; the stored preference is untouched, since the owner is the one\n // that persists. Reading `local.selection` — a prop getter, not a destructured\n // value — is what keeps this subscribed for the provider's lifetime.\n createEffect(() => {\n const incoming = local.selection\n if (incoming) setSelectionState((current) => mergeThemeSelection(current, incoming))\n })\n\n const [systemAppearance, setSystemAppearance] = createSignal<ThemeAppearance>('light')\n\n if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {\n const query = window.matchMedia('(prefers-color-scheme: dark)')\n setSystemAppearance(query.matches ? 'dark' : 'light')\n const onChange = (event: MediaQueryListEvent) =>\n setSystemAppearance(event.matches ? 'dark' : 'light')\n query.addEventListener('change', onChange)\n onCleanup(() => query.removeEventListener('change', onChange))\n }\n\n // What the stored preference resolves to. `selection()`, `variant()` and\n // `resolvedAppearance()` answer from this and never from a preview, so a picker\n // that previews a draft still reads back what is committed.\n const committed = createMemo(() => resolveThemeState(selection(), systemAppearance(), registry()))\n const resolvedAppearance = createMemo<ThemeAppearance>(() => committed().appearance)\n const variant = createMemo<ThemeVariant>(() => committed().variant)\n\n const [draft, setDraft] = createSignal<Partial<ThemeSelection> | undefined>()\n const shownSelection = createMemo(() => {\n const preview = draft()\n return preview ? mergeThemeSelection(selection(), preview) : selection()\n })\n const shown = createMemo(() =>\n draft() ? resolveThemeState(shownSelection(), systemAppearance(), registry()) : committed()\n )\n const shownAppearance = createMemo<ThemeAppearance>(() => shown().appearance)\n\n // The surface axis. Off, none of this reads the operating system: the media query\n // is subscribed only while the axis is on, so a provider that never opts in adds no\n // listener and no repaint.\n const surfaceOn = (candidate: ThemeSelection) =>\n local.surface === true || typeof local.surface === 'object' || candidate.surface !== undefined\n const nativeTranslucency = () => {\n const capability = typeof local.surface === 'object' ? local.surface.nativeTranslucency : false\n return (typeof capability === 'function' ? capability() : capability) === true\n }\n const [osReducedTransparency, setOsReducedTransparency] = createSignal(\n surfaceOn(untrack(shownSelection)) ? (reducedTransparencyMedia()?.matches ?? false) : false\n )\n const axisOn = createMemo(() => surfaceOn(shownSelection()))\n createEffect(() => {\n const query = axisOn() ? reducedTransparencyMedia() : undefined\n setOsReducedTransparency(query?.matches ?? false)\n if (!query) return\n const onChange = (event: MediaQueryListEvent) => setOsReducedTransparency(event.matches)\n query.addEventListener('change', onChange)\n onCleanup(() => query.removeEventListener('change', onChange))\n })\n const surfaceStateOf = (candidate: ThemeSelection) =>\n resolveSurfaceState(candidate.surface, {\n osReducedTransparency: osReducedTransparency(),\n userReducedTransparency: candidate.reduceTransparency === true,\n nativeTranslucency: nativeTranslucency(),\n })\n const committedSurface = createMemo(() =>\n surfaceOn(selection()) ? surfaceStateOf(selection()) : undefined\n )\n\n // A selection that names a catalogue theme beyond the shipped default pair cannot be\n // painted or previewed until the whole catalogue has loaded. Once a load has failed\n // the provider paints what the shipped data can.\n const waitingFor = (candidate: ThemeSelection, appearance: ThemeAppearance) =>\n !source().loaded() && !source().failed() && needsCatalogue(candidate, appearance)\n createEffect(() => {\n if (\n needsCatalogue(selection(), committed().appearance) ||\n needsCatalogue(shownSelection(), shown().appearance)\n )\n void source().load()\n })\n\n let written: ReadonlySet<string> | undefined\n let restoreTransitions: (() => void) | undefined\n createEffect(() => {\n if (typeof document === 'undefined') return\n const current = engine()\n const display = shown()\n // Until the catalogue arrives the document keeps what is already on it — the\n // stylesheet's theme, set before first paint by `themeScript` — instead of\n // flashing the default for a theme that is only not loaded yet.\n if (waitingFor(shownSelection(), display.appearance)) return\n const state = {\n selection: shownSelection(),\n appearance: display.appearance,\n variant: display.variant,\n terminalVariant: resolveTerminalVariant(shownSelection().terminalThemeId, registry()),\n codeVariant: resolveCodeVariant(shownSelection().codeThemeId, registry()),\n surface: axisOn() ? surfaceStateOf(shownSelection()) : undefined,\n }\n const projectionOptions = local.tokenProjection\n ? { tokenProjection: local.tokenProjection }\n : {}\n const options = {\n transformTokens: local.transformTokens,\n ...projectionOptions,\n accentContrastFloor: local.accentContrastFloor,\n palette: local.palette,\n editorRoles: local.editorRoles,\n }\n const apply = () => {\n written = applyThemeToRoot(current, document.documentElement, state, options, written)\n }\n if (local.disableTransitionOnChange) {\n restoreTransitions?.()\n restoreTransitions = applyWithoutTransitions(document, apply)\n } else {\n apply()\n }\n })\n onCleanup(() => restoreTransitions?.())\n\n // A pair beyond the defaults offers its accents once the catalogue is here; reading\n // them is not a reason to load it.\n const lightThemeId = createMemo(() => selection().lightThemeId)\n const darkThemeId = createMemo(() => selection().darkThemeId)\n const themeAccents = createMemo(() => {\n const pair = { lightThemeId: lightThemeId(), darkThemeId: darkThemeId() }\n return !source().loaded() && pairNeedsData(pair)\n ? []\n : engine().themeAccentsFor(pair.lightThemeId, pair.darkThemeId)\n })\n\n const zoomFonts = (intent: FontZoomIntent) =>\n value.setSelection({ fonts: zoomedFontSettings(selection(), intent) })\n\n // The platform zoom chords drive the three text sizes, captured like the other\n // global chords; an event something else already handled never double-steps.\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.defaultPrevented) return\n const intent = fontZoomShortcut(event)\n if (!intent) return\n event.preventDefault()\n zoomFonts(intent)\n }\n createEffect(() => {\n if (!local.fontZoom || typeof window === 'undefined') return\n window.addEventListener('keydown', onKeyDown, { capture: true })\n onCleanup(() => window.removeEventListener('keydown', onKeyDown, { capture: true }))\n })\n\n const value: ThemeContextValue = {\n selection,\n resolvedAppearance,\n shownAppearance,\n variant,\n get themes() {\n return engine().builtinThemes\n },\n themeAccents,\n allThemes: registry,\n preview(next) {\n setDraft(next ? { ...next } : undefined)\n },\n previewing: () => draft() !== undefined,\n accentRolesFor(accent, variantId) {\n // Before the catalogue arrives the light engine answers provisionally and asks\n // for it; reading `engine()` re-runs a reactive caller on arrival.\n return accentRolesForState(engine(), accent, variantId, {\n selection: selection(),\n variant: variant(),\n registry: registry(),\n accentContrastFloor: local.accentContrastFloor,\n })\n },\n catalogueReady: () => source().loaded(),\n loadCatalogue: () => source().load(),\n effectiveSurface: () => committedSurface()?.surface ?? 'opaque',\n reduceTransparencyActive: () => committedSurface()?.reduceTransparencyActive ?? false,\n zoomFonts,\n setSelection(patch) {\n const current = selection()\n const next = mergeThemeSelection(current, patch)\n setDraft(undefined)\n if (sameThemeSelection(current, next)) return\n setSelectionState(next)\n writePersisted(persistence, next)\n },\n }\n\n return value\n}\n"],"mappings":";;;;;;;;;;;;AA+LA,SAAS,2BAAuD;CAC9D,OAAO,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe,aACjE,OAAO,WAAW,0BAA0B,IAC5C,KAAA;AACN;;;;;;;;AAUA,SAAS,mBAAmB,GAAmB,GAAmB;CAChE,OAAO,MAAM,KAAK,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;AAC1D;AAEA,SAAgB,kBACd,OACa;CACb,MAAM,QAAQ,wBAAwB,KAAK;CAC3C,OAAO,gBAAgB,aAAa,CAAC,CAAC,UAAU;EAC9C;EACA,IAAI,WAAW;GACb,OAAO,MAAM;EACf;CACF,CAAC;AACH;;;;;AAMA,SAAgB,wBACd,OACmB;CACnB,iCAAiC,MAAM,eAAe;CACtD,MAAM,CAAC,SAAS,WAAW,OAAO;EAChC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,MAAM,mBAAmB,MAAM,cAAA;CAC/B,MAAM,cAAc,MAAM,eAAe,wBAAwB,UAAU;CAK3E,MAAM,cAAc,iBAClB,OAAO,MAAM,WAAW,aAAa,MAAM,OAAO,IAAK,MAAM,UAAU,CAAC,CAC1E;CACA,MAAM,eAAe,MAAM;CAC3B,MAAM,eAAe,OAAO,CAAC,CAAC,OAAO;CACrC,MAAM,WAAW,iBAAiB,cAAc,OAAO,CAAC,CAAC,eAAe,YAAY,CAAC,CAAC;CAKtF,MAAM,CAAC,WAAW,qBAAqB,aACrC,sBAAsB,cAAc,WAAW,GAAG,MAAM,OAAO,GAC/D,EAAE,QAAQ,mBAAmB,CAC/B;CAMA,mBAAmB;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EACA;EACA;EACA;EACA,IAAI,SAAS;GACX,OAAO,OAAO,CAAC,CAAC;EAClB;EACA;EACA,WAAW;EACX,QAAQ,MAAM;GACZ,SAAS,OAAO,EAAE,GAAG,KAAK,IAAI,KAAA,CAAS;EACzC;EACA,kBAAkB,MAAM,MAAM,KAAA;EAC9B,eAAe,QAAQ,WAAW;GAGhC,OAAO,oBAAoB,OAAO,GAAG,QAAQ,WAAW;IACtD,WAAW,UAAU;IACrB,SAAS,QAAQ;IACjB,UAAU,SAAS;IACnB,qBAAqB,MAAM;GAC7B,CAAC;EACH;EACA,sBAAsB,OAAO,CAAC,CAAC,OAAO;EACtC,qBAAqB,OAAO,CAAC,CAAC,KAAK;EACnC,wBAAwB,iBAAiB,CAAC,EAAE,WAAW;EACvD,gCAAgC,iBAAiB,CAAC,EAAE,4BAA4B;EAChF;EACA,aAAa,OAAO;GAClB,MAAM,UAAU,UAAU;GAC1B,MAAM,OAAO,oBAAoB,SAAS,KAAK;GAC/C,SAAS,KAAA,CAAS;GAClB,IAAI,mBAAmB,SAAS,IAAI,GAAG;GACvC,kBAAkB,IAAI;GACtB,eAAe,aAAa,IAAI;EAClC;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"theme-provider-value.js","names":[],"sources":["../../../src/components/theme/theme-provider-value.ts"],"sourcesContent":["import type { JSX } from 'solid-js'\nimport {\n createComponent,\n createEffect,\n createMemo,\n createSignal,\n onCleanup,\n splitProps,\n untrack,\n} from 'solid-js'\nimport type { ThemeTokenProjectionOptions } from './token-projection'\nimport { assertThemeTokenProjectionConfig } from './token-projection-options'\nimport { fontZoomShortcut, type FontZoomIntent } from '#lib/font-zoom'\nimport { DEFAULT_THEME_STORAGE_KEY } from '#lib/theme-defaults'\nimport { REDUCED_TRANSPARENCY_QUERY, resolveSurfaceState } from '#lib/theme-surface'\nimport { needsCatalogue, pairNeedsData, type ThemeEngine } from '#lib/theme-engine'\nimport type { EditorRolesMode, ThemeAppearance, ThemeVariant } from '#lib/theme-types'\nimport { themeContext } from './theme-context'\nimport { applyThemeToRoot, applyWithoutTransitions } from './theme-document'\nimport {\n localStoragePersistence,\n readPersisted,\n writePersisted,\n type ThemePersistence,\n} from './theme-persistence'\nimport {\n accentRolesForState,\n initialThemeSelection,\n mergeRegistry,\n mergeThemeSelection,\n resolveCodeVariant,\n resolveTerminalVariant,\n resolveThemeState,\n zoomedFontSettings,\n type ThemeContextValue,\n type ThemeSelection,\n} from './theme-state'\n\n/**\n * The props both `ThemeProvider`s take.\n *\n * ## What a preference is\n *\n * Four independent choices (`ThemeSelection`), and keeping them independent is the\n * point: appearance, a theme per appearance, an accent and fonts. They compose: a\n * user who wants Nord with a violet accent and the system font should not need\n * someone to author that combination.\n *\n * ## Where the rules live\n *\n * The provider is wiring. What a selection merges to and resolves to is\n * `theme-state.ts`; what lands on `<html>` is `theme-document.ts`; where the\n * preference is kept is `theme-persistence.ts`.\n *\n * ## Why the variants are applied as inline properties\n *\n * The catalogue is data, and a theme is applied by writing its roles onto\n * `<html>` as custom properties. That is what makes an imported palette work\n * without a hand-written `[data-theme]` block per theme, and it is why a settings\n * UI can show a preview by reading the same object rather than by loading a\n * stylesheet. `theme.css` keeps the default theme's values so the first paint is\n * correct before any script runs.\n */\nexport type ThemeProviderProps = {\n children?: JSX.Element\n /** Where the preference is persisted. Distinct per application. */\n storageKey?: string\n /** Start from this instead of the stored preference. */\n initial?: Partial<ThemeSelection>\n /**\n * The selection, owned by the caller.\n *\n * For a consumer that keeps the state itself — a settings store, or a workshop\n * whose selection lives in Storybook globals — rather than handing it to this\n * provider's signal. Each change lands here and the document follows; nothing is\n * written to the store, because the caller is the one who persists. A picker\n * below the provider still works, and its change is the caller's to read back.\n *\n * Absent, the provider is the whole owner: it reads `storageKey` on mount,\n * seeds from `initial`, and persists every `setSelection`.\n */\n selection?: Partial<ThemeSelection>\n /**\n * Where the preference is kept, in place of `localStorage` under `storageKey`.\n *\n * Read once when the provider is created, so changing the prop later does not\n * move the store. `storageKey` is ignored when this is given.\n */\n persistence?: ThemePersistence\n /**\n * Variants the host adds to the built-in catalogue — themes a user imported.\n *\n * A function is read inside the provider's reactive scope, so one that reads a\n * signal keeps the picker and the document current when the set changes. A\n * stored id that names no variant, built in or added, paints the default of its\n * appearance and stays in the selection untouched.\n */\n themes?: readonly ThemeVariant[] | (() => readonly ThemeVariant[])\n /**\n * Rewrites the custom properties of each pass before they are written to\n * `<html>`: the variant's roles with the accent over them. `tokensAsHex` from\n * `lib/themes` is the one the system ships.\n */\n transformTokens?: (tokens: Record<string, string>) => Record<string, string>\n /**\n * Switch CSS transitions off for the frame that carries a change, so a theme\n * switch cannot animate the whole page. Off by default: it adds a `<style>`\n * element to `<head>` for two frames on every change.\n */\n disableTransitionOnChange?: boolean\n /**\n * The contrast ratio an accent is held to against the variant's background,\n * repaired to the nearest passing colour when it falls short. Absent, presets\n * are painted verbatim — the catalogue measured them for its own themes — and\n * only a custom `#rrggbb` is held to 3:1. A host that adds themes the catalogue\n * never measured passes 3 to hold the presets to it as well; for the catalogue's\n * own themes the floor changes no preset.\n */\n accentContrastFloor?: number\n /**\n * Turns the surface axis on: `selection.surface` and `selection.reduceTransparency`\n * are resolved against the operating system's Reduce Transparency setting and the\n * host's capability, and `data-surface`, `data-reduce-transparency` and\n * `--surface-alpha` are written to `<html>` (the frost rule in `theme.css` reads\n * them). Off by default: a provider that never opts in writes none of them, adds no\n * media-query listener, and stores nothing new.\n *\n * An object also states the host's capability. `nativeTranslucency` is whether the\n * window can render the OS's own translucency; without it a `translucent`\n * preference paints the tokenized `frosted` surface instead of pretending to\n * vibrancy. A function is read inside the provider's reactive scope, for a\n * capability that is learned after mount.\n *\n * A selection that already carries a `surface` turns the axis on for itself, so a\n * host that stores the field gets the same document without the prop.\n */\n surface?: boolean | { nativeTranslucency?: boolean | (() => boolean) }\n /**\n * Where a catalogue variant's palette comes from. `inline` (the default) writes\n * every role onto `<html>`. `stylesheet` leaves a catalogue variant to the host's\n * `[data-theme]` stylesheet and writes inline only what no stylesheet can know: a\n * host's own `themes`, the accent, the pinned terminal palette, the surface alpha\n * and the fonts. Switching from a host variant back to a catalogue one removes the\n * properties the host variant wrote.\n */\n palette?: 'inline' | 'stylesheet'\n /**\n * The projection behind the `--editor-*` ramp. `syntax` (the default) is the\n * catalogue's quiet syntax roles, a comment among them deliberately below\n * body-text contrast. `floor` holds every role to 4.5:1 on the canvas, as\n * hex, for a host that renders code as content (a diff, a file view) rather than\n * as decoration.\n *\n * Applies to catalogue variants; a host's own `themes` keep their `editor` and\n * their `tokens`. With `palette=\"stylesheet\"` it is the one palette property a\n * catalogue variant still writes inline, because `theme-variants.css` is generated\n * for `syntax`. Absent, nothing changes.\n */\n editorRoles?: EditorRolesMode\n /**\n * Bind the platform zoom chords (Cmd or Ctrl with `=`, `+`, `-`, `0`) to the three\n * text sizes instead of the browser's page zoom: stepping them together is zoom\n * inside the persisted type system. Off by default: it adds a capturing `keydown`\n * listener to `window`, and an event already handled elsewhere is left alone.\n * `zoomFonts` on the context does the same from a menu or a host's own binding.\n */\n fontZoom?: boolean\n} & ThemeTokenProjectionOptions\n\n/**\n * Where the provider's catalogue questions are answered, and whether the whole\n * catalogue is available yet.\n *\n * The eager provider's source is the full catalogue and is always loaded. The lazy\n * provider's source starts on the default pair that ships with it and swaps to the\n * full catalogue when {@link ThemeCatalogueSource.load} resolves. Both read the same\n * way in the provider: `engine()` is reactive, so everything derived from it follows\n * the swap.\n */\nexport type ThemeCatalogueSource = {\n /** The engine answering catalogue questions now. Changes once, when loading completes. */\n engine: () => ThemeEngine\n /** True when `engine()` is the full catalogue. */\n loaded: () => boolean\n /** True when loading failed; the provider then paints what it can without the rest. */\n failed: () => boolean\n /** Start loading the full catalogue (idempotent). Resolves when `loaded()` is true. */\n load: () => Promise<void>\n}\n\n/** The operating system's Reduce Transparency query, where there is a window to ask. */\nfunction reducedTransparencyMedia(): MediaQueryList | undefined {\n return typeof window !== 'undefined' && typeof window.matchMedia === 'function'\n ? window.matchMedia(REDUCED_TRANSPARENCY_QUERY)\n : undefined\n}\n\n/**\n * The provider, parameterised by where its catalogue comes from: the eager\n * `ThemeProvider` passes the whole catalogue, the lazy one a source that loads it.\n * Nothing here imports catalogue code or data, which is what lets the lazy entry keep\n * them out of a consumer's start-up chunk.\n */\n\n/** Selections are small plain records built in one key order, so this is exact. */\nfunction sameThemeSelection(a: ThemeSelection, b: ThemeSelection) {\n return a === b || JSON.stringify(a) === JSON.stringify(b)\n}\n\nexport function ThemeProviderWith(\n props: ThemeProviderProps & { catalogue: ThemeCatalogueSource }\n): JSX.Element {\n const value = createThemeContextValue(props)\n return createComponent(themeContext().Provider, {\n value,\n get children() {\n return props.children\n },\n })\n}\n\n/**\n * Everything the provider is, as a value: the context object, with its effects and\n * listeners created in the caller's reactive scope.\n */\nexport function createThemeContextValue(\n props: ThemeProviderProps & { catalogue: ThemeCatalogueSource }\n): ThemeContextValue {\n assertThemeTokenProjectionConfig(props.tokenProjection)\n const [local] = splitProps(props, [\n 'catalogue',\n 'storageKey',\n 'initial',\n 'selection',\n 'persistence',\n 'themes',\n 'transformTokens',\n 'tokenProjection',\n 'disableTransitionOnChange',\n 'accentContrastFloor',\n 'surface',\n 'palette',\n 'editorRoles',\n 'fontZoom',\n ])\n const storageKey = () => local.storageKey ?? DEFAULT_THEME_STORAGE_KEY\n const persistence = local.persistence ?? localStoragePersistence(storageKey)\n\n // Read before the first resolution and before the store is, so a persistence whose\n // answer depends on the extras (an id it only accepts if the theme exists) sees\n // them.\n const extraThemes = createMemo(() =>\n typeof local.themes === 'function' ? local.themes() : (local.themes ?? [])\n )\n const source = () => local.catalogue\n const engine = () => source().engine()\n const registry = createMemo(() => mergeRegistry(engine().builtinThemes, extraThemes()))\n\n // A patch that changes nothing (pressing the current toggle again, a font step\n // that clamps) leaves the signal alone, so the document pass and the store write\n // that follow every change do not run for it.\n const [selection, setSelectionState] = createSignal<ThemeSelection>(\n initialThemeSelection(readPersisted(persistence), local.initial),\n { equals: sameThemeSelection }\n )\n\n // The controlled half of the contract. A patch from the owner replaces the\n // matching axes; the stored preference is untouched, since the owner is the one\n // that persists. Reading `local.selection` — a prop getter, not a destructured\n // value — is what keeps this subscribed for the provider's lifetime.\n createEffect(() => {\n const incoming = local.selection\n if (incoming) setSelectionState((current) => mergeThemeSelection(current, incoming))\n })\n\n const [systemAppearance, setSystemAppearance] = createSignal<ThemeAppearance>('light')\n\n if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {\n const query = window.matchMedia('(prefers-color-scheme: dark)')\n setSystemAppearance(query.matches ? 'dark' : 'light')\n const onChange = (event: MediaQueryListEvent) =>\n setSystemAppearance(event.matches ? 'dark' : 'light')\n query.addEventListener('change', onChange)\n onCleanup(() => query.removeEventListener('change', onChange))\n }\n\n // What the stored preference resolves to. `selection()`, `variant()` and\n // `resolvedAppearance()` answer from this and never from a preview, so a picker\n // that previews a draft still reads back what is committed.\n const committed = createMemo(() => resolveThemeState(selection(), systemAppearance(), registry()))\n const resolvedAppearance = createMemo<ThemeAppearance>(() => committed().appearance)\n const variant = createMemo<ThemeVariant>(() => committed().variant)\n\n const [draft, setDraft] = createSignal<Partial<ThemeSelection> | undefined>()\n const shownSelection = createMemo(() => {\n const preview = draft()\n return preview ? mergeThemeSelection(selection(), preview) : selection()\n })\n const shown = createMemo(() =>\n draft() ? resolveThemeState(shownSelection(), systemAppearance(), registry()) : committed()\n )\n const shownAppearance = createMemo<ThemeAppearance>(() => shown().appearance)\n\n // The surface axis. Off, none of this reads the operating system: the media query\n // is subscribed only while the axis is on, so a provider that never opts in adds no\n // listener and no repaint.\n const surfaceOn = (candidate: ThemeSelection) =>\n local.surface === true || typeof local.surface === 'object' || candidate.surface !== undefined\n const nativeTranslucency = () => {\n const capability = typeof local.surface === 'object' ? local.surface.nativeTranslucency : false\n return (typeof capability === 'function' ? capability() : capability) === true\n }\n const [osReducedTransparency, setOsReducedTransparency] = createSignal(\n surfaceOn(untrack(shownSelection)) ? (reducedTransparencyMedia()?.matches ?? false) : false\n )\n const axisOn = createMemo(() => surfaceOn(shownSelection()))\n createEffect(() => {\n const query = axisOn() ? reducedTransparencyMedia() : undefined\n setOsReducedTransparency(query?.matches ?? false)\n if (!query) return\n const onChange = (event: MediaQueryListEvent) => setOsReducedTransparency(event.matches)\n query.addEventListener('change', onChange)\n onCleanup(() => query.removeEventListener('change', onChange))\n })\n const surfaceStateOf = (candidate: ThemeSelection) =>\n resolveSurfaceState(candidate.surface, {\n osReducedTransparency: osReducedTransparency(),\n userReducedTransparency: candidate.reduceTransparency === true,\n nativeTranslucency: nativeTranslucency(),\n })\n const committedSurface = createMemo(() =>\n surfaceOn(selection()) ? surfaceStateOf(selection()) : undefined\n )\n\n // A selection that names a catalogue theme beyond the shipped default pair cannot be\n // painted or previewed until the whole catalogue has loaded. Once a load has failed\n // the provider paints what the shipped data can.\n const waitingFor = (candidate: ThemeSelection, appearance: ThemeAppearance) =>\n !source().loaded() && !source().failed() && needsCatalogue(candidate, appearance)\n createEffect(() => {\n if (\n needsCatalogue(selection(), committed().appearance) ||\n needsCatalogue(shownSelection(), shown().appearance)\n )\n void source().load()\n })\n\n let written: ReadonlySet<string> | undefined\n let restoreTransitions: (() => void) | undefined\n createEffect(() => {\n if (typeof document === 'undefined') return\n const current = engine()\n const display = shown()\n // Until the catalogue arrives the document keeps what is already on it — the\n // stylesheet's theme, set before first paint by `themeScript` — instead of\n // flashing the default for a theme that is only not loaded yet.\n if (waitingFor(shownSelection(), display.appearance)) return\n const state = {\n selection: shownSelection(),\n appearance: display.appearance,\n variant: display.variant,\n terminalVariant: resolveTerminalVariant(shownSelection().terminalThemeId, registry()),\n codeVariant: resolveCodeVariant(shownSelection().codeThemeId, registry()),\n surface: axisOn() ? surfaceStateOf(shownSelection()) : undefined,\n }\n const projectionOptions = local.tokenProjection\n ? { tokenProjection: local.tokenProjection }\n : {}\n const options = {\n transformTokens: local.transformTokens,\n ...projectionOptions,\n accentContrastFloor: local.accentContrastFloor,\n palette: local.palette,\n editorRoles: local.editorRoles,\n }\n const apply = () => {\n written = applyThemeToRoot(current, document.documentElement, state, options, written)\n }\n if (local.disableTransitionOnChange) {\n restoreTransitions?.()\n restoreTransitions = applyWithoutTransitions(document, apply)\n } else {\n apply()\n }\n })\n onCleanup(() => restoreTransitions?.())\n\n // A pair beyond the defaults offers its accents once the catalogue is here; reading\n // them is not a reason to load it.\n const lightThemeId = createMemo(() => selection().lightThemeId)\n const darkThemeId = createMemo(() => selection().darkThemeId)\n const themeAccents = createMemo(() => {\n const pair = { lightThemeId: lightThemeId(), darkThemeId: darkThemeId() }\n return !source().loaded() && pairNeedsData(pair)\n ? []\n : engine().themeAccentsFor(pair.lightThemeId, pair.darkThemeId)\n })\n\n const zoomFonts = (intent: FontZoomIntent) =>\n value.setSelection({ fonts: zoomedFontSettings(selection(), intent) })\n\n // The platform zoom chords drive the three text sizes, captured like the other\n // global chords; an event something else already handled never double-steps.\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.defaultPrevented) return\n const intent = fontZoomShortcut(event)\n if (!intent) return\n event.preventDefault()\n zoomFonts(intent)\n }\n createEffect(() => {\n if (!local.fontZoom || typeof window === 'undefined') return\n window.addEventListener('keydown', onKeyDown, { capture: true })\n onCleanup(() => window.removeEventListener('keydown', onKeyDown, { capture: true }))\n })\n\n const value: ThemeContextValue = {\n selection,\n resolvedAppearance,\n shownAppearance,\n variant,\n get themes() {\n return engine().builtinThemes\n },\n themeAccents,\n allThemes: registry,\n preview(next) {\n setDraft(next ? { ...next } : undefined)\n },\n previewing: () => draft() !== undefined,\n accentRolesFor(accent, variantId) {\n // Before the catalogue arrives the light engine answers provisionally and asks\n // for it; reading `engine()` re-runs a reactive caller on arrival.\n return accentRolesForState(engine(), accent, variantId, {\n selection: selection(),\n variant: variant(),\n registry: registry(),\n accentContrastFloor: local.accentContrastFloor,\n })\n },\n catalogueReady: () => source().loaded(),\n loadCatalogue: () => source().load(),\n effectiveSurface: () => committedSurface()?.surface ?? 'opaque',\n reduceTransparencyActive: () => committedSurface()?.reduceTransparencyActive ?? false,\n zoomFonts,\n setSelection(patch) {\n const current = selection()\n const next = mergeThemeSelection(current, patch)\n setDraft(undefined)\n if (sameThemeSelection(current, next)) return\n setSelectionState(next)\n writePersisted(persistence, next)\n },\n }\n\n return value\n}\n"],"mappings":";;;;;;;;;;;;AA+LA,SAAS,2BAAuD;CAC9D,OAAO,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe,aACjE,OAAO,WAAW,0BAA0B,IAC5C,KAAA;AACN;;;;;;;;AAUA,SAAS,mBAAmB,GAAmB,GAAmB;CAChE,OAAO,MAAM,KAAK,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;AAC1D;AAEA,SAAgB,kBACd,OACa;CACb,MAAM,QAAQ,wBAAwB,KAAK;CAC3C,OAAO,gBAAgB,aAAa,CAAC,CAAC,UAAU;EAC9C;EACA,IAAI,WAAW;GACb,OAAO,MAAM;EACf;CACF,CAAC;AACH;;;;;AAMA,SAAgB,wBACd,OACmB;CACnB,iCAAiC,MAAM,eAAe;CACtD,MAAM,CAAC,SAAS,WAAW,OAAO;EAChC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,MAAM,mBAAmB,MAAM,cAAA;CAC/B,MAAM,cAAc,MAAM,eAAe,wBAAwB,UAAU;CAK3E,MAAM,cAAc,iBAClB,OAAO,MAAM,WAAW,aAAa,MAAM,OAAO,IAAK,MAAM,UAAU,CAAC,CAC1E;CACA,MAAM,eAAe,MAAM;CAC3B,MAAM,eAAe,OAAO,CAAC,CAAC,OAAO;CACrC,MAAM,WAAW,iBAAiB,cAAc,OAAO,CAAC,CAAC,eAAe,YAAY,CAAC,CAAC;CAKtF,MAAM,CAAC,WAAW,qBAAqB,aACrC,sBAAsB,cAAc,WAAW,GAAG,MAAM,OAAO,GAC/D,EAAE,QAAQ,mBAAmB,CAC/B;CAMA,mBAAmB;EACjB,MAAM,WAAW,MAAM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I,SAAS;GACX,OAAO,OAAO,CAAC,CAAC;EAClB;EACA;EACA,WAAW;EACX,QAAQ,MAAM;GACZ,SAAS,OAAO,EAAE,GAAG,KAAK,IAAI,KAAA,CAAS;EACzC;EACA,kBAAkB,MAAM,MAAM,KAAA;EAC9B,eAAe,QAAQ,WAAW;GAGhC,OAAO,oBAAoB,OAAO,GAAG,QAAQ,WAAW;IACtD,WAAW,UAAU;IACrB,SAAS,QAAQ;IACjB,UAAU,SAAS;IACnB,qBAAqB,MAAM;GAC7B,CAAC;EACH;EACA,sBAAsB,OAAO,CAAC,CAAC,OAAO;EACtC,qBAAqB,OAAO,CAAC,CAAC,KAAK;EACnC,wBAAwB,iBAAiB,CAAC,EAAE,WAAW;EACvD,gCAAgC,iBAAiB,CAAC,EAAE,4BAA4B;EAChF;EACA,aAAa,OAAO;GAClB,MAAM,UAAU,UAAU;GAC1B,MAAM,OAAO,oBAAoB,SAAS,KAAK;GAC/C,SAAS,KAAA,CAAS;GAClB,IAAI,mBAAmB,SAAS,IAAI,GAAG;GACvC,kBAAkB,IAAI;GACtB,eAAe,aAAa,IAAI;EAClC;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/button/button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAC9E,OAAO,
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/button/button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAC9E,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAwC,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AAGvF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc;;;;8EA6D1B,CAAA;AAED,KAAK,kBAAkB,GAAG,YAAY,CAAC,OAAO,cAAc,CAAC,CAAA;AAE7D,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,cAAc,GAAG,QAAQ,IAAI,gBAAgB,CAC7E,CAAC,EACD,kBAAkB,GAAG;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CACF,CAAA;AAED,wBAAgB,MAAM,CAAC,CAAC,SAAS,cAAc,GAAG,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,kCAwDhF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { controlInteractive, controlSize, cva } from "../../../lib/variants.js";
|
|
2
2
|
import { cn } from "../../../lib/utils.js";
|
|
3
|
-
import { createComponent, isServer, mergeProps, spread } from "solid-js/web";
|
|
4
|
-
import { Show, mergeProps as mergeProps$1, splitProps } from "solid-js";
|
|
3
|
+
import { createComponent, isServer, memo, mergeProps, spread } from "solid-js/web";
|
|
4
|
+
import { Show, mergeProps as mergeProps$1, sharedConfig, splitProps } from "solid-js";
|
|
5
5
|
import { Polymorphic } from "@kobalte/core/polymorphic";
|
|
6
6
|
// src/components/ui/button/button.tsx
|
|
7
7
|
/**
|
|
@@ -95,7 +95,7 @@ function Button(props) {
|
|
|
95
95
|
};
|
|
96
96
|
return createComponent(Show, {
|
|
97
97
|
get when() {
|
|
98
|
-
return !isServer && (local.as === void 0 || local.as === "button");
|
|
98
|
+
return memo(() => !!(!isServer && !sharedConfig.context))() && (local.as === void 0 || local.as === "button");
|
|
99
99
|
},
|
|
100
100
|
get fallback() {
|
|
101
101
|
return createComponent(Polymorphic, mergeProps({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","names":["Polymorphic","mergeProps","Show","splitProps","isServer","spread","cva","controlInteractive","controlSize","cn","buttonVariants","variants","variant","default","secondary","destructive","outline","ghost","toolbar","subtle","success","link","size","xs","sm","md","lg","xl","touchTarget","comfortable","defaultVariants","class","Button","props","local","rest","as","className","native","element","document","createElement","type","_$createComponent","when","undefined","fallback","_$mergeProps","children"],"sources":["../../../../src/components/ui/button/button.tsx"],"sourcesContent":["import { Polymorphic, type PolymorphicProps } from '@kobalte/core/polymorphic'\nimport {
|
|
1
|
+
{"version":3,"file":"button.js","names":["Polymorphic","mergeProps","sharedConfig","Show","splitProps","isServer","spread","cva","controlInteractive","controlSize","cn","buttonVariants","variants","variant","default","secondary","destructive","outline","ghost","toolbar","subtle","success","link","size","xs","sm","md","lg","xl","touchTarget","comfortable","defaultVariants","class","Button","props","local","rest","as","className","native","element","document","createElement","type","_$createComponent","when","_$memo","context","undefined","fallback","_$mergeProps","children"],"sources":["../../../../src/components/ui/button/button.tsx"],"sourcesContent":["import { Polymorphic, type PolymorphicProps } from '@kobalte/core/polymorphic'\nimport {\n type ComponentProps,\n mergeProps,\n sharedConfig,\n Show,\n splitProps,\n type ValidComponent,\n} from 'solid-js'\nimport { isServer, spread } from 'solid-js/web'\nimport { cva, controlInteractive, controlSize, type VariantProps } from '#lib/variants'\nimport { cn } from '#lib/utils'\n\n/**\n * Button.\n *\n * One appearance ladder shared by every pressable thing in the system: a\n * button, a toolbar control, a dialog action, and a menu row all draw from the\n * same tokens, so a row of them cannot drift apart.\n *\n * The variants answer \"what is this for\", never \"what colour is it\". A caller\n * that wants a red button writes `variant=\"destructive\"`; the red lives here.\n * That is also what lets the design-system linter tell a caller which variant\n * to use instead of only which class was wrong.\n *\n * Polymorphic: pass `as=\"a\"` (or any component) and the button becomes it\n * while keeping the same styling contract. This replaces the React-era\n * `asChild` primitive, which has no Solid equivalent that preserves props.\n */\nexport const buttonVariants = cva(\n `${controlInteractive} inline-flex shrink-0 items-center justify-center rounded-md font-medium whitespace-nowrap select-none [&_svg]:pointer-events-none [&_svg]:shrink-0`,\n {\n variants: {\n variant: {\n /** The one primary action in a view. */\n default: 'bg-primary text-primary-foreground hover:bg-primary-hover',\n secondary: 'bg-secondary text-secondary-foreground hover:bg-surface-hover',\n /** For the action that destroys something. Never the default. */\n destructive:\n 'bg-destructive-action text-destructive-action-foreground hover:bg-destructive-action/90 focus-visible:ring-destructive-subtle',\n /** A bordered button for a surface that already has a fill. */\n outline:\n 'border border-border bg-transparent text-foreground hover:bg-surface-hover hover:border-input',\n /** No chrome until hover. The default for toolbar and row actions. */\n ghost: 'text-foreground hover:bg-surface-hover',\n /**\n * A ghost that opens something: a sheet, menu or popover trigger in a\n * toolbar. While its surface is open it holds the accent's own tint,\n * the same treatment that drives the side rail's active destination,\n * so the open control never reads identical to its closed neighbours\n * and the app's pressed chrome reads as one accent chroma. The\n * compound hover keeps the tint when an open control is pointed at.\n */\n toolbar:\n 'text-foreground hover:bg-surface-hover data-[expanded]:bg-primary-subtle data-[expanded]:text-primary data-[expanded]:hover:bg-primary-subtle',\n /** A tinted primary, for a secondary action inside a primary flow. */\n subtle: 'bg-primary-subtle text-primary hover:bg-primary-subtle/80',\n success: 'bg-success text-success-foreground hover:bg-success/90',\n link: 'text-primary underline-offset-4 hover:underline',\n },\n size: {\n '2xs': `${controlSize['2xs']} [&_svg]:size-3`,\n xs: `${controlSize.xs} [&_svg]:size-3.5`,\n sm: `${controlSize.sm} [&_svg]:size-3.5`,\n md: `${controlSize.md} [&_svg]:size-4`,\n lg: `${controlSize.lg} [&_svg]:size-4`,\n xl: `${controlSize.xl} [&_svg]:size-5`,\n '2xl': `${controlSize['2xl']} [&_svg]:size-6`,\n /* Square, for an icon with no label. The accessible name then has to\n come from `aria-label` or a visually hidden label — an icon-only\n button with neither is the accessibility finding the Storybook lane\n catches on every story. */\n 'icon-2xs': 'size-control-2xs p-0 [&_svg]:size-3',\n 'icon-xs': 'size-control-xs p-0 [&_svg]:size-3.5',\n 'icon-sm': 'size-control-sm p-0 [&_svg]:size-3.5',\n 'icon-md': 'size-control-md p-0 [&_svg]:size-4',\n 'icon-lg': 'size-control-lg p-0 [&_svg]:size-4',\n 'icon-xl': 'size-control-xl p-0 [&_svg]:size-5',\n 'icon-2xl': 'size-control-2xl p-0 [&_svg]:size-6',\n },\n /** Opt in to a stable touch target on devices with any coarse pointer. */\n touchTarget: {\n comfortable: 'touch-target-comfortable',\n },\n },\n defaultVariants: {\n variant: 'default',\n size: 'md',\n },\n }\n)\n\ntype ButtonVariantProps = VariantProps<typeof buttonVariants>\n\nexport type ButtonProps<T extends ValidComponent = 'button'> = PolymorphicProps<\n T,\n ButtonVariantProps & {\n class?: string\n }\n>\n\nexport function Button<T extends ValidComponent = 'button'>(props: ButtonProps<T>) {\n const [local, rest] = splitProps(props as ButtonProps & { as?: ValidComponent }, [\n 'as',\n 'variant',\n 'size',\n 'touchTarget',\n 'class',\n ])\n const className = () =>\n cn(\n buttonVariants({\n variant: local.variant,\n size: local.size,\n touchTarget: local.touchTarget,\n }),\n local.class\n )\n\n // A native button, the common case, is written directly: Polymorphic goes\n // through Dynamic, two prop proxies and a memo per button. It is built with\n // createElement and spread, which is what the compiled JSX would do, so the\n // module holds no template: `buttonVariants` stays importable in plain Node\n // (a server renderer reads the class contract from this entry). A server\n // render has no document, so it takes the Polymorphic path. So does a button\n // the client hydrates: a fresh element would not adopt the server's node, and\n // its children would look for server nodes that were never claimed.\n const native = () => {\n const element = document.createElement('button')\n spread(\n element,\n mergeProps({ type: 'button', 'data-slot': 'button' }, rest as ComponentProps<'button'>, {\n get class() {\n return className()\n },\n }),\n false,\n false\n )\n return element\n }\n return (\n <Show\n when={!isServer && !sharedConfig.context && (local.as === undefined || local.as === 'button')}\n fallback={\n <Polymorphic\n as={local.as ?? 'button'}\n type=\"button\"\n data-slot=\"button\"\n class={className()}\n {...(rest as ComponentProps<'button'>)}\n />\n }\n >\n {native()}\n </Show>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAaW,iBAAiBJ,IAC5B,GAAGC,mBAAkB,sJACrB;CACEI,UAAU;EACRC,SAAS;;GAEPC,SAAS;GACTC,WAAW;;GAEXC,aACE;;GAEFC,SACE;;GAEFC,OAAO;;;;;;;;;GASPC,SACE;;G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MAAI;IAAA,aAAA;IAAA,KAAA,WAAA;KAAA,OAEGL,UAAU;IAAC;GAAA,GACbF,IAAgC,CAAA;EAAA;EAAA,IAAAe,WAAA;GAAA,OAIxCZ,OAAO;EAAC;CAAA,CAAA;AAGf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/tooltip/tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAqB,MAAM,uBAAuB,CAAA;AACpF,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/tooltip/tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAqB,MAAM,uBAAuB,CAAA;AACpF,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAgD7D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B;aAC5B,QAAQ,CAAC,WAAW,GAAG,SAAS,CAAC;aACjC,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI;cACrC,CAAA;AAwFJ,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,CAAA;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAY1D;AAED,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,OAAO,cAAc,CAAC,CAAA;AAEpE,wBAAgB,OAAO,CAAC,KAAK,EAAE,gBAAgB,eAuJ9C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,cAAc,CAAC,OAAO,CAAC,eA0ClF;AAED,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,cAAc,CAAC,OAAO,CAAC,GAAG;IAChF;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;CACnB,CAAA;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eA4ExD"}
|
|
@@ -21,12 +21,6 @@ var tooltipDefaults = {
|
|
|
21
21
|
};
|
|
22
22
|
var TooltipTimingContext = createContext(tooltipDefaults);
|
|
23
23
|
/**
|
|
24
|
-
* How long after a pointer leaves a keyboard-focused trigger its close request
|
|
25
|
-
* still counts as the pointer's: Kobalte reports that close one `closeDelay`
|
|
26
|
-
* later, plus a frame of slack for the timer to fire.
|
|
27
|
-
*/
|
|
28
|
-
var POINTER_CLOSE_INTENT_SLACK_MS = 50;
|
|
29
|
-
/**
|
|
30
24
|
* The layer a tooltip sits in, when that layer closes on Escape.
|
|
31
25
|
*
|
|
32
26
|
* Kobalte stacks a tooltip's content as the top-most dismissable layer, and
|
|
@@ -124,19 +118,12 @@ function Tooltip$1(props) {
|
|
|
124
118
|
let closeIntent = false;
|
|
125
119
|
let ignoreDuplicateClose = false;
|
|
126
120
|
let onOpenChange;
|
|
127
|
-
let
|
|
128
|
-
let pointerCloseIntentTimeout;
|
|
121
|
+
let pointerClosePending = false;
|
|
129
122
|
const clearPointerCloseIntent = () => {
|
|
130
|
-
|
|
131
|
-
if (pointerCloseIntentTimeout) clearTimeout(pointerCloseIntentTimeout);
|
|
132
|
-
pointerCloseIntentTimeout = void 0;
|
|
123
|
+
pointerClosePending = false;
|
|
133
124
|
};
|
|
134
125
|
const markPointerCloseIntent = () => {
|
|
135
|
-
if (
|
|
136
|
-
clearPointerCloseIntent();
|
|
137
|
-
const intentWindow = (props.closeDelay ?? timing.closeDelay) + POINTER_CLOSE_INTENT_SLACK_MS;
|
|
138
|
-
pointerCloseIntentUntil = Date.now() + intentWindow;
|
|
139
|
-
pointerCloseIntentTimeout = setTimeout(clearPointerCloseIntent, intentWindow);
|
|
126
|
+
if (isOpen()) pointerClosePending = true;
|
|
140
127
|
};
|
|
141
128
|
const markCloseIntent = () => {
|
|
142
129
|
closeIntent = true;
|
|
@@ -186,8 +173,7 @@ function Tooltip$1(props) {
|
|
|
186
173
|
setTooltipInteractionOpen(interaction, true);
|
|
187
174
|
} else {
|
|
188
175
|
const focusedTrigger = interaction.isTriggerFocused();
|
|
189
|
-
|
|
190
|
-
if (source !== "handoff" && focusedTrigger && Date.now() <= pointerCloseIntentUntil && !closeIntent && !anotherTooltipOpening) {
|
|
176
|
+
if (source !== "handoff" && focusedTrigger && pointerClosePending && !closeIntent && !(pendingTooltipOpenId !== void 0 && pendingTooltipOpenId !== id)) {
|
|
191
177
|
clearPointerCloseIntent();
|
|
192
178
|
return;
|
|
193
179
|
}
|