flexui-runtime 2.0.0-alpha.1 → 2.0.0-alpha.3

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 CHANGED
@@ -1,52 +1,79 @@
1
- # @flexui/runtime
1
+ # flexui-runtime
2
2
 
3
- Optional zero-dependency browser runtime for [FlexUI](https://github.com/Ahaduzzamankhan/flexui) components. The CSS works without it; this package adds keyboard behaviour, focus management, ARIA state and DOM events on top of native `<dialog>` and the popover API.
3
+ The optional browser runtime for FlexUI components. It adds keyboard
4
+ behaviour, focus management, ARIA state and DOM events on top of native
5
+ `<dialog>`, the popover API and your existing markup. The CSS works on its own;
6
+ this package is what makes the interactive components feel finished.
7
+
8
+ Zero dependencies, ESM, about as small as a runtime can be.
4
9
 
5
10
  ```bash
6
- npm install @flexui/runtime
11
+ npm install flexui-runtime
7
12
  ```
8
13
 
9
- ```ts
10
- import { init } from "@flexui/runtime";
14
+ ```js
15
+ import { init } from "flexui-runtime";
11
16
 
12
- const dispose = init();
17
+ const cleanup = init();
13
18
  ```
14
19
 
15
- ## Features
16
-
17
- - Dialogs and drawers: backdrop dismissal, Escape, scroll locking, focus trap and focus restoration.
18
- - Dropdown menus: arrow/Home/End navigation, roving focus, outside dismissal.
19
- - Popovers: native popover API with viewport-aware positioning and a fallback.
20
- - Tabs: roving tabindex, automatic activation, horizontal/vertical orientation.
21
- - Toasts: polite live region, four-toast cap, pause on hover/focus, sticky option.
22
- - Command palette: Ctrl/Cmd+K, multi-term filtering, active descendant, events.
23
- - Theme switching: light/dark/system, `localStorage`, `prefers-color-scheme`.
24
- - Focus helpers: `focusable`, `focusFirst`, `trapFocus`.
25
-
26
- ## Markup contracts
20
+ Call `init()` once per page. It scans the document for the data attributes below
21
+ and returns a cleanup function that unbinds everything it attached.
22
+
23
+ ## What it handles
24
+
25
+ - **Dialogs and drawers** — backdrop dismissal, Escape, scroll locking, focus
26
+ trap and focus restoration to the element that opened them.
27
+ - **Dropdown menus** — arrow, Home and End navigation, roving focus, dismissal
28
+ on outside click.
29
+ - **Popovers** — native popover API with viewport-aware positioning.
30
+ - **Tabs** — roving tabindex, automatic activation, horizontal and vertical
31
+ orientation.
32
+ - **Toasts** — polite live region, a four-toast cap, pause on hover or focus, and
33
+ a sticky option.
34
+ - **Command palette** — Ctrl/Cmd+K, multi-term filtering, active descendant and
35
+ events.
36
+ - **Theme switching** — light, dark and system, with `localStorage` and
37
+ `prefers-color-scheme`.
38
+ - **Focus helpers** — `focusable`, `focusFirst` and `trapFocus` for your own
39
+ widgets.
40
+
41
+ ## Markup
27
42
 
28
43
  | Feature | Markup |
29
44
  | --- | --- |
30
- | Dialog | `<dialog class="fui-dialog" data-fui-dialog>` with `data-fui-open="#id"` / `data-fui-close` |
45
+ | Dialog | `<dialog class="fui-dialog" data-fui-dialog>`, opened with `data-fui-open="#id"` and closed with `data-fui-close` |
31
46
  | Drawer | `<dialog class="fui-drawer" data-fui-drawer data-fui-side="right">` |
32
- | Dropdown | `data-fui-dropdown="#menu"` + `role="menu"` items |
33
- | Popover | `data-fui-popover="#panel"` + `popover` panel |
34
- | Tabs | `data-fui-tabs` + `role="tablist"` / `tab` / `tabpanel` |
47
+ | Dropdown | `data-fui-dropdown="#menu"` on the trigger, `role="menu"` on the items |
48
+ | Popover | `data-fui-popover="#panel"` on the trigger, `popover` on the panel |
49
+ | Tabs | `data-fui-tabs` with `role="tablist"`, `role="tab"` and `role="tabpanel"` |
35
50
  | Toast | `toast({ title, description, variant, duration })` |
36
- | Command palette | `data-fui-command` + input/list/item attributes |
51
+ | Command palette | `data-fui-command` plus the input, list and item attributes |
37
52
  | Theme | `data-fui-theme-set="light\|dark\|system"` or `data-fui-theme-toggle` |
38
53
 
39
- `init(root?)` returns a cleanup function and is safe to call once per page. Every feature is also exported from its own entry point:
40
-
41
- ```ts
42
- import { initDialogs } from "@flexui/runtime/dialog";
43
- import { toast } from "@flexui/runtime/toast";
44
- import { setTheme } from "@flexui/runtime/theme";
54
+ ## Per-feature entry points
55
+
56
+ Importing the whole runtime is convenient; importing one module keeps the rest
57
+ out of your bundle. Every feature has its own entry:
58
+
59
+ ```js
60
+ import { initDialogs } from "flexui-runtime/dialog";
61
+ import { initDrawers } from "flexui-runtime/drawer";
62
+ import { initDropdowns } from "flexui-runtime/dropdown";
63
+ import { initPopovers } from "flexui-runtime/popover";
64
+ import { initTabs } from "flexui-runtime/tabs";
65
+ import { toast } from "flexui-runtime/toast";
66
+ import { initCommand } from "flexui-runtime/command";
67
+ import { setTheme, getTheme, initTheme } from "flexui-runtime/theme";
68
+ import { focusFirst, trapFocus } from "flexui-runtime/focus";
45
69
  ```
46
70
 
71
+ `flexui-runtime/auto` is a side-effect entry that initialises everything as soon
72
+ as the DOM is ready.
73
+
47
74
  ## Events
48
75
 
49
- All events bubble and are cancelable.
76
+ Every event bubbles and is cancelable.
50
77
 
51
78
  | Event | Detail |
52
79
  | --- | --- |
@@ -58,14 +85,23 @@ All events bubble and are cancelable.
58
85
  | `fui:command` | `{ value, label, item, palette }` |
59
86
  | `fui:themechange` | `{ mode, resolved }` |
60
87
 
61
- ## Docs
62
-
63
- The full guide lives in [docs/runtime.md](https://github.com/Ahaduzzamankhan/flexui/blob/main/docs/runtime.md).
88
+ ## Theming
64
89
 
65
- ## Build
90
+ ```js
91
+ import { setTheme, getTheme } from "flexui-runtime/theme";
66
92
 
67
- ```bash
68
- bun run build:runtime
93
+ setTheme("dark"); // "light" | "dark" | "system"
94
+ getTheme(); // { mode: "dark", resolved: "dark" }
69
95
  ```
70
96
 
71
- Output is ESM plus declarations in `dist/`. MIT licensed.
97
+ Theme state is stored under a configurable key, so several sites on one origin
98
+ can keep independent preferences.
99
+
100
+ ## Documentation
101
+
102
+ The full guide, including every option and the complete event list, lives in
103
+ [docs/runtime.md](https://github.com/Ahaduzzamankhan/flexui/blob/main/docs/runtime.md).
104
+
105
+ ## License
106
+
107
+ MIT
package/dist/command.js CHANGED
@@ -26,7 +26,7 @@ export class CommandPalette {
26
26
  const input = element.querySelector("[data-fui-command-input], input[role='combobox'], input");
27
27
  const list = element.querySelector("[data-fui-command-list], [role='listbox']");
28
28
  if (!input || !list) {
29
- throw new Error("@flexui/runtime: command palette needs an input and a list");
29
+ throw new Error("flexui-runtime: command palette needs an input and a list");
30
30
  }
31
31
  this.input = input;
32
32
  this.list = list;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexui-runtime",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Optional zero-dependency browser runtime for FlexUI components",
5
5
  "license": "MIT",
6
6
  "type": "module",