@gemologic/sheen 0.1.0-rc.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.
Files changed (271) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +32 -0
  3. package/dist/core.d.ts +52 -0
  4. package/dist/core.js +29 -0
  5. package/dist/formisch.d.ts +5 -0
  6. package/dist/formisch.js +22 -0
  7. package/dist/forms.d.ts +34 -0
  8. package/dist/forms.js +18 -0
  9. package/dist/index.d.ts +144 -0
  10. package/dist/index.js +75 -0
  11. package/dist/layout/Layout.d.ts +28 -0
  12. package/dist/layout/Layout.js +121 -0
  13. package/dist/metadata.d.ts +46 -0
  14. package/dist/metadata.js +47 -0
  15. package/dist/navigation.d.ts +30 -0
  16. package/dist/navigation.js +16 -0
  17. package/dist/overlays.d.ts +28 -0
  18. package/dist/overlays.js +15 -0
  19. package/dist/primitives/Accordion.d.ts +16 -0
  20. package/dist/primitives/Accordion.js +223 -0
  21. package/dist/primitives/ActivityTimeline.d.ts +20 -0
  22. package/dist/primitives/ActivityTimeline.js +104 -0
  23. package/dist/primitives/AlertDialog.d.ts +7 -0
  24. package/dist/primitives/AlertDialog.js +8 -0
  25. package/dist/primitives/Avatar.d.ts +22 -0
  26. package/dist/primitives/Avatar.js +115 -0
  27. package/dist/primitives/Breadcrumb.d.ts +11 -0
  28. package/dist/primitives/Breadcrumb.js +66 -0
  29. package/dist/primitives/Button.d.ts +11 -0
  30. package/dist/primitives/Button.js +59 -0
  31. package/dist/primitives/ButtonGroup.d.ts +7 -0
  32. package/dist/primitives/ButtonGroup.js +33 -0
  33. package/dist/primitives/Checkbox.d.ts +22 -0
  34. package/dist/primitives/Checkbox.js +93 -0
  35. package/dist/primitives/CheckboxGroup.d.ts +18 -0
  36. package/dist/primitives/CheckboxGroup.js +122 -0
  37. package/dist/primitives/Collapsible.d.ts +9 -0
  38. package/dist/primitives/Collapsible.js +72 -0
  39. package/dist/primitives/Combobox.d.ts +41 -0
  40. package/dist/primitives/Combobox.js +684 -0
  41. package/dist/primitives/CommandPalette.d.ts +42 -0
  42. package/dist/primitives/CommandPalette.js +319 -0
  43. package/dist/primitives/ConfirmDialog.d.ts +11 -0
  44. package/dist/primitives/ConfirmDialog.js +42 -0
  45. package/dist/primitives/ContextMenu.d.ts +16 -0
  46. package/dist/primitives/ContextMenu.js +132 -0
  47. package/dist/primitives/DescriptionList.d.ts +11 -0
  48. package/dist/primitives/DescriptionList.js +44 -0
  49. package/dist/primitives/Dialog.d.ts +21 -0
  50. package/dist/primitives/Dialog.js +141 -0
  51. package/dist/primitives/Drawer.d.ts +9 -0
  52. package/dist/primitives/Drawer.js +21 -0
  53. package/dist/primitives/DropdownMenu.d.ts +59 -0
  54. package/dist/primitives/DropdownMenu.js +441 -0
  55. package/dist/primitives/EditableTextField.d.ts +11 -0
  56. package/dist/primitives/EditableTextField.js +126 -0
  57. package/dist/primitives/EmptyState.d.ts +7 -0
  58. package/dist/primitives/EmptyState.js +45 -0
  59. package/dist/primitives/Field.d.ts +18 -0
  60. package/dist/primitives/Field.js +72 -0
  61. package/dist/primitives/FileDropzone.d.ts +40 -0
  62. package/dist/primitives/FileDropzone.js +261 -0
  63. package/dist/primitives/IconButton.d.ts +8 -0
  64. package/dist/primitives/IconButton.js +34 -0
  65. package/dist/primitives/Input.d.ts +7 -0
  66. package/dist/primitives/Input.js +55 -0
  67. package/dist/primitives/InputGroup.d.ts +7 -0
  68. package/dist/primitives/InputGroup.js +73 -0
  69. package/dist/primitives/Link.d.ts +7 -0
  70. package/dist/primitives/Link.js +35 -0
  71. package/dist/primitives/LinkTooltip.d.ts +11 -0
  72. package/dist/primitives/LinkTooltip.js +88 -0
  73. package/dist/primitives/NavList.d.ts +17 -0
  74. package/dist/primitives/NavList.js +143 -0
  75. package/dist/primitives/Notice.d.ts +8 -0
  76. package/dist/primitives/Notice.js +64 -0
  77. package/dist/primitives/NumberField.d.ts +22 -0
  78. package/dist/primitives/NumberField.js +177 -0
  79. package/dist/primitives/Pagination.d.ts +12 -0
  80. package/dist/primitives/Pagination.js +127 -0
  81. package/dist/primitives/Popover.d.ts +12 -0
  82. package/dist/primitives/Popover.js +103 -0
  83. package/dist/primitives/Progress.d.ts +17 -0
  84. package/dist/primitives/Progress.js +98 -0
  85. package/dist/primitives/RadioGroup.d.ts +19 -0
  86. package/dist/primitives/RadioGroup.js +173 -0
  87. package/dist/primitives/Resizable.d.ts +36 -0
  88. package/dist/primitives/Resizable.js +196 -0
  89. package/dist/primitives/ScrollArea.d.ts +6 -0
  90. package/dist/primitives/ScrollArea.js +178 -0
  91. package/dist/primitives/SearchInput.d.ts +12 -0
  92. package/dist/primitives/SearchInput.js +89 -0
  93. package/dist/primitives/SegmentedControl.d.ts +25 -0
  94. package/dist/primitives/SegmentedControl.js +188 -0
  95. package/dist/primitives/Select.d.ts +24 -0
  96. package/dist/primitives/Select.js +320 -0
  97. package/dist/primitives/Separator.d.ts +6 -0
  98. package/dist/primitives/Separator.js +31 -0
  99. package/dist/primitives/ShortcutPending.d.ts +6 -0
  100. package/dist/primitives/ShortcutPending.js +40 -0
  101. package/dist/primitives/ShortcutProvider.d.ts +32 -0
  102. package/dist/primitives/ShortcutProvider.js +172 -0
  103. package/dist/primitives/ShortcutScope.d.ts +6 -0
  104. package/dist/primitives/ShortcutScope.js +29 -0
  105. package/dist/primitives/ShortcutSheet.d.ts +5 -0
  106. package/dist/primitives/ShortcutSheet.js +87 -0
  107. package/dist/primitives/Skeleton.d.ts +5 -0
  108. package/dist/primitives/Skeleton.js +23 -0
  109. package/dist/primitives/Slider.d.ts +35 -0
  110. package/dist/primitives/Slider.js +210 -0
  111. package/dist/primitives/Spinner.d.ts +7 -0
  112. package/dist/primitives/Spinner.js +44 -0
  113. package/dist/primitives/Status.d.ts +15 -0
  114. package/dist/primitives/Status.js +78 -0
  115. package/dist/primitives/Stepper.d.ts +32 -0
  116. package/dist/primitives/Stepper.js +147 -0
  117. package/dist/primitives/Surface.d.ts +11 -0
  118. package/dist/primitives/Surface.js +58 -0
  119. package/dist/primitives/Switch.d.ts +4 -0
  120. package/dist/primitives/Switch.js +7 -0
  121. package/dist/primitives/Table.d.ts +23 -0
  122. package/dist/primitives/Table.js +101 -0
  123. package/dist/primitives/Tabs.d.ts +17 -0
  124. package/dist/primitives/Tabs.js +157 -0
  125. package/dist/primitives/TagInput.d.ts +33 -0
  126. package/dist/primitives/TagInput.js +288 -0
  127. package/dist/primitives/Textarea.d.ts +8 -0
  128. package/dist/primitives/Textarea.js +106 -0
  129. package/dist/primitives/Toast.d.ts +10 -0
  130. package/dist/primitives/Toast.js +78 -0
  131. package/dist/primitives/Toaster.d.ts +9 -0
  132. package/dist/primitives/Toaster.js +183 -0
  133. package/dist/primitives/Tooltip.d.ts +13 -0
  134. package/dist/primitives/Tooltip.js +84 -0
  135. package/dist/primitives/Tree.d.ts +23 -0
  136. package/dist/primitives/Tree.js +275 -0
  137. package/dist/primitives/Typography.d.ts +16 -0
  138. package/dist/primitives/Typography.js +82 -0
  139. package/dist/primitives/boolean-input-state.d.ts +14 -0
  140. package/dist/primitives/boolean-input-state.js +39 -0
  141. package/dist/primitives/button-variants.d.ts +9 -0
  142. package/dist/primitives/button-variants.js +7 -0
  143. package/dist/primitives/choice-options.d.ts +7 -0
  144. package/dist/primitives/choice-options.js +35 -0
  145. package/dist/primitives/create-confirm.d.ts +15 -0
  146. package/dist/primitives/create-confirm.js +49 -0
  147. package/dist/primitives/create-toaster.d.ts +51 -0
  148. package/dist/primitives/create-toaster.js +87 -0
  149. package/dist/primitives/link-focus.d.ts +2 -0
  150. package/dist/primitives/link-focus.js +38 -0
  151. package/dist/primitives/menu-focus.d.ts +3 -0
  152. package/dist/primitives/menu-focus.js +32 -0
  153. package/dist/primitives/tooltip-layer.d.ts +14 -0
  154. package/dist/primitives/tooltip-layer.js +84 -0
  155. package/dist/theme/ThemeProvider.d.ts +59 -0
  156. package/dist/theme/ThemeProvider.js +239 -0
  157. package/dist/theme/intl.d.ts +6 -0
  158. package/dist/theme/intl.js +13 -0
  159. package/dist/theme/keyboard-script.d.ts +2 -0
  160. package/dist/theme/keyboard-script.js +6 -0
  161. package/dist/theme/layers.d.ts +7 -0
  162. package/dist/theme/layers.js +23 -0
  163. package/dist/theme/messages.d.ts +235 -0
  164. package/dist/theme/messages.js +115 -0
  165. package/dist/theme/script.d.ts +9 -0
  166. package/dist/theme/script.js +49 -0
  167. package/dist/theme/state.d.ts +27 -0
  168. package/dist/theme/state.js +55 -0
  169. package/dist/utils/browser-status.d.ts +5 -0
  170. package/dist/utils/browser-status.js +22 -0
  171. package/dist/utils/cn.d.ts +3 -0
  172. package/dist/utils/cn.js +7 -0
  173. package/dist/utils/optimistic.d.ts +6 -0
  174. package/dist/utils/optimistic.js +16 -0
  175. package/dist/utils/polymorphic.d.ts +1 -0
  176. package/dist/utils/shortcut-platform.d.ts +2 -0
  177. package/dist/utils/shortcut-platform.js +10 -0
  178. package/dist/utils/shortcut-registry.d.ts +61 -0
  179. package/dist/utils/shortcut-registry.js +186 -0
  180. package/package.json +100 -0
  181. package/src/core.ts +55 -0
  182. package/src/formisch.ts +28 -0
  183. package/src/forms.ts +34 -0
  184. package/src/index.ts +144 -0
  185. package/src/layout/Layout.tsx +43 -0
  186. package/src/metadata.d.ts +46 -0
  187. package/src/metadata.ts +66 -0
  188. package/src/navigation.ts +30 -0
  189. package/src/overlays.ts +28 -0
  190. package/src/primitives/Accordion.tsx +145 -0
  191. package/src/primitives/ActivityTimeline.tsx +72 -0
  192. package/src/primitives/AlertDialog.tsx +8 -0
  193. package/src/primitives/Avatar.tsx +85 -0
  194. package/src/primitives/Breadcrumb.tsx +41 -0
  195. package/src/primitives/Button.tsx +27 -0
  196. package/src/primitives/ButtonGroup.tsx +18 -0
  197. package/src/primitives/Checkbox.tsx +51 -0
  198. package/src/primitives/CheckboxGroup.tsx +73 -0
  199. package/src/primitives/Collapsible.tsx +43 -0
  200. package/src/primitives/Combobox.tsx +402 -0
  201. package/src/primitives/CommandPalette.tsx +234 -0
  202. package/src/primitives/ConfirmDialog.tsx +25 -0
  203. package/src/primitives/ContextMenu.tsx +100 -0
  204. package/src/primitives/DescriptionList.tsx +26 -0
  205. package/src/primitives/Dialog.tsx +81 -0
  206. package/src/primitives/Drawer.tsx +26 -0
  207. package/src/primitives/DropdownMenu.tsx +221 -0
  208. package/src/primitives/EditableTextField.tsx +91 -0
  209. package/src/primitives/EmptyState.tsx +21 -0
  210. package/src/primitives/Field.tsx +38 -0
  211. package/src/primitives/FileDropzone.tsx +189 -0
  212. package/src/primitives/IconButton.tsx +22 -0
  213. package/src/primitives/Input.tsx +17 -0
  214. package/src/primitives/InputGroup.tsx +23 -0
  215. package/src/primitives/Link.tsx +19 -0
  216. package/src/primitives/LinkTooltip.tsx +31 -0
  217. package/src/primitives/NavList.tsx +58 -0
  218. package/src/primitives/Notice.tsx +25 -0
  219. package/src/primitives/NumberField.tsx +168 -0
  220. package/src/primitives/Pagination.tsx +64 -0
  221. package/src/primitives/Popover.tsx +44 -0
  222. package/src/primitives/Progress.tsx +62 -0
  223. package/src/primitives/RadioGroup.tsx +104 -0
  224. package/src/primitives/Resizable.tsx +170 -0
  225. package/src/primitives/ScrollArea.tsx +115 -0
  226. package/src/primitives/SearchInput.tsx +98 -0
  227. package/src/primitives/SegmentedControl.tsx +140 -0
  228. package/src/primitives/Select.tsx +171 -0
  229. package/src/primitives/Separator.tsx +13 -0
  230. package/src/primitives/ShortcutPending.tsx +21 -0
  231. package/src/primitives/ShortcutProvider.tsx +179 -0
  232. package/src/primitives/ShortcutScope.tsx +17 -0
  233. package/src/primitives/ShortcutSheet.tsx +35 -0
  234. package/src/primitives/Skeleton.tsx +12 -0
  235. package/src/primitives/Slider.tsx +153 -0
  236. package/src/primitives/Spinner.tsx +19 -0
  237. package/src/primitives/Status.tsx +33 -0
  238. package/src/primitives/Stepper.tsx +106 -0
  239. package/src/primitives/Surface.tsx +21 -0
  240. package/src/primitives/Switch.tsx +9 -0
  241. package/src/primitives/Table.tsx +57 -0
  242. package/src/primitives/Tabs.tsx +96 -0
  243. package/src/primitives/TagInput.tsx +282 -0
  244. package/src/primitives/Textarea.tsx +77 -0
  245. package/src/primitives/Toast.tsx +36 -0
  246. package/src/primitives/Toaster.tsx +175 -0
  247. package/src/primitives/Tooltip.tsx +41 -0
  248. package/src/primitives/Tree.tsx +256 -0
  249. package/src/primitives/Typography.tsx +39 -0
  250. package/src/primitives/boolean-input-state.ts +65 -0
  251. package/src/primitives/button-variants.ts +20 -0
  252. package/src/primitives/choice-options.ts +39 -0
  253. package/src/primitives/create-confirm.tsx +56 -0
  254. package/src/primitives/create-toaster.ts +128 -0
  255. package/src/primitives/link-focus.ts +38 -0
  256. package/src/primitives/menu-focus.ts +43 -0
  257. package/src/primitives/tooltip-layer.tsx +53 -0
  258. package/src/styles.css +655 -0
  259. package/src/theme/ThemeProvider.tsx +215 -0
  260. package/src/theme/intl.ts +14 -0
  261. package/src/theme/keyboard-script.ts +4 -0
  262. package/src/theme/layers.ts +16 -0
  263. package/src/theme/messages.ts +157 -0
  264. package/src/theme/script.ts +70 -0
  265. package/src/theme/state.ts +48 -0
  266. package/src/utils/browser-status.ts +36 -0
  267. package/src/utils/cn.ts +5 -0
  268. package/src/utils/optimistic.ts +22 -0
  269. package/src/utils/polymorphic.ts +1 -0
  270. package/src/utils/shortcut-platform.ts +4 -0
  271. package/src/utils/shortcut-registry.ts +216 -0
@@ -0,0 +1,215 @@
1
+ import { createContext, createEffect, createMemo, createSignal, createUniqueId, onCleanup, onMount, useContext } from "solid-js";
2
+ import type { Accessor, JSX, ParentProps } from "solid-js";
3
+ import { I18nProvider } from "@kobalte/core/i18n";
4
+ import { bundledThemeMetadata, iconSetForTheme } from "@gemologic/sheen-tokens/catalog";
5
+ import type { ThemeMetadata } from "@gemologic/sheen-tokens/catalog";
6
+ import type { Mode } from "@gemologic/sheen-tokens";
7
+ import { defaultThemeState, readThemeState, resolveThemeState } from "./state.ts";
8
+ import type { ThemeOverrides, ThemeState } from "./state.ts";
9
+ import { createScopeScript } from "./script.ts";
10
+ import { createOverlayStack } from "./layers.ts";
11
+ import type { OverlayStack } from "./layers.ts";
12
+ import { englishMessages, resolveMessages } from "./messages.ts";
13
+ import type { Messages } from "./messages.ts";
14
+
15
+ interface ThemeRuntime {
16
+ state: Accessor<ThemeState>;
17
+ defaults: ThemeState;
18
+ resolvedMode: Accessor<Mode>;
19
+ ready: Accessor<boolean>;
20
+ portal: Accessor<HTMLElement | undefined>;
21
+ tokenTarget: Accessor<HTMLElement | undefined>;
22
+ themes: readonly ThemeMetadata[];
23
+ nonce: string | undefined;
24
+ layers: OverlayStack;
25
+ messages: Accessor<Messages>;
26
+ set: (next: Partial<ThemeState>) => Promise<void>;
27
+ }
28
+
29
+ export interface ThemeContextValue extends Omit<ThemeRuntime, "themes"> {
30
+ theme: Accessor<string>;
31
+ mode: Accessor<ThemeState["mode"]>;
32
+ accent: Accessor<ThemeState["accent"]>;
33
+ density: Accessor<ThemeState["density"]>;
34
+ radius: Accessor<ThemeState["radius"]>;
35
+ themes: Accessor<readonly ThemeMetadata[]>;
36
+ setTheme: (value: string) => Promise<void>;
37
+ setMode: (value: ThemeState["mode"]) => Promise<void>;
38
+ setAccent: (value: ThemeState["accent"]) => Promise<void>;
39
+ setDensity: (value: ThemeState["density"]) => Promise<void>;
40
+ setRadius: (value: ThemeState["radius"]) => Promise<void>;
41
+ }
42
+
43
+ function exposeTheme(runtime: ThemeRuntime): ThemeContextValue {
44
+ return {
45
+ ...runtime,
46
+ portal: () => runtime.ready() ? runtime.portal() : undefined,
47
+ tokenTarget: () => runtime.ready() ? runtime.tokenTarget() : undefined,
48
+ theme: () => runtime.state().theme,
49
+ mode: () => runtime.state().mode,
50
+ accent: () => runtime.state().accent,
51
+ density: () => runtime.state().density,
52
+ radius: () => runtime.state().radius,
53
+ themes: () => runtime.themes,
54
+ setTheme: theme => runtime.set({ theme }),
55
+ setMode: mode => runtime.set({ mode }),
56
+ setAccent: accent => runtime.set({ accent }),
57
+ setDensity: density => runtime.set({ density }),
58
+ setRadius: radius => runtime.set({ radius }),
59
+ };
60
+ }
61
+
62
+ const ThemeContext = createContext<ThemeContextValue>();
63
+
64
+ export function useTheme(): ThemeContextValue {
65
+ const context = useContext(ThemeContext);
66
+ if (!context) throw new Error("sheen components require a ThemeProvider");
67
+ return context;
68
+ }
69
+
70
+ function attributes(state: ThemeState, mode: Mode, themes: readonly ThemeMetadata[]): Record<string, string> {
71
+ return Object.fromEntries(Object.entries({ ...state, mode, "icon-set": iconSetForTheme(state.theme, themes) }).map(([name, value]) => [`data-sheen-${name}`, value]));
72
+ }
73
+
74
+ function PortalTarget(props: { kind: "root" | "scope"; state: ThemeState | undefined; mode: Mode; themes: readonly ThemeMetadata[]; ready?: boolean; ref: (element: HTMLDivElement) => void }): JSX.Element {
75
+ // Attribute spreads also reconcile children. Portal children belong to their overlay owners.
76
+ return <div ref={props.ref} data-sheen-portal={props.kind} data-sheen-ready={props.ready}
77
+ data-sheen-theme={props.state?.theme} data-sheen-mode={props.state ? props.mode : undefined}
78
+ data-sheen-icon-set={props.state ? iconSetForTheme(props.state.theme, props.themes) : undefined}
79
+ data-sheen-accent={props.state?.accent} data-sheen-density={props.state?.density}
80
+ data-sheen-radius={props.state?.radius} data-sheen-motion={props.state?.motion}
81
+ data-sheen-locale={props.state?.locale} data-sheen-direction={props.state?.direction} />;
82
+ }
83
+
84
+ function modeSignal(): Accessor<Mode> {
85
+ const [mode, setMode] = createSignal<Mode>("dark");
86
+ onMount(() => {
87
+ const query = matchMedia("(prefers-color-scheme: dark)");
88
+ const update = (): void => { setMode(query.matches ? "dark" : "light"); };
89
+ update(); query.addEventListener("change", update);
90
+ onCleanup(() => query.removeEventListener("change", update));
91
+ });
92
+ return mode;
93
+ }
94
+
95
+ export interface ThemeProviderProps extends ParentProps {
96
+ initialState?: ThemeState;
97
+ defaultMode?: ThemeState["mode"];
98
+ defaultTheme?: string;
99
+ defaultAccent?: ThemeState["accent"];
100
+ defaultDensity?: ThemeState["density"];
101
+ defaultRadius?: ThemeState["radius"];
102
+ defaultMotion?: ThemeState["motion"];
103
+ direction?: ThemeState["direction"];
104
+ locale?: string;
105
+ themes?: readonly ThemeMetadata[];
106
+ storageKey?: string;
107
+ hydration?: "client" | "cookie";
108
+ persist?: (state: ThemeState) => Promise<void>;
109
+ onPersistenceError?: (error: unknown) => void;
110
+ nonce?: string;
111
+ messages?: Partial<Messages>;
112
+ }
113
+
114
+ export function ThemeProvider(props: ThemeProviderProps): JSX.Element {
115
+ const themes = () => props.themes ?? bundledThemeMetadata;
116
+ const defaults: ThemeState = {
117
+ ...defaultThemeState,
118
+ theme: props.defaultTheme ?? defaultThemeState.theme, mode: props.defaultMode ?? "dark", accent: props.defaultAccent ?? "jade",
119
+ density: props.defaultDensity ?? "comfortable", radius: props.defaultRadius ?? "soft", motion: props.defaultMotion ?? "full",
120
+ direction: props.direction ?? "ltr", locale: props.locale ?? "en-US",
121
+ };
122
+ const [state, setState] = createSignal<ThemeState>(props.initialState ?? defaults);
123
+ const [ready, setReady] = createSignal(false);
124
+ const [portal, setPortal] = createSignal<HTMLElement>();
125
+ const system = modeSignal();
126
+ const mode = createMemo(() => state().mode === "system" ? system() : state().mode === "light" ? "light" : "dark");
127
+ let revision = 0;
128
+ function updateDocument(): void {
129
+ for (const [name, value] of Object.entries(attributes(state(), mode(), themes()))) document.documentElement.setAttribute(name, value);
130
+ document.documentElement.setAttribute("data-sheen-preference", state().mode);
131
+ document.documentElement.dir = state().direction;
132
+ document.documentElement.lang = state().locale;
133
+ }
134
+ onMount(() => {
135
+ if (props.hydration !== "cookie") {
136
+ const root = document.documentElement;
137
+ const snapshot = Object.fromEntries(Object.keys(defaults).map(name => [name, root.getAttribute(`data-sheen-${name}`)]));
138
+ setState(readThemeState({ ...snapshot, mode: root.getAttribute("data-sheen-preference") ?? snapshot.mode }, defaults, themes().map(theme => theme.id)));
139
+ }
140
+ setReady(true);
141
+ updateDocument();
142
+ });
143
+ createEffect(() => { if (ready()) updateDocument(); });
144
+ const context = exposeTheme({
145
+ state, defaults, resolvedMode: mode, ready, portal, tokenTarget: () => document.documentElement, themes: themes(), nonce: props.nonce, layers: createOverlayStack(),
146
+ messages: createMemo(() => resolveMessages(englishMessages, props.messages)),
147
+ async set(next) {
148
+ const candidate = readThemeState({ ...state(), ...next }, defaults, context.themes().map(theme => theme.id));
149
+ const token = ++revision;
150
+ if (props.hydration === "cookie") {
151
+ if (!props.persist) throw new Error("Cookie hydration requires an app persistence callback");
152
+ try { await props.persist(candidate); }
153
+ catch (error) { props.onPersistenceError?.(error); throw error; }
154
+ }
155
+ if (token !== revision) return;
156
+ setState(candidate); updateDocument();
157
+ if (props.hydration !== "cookie") {
158
+ try { localStorage.setItem(props.storageKey ?? "sheen", JSON.stringify(candidate)); }
159
+ catch (error) { props.onPersistenceError?.(error); }
160
+ }
161
+ },
162
+ });
163
+ return <ThemeContext.Provider value={context}><I18nProvider locale={state().locale} direction={state().direction}>
164
+ {props.children}
165
+ <PortalTarget kind="root" ready={ready()} ref={setPortal} state={ready() ? state() : undefined} mode={mode()} themes={themes()} />
166
+ </I18nProvider></ThemeContext.Provider>;
167
+ }
168
+
169
+ export interface ThemeScopeProps extends ParentProps, ThemeOverrides { controllable?: boolean; class?: string; messages?: Partial<Messages> }
170
+
171
+ export function ThemeScope(props: ThemeScopeProps): JSX.Element {
172
+ const parent = useTheme();
173
+ const [local, setLocal] = createSignal<Partial<ThemeState>>({});
174
+ const [portal, setPortal] = createSignal<HTMLElement>();
175
+ const state = createMemo(() => resolveThemeState(parent.state(), {
176
+ theme: props.theme ?? (props.theme === null ? null : parent.state().theme),
177
+ mode: props.mode ?? (props.mode === null ? null : parent.state().mode),
178
+ accent: props.accent ?? (props.accent === null ? null : parent.state().accent),
179
+ density: props.density ?? (props.density === null ? null : parent.state().density),
180
+ radius: props.radius ?? (props.radius === null ? null : parent.state().radius),
181
+ motion: props.motion ?? (props.motion === null ? null : parent.state().motion),
182
+ direction: props.direction ?? (props.direction === null ? null : parent.state().direction),
183
+ locale: props.locale ?? (props.locale === null ? null : parent.state().locale),
184
+ ...local(),
185
+ }, parent.defaults));
186
+ const system = modeSignal();
187
+ const mode = createMemo<Mode>(() => state().mode === "system" ? system() : state().mode === "light" ? "light" : "dark");
188
+ const themes = () => parent.themes();
189
+ const context = exposeTheme({ ...parent, themes: parent.themes(), state, portal, tokenTarget: () => portal()?.parentElement ?? undefined, resolvedMode: mode,
190
+ messages: createMemo(() => resolveMessages(parent.messages(), props.messages)),
191
+ async set(next) {
192
+ if (!props.controllable) throw new Error("ThemeScope setters require controllable=true");
193
+ setLocal(previous => ({ ...previous, ...next }));
194
+ } });
195
+ const id = createUniqueId();
196
+ const overrides = (): ThemeOverrides => {
197
+ const result: ThemeOverrides = {};
198
+ if (props.theme !== undefined) result.theme = props.theme;
199
+ if (props.mode !== undefined) result.mode = props.mode;
200
+ if (props.accent !== undefined) result.accent = props.accent;
201
+ if (props.density !== undefined) result.density = props.density;
202
+ if (props.radius !== undefined) result.radius = props.radius;
203
+ if (props.motion !== undefined) result.motion = props.motion;
204
+ if (props.direction !== undefined) result.direction = props.direction;
205
+ if (props.locale !== undefined) result.locale = props.locale;
206
+ return result;
207
+ };
208
+ return <ThemeContext.Provider value={context}><I18nProvider locale={state().locale} direction={state().direction}>
209
+ <section id={id} class={props.class} {...attributes(state(), mode(), themes())} dir={state().direction} lang={state().locale}>
210
+ {props.children}
211
+ <PortalTarget kind="scope" ref={setPortal} state={state()} mode={mode()} themes={themes()} />
212
+ <script nonce={parent.nonce} innerHTML={createScopeScript(overrides(), parent.defaults, themes())} />
213
+ </section>
214
+ </I18nProvider></ThemeContext.Provider>;
215
+ }
@@ -0,0 +1,14 @@
1
+ import { createMemo } from "solid-js";
2
+ import type { Accessor } from "solid-js";
3
+ import { useTheme } from "./ThemeProvider.tsx";
4
+
5
+ /** Construct once per locale change, then reuse in every cell of a numeric column. */
6
+ export function useNumberFormatter(options: Intl.NumberFormatOptions = {}): Accessor<Intl.NumberFormat> {
7
+ const theme = useTheme();
8
+ return createMemo(() => new Intl.NumberFormat(theme.state().locale, options));
9
+ }
10
+
11
+ export function useDateFormatter(options: Intl.DateTimeFormatOptions & { timeZone: string } = { timeZone: "UTC" }): Accessor<Intl.DateTimeFormat> {
12
+ const theme = useTheme();
13
+ return createMemo(() => new Intl.DateTimeFormat(theme.state().locale, options));
14
+ }
@@ -0,0 +1,4 @@
1
+ /** Install after Solid's hydration bootstrap, before any interactive markup. */
2
+ export function createKeyboardHydrationScript(): string {
3
+ return `(()=>{document.addEventListener("keydown",event=>{const target=event.target;if(!(target instanceof Element)||!target.matches("[data-sheen-select-trigger],[data-sheen-menu-trigger]")||event.ctrlKey||event.metaKey||event.altKey||event.isComposing)return;if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight"].includes(event.key)&&event.key.length!==1)return;if(event.key===" ")return;const hydration=window._$HY;if(!hydration?.events||hydration.completed.has(target)||!target.hasAttribute("data-hk"))return;event.preventDefault();hydration.events.push([target,event]);});})();`;
4
+ }
@@ -0,0 +1,16 @@
1
+ import { createSignal } from "solid-js";
2
+
3
+ export function createOverlayStack() {
4
+ const [layers, setLayers] = createSignal<readonly string[]>([]);
5
+ return {
6
+ register(id: string): () => void {
7
+ setLayers(current => current.includes(id) ? current : [...current, id]);
8
+ return () => { setLayers(current => current.filter(item => item !== id)); };
9
+ },
10
+ isTop(id: string): boolean { return layers().at(-1) === id; },
11
+ zIndex(id: string): number { return 100 + Math.max(0, layers().indexOf(id)) * 2; },
12
+ aboveAll(): number { return 100 + layers().length * 2; },
13
+ };
14
+ }
15
+
16
+ export type OverlayStack = ReturnType<typeof createOverlayStack>;
@@ -0,0 +1,157 @@
1
+ export const englishMessages = Object.freeze({
2
+ close: "Close", cancel: "Cancel", confirm: "Confirm", retry: "Retry", remove: "Remove", breadcrumb: "Breadcrumb",
3
+ loading: "Loading", notifications: "Notifications", noNotifications: "No notifications", unread: "Unread", markAllNotificationsRead: "Mark all read", noResults: "No results", empty: "Nothing here yet", selectOption: "Select an option",
4
+ avatarOverflow: "{count} more",
5
+ nextPage: "Next page", previousPage: "Previous page", firstPage: "First page", lastPage: "Last page",
6
+ pagination: "Pagination", pageLabel: "Page {page}", pageStatus: "Page {page} of {pages}", clearSearch: "Clear search",
7
+ statusBar: "Application status", connected: "Connected", connecting: "Connecting", disconnected: "Disconnected", degraded: "Degraded connection", unknownConnection: "Connection unknown", backgroundTasks: "Background tasks",
8
+ notFound: "Not found", serverError: "Something went wrong", permissionDenied: "Permission denied", retrying: "Retrying", retryFailed: "Retry failed. Try again.",
9
+ moreActions: "More actions", pendingShortcut: "Pending shortcut", shortcutHelp: "Keyboard shortcuts", shortcutGroup: "Application",
10
+ commandPalette: "Command palette", openCommandPalette: "Open command palette", searchCommands: "Search commands", commandResults: "Command results", recentCommands: "Recent", refreshingCommands: "Refreshing commands", commandSourceFailed: "Commands could not be refreshed.",
11
+ cycleThemeMode: "Cycle theme mode", toggleSidebar: "Toggle sidebar", sidebar: "Sidebar",
12
+ savedViews: "Saved views", selectView: "Select a saved view", viewName: "View name", saveView: "Save view", saveCurrentView: "Save current view", manageSavedViews: "Manage saved views", noSavedViews: "No saved views yet.", renameView: "Rename view", restoreView: "Restore view", deleteView: "Delete view", deleteSavedViewTitle: "Delete saved view?", deleteSavedViewDescription: "Delete {name}? This cannot be undone.", retryViewOperation: "Retry view operation",
13
+ settingsSections: "Settings sections", settingsSaveBar: "Settings save bar", saveChanges: "Save changes", savingChanges: "Saving changes", unsavedChanges: "Unsaved changes", saveFailed: "Save failed. Your changes were retained.",
14
+ editableUpdateFailed: "Update failed. Your draft was retained.",
15
+ tagValues: "Tags", tagAdded: "Added {value}", tagRemoved: "Removed {value}", tagMoved: "Moved {value}", tagDuplicate: "{value} is already added.", tagValidating: "Validating tag", tagValidationFailed: "Tag validation failed. Your draft was retained.", tagReorderInstructions: "Press Delete to remove. Hold Alt and press an arrow key, Home, or End to reorder.",
16
+ chooseFiles: "Choose files", dropFilesHere: "Drop files here", fileDropHint: "Drag files here or choose from this device.", selectedFiles: "Selected files", fileCountRejected: "Only {count} more files can be added.", fileTooLarge: "{name} exceeds the {size} limit.", fileTypeRejected: "{name} is not an accepted file type.", uploadProgress: "Upload progress for {name}",
17
+ workflowCompleted: "Completed", workflowCurrent: "Current", workflowUpcoming: "Upcoming", workflowError: "Error", stepperProgress: "{label} progress",
18
+ increaseValue: "Increase {label}", decreaseValue: "Decrease {label}", minimumValue: "Minimum {label}", maximumValue: "Maximum {label}",
19
+ expandTreeItem: "Expand {label}", collapseTreeItem: "Collapse {label}",
20
+ shortcutInventory: "All registered shortcuts. Availability depends on the active scope.", shortcutShadowed: "Replaced by a newer binding", shortcutDisabled: "Character shortcut disabled",
21
+ unsavedTitle: "Discard unsaved changes?", unsavedDescription: "Your unsaved changes will be lost if you leave this page.", discardChanges: "Discard changes", navigationFailed: "Navigation failed. Your changes have been retained.",
22
+ });
23
+
24
+ /** Optional message families supplied by packages layered on the UI provider. */
25
+ export interface ExtensionMessages {
26
+ readonly copyCode?: string;
27
+ readonly codeCopied?: string;
28
+ readonly codeCopyFailed?: string;
29
+ readonly wrapCode?: string;
30
+ readonly stopWrappingCode?: string;
31
+ readonly codeHighlightedLines?: string;
32
+ readonly viewerSearch?: string;
33
+ readonly viewerCopy?: string;
34
+ readonly viewerCopied?: string;
35
+ readonly viewerCopyFailed?: string;
36
+ readonly viewerMatches?: string;
37
+ readonly searchTable?: string;
38
+ readonly tableShortcuts?: string;
39
+ readonly refreshing?: string;
40
+ readonly previousResults?: string;
41
+ readonly clearFilters?: string;
42
+ readonly clearSearchAndFilters?: string;
43
+ readonly selectAll?: string;
44
+ readonly selectPage?: string;
45
+ readonly selectRow?: string;
46
+ readonly clearSelection?: string;
47
+ readonly selectionActions?: string;
48
+ readonly selectedCount?: string;
49
+ readonly cardView?: string;
50
+ readonly rowActions?: string;
51
+ readonly sort?: string;
52
+ readonly sortColumn?: string;
53
+ readonly sortedAscending?: string;
54
+ readonly sortedDescending?: string;
55
+ readonly notSorted?: string;
56
+ readonly sortPriority?: string;
57
+ readonly export?: string;
58
+ readonly exportCSV?: string;
59
+ readonly exportJSON?: string;
60
+ readonly preparingExport?: string;
61
+ readonly exportFailed?: string;
62
+ readonly retryExport?: string;
63
+ readonly downloadLastExport?: string;
64
+ readonly filters?: string;
65
+ readonly filterAdd?: string;
66
+ readonly filterColumns?: string;
67
+ readonly filterSearchColumns?: string;
68
+ readonly filterEdit?: string;
69
+ readonly filterRemove?: string;
70
+ readonly filterApply?: string;
71
+ readonly filterOperator?: string;
72
+ readonly filterValue?: string;
73
+ readonly filterMinimum?: string;
74
+ readonly filterMaximum?: string;
75
+ readonly filterDate?: string;
76
+ readonly filterStartDate?: string;
77
+ readonly filterEndDate?: string;
78
+ readonly filterValues?: string;
79
+ readonly filterCaseSensitive?: string;
80
+ readonly filterNegated?: string;
81
+ readonly filterInheritedNegation?: string;
82
+ readonly filterInvalid?: string;
83
+ readonly filterEquals?: string;
84
+ readonly filterContains?: string;
85
+ readonly filterStartsWith?: string;
86
+ readonly filterEndsWith?: string;
87
+ readonly filterLessThan?: string;
88
+ readonly filterAtMost?: string;
89
+ readonly filterGreaterThan?: string;
90
+ readonly filterAtLeast?: string;
91
+ readonly filterBetween?: string;
92
+ readonly filterIsEmpty?: string;
93
+ readonly filterIsAnyOf?: string;
94
+ readonly filterSummary?: string;
95
+ readonly filterNot?: string;
96
+ readonly filterInheritedNot?: string;
97
+ readonly queryBuilder?: string;
98
+ readonly queryGroup?: string;
99
+ readonly queryRule?: string;
100
+ readonly queryMatch?: string;
101
+ readonly queryMatchAll?: string;
102
+ readonly queryMatchAny?: string;
103
+ readonly queryColumn?: string;
104
+ readonly queryAddRule?: string;
105
+ readonly queryAddGroup?: string;
106
+ readonly queryNegate?: string;
107
+ readonly queryRemoveNegation?: string;
108
+ readonly queryRemove?: string;
109
+ readonly queryMoveBefore?: string;
110
+ readonly queryMoveAfter?: string;
111
+ readonly queryChanged?: string;
112
+ readonly groupMissing?: string;
113
+ readonly loadingChildren?: string;
114
+ readonly columns?: string;
115
+ readonly showColumn?: string;
116
+ readonly moveColumnStart?: string;
117
+ readonly moveColumnEnd?: string;
118
+ readonly pinColumn?: string;
119
+ readonly pinNone?: string;
120
+ readonly pinStart?: string;
121
+ readonly pinEnd?: string;
122
+ readonly autoFitColumn?: string;
123
+ readonly resetColumnWidth?: string;
124
+ readonly reorderColumn?: string;
125
+ readonly resizeColumn?: string;
126
+ readonly columnWidthPixels?: string;
127
+ readonly editCell?: string;
128
+ readonly cellValueRequired?: string;
129
+ readonly cellValueInvalid?: string;
130
+ readonly noValue?: string;
131
+ readonly cellUpdateFailed?: string;
132
+ readonly cellUpdateFailedDescription?: string;
133
+ readonly cellConflict?: string;
134
+ readonly tableControls?: string;
135
+ readonly resultCountOne?: string;
136
+ readonly resultCount?: string;
137
+ readonly expand?: string;
138
+ readonly collapse?: string;
139
+ readonly chartViewAsTable?: string;
140
+ readonly chartMissingValue?: string;
141
+ readonly chartTablePagination?: string;
142
+ readonly chartShowSeries?: string;
143
+ readonly chartHideSeries?: string;
144
+ readonly chartZoomControls?: string;
145
+ readonly chartZoomIn?: string;
146
+ readonly chartZoomOut?: string;
147
+ readonly chartResetZoom?: string;
148
+ readonly chartKeyboardInstructions?: string;
149
+ }
150
+
151
+ type CoreMessages = Readonly<Record<keyof typeof englishMessages, string>>;
152
+ export type Messages = CoreMessages & ExtensionMessages;
153
+
154
+ export function resolveMessages(parent: Messages, overrides: Partial<Messages> = {}): Messages {
155
+ for (const value of Object.values(overrides)) if (typeof value !== "string") throw new Error("Sheen message overrides must be strings");
156
+ return Object.freeze({ ...parent, ...overrides });
157
+ }
@@ -0,0 +1,70 @@
1
+ import { defaultThemeState, themeChoices } from "./state.ts";
2
+ import type { ThemeOverrides, ThemeState } from "./state.ts";
3
+ import { bundledThemeMetadata } from "@gemologic/sheen-tokens/catalog";
4
+ import type { ThemeMetadata } from "@gemologic/sheen-tokens/catalog";
5
+
6
+ interface ScriptConfig { defaults: ThemeState; storageKey: string; choices: Readonly<Record<string, readonly string[]>>; iconSets: Readonly<Record<string, ThemeMetadata["iconSet"]>> }
7
+
8
+ function bootstrap(config: ScriptConfig): void {
9
+ const state: Record<string, string> = { ...config.defaults };
10
+ try {
11
+ const saved: unknown = JSON.parse(localStorage.getItem(config.storageKey) ?? "null");
12
+ if (typeof saved === "object" && saved !== null) {
13
+ for (const [name, value] of Object.entries(saved)) {
14
+ if (typeof value !== "string") continue;
15
+ if (config.choices[name]?.includes(value)) state[name] = value;
16
+ if (name === "locale") {
17
+ try { if (Intl.getCanonicalLocales(value).length) state.locale = value; } catch { /* Use the configured locale for invalid input. */ }
18
+ }
19
+ }
20
+ }
21
+ } catch { /* Storage is optional; configured dark defaults remain usable. */ }
22
+ const root = document.documentElement;
23
+ for (const [name, value] of Object.entries(state)) {
24
+ const resolved = name === "mode" && value === "system" ? (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light") : value;
25
+ root.setAttribute(`data-sheen-${name}`, resolved);
26
+ }
27
+ root.setAttribute("data-sheen-preference", state.mode ?? "dark");
28
+ root.setAttribute("data-sheen-icon-set", config.iconSets[state.theme ?? ""] ?? "radix");
29
+ root.setAttribute("dir", state.direction ?? "ltr");
30
+ root.setAttribute("lang", state.locale ?? "en-US");
31
+ }
32
+
33
+ export function createThemeScript(options: { defaults?: ThemeState; storageKey?: string; themeIds?: readonly string[]; themes?: readonly ThemeMetadata[] } = {}): string {
34
+ const themes = options.themes ?? bundledThemeMetadata;
35
+ const themeIds = options.themeIds ?? themes.map(theme => theme.id);
36
+ const config: ScriptConfig = {
37
+ defaults: options.defaults ?? { ...defaultThemeState },
38
+ storageKey: options.storageKey ?? "sheen",
39
+ choices: { ...themeChoices, theme: themeIds },
40
+ iconSets: Object.fromEntries(themes.map(theme => [theme.id, theme.iconSet])),
41
+ };
42
+ const json = JSON.stringify(config).replaceAll("<", "\\u003c").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
43
+ return `(${bootstrap.toString()})(${json});`;
44
+ }
45
+
46
+ function bootstrapScope(overrides: ThemeOverrides, defaults: ThemeState, iconSets: Readonly<Record<string, ThemeMetadata["iconSet"]>>): void {
47
+ const scope = document.currentScript?.parentElement;
48
+ const parent = scope?.parentElement?.closest("[data-sheen-theme]");
49
+ if (!scope || !parent) return;
50
+ for (const [axis, fallback] of Object.entries(defaults)) {
51
+ const supplied: unknown = Object.getOwnPropertyDescriptor(overrides, axis)?.value;
52
+ let value = supplied === null ? fallback : typeof supplied === "string" ? supplied : parent.getAttribute(`data-sheen-${axis}`) ?? fallback;
53
+ if (axis === "mode" && value === "system") value = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
54
+ scope.setAttribute(`data-sheen-${axis}`, value);
55
+ const target = scope.querySelector(':scope > [data-sheen-portal="scope"]');
56
+ target?.setAttribute(`data-sheen-${axis}`, value);
57
+ }
58
+ scope.setAttribute("dir", scope.getAttribute("data-sheen-direction") ?? "ltr");
59
+ scope.setAttribute("lang", scope.getAttribute("data-sheen-locale") ?? "en-US");
60
+ const target = scope.querySelector(':scope > [data-sheen-portal="scope"]');
61
+ const iconSet = iconSets[scope.getAttribute("data-sheen-theme") ?? ""] ?? "radix";
62
+ scope.setAttribute("data-sheen-icon-set", iconSet);
63
+ target?.setAttribute("data-sheen-icon-set", iconSet);
64
+ }
65
+
66
+ export function createScopeScript(overrides: ThemeOverrides, defaults: ThemeState, themes: readonly ThemeMetadata[] = bundledThemeMetadata): string {
67
+ const encode = (value: unknown): string => JSON.stringify(value).replaceAll("<", "\\u003c").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
68
+ const iconSets = Object.fromEntries(themes.map(theme => [theme.id, theme.iconSet]));
69
+ return `(${bootstrapScope.toString()})(${encode(overrides)},${encode(defaults)},${encode(iconSets)});`;
70
+ }
@@ -0,0 +1,48 @@
1
+ import { accentNames, bundledThemeMetadata, isAccentName } from "@gemologic/sheen-tokens/catalog";
2
+ import type { AccentName } from "@gemologic/sheen-tokens/catalog";
3
+ import type { Mode } from "@gemologic/sheen-tokens";
4
+
5
+ export interface ThemeState {
6
+ theme: string;
7
+ mode: Mode | "system";
8
+ accent: AccentName;
9
+ density: "compact" | "comfortable" | "spacious";
10
+ radius: "sharp" | "soft" | "round";
11
+ motion: "full" | "reduced";
12
+ direction: "ltr" | "rtl";
13
+ locale: string;
14
+ }
15
+
16
+ export const defaultThemeState: Readonly<ThemeState> = Object.freeze({ theme: "obsidian", mode: "dark", accent: "jade", density: "comfortable", radius: "soft", motion: "full", direction: "ltr", locale: "en-US" });
17
+ export type ThemeOverrides = { [K in keyof ThemeState]?: ThemeState[K] | null };
18
+
19
+ export function resolveThemeState(parent: ThemeState, overrides: ThemeOverrides, defaults: ThemeState): ThemeState {
20
+ return {
21
+ theme: overrides.theme === null ? defaults.theme : overrides.theme ?? parent.theme,
22
+ mode: overrides.mode === null ? defaults.mode : overrides.mode ?? parent.mode,
23
+ accent: overrides.accent === null ? defaults.accent : overrides.accent ?? parent.accent,
24
+ density: overrides.density === null ? defaults.density : overrides.density ?? parent.density,
25
+ radius: overrides.radius === null ? defaults.radius : overrides.radius ?? parent.radius,
26
+ motion: overrides.motion === null ? defaults.motion : overrides.motion ?? parent.motion,
27
+ direction: overrides.direction === null ? defaults.direction : overrides.direction ?? parent.direction,
28
+ locale: overrides.locale === null ? defaults.locale : overrides.locale ?? parent.locale,
29
+ };
30
+ }
31
+
32
+ export function readThemeState(value: unknown, fallback: ThemeState, themeIds: readonly string[] = bundledThemeMetadata.map(theme => theme.id)): ThemeState {
33
+ if (typeof value !== "object" || value === null) return { ...fallback };
34
+ const result = { ...fallback };
35
+ if ("theme" in value && typeof value.theme === "string" && themeIds.includes(value.theme)) result.theme = value.theme;
36
+ if ("mode" in value && (value.mode === "dark" || value.mode === "light" || value.mode === "system")) result.mode = value.mode;
37
+ if ("accent" in value && typeof value.accent === "string" && isAccentName(value.accent)) result.accent = value.accent;
38
+ if ("density" in value && (value.density === "compact" || value.density === "comfortable" || value.density === "spacious")) result.density = value.density;
39
+ if ("radius" in value && (value.radius === "sharp" || value.radius === "soft" || value.radius === "round")) result.radius = value.radius;
40
+ if ("motion" in value && (value.motion === "full" || value.motion === "reduced")) result.motion = value.motion;
41
+ if ("direction" in value && (value.direction === "rtl" || value.direction === "ltr")) result.direction = value.direction;
42
+ if ("locale" in value && typeof value.locale === "string") {
43
+ try { if (Intl.getCanonicalLocales(value.locale).length) result.locale = value.locale; } catch { /* Invalid persisted locale uses the explicit fallback. */ }
44
+ }
45
+ return result;
46
+ }
47
+
48
+ export const themeChoices = Object.freeze({ theme: bundledThemeMetadata.map(theme => theme.id), mode: ["dark", "light", "system"], accent: accentNames, density: ["compact", "comfortable", "spacious"], radius: ["sharp", "soft", "round"], motion: ["full", "reduced"], direction: ["ltr", "rtl"] });
@@ -0,0 +1,36 @@
1
+ import { createSignal, onCleanup, onMount } from "solid-js";
2
+ import type { Accessor } from "solid-js";
3
+
4
+ /** Browser connectivity hint, not backend health. Undefined until client mount. */
5
+ export function useOnlineStatus(): Accessor<boolean | undefined> {
6
+ const [online, setOnline] = createSignal<boolean>();
7
+ onMount(() => {
8
+ const update = () => setOnline(window.navigator.onLine);
9
+ window.addEventListener("online", update);
10
+ window.addEventListener("offline", update);
11
+ update();
12
+ onCleanup(() => {
13
+ window.removeEventListener("online", update);
14
+ window.removeEventListener("offline", update);
15
+ });
16
+ });
17
+ return online;
18
+ }
19
+
20
+ /** Document focus, not merely an active element. Undefined until client mount. */
21
+ export function useIsWindowFocused(): Accessor<boolean | undefined> {
22
+ const [focused, setFocused] = createSignal<boolean>();
23
+ onMount(() => {
24
+ const update = () => setFocused(document.hasFocus());
25
+ window.addEventListener("focus", update);
26
+ window.addEventListener("blur", update);
27
+ document.addEventListener("visibilitychange", update);
28
+ update();
29
+ onCleanup(() => {
30
+ window.removeEventListener("focus", update);
31
+ window.removeEventListener("blur", update);
32
+ document.removeEventListener("visibilitychange", update);
33
+ });
34
+ });
35
+ return focused;
36
+ }
@@ -0,0 +1,5 @@
1
+ import { clsx } from "clsx";
2
+ import type { ClassValue } from "clsx";
3
+
4
+ /** Flattens conditional class values. Component styles live below consumer utilities in the cascade. */
5
+ export function cn(...values: ClassValue[]): string { return clsx(values); }
@@ -0,0 +1,22 @@
1
+ export type OptimisticRevert = () => void | Promise<void>;
2
+
3
+ /**
4
+ * Apply app-owned local state immediately and revert once if its commit fails.
5
+ * The app must make its inverse safe for concurrent edits; this helper owns no cache.
6
+ */
7
+ export async function optimistic<T>(
8
+ apply: () => OptimisticRevert,
9
+ commit: () => T | Promise<T>,
10
+ ): Promise<T> {
11
+ const revert = apply();
12
+ try {
13
+ return await commit();
14
+ } catch (commitError) {
15
+ try {
16
+ await revert();
17
+ } catch (revertError) {
18
+ throw new AggregateError([commitError, revertError], "Optimistic commit and rollback both failed", { cause: commitError });
19
+ }
20
+ throw commitError;
21
+ }
22
+ }
@@ -0,0 +1 @@
1
+ export type { PolymorphicProps as SheenPolymorphicProps } from "@kobalte/core/polymorphic";
@@ -0,0 +1,4 @@
1
+ /** Platform hints select keyboard conventions, never browser feature support. */
2
+ export function resolveShortcutPlatform(platform: string): "mac" | "other" {
3
+ return platform.startsWith("Mac") || ["iPhone", "iPad", "iPod"].includes(platform) ? "mac" : "other";
4
+ }