@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.
- package/CUSTOMIZATION.md +34 -172
- package/README.md +10 -33
- package/custom-elements.json +369 -0
- package/package.json +3 -2
- package/src/button-machine.js +54 -0
- package/src/component-config.js +7 -0
- package/src/component-recipes.js +2 -24
- package/src/copy-feedback.js +32 -0
- package/src/dialog-machine.js +104 -0
- package/src/dropdown-machine.js +253 -0
- package/src/generated-manifest.json +104 -92
- package/src/index.d.ts +7 -8
- package/src/index.js +7 -8
- package/src/input-machine.js +33 -0
- package/src/open-button.d.ts +34 -393
- package/src/open-button.generated.js +592 -0
- package/src/open-button.js +115 -1065
- package/src/open-code-block.d.ts +15 -177
- package/src/open-code-block.generated.js +293 -0
- package/src/open-code-block.js +112 -249
- package/src/open-dialog.d.ts +22 -263
- package/src/open-dialog.generated.js +501 -0
- package/src/open-dialog.js +137 -667
- package/src/open-dropdown.css +6 -0
- package/src/open-dropdown.d.ts +15 -220
- package/src/open-dropdown.generated.js +211 -0
- package/src/open-dropdown.js +74 -365
- package/src/open-input.css +23 -6
- package/src/open-input.d.ts +35 -440
- package/src/open-input.generated.js +685 -0
- package/src/open-input.js +161 -1748
- package/src/open-theme-toggle.d.ts +19 -192
- package/src/open-theme-toggle.generated.js +564 -0
- package/src/open-theme-toggle.js +209 -531
- package/src/theme-contract.js +40 -0
- package/src/register.d.ts +0 -4
- package/src/register.js +0 -22
|
@@ -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
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 };
|