@dou-ui/theme 0.0.0-stage → 0.1.0-alpha.0
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/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/breakpoints.d.ts +13 -0
- package/dist/collaboration.d.ts +7 -0
- package/dist/components/affix.css +1 -0
- package/dist/components/alert.css +1 -0
- package/dist/components/anchor.css +1 -0
- package/dist/components/autocomplete.css +1 -0
- package/dist/components/avatar.css +1 -0
- package/dist/components/back-top.css +1 -0
- package/dist/components/badge.css +1 -0
- package/dist/components/banner.css +1 -0
- package/dist/components/breadcrumb.css +1 -0
- package/dist/components/button.css +1 -0
- package/dist/components/calendar-heatmap.css +1 -0
- package/dist/components/calendar-view.css +1 -0
- package/dist/components/card.css +1 -0
- package/dist/components/carousel.css +1 -0
- package/dist/components/cascader.css +1 -0
- package/dist/components/chat-artifact.css +1 -0
- package/dist/components/chat-attachments.css +1 -0
- package/dist/components/chat-bubble.css +1 -0
- package/dist/components/chat-confirm.css +1 -0
- package/dist/components/chat-context-meter.css +1 -0
- package/dist/components/chat-input.css +1 -0
- package/dist/components/chat-list.css +1 -0
- package/dist/components/chat-message.css +1 -0
- package/dist/components/chat-plan.css +1 -0
- package/dist/components/chat-reasoning.css +1 -0
- package/dist/components/chat-sources.css +1 -0
- package/dist/components/chat-steps.css +1 -0
- package/dist/components/chat-suggestions.css +1 -0
- package/dist/components/chat-tool-call.css +1 -0
- package/dist/components/check-tag.css +1 -0
- package/dist/components/checkbox.css +1 -0
- package/dist/components/code-block.css +1 -0
- package/dist/components/collapse.css +1 -0
- package/dist/components/color-mode.css +1 -0
- package/dist/components/color-panel.css +1 -0
- package/dist/components/color-picker.css +1 -0
- package/dist/components/command.css +1 -0
- package/dist/components/comment-thread.css +1 -0
- package/dist/components/context-menu.css +1 -0
- package/dist/components/copy-button.css +1 -0
- package/dist/components/countdown.css +1 -0
- package/dist/components/date-picker.css +1 -0
- package/dist/components/descriptions.css +1 -0
- package/dist/components/dialog-box.css +1 -0
- package/dist/components/dialog.css +1 -0
- package/dist/components/divider.css +1 -0
- package/dist/components/drawer.css +1 -0
- package/dist/components/dropdown.css +1 -0
- package/dist/components/editable.css +1 -0
- package/dist/components/ellipsis.css +1 -0
- package/dist/components/empty.css +1 -0
- package/dist/components/field-group.css +1 -0
- package/dist/components/find-replace.css +1 -0
- package/dist/components/form.css +1 -0
- package/dist/components/grid.css +1 -0
- package/dist/components/highlight.css +1 -0
- package/dist/components/icon.css +1 -0
- package/dist/components/image-cropper.css +1 -0
- package/dist/components/image.css +1 -0
- package/dist/components/infinite-scroll.css +1 -0
- package/dist/components/input-date.css +1 -0
- package/dist/components/input-number.css +1 -0
- package/dist/components/input-otp.css +1 -0
- package/dist/components/input-tag.css +1 -0
- package/dist/components/input.css +1 -0
- package/dist/components/kbd.css +1 -0
- package/dist/components/layout.css +1 -0
- package/dist/components/link.css +1 -0
- package/dist/components/listbox.css +1 -0
- package/dist/components/loading.css +1 -0
- package/dist/components/marquee.css +1 -0
- package/dist/components/masonry.css +1 -0
- package/dist/components/menu.css +1 -0
- package/dist/components/menubar.css +1 -0
- package/dist/components/node-graph.css +1 -0
- package/dist/components/overlay.css +1 -0
- package/dist/components/page-header.css +1 -0
- package/dist/components/pagination.css +1 -0
- package/dist/components/picker.css +1 -0
- package/dist/components/popconfirm.css +1 -0
- package/dist/components/popover.css +1 -0
- package/dist/components/progress-group.css +1 -0
- package/dist/components/progress.css +1 -0
- package/dist/components/qrcode.css +1 -0
- package/dist/components/radio.css +1 -0
- package/dist/components/rate.css +1 -0
- package/dist/components/relative-time.css +1 -0
- package/dist/components/result.css +1 -0
- package/dist/components/scrollbar.css +1 -0
- package/dist/components/segmented-control.css +1 -0
- package/dist/components/select.css +1 -0
- package/dist/components/shimmer.css +1 -0
- package/dist/components/skeleton.css +1 -0
- package/dist/components/slider.css +1 -0
- package/dist/components/sortable.css +1 -0
- package/dist/components/space.css +1 -0
- package/dist/components/sparkline.css +1 -0
- package/dist/components/spinner.css +1 -0
- package/dist/components/splitter.css +1 -0
- package/dist/components/statistic.css +1 -0
- package/dist/components/steps.css +1 -0
- package/dist/components/stream-text.css +1 -0
- package/dist/components/switch.css +1 -0
- package/dist/components/table.css +1 -0
- package/dist/components/tabs.css +1 -0
- package/dist/components/tag.css +1 -0
- package/dist/components/text.css +1 -0
- package/dist/components/textarea.css +1 -0
- package/dist/components/time-picker.css +1 -0
- package/dist/components/timeline.css +1 -0
- package/dist/components/toast.css +1 -0
- package/dist/components/toggle.css +1 -0
- package/dist/components/toolbar.css +1 -0
- package/dist/components/tooltip.css +1 -0
- package/dist/components/tour.css +1 -0
- package/dist/components/transfer.css +1 -0
- package/dist/components/tree-select.css +1 -0
- package/dist/components/tree.css +1 -0
- package/dist/components/typography.css +1 -0
- package/dist/components/upload.css +1 -0
- package/dist/components/user.css +1 -0
- package/dist/components/virtual-list.css +1 -0
- package/dist/components/watermark.css +1 -0
- package/dist/core.css +1 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +371 -0
- package/dist/tokens/create.d.ts +47 -0
- package/dist/tokens/css.d.ts +20 -0
- package/dist/tokens/dark.d.ts +5 -0
- package/dist/tokens/define.d.ts +9 -0
- package/dist/tokens/light.d.ts +10 -0
- package/dist/tokens/types.d.ts +220 -0
- package/dist/tokens.css +1 -0
- package/package.json +45 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { ChartPalette, DeepPartial, SizeScale, SyntaxPalette, ThemeTokens, ToneTokens, } from './tokens/types';
|
|
2
|
+
export { light } from './tokens/light';
|
|
3
|
+
export { dark } from './tokens/dark';
|
|
4
|
+
export { defineTheme } from './tokens/define';
|
|
5
|
+
export { contrastRatio, createTheme, createTone, mixColors, parseColor } from './tokens/create';
|
|
6
|
+
export type { CreateThemeOptions, ThemeColors } from './tokens/create';
|
|
7
|
+
export { CSS_VAR_PREFIX, cssVarName, flattenTokens, themeToCss } from './tokens/css';
|
|
8
|
+
export { breakpoints } from './breakpoints';
|
|
9
|
+
export { collaborationColors } from './collaboration';
|
|
10
|
+
export type { Breakpoint } from './breakpoints';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
// src/tokens/light.ts
|
|
2
|
+
var light = {
|
|
3
|
+
scheme: { dark: "0" },
|
|
4
|
+
color: {
|
|
5
|
+
neutral: { DEFAULT: "#171717", on: "#ffffff", text: "#171717" },
|
|
6
|
+
primary: { DEFAULT: "#3f56b5", on: "#ffffff", text: "#3f56b5" },
|
|
7
|
+
success: { DEFAULT: "#2e7d5b", on: "#ffffff", text: "#2c7756" },
|
|
8
|
+
warning: { DEFAULT: "#92651d", on: "#ffffff", text: "#8b5f1c" },
|
|
9
|
+
danger: { DEFAULT: "#b2423e", on: "#ffffff", text: "#b2423e" },
|
|
10
|
+
bg: {
|
|
11
|
+
canvas: "#fafafa",
|
|
12
|
+
surface: "#ffffff",
|
|
13
|
+
muted: "#f2f2f2"
|
|
14
|
+
},
|
|
15
|
+
text: {
|
|
16
|
+
DEFAULT: "#171717",
|
|
17
|
+
secondary: "#5c5c5c",
|
|
18
|
+
tertiary: "#737373",
|
|
19
|
+
disabled: "#b5b5b5"
|
|
20
|
+
},
|
|
21
|
+
border: {
|
|
22
|
+
subtle: "#f0f0f0",
|
|
23
|
+
DEFAULT: "#e6e6e6",
|
|
24
|
+
strong: "#d1d1d1"
|
|
25
|
+
},
|
|
26
|
+
focus: "#6a82cf",
|
|
27
|
+
edge: "#000000",
|
|
28
|
+
chart: {
|
|
29
|
+
1: "#3d3d3d",
|
|
30
|
+
2: "#3f6aa1",
|
|
31
|
+
3: "#b08341",
|
|
32
|
+
4: "#2a9f9a",
|
|
33
|
+
5: "#b4666d",
|
|
34
|
+
6: "#5b4481",
|
|
35
|
+
7: "#48773e",
|
|
36
|
+
8: "#7e3e1e"
|
|
37
|
+
},
|
|
38
|
+
syntax: {
|
|
39
|
+
keyword: "#7b3f99",
|
|
40
|
+
string: "#3c7536",
|
|
41
|
+
number: "#a14a24",
|
|
42
|
+
comment: "#6b6b6b",
|
|
43
|
+
function: "#3550a8",
|
|
44
|
+
type: "#1d726c",
|
|
45
|
+
variable: "#171717",
|
|
46
|
+
property: "#2c6688",
|
|
47
|
+
operator: "#5c5c5c",
|
|
48
|
+
punctuation: "#5c5c5c",
|
|
49
|
+
tag: "#9a3a4c",
|
|
50
|
+
attribute: "#7d5d16",
|
|
51
|
+
meta: "#666666",
|
|
52
|
+
invalid: "#b2423e"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
font: {
|
|
56
|
+
family: 'system-ui, -apple-system, "Segoe UI", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif',
|
|
57
|
+
familyMono: 'ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',
|
|
58
|
+
size: { sm: "13px", md: "14px", lg: "16px" },
|
|
59
|
+
weight: { regular: "400", medium: "500", bold: "600" },
|
|
60
|
+
lineHeight: "1.6"
|
|
61
|
+
},
|
|
62
|
+
radius: {
|
|
63
|
+
control: "6px",
|
|
64
|
+
container: "12px",
|
|
65
|
+
full: "9999px"
|
|
66
|
+
},
|
|
67
|
+
control: {
|
|
68
|
+
height: { sm: "28px", md: "32px", lg: "40px" },
|
|
69
|
+
paddingX: { sm: "10px", md: "12px", lg: "16px" },
|
|
70
|
+
gap: { sm: "4px", md: "6px", lg: "8px" }
|
|
71
|
+
},
|
|
72
|
+
space: { sm: "8px", md: "12px", lg: "20px" },
|
|
73
|
+
shadow: {
|
|
74
|
+
sm: "0 1px 1px rgb(0 0 0 / 0.03), 0 1px 2px rgb(0 0 0 / 0.05)",
|
|
75
|
+
md: "0 1px 2px rgb(0 0 0 / 0.04), 0 4px 12px -2px rgb(0 0 0 / 0.06)",
|
|
76
|
+
lg: "0 2px 4px rgb(0 0 0 / 0.04), 0 16px 32px -8px rgb(0 0 0 / 0.1)",
|
|
77
|
+
highlight: "inset 0 1px 0 rgb(255 255 255 / 0.14)"
|
|
78
|
+
},
|
|
79
|
+
motion: {
|
|
80
|
+
duration: { instant: "100ms", fast: "150ms", normal: "220ms", slow: "320ms" },
|
|
81
|
+
easing: {
|
|
82
|
+
DEFAULT: "cubic-bezier(0.2, 0, 0, 1)",
|
|
83
|
+
enter: "cubic-bezier(0.16, 1, 0.3, 1)",
|
|
84
|
+
exit: "cubic-bezier(0.4, 0, 1, 1)",
|
|
85
|
+
spring: "linear(0, 0.192, 0.408, 0.616, 0.797, 0.94, 1.043, 1.107, 1.138, 1.145, 1.133, 1.111, 1.084, 1.057, 1.033, 1.013, 0.998, 0.989, 0.983, 0.982, 0.983, 0.985, 0.988, 0.992, 1)"
|
|
86
|
+
},
|
|
87
|
+
distance: { sm: "4px", md: "8px" },
|
|
88
|
+
scale: "0.98",
|
|
89
|
+
loop: { spin: "0.8s", pulse: "1.6s", sweep: "2s" }
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
// src/tokens/define.ts
|
|
93
|
+
function defineTheme(base, overrides) {
|
|
94
|
+
return merge(base, overrides);
|
|
95
|
+
}
|
|
96
|
+
function isTree(value) {
|
|
97
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
98
|
+
}
|
|
99
|
+
function merge(base, overrides) {
|
|
100
|
+
const result = { ...base };
|
|
101
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
102
|
+
if (value === undefined)
|
|
103
|
+
continue;
|
|
104
|
+
const current = result[key];
|
|
105
|
+
result[key] = isTree(current) && isTree(value) ? merge(current, value) : value;
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/tokens/dark.ts
|
|
111
|
+
var dark = defineTheme(light, {
|
|
112
|
+
scheme: { dark: "1" },
|
|
113
|
+
color: {
|
|
114
|
+
neutral: { DEFAULT: "#ededed", on: "#0a0a0a", text: "#ededed" },
|
|
115
|
+
primary: { DEFAULT: "#4c66cb", on: "#ffffff", text: "#768ad7" },
|
|
116
|
+
success: { DEFAULT: "#2f8060", on: "#ffffff", text: "#42a87d" },
|
|
117
|
+
warning: { DEFAULT: "#c18a3c", on: "#1a1206", text: "#c99852" },
|
|
118
|
+
danger: { DEFAULT: "#c5453e", on: "#ffffff", text: "#d4746f" },
|
|
119
|
+
bg: {
|
|
120
|
+
canvas: "#0a0a0a",
|
|
121
|
+
surface: "#111111",
|
|
122
|
+
muted: "#1c1c1c"
|
|
123
|
+
},
|
|
124
|
+
text: {
|
|
125
|
+
DEFAULT: "#ededed",
|
|
126
|
+
secondary: "#a3a3a3",
|
|
127
|
+
tertiary: "#858585",
|
|
128
|
+
disabled: "#4d4d4d"
|
|
129
|
+
},
|
|
130
|
+
border: {
|
|
131
|
+
subtle: "#1a1a1a",
|
|
132
|
+
DEFAULT: "#262626",
|
|
133
|
+
strong: "#3a3a3a"
|
|
134
|
+
},
|
|
135
|
+
focus: "#5a73b3",
|
|
136
|
+
edge: "#000000",
|
|
137
|
+
chart: {
|
|
138
|
+
1: "#d4d4d4",
|
|
139
|
+
2: "#8db4e7",
|
|
140
|
+
3: "#deb67f",
|
|
141
|
+
4: "#36908b",
|
|
142
|
+
5: "#e29ba0",
|
|
143
|
+
6: "#9480b8",
|
|
144
|
+
7: "#7ca573",
|
|
145
|
+
8: "#ab7055"
|
|
146
|
+
},
|
|
147
|
+
syntax: {
|
|
148
|
+
keyword: "#c3a0de",
|
|
149
|
+
string: "#9fc48f",
|
|
150
|
+
number: "#e2a382",
|
|
151
|
+
comment: "#858585",
|
|
152
|
+
function: "#94adea",
|
|
153
|
+
type: "#6fc2b9",
|
|
154
|
+
variable: "#ededed",
|
|
155
|
+
property: "#8bbcd9",
|
|
156
|
+
operator: "#a3a3a3",
|
|
157
|
+
punctuation: "#a3a3a3",
|
|
158
|
+
tag: "#e39aa6",
|
|
159
|
+
attribute: "#d6b46f",
|
|
160
|
+
meta: "#949494",
|
|
161
|
+
invalid: "#d4746f"
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
shadow: {
|
|
165
|
+
sm: "0 1px 2px rgb(0 0 0 / 0.5)",
|
|
166
|
+
md: "0 1px 2px rgb(0 0 0 / 0.5), 0 4px 12px -2px rgb(0 0 0 / 0.5)",
|
|
167
|
+
lg: "0 2px 4px rgb(0 0 0 / 0.5), 0 16px 32px -8px rgb(0 0 0 / 0.7)",
|
|
168
|
+
highlight: "inset 0 1px 0 rgb(255 255 255 / 0.1)"
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
// src/tokens/create.ts
|
|
172
|
+
var TEXT_CONTRAST = 4.5;
|
|
173
|
+
var FOCUS_CONTRAST = 3;
|
|
174
|
+
function createTheme(colors, options = {}) {
|
|
175
|
+
return {
|
|
176
|
+
light: themeFor(options.light ?? light, colors),
|
|
177
|
+
dark: themeFor(options.dark ?? dark, colors)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function themeFor(base, colors) {
|
|
181
|
+
const color = {};
|
|
182
|
+
for (const name of ["primary", "success", "warning", "danger"]) {
|
|
183
|
+
const value = colors[name];
|
|
184
|
+
if (value)
|
|
185
|
+
color[name] = createTone(value, base);
|
|
186
|
+
}
|
|
187
|
+
if (colors.primary)
|
|
188
|
+
color.focus = focusColor(colors.primary, base);
|
|
189
|
+
return defineTheme(base, { color });
|
|
190
|
+
}
|
|
191
|
+
function createTone(value, base = light) {
|
|
192
|
+
const surfaces = [base.color.bg.canvas, base.color.bg.surface, base.color.bg.muted].map(parseColor);
|
|
193
|
+
const isDark = luminance(surfaces[1]) < 0.18;
|
|
194
|
+
const seed = toOklch(parseColor(value));
|
|
195
|
+
const white = [1, 1, 1];
|
|
196
|
+
const ink = parseColor(isDark ? base.color.neutral.on : base.color.neutral.DEFAULT);
|
|
197
|
+
let fill = seed;
|
|
198
|
+
let on = pickOn(fromOklch(fill), white, ink);
|
|
199
|
+
if (!on) {
|
|
200
|
+
const darker = adjust(seed, -1, (rgb) => contrast(rgb, white) >= TEXT_CONTRAST);
|
|
201
|
+
const lighter = adjust(seed, 1, (rgb) => contrast(rgb, ink) >= TEXT_CONTRAST);
|
|
202
|
+
fill = Math.abs(darker[0] - seed[0]) <= Math.abs(lighter[0] - seed[0]) ? darker : lighter;
|
|
203
|
+
on = pickOn(fromOklch(fill), white, ink);
|
|
204
|
+
}
|
|
205
|
+
const reads = (rgb) => surfaces.every((surface) => contrast(rgb, surface) >= TEXT_CONTRAST);
|
|
206
|
+
const text = reads(fromOklch(fill)) ? fill : adjust(fill, isDark ? 1 : -1, reads);
|
|
207
|
+
return { DEFAULT: toHex(fromOklch(fill)), on: toHex(on), text: toHex(fromOklch(text)) };
|
|
208
|
+
}
|
|
209
|
+
function focusColor(value, base) {
|
|
210
|
+
const page = parseColor(base.color.bg.canvas);
|
|
211
|
+
const isDark = luminance(page) < 0.18;
|
|
212
|
+
const [l, c, h] = toOklch(parseColor(value));
|
|
213
|
+
const start = [isDark ? Math.min(l, 0.58) : Math.max(l, 0.62), c * 0.8, h];
|
|
214
|
+
const visible = (rgb) => contrast(rgb, page) >= FOCUS_CONTRAST;
|
|
215
|
+
const ring = visible(fromOklch(start)) ? start : adjust(start, isDark ? 1 : -1, visible);
|
|
216
|
+
return toHex(fromOklch(ring));
|
|
217
|
+
}
|
|
218
|
+
function contrastRatio(a, b) {
|
|
219
|
+
return contrast(parseColor(a), parseColor(b));
|
|
220
|
+
}
|
|
221
|
+
function pickOn(fill, white, ink) {
|
|
222
|
+
const toWhite = contrast(fill, white);
|
|
223
|
+
const toInk = contrast(fill, ink);
|
|
224
|
+
if (Math.max(toWhite, toInk) < TEXT_CONTRAST)
|
|
225
|
+
return;
|
|
226
|
+
return toWhite >= TEXT_CONTRAST ? white : ink;
|
|
227
|
+
}
|
|
228
|
+
function adjust(color, direction, ok) {
|
|
229
|
+
const [l, c, h] = color;
|
|
230
|
+
for (let next = l;next >= 0 && next <= 1; next += direction * 0.005) {
|
|
231
|
+
const candidate = [next, c, h];
|
|
232
|
+
if (ok(fromOklch(candidate)))
|
|
233
|
+
return candidate;
|
|
234
|
+
}
|
|
235
|
+
return [direction > 0 ? 1 : 0, 0, h];
|
|
236
|
+
}
|
|
237
|
+
function contrast(a, b) {
|
|
238
|
+
const hi = Math.max(luminance(a), luminance(b));
|
|
239
|
+
const lo = Math.min(luminance(a), luminance(b));
|
|
240
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
241
|
+
}
|
|
242
|
+
function luminance([r, g, b]) {
|
|
243
|
+
return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);
|
|
244
|
+
}
|
|
245
|
+
function linear(channel) {
|
|
246
|
+
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
|
247
|
+
}
|
|
248
|
+
function gamma(channel) {
|
|
249
|
+
return channel <= 0.0031308 ? channel * 12.92 : 1.055 * channel ** (1 / 2.4) - 0.055;
|
|
250
|
+
}
|
|
251
|
+
function parseColor(value) {
|
|
252
|
+
const input = value.trim().toLowerCase();
|
|
253
|
+
const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/.exec(input);
|
|
254
|
+
if (hex) {
|
|
255
|
+
const digits = hex[1].length === 3 ? [...hex[1]].map((d) => d + d).join("") : hex[1];
|
|
256
|
+
return [0, 2, 4].map((i) => Number.parseInt(digits.slice(i, i + 2), 16) / 255);
|
|
257
|
+
}
|
|
258
|
+
const rgb = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/.exec(input);
|
|
259
|
+
if (rgb)
|
|
260
|
+
return [rgb[1], rgb[2], rgb[3]].map((n) => Number(n) / 255);
|
|
261
|
+
throw new Error(`[@dou-ui/theme] unsupported color "${value}": use #rrggbb or rgb()`);
|
|
262
|
+
}
|
|
263
|
+
function toHex(rgb) {
|
|
264
|
+
return `#${rgb.map((channel) => Math.round(Math.min(1, Math.max(0, channel)) * 255).toString(16).padStart(2, "0")).join("")}`;
|
|
265
|
+
}
|
|
266
|
+
function toOklab(rgb) {
|
|
267
|
+
const [r, g, b] = rgb.map(linear);
|
|
268
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
269
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
270
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
271
|
+
return [
|
|
272
|
+
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
273
|
+
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
274
|
+
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s
|
|
275
|
+
];
|
|
276
|
+
}
|
|
277
|
+
function toOklch(rgb) {
|
|
278
|
+
const [L, A, B] = toOklab(rgb);
|
|
279
|
+
return [L, Math.hypot(A, B), Math.atan2(B, A)];
|
|
280
|
+
}
|
|
281
|
+
function fromOklch([L, C, h]) {
|
|
282
|
+
for (let chroma = C;; chroma = Math.max(0, chroma - 0.002)) {
|
|
283
|
+
const rgb = oklabToRgb(L, chroma * Math.cos(h), chroma * Math.sin(h));
|
|
284
|
+
if (chroma === 0 || rgb.every((v) => v >= -0.0001 && v <= 1 + 0.0001)) {
|
|
285
|
+
return rgb.map((v) => Math.round(Math.min(1, Math.max(0, v || 0)) * 255) / 255);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function oklabToRgb(L, A, B) {
|
|
290
|
+
const l = (L + 0.3963377774 * A + 0.2158037573 * B) ** 3;
|
|
291
|
+
const m = (L - 0.1055613458 * A - 0.0638541728 * B) ** 3;
|
|
292
|
+
const s = (L - 0.0894841775 * A - 1.291485548 * B) ** 3;
|
|
293
|
+
return [
|
|
294
|
+
gamma(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
|
|
295
|
+
gamma(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
|
|
296
|
+
gamma(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s)
|
|
297
|
+
];
|
|
298
|
+
}
|
|
299
|
+
function mixColors(color, base, amount) {
|
|
300
|
+
const a = toOklab(parseColor(color));
|
|
301
|
+
const b = toOklab(parseColor(base));
|
|
302
|
+
const t = Math.min(1, Math.max(0, amount));
|
|
303
|
+
const [L, A, B] = a.map((v, i) => v * t + b[i] * (1 - t));
|
|
304
|
+
return toHex(oklabToRgb(L, A, B));
|
|
305
|
+
}
|
|
306
|
+
// src/tokens/css.ts
|
|
307
|
+
var CSS_VAR_PREFIX = "dou";
|
|
308
|
+
function cssVarName(path) {
|
|
309
|
+
const segments = path.split(".").filter((segment) => segment !== "DEFAULT").map(kebab);
|
|
310
|
+
return `--${CSS_VAR_PREFIX}-${segments.join("-")}`;
|
|
311
|
+
}
|
|
312
|
+
function flattenTokens(tokens) {
|
|
313
|
+
const entries = [];
|
|
314
|
+
const walk = (node, path) => {
|
|
315
|
+
if (typeof node === "string") {
|
|
316
|
+
entries.push([cssVarName(path.join(".")), node]);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (typeof node === "object" && node !== null) {
|
|
320
|
+
for (const [key, value] of Object.entries(node))
|
|
321
|
+
walk(value, [...path, key]);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
walk(tokens, []);
|
|
325
|
+
return entries;
|
|
326
|
+
}
|
|
327
|
+
function themeToCss(tokens, selector = ":root") {
|
|
328
|
+
const body = flattenTokens(tokens).map(([name, value]) => ` ${name}: ${value};`).join(`
|
|
329
|
+
`);
|
|
330
|
+
return `${selector} {
|
|
331
|
+
${body}
|
|
332
|
+
}
|
|
333
|
+
`;
|
|
334
|
+
}
|
|
335
|
+
function kebab(value) {
|
|
336
|
+
return value.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
|
|
337
|
+
}
|
|
338
|
+
// src/breakpoints.ts
|
|
339
|
+
var breakpoints = {
|
|
340
|
+
sm: 640,
|
|
341
|
+
md: 768,
|
|
342
|
+
lg: 1024,
|
|
343
|
+
xl: 1280
|
|
344
|
+
};
|
|
345
|
+
// src/collaboration.ts
|
|
346
|
+
var collaborationColors = [
|
|
347
|
+
"#3b6ea8",
|
|
348
|
+
"#a8553b",
|
|
349
|
+
"#3b8a6e",
|
|
350
|
+
"#8a3b7a",
|
|
351
|
+
"#8a7a3b",
|
|
352
|
+
"#5b4fa8",
|
|
353
|
+
"#3b8a8a",
|
|
354
|
+
"#a83b55"
|
|
355
|
+
];
|
|
356
|
+
export {
|
|
357
|
+
CSS_VAR_PREFIX,
|
|
358
|
+
breakpoints,
|
|
359
|
+
collaborationColors,
|
|
360
|
+
contrastRatio,
|
|
361
|
+
createTheme,
|
|
362
|
+
createTone,
|
|
363
|
+
cssVarName,
|
|
364
|
+
dark,
|
|
365
|
+
defineTheme,
|
|
366
|
+
flattenTokens,
|
|
367
|
+
light,
|
|
368
|
+
mixColors,
|
|
369
|
+
parseColor,
|
|
370
|
+
themeToCss
|
|
371
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ThemeTokens, ToneTokens } from './types';
|
|
2
|
+
/** Brand colors to build a theme from. Any tone left out keeps the base theme's value. */
|
|
3
|
+
export interface ThemeColors {
|
|
4
|
+
primary?: string;
|
|
5
|
+
success?: string;
|
|
6
|
+
warning?: string;
|
|
7
|
+
danger?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateThemeOptions {
|
|
10
|
+
/** Light theme to start from. Defaults to the built-in `light`. */
|
|
11
|
+
light?: ThemeTokens;
|
|
12
|
+
/** Dark theme to start from. Defaults to the built-in `dark`. */
|
|
13
|
+
dark?: ThemeTokens;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build a light and a dark theme from a few brand colors.
|
|
17
|
+
*
|
|
18
|
+
* Each color becomes a full tone: the color itself, the text color that
|
|
19
|
+
* reads on it, and a version that reads as text on the page. Lightness is
|
|
20
|
+
* adjusted in OKLCH until every pair reaches 4.5:1, so the hue stays
|
|
21
|
+
* recognizable while text stays legible. The focus ring follows `primary`.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const { light, dark } = createTheme({ primary: '#7c3aed' })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function createTheme(colors: ThemeColors, options?: CreateThemeOptions): {
|
|
28
|
+
light: ThemeTokens;
|
|
29
|
+
dark: ThemeTokens;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Turn one color into a tone for the given theme. The theme's backgrounds
|
|
33
|
+
* decide whether it is light or dark, and which surfaces the tone's text
|
|
34
|
+
* has to read on.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createTone(value: string, base?: ThemeTokens): ToneTokens;
|
|
37
|
+
/** WCAG contrast ratio between two colors, from 1 to 21. */
|
|
38
|
+
export declare function contrastRatio(a: string, b: string): number;
|
|
39
|
+
type Rgb = [number, number, number];
|
|
40
|
+
/** Parse `#rgb`, `#rrggbb` or `rgb(r g b)` / `rgb(r, g, b)` into 0–1 channels. */
|
|
41
|
+
export declare function parseColor(value: string): Rgb;
|
|
42
|
+
/**
|
|
43
|
+
* `amount` (0–1) of `color` mixed into `base` in OKLab, as CSS
|
|
44
|
+
* `color-mix(in oklab, color amount, base)` does, as `#rrggbb`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function mixColors(color: string, base: string, amount: number): string;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ThemeTokens } from './types';
|
|
2
|
+
export declare const CSS_VAR_PREFIX = "dou";
|
|
3
|
+
/**
|
|
4
|
+
* Turn a token path into its CSS custom property name.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* cssVarName('color.primary') // '--dou-color-primary'
|
|
8
|
+
* cssVarName('control.height.md') // '--dou-control-height-md'
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function cssVarName(path: string): string;
|
|
12
|
+
/** Flatten a token tree into `[cssVarName, value]` pairs. */
|
|
13
|
+
export declare function flattenTokens(tokens: ThemeTokens): Array<[string, string]>;
|
|
14
|
+
/**
|
|
15
|
+
* Serialize a theme into a CSS rule.
|
|
16
|
+
*
|
|
17
|
+
* Themes are plain custom properties, so they can be scoped to any subtree:
|
|
18
|
+
* pass a selector such as `.sidebar` to theme only part of a page.
|
|
19
|
+
*/
|
|
20
|
+
export declare function themeToCss(tokens: ThemeTokens, selector?: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DeepPartial, ThemeTokens } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Create a theme by overriding parts of a base theme.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const brand = defineTheme(light, { color: { primary: { DEFAULT: '#7c3aed' } } })
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare function defineTheme(base: ThemeTokens, overrides: DeepPartial<ThemeTokens>): ThemeTokens;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ThemeTokens } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Light theme.
|
|
4
|
+
*
|
|
5
|
+
* Ink on paper: the interface is built from near-black, white and a
|
|
6
|
+
* narrow band of warm-neutral grays. Hue is reserved for meaning
|
|
7
|
+
* (primary action, success, warning, danger) and is kept desaturated so
|
|
8
|
+
* it never shouts.
|
|
9
|
+
*/
|
|
10
|
+
export declare const light: ThemeTokens;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape every DouUI theme must satisfy.
|
|
3
|
+
*
|
|
4
|
+
* Tokens describe *roles* (what a value is for), never raw palette steps.
|
|
5
|
+
* Components only ever read these roles, so a theme can change the whole
|
|
6
|
+
* look without touching a single component.
|
|
7
|
+
*
|
|
8
|
+
* A nested key becomes a CSS custom property by joining the path with `-`
|
|
9
|
+
* and converting camelCase to kebab-case. The special key `DEFAULT` is
|
|
10
|
+
* dropped from the path:
|
|
11
|
+
*
|
|
12
|
+
* color.primary.DEFAULT -> --dou-color-primary
|
|
13
|
+
* color.primary.on -> --dou-color-primary-on
|
|
14
|
+
* control.height.md -> --dou-control-height-md
|
|
15
|
+
*/
|
|
16
|
+
export interface ThemeTokens {
|
|
17
|
+
/**
|
|
18
|
+
* Which side of the light / dark split the theme is on, as a number so
|
|
19
|
+
* styles can mix between a light and a dark value with it:
|
|
20
|
+
* `calc(4% * var(--dou-scheme-dark))` is `0%` in a light theme and `4%`
|
|
21
|
+
* in a dark one. Components take their light and dark variants from this
|
|
22
|
+
* token rather than from `color-scheme`, so a theme is decided by its
|
|
23
|
+
* tokens alone, under any selector.
|
|
24
|
+
*/
|
|
25
|
+
scheme: {
|
|
26
|
+
/** `'0'` in light themes, `'1'` in dark ones. */
|
|
27
|
+
dark: '0' | '1';
|
|
28
|
+
};
|
|
29
|
+
color: {
|
|
30
|
+
/** Brand / main call to action. */
|
|
31
|
+
primary: ToneTokens;
|
|
32
|
+
/** Default tone for everyday, low-emphasis actions. */
|
|
33
|
+
neutral: ToneTokens;
|
|
34
|
+
success: ToneTokens;
|
|
35
|
+
warning: ToneTokens;
|
|
36
|
+
danger: ToneTokens;
|
|
37
|
+
bg: {
|
|
38
|
+
/** The page itself. */
|
|
39
|
+
canvas: string;
|
|
40
|
+
/** Cards, popovers, inputs: anything sitting on the canvas. */
|
|
41
|
+
surface: string;
|
|
42
|
+
/** Recessed or disabled areas. */
|
|
43
|
+
muted: string;
|
|
44
|
+
};
|
|
45
|
+
text: {
|
|
46
|
+
/** Headings and body copy. */
|
|
47
|
+
DEFAULT: string;
|
|
48
|
+
/** Supporting copy, labels, descriptions. */
|
|
49
|
+
secondary: string;
|
|
50
|
+
/** Placeholders, hints, meta information. */
|
|
51
|
+
tertiary: string;
|
|
52
|
+
disabled: string;
|
|
53
|
+
};
|
|
54
|
+
border: {
|
|
55
|
+
/** Hairlines between areas, e.g. dividers and table rows. */
|
|
56
|
+
subtle: string;
|
|
57
|
+
/** Outlines of controls and containers. */
|
|
58
|
+
DEFAULT: string;
|
|
59
|
+
/** Hovered outlines and emphasis. */
|
|
60
|
+
strong: string;
|
|
61
|
+
};
|
|
62
|
+
/** Focus ring color. */
|
|
63
|
+
focus: string;
|
|
64
|
+
/**
|
|
65
|
+
* Mixed into a tone to draw the edge of filled controls, so a solid
|
|
66
|
+
* button reads as a pressed-in shape rather than a flat block.
|
|
67
|
+
*/
|
|
68
|
+
edge: string;
|
|
69
|
+
/**
|
|
70
|
+
* Categorical colors for chart series, in the order they are used. The
|
|
71
|
+
* first is neutral, so a chart with one series is not colored for no
|
|
72
|
+
* reason; the rest are low-saturation hues told apart by lightness as
|
|
73
|
+
* well, so they stay distinct for common color-vision deficiencies.
|
|
74
|
+
*/
|
|
75
|
+
chart: ChartPalette;
|
|
76
|
+
/**
|
|
77
|
+
* Code colors by token kind (`--dou-color-syntax-keyword`, …), shared by
|
|
78
|
+
* the code editor and code blocks. Deep, low-saturation hues on the
|
|
79
|
+
* surface; plain names and punctuation stay in the text colors, so the
|
|
80
|
+
* hue lands on what tells code apart.
|
|
81
|
+
*/
|
|
82
|
+
syntax: SyntaxPalette;
|
|
83
|
+
};
|
|
84
|
+
font: {
|
|
85
|
+
family: string;
|
|
86
|
+
familyMono: string;
|
|
87
|
+
size: SizeScale;
|
|
88
|
+
weight: {
|
|
89
|
+
regular: string;
|
|
90
|
+
medium: string;
|
|
91
|
+
bold: string;
|
|
92
|
+
};
|
|
93
|
+
lineHeight: string;
|
|
94
|
+
};
|
|
95
|
+
radius: {
|
|
96
|
+
/** Buttons, inputs and other interactive controls. */
|
|
97
|
+
control: string;
|
|
98
|
+
/** Cards, dialogs and other containers. */
|
|
99
|
+
container: string;
|
|
100
|
+
full: string;
|
|
101
|
+
};
|
|
102
|
+
/** Shared sizing of interactive controls so they line up in a row. */
|
|
103
|
+
control: {
|
|
104
|
+
height: SizeScale;
|
|
105
|
+
paddingX: SizeScale;
|
|
106
|
+
gap: SizeScale;
|
|
107
|
+
};
|
|
108
|
+
/** Gaps between neighbouring elements, e.g. items in a row of buttons. */
|
|
109
|
+
space: SizeScale;
|
|
110
|
+
/**
|
|
111
|
+
* Elevation. Hierarchy comes from surface and border first; shadows
|
|
112
|
+
* stay faint and are reserved for things that float above the page.
|
|
113
|
+
*/
|
|
114
|
+
shadow: {
|
|
115
|
+
/** Resting controls such as outlined buttons and inputs. */
|
|
116
|
+
sm: string;
|
|
117
|
+
/** Cards and menus. */
|
|
118
|
+
md: string;
|
|
119
|
+
/** Dialogs and other overlays. */
|
|
120
|
+
lg: string;
|
|
121
|
+
/** Inner top light on filled controls, a hint of bevel. */
|
|
122
|
+
highlight: string;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Motion. Things that appear decelerate into place, things that leave
|
|
126
|
+
* accelerate away and take less time. Distances stay small, and
|
|
127
|
+
* reduced-motion settings override these values page-wide.
|
|
128
|
+
*/
|
|
129
|
+
motion: {
|
|
130
|
+
duration: {
|
|
131
|
+
/** Color and opacity feedback, and every fade under reduced motion. */
|
|
132
|
+
instant: string;
|
|
133
|
+
/** Hover and press, small rotations, popups leaving. */
|
|
134
|
+
fast: string;
|
|
135
|
+
/** Popups and dialogs entering, disclosure, indicators moving. */
|
|
136
|
+
normal: string;
|
|
137
|
+
/** Panels that travel across the screen, such as drawers. */
|
|
138
|
+
slow: string;
|
|
139
|
+
};
|
|
140
|
+
easing: {
|
|
141
|
+
/** Changes between two states of something already on screen. */
|
|
142
|
+
DEFAULT: string;
|
|
143
|
+
/** Something appearing: fast start, gentle stop. */
|
|
144
|
+
enter: string;
|
|
145
|
+
/** Something leaving: gentle start, fast finish. */
|
|
146
|
+
exit: string;
|
|
147
|
+
/**
|
|
148
|
+
* Overshoots and settles back. Only for direct manipulation, where
|
|
149
|
+
* the element answers a finger or pointer that is still on it.
|
|
150
|
+
*/
|
|
151
|
+
spring: string;
|
|
152
|
+
};
|
|
153
|
+
/** How far things travel when entering or leaving. */
|
|
154
|
+
distance: {
|
|
155
|
+
sm: string;
|
|
156
|
+
md: string;
|
|
157
|
+
};
|
|
158
|
+
/** The scale things start from when they appear. */
|
|
159
|
+
scale: string;
|
|
160
|
+
/** Periods of looping animations. */
|
|
161
|
+
loop: {
|
|
162
|
+
/** Spinners and indeterminate progress. */
|
|
163
|
+
spin: string;
|
|
164
|
+
/** Breathing, blinking and typing dots. */
|
|
165
|
+
pulse: string;
|
|
166
|
+
/** Placeholder sweeps and ripples. */
|
|
167
|
+
sweep: string;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** A tone is a single color plus the color that reads on top of it. */
|
|
172
|
+
export interface ToneTokens {
|
|
173
|
+
DEFAULT: string;
|
|
174
|
+
/** Foreground (text / icon) color used on a solid `DEFAULT` background. */
|
|
175
|
+
on: string;
|
|
176
|
+
/**
|
|
177
|
+
* The tone used as text on the page or on a faint tint of itself (soft
|
|
178
|
+
* buttons and tags, links, toned text). Usually `DEFAULT`; dark themes
|
|
179
|
+
* lighten it, because one color cannot both carry white text and read
|
|
180
|
+
* as text on a dark page.
|
|
181
|
+
*/
|
|
182
|
+
text: string;
|
|
183
|
+
}
|
|
184
|
+
/** Eight series colors, `--dou-color-chart-1` to `--dou-color-chart-8`. */
|
|
185
|
+
export interface ChartPalette {
|
|
186
|
+
1: string;
|
|
187
|
+
2: string;
|
|
188
|
+
3: string;
|
|
189
|
+
4: string;
|
|
190
|
+
5: string;
|
|
191
|
+
6: string;
|
|
192
|
+
7: string;
|
|
193
|
+
8: string;
|
|
194
|
+
}
|
|
195
|
+
/** One color per kind of code token. */
|
|
196
|
+
export interface SyntaxPalette {
|
|
197
|
+
keyword: string;
|
|
198
|
+
string: string;
|
|
199
|
+
number: string;
|
|
200
|
+
comment: string;
|
|
201
|
+
function: string;
|
|
202
|
+
type: string;
|
|
203
|
+
variable: string;
|
|
204
|
+
property: string;
|
|
205
|
+
operator: string;
|
|
206
|
+
punctuation: string;
|
|
207
|
+
tag: string;
|
|
208
|
+
attribute: string;
|
|
209
|
+
meta: string;
|
|
210
|
+
invalid: string;
|
|
211
|
+
}
|
|
212
|
+
export interface SizeScale {
|
|
213
|
+
sm: string;
|
|
214
|
+
md: string;
|
|
215
|
+
lg: string;
|
|
216
|
+
}
|
|
217
|
+
/** Recursively optional version of a token tree, for partial overrides. */
|
|
218
|
+
export type DeepPartial<T> = {
|
|
219
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
220
|
+
};
|