@openelement/ui 1.0.0-alpha.14 → 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 +106 -112
- package/README.md +19 -39
- 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 +135 -87
- package/src/index.d.ts +7 -8
- package/src/index.js +7 -8
- package/src/input-machine.js +33 -0
- package/src/open-button.css +119 -108
- package/src/open-button.d.ts +34 -342
- package/src/open-button.generated.js +592 -0
- package/src/open-button.js +115 -1140
- package/src/open-code-block.css +24 -44
- package/src/open-code-block.d.ts +15 -175
- package/src/open-code-block.generated.js +293 -0
- package/src/open-code-block.js +112 -224
- package/src/open-dialog.css +114 -127
- package/src/open-dialog.d.ts +22 -261
- package/src/open-dialog.generated.js +501 -0
- package/src/open-dialog.js +137 -632
- package/src/open-dropdown.css +26 -26
- package/src/open-dropdown.d.ts +15 -218
- package/src/open-dropdown.generated.js +211 -0
- package/src/open-dropdown.js +74 -355
- package/src/open-input.css +69 -74
- package/src/open-input.d.ts +34 -461
- package/src/open-input.generated.js +685 -0
- package/src/open-input.js +161 -1802
- package/src/open-theme-toggle.css +37 -47
- package/src/open-theme-toggle.d.ts +19 -190
- package/src/open-theme-toggle.generated.js +564 -0
- package/src/open-theme-toggle.js +209 -509
- package/src/theme-contract.js +40 -0
- package/src/theme.css +26 -8
- package/src/control-recipe.css +0 -21
- 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/theme.css
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
No carried ramp step other than zinc-50 changed value between the two
|
|
22
22
|
versions. With the alpha9 C5 twin removal this file has no compiled
|
|
23
23
|
shadow form: the installed Tailwind defaults are the only scale
|
|
24
|
-
evaluation, reached exclusively through the
|
|
24
|
+
evaluation, reached exclusively through the Tailwind entry's build.
|
|
25
25
|
|
|
26
26
|
Rules the roles obey (umbrella rulings, do not relitigate):
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
(var(--color-<ramp>-<step>)); no role carries a color literal.
|
|
30
30
|
- Dark pairs follow the shadcn v4 convention; the '.dark' selector is
|
|
31
31
|
re-pointed at this repo's theme mechanism
|
|
32
|
-
(:root[data-theme='dark'], :host([data-theme='dark'])) — the
|
|
32
|
+
(:root[data-theme='dark'], :host([data-theme='dark'])) — the entry's
|
|
33
33
|
Tailwind build compiles no @custom-variant here yet.
|
|
34
34
|
- One deliberate divergence from the shadcn default palette: light
|
|
35
35
|
--color-destructive sits on red-700, not red-600 — red-600 clears 4.5:1
|
|
@@ -44,14 +44,32 @@
|
|
|
44
44
|
destructive — high-contrast palettes own hue, so status is carried by
|
|
45
45
|
the label and the border, not by color.
|
|
46
46
|
|
|
47
|
-
Consumption: the @openelement/router
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
Consumption: the @openelement/router Tailwind entry compiles this file —
|
|
48
|
+
declared in `tailwind: { theme: [...] }` — through the OFFICIAL
|
|
49
|
+
`@tailwindcss/vite` pipeline into the app's document stylesheet, in dev
|
|
50
|
+
and in the build alike. The ui package emits no values itself (the
|
|
51
|
+
theme-tokens twin is deleted): a consumer without the entry writes its own
|
|
52
|
+
table using these role names — the OFF contract in CUSTOMIZATION.md
|
|
53
|
+
("Value delivery").
|
|
54
|
+
|
|
55
|
+
`@theme static` — load-bearing, not a preference. A plain `@theme` block is
|
|
56
|
+
emitted only for the variables some generated UTILITY RULE references, and
|
|
57
|
+
the rules that consume these roles are the components' own authored sheets
|
|
58
|
+
(`.control`'s `color-mix(in srgb, var(--color-popover) …)`,
|
|
59
|
+
`:host(:state(disabled)) .control`'s `var(--color-muted)`), which the engine
|
|
60
|
+
never sees: they are adopted into the shadow root through the style-asset
|
|
61
|
+
channel, not compiled into the Tailwind entry. Under a plain `@theme` the
|
|
62
|
+
roles those rules name (popover, border, muted, background, …) were pruned
|
|
63
|
+
from BOTH entries, so the declarations computed to nothing and the control
|
|
64
|
+
fell back to the UA surface — the tree-shaking defect the alpha15 S-lane
|
|
65
|
+
acceptance missed by measuring padding and width only. `static` is the
|
|
66
|
+
engine's own documented escape hatch for exactly this case ("always include
|
|
67
|
+
these theme variables in the output"), so the emitted table matches the
|
|
68
|
+
inventory this document promises, whatever a given build happens to use.
|
|
69
|
+
Guarded by `__tests__/theme-delivery.test.ts`.
|
|
52
70
|
═══════════════════════════════════════════════════════════════════════ */
|
|
53
71
|
|
|
54
|
-
@theme {
|
|
72
|
+
@theme static {
|
|
55
73
|
/* ── shadcn semantic roles (light), over the TW4 default scale.
|
|
56
74
|
Violet-anchored roles (the brand reads violet); neutral surfaces stay
|
|
57
75
|
zinc so the page base keeps its near-neutral paper feel. ── */
|
package/src/control-recipe.css
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/* .control — the structural+visual recipe shared by open-button and
|
|
2
|
-
* open-input. Ported verbatim from the pre-#1558 controlRecipe sheet (the
|
|
3
|
-
* alpha.9 design system); the #1558 migration had left a layout skeleton. */
|
|
4
|
-
.control {
|
|
5
|
-
font: inherit;
|
|
6
|
-
color: var(--color-foreground);
|
|
7
|
-
background: color-mix(in srgb, var(--color-popover) 78%, transparent);
|
|
8
|
-
border: calc(var(--spacing) * 0.25) solid color-mix(in srgb, var(--color-border) 72%, var(--color-primary));
|
|
9
|
-
border-radius: var(--radius-md);
|
|
10
|
-
box-shadow: inset 0 1px 0 color-mix(in srgb, var(--color-white) 12%, transparent);
|
|
11
|
-
transition: border-color var(--default-transition-duration) var(--ease-out),
|
|
12
|
-
background var(--default-transition-duration) var(--ease-out),
|
|
13
|
-
box-shadow var(--default-transition-duration) var(--ease-out),
|
|
14
|
-
transform var(--default-transition-duration) var(--ease-out);
|
|
15
|
-
}
|
|
16
|
-
.control:hover { border-color: color-mix(in srgb, var(--color-violet-400) 74%, var(--color-border)); }
|
|
17
|
-
.control:focus-visible {
|
|
18
|
-
outline: calc(var(--spacing) * 0.5) solid var(--color-ring);
|
|
19
|
-
outline-offset: calc(var(--spacing) * 0.75);
|
|
20
|
-
}
|
|
21
|
-
.control:disabled, .control[aria-disabled="true"] { opacity: .48; cursor: not-allowed; }
|
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 };
|