@openelement/ui 1.0.0-alpha.15 → 1.0.0-alpha.16

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.
@@ -0,0 +1,40 @@
1
+ //#region src/theme-contract.ts
2
+ /** The localStorage key both consumers read. */
3
+ const THEME_STORAGE_KEY = "open-theme";
4
+ /** Whether a value is one of the two accepted theme names. */
5
+ function isSiteTheme(value) {
6
+ return value === "light" || value === "dark";
7
+ }
8
+ /**
9
+ * The one acceptance rule: an exact saved `light`/`dark` wins; anything else
10
+ * (missing, blocked storage, legacy truthy garbage) falls back to the system
11
+ * preference; with no light preference the default is `dark` — the toggle's
12
+ * documented no-preference default.
13
+ */
14
+ function resolveSiteTheme(saved, prefersLight) {
15
+ if (isSiteTheme(saved)) return saved;
16
+ return prefersLight ? "light" : "dark";
17
+ }
18
+ /**
19
+ * Apply the theme to the document root — the ONLY writer of
20
+ * `html[data-theme]`.
21
+ *
22
+ * Returns whether anything was written. A theme that is already in place
23
+ * writes nothing (no attribute mutation, no style write), which is what makes
24
+ * the two consumers idempotent together: pre-paint wins the first write and
25
+ * hydration is a no-op instead of a second mutation.
26
+ */
27
+ function applyDocumentTheme(root, theme) {
28
+ let changed = false;
29
+ if (root.getAttribute("data-theme") !== theme) {
30
+ root.setAttribute("data-theme", theme);
31
+ changed = true;
32
+ }
33
+ if (root.style && root.style.colorScheme !== theme) {
34
+ root.style.colorScheme = theme;
35
+ changed = true;
36
+ }
37
+ return changed;
38
+ }
39
+ //#endregion
40
+ export { THEME_STORAGE_KEY, applyDocumentTheme, isSiteTheme, resolveSiteTheme };
package/src/register.d.ts DELETED
@@ -1,4 +0,0 @@
1
- //#region src/register.d.ts
2
- /** Explicitly register every first-party UI element. Safe to call repeatedly. */
3
- export declare function registerOpenUi(registry?: CustomElementRegistry | undefined): void;
4
- //#endregion
package/src/register.js DELETED
@@ -1,22 +0,0 @@
1
- import { OpenButton } from "./open-button.js";
2
- import { OpenInput } from "./open-input.js";
3
- import { OpenCodeBlock } from "./open-code-block.js";
4
- import { OpenThemeToggle } from "./open-theme-toggle.js";
5
- import { OpenDialog } from "./open-dialog.js";
6
- import { OpenDropdown } from "./open-dropdown.js";
7
- //#region src/register.ts
8
- const COMPONENTS = [
9
- ["open-button", OpenButton],
10
- ["open-input", OpenInput],
11
- ["open-theme-toggle", OpenThemeToggle],
12
- ["open-code-block", OpenCodeBlock],
13
- ["open-dialog", OpenDialog],
14
- ["open-dropdown", OpenDropdown]
15
- ];
16
- /** Explicitly register every first-party UI element. Safe to call repeatedly. */
17
- function registerOpenUi(registry = globalThis.customElements) {
18
- if (!registry) return;
19
- for (const [tagName, constructor] of COMPONENTS) if (!registry.get(tagName)) registry.define(tagName, constructor);
20
- }
21
- //#endregion
22
- export { registerOpenUi };