@cicord/ui 0.0.0-bootstrap.0 → 0.1.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 +202 -0
- package/README.md +30 -0
- package/dist/index.d.mts +225 -0
- package/dist/index.mjs +758 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +689 -0
- package/package.json +68 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,758 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
// src/color.ts
|
|
4
|
+
function parseHex(value) {
|
|
5
|
+
if (!value) return void 0;
|
|
6
|
+
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(value.trim());
|
|
7
|
+
if (!m) return void 0;
|
|
8
|
+
let hex = m[1];
|
|
9
|
+
if (hex.length === 3) hex = Array.from(hex).map((c) => c + c).join("");
|
|
10
|
+
const n = Number.parseInt(hex, 16);
|
|
11
|
+
return [
|
|
12
|
+
n >> 16 & 255,
|
|
13
|
+
n >> 8 & 255,
|
|
14
|
+
n & 255
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
function toHex([r, g, b]) {
|
|
18
|
+
return `#${[
|
|
19
|
+
r,
|
|
20
|
+
g,
|
|
21
|
+
b
|
|
22
|
+
].map((c) => Math.round(Math.max(0, Math.min(255, c))).toString(16).padStart(2, "0")).join("")}`;
|
|
23
|
+
}
|
|
24
|
+
/** WCAG relative luminance. */
|
|
25
|
+
function luminance([r, g, b]) {
|
|
26
|
+
const lin = (c) => {
|
|
27
|
+
const s = c / 255;
|
|
28
|
+
return s <= .03928 ? s / 12.92 : ((s + .055) / 1.055) ** 2.4;
|
|
29
|
+
};
|
|
30
|
+
return .2126 * lin(r) + .7152 * lin(g) + .0722 * lin(b);
|
|
31
|
+
}
|
|
32
|
+
function contrast(a, b) {
|
|
33
|
+
const [hi, lo] = [luminance(a), luminance(b)].toSorted((x, y) => y - x);
|
|
34
|
+
return (hi + .05) / (lo + .05);
|
|
35
|
+
}
|
|
36
|
+
function mix(a, b, amount) {
|
|
37
|
+
return [
|
|
38
|
+
a[0] + (b[0] - a[0]) * amount,
|
|
39
|
+
a[1] + (b[1] - a[1]) * amount,
|
|
40
|
+
a[2] + (b[2] - a[2]) * amount
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
const WHITE = [
|
|
44
|
+
255,
|
|
45
|
+
255,
|
|
46
|
+
255
|
|
47
|
+
];
|
|
48
|
+
const INK = [
|
|
49
|
+
16,
|
|
50
|
+
17,
|
|
51
|
+
24
|
|
52
|
+
];
|
|
53
|
+
/** Text color (white or ink) with the best contrast on `background`. */
|
|
54
|
+
function readableOn(background) {
|
|
55
|
+
return contrast(background, WHITE) >= contrast(background, INK) ? "#ffffff" : toHex(INK);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Variant of `color` usable as text/icon on `surface` (WCAG ≥ `target`): mixed toward white
|
|
59
|
+
* on dark surfaces and toward ink on light ones, as little as needed.
|
|
60
|
+
*/
|
|
61
|
+
function legibleOn(color, surface, target = 4.5) {
|
|
62
|
+
const toward = luminance(surface) < .4 ? WHITE : INK;
|
|
63
|
+
for (let step = 0; step <= 20; step++) {
|
|
64
|
+
const candidate = toHex(mix(color, toward, step / 20));
|
|
65
|
+
if (contrast(parseHex(candidate), surface) >= target) return candidate;
|
|
66
|
+
}
|
|
67
|
+
return toHex(toward);
|
|
68
|
+
}
|
|
69
|
+
// src/theme.tsx
|
|
70
|
+
const DEFAULT_PRIMARY = "#5865f2";
|
|
71
|
+
const DEFAULT_ACCENT = "#eb459e";
|
|
72
|
+
const DEFAULT_PRIMARY_RGB = parseHex(DEFAULT_PRIMARY);
|
|
73
|
+
const DEFAULT_ACCENT_RGB = parseHex(DEFAULT_ACCENT);
|
|
74
|
+
const SURFACE = {
|
|
75
|
+
dark: [
|
|
76
|
+
27,
|
|
77
|
+
29,
|
|
78
|
+
38
|
|
79
|
+
],
|
|
80
|
+
light: [
|
|
81
|
+
255,
|
|
82
|
+
255,
|
|
83
|
+
255
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
/** CSS custom properties for a theme in a given mode. */
|
|
87
|
+
function themeVariables(theme, mode) {
|
|
88
|
+
const primary = parseHex(theme?.primary) ?? DEFAULT_PRIMARY_RGB;
|
|
89
|
+
const accent = parseHex(theme?.accent) ?? DEFAULT_ACCENT_RGB;
|
|
90
|
+
const surface = SURFACE[mode];
|
|
91
|
+
return {
|
|
92
|
+
"--cicord-primary": toHex(primary),
|
|
93
|
+
"--cicord-primary-fg": readableOn(primary),
|
|
94
|
+
"--cicord-primary-text": legibleOn(primary, surface),
|
|
95
|
+
"--cicord-accent": toHex(accent),
|
|
96
|
+
"--cicord-accent-fg": readableOn(accent),
|
|
97
|
+
"--cicord-accent-text": legibleOn(accent, surface)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function systemMode() {
|
|
101
|
+
if (typeof window === "undefined" || !window.matchMedia) return "dark";
|
|
102
|
+
return window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
|
|
103
|
+
}
|
|
104
|
+
/** Resolves "system" with `prefers-color-scheme` and follows its changes. Default: dark. */
|
|
105
|
+
function useResolvedMode(mode) {
|
|
106
|
+
const [system, setSystem] = useState(systemMode);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (mode !== "system" || typeof window === "undefined" || !window.matchMedia) return void 0;
|
|
109
|
+
const media = window.matchMedia("(prefers-color-scheme: light)");
|
|
110
|
+
const update = () => setSystem(media.matches ? "light" : "dark");
|
|
111
|
+
update();
|
|
112
|
+
media.addEventListener("change", update);
|
|
113
|
+
return () => media.removeEventListener("change", update);
|
|
114
|
+
}, [mode]);
|
|
115
|
+
if (mode === "light" || mode === "dark") return mode;
|
|
116
|
+
if (mode === "system") return system;
|
|
117
|
+
return "dark";
|
|
118
|
+
}
|
|
119
|
+
const ThemeContext = createContext({
|
|
120
|
+
theme: {},
|
|
121
|
+
mode: "dark"
|
|
122
|
+
});
|
|
123
|
+
function useCicordTheme() {
|
|
124
|
+
return useContext(ThemeContext);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Maps the server theme `{primary, accent, mode}` to CSS variables (`--cicord-*`) and a
|
|
128
|
+
* `data-cicord-mode` attribute that switches the light/dark palettes of styles.css.
|
|
129
|
+
*/
|
|
130
|
+
function ThemeProvider({ theme, mode, global = false, className, style, children }) {
|
|
131
|
+
const resolved = useResolvedMode(mode ?? theme?.mode);
|
|
132
|
+
const vars = useMemo(() => themeVariables(theme, resolved), [theme, resolved]);
|
|
133
|
+
const value = useMemo(() => ({
|
|
134
|
+
theme: theme ?? {},
|
|
135
|
+
mode: resolved
|
|
136
|
+
}), [theme, resolved]);
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
if (!global || typeof document === "undefined") return void 0;
|
|
139
|
+
const root = document.documentElement;
|
|
140
|
+
const previous = root.getAttribute("data-cicord-mode");
|
|
141
|
+
root.setAttribute("data-cicord-mode", resolved);
|
|
142
|
+
root.style.colorScheme = resolved;
|
|
143
|
+
for (const [k, v] of Object.entries(vars)) root.style.setProperty(k, v);
|
|
144
|
+
root.classList.add("cicord-root");
|
|
145
|
+
return () => {
|
|
146
|
+
if (previous === null) root.removeAttribute("data-cicord-mode");
|
|
147
|
+
else root.setAttribute("data-cicord-mode", previous);
|
|
148
|
+
for (const k of Object.keys(vars)) root.style.removeProperty(k);
|
|
149
|
+
};
|
|
150
|
+
}, [
|
|
151
|
+
global,
|
|
152
|
+
resolved,
|
|
153
|
+
vars
|
|
154
|
+
]);
|
|
155
|
+
return /* @__PURE__ */ jsx(ThemeContext.Provider, {
|
|
156
|
+
value,
|
|
157
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
158
|
+
className: ["cicord-root", className].filter(Boolean).join(" "),
|
|
159
|
+
"data-cicord-mode": resolved,
|
|
160
|
+
style: {
|
|
161
|
+
...vars,
|
|
162
|
+
colorScheme: resolved,
|
|
163
|
+
...style
|
|
164
|
+
},
|
|
165
|
+
children
|
|
166
|
+
})
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
// src/components.tsx
|
|
170
|
+
const cx = (...parts) => parts.filter(Boolean).join(" ");
|
|
171
|
+
function Spinner({ size = "md", label = "Loading", className }) {
|
|
172
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
173
|
+
role: "status",
|
|
174
|
+
className: cx("cicord-spinner", `cicord-spinner--${size}`, className),
|
|
175
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
176
|
+
className: "cicord-spinner__ring",
|
|
177
|
+
"aria-hidden": "true"
|
|
178
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
179
|
+
className: "cicord-visually-hidden",
|
|
180
|
+
children: label
|
|
181
|
+
})]
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function buttonClass({ variant = "primary", size = "md", block, loading }, className) {
|
|
185
|
+
return cx("cicord-button", `cicord-button--${variant}`, `cicord-button--${size}`, block && "cicord-button--block", loading && "is-loading", className);
|
|
186
|
+
}
|
|
187
|
+
function Button({ variant, size, loading = false, icon, block, className, children, disabled, type = "button", ...rest }) {
|
|
188
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
189
|
+
...rest,
|
|
190
|
+
type,
|
|
191
|
+
className: buttonClass({
|
|
192
|
+
variant,
|
|
193
|
+
size,
|
|
194
|
+
block,
|
|
195
|
+
loading
|
|
196
|
+
}, className),
|
|
197
|
+
disabled: disabled || loading,
|
|
198
|
+
"aria-busy": loading || void 0,
|
|
199
|
+
children: [loading ? /* @__PURE__ */ jsx(Spinner, {
|
|
200
|
+
size: "sm",
|
|
201
|
+
label: ""
|
|
202
|
+
}) : icon ? /* @__PURE__ */ jsx("span", {
|
|
203
|
+
className: "cicord-button__icon",
|
|
204
|
+
"aria-hidden": "true",
|
|
205
|
+
children: icon
|
|
206
|
+
}) : null, /* @__PURE__ */ jsx("span", {
|
|
207
|
+
className: "cicord-button__label",
|
|
208
|
+
children
|
|
209
|
+
})]
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/** A link styled as a button (navigation, external URLs). */
|
|
213
|
+
function LinkButton({ variant, size, loading, icon, block, className, children, ...rest }) {
|
|
214
|
+
return /* @__PURE__ */ jsxs("a", {
|
|
215
|
+
...rest,
|
|
216
|
+
className: buttonClass({
|
|
217
|
+
variant,
|
|
218
|
+
size,
|
|
219
|
+
block,
|
|
220
|
+
loading
|
|
221
|
+
}, className),
|
|
222
|
+
children: [icon ? /* @__PURE__ */ jsx("span", {
|
|
223
|
+
className: "cicord-button__icon",
|
|
224
|
+
"aria-hidden": "true",
|
|
225
|
+
children: icon
|
|
226
|
+
}) : null, /* @__PURE__ */ jsx("span", {
|
|
227
|
+
className: "cicord-button__label",
|
|
228
|
+
children
|
|
229
|
+
})]
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function Card({ as: Tag = "div", padding = "md", tone = "raised", className, ...rest }) {
|
|
233
|
+
return /* @__PURE__ */ jsx(Tag, {
|
|
234
|
+
...rest,
|
|
235
|
+
className: cx("cicord-card", `cicord-card--${tone}`, `cicord-card--pad-${padding}`, className)
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function hue(text) {
|
|
239
|
+
let h = 0;
|
|
240
|
+
for (const ch of text) h = (h * 31 + ch.codePointAt(0)) % 360;
|
|
241
|
+
return h;
|
|
242
|
+
}
|
|
243
|
+
function initials(name) {
|
|
244
|
+
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
245
|
+
return (words.length > 1 ? [words[0], words[1]].map((w) => Array.from(w)[0]) : Array.from(words[0] ?? "?").slice(0, 1)).join("").toUpperCase();
|
|
246
|
+
}
|
|
247
|
+
function Avatar({ src, name, size = 40, ring, className }) {
|
|
248
|
+
const [failed, setFailed] = useState(false);
|
|
249
|
+
const style = {
|
|
250
|
+
"--cicord-avatar-size": `${size}px`,
|
|
251
|
+
"--cicord-avatar-hue": hue(name),
|
|
252
|
+
...ring ? { "--cicord-avatar-ring": ring } : {}
|
|
253
|
+
};
|
|
254
|
+
return /* @__PURE__ */ jsx("span", {
|
|
255
|
+
className: cx("cicord-avatar", ring && "cicord-avatar--ring", className),
|
|
256
|
+
style,
|
|
257
|
+
children: src && !failed ? /* @__PURE__ */ jsx("img", {
|
|
258
|
+
src,
|
|
259
|
+
alt: name,
|
|
260
|
+
width: size,
|
|
261
|
+
height: size,
|
|
262
|
+
onError: () => setFailed(true)
|
|
263
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
264
|
+
role: "img",
|
|
265
|
+
"aria-label": name,
|
|
266
|
+
className: "cicord-avatar__initials",
|
|
267
|
+
children: initials(name)
|
|
268
|
+
})
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/** A Discord-style role pill with its color dot. */
|
|
272
|
+
function RoleChip({ name, color, size = "md", fresh, className, style }) {
|
|
273
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
274
|
+
className: cx("cicord-role-chip", `cicord-role-chip--${size}`, fresh && "is-fresh", className),
|
|
275
|
+
style: {
|
|
276
|
+
...color ? { "--cicord-role": color } : {},
|
|
277
|
+
...style
|
|
278
|
+
},
|
|
279
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
280
|
+
className: "cicord-role-chip__dot",
|
|
281
|
+
"aria-hidden": "true"
|
|
282
|
+
}), name]
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
/** `--cicord-role` plus a readable foreground for marks drawn on it. */
|
|
286
|
+
function roleStyle(color) {
|
|
287
|
+
const rgb = parseHex(color);
|
|
288
|
+
if (!rgb) return void 0;
|
|
289
|
+
return {
|
|
290
|
+
"--cicord-role": color,
|
|
291
|
+
"--cicord-role-fg": readableOn(rgb)
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/** Group of ChoiceTiles: a `group` of checkboxes, or a `radiogroup`. */
|
|
295
|
+
function ChoiceGroup({ label, labelledBy, multiple = false, children, className }) {
|
|
296
|
+
const ref = useRef(null);
|
|
297
|
+
const radios = () => Array.from(ref.current?.querySelectorAll("[role=\"radio\"]:not(:disabled)") ?? []);
|
|
298
|
+
useLayoutEffect(() => {
|
|
299
|
+
if (multiple) return;
|
|
300
|
+
const all = radios();
|
|
301
|
+
const checked = all.findIndex((r) => r.getAttribute("aria-checked") === "true");
|
|
302
|
+
all.forEach((r, i) => r.tabIndex = i === (checked >= 0 ? checked : 0) ? 0 : -1);
|
|
303
|
+
});
|
|
304
|
+
const onKeyDown = (event) => {
|
|
305
|
+
if (multiple) return;
|
|
306
|
+
const delta = {
|
|
307
|
+
ArrowDown: 1,
|
|
308
|
+
ArrowRight: 1,
|
|
309
|
+
ArrowUp: -1,
|
|
310
|
+
ArrowLeft: -1
|
|
311
|
+
}[event.key];
|
|
312
|
+
if (!delta) return;
|
|
313
|
+
const all = radios();
|
|
314
|
+
const current = all.indexOf(document.activeElement);
|
|
315
|
+
if (current < 0) return;
|
|
316
|
+
event.preventDefault();
|
|
317
|
+
const next = all[(current + delta + all.length) % all.length];
|
|
318
|
+
next?.focus();
|
|
319
|
+
next?.click();
|
|
320
|
+
};
|
|
321
|
+
return /* @__PURE__ */ jsx("div", {
|
|
322
|
+
ref,
|
|
323
|
+
role: multiple ? "group" : "radiogroup",
|
|
324
|
+
...labelledBy ? { "aria-labelledby": labelledBy } : { "aria-label": label },
|
|
325
|
+
className: cx("cicord-choice-group", className),
|
|
326
|
+
onKeyDown,
|
|
327
|
+
children
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/** Large selectable tile (checkbox or radio) for picking a role. */
|
|
331
|
+
function ChoiceTile({ label, description, emoji, color, selected, multiple = false, disabled, onToggle, className }) {
|
|
332
|
+
const descriptionId = useId();
|
|
333
|
+
const labelId = useId();
|
|
334
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
335
|
+
type: "button",
|
|
336
|
+
role: multiple ? "checkbox" : "radio",
|
|
337
|
+
"aria-checked": selected,
|
|
338
|
+
"aria-labelledby": labelId,
|
|
339
|
+
"aria-describedby": description ? descriptionId : void 0,
|
|
340
|
+
disabled,
|
|
341
|
+
onClick: onToggle,
|
|
342
|
+
className: cx("cicord-choice", selected && "is-selected", className),
|
|
343
|
+
style: roleStyle(color),
|
|
344
|
+
children: [
|
|
345
|
+
/* @__PURE__ */ jsx("span", {
|
|
346
|
+
className: "cicord-choice__emoji",
|
|
347
|
+
"aria-hidden": "true",
|
|
348
|
+
children: emoji || /* @__PURE__ */ jsx("span", { className: "cicord-choice__dot" })
|
|
349
|
+
}),
|
|
350
|
+
/* @__PURE__ */ jsxs("span", {
|
|
351
|
+
className: "cicord-choice__text",
|
|
352
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
353
|
+
id: labelId,
|
|
354
|
+
className: "cicord-choice__label",
|
|
355
|
+
children: label
|
|
356
|
+
}), description ? /* @__PURE__ */ jsx("span", {
|
|
357
|
+
id: descriptionId,
|
|
358
|
+
className: "cicord-choice__description",
|
|
359
|
+
children: description
|
|
360
|
+
}) : null]
|
|
361
|
+
}),
|
|
362
|
+
/* @__PURE__ */ jsx("span", {
|
|
363
|
+
className: cx("cicord-choice__mark", multiple ? "is-check" : "is-radio"),
|
|
364
|
+
"aria-hidden": "true",
|
|
365
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
366
|
+
viewBox: "0 0 16 16",
|
|
367
|
+
width: "12",
|
|
368
|
+
height: "12",
|
|
369
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
370
|
+
d: "M3.5 8.5l3 3 6-7",
|
|
371
|
+
fill: "none",
|
|
372
|
+
stroke: "currentColor",
|
|
373
|
+
strokeWidth: "2.2",
|
|
374
|
+
strokeLinecap: "round",
|
|
375
|
+
strokeLinejoin: "round"
|
|
376
|
+
})
|
|
377
|
+
})
|
|
378
|
+
})
|
|
379
|
+
]
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
function Stepper({ steps, current, done, onSelect, label = "Progress", className }) {
|
|
383
|
+
const isDone = (i) => done ? done.includes(i) : i < current;
|
|
384
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
385
|
+
"aria-label": label,
|
|
386
|
+
className: cx("cicord-stepper", className),
|
|
387
|
+
children: /* @__PURE__ */ jsx("ol", { children: steps.map((step, i) => {
|
|
388
|
+
const state = i === current ? "current" : isDone(i) ? "done" : "todo";
|
|
389
|
+
const clickable = onSelect && (state === "done" || i < current);
|
|
390
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
391
|
+
className: "cicord-stepper__index",
|
|
392
|
+
"aria-hidden": "true",
|
|
393
|
+
children: state === "done" ? /* @__PURE__ */ jsx("svg", {
|
|
394
|
+
viewBox: "0 0 16 16",
|
|
395
|
+
width: "11",
|
|
396
|
+
height: "11",
|
|
397
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
398
|
+
d: "M3.5 8.5l3 3 6-7",
|
|
399
|
+
fill: "none",
|
|
400
|
+
stroke: "currentColor",
|
|
401
|
+
strokeWidth: "2.4",
|
|
402
|
+
strokeLinecap: "round",
|
|
403
|
+
strokeLinejoin: "round"
|
|
404
|
+
})
|
|
405
|
+
}) : i + 1
|
|
406
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
407
|
+
className: "cicord-stepper__label",
|
|
408
|
+
children: step.label
|
|
409
|
+
})] });
|
|
410
|
+
return /* @__PURE__ */ jsx("li", {
|
|
411
|
+
className: `cicord-stepper__step is-${state}`,
|
|
412
|
+
"aria-current": state === "current" ? "step" : void 0,
|
|
413
|
+
children: clickable ? /* @__PURE__ */ jsx("button", {
|
|
414
|
+
type: "button",
|
|
415
|
+
onClick: () => onSelect(i),
|
|
416
|
+
children: content
|
|
417
|
+
}) : /* @__PURE__ */ jsx("span", { children: content })
|
|
418
|
+
}, step.id);
|
|
419
|
+
}) })
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
function ProgressBar({ value, label, className }) {
|
|
423
|
+
const pct = Math.round(Math.max(0, Math.min(1, value)) * 100);
|
|
424
|
+
return /* @__PURE__ */ jsx("div", {
|
|
425
|
+
role: "progressbar",
|
|
426
|
+
"aria-label": label,
|
|
427
|
+
"aria-valuemin": 0,
|
|
428
|
+
"aria-valuemax": 100,
|
|
429
|
+
"aria-valuenow": pct,
|
|
430
|
+
className: cx("cicord-progress", className),
|
|
431
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
432
|
+
className: "cicord-progress__bar",
|
|
433
|
+
style: { width: `${pct}%` }
|
|
434
|
+
})
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
function Notice({ tone = "info", title, children, action, className }) {
|
|
438
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
439
|
+
role: tone === "error" ? "alert" : "status",
|
|
440
|
+
className: cx("cicord-notice", `cicord-notice--${tone}`, className),
|
|
441
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
442
|
+
className: "cicord-notice__body",
|
|
443
|
+
children: [title ? /* @__PURE__ */ jsx("p", {
|
|
444
|
+
className: "cicord-notice__title",
|
|
445
|
+
children: title
|
|
446
|
+
}) : null, children ? /* @__PURE__ */ jsx("div", {
|
|
447
|
+
className: "cicord-notice__text",
|
|
448
|
+
children
|
|
449
|
+
}) : null]
|
|
450
|
+
}), action ? /* @__PURE__ */ jsx("div", {
|
|
451
|
+
className: "cicord-notice__action",
|
|
452
|
+
children: action
|
|
453
|
+
}) : null]
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
/** Discord-like profile card: banner, avatar, name and role chips. */
|
|
457
|
+
function MemberCard({ displayName, username, avatarUrl, roles, fresh = [], banner, caption, emptyRoles, rolesLabel = "Roles", className, children }) {
|
|
458
|
+
const headingId = useId();
|
|
459
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
460
|
+
"aria-labelledby": headingId,
|
|
461
|
+
className: cx("cicord-member-card", className),
|
|
462
|
+
children: [
|
|
463
|
+
/* @__PURE__ */ jsx("div", {
|
|
464
|
+
className: "cicord-member-card__banner",
|
|
465
|
+
style: banner ? { background: banner } : void 0,
|
|
466
|
+
"aria-hidden": "true"
|
|
467
|
+
}),
|
|
468
|
+
/* @__PURE__ */ jsx("div", {
|
|
469
|
+
className: "cicord-member-card__head",
|
|
470
|
+
children: /* @__PURE__ */ jsx(Avatar, {
|
|
471
|
+
src: avatarUrl,
|
|
472
|
+
name: displayName,
|
|
473
|
+
size: 76,
|
|
474
|
+
className: "cicord-member-card__avatar"
|
|
475
|
+
})
|
|
476
|
+
}),
|
|
477
|
+
/* @__PURE__ */ jsxs("div", {
|
|
478
|
+
className: "cicord-member-card__body",
|
|
479
|
+
children: [
|
|
480
|
+
/* @__PURE__ */ jsx("h2", {
|
|
481
|
+
id: headingId,
|
|
482
|
+
className: "cicord-member-card__name",
|
|
483
|
+
children: displayName
|
|
484
|
+
}),
|
|
485
|
+
username ? /* @__PURE__ */ jsxs("p", {
|
|
486
|
+
className: "cicord-member-card__username",
|
|
487
|
+
children: ["@", username]
|
|
488
|
+
}) : null,
|
|
489
|
+
caption ? /* @__PURE__ */ jsx("p", {
|
|
490
|
+
className: "cicord-member-card__caption",
|
|
491
|
+
children: caption
|
|
492
|
+
}) : null,
|
|
493
|
+
/* @__PURE__ */ jsxs("div", {
|
|
494
|
+
className: "cicord-member-card__roles",
|
|
495
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
496
|
+
className: "cicord-member-card__roles-title",
|
|
497
|
+
children: rolesLabel
|
|
498
|
+
}), roles.length > 0 ? /* @__PURE__ */ jsx("ul", { children: roles.map((role) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(RoleChip, {
|
|
499
|
+
name: role.name,
|
|
500
|
+
color: role.color,
|
|
501
|
+
size: "sm",
|
|
502
|
+
fresh: fresh.includes(role.key)
|
|
503
|
+
}) }, role.key || role.name)) }) : /* @__PURE__ */ jsx("p", {
|
|
504
|
+
className: "cicord-member-card__empty",
|
|
505
|
+
children: emptyRoles
|
|
506
|
+
})]
|
|
507
|
+
}),
|
|
508
|
+
children
|
|
509
|
+
]
|
|
510
|
+
})
|
|
511
|
+
]
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
// src/markdown.tsx
|
|
515
|
+
/** Splits Markdown source into blocks. */
|
|
516
|
+
function parseMarkdown(source) {
|
|
517
|
+
const blocks = [];
|
|
518
|
+
let para = [];
|
|
519
|
+
let quote = [];
|
|
520
|
+
let list = null;
|
|
521
|
+
const flush = () => {
|
|
522
|
+
if (para.length) blocks.push({
|
|
523
|
+
type: "paragraph",
|
|
524
|
+
text: para.join(" ")
|
|
525
|
+
});
|
|
526
|
+
if (quote.length) blocks.push({
|
|
527
|
+
type: "quote",
|
|
528
|
+
text: quote.join(" ")
|
|
529
|
+
});
|
|
530
|
+
if (list) blocks.push({
|
|
531
|
+
type: "list",
|
|
532
|
+
...list
|
|
533
|
+
});
|
|
534
|
+
para = [];
|
|
535
|
+
quote = [];
|
|
536
|
+
list = null;
|
|
537
|
+
};
|
|
538
|
+
for (const raw of source.replace(/\r\n?/g, "\n").split("\n")) {
|
|
539
|
+
const line = raw.trim();
|
|
540
|
+
if (line === "") {
|
|
541
|
+
flush();
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
const heading = /^(#{1,3})\s+(.+)$/.exec(line);
|
|
545
|
+
if (heading) {
|
|
546
|
+
flush();
|
|
547
|
+
blocks.push({
|
|
548
|
+
type: "heading",
|
|
549
|
+
level: heading[1].length,
|
|
550
|
+
text: heading[2].replace(/\s+#+$/, "")
|
|
551
|
+
});
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
const bullet = /^[-*+]\s+(.*)$/.exec(line);
|
|
555
|
+
const numbered = /^\d{1,3}[.)]\s+(.*)$/.exec(line);
|
|
556
|
+
if (bullet || numbered) {
|
|
557
|
+
const ordered = !bullet;
|
|
558
|
+
if (!list || list.ordered !== ordered) {
|
|
559
|
+
flush();
|
|
560
|
+
list = {
|
|
561
|
+
ordered,
|
|
562
|
+
items: []
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
list.items.push((bullet ?? numbered)[1]);
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
if (line.startsWith(">")) {
|
|
569
|
+
if (!quote.length) flush();
|
|
570
|
+
quote.push(line.replace(/^>\s?/, ""));
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
if (list) {
|
|
574
|
+
const items = list.items;
|
|
575
|
+
items[items.length - 1] += ` ${line}`;
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
if (quote.length) flush();
|
|
579
|
+
para.push(line);
|
|
580
|
+
}
|
|
581
|
+
flush();
|
|
582
|
+
return blocks;
|
|
583
|
+
}
|
|
584
|
+
const SAFE_URL = /^https?:\/\//i;
|
|
585
|
+
/** Inline formatting → React nodes. */
|
|
586
|
+
function renderInline(text, keyPrefix = "i") {
|
|
587
|
+
const out = [];
|
|
588
|
+
const re = /(`([^`]+)`)|(\[([^\]]+)\]\(([^)\s]+)\))|(\*\*([^*]+)\*\*)|(__([^_]+)__)|(\*([^*\s][^*]*)\*)|(\b_([^_\s][^_]*)_\b)/g;
|
|
589
|
+
let last = 0;
|
|
590
|
+
let n = 0;
|
|
591
|
+
for (let m = re.exec(text); m; m = re.exec(text)) {
|
|
592
|
+
if (m.index > last) out.push(text.slice(last, m.index));
|
|
593
|
+
const key = `${keyPrefix}-${n++}`;
|
|
594
|
+
if (m[1]) out.push(/* @__PURE__ */ jsx("code", { children: m[2] }, key));
|
|
595
|
+
else if (m[3]) {
|
|
596
|
+
const href = m[5];
|
|
597
|
+
out.push(SAFE_URL.test(href) ? /* @__PURE__ */ jsx("a", {
|
|
598
|
+
href,
|
|
599
|
+
target: "_blank",
|
|
600
|
+
rel: "noopener noreferrer",
|
|
601
|
+
children: renderInline(m[4], key)
|
|
602
|
+
}, key) : m[4]);
|
|
603
|
+
} else if (m[6] || m[8]) out.push(/* @__PURE__ */ jsx("strong", { children: renderInline(m[7] ?? m[9], key) }, key));
|
|
604
|
+
else out.push(/* @__PURE__ */ jsx("em", { children: renderInline(m[11] ?? m[13], key) }, key));
|
|
605
|
+
last = m.index + m[0].length;
|
|
606
|
+
}
|
|
607
|
+
if (last < text.length) out.push(text.slice(last));
|
|
608
|
+
return out;
|
|
609
|
+
}
|
|
610
|
+
function Markdown({ source, baseLevel = 2, className }) {
|
|
611
|
+
const blocks = parseMarkdown(source);
|
|
612
|
+
if (!blocks.length) return null;
|
|
613
|
+
return /* @__PURE__ */ jsx("div", {
|
|
614
|
+
className: ["cicord-markdown", className].filter(Boolean).join(" "),
|
|
615
|
+
children: blocks.map((b, i) => {
|
|
616
|
+
const key = `b${i}`;
|
|
617
|
+
switch (b.type) {
|
|
618
|
+
case "heading": {
|
|
619
|
+
const Tag = `h${Math.min(6, baseLevel + b.level - 1)}`;
|
|
620
|
+
return /* @__PURE__ */ jsx(Tag, { children: renderInline(b.text, key) }, key);
|
|
621
|
+
}
|
|
622
|
+
case "quote": return /* @__PURE__ */ jsx("blockquote", { children: /* @__PURE__ */ jsx("p", { children: renderInline(b.text, key) }) }, key);
|
|
623
|
+
case "list": {
|
|
624
|
+
const Tag = b.ordered ? "ol" : "ul";
|
|
625
|
+
return /* @__PURE__ */ jsx(Tag, { children: b.items.map((item, j) => /* @__PURE__ */ jsx("li", { children: renderInline(item, `${key}-${j}`) }, j)) }, key);
|
|
626
|
+
}
|
|
627
|
+
default: return /* @__PURE__ */ jsx("p", { children: renderInline(b.text, key) }, key);
|
|
628
|
+
}
|
|
629
|
+
})
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
// src/icons.tsx
|
|
633
|
+
const paths = {
|
|
634
|
+
link: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", { d: "M10 14a4.5 4.5 0 0 0 6.4 0l3-3a4.5 4.5 0 0 0-6.4-6.4l-1 1" }), /* @__PURE__ */ jsx("path", { d: "M14 10a4.5 4.5 0 0 0-6.4 0l-3 3a4.5 4.5 0 0 0 6.4 6.4l1-1" })] }),
|
|
635
|
+
website: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("circle", {
|
|
636
|
+
cx: "12",
|
|
637
|
+
cy: "12",
|
|
638
|
+
r: "9"
|
|
639
|
+
}), /* @__PURE__ */ jsx("path", { d: "M3 12h18M12 3c2.5 2.6 3.8 5.6 3.8 9s-1.3 6.4-3.8 9c-2.5-2.6-3.8-5.6-3.8-9S9.5 5.6 12 3Z" })] }),
|
|
640
|
+
discord: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
641
|
+
/* @__PURE__ */ jsx("path", { d: "M7.5 7.5c3-1.3 6-1.3 9 0M7 16.5c3.3 1.4 6.7 1.4 10 0" }),
|
|
642
|
+
/* @__PURE__ */ jsx("path", { d: "M8.5 5.5 7 4.5C5.3 5 4 5.8 3 7c-1 3.5-1.2 7 0 10.5 1.2.9 2.6 1.6 4 2l1.3-2M15.5 5.5l1.5-1c1.7.5 3 1.3 4 2.5 1 3.5 1.2 7 0 10.5-1.2.9-2.6 1.6-4 2l-1.3-2" }),
|
|
643
|
+
/* @__PURE__ */ jsx("circle", {
|
|
644
|
+
cx: "9.3",
|
|
645
|
+
cy: "12.2",
|
|
646
|
+
r: "1.2"
|
|
647
|
+
}),
|
|
648
|
+
/* @__PURE__ */ jsx("circle", {
|
|
649
|
+
cx: "14.7",
|
|
650
|
+
cy: "12.2",
|
|
651
|
+
r: "1.2"
|
|
652
|
+
})
|
|
653
|
+
] }),
|
|
654
|
+
youtube: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("rect", {
|
|
655
|
+
x: "2.5",
|
|
656
|
+
y: "5.5",
|
|
657
|
+
width: "19",
|
|
658
|
+
height: "13",
|
|
659
|
+
rx: "4"
|
|
660
|
+
}), /* @__PURE__ */ jsx("path", { d: "m10.3 9.3 4.6 2.7-4.6 2.7Z" })] }),
|
|
661
|
+
twitch: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", { d: "M4.5 3.5h16v10.5l-4 4h-4l-3 3v-3h-5Z" }), /* @__PURE__ */ jsx("path", { d: "M11 8v4M15.5 8v4" })] }),
|
|
662
|
+
x: /* @__PURE__ */ jsx("path", { d: "M4 4l16 16M20 4 4 20" }),
|
|
663
|
+
bluesky: /* @__PURE__ */ jsx("path", { d: "M12 11c-1.6-3.2-5.4-7-7.6-6.6C2.7 4.7 3 8 3.6 10c.8 2.4 3.4 3 5.6 2.6-3.6.8-4 3.2-1.8 5 3 2.4 4.2-1.2 4.6-3 .4 1.8 1.6 5.4 4.6 3 2.2-1.8 1.8-4.2-1.8-5 2.2.4 4.8-.2 5.6-2.6.6-2 .9-5.3-.8-5.6C17.4 4 13.6 7.8 12 11Z" }),
|
|
664
|
+
mastodon: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", { d: "M20.5 9.5c0-4.4-2.9-5.7-2.9-5.7C16.2 3.1 13.7 3 12 3s-4.2.1-5.6.8c0 0-2.9 1.3-2.9 5.7 0 5.2-.3 11.4 9.7 10 0 0-1.9-.3-2.7-1.5" }), /* @__PURE__ */ jsx("path", { d: "M8 14.5V9.3a2 2 0 0 1 4 0v3M12 12.3V9.3a2 2 0 0 1 4 0v5.2" })] }),
|
|
665
|
+
instagram: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
666
|
+
/* @__PURE__ */ jsx("rect", {
|
|
667
|
+
x: "3.5",
|
|
668
|
+
y: "3.5",
|
|
669
|
+
width: "17",
|
|
670
|
+
height: "17",
|
|
671
|
+
rx: "5"
|
|
672
|
+
}),
|
|
673
|
+
/* @__PURE__ */ jsx("circle", {
|
|
674
|
+
cx: "12",
|
|
675
|
+
cy: "12",
|
|
676
|
+
r: "3.8"
|
|
677
|
+
}),
|
|
678
|
+
/* @__PURE__ */ jsx("circle", {
|
|
679
|
+
cx: "17.2",
|
|
680
|
+
cy: "6.8",
|
|
681
|
+
r: ".6"
|
|
682
|
+
})
|
|
683
|
+
] }),
|
|
684
|
+
tiktok: /* @__PURE__ */ jsx("path", { d: "M13.5 3v11.5a3.5 3.5 0 1 1-3.5-3.5M13.5 3c.4 2.8 2.2 4.6 5 5" }),
|
|
685
|
+
github: /* @__PURE__ */ jsx("path", { d: "M9 19c-4.3 1.4-4.3-2.5-6-3m12 5v-3.5c0-1 .1-1.4-.5-2 2.8-.3 5.5-1.4 5.5-6a4.6 4.6 0 0 0-1.3-3.2 4.2 4.2 0 0 0-.1-3.2s-1.1-.3-3.5 1.3a12.3 12.3 0 0 0-6.2 0C6.5 2.8 5.4 3.1 5.4 3.1a4.2 4.2 0 0 0-.1 3.2A4.6 4.6 0 0 0 4 9.5c0 4.6 2.7 5.7 5.5 6-.6.6-.6 1.2-.5 2V21" }),
|
|
686
|
+
reddit: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
687
|
+
/* @__PURE__ */ jsx("ellipse", {
|
|
688
|
+
cx: "12",
|
|
689
|
+
cy: "14.5",
|
|
690
|
+
rx: "8",
|
|
691
|
+
ry: "5.5"
|
|
692
|
+
}),
|
|
693
|
+
/* @__PURE__ */ jsx("path", { d: "M12 9l1.3-5 4 1M9.5 16.5c1.5 1 3.5 1 5 0" }),
|
|
694
|
+
/* @__PURE__ */ jsx("circle", {
|
|
695
|
+
cx: "18.5",
|
|
696
|
+
cy: "5.5",
|
|
697
|
+
r: "1.3"
|
|
698
|
+
}),
|
|
699
|
+
/* @__PURE__ */ jsx("circle", {
|
|
700
|
+
cx: "9",
|
|
701
|
+
cy: "13.5",
|
|
702
|
+
r: ".6"
|
|
703
|
+
}),
|
|
704
|
+
/* @__PURE__ */ jsx("circle", {
|
|
705
|
+
cx: "15",
|
|
706
|
+
cy: "13.5",
|
|
707
|
+
r: ".6"
|
|
708
|
+
})
|
|
709
|
+
] }),
|
|
710
|
+
steam: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
711
|
+
/* @__PURE__ */ jsx("circle", {
|
|
712
|
+
cx: "12",
|
|
713
|
+
cy: "12",
|
|
714
|
+
r: "9"
|
|
715
|
+
}),
|
|
716
|
+
/* @__PURE__ */ jsx("circle", {
|
|
717
|
+
cx: "15.5",
|
|
718
|
+
cy: "9.5",
|
|
719
|
+
r: "2.5"
|
|
720
|
+
}),
|
|
721
|
+
/* @__PURE__ */ jsx("circle", {
|
|
722
|
+
cx: "9",
|
|
723
|
+
cy: "15.5",
|
|
724
|
+
r: "1.8"
|
|
725
|
+
}),
|
|
726
|
+
/* @__PURE__ */ jsx("path", { d: "m3.5 13.5 4 1.7M10.6 14.6l3-3" })
|
|
727
|
+
] }),
|
|
728
|
+
rules: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", { d: "M6 3.5h9l3 3v14H6Z" }), /* @__PURE__ */ jsx("path", { d: "M9 10h6M9 13.5h6M9 17h3.5" })] }),
|
|
729
|
+
calendar: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("rect", {
|
|
730
|
+
x: "3.5",
|
|
731
|
+
y: "5",
|
|
732
|
+
width: "17",
|
|
733
|
+
height: "15.5",
|
|
734
|
+
rx: "2.5"
|
|
735
|
+
}), /* @__PURE__ */ jsx("path", { d: "M3.5 10h17M8 3v4M16 3v4" })] }),
|
|
736
|
+
shop: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", { d: "M4 8h16l-1.3 11.5a1.5 1.5 0 0 1-1.5 1.5H6.8a1.5 1.5 0 0 1-1.5-1.5Z" }), /* @__PURE__ */ jsx("path", { d: "M8.5 10V7a3.5 3.5 0 0 1 7 0v3" })] })
|
|
737
|
+
};
|
|
738
|
+
function LinkIcon({ name, size = 20, className }) {
|
|
739
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
740
|
+
className: ["cicord-link-icon", className].filter(Boolean).join(" "),
|
|
741
|
+
viewBox: "0 0 24 24",
|
|
742
|
+
width: size,
|
|
743
|
+
height: size,
|
|
744
|
+
fill: "none",
|
|
745
|
+
stroke: "currentColor",
|
|
746
|
+
strokeWidth: "1.7",
|
|
747
|
+
strokeLinecap: "round",
|
|
748
|
+
strokeLinejoin: "round",
|
|
749
|
+
"aria-hidden": "true",
|
|
750
|
+
"data-icon": name in paths ? name : "link",
|
|
751
|
+
children: paths[name] ?? paths["link"]
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
/** Icon names known by `LinkIcon`. */
|
|
755
|
+
const LINK_ICONS = Object.keys(paths);
|
|
756
|
+
export { Avatar, Button, Card, ChoiceGroup, ChoiceTile, DEFAULT_ACCENT, DEFAULT_PRIMARY, LINK_ICONS, LinkButton, LinkIcon, Markdown, MemberCard, Notice, ProgressBar, RoleChip, Spinner, Stepper, ThemeProvider, contrast, legibleOn, luminance, parseHex, parseMarkdown, readableOn, renderInline, themeVariables, useCicordTheme, useResolvedMode };
|
|
757
|
+
|
|
758
|
+
//# sourceMappingURL=index.mjs.map
|