@deepfuture/dui-core 0.0.1 → 0.0.4
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 +191 -0
- package/apply-theme.d.ts +2 -0
- package/apply-theme.js +4 -0
- package/floating-portal-controller.js +11 -2
- package/package.json +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# DUI
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://www.npmjs.com/package/@deepfuture/dui-core)
|
|
5
|
+
|
|
6
|
+
Unstyled [Lit](https://lit.dev) web component library with composable themes.
|
|
7
|
+
|
|
8
|
+
Components provide structure and behavior with zero visual opinions. Themes provide all aesthetics — colors, spacing, typography, borders. Swap the theme to completely change the look without touching component code.
|
|
9
|
+
|
|
10
|
+
**[Live Docs & Demos →](https://deepfuturenow.github.io/dui/)**
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
**npm / pnpm / yarn:**
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @deepfuture/dui-core @deepfuture/dui-components @deepfuture/dui-theme-default
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Deno:**
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { applyTheme } from "npm:@deepfuture/dui-core/apply-theme";
|
|
24
|
+
import { defaultTheme } from "npm:@deepfuture/dui-theme-default";
|
|
25
|
+
import { allComponents } from "npm:@deepfuture/dui-components/all";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**CDN (zero setup):**
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@deepfuture/dui-cdn/dui.min.js"></script>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { applyTheme } from "@deepfuture/dui-core/apply-theme";
|
|
38
|
+
import { defaultTheme } from "@deepfuture/dui-theme-default";
|
|
39
|
+
import { DuiButton } from "@deepfuture/dui-components/button";
|
|
40
|
+
import { DuiDialog, DuiDialogTrigger, DuiDialogPopup, DuiDialogClose } from "@deepfuture/dui-components/dialog";
|
|
41
|
+
|
|
42
|
+
// Register components with a theme — this is the only setup needed
|
|
43
|
+
applyTheme({
|
|
44
|
+
theme: defaultTheme,
|
|
45
|
+
components: [DuiButton, DuiDialog, DuiDialogTrigger, DuiDialogPopup, DuiDialogClose],
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<dui-dialog>
|
|
51
|
+
<dui-dialog-trigger>
|
|
52
|
+
<dui-button>Open Dialog</dui-button>
|
|
53
|
+
</dui-dialog-trigger>
|
|
54
|
+
<dui-dialog-popup>
|
|
55
|
+
<h2>Hello</h2>
|
|
56
|
+
<p>This is a dialog.</p>
|
|
57
|
+
<dui-dialog-close>
|
|
58
|
+
<dui-button variant="outline">Close</dui-button>
|
|
59
|
+
</dui-dialog-close>
|
|
60
|
+
</dui-dialog-popup>
|
|
61
|
+
</dui-dialog>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Or register everything at once:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { applyTheme } from "@deepfuture/dui-core/apply-theme";
|
|
68
|
+
import { defaultTheme } from "@deepfuture/dui-theme-default";
|
|
69
|
+
import { allComponents } from "@deepfuture/dui-components/all";
|
|
70
|
+
|
|
71
|
+
applyTheme({ theme: defaultTheme, components: allComponents });
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## How It Works
|
|
75
|
+
|
|
76
|
+
`applyTheme()` takes unstyled component classes and a theme, creates themed subclasses with composed styles, and registers them as custom elements.
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
Component structural CSS → Theme base styles → Theme component styles
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
No build step, no decorators, no code generation — just a function call. Components are standard web components that work in any framework or plain HTML.
|
|
83
|
+
|
|
84
|
+
## Components
|
|
85
|
+
|
|
86
|
+
43 component families, 85+ elements total.
|
|
87
|
+
|
|
88
|
+
| Category | Components |
|
|
89
|
+
|----------|-----------|
|
|
90
|
+
| **Actions** | Button, Link, Toggle, Toggle Group, Toolbar |
|
|
91
|
+
| **Forms** | Input, Textarea, Select, Combobox, Checkbox, Checkbox Group, Radio, Radio Group, Switch, Slider, Number Field, Dropzone |
|
|
92
|
+
| **Data Display** | Badge, Avatar, Calendar, Data Table, Progress, Spinner, Separator, Trunc |
|
|
93
|
+
| **Overlays** | Dialog, Alert Dialog, Popover, Tooltip, Menu, Menubar, Preview Card, Command |
|
|
94
|
+
| **Disclosure** | Accordion, Collapsible, Tabs |
|
|
95
|
+
| **Navigation** | Breadcrumb, Sidebar (with 12 sub-components) |
|
|
96
|
+
| **Layout** | HStack, VStack, Center, Page Inset, Scroll Area, Portal |
|
|
97
|
+
| **Utility** | Icon |
|
|
98
|
+
|
|
99
|
+
## Styling
|
|
100
|
+
|
|
101
|
+
DUI uses a two-layer styling approach:
|
|
102
|
+
|
|
103
|
+
### CSS Variables — for the variant system
|
|
104
|
+
|
|
105
|
+
Variables control values that variants, sizes, and states toggle:
|
|
106
|
+
|
|
107
|
+
```css
|
|
108
|
+
/* Override variant colors */
|
|
109
|
+
dui-button {
|
|
110
|
+
--button-bg: linear-gradient(135deg, pink, purple);
|
|
111
|
+
--button-radius: var(--radius-full);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### `::part(root)` — for everything else
|
|
116
|
+
|
|
117
|
+
Every component exposes a `root` CSS part for full CSS expressiveness:
|
|
118
|
+
|
|
119
|
+
```css
|
|
120
|
+
/* Frosted glass effect */
|
|
121
|
+
dui-dialog-popup::part(root) {
|
|
122
|
+
backdrop-filter: blur(12px);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Custom hover animation */
|
|
126
|
+
dui-button::part(root):hover {
|
|
127
|
+
filter: brightness(1.25);
|
|
128
|
+
transform: translateY(-1px);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* Glow shadow */
|
|
132
|
+
dui-badge::part(root) {
|
|
133
|
+
box-shadow: 0 0 16px oklch(0.7 0.2 280 / 0.4);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
No need for the library to anticipate every CSS property — `::part()` gives you direct access.
|
|
138
|
+
|
|
139
|
+
## Dark Mode
|
|
140
|
+
|
|
141
|
+
DUI uses CSS custom properties for theming. Toggle dark mode by adding `class="dark"` to a parent element:
|
|
142
|
+
|
|
143
|
+
```html
|
|
144
|
+
<body class="dark">
|
|
145
|
+
<!-- All DUI components render in dark mode -->
|
|
146
|
+
</body>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Packages
|
|
150
|
+
|
|
151
|
+
| Package | Purpose |
|
|
152
|
+
|---------|---------|
|
|
153
|
+
| [`@deepfuture/dui-core`](https://www.npmjs.com/package/@deepfuture/dui-core) | `applyTheme()`, event factory, base styles |
|
|
154
|
+
| [`@deepfuture/dui-components`](https://www.npmjs.com/package/@deepfuture/dui-components) | Unstyled component classes |
|
|
155
|
+
| [`@deepfuture/dui-theme-default`](https://www.npmjs.com/package/@deepfuture/dui-theme-default) | Design tokens + aesthetic styles |
|
|
156
|
+
| [`@deepfuture/dui-cdn`](https://www.npmjs.com/package/@deepfuture/dui-cdn) | Pre-bundled CDN build (all deps inlined) |
|
|
157
|
+
|
|
158
|
+
## Dev Tools
|
|
159
|
+
|
|
160
|
+
### Theme Editor
|
|
161
|
+
|
|
162
|
+
A visual editor for design tokens. Edit colors with OKLCH sliders, tweak spacing and typography, and export your customized `tokens.css`.
|
|
163
|
+
|
|
164
|
+
### Inspector
|
|
165
|
+
|
|
166
|
+
A runtime inspector and mutation API for DUI components. Two interfaces:
|
|
167
|
+
|
|
168
|
+
- **Visual UI** (Ctrl+Shift+I) — hover-highlight components, inspect properties/tokens/styles, edit theme CSS and design tokens live
|
|
169
|
+
- **Console API** — `window.__dui_inspect()`, `window.__dui_mutate.*`, `window.__dui_export()` for programmatic access by agents or scripts
|
|
170
|
+
|
|
171
|
+
Both share a changelog, so agent and human edits are visible to each other. Changes can be exported as structured source file diffs.
|
|
172
|
+
|
|
173
|
+
See **[Inspector docs](docs/inspector.md)** for the full API reference and usage guide.
|
|
174
|
+
|
|
175
|
+
## Documentation
|
|
176
|
+
|
|
177
|
+
- **[Live Docs](https://deepfuturenow.github.io/dui/)** — interactive demos for every component
|
|
178
|
+
- [Architecture](docs/architecture.md) — mental model, package responsibilities, design decisions
|
|
179
|
+
- [Creating Components](docs/creating-components.md) — guide for adding new components
|
|
180
|
+
- [Theming](docs/theming.md) — theme system, design tokens, writing component styles
|
|
181
|
+
- [Consuming](docs/consuming.md) — integrating DUI into an app
|
|
182
|
+
- [Inspector](docs/inspector.md) — runtime inspection, mutation API, and visual editor
|
|
183
|
+
- [Accessibility](docs/accessibility.md) — accessibility patterns and guidelines
|
|
184
|
+
|
|
185
|
+
## Contributing
|
|
186
|
+
|
|
187
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for dev setup, code conventions, and PR guidelines.
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
[MIT](LICENSE)
|
package/apply-theme.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface DuiTheme {
|
|
|
12
12
|
base: CSSResult;
|
|
13
13
|
/** Tag name → component aesthetic styles. */
|
|
14
14
|
styles: Map<string, CSSResult>;
|
|
15
|
+
/** Optional prose stylesheet for .dui-prose rich-text styling. */
|
|
16
|
+
prose?: CSSStyleSheet;
|
|
15
17
|
}
|
|
16
18
|
export interface ApplyThemeOptions {
|
|
17
19
|
theme: DuiTheme;
|
package/apply-theme.js
CHANGED
|
@@ -14,6 +14,10 @@ export function applyTheme({ theme, components }) {
|
|
|
14
14
|
if (!document.adoptedStyleSheets.includes(theme.tokens)) {
|
|
15
15
|
document.adoptedStyleSheets = [...document.adoptedStyleSheets, theme.tokens];
|
|
16
16
|
}
|
|
17
|
+
// 1b. Inject prose stylesheet if present (idempotent)
|
|
18
|
+
if (theme.prose && !document.adoptedStyleSheets.includes(theme.prose)) {
|
|
19
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, theme.prose];
|
|
20
|
+
}
|
|
17
21
|
// 2. For each component, create a themed subclass and register it
|
|
18
22
|
for (const Base of components) {
|
|
19
23
|
const tagName = Base.tagName;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* provided overlay root) so that popups escape `container-type` ancestors.
|
|
5
5
|
*/
|
|
6
6
|
import { adoptStyles, render, } from "lit";
|
|
7
|
+
import { getActiveTheme } from "./apply-theme.js";
|
|
7
8
|
import { notifyPopupClosing, notifyPopupOpening } from "./popup-coordinator.js";
|
|
8
9
|
import { onTransitionEnd, startFixedAutoUpdate, waitForAnimationFrame, } from "./floating-popup-utils.js";
|
|
9
10
|
export class FloatingPortalController {
|
|
@@ -161,9 +162,17 @@ export class FloatingPortalController {
|
|
|
161
162
|
positioner.style.pointerEvents = "none";
|
|
162
163
|
positioner.setAttribute("data-floating-portal", "");
|
|
163
164
|
positioner.setAttribute("data-dui-portal-for", this.#host.tagName.toLowerCase());
|
|
164
|
-
|
|
165
|
+
const theme = getActiveTheme();
|
|
166
|
+
const themeTag = this.#host.tagName.toLowerCase();
|
|
167
|
+
const themeComponentStyles = theme?.styles.get(themeTag);
|
|
168
|
+
const allStyles = [
|
|
169
|
+
...(this.#styles ?? []),
|
|
170
|
+
...(theme?.base ? [theme.base] : []),
|
|
171
|
+
...(themeComponentStyles ? [themeComponentStyles] : []),
|
|
172
|
+
];
|
|
173
|
+
if (allStyles.length > 0) {
|
|
165
174
|
const shadow = positioner.attachShadow({ mode: "open" });
|
|
166
|
-
adoptStyles(shadow,
|
|
175
|
+
adoptStyles(shadow, allStyles);
|
|
167
176
|
}
|
|
168
177
|
overlayRoot.appendChild(positioner);
|
|
169
178
|
this.#positioner = positioner;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepfuture/dui-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "DUI core — applyTheme(), setup(), event factory, base styles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/
|
|
9
|
+
"url": "https://github.com/deepfuturenow/dui.git",
|
|
10
10
|
"directory": "packages/core"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"files": [
|
|
55
55
|
"**/*.js",
|
|
56
56
|
"**/*.d.ts",
|
|
57
|
-
"**/*.css"
|
|
57
|
+
"**/*.css",
|
|
58
|
+
"README.md"
|
|
58
59
|
],
|
|
59
60
|
"dependencies": {
|
|
60
61
|
"lit": "^3.3.2",
|