@itkeazco/graphite 0.0.0-stage → 1.2.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/CHANGELOG.md +61 -0
- package/README.md +271 -2
- package/bin/graphite.js +94 -0
- package/dist/fonts.css +2 -0
- package/dist/icon-sets/phosphor-bold.json +1 -0
- package/dist/icon-sets/phosphor-light.json +1 -0
- package/dist/icon-sets/phosphor-regular.json +1 -0
- package/dist/icon-sets/tabler.json +1 -0
- package/dist/index.css +5 -0
- package/dist/index.d.ts +657 -0
- package/dist/index.js +2224 -0
- package/dist/layers.css +853 -0
- package/dist/neutrals.css +565 -0
- package/dist/styles.css +636 -0
- package/dist/tokens.css +824 -0
- package/dist/tokens.d.ts +35 -0
- package/dist/tokens.js +2 -0
- package/dist/tokens.json +884 -0
- package/dist/typography.css +26 -0
- package/package.json +90 -4
- package/rules/graphite.mdc +99 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2224 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/icon.tsx
|
|
4
|
+
import { createContext, forwardRef, useContext } from "react";
|
|
5
|
+
import { Mic, Box, Code, Bookmark, VolumeX, Volume2, X, Link, Play, Pause, Check, Minus, ChevronDown, ChevronRight, ChevronLeft, ChevronUp, Plus, Search, Info, TriangleAlert, CircleAlert, CircleCheck, Trash2, Copy, Sparkles, ArrowRight, ArrowLeft, Settings, User, Bell, Calendar, Menu, Ellipsis, ExternalLink, Eye, EyeOff, Upload, Download, Filter, Pencil, Star, Heart, House, LogOut, Square, MicOff, Share2, Clock, TrendingUp, TrendingDown, ArrowUpRight, ArrowDownRight, Wallet, CreditCard, Pipette, Sun, Moon, Monitor, RotateCcw } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
// src/lib.ts
|
|
8
|
+
import { useId, useState } from "react";
|
|
9
|
+
function useStableId(prefix) {
|
|
10
|
+
return (prefix || "gt") + useId().replace(/:/g, "");
|
|
11
|
+
}
|
|
12
|
+
function cx(...parts) {
|
|
13
|
+
return parts.filter(Boolean).join(" ");
|
|
14
|
+
}
|
|
15
|
+
function useControl(value, def, onChange) {
|
|
16
|
+
const state = useState(def);
|
|
17
|
+
const controlled = value !== void 0;
|
|
18
|
+
const cur = controlled ? value : state[0];
|
|
19
|
+
function set(next) {
|
|
20
|
+
if (!controlled) state[1](next);
|
|
21
|
+
if (onChange) onChange(next);
|
|
22
|
+
}
|
|
23
|
+
return [cur, set];
|
|
24
|
+
}
|
|
25
|
+
function isRtl(node) {
|
|
26
|
+
return getComputedStyle(node).direction === "rtl";
|
|
27
|
+
}
|
|
28
|
+
function optionValue(option) {
|
|
29
|
+
if (typeof option === "string") return option;
|
|
30
|
+
const value = option.value ?? option;
|
|
31
|
+
return typeof value === "string" ? value : "";
|
|
32
|
+
}
|
|
33
|
+
function setRef(ref, node) {
|
|
34
|
+
if (typeof ref === "function") ref(node);
|
|
35
|
+
else if (ref) ref.current = node;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/types.ts
|
|
39
|
+
var LUCIDE_NAMES = [
|
|
40
|
+
"mic",
|
|
41
|
+
"box",
|
|
42
|
+
"code",
|
|
43
|
+
"bookmark",
|
|
44
|
+
"volume-x",
|
|
45
|
+
"volume-2",
|
|
46
|
+
"x",
|
|
47
|
+
"link",
|
|
48
|
+
"play",
|
|
49
|
+
"pause",
|
|
50
|
+
"check",
|
|
51
|
+
"minus",
|
|
52
|
+
"chevron-down",
|
|
53
|
+
"chevron-right",
|
|
54
|
+
"chevron-left",
|
|
55
|
+
"chevron-up",
|
|
56
|
+
"plus",
|
|
57
|
+
"search",
|
|
58
|
+
"info",
|
|
59
|
+
"triangle-alert",
|
|
60
|
+
"circle-alert",
|
|
61
|
+
"circle-check",
|
|
62
|
+
"trash-2",
|
|
63
|
+
"copy",
|
|
64
|
+
"sparkles",
|
|
65
|
+
"arrow-right",
|
|
66
|
+
"arrow-left",
|
|
67
|
+
"settings",
|
|
68
|
+
"user",
|
|
69
|
+
"bell",
|
|
70
|
+
"calendar",
|
|
71
|
+
"menu",
|
|
72
|
+
"ellipsis",
|
|
73
|
+
"external-link",
|
|
74
|
+
"eye",
|
|
75
|
+
"eye-off",
|
|
76
|
+
"upload",
|
|
77
|
+
"download",
|
|
78
|
+
"filter",
|
|
79
|
+
"pencil",
|
|
80
|
+
"star",
|
|
81
|
+
"heart",
|
|
82
|
+
"house",
|
|
83
|
+
"log-out",
|
|
84
|
+
"square",
|
|
85
|
+
"mic-off",
|
|
86
|
+
"share-2",
|
|
87
|
+
"clock",
|
|
88
|
+
"trending-up",
|
|
89
|
+
"trending-down",
|
|
90
|
+
"arrow-up-right",
|
|
91
|
+
"arrow-down-right",
|
|
92
|
+
"wallet",
|
|
93
|
+
"credit-card",
|
|
94
|
+
"pipette",
|
|
95
|
+
"sun",
|
|
96
|
+
"moon",
|
|
97
|
+
"monitor",
|
|
98
|
+
"rotate-ccw"
|
|
99
|
+
];
|
|
100
|
+
var ICON_ALIASES = {
|
|
101
|
+
cube: "box",
|
|
102
|
+
mute: "volume-x",
|
|
103
|
+
volume: "volume-2",
|
|
104
|
+
close: "x",
|
|
105
|
+
chevronDown: "chevron-down",
|
|
106
|
+
chevronRight: "chevron-right",
|
|
107
|
+
alert: "triangle-alert",
|
|
108
|
+
trash: "trash-2",
|
|
109
|
+
sparkle: "sparkles",
|
|
110
|
+
more: "ellipsis",
|
|
111
|
+
home: "house",
|
|
112
|
+
edit: "pencil"
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/icon.tsx
|
|
116
|
+
import { jsx } from "react/jsx-runtime";
|
|
117
|
+
var LUCIDE = {
|
|
118
|
+
mic: Mic,
|
|
119
|
+
box: Box,
|
|
120
|
+
code: Code,
|
|
121
|
+
bookmark: Bookmark,
|
|
122
|
+
"volume-x": VolumeX,
|
|
123
|
+
"volume-2": Volume2,
|
|
124
|
+
x: X,
|
|
125
|
+
link: Link,
|
|
126
|
+
play: Play,
|
|
127
|
+
pause: Pause,
|
|
128
|
+
check: Check,
|
|
129
|
+
minus: Minus,
|
|
130
|
+
"chevron-down": ChevronDown,
|
|
131
|
+
"chevron-right": ChevronRight,
|
|
132
|
+
"chevron-left": ChevronLeft,
|
|
133
|
+
"chevron-up": ChevronUp,
|
|
134
|
+
plus: Plus,
|
|
135
|
+
search: Search,
|
|
136
|
+
info: Info,
|
|
137
|
+
"triangle-alert": TriangleAlert,
|
|
138
|
+
"circle-alert": CircleAlert,
|
|
139
|
+
"circle-check": CircleCheck,
|
|
140
|
+
"trash-2": Trash2,
|
|
141
|
+
copy: Copy,
|
|
142
|
+
sparkles: Sparkles,
|
|
143
|
+
"arrow-right": ArrowRight,
|
|
144
|
+
"arrow-left": ArrowLeft,
|
|
145
|
+
settings: Settings,
|
|
146
|
+
user: User,
|
|
147
|
+
bell: Bell,
|
|
148
|
+
calendar: Calendar,
|
|
149
|
+
menu: Menu,
|
|
150
|
+
ellipsis: Ellipsis,
|
|
151
|
+
"external-link": ExternalLink,
|
|
152
|
+
eye: Eye,
|
|
153
|
+
"eye-off": EyeOff,
|
|
154
|
+
upload: Upload,
|
|
155
|
+
download: Download,
|
|
156
|
+
filter: Filter,
|
|
157
|
+
pencil: Pencil,
|
|
158
|
+
star: Star,
|
|
159
|
+
heart: Heart,
|
|
160
|
+
house: House,
|
|
161
|
+
"log-out": LogOut,
|
|
162
|
+
square: Square,
|
|
163
|
+
"mic-off": MicOff,
|
|
164
|
+
"share-2": Share2,
|
|
165
|
+
clock: Clock,
|
|
166
|
+
"trending-up": TrendingUp,
|
|
167
|
+
"trending-down": TrendingDown,
|
|
168
|
+
"arrow-up-right": ArrowUpRight,
|
|
169
|
+
"arrow-down-right": ArrowDownRight,
|
|
170
|
+
wallet: Wallet,
|
|
171
|
+
"credit-card": CreditCard,
|
|
172
|
+
pipette: Pipette,
|
|
173
|
+
sun: Sun,
|
|
174
|
+
moon: Moon,
|
|
175
|
+
monitor: Monitor,
|
|
176
|
+
"rotate-ccw": RotateCcw
|
|
177
|
+
};
|
|
178
|
+
var FILLED = { play: 1, pause: 1 };
|
|
179
|
+
var IconSetContext = createContext(null);
|
|
180
|
+
function IconSetProvider({ set, children }) {
|
|
181
|
+
return /* @__PURE__ */ jsx(IconSetContext.Provider, { value: set || null, children });
|
|
182
|
+
}
|
|
183
|
+
var IconRoot = forwardRef(function Icon({ name, size = 20, strokeWidth, className, label, style, ...rest }, ref) {
|
|
184
|
+
const key = typeof name === "string" ? ICON_ALIASES[name] || name : "";
|
|
185
|
+
const set = useContext(IconSetContext);
|
|
186
|
+
const inner = set && key ? set.icons[key] : void 0;
|
|
187
|
+
if (inner) {
|
|
188
|
+
const stroke = set.mode !== "fill";
|
|
189
|
+
const a11y = label ? { role: "img", "aria-label": label } : { "aria-hidden": true };
|
|
190
|
+
return /* @__PURE__ */ jsx(
|
|
191
|
+
"svg",
|
|
192
|
+
{
|
|
193
|
+
...rest,
|
|
194
|
+
...a11y,
|
|
195
|
+
ref,
|
|
196
|
+
width: size,
|
|
197
|
+
height: size,
|
|
198
|
+
viewBox: set.viewBox || "0 0 24 24",
|
|
199
|
+
focusable: "false",
|
|
200
|
+
className: cx("gt-icon", className),
|
|
201
|
+
fill: stroke ? FILLED[key] ? "currentColor" : "none" : "currentColor",
|
|
202
|
+
stroke: stroke ? "currentColor" : void 0,
|
|
203
|
+
strokeLinecap: stroke ? "round" : void 0,
|
|
204
|
+
strokeLinejoin: stroke ? "round" : void 0,
|
|
205
|
+
style: stroke ? { ...style, strokeWidth: strokeWidth != null ? strokeWidth : "var(--icon-stroke)" } : style,
|
|
206
|
+
dangerouslySetInnerHTML: { __html: inner }
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const C = name && typeof name !== "string" ? name : LUCIDE[key];
|
|
211
|
+
if (!C) {
|
|
212
|
+
const env = globalThis.process?.env;
|
|
213
|
+
if (env && env.NODE_ENV !== "production") {
|
|
214
|
+
const pascal = key.replace(/(^|-)([a-z0-9])/g, (_m, _d, c) => c.toUpperCase());
|
|
215
|
+
console.warn('[graphite] Icon "' + name + '" is not built in. Import it from lucide-react and pass the component: <Icon name={' + pascal + "} />");
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
const props = {
|
|
220
|
+
...rest,
|
|
221
|
+
ref,
|
|
222
|
+
size,
|
|
223
|
+
className: cx("gt-icon", className),
|
|
224
|
+
focusable: "false",
|
|
225
|
+
style: { ...style, strokeWidth: strokeWidth != null ? strokeWidth : "var(--icon-stroke)" }
|
|
226
|
+
};
|
|
227
|
+
if (label) {
|
|
228
|
+
props.role = "img";
|
|
229
|
+
props["aria-label"] = label;
|
|
230
|
+
} else {
|
|
231
|
+
props["aria-hidden"] = true;
|
|
232
|
+
}
|
|
233
|
+
if (FILLED[key]) props.fill = "currentColor";
|
|
234
|
+
const Glyph = C;
|
|
235
|
+
return /* @__PURE__ */ jsx(Glyph, { ...props });
|
|
236
|
+
});
|
|
237
|
+
var Icon2 = Object.assign(IconRoot, { names: LUCIDE_NAMES });
|
|
238
|
+
|
|
239
|
+
// src/button.tsx
|
|
240
|
+
import { forwardRef as forwardRef2 } from "react";
|
|
241
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
242
|
+
var Button = forwardRef2(function Button2({ variant = "secondary", size = "md", icon, block, className, children, iconRight, loading, type = "button", ...rest }, ref) {
|
|
243
|
+
const iconSize = size === "sm" ? 16 : size === "lg" ? 20 : 18;
|
|
244
|
+
return /* @__PURE__ */ jsxs(
|
|
245
|
+
"button",
|
|
246
|
+
{
|
|
247
|
+
ref,
|
|
248
|
+
type,
|
|
249
|
+
...rest,
|
|
250
|
+
"aria-busy": loading || void 0,
|
|
251
|
+
className: cx("gt-btn", "gt-btn--" + variant, "gt-btn--" + size, block && "gt-btn--block", loading && "is-loading", className),
|
|
252
|
+
children: [
|
|
253
|
+
loading ? /* @__PURE__ */ jsx2("span", { className: "gt-spinner", "aria-hidden": true }) : null,
|
|
254
|
+
icon ? /* @__PURE__ */ jsx2(Icon2, { name: icon, size: iconSize }) : null,
|
|
255
|
+
children != null ? /* @__PURE__ */ jsx2("span", { children }) : null,
|
|
256
|
+
iconRight ? /* @__PURE__ */ jsx2(Icon2, { name: iconRight, size: iconSize }) : null
|
|
257
|
+
]
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// src/icon-button.tsx
|
|
263
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
264
|
+
var BUTTON_VARIANTS = /* @__PURE__ */ new Set(["primary", "secondary", "soft", "ghost", "danger"]);
|
|
265
|
+
function IconButton({ variant = "ghost", size = "md", icon, label, className, active, ...rest }) {
|
|
266
|
+
const iconSize = size === "sm" ? 16 : size === "lg" ? 20 : 18;
|
|
267
|
+
const shared = BUTTON_VARIANTS.has(variant);
|
|
268
|
+
return /* @__PURE__ */ jsx3(
|
|
269
|
+
"button",
|
|
270
|
+
{
|
|
271
|
+
type: "button",
|
|
272
|
+
"aria-label": label,
|
|
273
|
+
title: label,
|
|
274
|
+
"aria-pressed": active === void 0 ? void 0 : !!active,
|
|
275
|
+
...rest,
|
|
276
|
+
className: cx(
|
|
277
|
+
"gt-iconbtn",
|
|
278
|
+
shared ? cx("gt-btn", "gt-btn--" + variant, "gt-btn--" + size, "gt-btn--icon") : cx("gt-iconbtn--" + variant, "gt-iconbtn--" + size),
|
|
279
|
+
active && "is-active",
|
|
280
|
+
className
|
|
281
|
+
),
|
|
282
|
+
children: /* @__PURE__ */ jsx3(Icon2, { name: icon, size: iconSize })
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/text.tsx
|
|
288
|
+
import { createElement, forwardRef as forwardRef3 } from "react";
|
|
289
|
+
var Text = forwardRef3(function Text2({ variant = "body", as = "span", tone, className, children, ...rest }, ref) {
|
|
290
|
+
return createElement(
|
|
291
|
+
as,
|
|
292
|
+
{ ...rest, ref, className: cx("gt-text-" + variant, tone && "gt-text--" + tone, className) },
|
|
293
|
+
children
|
|
294
|
+
);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// src/heading.tsx
|
|
298
|
+
import { createElement as createElement2, forwardRef as forwardRef4 } from "react";
|
|
299
|
+
var Heading = forwardRef4(function Heading2({ level = 2, variant = "title", as, className, children, ...rest }, ref) {
|
|
300
|
+
const tag = as || "h" + level;
|
|
301
|
+
return createElement2(
|
|
302
|
+
tag,
|
|
303
|
+
{ ...rest, ref, className: cx("gt-text-" + variant, className) },
|
|
304
|
+
children
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// src/segmented-control.tsx
|
|
309
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
310
|
+
function SegmentedControl({ options = [], value, defaultValue, onChange, label, size = "md", disabled, block, className }) {
|
|
311
|
+
const [current, set] = useControl(value, defaultValue !== void 0 ? defaultValue : options[0] && options[0].value, onChange);
|
|
312
|
+
function key(event, index) {
|
|
313
|
+
const rtl = isRtl(event.currentTarget);
|
|
314
|
+
const horizontal = event.key === "ArrowRight" ? 1 : event.key === "ArrowLeft" ? -1 : 0;
|
|
315
|
+
const step = horizontal ? rtl ? -horizontal : horizontal : 0;
|
|
316
|
+
if (!step) return;
|
|
317
|
+
event.preventDefault();
|
|
318
|
+
const next = (index + step + options.length) % options.length;
|
|
319
|
+
set(options[next].value);
|
|
320
|
+
const button = event.currentTarget.parentNode?.children[next];
|
|
321
|
+
if (button) button.focus();
|
|
322
|
+
}
|
|
323
|
+
return /* @__PURE__ */ jsx4("div", { role: "radiogroup", "aria-label": label, className: cx("gt-seg", "gt-seg--" + size, block && "gt-seg--block", disabled && "is-disabled", className), "aria-disabled": disabled || void 0, children: options.map((option, index) => {
|
|
324
|
+
const on = option.value === current;
|
|
325
|
+
return /* @__PURE__ */ jsxs2("button", { type: "button", role: "radio", "aria-checked": on, "aria-label": option.icon && !option.label ? option.ariaLabel || option.value : void 0, tabIndex: on ? 0 : -1, className: cx("gt-seg__opt", on && "is-on", option.icon && !option.label && "is-icon", option.className), onClick: () => {
|
|
326
|
+
set(option.value);
|
|
327
|
+
}, onKeyDown: (event) => {
|
|
328
|
+
key(event, index);
|
|
329
|
+
}, children: [
|
|
330
|
+
option.icon ? /* @__PURE__ */ jsx4(Icon2, { name: option.icon, size: 20 }) : null,
|
|
331
|
+
option.label ? /* @__PURE__ */ jsx4("span", { children: option.label }) : null
|
|
332
|
+
] }, option.value);
|
|
333
|
+
}) });
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// src/switch.tsx
|
|
337
|
+
import { forwardRef as forwardRef5 } from "react";
|
|
338
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
339
|
+
var Switch = forwardRef5(function Switch2({ checked, defaultChecked, onCheckedChange, onChange, label, ariaLabel, size, disabled, className, id: idProp, onClick, "aria-label": ariaLabelProp, ...rest }, ref) {
|
|
340
|
+
const [on, set] = useControl(checked, !!defaultChecked, (next) => {
|
|
341
|
+
if (onCheckedChange) onCheckedChange(next);
|
|
342
|
+
if (onChange) onChange(next);
|
|
343
|
+
});
|
|
344
|
+
const autoId = useStableId("sw");
|
|
345
|
+
const id = idProp || autoId;
|
|
346
|
+
const name = label || ariaLabel || ariaLabelProp;
|
|
347
|
+
const env = globalThis.process?.env;
|
|
348
|
+
if (env && env.NODE_ENV !== "production" && !name) {
|
|
349
|
+
console.warn("[graphite] Switch requires a label or ariaLabel.");
|
|
350
|
+
}
|
|
351
|
+
function click(event) {
|
|
352
|
+
if (onClick) onClick(event);
|
|
353
|
+
if (!event.defaultPrevented) set(!on);
|
|
354
|
+
}
|
|
355
|
+
const button = /* @__PURE__ */ jsx5(
|
|
356
|
+
"button",
|
|
357
|
+
{
|
|
358
|
+
...rest,
|
|
359
|
+
ref,
|
|
360
|
+
id,
|
|
361
|
+
type: "button",
|
|
362
|
+
role: "switch",
|
|
363
|
+
"aria-checked": on,
|
|
364
|
+
disabled,
|
|
365
|
+
"aria-label": label ? void 0 : name,
|
|
366
|
+
className: cx("gt-switch", on && "is-on", size === "sm" && "gt-switch--sm", className),
|
|
367
|
+
onClick: click,
|
|
368
|
+
children: /* @__PURE__ */ jsx5("span", { className: "gt-switch__thumb" })
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
if (!label) return button;
|
|
372
|
+
return /* @__PURE__ */ jsxs3("div", { className: "gt-inline", children: [
|
|
373
|
+
button,
|
|
374
|
+
/* @__PURE__ */ jsx5("label", { htmlFor: id, className: "gt-inline__label gt-text-body", children: label })
|
|
375
|
+
] });
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// src/checkbox.tsx
|
|
379
|
+
import { forwardRef as forwardRef6, useEffect, useRef } from "react";
|
|
380
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
381
|
+
var Checkbox = forwardRef6(function Checkbox2({ checked, defaultChecked, onCheckedChange, onChange, label, description, indeterminate, disabled, className, id: idProp, ...rest }, ref) {
|
|
382
|
+
const [on, set] = useControl(checked, !!defaultChecked, onCheckedChange);
|
|
383
|
+
const autoId = useStableId("cb");
|
|
384
|
+
const id = idProp || autoId;
|
|
385
|
+
const descId = description ? id + "-desc" : void 0;
|
|
386
|
+
const localRef = useRef(null);
|
|
387
|
+
useEffect(() => {
|
|
388
|
+
if (localRef.current) localRef.current.indeterminate = !!indeterminate;
|
|
389
|
+
}, [indeterminate]);
|
|
390
|
+
function change(event) {
|
|
391
|
+
set(event.target.checked);
|
|
392
|
+
if (onChange) onChange(event);
|
|
393
|
+
}
|
|
394
|
+
return /* @__PURE__ */ jsxs4("label", { htmlFor: id, className: cx("gt-check", disabled && "is-disabled", className), children: [
|
|
395
|
+
/* @__PURE__ */ jsx6(
|
|
396
|
+
"input",
|
|
397
|
+
{
|
|
398
|
+
...rest,
|
|
399
|
+
ref: (node) => {
|
|
400
|
+
localRef.current = node;
|
|
401
|
+
setRef(ref, node);
|
|
402
|
+
if (node) node.indeterminate = !!indeterminate;
|
|
403
|
+
},
|
|
404
|
+
id,
|
|
405
|
+
type: "checkbox",
|
|
406
|
+
checked: on,
|
|
407
|
+
disabled,
|
|
408
|
+
"aria-checked": indeterminate ? "mixed" : void 0,
|
|
409
|
+
"aria-describedby": descId,
|
|
410
|
+
onChange: change
|
|
411
|
+
}
|
|
412
|
+
),
|
|
413
|
+
/* @__PURE__ */ jsx6("span", { className: "gt-check__box", "aria-hidden": true, children: /* @__PURE__ */ jsx6(Icon2, { name: indeterminate ? "minus" : "check", size: 14 }) }),
|
|
414
|
+
/* @__PURE__ */ jsxs4("span", { className: "gt-check__text", children: [
|
|
415
|
+
/* @__PURE__ */ jsx6("span", { className: "gt-check__label gt-text-body", children: label }),
|
|
416
|
+
description ? /* @__PURE__ */ jsx6("span", { id: descId, className: "gt-check__desc gt-text-caption", children: description }) : null
|
|
417
|
+
] })
|
|
418
|
+
] });
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
// src/radio-shell.tsx
|
|
422
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
423
|
+
function radioShell(props, cls, render) {
|
|
424
|
+
const options = props.options || [];
|
|
425
|
+
const name = useStableId("rg");
|
|
426
|
+
const hintId = name + "-hint";
|
|
427
|
+
const [current, set] = useControl(props.value, props.defaultValue !== void 0 ? props.defaultValue : null, props.onChange);
|
|
428
|
+
const msg = props.error || props.hint;
|
|
429
|
+
return /* @__PURE__ */ jsxs5("fieldset", { className: cx("gt-rgroup", cls, props.orientation === "horizontal" && "gt-rgroup--row", props.error && "is-error", props.className), disabled: props.disabled, "aria-describedby": msg ? hintId : void 0, children: [
|
|
430
|
+
props.label ? /* @__PURE__ */ jsxs5("legend", { className: cx("gt-rgroup__legend", props.hideLabel && "is-hidden"), children: [
|
|
431
|
+
props.label,
|
|
432
|
+
props.required ? /* @__PURE__ */ jsx7("span", { className: "gt-rgroup__req", children: "Required" }) : null
|
|
433
|
+
] }) : null,
|
|
434
|
+
/* @__PURE__ */ jsx7("div", { className: cls === "gt-rgroup--cards" ? "gt-radios" : "gt-rgroup__list", children: options.map((option, index) => {
|
|
435
|
+
const on = option.value === current;
|
|
436
|
+
const descId = name + "-d" + index;
|
|
437
|
+
const input = /* @__PURE__ */ jsx7("input", { className: "gt-rdot", type: "radio", name, value: option.value, checked: on, disabled: option.disabled, required: props.required, "aria-invalid": props.error ? true : void 0, "aria-describedby": option.description ? descId : void 0, onChange: () => {
|
|
438
|
+
set(option.value);
|
|
439
|
+
} });
|
|
440
|
+
return render(option, on, input, descId);
|
|
441
|
+
}) }),
|
|
442
|
+
msg ? /* @__PURE__ */ jsx7("p", { id: hintId, className: "gt-rgroup__hint", style: { margin: 0 }, children: msg }) : null
|
|
443
|
+
] });
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// src/radio-group.tsx
|
|
447
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
448
|
+
function RadioGroup(props) {
|
|
449
|
+
return radioShell(props, "gt-rgroup--plain", (option, _on, input, descId) => {
|
|
450
|
+
const item = option;
|
|
451
|
+
return /* @__PURE__ */ jsxs6("label", { className: cx("gt-radio-item", item.disabled && "is-disabled", item.className), children: [
|
|
452
|
+
input,
|
|
453
|
+
/* @__PURE__ */ jsxs6("span", { className: "gt-radio-item__text", children: [
|
|
454
|
+
/* @__PURE__ */ jsx8("span", { className: "gt-radio-item__label", children: item.label }),
|
|
455
|
+
item.description ? /* @__PURE__ */ jsx8("span", { id: descId, className: "gt-radio-item__desc", children: item.description }) : null
|
|
456
|
+
] })
|
|
457
|
+
] }, item.value);
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// src/badge.tsx
|
|
462
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
463
|
+
function Badge({ tone = "neutral", variant = "subtle", size = "md", dot, icon, children, className }) {
|
|
464
|
+
return /* @__PURE__ */ jsxs7("span", { className: cx("gt-badge", "gt-badge--" + tone, variant === "bold" && "gt-badge--bold", size !== "md" && "gt-badge--" + size, className), children: [
|
|
465
|
+
tone === "live" ? /* @__PURE__ */ jsx9("span", { className: "gt-badge__dot" }) : dot ? /* @__PURE__ */ jsx9("span", { className: "gt-badge__dot gt-badge__dot--static" }) : null,
|
|
466
|
+
icon ? /* @__PURE__ */ jsx9(Icon2, { name: icon, size: size === "lg" ? 14 : 12 }) : null,
|
|
467
|
+
children
|
|
468
|
+
] });
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/radio-cards.tsx
|
|
472
|
+
import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
473
|
+
function RadioCards(props) {
|
|
474
|
+
return radioShell({ ...props, hideLabel: !props.showLabel }, "gt-rgroup--cards", (option, on, input, descId) => {
|
|
475
|
+
const card = option;
|
|
476
|
+
return /* @__PURE__ */ jsxs8("label", { className: cx("gt-radio", on && "is-on", card.disabled && "is-disabled", card.className), children: [
|
|
477
|
+
input,
|
|
478
|
+
/* @__PURE__ */ jsxs8("span", { className: "gt-radio__text", children: [
|
|
479
|
+
/* @__PURE__ */ jsxs8("span", { className: "gt-radio__title", children: [
|
|
480
|
+
card.title,
|
|
481
|
+
card.badge ? /* @__PURE__ */ jsx10(Badge, { tone: "outline", children: card.badge }) : null
|
|
482
|
+
] }),
|
|
483
|
+
card.description ? /* @__PURE__ */ jsx10("span", { id: descId, className: "gt-radio__desc", children: card.description }) : null
|
|
484
|
+
] })
|
|
485
|
+
] }, card.value);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// src/chip-group.tsx
|
|
490
|
+
import { forwardRef as forwardRef7 } from "react";
|
|
491
|
+
import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
492
|
+
function optionDisabled(option) {
|
|
493
|
+
return typeof option !== "string" && !!option.disabled;
|
|
494
|
+
}
|
|
495
|
+
var ChipGroup = forwardRef7(function ChipGroup2({ options = [], multiple, value, defaultValue, onValueChange, onChange, label, className, ...rest }, ref) {
|
|
496
|
+
const multi = !!multiple;
|
|
497
|
+
const [current, set] = useControl(
|
|
498
|
+
value,
|
|
499
|
+
defaultValue !== void 0 ? defaultValue : multi ? [] : null,
|
|
500
|
+
(next) => {
|
|
501
|
+
if (next == null) return;
|
|
502
|
+
if (onValueChange) onValueChange(next);
|
|
503
|
+
if (onChange) onChange(next);
|
|
504
|
+
}
|
|
505
|
+
);
|
|
506
|
+
function isOn(v) {
|
|
507
|
+
return multi ? (Array.isArray(current) ? current : []).indexOf(v) >= 0 : current === v;
|
|
508
|
+
}
|
|
509
|
+
function toggle(v) {
|
|
510
|
+
if (!multi) return set(v);
|
|
511
|
+
const next = (Array.isArray(current) ? current : []).slice();
|
|
512
|
+
const index = next.indexOf(v);
|
|
513
|
+
if (index >= 0) next.splice(index, 1);
|
|
514
|
+
else next.push(v);
|
|
515
|
+
set(next);
|
|
516
|
+
}
|
|
517
|
+
function move(event, index) {
|
|
518
|
+
const rtl = isRtl(event.currentTarget);
|
|
519
|
+
const horizontal = event.key === "ArrowRight" ? 1 : event.key === "ArrowLeft" ? -1 : 0;
|
|
520
|
+
const vertical = event.key === "ArrowDown" ? 1 : event.key === "ArrowUp" ? -1 : 0;
|
|
521
|
+
const dir = vertical || (horizontal ? rtl ? -horizontal : horizontal : 0);
|
|
522
|
+
if (!dir) return;
|
|
523
|
+
event.preventDefault();
|
|
524
|
+
const count = options.length;
|
|
525
|
+
for (let step = 1; step <= count; step++) {
|
|
526
|
+
const next = (index + dir * step + count) % count;
|
|
527
|
+
if (optionDisabled(options[next])) continue;
|
|
528
|
+
set(optionValue(options[next]));
|
|
529
|
+
const buttons = event.currentTarget.parentElement?.querySelectorAll("button");
|
|
530
|
+
const button = buttons && buttons[next];
|
|
531
|
+
if (button) button.focus();
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
const named = label || rest["aria-label"];
|
|
536
|
+
const env = globalThis.process?.env;
|
|
537
|
+
if (env && env.NODE_ENV !== "production" && !named) {
|
|
538
|
+
console.warn("[graphite] ChipGroup requires a label.");
|
|
539
|
+
}
|
|
540
|
+
const selectedIndex = multi ? -1 : options.findIndex((option) => optionValue(option) === current);
|
|
541
|
+
return /* @__PURE__ */ jsx11(
|
|
542
|
+
"div",
|
|
543
|
+
{
|
|
544
|
+
...rest,
|
|
545
|
+
ref,
|
|
546
|
+
role: multi ? "group" : "radiogroup",
|
|
547
|
+
"aria-label": label || rest["aria-label"],
|
|
548
|
+
className: cx("gt-chips", className),
|
|
549
|
+
children: options.map((option, index) => {
|
|
550
|
+
const v = optionValue(option);
|
|
551
|
+
const on = isOn(v);
|
|
552
|
+
const disabled = optionDisabled(option);
|
|
553
|
+
const extra = typeof option === "string" ? void 0 : option.className;
|
|
554
|
+
const text = typeof option === "string" ? option : option.label ?? v;
|
|
555
|
+
const tabIndex = multi ? void 0 : selectedIndex < 0 ? index === options.findIndex((item) => !optionDisabled(item)) ? 0 : -1 : on ? 0 : -1;
|
|
556
|
+
return /* @__PURE__ */ jsxs9(
|
|
557
|
+
"button",
|
|
558
|
+
{
|
|
559
|
+
type: "button",
|
|
560
|
+
role: multi ? void 0 : "radio",
|
|
561
|
+
"aria-pressed": multi ? on : void 0,
|
|
562
|
+
"aria-checked": multi ? void 0 : on,
|
|
563
|
+
tabIndex,
|
|
564
|
+
disabled,
|
|
565
|
+
className: cx("gt-chip", on && "is-on", extra),
|
|
566
|
+
onClick: () => {
|
|
567
|
+
toggle(v);
|
|
568
|
+
},
|
|
569
|
+
onKeyDown: multi ? void 0 : (event) => {
|
|
570
|
+
move(event, index);
|
|
571
|
+
},
|
|
572
|
+
children: [
|
|
573
|
+
on && multi ? /* @__PURE__ */ jsx11(Icon2, { name: "check", size: 14 }) : null,
|
|
574
|
+
text
|
|
575
|
+
]
|
|
576
|
+
},
|
|
577
|
+
v === "" ? index : v
|
|
578
|
+
);
|
|
579
|
+
})
|
|
580
|
+
}
|
|
581
|
+
);
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
// src/input.tsx
|
|
585
|
+
import { forwardRef as forwardRef8 } from "react";
|
|
586
|
+
|
|
587
|
+
// src/field.tsx
|
|
588
|
+
import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
589
|
+
function Field(props, id, control) {
|
|
590
|
+
return /* @__PURE__ */ jsxs10("div", { className: cx("gt-field", props.error && "is-error", props.disabled && "is-disabled", props.className), children: [
|
|
591
|
+
props.label ? /* @__PURE__ */ jsxs10("label", { htmlFor: id, className: "gt-field__label", children: [
|
|
592
|
+
props.label,
|
|
593
|
+
props.optional ? /* @__PURE__ */ jsx12("span", { className: "gt-field__opt", children: "Optional" }) : null
|
|
594
|
+
] }) : null,
|
|
595
|
+
control,
|
|
596
|
+
props.error || props.hint ? /* @__PURE__ */ jsx12("span", { id: id + "-hint", className: "gt-field__hint", children: props.error || props.hint }) : null
|
|
597
|
+
] });
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/input.tsx
|
|
601
|
+
import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
602
|
+
var Input = forwardRef8(function Input2({ label, hint, error, icon, suffix, className, optional, disabled, id: idProp, ...rest }, ref) {
|
|
603
|
+
const autoId = useStableId("in");
|
|
604
|
+
const id = idProp || autoId;
|
|
605
|
+
return Field({ label, hint, error, className, optional, disabled }, id, /* @__PURE__ */ jsxs11("div", { className: "gt-input", children: [
|
|
606
|
+
icon ? /* @__PURE__ */ jsx13(Icon2, { name: icon, size: 18 }) : null,
|
|
607
|
+
/* @__PURE__ */ jsx13(
|
|
608
|
+
"input",
|
|
609
|
+
{
|
|
610
|
+
ref,
|
|
611
|
+
id,
|
|
612
|
+
"aria-invalid": error ? true : void 0,
|
|
613
|
+
"aria-describedby": error || hint ? id + "-hint" : void 0,
|
|
614
|
+
disabled,
|
|
615
|
+
...rest
|
|
616
|
+
}
|
|
617
|
+
),
|
|
618
|
+
suffix ? /* @__PURE__ */ jsx13("span", { className: "gt-input__suffix", children: suffix }) : null
|
|
619
|
+
] }));
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
// src/textarea.tsx
|
|
623
|
+
import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
624
|
+
function Textarea({ label, hint, error, className, optional, value, defaultValue, onChange, maxLength, disabled, ...rest }) {
|
|
625
|
+
const id = useStableId("ta");
|
|
626
|
+
const [current, set] = useControl(value, defaultValue || "", onChange ? (next) => {
|
|
627
|
+
onChange(next);
|
|
628
|
+
} : void 0);
|
|
629
|
+
return Field({ label, hint, error, className, optional, disabled }, id, /* @__PURE__ */ jsxs12("div", { className: "gt-textarea", children: [
|
|
630
|
+
/* @__PURE__ */ jsx14("textarea", { id, rows: 4, value: current, onChange: (event) => {
|
|
631
|
+
set(event.target.value);
|
|
632
|
+
}, "aria-describedby": error || hint ? id + "-hint" : void 0, disabled, ...rest }),
|
|
633
|
+
maxLength ? /* @__PURE__ */ jsx14("span", { className: "gt-textarea__count", children: (current || "").length + " / " + maxLength }) : null
|
|
634
|
+
] }));
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// src/select.tsx
|
|
638
|
+
import { forwardRef as forwardRef9 } from "react";
|
|
639
|
+
import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
640
|
+
var Select = forwardRef9(function Select2({ label, hint, error, className, options = [], optional, disabled, id: idProp, onChange, onValueChange, ...rest }, ref) {
|
|
641
|
+
const autoId = useStableId("se");
|
|
642
|
+
const id = idProp || autoId;
|
|
643
|
+
function change(event) {
|
|
644
|
+
if (onChange) onChange(event);
|
|
645
|
+
if (onValueChange) onValueChange(event.target.value);
|
|
646
|
+
}
|
|
647
|
+
return Field({ label, hint, error, className, optional, disabled }, id, /* @__PURE__ */ jsxs13("div", { className: "gt-select", children: [
|
|
648
|
+
/* @__PURE__ */ jsx15(
|
|
649
|
+
"select",
|
|
650
|
+
{
|
|
651
|
+
...rest,
|
|
652
|
+
ref,
|
|
653
|
+
id,
|
|
654
|
+
disabled,
|
|
655
|
+
"aria-invalid": error ? true : void 0,
|
|
656
|
+
"aria-describedby": error || hint ? id + "-hint" : void 0,
|
|
657
|
+
onChange: change,
|
|
658
|
+
children: options.map((option, index) => {
|
|
659
|
+
const v = optionValue(option);
|
|
660
|
+
const text = typeof option === "string" ? option : option.label ?? v;
|
|
661
|
+
return /* @__PURE__ */ jsx15("option", { value: v, children: text }, index + ":" + v);
|
|
662
|
+
})
|
|
663
|
+
}
|
|
664
|
+
),
|
|
665
|
+
/* @__PURE__ */ jsx15(Icon2, { name: "chevron-down", size: 16 })
|
|
666
|
+
] }));
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
// src/card.tsx
|
|
670
|
+
import { forwardRef as forwardRef10 } from "react";
|
|
671
|
+
import { Fragment, jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
672
|
+
var Card = forwardRef10(function Card2({ title, description, footer, children, variant = "surface", className, ...rest }, ref) {
|
|
673
|
+
const titleId = useStableId("card");
|
|
674
|
+
const labelled = Boolean(title) && rest["aria-labelledby"] == null && rest["aria-label"] == null;
|
|
675
|
+
const props = {
|
|
676
|
+
...rest,
|
|
677
|
+
className: cx("gt-card", variant === "elevated" && "gt-card--elevated", className),
|
|
678
|
+
...labelled ? { "aria-labelledby": titleId } : {}
|
|
679
|
+
};
|
|
680
|
+
const inner = /* @__PURE__ */ jsxs14(Fragment, { children: [
|
|
681
|
+
title || description ? /* @__PURE__ */ jsxs14("div", { className: "gt-card__head", children: [
|
|
682
|
+
title ? /* @__PURE__ */ jsx16(Heading, { id: labelled ? titleId : void 0, level: 2, className: "gt-card__title", children: title }) : null,
|
|
683
|
+
description ? /* @__PURE__ */ jsx16("p", { className: "gt-card__desc gt-text-body gt-text--secondary", children: description }) : null
|
|
684
|
+
] }) : null,
|
|
685
|
+
children != null ? /* @__PURE__ */ jsx16("div", { className: "gt-card__body", children }) : null,
|
|
686
|
+
footer ? /* @__PURE__ */ jsx16("footer", { className: "gt-card__foot", children: footer }) : null
|
|
687
|
+
] });
|
|
688
|
+
if (title) return /* @__PURE__ */ jsx16("section", { ...props, ref, children: inner });
|
|
689
|
+
return /* @__PURE__ */ jsx16("div", { ...props, ref, children: inner });
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
// src/list-row.tsx
|
|
693
|
+
import { forwardRef as forwardRef11 } from "react";
|
|
694
|
+
import { Fragment as Fragment2, jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
695
|
+
var ListRow = forwardRef11(function ListRow2({ title, description, icon, leading, trailing, href, onClick, disabled, chevron, className, ...rest }, ref) {
|
|
696
|
+
const action = Boolean(href || onClick);
|
|
697
|
+
const classNames = cx("gt-row", action && "gt-row--action", disabled && "is-disabled", className);
|
|
698
|
+
const body = /* @__PURE__ */ jsxs15(Fragment2, { children: [
|
|
699
|
+
leading ? /* @__PURE__ */ jsx17("span", { className: "gt-row__lead", children: leading }) : icon ? /* @__PURE__ */ jsx17("span", { className: "gt-row__icon", children: /* @__PURE__ */ jsx17(Icon2, { name: icon, size: 18 }) }) : null,
|
|
700
|
+
/* @__PURE__ */ jsxs15("div", { className: "gt-row__text", children: [
|
|
701
|
+
/* @__PURE__ */ jsx17("span", { className: "gt-row__title", children: title }),
|
|
702
|
+
description ? /* @__PURE__ */ jsx17("span", { className: "gt-row__desc", children: description }) : null
|
|
703
|
+
] }),
|
|
704
|
+
trailing || chevron ? /* @__PURE__ */ jsxs15("div", { className: "gt-row__control", children: [
|
|
705
|
+
trailing,
|
|
706
|
+
chevron ? /* @__PURE__ */ jsx17(Icon2, { name: "chevron-right", size: 18, className: "gt-row__chevron" }) : null
|
|
707
|
+
] }) : null
|
|
708
|
+
] });
|
|
709
|
+
if (href && !disabled) {
|
|
710
|
+
return /* @__PURE__ */ jsx17("a", { ...rest, ref, href, onClick, className: classNames, children: body });
|
|
711
|
+
}
|
|
712
|
+
if (onClick || href && disabled) {
|
|
713
|
+
return /* @__PURE__ */ jsx17(
|
|
714
|
+
"button",
|
|
715
|
+
{
|
|
716
|
+
...rest,
|
|
717
|
+
ref,
|
|
718
|
+
type: "button",
|
|
719
|
+
disabled: disabled || void 0,
|
|
720
|
+
onClick: disabled ? void 0 : onClick,
|
|
721
|
+
className: classNames,
|
|
722
|
+
children: body
|
|
723
|
+
}
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
return /* @__PURE__ */ jsx17("div", { ...rest, ref, className: classNames, "aria-disabled": disabled || void 0, children: body });
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
// src/divider.tsx
|
|
730
|
+
import { forwardRef as forwardRef12 } from "react";
|
|
731
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
732
|
+
var Divider = forwardRef12(function Divider2({ orientation = "horizontal", inset, className, ...rest }, ref) {
|
|
733
|
+
return /* @__PURE__ */ jsx18(
|
|
734
|
+
"hr",
|
|
735
|
+
{
|
|
736
|
+
...rest,
|
|
737
|
+
ref,
|
|
738
|
+
"aria-orientation": orientation === "vertical" ? "vertical" : void 0,
|
|
739
|
+
className: cx(
|
|
740
|
+
"gt-divider",
|
|
741
|
+
orientation === "vertical" && "gt-divider--vertical",
|
|
742
|
+
inset && "gt-divider--inset",
|
|
743
|
+
className
|
|
744
|
+
)
|
|
745
|
+
}
|
|
746
|
+
);
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
// src/avatar.tsx
|
|
750
|
+
import { jsx as jsx19, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
751
|
+
function Avatar({ name, src, size = "md", status, className }) {
|
|
752
|
+
const init = (name || "?").split(/\s+/).map((word) => word[0]).slice(0, 2).join("").toUpperCase();
|
|
753
|
+
return /* @__PURE__ */ jsxs16("span", { className: cx("gt-avatar", "gt-avatar--" + size, className), title: name, role: "img", "aria-label": name, children: [
|
|
754
|
+
src ? /* @__PURE__ */ jsx19("img", { src, alt: "" }) : init,
|
|
755
|
+
status ? /* @__PURE__ */ jsx19("span", { className: "gt-avatar__status gt-avatar__status--" + status, "aria-hidden": true }) : null
|
|
756
|
+
] });
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/kbd.tsx
|
|
760
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
761
|
+
function Kbd({ children, className }) {
|
|
762
|
+
return /* @__PURE__ */ jsx20("kbd", { className: cx("gt-kbd", className), children });
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/progress.tsx
|
|
766
|
+
import { jsx as jsx21, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
767
|
+
function Progress({ value, label, showValue, indeterminate, error, className }) {
|
|
768
|
+
const v = Math.max(0, Math.min(100, value || 0));
|
|
769
|
+
return /* @__PURE__ */ jsxs17("div", { className: cx("gt-progress", indeterminate && "is-indeterminate", error && "is-error", className), children: [
|
|
770
|
+
label || showValue ? /* @__PURE__ */ jsxs17("div", { className: "gt-progress__head", children: [
|
|
771
|
+
/* @__PURE__ */ jsx21("span", { children: label }),
|
|
772
|
+
error ? /* @__PURE__ */ jsx21("span", { className: "gt-progress__val", children: error }) : showValue && !indeterminate ? /* @__PURE__ */ jsx21("span", { className: "gt-progress__val", children: Math.round(v) + "%" }) : null
|
|
773
|
+
] }) : null,
|
|
774
|
+
/* @__PURE__ */ jsx21("div", { className: "gt-progress__track", role: "progressbar", "aria-valuenow": indeterminate ? void 0 : v, "aria-valuemin": 0, "aria-valuemax": 100, "aria-label": label, children: /* @__PURE__ */ jsx21("div", { className: "gt-progress__bar", style: { width: v + "%" } }) })
|
|
775
|
+
] });
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// src/tooltip.tsx
|
|
779
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
780
|
+
import { jsx as jsx22, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
781
|
+
function Tooltip({ content, shortcut, side = "top", open, children }) {
|
|
782
|
+
const [shown, setShown] = useState2(!!open);
|
|
783
|
+
const id = useStableId("tt");
|
|
784
|
+
useEffect2(() => {
|
|
785
|
+
if (open !== void 0) setShown(open);
|
|
786
|
+
}, [open]);
|
|
787
|
+
const show = () => {
|
|
788
|
+
setShown(true);
|
|
789
|
+
};
|
|
790
|
+
const hide = () => {
|
|
791
|
+
if (!open) setShown(false);
|
|
792
|
+
};
|
|
793
|
+
return /* @__PURE__ */ jsxs18("span", { className: "gt-tip", onMouseEnter: show, onMouseLeave: hide, onFocus: show, onBlur: hide, "aria-describedby": id, children: [
|
|
794
|
+
children,
|
|
795
|
+
/* @__PURE__ */ jsxs18("span", { id, role: "tooltip", className: cx("gt-tip__bubble", shown && "is-open", "gt-tip--" + side), children: [
|
|
796
|
+
content,
|
|
797
|
+
shortcut ? /* @__PURE__ */ jsx22(Kbd, { children: shortcut }) : null
|
|
798
|
+
] })
|
|
799
|
+
] });
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// src/toast.tsx
|
|
803
|
+
import { jsx as jsx23, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
804
|
+
function Toast({ tone = "neutral", icon, action, onAction, onClose, children, className }) {
|
|
805
|
+
const ic = tone === "success" ? "check" : tone === "info" ? "info" : tone === "error" ? "x" : tone === "warning" ? "triangle-alert" : icon;
|
|
806
|
+
return /* @__PURE__ */ jsxs19("div", { role: "status", className: cx("gt-toast", "gt-toast--" + tone, className), children: [
|
|
807
|
+
ic ? /* @__PURE__ */ jsx23("span", { className: "gt-toast__icon", children: /* @__PURE__ */ jsx23(Icon2, { name: ic, size: 16 }) }) : null,
|
|
808
|
+
/* @__PURE__ */ jsx23("span", { className: "gt-toast__msg", children }),
|
|
809
|
+
action ? /* @__PURE__ */ jsx23("button", { type: "button", className: "gt-toast__action", onClick: onAction, children: action }) : null,
|
|
810
|
+
onClose ? /* @__PURE__ */ jsx23(IconButton, { icon: "x", label: "Dismiss", size: "sm", onClick: onClose }) : null
|
|
811
|
+
] });
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// src/dialog.tsx
|
|
815
|
+
import { useEffect as useEffect3 } from "react";
|
|
816
|
+
import { jsx as jsx24, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
817
|
+
function Dialog({ open, title, description, actions, onClose, inline, size = "sm", children }) {
|
|
818
|
+
useEffect3(() => {
|
|
819
|
+
if (!open || inline) return;
|
|
820
|
+
function onKey(event) {
|
|
821
|
+
if (event.key === "Escape" && onClose) onClose();
|
|
822
|
+
}
|
|
823
|
+
document.addEventListener("keydown", onKey);
|
|
824
|
+
return () => {
|
|
825
|
+
document.removeEventListener("keydown", onKey);
|
|
826
|
+
};
|
|
827
|
+
}, [open, inline]);
|
|
828
|
+
if (!open) return null;
|
|
829
|
+
return /* @__PURE__ */ jsx24("div", { className: cx("gt-scrim", inline && "gt-scrim--inline"), onClick: (event) => {
|
|
830
|
+
if (event.target === event.currentTarget && onClose) onClose();
|
|
831
|
+
}, children: /* @__PURE__ */ jsxs20("div", { role: "dialog", "aria-modal": inline ? void 0 : true, "aria-label": title, className: cx("gt-dialog", size === "md" && "gt-dialog--md"), children: [
|
|
832
|
+
/* @__PURE__ */ jsxs20("div", { className: "gt-dialog__head", children: [
|
|
833
|
+
/* @__PURE__ */ jsx24("h2", { className: "gt-dialog__title", children: title }),
|
|
834
|
+
onClose ? /* @__PURE__ */ jsx24(IconButton, { icon: "x", label: "Close", size: "sm", onClick: onClose }) : null
|
|
835
|
+
] }),
|
|
836
|
+
description ? /* @__PURE__ */ jsx24("p", { className: "gt-dialog__desc", children: description }) : null,
|
|
837
|
+
children ? /* @__PURE__ */ jsx24("div", { className: "gt-dialog__body", children }) : null,
|
|
838
|
+
actions ? /* @__PURE__ */ jsx24("div", { className: "gt-dialog__actions", children: actions }) : null
|
|
839
|
+
] }) });
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// src/charts.tsx
|
|
843
|
+
import { useEffect as useEffect4, useLayoutEffect, useRef as useRef2, useState as useState3 } from "react";
|
|
844
|
+
import { Fragment as Fragment3, jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
845
|
+
var plain = (value) => value.toLocaleString();
|
|
846
|
+
function useWidth() {
|
|
847
|
+
const ref = useRef2(null);
|
|
848
|
+
const [width, setWidth] = useState3(0);
|
|
849
|
+
useEffect4(() => {
|
|
850
|
+
const node = ref.current;
|
|
851
|
+
if (!node) return;
|
|
852
|
+
setWidth(node.clientWidth);
|
|
853
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
854
|
+
const observer = new ResizeObserver(() => setWidth(node.clientWidth));
|
|
855
|
+
observer.observe(node);
|
|
856
|
+
return () => observer.disconnect();
|
|
857
|
+
}, []);
|
|
858
|
+
return [ref, width];
|
|
859
|
+
}
|
|
860
|
+
function smoothPath(points) {
|
|
861
|
+
const n = points.length;
|
|
862
|
+
if (n === 0) return "";
|
|
863
|
+
if (n < 3) return points.map((p, i) => (i ? "L" : "M") + p[0] + "," + p[1]).join(" ");
|
|
864
|
+
const dx = [], slope = [];
|
|
865
|
+
for (let i = 0; i < n - 1; i++) {
|
|
866
|
+
dx[i] = points[i + 1][0] - points[i][0];
|
|
867
|
+
slope[i] = (points[i + 1][1] - points[i][1]) / (dx[i] || 1);
|
|
868
|
+
}
|
|
869
|
+
const tangent = [slope[0]];
|
|
870
|
+
for (let i = 1; i < n - 1; i++) tangent[i] = slope[i - 1] * slope[i] <= 0 ? 0 : (slope[i - 1] + slope[i]) / 2;
|
|
871
|
+
tangent[n - 1] = slope[n - 2];
|
|
872
|
+
for (let i = 0; i < n - 1; i++) {
|
|
873
|
+
if (slope[i] === 0) {
|
|
874
|
+
tangent[i] = 0;
|
|
875
|
+
tangent[i + 1] = 0;
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
const a = tangent[i] / slope[i], b = tangent[i + 1] / slope[i], s = a * a + b * b;
|
|
879
|
+
if (s > 9) {
|
|
880
|
+
const k = 3 / Math.sqrt(s);
|
|
881
|
+
tangent[i] = k * a * slope[i];
|
|
882
|
+
tangent[i + 1] = k * b * slope[i];
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
let d = "M" + points[0][0] + "," + points[0][1];
|
|
886
|
+
for (let i = 0; i < n - 1; i++) {
|
|
887
|
+
const h = dx[i] / 3;
|
|
888
|
+
d += " C" + (points[i][0] + h) + "," + (points[i][1] + tangent[i] * h) + " " + (points[i + 1][0] - h) + "," + (points[i + 1][1] - tangent[i + 1] * h) + " " + points[i + 1][0] + "," + points[i + 1][1];
|
|
889
|
+
}
|
|
890
|
+
return d;
|
|
891
|
+
}
|
|
892
|
+
function niceTicks(min, max, count) {
|
|
893
|
+
if (min === max) {
|
|
894
|
+
max = min + 1;
|
|
895
|
+
min = min - 1;
|
|
896
|
+
}
|
|
897
|
+
const raw = (max - min) / Math.max(1, count);
|
|
898
|
+
const mag = 10 ** Math.floor(Math.log10(raw));
|
|
899
|
+
const step = [1, 2, 2.5, 5, 10].map((m) => m * mag).find((s) => s >= raw) || raw;
|
|
900
|
+
const lo = Math.floor(min / step) * step, hi = Math.ceil(max / step) * step;
|
|
901
|
+
const ticks = [];
|
|
902
|
+
for (let v = lo; v <= hi + step / 2; v += step) ticks.push(Number(v.toFixed(10)));
|
|
903
|
+
return ticks;
|
|
904
|
+
}
|
|
905
|
+
function SrTable({ caption, rows }) {
|
|
906
|
+
return /* @__PURE__ */ jsxs21("table", { className: "gt-sr-only", children: [
|
|
907
|
+
/* @__PURE__ */ jsx25("caption", { children: caption }),
|
|
908
|
+
/* @__PURE__ */ jsx25("tbody", { children: rows.map(([k, v], i) => /* @__PURE__ */ jsxs21("tr", { children: [
|
|
909
|
+
/* @__PURE__ */ jsx25("th", { scope: "row", children: k }),
|
|
910
|
+
/* @__PURE__ */ jsx25("td", { children: v })
|
|
911
|
+
] }, i)) })
|
|
912
|
+
] });
|
|
913
|
+
}
|
|
914
|
+
function Sparkline({ data, width = 96, height = 28, tone = "default", area = true, label, className }) {
|
|
915
|
+
const id = useStableId("spark");
|
|
916
|
+
if (data.length < 2) return null;
|
|
917
|
+
const min = Math.min(...data), max = Math.max(...data), pad = 2;
|
|
918
|
+
const pts = data.map((v, i) => [pad + i / (data.length - 1) * (width - pad * 2), pad + (1 - (v - min) / (max - min || 1)) * (height - pad * 2)]);
|
|
919
|
+
const resolved = tone === "auto" ? data[data.length - 1] > data[0] ? "success" : data[data.length - 1] < data[0] ? "danger" : "default" : tone;
|
|
920
|
+
const line = smoothPath(pts);
|
|
921
|
+
return /* @__PURE__ */ jsxs21("svg", { className: cx("gt-spark", "gt-spark--" + resolved, className), width, height, viewBox: `0 0 ${width} ${height}`, role: label ? "img" : void 0, "aria-label": label, "aria-hidden": label ? void 0 : true, children: [
|
|
922
|
+
area ? /* @__PURE__ */ jsxs21(Fragment3, { children: [
|
|
923
|
+
/* @__PURE__ */ jsx25("defs", { children: /* @__PURE__ */ jsxs21("linearGradient", { id, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
924
|
+
/* @__PURE__ */ jsx25("stop", { offset: "0", stopColor: "currentColor", stopOpacity: "0.18" }),
|
|
925
|
+
/* @__PURE__ */ jsx25("stop", { offset: "1", stopColor: "currentColor", stopOpacity: "0" })
|
|
926
|
+
] }) }),
|
|
927
|
+
/* @__PURE__ */ jsx25("path", { d: `${line} L${pts[pts.length - 1][0]},${height} L${pts[0][0]},${height} Z`, fill: `url(#${id})` })
|
|
928
|
+
] }) : null,
|
|
929
|
+
/* @__PURE__ */ jsx25("path", { className: "gt-spark__line", d: line })
|
|
930
|
+
] });
|
|
931
|
+
}
|
|
932
|
+
function LineChart({ data, labels, compare, compareLabel = "Previous", label, height = 200, format: format2 = plain, area = true, yTicks = 4, className }) {
|
|
933
|
+
const [ref, width] = useWidth();
|
|
934
|
+
const gradient = useStableId("line");
|
|
935
|
+
const [active, setActive] = useState3(null);
|
|
936
|
+
const n = data.length;
|
|
937
|
+
const all = compare ? data.concat(compare) : data;
|
|
938
|
+
const ticks = niceTicks(Math.min(...all), Math.max(...all), yTicks);
|
|
939
|
+
const lo = ticks[0], hi = ticks[ticks.length - 1];
|
|
940
|
+
const top = 8, bottom = height - 8;
|
|
941
|
+
const x = (i) => n < 2 ? width / 2 : i / (n - 1) * width;
|
|
942
|
+
const y = (v) => bottom - (v - lo) / (hi - lo || 1) * (bottom - top);
|
|
943
|
+
const pts = data.map((v, i) => [x(i), y(v)]);
|
|
944
|
+
const cmp = compare ? compare.slice(0, n).map((v, i) => [x(i), y(v)]) : [];
|
|
945
|
+
const line = width ? smoothPath(pts) : "";
|
|
946
|
+
function pick(event) {
|
|
947
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
948
|
+
setActive(Math.max(0, Math.min(n - 1, Math.round((event.clientX - box.left) / (box.width || 1) * (n - 1)))));
|
|
949
|
+
}
|
|
950
|
+
function key(event) {
|
|
951
|
+
const cur = active ?? n - 1;
|
|
952
|
+
if (event.key === "ArrowRight" || event.key === "ArrowLeft") {
|
|
953
|
+
event.preventDefault();
|
|
954
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
955
|
+
const step2 = event.key === "ArrowRight" !== rtl ? 1 : -1;
|
|
956
|
+
setActive(Math.max(0, Math.min(n - 1, cur + step2)));
|
|
957
|
+
} else if (event.key === "Home") {
|
|
958
|
+
event.preventDefault();
|
|
959
|
+
setActive(0);
|
|
960
|
+
} else if (event.key === "End") {
|
|
961
|
+
event.preventDefault();
|
|
962
|
+
setActive(n - 1);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
const step = labels ? Math.max(1, Math.ceil(labels.length / Math.max(2, Math.floor((width || 320) / 64)))) : 1;
|
|
966
|
+
const lastShown = (n - 1) % step === 0 || (n - 1) % step >= step / 2;
|
|
967
|
+
const showLabel = (i) => i === n - 1 ? lastShown : i % step === 0 && !(lastShown && n - 1 - i < step / 2);
|
|
968
|
+
return /* @__PURE__ */ jsxs21("div", { className: cx("gt-chart", "gt-linechart", className), children: [
|
|
969
|
+
/* @__PURE__ */ jsxs21("div", { className: "gt-linechart__frame", children: [
|
|
970
|
+
/* @__PURE__ */ jsx25("div", { className: "gt-chart__yaxis", style: { height }, "aria-hidden": true, children: ticks.slice().reverse().map((t) => /* @__PURE__ */ jsx25("span", { style: { top: y(t) }, children: format2(t) }, t)) }),
|
|
971
|
+
/* @__PURE__ */ jsxs21("div", { ref, className: "gt-linechart__plot", tabIndex: 0, role: "img", "aria-label": label + ". Use arrow keys to read values.", onKeyDown: key, onFocus: () => setActive((a) => a ?? n - 1), onBlur: () => setActive(null), children: [
|
|
972
|
+
width ? /* @__PURE__ */ jsxs21("svg", { width, height, onPointerMove: pick, onPointerLeave: () => setActive(null), "aria-hidden": true, children: [
|
|
973
|
+
/* @__PURE__ */ jsx25("defs", { children: /* @__PURE__ */ jsxs21("linearGradient", { id: gradient, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
974
|
+
/* @__PURE__ */ jsx25("stop", { offset: "0", stopColor: "var(--chart-line)", stopOpacity: "var(--chart-area-opacity)" }),
|
|
975
|
+
/* @__PURE__ */ jsx25("stop", { offset: "1", stopColor: "var(--chart-line)", stopOpacity: "0" })
|
|
976
|
+
] }) }),
|
|
977
|
+
ticks.map((t) => /* @__PURE__ */ jsx25("line", { className: "gt-chart__grid", x1: 0, x2: width, y1: y(t), y2: y(t) }, t)),
|
|
978
|
+
cmp.length > 1 ? /* @__PURE__ */ jsx25("path", { className: "gt-linechart__compare", d: smoothPath(cmp) }) : null,
|
|
979
|
+
area && n > 1 ? /* @__PURE__ */ jsx25("path", { d: `${line} L${width},${bottom} L0,${bottom} Z`, fill: `url(#${gradient})` }) : null,
|
|
980
|
+
/* @__PURE__ */ jsx25("path", { className: "gt-linechart__line", d: line }),
|
|
981
|
+
active != null ? /* @__PURE__ */ jsxs21(Fragment3, { children: [
|
|
982
|
+
/* @__PURE__ */ jsx25("line", { className: "gt-chart__guide", x1: pts[active][0], x2: pts[active][0], y1: top, y2: bottom }),
|
|
983
|
+
/* @__PURE__ */ jsx25("circle", { className: "gt-linechart__dot", cx: pts[active][0], cy: pts[active][1], r: 5 })
|
|
984
|
+
] }) : null
|
|
985
|
+
] }) : /* @__PURE__ */ jsx25("div", { style: { height } }),
|
|
986
|
+
active != null && width ? /* @__PURE__ */ jsxs21("div", { className: "gt-chart__tip", style: { left: Math.max(48, Math.min(width - 48, pts[active][0])), top: pts[active][1] }, "aria-live": "polite", children: [
|
|
987
|
+
/* @__PURE__ */ jsx25("strong", { children: format2(data[active]) }),
|
|
988
|
+
labels ? /* @__PURE__ */ jsx25("span", { children: labels[active] }) : null,
|
|
989
|
+
compare && compare[active] != null ? /* @__PURE__ */ jsxs21("span", { children: [
|
|
990
|
+
compareLabel,
|
|
991
|
+
" ",
|
|
992
|
+
format2(compare[active])
|
|
993
|
+
] }) : null
|
|
994
|
+
] }) : null
|
|
995
|
+
] })
|
|
996
|
+
] }),
|
|
997
|
+
labels ? /* @__PURE__ */ jsx25("div", { className: "gt-chart__xaxis", "aria-hidden": true, children: labels.map((l, i) => /* @__PURE__ */ jsx25("span", { style: { left: width ? x(i) : void 0, visibility: showLabel(i) ? void 0 : "hidden" }, children: l }, i)) }) : null,
|
|
998
|
+
/* @__PURE__ */ jsx25(SrTable, { caption: label, rows: data.map((v, i) => [labels ? labels[i] : String(i + 1), format2(v)]) })
|
|
999
|
+
] });
|
|
1000
|
+
}
|
|
1001
|
+
function BarChart({ data, label, height = 160, format: format2 = plain, selected, defaultSelected, onSelect, className }) {
|
|
1002
|
+
const [cur, set] = useControl(selected, defaultSelected ?? data.length - 1, onSelect);
|
|
1003
|
+
const max = Math.max(...data.map((d) => d.value), 0) || 1;
|
|
1004
|
+
return /* @__PURE__ */ jsxs21("div", { className: cx("gt-chart", "gt-barchart", className), role: "group", "aria-label": label, children: [
|
|
1005
|
+
/* @__PURE__ */ jsx25("div", { className: "gt-barchart__bars", style: { height }, children: data.map((d, i) => {
|
|
1006
|
+
const on = i === cur;
|
|
1007
|
+
return /* @__PURE__ */ jsx25("button", { type: "button", className: cx("gt-barchart__col", on && "is-selected"), "aria-pressed": on, "aria-label": d.label + ": " + format2(d.value), onClick: () => set(i), children: /* @__PURE__ */ jsx25("span", { className: "gt-barchart__bar", style: { height: Math.max(2, d.value / max * 100) + "%" }, children: on ? /* @__PURE__ */ jsx25("span", { className: "gt-barchart__value", "aria-hidden": true, children: format2(d.value) }) : null }) }, i);
|
|
1008
|
+
}) }),
|
|
1009
|
+
/* @__PURE__ */ jsx25("div", { className: "gt-barchart__labels", "aria-hidden": true, children: data.map((d, i) => /* @__PURE__ */ jsx25("span", { className: i === cur ? "is-selected" : void 0, children: d.label }, i)) })
|
|
1010
|
+
] });
|
|
1011
|
+
}
|
|
1012
|
+
function DonutChart({ data, label, size = 168, thickness = 20, center, centerLabel = "Total", format: format2 = plain, legend = true, rounded, className }) {
|
|
1013
|
+
const [active, setActive] = useState3(null);
|
|
1014
|
+
const rootRef = useRef2(null);
|
|
1015
|
+
const [capToken, setCapToken] = useState3("round");
|
|
1016
|
+
useLayoutEffect(() => {
|
|
1017
|
+
if (rounded !== void 0 || !rootRef.current) return;
|
|
1018
|
+
const v = getComputedStyle(rootRef.current).getPropertyValue("--chart-cap").trim() || "round";
|
|
1019
|
+
if (v !== capToken) setCapToken(v);
|
|
1020
|
+
});
|
|
1021
|
+
const isRound = rounded ?? capToken !== "butt";
|
|
1022
|
+
const total = data.reduce((s, d) => s + Math.max(0, d.value), 0);
|
|
1023
|
+
const r = (size - thickness) / 2, c = 2 * Math.PI * r;
|
|
1024
|
+
const parts = data.filter((d) => d.value > 0).length;
|
|
1025
|
+
const gap = parts > 1 ? Math.min(4, c / 100) : 0;
|
|
1026
|
+
const cap = isRound && parts > 1 ? thickness : 0;
|
|
1027
|
+
const colour = (i) => data[i].color || `var(--chart-${i % 6 + 1})`;
|
|
1028
|
+
let offset = 0;
|
|
1029
|
+
const shown = active != null ? data[active] : null;
|
|
1030
|
+
return /* @__PURE__ */ jsxs21("div", { ref: rootRef, className: cx("gt-chart", "gt-donut", className), children: [
|
|
1031
|
+
/* @__PURE__ */ jsxs21("div", { className: "gt-donut__ring", style: { width: size, height: size }, children: [
|
|
1032
|
+
/* @__PURE__ */ jsxs21("svg", { width: size, height: size, viewBox: `0 0 ${size} ${size}`, role: "img", "aria-label": label, children: [
|
|
1033
|
+
/* @__PURE__ */ jsx25("circle", { cx: size / 2, cy: size / 2, r, fill: "none", stroke: "var(--chart-track)", strokeWidth: thickness }),
|
|
1034
|
+
data.map((d, i) => {
|
|
1035
|
+
const len = total ? Math.max(0, d.value) / total * c : 0;
|
|
1036
|
+
const seg = /* @__PURE__ */ jsx25(
|
|
1037
|
+
"circle",
|
|
1038
|
+
{
|
|
1039
|
+
className: cx("gt-donut__seg", active != null && active !== i && "is-dim"),
|
|
1040
|
+
cx: size / 2,
|
|
1041
|
+
cy: size / 2,
|
|
1042
|
+
r,
|
|
1043
|
+
fill: "none",
|
|
1044
|
+
stroke: colour(i),
|
|
1045
|
+
strokeWidth: thickness,
|
|
1046
|
+
strokeLinecap: cap ? "round" : "butt",
|
|
1047
|
+
strokeDasharray: `${len > 0 ? Math.max(1e-3, len - gap - cap) : 0} ${c}`,
|
|
1048
|
+
strokeDashoffset: -(offset + cap / 2),
|
|
1049
|
+
transform: `rotate(-90 ${size / 2} ${size / 2})`,
|
|
1050
|
+
onPointerEnter: () => setActive(i),
|
|
1051
|
+
onPointerLeave: () => setActive(null)
|
|
1052
|
+
},
|
|
1053
|
+
i
|
|
1054
|
+
);
|
|
1055
|
+
offset += len;
|
|
1056
|
+
return seg;
|
|
1057
|
+
})
|
|
1058
|
+
] }),
|
|
1059
|
+
/* @__PURE__ */ jsxs21("div", { className: "gt-donut__center", "aria-hidden": true, children: [
|
|
1060
|
+
/* @__PURE__ */ jsx25("span", { className: "gt-donut__label", children: shown ? shown.label : centerLabel }),
|
|
1061
|
+
/* @__PURE__ */ jsx25("span", { className: "gt-donut__total", children: shown ? format2(shown.value) : center ?? format2(total) })
|
|
1062
|
+
] })
|
|
1063
|
+
] }),
|
|
1064
|
+
legend ? /* @__PURE__ */ jsx25("ul", { className: "gt-donut__legend", children: data.map((d, i) => /* @__PURE__ */ jsxs21("li", { className: cx(active === i && "is-active"), onPointerEnter: () => setActive(i), onPointerLeave: () => setActive(null), children: [
|
|
1065
|
+
/* @__PURE__ */ jsx25("span", { className: "gt-donut__dot", style: { background: colour(i) }, "aria-hidden": true }),
|
|
1066
|
+
/* @__PURE__ */ jsx25("span", { className: "gt-donut__name", children: d.label }),
|
|
1067
|
+
/* @__PURE__ */ jsx25("span", { className: "gt-donut__val", children: format2(d.value) }),
|
|
1068
|
+
/* @__PURE__ */ jsxs21("span", { className: "gt-donut__pct", children: [
|
|
1069
|
+
total ? Math.round(d.value / total * 100) : 0,
|
|
1070
|
+
"%"
|
|
1071
|
+
] })
|
|
1072
|
+
] }, i)) }) : /* @__PURE__ */ jsx25(SrTable, { caption: label, rows: data.map((d) => [d.label, format2(d.value)]) })
|
|
1073
|
+
] });
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// src/stat.tsx
|
|
1077
|
+
import { jsx as jsx26, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
1078
|
+
var percent = (delta) => (delta > 0 ? "+" : delta < 0 ? "\u2212" : "") + Math.abs(delta).toLocaleString(void 0, { maximumFractionDigits: 1 }) + "%";
|
|
1079
|
+
function Stat({ label, value, delta, deltaLabel, deltaFormat = percent, invert, chart, icon, size = "md", className }) {
|
|
1080
|
+
const dir = delta == null || delta === 0 ? "flat" : delta > 0 ? "up" : "down";
|
|
1081
|
+
const good = dir === "flat" ? "flat" : dir === "up" !== !!invert ? "good" : "bad";
|
|
1082
|
+
return /* @__PURE__ */ jsxs22("div", { className: cx("gt-stat", "gt-stat--" + size, className), children: [
|
|
1083
|
+
/* @__PURE__ */ jsxs22("div", { className: "gt-stat__label", children: [
|
|
1084
|
+
icon ? /* @__PURE__ */ jsx26(Icon2, { name: icon, size: 16 }) : null,
|
|
1085
|
+
/* @__PURE__ */ jsx26("span", { children: label })
|
|
1086
|
+
] }),
|
|
1087
|
+
/* @__PURE__ */ jsxs22("div", { className: "gt-stat__row", children: [
|
|
1088
|
+
/* @__PURE__ */ jsx26("div", { className: "gt-stat__value", children: value }),
|
|
1089
|
+
chart && chart.length > 1 ? /* @__PURE__ */ jsx26(Sparkline, { className: "gt-stat__chart", data: chart, tone: good === "good" ? "success" : good === "bad" ? "danger" : "muted", width: size === "lg" ? 120 : 88, height: size === "lg" ? 40 : 30 }) : null
|
|
1090
|
+
] }),
|
|
1091
|
+
delta != null || deltaLabel ? /* @__PURE__ */ jsxs22("div", { className: "gt-stat__foot", children: [
|
|
1092
|
+
delta != null ? /* @__PURE__ */ jsxs22("span", { className: cx("gt-stat__delta", "is-" + good), children: [
|
|
1093
|
+
dir !== "flat" ? /* @__PURE__ */ jsx26(Icon2, { name: dir === "up" ? "trending-up" : "trending-down", size: 14 }) : null,
|
|
1094
|
+
/* @__PURE__ */ jsx26("span", { className: "gt-sr-only", children: good === "good" ? "Better: " : good === "bad" ? "Worse: " : "" }),
|
|
1095
|
+
deltaFormat(delta)
|
|
1096
|
+
] }) : null,
|
|
1097
|
+
deltaLabel ? /* @__PURE__ */ jsx26("span", { className: "gt-stat__note", children: deltaLabel }) : null
|
|
1098
|
+
] }) : null
|
|
1099
|
+
] });
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// src/color-picker.tsx
|
|
1103
|
+
import { useEffect as useEffect5, useRef as useRef3, useState as useState4 } from "react";
|
|
1104
|
+
import { jsx as jsx27, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
1105
|
+
var clamp = (n, lo = 0, hi = 1) => Math.min(hi, Math.max(lo, n));
|
|
1106
|
+
var round = (n, d = 0) => Number(n.toFixed(d));
|
|
1107
|
+
function hsvToRgb({ h, s, v, a }) {
|
|
1108
|
+
const f = (n) => {
|
|
1109
|
+
const k = (n + h / 60) % 6;
|
|
1110
|
+
return v - v * s * Math.max(0, Math.min(k, 4 - k, 1));
|
|
1111
|
+
};
|
|
1112
|
+
return { r: Math.round(f(5) * 255), g: Math.round(f(3) * 255), b: Math.round(f(1) * 255), a };
|
|
1113
|
+
}
|
|
1114
|
+
function rgbToHsv({ r, g, b, a }) {
|
|
1115
|
+
r /= 255;
|
|
1116
|
+
g /= 255;
|
|
1117
|
+
b /= 255;
|
|
1118
|
+
const max = Math.max(r, g, b), d = max - Math.min(r, g, b);
|
|
1119
|
+
let h = 0;
|
|
1120
|
+
if (d) h = max === r ? (g - b) / d % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
|
|
1121
|
+
return { h: (h * 60 + 360) % 360, s: max ? d / max : 0, v: max, a };
|
|
1122
|
+
}
|
|
1123
|
+
var hex2 = (n) => Math.round(n).toString(16).padStart(2, "0");
|
|
1124
|
+
function toHex(c, alpha = true) {
|
|
1125
|
+
return "#" + hex2(c.r) + hex2(c.g) + hex2(c.b) + (alpha && c.a < 1 ? hex2(c.a * 255) : "");
|
|
1126
|
+
}
|
|
1127
|
+
function toHsl({ r, g, b, a }) {
|
|
1128
|
+
r /= 255;
|
|
1129
|
+
g /= 255;
|
|
1130
|
+
b /= 255;
|
|
1131
|
+
const max = Math.max(r, g, b), min = Math.min(r, g, b), l = (max + min) / 2, d = max - min;
|
|
1132
|
+
const s = d ? d / (1 - Math.abs(2 * l - 1)) : 0;
|
|
1133
|
+
let h = 0;
|
|
1134
|
+
if (d) h = max === r ? (g - b) / d % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
|
|
1135
|
+
return { h: Math.round((h * 60 + 360) % 360), s: Math.round(s * 100), l: Math.round(l * 100), a };
|
|
1136
|
+
}
|
|
1137
|
+
function hslToRgb(h, s, l, a) {
|
|
1138
|
+
s /= 100;
|
|
1139
|
+
l /= 100;
|
|
1140
|
+
const k = (n) => (n + h / 30) % 12, m = s * Math.min(l, 1 - l);
|
|
1141
|
+
const f = (n) => l - m * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1));
|
|
1142
|
+
return { r: Math.round(f(0) * 255), g: Math.round(f(8) * 255), b: Math.round(f(4) * 255), a };
|
|
1143
|
+
}
|
|
1144
|
+
function parseColor(input) {
|
|
1145
|
+
const s = input.trim().toLowerCase();
|
|
1146
|
+
let m = /^#?([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.exec(s);
|
|
1147
|
+
if (m) {
|
|
1148
|
+
let x = m[1];
|
|
1149
|
+
if (x.length <= 4) x = x.replace(/./g, "$&$&");
|
|
1150
|
+
const n = (i) => parseInt(x.slice(i, i + 2), 16);
|
|
1151
|
+
return { r: n(0), g: n(2), b: n(4), a: x.length === 8 ? round(n(6) / 255, 2) : 1 };
|
|
1152
|
+
}
|
|
1153
|
+
m = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?\s*\)$/.exec(s);
|
|
1154
|
+
if (m) {
|
|
1155
|
+
const a = m[4] == null ? 1 : m[4].endsWith("%") ? parseFloat(m[4]) / 100 : parseFloat(m[4]);
|
|
1156
|
+
return { r: clamp(+m[1], 0, 255), g: clamp(+m[2], 0, 255), b: clamp(+m[3], 0, 255), a: clamp(a) };
|
|
1157
|
+
}
|
|
1158
|
+
m = /^hsla?\(\s*([\d.]+)(?:deg)?[\s,]+([\d.]+)%?[\s,]+([\d.]+)%?(?:[\s,/]+([\d.]+%?))?\s*\)$/.exec(s);
|
|
1159
|
+
if (m) {
|
|
1160
|
+
const a = m[4] == null ? 1 : m[4].endsWith("%") ? parseFloat(m[4]) / 100 : parseFloat(m[4]);
|
|
1161
|
+
return hslToRgb(+m[1] % 360, clamp(+m[2], 0, 100), clamp(+m[3], 0, 100), clamp(a));
|
|
1162
|
+
}
|
|
1163
|
+
return null;
|
|
1164
|
+
}
|
|
1165
|
+
function format(c, fmt) {
|
|
1166
|
+
const rgb = hsvToRgb(c);
|
|
1167
|
+
if (fmt === "rgb") return `${rgb.r}, ${rgb.g}, ${rgb.b}`;
|
|
1168
|
+
if (fmt === "hsl") {
|
|
1169
|
+
const l = toHsl(rgb);
|
|
1170
|
+
return `${l.h}, ${l.s}%, ${l.l}%`;
|
|
1171
|
+
}
|
|
1172
|
+
return toHex(rgb, false).slice(1).toUpperCase();
|
|
1173
|
+
}
|
|
1174
|
+
function cssColor(c) {
|
|
1175
|
+
return toHex(hsvToRgb(c));
|
|
1176
|
+
}
|
|
1177
|
+
function fromString(value, fallback) {
|
|
1178
|
+
const rgb = value ? parseColor(value) : null;
|
|
1179
|
+
return rgb ? rgbToHsv(rgb) : fallback;
|
|
1180
|
+
}
|
|
1181
|
+
function parseGradient(value) {
|
|
1182
|
+
if (!value || !/^linear-gradient\(/i.test(value.trim())) return null;
|
|
1183
|
+
const body = value.trim().slice(value.indexOf("(") + 1, -1);
|
|
1184
|
+
const parts = body.split(/,(?![^(]*\))/).map((p) => p.trim());
|
|
1185
|
+
let angle = 90;
|
|
1186
|
+
if (/deg$/.test(parts[0])) angle = parseFloat(parts.shift());
|
|
1187
|
+
const stops = parts.map((p, i) => {
|
|
1188
|
+
const m = /^(.*?)\s+([\d.]+)%$/.exec(p);
|
|
1189
|
+
const rgb = parseColor(m ? m[1] : p);
|
|
1190
|
+
return { c: rgb ? rgbToHsv(rgb) : { h: 0, s: 0, v: 0, a: 1 }, at: m ? +m[2] / 100 : i / Math.max(1, parts.length - 1) };
|
|
1191
|
+
});
|
|
1192
|
+
return stops.length >= 2 ? { angle, stops } : null;
|
|
1193
|
+
}
|
|
1194
|
+
function gradientCss(angle, stops) {
|
|
1195
|
+
return `linear-gradient(${Math.round(angle)}deg, ${stops.slice().sort((a, b) => a.at - b.at).map((s) => cssColor(s.c) + " " + Math.round(s.at * 100) + "%").join(", ")})`;
|
|
1196
|
+
}
|
|
1197
|
+
function useDrag(onMove, measure) {
|
|
1198
|
+
const move = useRef3(onMove);
|
|
1199
|
+
move.current = onMove;
|
|
1200
|
+
return {
|
|
1201
|
+
onPointerDown(event) {
|
|
1202
|
+
if (event.button !== 0) return;
|
|
1203
|
+
const el = event.currentTarget;
|
|
1204
|
+
el.setPointerCapture(event.pointerId);
|
|
1205
|
+
const at2 = (e) => {
|
|
1206
|
+
const r = (measure ? measure(el) : el).getBoundingClientRect();
|
|
1207
|
+
let x = clamp((e.clientX - r.left) / (r.width || 1));
|
|
1208
|
+
if (isRtl(el)) x = 1 - x;
|
|
1209
|
+
move.current(x, clamp((e.clientY - r.top) / (r.height || 1)));
|
|
1210
|
+
};
|
|
1211
|
+
at2(event);
|
|
1212
|
+
const onMoveEv = (e) => at2(e);
|
|
1213
|
+
const up = () => {
|
|
1214
|
+
el.removeEventListener("pointermove", onMoveEv);
|
|
1215
|
+
el.removeEventListener("pointerup", up);
|
|
1216
|
+
el.removeEventListener("pointercancel", up);
|
|
1217
|
+
};
|
|
1218
|
+
el.addEventListener("pointermove", onMoveEv);
|
|
1219
|
+
el.addEventListener("pointerup", up);
|
|
1220
|
+
el.addEventListener("pointercancel", up);
|
|
1221
|
+
el.focus();
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
function Track({ label, value, max, onChange, className, style, valueText, children }) {
|
|
1226
|
+
const drag = useDrag((x) => onChange(x * max));
|
|
1227
|
+
function key(e) {
|
|
1228
|
+
const big = e.shiftKey ? 10 : 1, step = max / 100 * big;
|
|
1229
|
+
const rtl = isRtl(e.currentTarget);
|
|
1230
|
+
const map = { ArrowRight: rtl ? -step : step, ArrowUp: step, ArrowLeft: rtl ? step : -step, ArrowDown: -step };
|
|
1231
|
+
if (e.key in map) {
|
|
1232
|
+
e.preventDefault();
|
|
1233
|
+
onChange(clamp(value + map[e.key], 0, max));
|
|
1234
|
+
} else if (e.key === "Home") {
|
|
1235
|
+
e.preventDefault();
|
|
1236
|
+
onChange(0);
|
|
1237
|
+
} else if (e.key === "End") {
|
|
1238
|
+
e.preventDefault();
|
|
1239
|
+
onChange(max);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
return /* @__PURE__ */ jsxs23("div", { className: cx("gt-cp__track", className), style, role: "slider", tabIndex: 0, "aria-label": label, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuenow": Math.round(value), "aria-valuetext": valueText, onKeyDown: key, ...drag, children: [
|
|
1243
|
+
children,
|
|
1244
|
+
/* @__PURE__ */ jsx27("span", { className: "gt-cp__thumb", style: { insetInlineStart: value / max * 100 + "%" } })
|
|
1245
|
+
] });
|
|
1246
|
+
}
|
|
1247
|
+
var FORMATS = [{ value: "hex", label: "Hex" }, { value: "rgb", label: "RGB" }, { value: "hsl", label: "HSL" }];
|
|
1248
|
+
function ColorPicker({ value, defaultValue = "#1a1a1a", onChange, modes = ["color"], alpha = true, eyedropper = true, swatches, label = "Colour", className }) {
|
|
1249
|
+
const startGradient = parseGradient(value ?? defaultValue);
|
|
1250
|
+
const [mode, setMode] = useState4(startGradient && modes.includes("gradient") ? "gradient" : "color");
|
|
1251
|
+
const [color, setColor] = useState4(() => fromString(startGradient ? void 0 : value ?? defaultValue, { h: 0, s: 0, v: 0.1, a: 1 }));
|
|
1252
|
+
const [angle, setAngle] = useState4(startGradient ? startGradient.angle : 90);
|
|
1253
|
+
const [stops, setStops] = useState4(() => startGradient ? startGradient.stops : [{ c: { h: 36, s: 0.36, v: 1, a: 1 }, at: 0 }, { c: { h: 24, s: 0.9, v: 0.95, a: 1 }, at: 1 }]);
|
|
1254
|
+
const [active, setActive] = useState4(0);
|
|
1255
|
+
const [fmt, setFmt] = useState4("hex");
|
|
1256
|
+
const [draft, setDraft] = useState4(null);
|
|
1257
|
+
const [alphaDraft, setAlphaDraft] = useState4(null);
|
|
1258
|
+
const canPick = eyedropper && typeof window !== "undefined" && "EyeDropper" in window;
|
|
1259
|
+
const last = useRef3(value);
|
|
1260
|
+
useEffect5(() => {
|
|
1261
|
+
if (value === void 0 || value === last.current) return;
|
|
1262
|
+
last.current = value;
|
|
1263
|
+
const g = parseGradient(value);
|
|
1264
|
+
if (g) {
|
|
1265
|
+
setAngle(g.angle);
|
|
1266
|
+
setStops(g.stops);
|
|
1267
|
+
setMode("gradient");
|
|
1268
|
+
} else {
|
|
1269
|
+
setColor((c) => fromString(value, c));
|
|
1270
|
+
setMode("color");
|
|
1271
|
+
}
|
|
1272
|
+
}, [value]);
|
|
1273
|
+
const cur = mode === "gradient" ? stops[Math.min(active, stops.length - 1)].c : color;
|
|
1274
|
+
function emit(nextColor, nextStops = stops, nextAngle = angle, nextMode = mode) {
|
|
1275
|
+
const out = nextMode === "gradient" ? gradientCss(nextAngle, nextStops) : cssColor(nextColor);
|
|
1276
|
+
last.current = out;
|
|
1277
|
+
if (onChange) onChange(out);
|
|
1278
|
+
}
|
|
1279
|
+
function update(patch) {
|
|
1280
|
+
const next = { ...cur, ...patch };
|
|
1281
|
+
if (mode === "gradient") {
|
|
1282
|
+
const ns = stops.map((s, i) => i === active ? { ...s, c: next } : s);
|
|
1283
|
+
setStops(ns);
|
|
1284
|
+
emit(color, ns);
|
|
1285
|
+
} else {
|
|
1286
|
+
setColor(next);
|
|
1287
|
+
emit(next);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
const area = useDrag((x, y) => update({ s: x, v: 1 - y }));
|
|
1291
|
+
function areaKey(e) {
|
|
1292
|
+
const step = e.shiftKey ? 0.1 : 0.01, rtl = isRtl(e.currentTarget);
|
|
1293
|
+
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
1294
|
+
e.preventDefault();
|
|
1295
|
+
update({ s: clamp(cur.s + (e.key === "ArrowRight" !== rtl ? step : -step)) });
|
|
1296
|
+
} else if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
1297
|
+
e.preventDefault();
|
|
1298
|
+
update({ v: clamp(cur.v + (e.key === "ArrowUp" ? step : -step)) });
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
const stopDrag = useDrag((x) => {
|
|
1302
|
+
const ns = stops.map((s, i) => i === active ? { ...s, at: round(x, 3) } : s);
|
|
1303
|
+
setStops(ns);
|
|
1304
|
+
emit(color, ns);
|
|
1305
|
+
}, (el) => el.parentElement || el);
|
|
1306
|
+
async function pick() {
|
|
1307
|
+
try {
|
|
1308
|
+
const result = await new window.EyeDropper().open();
|
|
1309
|
+
const rgb2 = parseColor(result.sRGBHex);
|
|
1310
|
+
if (rgb2) update({ ...rgbToHsv(rgb2), a: cur.a });
|
|
1311
|
+
} catch {
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
function commitText(text) {
|
|
1315
|
+
setDraft(null);
|
|
1316
|
+
const raw = text.trim();
|
|
1317
|
+
const parsed = fmt === "hex" ? parseColor(raw) : fmt === "rgb" ? parseColor(`rgb(${raw.replace(/^rgba?\(|\)$/g, "")})`) : parseColor(`hsl(${raw.replace(/^hsla?\(|\)$/g, "")})`);
|
|
1318
|
+
if (parsed) update({ ...rgbToHsv(parsed), a: cur.a });
|
|
1319
|
+
}
|
|
1320
|
+
function commitAlpha(text) {
|
|
1321
|
+
setAlphaDraft(null);
|
|
1322
|
+
const n = parseFloat(text);
|
|
1323
|
+
if (!Number.isNaN(n)) update({ a: clamp(n / 100) });
|
|
1324
|
+
}
|
|
1325
|
+
const rgb = hsvToRgb(cur);
|
|
1326
|
+
const solid = toHex({ ...rgb, a: 1 }, false);
|
|
1327
|
+
const hueColor = toHex(hsvToRgb({ h: cur.h, s: 1, v: 1, a: 1 }), false);
|
|
1328
|
+
const sorted = stops.map((s, i) => ({ ...s, i })).sort((a, b) => a.at - b.at);
|
|
1329
|
+
return /* @__PURE__ */ jsxs23("div", { className: cx("gt-cp", className), role: "group", "aria-label": label, children: [
|
|
1330
|
+
modes.length > 1 ? /* @__PURE__ */ jsx27(
|
|
1331
|
+
SegmentedControl,
|
|
1332
|
+
{
|
|
1333
|
+
label: "Fill type",
|
|
1334
|
+
value: mode,
|
|
1335
|
+
onChange: (m) => {
|
|
1336
|
+
const nm = m;
|
|
1337
|
+
setMode(nm);
|
|
1338
|
+
emit(color, stops, angle, nm);
|
|
1339
|
+
},
|
|
1340
|
+
options: modes.map((m) => ({ value: m, label: m === "color" ? "Color" : "Gradient" })),
|
|
1341
|
+
className: "gt-cp__modes"
|
|
1342
|
+
}
|
|
1343
|
+
) : null,
|
|
1344
|
+
mode === "gradient" ? /* @__PURE__ */ jsxs23("div", { className: "gt-cp__gradient", children: [
|
|
1345
|
+
/* @__PURE__ */ jsx27(
|
|
1346
|
+
"div",
|
|
1347
|
+
{
|
|
1348
|
+
className: "gt-cp__stops",
|
|
1349
|
+
style: { background: gradientCss(90, stops) },
|
|
1350
|
+
onPointerDown: (e) => {
|
|
1351
|
+
if (e.target !== e.currentTarget) return;
|
|
1352
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
1353
|
+
let at2 = clamp((e.clientX - r.left) / r.width);
|
|
1354
|
+
if (isRtl(e.currentTarget)) at2 = 1 - at2;
|
|
1355
|
+
const ns = stops.concat({ c: { ...cur }, at: round(at2, 3) });
|
|
1356
|
+
setStops(ns);
|
|
1357
|
+
setActive(ns.length - 1);
|
|
1358
|
+
emit(color, ns);
|
|
1359
|
+
},
|
|
1360
|
+
children: sorted.map((s) => /* @__PURE__ */ jsx27(
|
|
1361
|
+
"button",
|
|
1362
|
+
{
|
|
1363
|
+
type: "button",
|
|
1364
|
+
className: cx("gt-cp__stop", s.i === active && "is-on"),
|
|
1365
|
+
style: { insetInlineStart: s.at * 100 + "%", background: cssColor(s.c) },
|
|
1366
|
+
"aria-label": `Stop ${Math.round(s.at * 100)}%, ${toHex(hsvToRgb(s.c))}`,
|
|
1367
|
+
"aria-pressed": s.i === active,
|
|
1368
|
+
onPointerDown: (e) => {
|
|
1369
|
+
setActive(s.i);
|
|
1370
|
+
stopDrag.onPointerDown(e);
|
|
1371
|
+
},
|
|
1372
|
+
onKeyDown: (e) => {
|
|
1373
|
+
if ((e.key === "Delete" || e.key === "Backspace") && stops.length > 2) {
|
|
1374
|
+
e.preventDefault();
|
|
1375
|
+
const ns = stops.filter((_, i) => i !== s.i);
|
|
1376
|
+
setStops(ns);
|
|
1377
|
+
setActive(0);
|
|
1378
|
+
emit(color, ns);
|
|
1379
|
+
} else if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
1380
|
+
e.preventDefault();
|
|
1381
|
+
const d = (e.key === "ArrowRight" !== isRtl(e.currentTarget) ? 1 : -1) * (e.shiftKey ? 0.1 : 0.01);
|
|
1382
|
+
const ns = stops.map((x, i) => i === s.i ? { ...x, at: round(clamp(x.at + d), 3) } : x);
|
|
1383
|
+
setStops(ns);
|
|
1384
|
+
emit(color, ns);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
},
|
|
1388
|
+
s.i
|
|
1389
|
+
))
|
|
1390
|
+
}
|
|
1391
|
+
),
|
|
1392
|
+
/* @__PURE__ */ jsxs23("div", { className: "gt-cp__angle", children: [
|
|
1393
|
+
/* @__PURE__ */ jsx27("span", { children: "Angle" }),
|
|
1394
|
+
/* @__PURE__ */ jsx27(Track, { label: "Angle", value: angle, max: 360, valueText: Math.round(angle) + " degrees", onChange: (v) => {
|
|
1395
|
+
setAngle(v);
|
|
1396
|
+
emit(color, stops, v);
|
|
1397
|
+
}, className: "gt-cp__track--angle" }),
|
|
1398
|
+
/* @__PURE__ */ jsxs23("output", { children: [
|
|
1399
|
+
Math.round(angle),
|
|
1400
|
+
"\xB0"
|
|
1401
|
+
] })
|
|
1402
|
+
] })
|
|
1403
|
+
] }) : null,
|
|
1404
|
+
/* @__PURE__ */ jsx27(
|
|
1405
|
+
"div",
|
|
1406
|
+
{
|
|
1407
|
+
className: "gt-cp__area",
|
|
1408
|
+
style: { backgroundColor: hueColor },
|
|
1409
|
+
role: "slider",
|
|
1410
|
+
tabIndex: 0,
|
|
1411
|
+
"aria-label": "Saturation and brightness",
|
|
1412
|
+
"aria-valuetext": `Saturation ${Math.round(cur.s * 100)}%, brightness ${Math.round(cur.v * 100)}%`,
|
|
1413
|
+
"aria-valuenow": Math.round(cur.s * 100),
|
|
1414
|
+
"aria-valuemin": 0,
|
|
1415
|
+
"aria-valuemax": 100,
|
|
1416
|
+
onKeyDown: areaKey,
|
|
1417
|
+
...area,
|
|
1418
|
+
children: /* @__PURE__ */ jsx27("span", { className: "gt-cp__thumb", style: { insetInlineStart: cur.s * 100 + "%", top: (1 - cur.v) * 100 + "%", background: solid } })
|
|
1419
|
+
}
|
|
1420
|
+
),
|
|
1421
|
+
/* @__PURE__ */ jsxs23("div", { className: "gt-cp__fields", children: [
|
|
1422
|
+
/* @__PURE__ */ jsx27("select", { className: "gt-cp__format", "aria-label": "Colour format", value: fmt, onChange: (e) => {
|
|
1423
|
+
setFmt(e.target.value);
|
|
1424
|
+
setDraft(null);
|
|
1425
|
+
}, children: FORMATS.map((f) => /* @__PURE__ */ jsx27("option", { value: f.value, children: f.label }, f.value)) }),
|
|
1426
|
+
/* @__PURE__ */ jsxs23("span", { className: "gt-cp__value", children: [
|
|
1427
|
+
/* @__PURE__ */ jsx27("span", { className: "gt-cp__swatch", style: { "--gt-cp-swatch": toHex(rgb) }, "aria-hidden": true }),
|
|
1428
|
+
/* @__PURE__ */ jsx27(
|
|
1429
|
+
"input",
|
|
1430
|
+
{
|
|
1431
|
+
"aria-label": FORMATS.find((f) => f.value === fmt).label + " value",
|
|
1432
|
+
spellCheck: false,
|
|
1433
|
+
value: draft ?? format(cur, fmt),
|
|
1434
|
+
onChange: (e) => setDraft(e.target.value),
|
|
1435
|
+
onBlur: (e) => commitText(e.target.value),
|
|
1436
|
+
onKeyDown: (e) => {
|
|
1437
|
+
if (e.key === "Enter") commitText(e.currentTarget.value);
|
|
1438
|
+
if (e.key === "Escape") setDraft(null);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
)
|
|
1442
|
+
] }),
|
|
1443
|
+
alpha ? /* @__PURE__ */ jsxs23("span", { className: "gt-cp__alpha-field", children: [
|
|
1444
|
+
/* @__PURE__ */ jsx27(
|
|
1445
|
+
"input",
|
|
1446
|
+
{
|
|
1447
|
+
"aria-label": "Opacity, percent",
|
|
1448
|
+
inputMode: "numeric",
|
|
1449
|
+
value: alphaDraft ?? String(Math.round(cur.a * 100)),
|
|
1450
|
+
onChange: (e) => setAlphaDraft(e.target.value),
|
|
1451
|
+
onBlur: (e) => commitAlpha(e.target.value),
|
|
1452
|
+
onKeyDown: (e) => {
|
|
1453
|
+
if (e.key === "Enter") commitAlpha(e.currentTarget.value);
|
|
1454
|
+
if (e.key === "Escape") setAlphaDraft(null);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
),
|
|
1458
|
+
/* @__PURE__ */ jsx27("span", { "aria-hidden": true, children: "%" })
|
|
1459
|
+
] }) : null
|
|
1460
|
+
] }),
|
|
1461
|
+
/* @__PURE__ */ jsxs23("div", { className: "gt-cp__sliders", children: [
|
|
1462
|
+
canPick ? /* @__PURE__ */ jsx27("button", { type: "button", className: "gt-cp__dropper", "aria-label": "Pick a colour from the screen", title: "Pick from screen", onClick: pick, children: /* @__PURE__ */ jsx27(Icon2, { name: "pipette", size: 20 }) }) : null,
|
|
1463
|
+
/* @__PURE__ */ jsxs23("div", { className: "gt-cp__tracks", children: [
|
|
1464
|
+
/* @__PURE__ */ jsx27(Track, { label: "Hue", value: cur.h, max: 360, valueText: Math.round(cur.h) + " degrees", onChange: (v) => update({ h: Math.min(v, 359.9) }), className: "gt-cp__track--hue" }),
|
|
1465
|
+
alpha ? /* @__PURE__ */ jsx27(
|
|
1466
|
+
Track,
|
|
1467
|
+
{
|
|
1468
|
+
label: "Opacity",
|
|
1469
|
+
value: cur.a * 100,
|
|
1470
|
+
max: 100,
|
|
1471
|
+
valueText: Math.round(cur.a * 100) + "%",
|
|
1472
|
+
onChange: (v) => update({ a: round(v / 100, 2) }),
|
|
1473
|
+
className: "gt-cp__track--alpha",
|
|
1474
|
+
style: { "--gt-cp-solid": solid }
|
|
1475
|
+
}
|
|
1476
|
+
) : null
|
|
1477
|
+
] })
|
|
1478
|
+
] }),
|
|
1479
|
+
swatches && swatches.length ? /* @__PURE__ */ jsx27("div", { className: "gt-cp__swatches", role: "group", "aria-label": "Saved colours", children: swatches.map((s) => /* @__PURE__ */ jsx27(
|
|
1480
|
+
"button",
|
|
1481
|
+
{
|
|
1482
|
+
type: "button",
|
|
1483
|
+
className: "gt-cp__chip",
|
|
1484
|
+
style: { background: s },
|
|
1485
|
+
"aria-label": s,
|
|
1486
|
+
title: s,
|
|
1487
|
+
onClick: () => {
|
|
1488
|
+
const p = parseColor(s);
|
|
1489
|
+
if (p) update(rgbToHsv(p));
|
|
1490
|
+
}
|
|
1491
|
+
},
|
|
1492
|
+
s
|
|
1493
|
+
)) }) : null
|
|
1494
|
+
] });
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
// src/popover.tsx
|
|
1498
|
+
import { useEffect as useEffect6, useLayoutEffect as useLayoutEffect2, useRef as useRef4, useState as useState5 } from "react";
|
|
1499
|
+
import { createPortal } from "react-dom";
|
|
1500
|
+
import { jsx as jsx28 } from "react/jsx-runtime";
|
|
1501
|
+
var OPPOSITE = { top: "bottom", bottom: "top", left: "right", right: "left" };
|
|
1502
|
+
var MARGIN = 8;
|
|
1503
|
+
var INHERIT = ["data-radius", "data-size", "data-brand", "data-theme"];
|
|
1504
|
+
function place(anchor, panel, side, align, offset) {
|
|
1505
|
+
const vw = window.innerWidth, vh = window.innerHeight;
|
|
1506
|
+
const room = { top: anchor.top, bottom: vh - anchor.bottom, left: anchor.left, right: vw - anchor.right };
|
|
1507
|
+
const need = (s) => (s === "top" || s === "bottom" ? panel.height : panel.width) + offset + MARGIN;
|
|
1508
|
+
const order = [side, OPPOSITE[side], ...["bottom", "top", "right", "left"].sort((a, b) => room[b] - room[a])];
|
|
1509
|
+
const chosen = order.find((s) => room[s] >= need(s)) || order[2];
|
|
1510
|
+
let top, left;
|
|
1511
|
+
if (chosen === "top" || chosen === "bottom") {
|
|
1512
|
+
top = chosen === "bottom" ? anchor.bottom + offset : anchor.top - offset - panel.height;
|
|
1513
|
+
left = align === "start" ? anchor.left : align === "end" ? anchor.right - panel.width : anchor.left + anchor.width / 2 - panel.width / 2;
|
|
1514
|
+
} else {
|
|
1515
|
+
left = chosen === "right" ? anchor.right + offset : anchor.left - offset - panel.width;
|
|
1516
|
+
top = align === "start" ? anchor.top : align === "end" ? anchor.bottom - panel.height : anchor.top + anchor.height / 2 - panel.height / 2;
|
|
1517
|
+
}
|
|
1518
|
+
left = Math.min(Math.max(MARGIN, left), vw - panel.width - MARGIN);
|
|
1519
|
+
top = Math.min(Math.max(MARGIN, top), vh - panel.height - MARGIN);
|
|
1520
|
+
return { top, left, side: chosen };
|
|
1521
|
+
}
|
|
1522
|
+
function Popover({ open, onClose, anchor, side = "bottom", align = "start", offset = 8, label, children, className }) {
|
|
1523
|
+
const ref = useRef4(null);
|
|
1524
|
+
const [pos, setPos] = useState5(null);
|
|
1525
|
+
useLayoutEffect2(() => {
|
|
1526
|
+
if (!open) {
|
|
1527
|
+
setPos(null);
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
const a0 = anchor.current, p0 = ref.current;
|
|
1531
|
+
if (a0 && p0) for (const attr of INHERIT) {
|
|
1532
|
+
const host = a0.closest("[" + attr + "]");
|
|
1533
|
+
const value = host && host.getAttribute(attr);
|
|
1534
|
+
if (value) p0.setAttribute(attr, value);
|
|
1535
|
+
else p0.removeAttribute(attr);
|
|
1536
|
+
}
|
|
1537
|
+
function update() {
|
|
1538
|
+
const a = anchor.current, p = ref.current;
|
|
1539
|
+
if (!a || !p) return;
|
|
1540
|
+
setPos(place(a.getBoundingClientRect(), { width: p.offsetWidth, height: p.offsetHeight }, side, align, offset));
|
|
1541
|
+
}
|
|
1542
|
+
update();
|
|
1543
|
+
const ro = typeof ResizeObserver !== "undefined" && ref.current ? new ResizeObserver(update) : null;
|
|
1544
|
+
if (ro && ref.current) ro.observe(ref.current);
|
|
1545
|
+
window.addEventListener("resize", update);
|
|
1546
|
+
window.addEventListener("scroll", update, true);
|
|
1547
|
+
return () => {
|
|
1548
|
+
if (ro) ro.disconnect();
|
|
1549
|
+
window.removeEventListener("resize", update);
|
|
1550
|
+
window.removeEventListener("scroll", update, true);
|
|
1551
|
+
};
|
|
1552
|
+
}, [open, side, align, offset, anchor]);
|
|
1553
|
+
useEffect6(() => {
|
|
1554
|
+
if (!open) return;
|
|
1555
|
+
const trigger = anchor.current;
|
|
1556
|
+
const panel = ref.current;
|
|
1557
|
+
const opener = document.activeElement;
|
|
1558
|
+
function key(event) {
|
|
1559
|
+
if (event.key === "Escape") {
|
|
1560
|
+
event.stopPropagation();
|
|
1561
|
+
onClose();
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
function down(event) {
|
|
1565
|
+
const t = event.target;
|
|
1566
|
+
if (panel && !panel.contains(t) && !(trigger && trigger.contains(t))) onClose();
|
|
1567
|
+
}
|
|
1568
|
+
document.addEventListener("keydown", key, true);
|
|
1569
|
+
document.addEventListener("pointerdown", down, true);
|
|
1570
|
+
return () => {
|
|
1571
|
+
document.removeEventListener("keydown", key, true);
|
|
1572
|
+
document.removeEventListener("pointerdown", down, true);
|
|
1573
|
+
const active = document.activeElement;
|
|
1574
|
+
if (!active || active === document.body || panel && panel.contains(active)) {
|
|
1575
|
+
const back = opener && opener !== document.body && opener.isConnected ? opener : trigger;
|
|
1576
|
+
if (back) back.focus({ preventScroll: true });
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
}, [open, onClose, anchor]);
|
|
1580
|
+
const placed = pos != null;
|
|
1581
|
+
useEffect6(() => {
|
|
1582
|
+
if (!open || !placed || !ref.current) return;
|
|
1583
|
+
if (ref.current.contains(document.activeElement)) return;
|
|
1584
|
+
const first = ref.current.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
1585
|
+
(first || ref.current).focus({ preventScroll: true });
|
|
1586
|
+
}, [open, placed]);
|
|
1587
|
+
if (!open || typeof document === "undefined") return null;
|
|
1588
|
+
return createPortal(
|
|
1589
|
+
/* @__PURE__ */ jsx28(
|
|
1590
|
+
"div",
|
|
1591
|
+
{
|
|
1592
|
+
ref,
|
|
1593
|
+
role: "dialog",
|
|
1594
|
+
"aria-label": label,
|
|
1595
|
+
tabIndex: -1,
|
|
1596
|
+
className: cx("gt-popover", pos && "gt-popover--" + pos.side, className),
|
|
1597
|
+
style: pos ? { top: pos.top, left: pos.left } : { top: 0, left: 0, visibility: "hidden" },
|
|
1598
|
+
children
|
|
1599
|
+
}
|
|
1600
|
+
),
|
|
1601
|
+
document.body
|
|
1602
|
+
);
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
// src/label.tsx
|
|
1606
|
+
import { jsx as jsx29, jsxs as jsxs24 } from "react/jsx-runtime";
|
|
1607
|
+
function Label({ htmlFor, required, optional, children, className, ...rest }) {
|
|
1608
|
+
return /* @__PURE__ */ jsxs24("label", { ...rest, htmlFor, className: cx("gt-label", className), children: [
|
|
1609
|
+
children,
|
|
1610
|
+
required ? /* @__PURE__ */ jsx29("span", { className: "gt-label__req", "aria-hidden": true, children: "*" }) : null,
|
|
1611
|
+
optional && !required ? /* @__PURE__ */ jsx29("span", { className: "gt-label__opt", children: "(optional)" }) : null
|
|
1612
|
+
] });
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// src/slider.tsx
|
|
1616
|
+
import { useRef as useRef5, useState as useState6 } from "react";
|
|
1617
|
+
import { jsx as jsx30, jsxs as jsxs25 } from "react/jsx-runtime";
|
|
1618
|
+
function Slider({ value, defaultValue, onChange, min = 0, max = 100, step = 1, disabled, label, valueText, size = "md", className, id }) {
|
|
1619
|
+
const [current, set] = useControl(value, defaultValue != null ? defaultValue : min, onChange);
|
|
1620
|
+
const ref = useRef5(null);
|
|
1621
|
+
const [drag, setDrag] = useState6(false);
|
|
1622
|
+
function clamp2(next) {
|
|
1623
|
+
const stepped = Math.round((next - min) / step) * step + min;
|
|
1624
|
+
return Math.min(max, Math.max(min, +stepped.toFixed(4)));
|
|
1625
|
+
}
|
|
1626
|
+
function fromX(x) {
|
|
1627
|
+
const el = ref.current;
|
|
1628
|
+
if (!el) return;
|
|
1629
|
+
const rect = el.getBoundingClientRect();
|
|
1630
|
+
const fromStart = isRtl(el) ? rect.right - x : x - rect.left;
|
|
1631
|
+
set(clamp2(min + fromStart / rect.width * (max - min)));
|
|
1632
|
+
}
|
|
1633
|
+
const pct = (current - min) / (max - min) * 100;
|
|
1634
|
+
return /* @__PURE__ */ jsxs25(
|
|
1635
|
+
"div",
|
|
1636
|
+
{
|
|
1637
|
+
ref,
|
|
1638
|
+
id,
|
|
1639
|
+
role: "slider",
|
|
1640
|
+
tabIndex: disabled ? -1 : 0,
|
|
1641
|
+
"aria-label": label,
|
|
1642
|
+
"aria-valuemin": min,
|
|
1643
|
+
"aria-valuemax": max,
|
|
1644
|
+
"aria-valuenow": current,
|
|
1645
|
+
"aria-valuetext": valueText ? valueText(current) : void 0,
|
|
1646
|
+
"aria-disabled": disabled || void 0,
|
|
1647
|
+
className: cx("gt-range", "gt-range--" + size, drag && "is-dragging", disabled && "is-disabled", className),
|
|
1648
|
+
style: { ["--gt-range-pct"]: pct + "%" },
|
|
1649
|
+
onPointerDown: (event) => {
|
|
1650
|
+
if (disabled) return;
|
|
1651
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
1652
|
+
setDrag(true);
|
|
1653
|
+
fromX(event.clientX);
|
|
1654
|
+
},
|
|
1655
|
+
onPointerMove: (event) => {
|
|
1656
|
+
if (drag) fromX(event.clientX);
|
|
1657
|
+
},
|
|
1658
|
+
onPointerUp: () => {
|
|
1659
|
+
setDrag(false);
|
|
1660
|
+
},
|
|
1661
|
+
onPointerCancel: () => {
|
|
1662
|
+
setDrag(false);
|
|
1663
|
+
},
|
|
1664
|
+
onKeyDown: (event) => {
|
|
1665
|
+
if (disabled) return;
|
|
1666
|
+
const big = (max - min) / 10;
|
|
1667
|
+
const stepX = isRtl(event.currentTarget) ? -step : step;
|
|
1668
|
+
const delta = { ArrowRight: stepX, ArrowUp: step, ArrowLeft: -stepX, ArrowDown: -step, PageUp: big, PageDown: -big };
|
|
1669
|
+
const d = delta[event.key];
|
|
1670
|
+
if (event.key === "Home") {
|
|
1671
|
+
event.preventDefault();
|
|
1672
|
+
set(min);
|
|
1673
|
+
} else if (event.key === "End") {
|
|
1674
|
+
event.preventDefault();
|
|
1675
|
+
set(max);
|
|
1676
|
+
} else if (d) {
|
|
1677
|
+
event.preventDefault();
|
|
1678
|
+
set(clamp2(current + d));
|
|
1679
|
+
}
|
|
1680
|
+
},
|
|
1681
|
+
children: [
|
|
1682
|
+
/* @__PURE__ */ jsx30("span", { className: "gt-range__track", children: /* @__PURE__ */ jsx30("span", { className: "gt-range__fill" }) }),
|
|
1683
|
+
/* @__PURE__ */ jsx30("span", { className: "gt-range__thumb" })
|
|
1684
|
+
]
|
|
1685
|
+
}
|
|
1686
|
+
);
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
// src/skeleton.tsx
|
|
1690
|
+
import { jsx as jsx31 } from "react/jsx-runtime";
|
|
1691
|
+
function Skeleton({ width, height = 16, radius = "sm", className, style }) {
|
|
1692
|
+
return /* @__PURE__ */ jsx31(
|
|
1693
|
+
"span",
|
|
1694
|
+
{
|
|
1695
|
+
"aria-hidden": true,
|
|
1696
|
+
className: cx("gt-skeleton", "gt-skeleton--" + radius, className),
|
|
1697
|
+
style: { width: typeof width === "number" ? width + "px" : width, height: typeof height === "number" ? height + "px" : height, ...style }
|
|
1698
|
+
}
|
|
1699
|
+
);
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
// src/alert.tsx
|
|
1703
|
+
import { jsx as jsx32, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
1704
|
+
var ICON = { neutral: "info", info: "info", success: "circle-check", warning: "triangle-alert", danger: "circle-alert" };
|
|
1705
|
+
function Alert({ tone = "neutral", title, children, action, onClose, icon, className }) {
|
|
1706
|
+
const urgent = tone === "danger" || tone === "warning";
|
|
1707
|
+
return /* @__PURE__ */ jsxs26("div", { role: urgent ? "alert" : "status", className: cx("gt-alert", "gt-alert--" + tone, className), children: [
|
|
1708
|
+
/* @__PURE__ */ jsx32("span", { className: "gt-alert__icon", children: /* @__PURE__ */ jsx32(Icon2, { name: icon || ICON[tone], size: 20 }) }),
|
|
1709
|
+
/* @__PURE__ */ jsxs26("div", { className: "gt-alert__text", children: [
|
|
1710
|
+
title ? /* @__PURE__ */ jsx32("div", { className: "gt-alert__title", children: title }) : null,
|
|
1711
|
+
children ? /* @__PURE__ */ jsx32("div", { className: "gt-alert__desc", children }) : null,
|
|
1712
|
+
action ? /* @__PURE__ */ jsx32("div", { className: "gt-alert__action", children: action }) : null
|
|
1713
|
+
] }),
|
|
1714
|
+
onClose ? /* @__PURE__ */ jsx32(IconButton, { icon: "x", label: "Dismiss", size: "sm", variant: "tertiary", onClick: onClose, className: "gt-alert__close" }) : null
|
|
1715
|
+
] });
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
// src/breadcrumb.tsx
|
|
1719
|
+
import { jsx as jsx33, jsxs as jsxs27 } from "react/jsx-runtime";
|
|
1720
|
+
function Breadcrumb({ items, className, label = "Breadcrumb" }) {
|
|
1721
|
+
return /* @__PURE__ */ jsx33("nav", { "aria-label": label, className: cx("gt-crumbs", className), children: /* @__PURE__ */ jsx33("ol", { children: items.map((item, i) => {
|
|
1722
|
+
const last = i === items.length - 1;
|
|
1723
|
+
return /* @__PURE__ */ jsxs27("li", { children: [
|
|
1724
|
+
last ? /* @__PURE__ */ jsx33("span", { "aria-current": "page", className: "gt-crumbs__current", children: item.label }) : item.href ? /* @__PURE__ */ jsx33("a", { href: item.href, onClick: item.onClick, className: "gt-crumbs__link", children: item.label }) : /* @__PURE__ */ jsx33("button", { type: "button", onClick: item.onClick, className: "gt-crumbs__link", children: item.label }),
|
|
1725
|
+
!last ? /* @__PURE__ */ jsx33(Icon2, { name: "chevron-right", size: 16, className: "gt-crumbs__sep" }) : null
|
|
1726
|
+
] }, i);
|
|
1727
|
+
}) }) });
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
// src/tabs.tsx
|
|
1731
|
+
import { jsx as jsx34, jsxs as jsxs28 } from "react/jsx-runtime";
|
|
1732
|
+
function Tabs({ items, value, defaultValue, onChange, variant = "line", block, label, className }) {
|
|
1733
|
+
const [current, set] = useControl(value, defaultValue !== void 0 ? defaultValue : items[0] && items[0].value, onChange);
|
|
1734
|
+
const id = useStableId("tabs");
|
|
1735
|
+
const enabled = items.filter((t) => !t.disabled);
|
|
1736
|
+
function key(event) {
|
|
1737
|
+
const rtl = isRtl(event.currentTarget);
|
|
1738
|
+
const at2 = enabled.findIndex((t2) => t2.value === current);
|
|
1739
|
+
let next = -1;
|
|
1740
|
+
if (event.key === "ArrowRight") next = at2 + (rtl ? -1 : 1);
|
|
1741
|
+
else if (event.key === "ArrowLeft") next = at2 + (rtl ? 1 : -1);
|
|
1742
|
+
else if (event.key === "Home") next = 0;
|
|
1743
|
+
else if (event.key === "End") next = enabled.length - 1;
|
|
1744
|
+
else return;
|
|
1745
|
+
event.preventDefault();
|
|
1746
|
+
const t = enabled[(next + enabled.length) % enabled.length];
|
|
1747
|
+
set(t.value);
|
|
1748
|
+
const el = document.getElementById(id + "-tab-" + t.value);
|
|
1749
|
+
if (el) el.focus();
|
|
1750
|
+
}
|
|
1751
|
+
const active = items.find((t) => t.value === current);
|
|
1752
|
+
return /* @__PURE__ */ jsxs28("div", { className: cx("gt-tabs", "gt-tabs--" + variant, block && "gt-tabs--block", className), children: [
|
|
1753
|
+
/* @__PURE__ */ jsx34("div", { role: "tablist", "aria-label": label, className: "gt-tabs__list", children: items.map((t) => {
|
|
1754
|
+
const on = t.value === current;
|
|
1755
|
+
return /* @__PURE__ */ jsxs28(
|
|
1756
|
+
"button",
|
|
1757
|
+
{
|
|
1758
|
+
id: id + "-tab-" + t.value,
|
|
1759
|
+
type: "button",
|
|
1760
|
+
role: "tab",
|
|
1761
|
+
"aria-selected": on,
|
|
1762
|
+
"aria-controls": t.content != null ? id + "-panel" : void 0,
|
|
1763
|
+
tabIndex: on ? 0 : -1,
|
|
1764
|
+
disabled: t.disabled,
|
|
1765
|
+
className: cx("gt-tabs__tab", on && "is-on"),
|
|
1766
|
+
onClick: () => {
|
|
1767
|
+
set(t.value);
|
|
1768
|
+
},
|
|
1769
|
+
onKeyDown: key,
|
|
1770
|
+
children: [
|
|
1771
|
+
t.icon ? /* @__PURE__ */ jsx34(Icon2, { name: t.icon, size: 16 }) : null,
|
|
1772
|
+
/* @__PURE__ */ jsx34("span", { children: t.label }),
|
|
1773
|
+
t.count != null ? /* @__PURE__ */ jsx34("span", { className: "gt-tabs__count", children: t.count }) : null
|
|
1774
|
+
]
|
|
1775
|
+
},
|
|
1776
|
+
t.value
|
|
1777
|
+
);
|
|
1778
|
+
}) }),
|
|
1779
|
+
active && active.content != null ? /* @__PURE__ */ jsx34("div", { role: "tabpanel", id: id + "-panel", "aria-labelledby": id + "-tab-" + active.value, tabIndex: 0, className: "gt-tabs__panel", children: active.content }) : null
|
|
1780
|
+
] });
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
// src/accordion.tsx
|
|
1784
|
+
import { useState as useState7 } from "react";
|
|
1785
|
+
import { jsx as jsx35, jsxs as jsxs29 } from "react/jsx-runtime";
|
|
1786
|
+
function Accordion({ items, type = "single", defaultValue, className }) {
|
|
1787
|
+
const id = useStableId("acc");
|
|
1788
|
+
const initial = defaultValue == null ? [] : Array.isArray(defaultValue) ? defaultValue : [defaultValue];
|
|
1789
|
+
const [open, setOpen] = useState7(initial);
|
|
1790
|
+
function toggle(v) {
|
|
1791
|
+
setOpen((cur) => cur.includes(v) ? cur.filter((x) => x !== v) : type === "single" ? [v] : [...cur, v]);
|
|
1792
|
+
}
|
|
1793
|
+
return /* @__PURE__ */ jsx35("div", { className: cx("gt-acc", className), children: items.map((item) => {
|
|
1794
|
+
const on = open.includes(item.value);
|
|
1795
|
+
return /* @__PURE__ */ jsxs29("div", { className: cx("gt-acc__item", on && "is-open"), children: [
|
|
1796
|
+
/* @__PURE__ */ jsx35("h3", { className: "gt-acc__heading", children: /* @__PURE__ */ jsxs29(
|
|
1797
|
+
"button",
|
|
1798
|
+
{
|
|
1799
|
+
type: "button",
|
|
1800
|
+
id: id + "-h-" + item.value,
|
|
1801
|
+
"aria-expanded": on,
|
|
1802
|
+
"aria-controls": id + "-p-" + item.value,
|
|
1803
|
+
disabled: item.disabled,
|
|
1804
|
+
className: "gt-acc__trigger",
|
|
1805
|
+
onClick: () => {
|
|
1806
|
+
toggle(item.value);
|
|
1807
|
+
},
|
|
1808
|
+
children: [
|
|
1809
|
+
/* @__PURE__ */ jsx35("span", { children: item.title }),
|
|
1810
|
+
/* @__PURE__ */ jsx35(Icon2, { name: "chevron-down", size: 16, className: "gt-acc__chev" })
|
|
1811
|
+
]
|
|
1812
|
+
}
|
|
1813
|
+
) }),
|
|
1814
|
+
/* @__PURE__ */ jsx35("div", { role: "region", id: id + "-p-" + item.value, "aria-labelledby": id + "-h-" + item.value, className: "gt-acc__panel", hidden: !on, children: /* @__PURE__ */ jsx35("div", { className: "gt-acc__body", children: item.content }) })
|
|
1815
|
+
] }, item.value);
|
|
1816
|
+
}) });
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
// src/pagination.tsx
|
|
1820
|
+
import { jsx as jsx36, jsxs as jsxs30 } from "react/jsx-runtime";
|
|
1821
|
+
function pages(page, count, siblings) {
|
|
1822
|
+
const total = siblings * 2 + 5;
|
|
1823
|
+
if (count <= total) return Array.from({ length: count }, (_, i) => i + 1);
|
|
1824
|
+
const left = Math.max(page - siblings, 2), right = Math.min(page + siblings, count - 1);
|
|
1825
|
+
const out = [1];
|
|
1826
|
+
if (left > 2) out.push("\u2026");
|
|
1827
|
+
for (let p = left; p <= right; p++) out.push(p);
|
|
1828
|
+
if (right < count - 1) out.push("\u2026");
|
|
1829
|
+
out.push(count);
|
|
1830
|
+
return out;
|
|
1831
|
+
}
|
|
1832
|
+
function Pagination({ page, pageCount, onChange, siblings = 1, label = "Pagination", className }) {
|
|
1833
|
+
const go = (p) => {
|
|
1834
|
+
if (p >= 1 && p <= pageCount && p !== page && onChange) onChange(p);
|
|
1835
|
+
};
|
|
1836
|
+
return /* @__PURE__ */ jsxs30("nav", { "aria-label": label, className: cx("gt-pages", className), children: [
|
|
1837
|
+
/* @__PURE__ */ jsx36(IconButton, { icon: "chevron-left", label: "Previous page", size: "sm", variant: "tertiary", disabled: page <= 1, onClick: () => {
|
|
1838
|
+
go(page - 1);
|
|
1839
|
+
} }),
|
|
1840
|
+
pages(page, pageCount, siblings).map((p, i) => p === "\u2026" ? /* @__PURE__ */ jsx36("span", { className: "gt-pages__gap", "aria-hidden": true, children: "\u2026" }, "e" + i) : /* @__PURE__ */ jsx36("button", { type: "button", "aria-current": p === page ? "page" : void 0, className: cx("gt-pages__num", p === page && "is-on"), onClick: () => {
|
|
1841
|
+
go(p);
|
|
1842
|
+
}, children: p }, p)),
|
|
1843
|
+
/* @__PURE__ */ jsx36(IconButton, { icon: "chevron-right", label: "Next page", size: "sm", variant: "tertiary", disabled: page >= pageCount, onClick: () => {
|
|
1844
|
+
go(page + 1);
|
|
1845
|
+
} })
|
|
1846
|
+
] });
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
// src/table.tsx
|
|
1850
|
+
import { jsx as jsx37, jsxs as jsxs31 } from "react/jsx-runtime";
|
|
1851
|
+
function Table({ columns, rows, rowKey, caption, density = "comfortable", selectedKey, onRowClick, empty = "Nothing here yet", className }) {
|
|
1852
|
+
const keyOf = (row, i) => String(rowKey ? typeof rowKey === "function" ? rowKey(row) : row[rowKey] : i);
|
|
1853
|
+
return /* @__PURE__ */ jsx37("div", { className: cx("gt-table", "gt-table--" + density, className), children: /* @__PURE__ */ jsxs31("table", { children: [
|
|
1854
|
+
caption ? /* @__PURE__ */ jsx37("caption", { className: "gt-table__caption", children: caption }) : null,
|
|
1855
|
+
/* @__PURE__ */ jsx37("thead", { children: /* @__PURE__ */ jsx37("tr", { children: columns.map((c) => /* @__PURE__ */ jsx37("th", { scope: "col", style: { width: c.width, textAlign: c.align || "start" }, children: c.header }, c.key)) }) }),
|
|
1856
|
+
/* @__PURE__ */ jsx37("tbody", { children: rows.length === 0 ? /* @__PURE__ */ jsx37("tr", { children: /* @__PURE__ */ jsx37("td", { colSpan: columns.length, className: "gt-table__empty", children: empty }) }) : rows.map((row, i) => {
|
|
1857
|
+
const k = keyOf(row, i);
|
|
1858
|
+
return /* @__PURE__ */ jsx37(
|
|
1859
|
+
"tr",
|
|
1860
|
+
{
|
|
1861
|
+
"aria-selected": selectedKey != null ? selectedKey === k : void 0,
|
|
1862
|
+
className: cx(onRowClick && "is-clickable", selectedKey === k && "is-selected"),
|
|
1863
|
+
onClick: onRowClick ? () => {
|
|
1864
|
+
onRowClick(row);
|
|
1865
|
+
} : void 0,
|
|
1866
|
+
children: columns.map((c) => /* @__PURE__ */ jsx37("td", { style: { textAlign: c.align || "start" }, children: c.render ? c.render(row) : String(row[c.key] ?? "") }, c.key))
|
|
1867
|
+
},
|
|
1868
|
+
k
|
|
1869
|
+
);
|
|
1870
|
+
}) })
|
|
1871
|
+
] }) });
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// src/sheet.tsx
|
|
1875
|
+
import { useEffect as useEffect7, useRef as useRef6 } from "react";
|
|
1876
|
+
import { createPortal as createPortal2 } from "react-dom";
|
|
1877
|
+
import { jsx as jsx38, jsxs as jsxs32 } from "react/jsx-runtime";
|
|
1878
|
+
function Sheet({ open, onClose, side = "right", title, description, footer, size = "md", children, className }) {
|
|
1879
|
+
const ref = useRef6(null);
|
|
1880
|
+
const titleId = useStableId("sheet");
|
|
1881
|
+
useEffect7(() => {
|
|
1882
|
+
if (!open) return;
|
|
1883
|
+
const opener = document.activeElement;
|
|
1884
|
+
function key(event) {
|
|
1885
|
+
if (event.key === "Escape") onClose();
|
|
1886
|
+
}
|
|
1887
|
+
document.addEventListener("keydown", key);
|
|
1888
|
+
const first = ref.current && ref.current.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
1889
|
+
(first || ref.current)?.focus({ preventScroll: true });
|
|
1890
|
+
return () => {
|
|
1891
|
+
document.removeEventListener("keydown", key);
|
|
1892
|
+
if (opener && opener.isConnected) opener.focus({ preventScroll: true });
|
|
1893
|
+
};
|
|
1894
|
+
}, [open, onClose]);
|
|
1895
|
+
if (!open || typeof document === "undefined") return null;
|
|
1896
|
+
return createPortal2(
|
|
1897
|
+
/* @__PURE__ */ jsx38("div", { className: "gt-scrim gt-sheet-scrim", onClick: (event) => {
|
|
1898
|
+
if (event.target === event.currentTarget) onClose();
|
|
1899
|
+
}, children: /* @__PURE__ */ jsxs32("div", { ref, role: "dialog", "aria-modal": true, "aria-labelledby": titleId, tabIndex: -1, className: cx("gt-sheet", "gt-sheet--" + side, "gt-sheet--" + size, className), children: [
|
|
1900
|
+
/* @__PURE__ */ jsxs32("div", { className: "gt-sheet__head", children: [
|
|
1901
|
+
/* @__PURE__ */ jsxs32("div", { className: "gt-sheet__titles", children: [
|
|
1902
|
+
/* @__PURE__ */ jsx38("h2", { id: titleId, className: "gt-sheet__title", children: title }),
|
|
1903
|
+
description ? /* @__PURE__ */ jsx38("p", { className: "gt-sheet__desc", children: description }) : null
|
|
1904
|
+
] }),
|
|
1905
|
+
/* @__PURE__ */ jsx38(IconButton, { icon: "x", label: "Close", size: "sm", variant: "tertiary", onClick: onClose })
|
|
1906
|
+
] }),
|
|
1907
|
+
/* @__PURE__ */ jsx38("div", { className: "gt-sheet__body", children }),
|
|
1908
|
+
footer ? /* @__PURE__ */ jsx38("div", { className: "gt-sheet__foot", children: footer }) : null
|
|
1909
|
+
] }) }),
|
|
1910
|
+
document.body
|
|
1911
|
+
);
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
// src/dropdown-menu.tsx
|
|
1915
|
+
import { cloneElement, isValidElement, useRef as useRef7, useState as useState8 } from "react";
|
|
1916
|
+
import { Fragment as Fragment4, jsx as jsx39, jsxs as jsxs33 } from "react/jsx-runtime";
|
|
1917
|
+
function DropdownMenu({ trigger, items, side = "bottom", align = "start", label = "Menu", className }) {
|
|
1918
|
+
const [open, setOpen] = useState8(false);
|
|
1919
|
+
const anchor = useRef7(null);
|
|
1920
|
+
const id = useStableId("menu");
|
|
1921
|
+
function move(event) {
|
|
1922
|
+
const list = Array.from(event.currentTarget.querySelectorAll("[role='menuitem']:not([aria-disabled='true'])"));
|
|
1923
|
+
const at2 = list.indexOf(document.activeElement);
|
|
1924
|
+
let next = -1;
|
|
1925
|
+
if (event.key === "ArrowDown") next = at2 + 1;
|
|
1926
|
+
else if (event.key === "ArrowUp") next = at2 - 1;
|
|
1927
|
+
else if (event.key === "Home") next = 0;
|
|
1928
|
+
else if (event.key === "End") next = list.length - 1;
|
|
1929
|
+
else if (event.key === "Tab") {
|
|
1930
|
+
setOpen(false);
|
|
1931
|
+
return;
|
|
1932
|
+
} else return;
|
|
1933
|
+
event.preventDefault();
|
|
1934
|
+
const el = list[(next + list.length) % list.length];
|
|
1935
|
+
if (el) el.focus();
|
|
1936
|
+
}
|
|
1937
|
+
const triggerEl = isValidElement(trigger) ? cloneElement(trigger, {
|
|
1938
|
+
"aria-haspopup": "menu",
|
|
1939
|
+
"aria-expanded": open,
|
|
1940
|
+
"aria-controls": open ? id : void 0,
|
|
1941
|
+
onClick: () => {
|
|
1942
|
+
setOpen((o) => !o);
|
|
1943
|
+
},
|
|
1944
|
+
onKeyDown: (event) => {
|
|
1945
|
+
if (event.key === "ArrowDown") {
|
|
1946
|
+
event.preventDefault();
|
|
1947
|
+
setOpen(true);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
}) : trigger;
|
|
1951
|
+
return /* @__PURE__ */ jsxs33(Fragment4, { children: [
|
|
1952
|
+
/* @__PURE__ */ jsx39("span", { ref: anchor, className: "gt-menu-anchor", children: triggerEl }),
|
|
1953
|
+
/* @__PURE__ */ jsx39(Popover, { open, onClose: () => {
|
|
1954
|
+
setOpen(false);
|
|
1955
|
+
}, anchor, side, align, label, className: cx("gt-menu", className), children: /* @__PURE__ */ jsx39("div", { id, role: "menu", "aria-label": label, onKeyDown: move, children: items.map((it, i) => {
|
|
1956
|
+
if (it.type === "separator") return /* @__PURE__ */ jsx39("div", { role: "separator", className: "gt-menu__sep" }, i);
|
|
1957
|
+
if (it.type === "label") return /* @__PURE__ */ jsx39("div", { className: "gt-menu__label", children: it.label }, i);
|
|
1958
|
+
return /* @__PURE__ */ jsxs33(
|
|
1959
|
+
"button",
|
|
1960
|
+
{
|
|
1961
|
+
type: "button",
|
|
1962
|
+
role: "menuitem",
|
|
1963
|
+
"aria-disabled": it.disabled || void 0,
|
|
1964
|
+
tabIndex: -1,
|
|
1965
|
+
className: cx("gt-menu__item", it.danger && "is-danger"),
|
|
1966
|
+
onClick: () => {
|
|
1967
|
+
if (it.disabled) return;
|
|
1968
|
+
setOpen(false);
|
|
1969
|
+
if (it.onSelect) it.onSelect();
|
|
1970
|
+
},
|
|
1971
|
+
children: [
|
|
1972
|
+
it.icon ? /* @__PURE__ */ jsx39(Icon2, { name: it.icon, size: 16 }) : null,
|
|
1973
|
+
/* @__PURE__ */ jsx39("span", { className: "gt-menu__text", children: it.label }),
|
|
1974
|
+
it.shortcut ? /* @__PURE__ */ jsx39("kbd", { className: "gt-menu__kbd", children: it.shortcut }) : null
|
|
1975
|
+
]
|
|
1976
|
+
},
|
|
1977
|
+
i
|
|
1978
|
+
);
|
|
1979
|
+
}) }) })
|
|
1980
|
+
] });
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
// src/palette.ts
|
|
1984
|
+
var BRAND_STEPS = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
1985
|
+
var TARGET_L = [0.975, 0.94, 0.885, 0.81, 0.71, 0.63, 0.555, 0.49, 0.425, 0.38, 0.28];
|
|
1986
|
+
var CHROMA = [0.12, 0.26, 0.46, 0.7, 0.9, 1, 1, 0.92, 0.8, 0.68, 0.5];
|
|
1987
|
+
function parseHex(hex) {
|
|
1988
|
+
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
|
|
1989
|
+
if (!m) throw new Error(`Expected a hex colour like #8419eb, got "${hex}"`);
|
|
1990
|
+
const s = m[1].length === 3 ? m[1].replace(/./g, "$&$&") : m[1];
|
|
1991
|
+
return [0, 2, 4].map((i) => parseInt(s.slice(i, i + 2), 16) / 255);
|
|
1992
|
+
}
|
|
1993
|
+
function toHex2(rgb) {
|
|
1994
|
+
return "#" + rgb.map((v) => Math.round(Math.min(1, Math.max(0, v)) * 255).toString(16).padStart(2, "0")).join("");
|
|
1995
|
+
}
|
|
1996
|
+
var toLinear = (v) => v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
1997
|
+
var toGamma = (v) => v <= 31308e-7 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055;
|
|
1998
|
+
function rgbToLch(rgb) {
|
|
1999
|
+
const [r, g, b] = rgb.map(toLinear);
|
|
2000
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
2001
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
2002
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
2003
|
+
const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
|
|
2004
|
+
const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
|
|
2005
|
+
const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
|
|
2006
|
+
return [L, Math.hypot(A, B), Math.atan2(B, A) * 180 / Math.PI];
|
|
2007
|
+
}
|
|
2008
|
+
function lchToLinear([L, C, H]) {
|
|
2009
|
+
const a = C * Math.cos(H * Math.PI / 180);
|
|
2010
|
+
const b = C * Math.sin(H * Math.PI / 180);
|
|
2011
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
2012
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
2013
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
2014
|
+
return [
|
|
2015
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
2016
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
2017
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
|
|
2018
|
+
];
|
|
2019
|
+
}
|
|
2020
|
+
function lchToHex(lch) {
|
|
2021
|
+
const inGamut = (c2) => lchToLinear([lch[0], c2, lch[2]]).every((v) => v >= -5e-4 && v <= 1.0005);
|
|
2022
|
+
let c = lch[1];
|
|
2023
|
+
if (!inGamut(c)) {
|
|
2024
|
+
let lo = 0;
|
|
2025
|
+
for (let i = 0; i < 24; i++) {
|
|
2026
|
+
const mid = (lo + c) / 2;
|
|
2027
|
+
if (inGamut(mid)) lo = mid;
|
|
2028
|
+
else c = mid;
|
|
2029
|
+
}
|
|
2030
|
+
c = lo;
|
|
2031
|
+
}
|
|
2032
|
+
return toHex2(lchToLinear([lch[0], c, lch[2]]).map(toGamma));
|
|
2033
|
+
}
|
|
2034
|
+
function luminance(hex) {
|
|
2035
|
+
const [r, g, b] = parseHex(hex).map(toLinear);
|
|
2036
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
2037
|
+
}
|
|
2038
|
+
function contrastRatio(a, b) {
|
|
2039
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
2040
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
2041
|
+
}
|
|
2042
|
+
function brandScale(hex) {
|
|
2043
|
+
const input = parseHex(hex);
|
|
2044
|
+
const [L, C, H] = rgbToLch(input);
|
|
2045
|
+
let baseIndex = 0;
|
|
2046
|
+
TARGET_L.forEach((t, i) => {
|
|
2047
|
+
if (Math.abs(t - L) < Math.abs(TARGET_L[baseIndex] - L)) baseIndex = i;
|
|
2048
|
+
});
|
|
2049
|
+
const peak = C / CHROMA[baseIndex];
|
|
2050
|
+
const shift = L - TARGET_L[baseIndex];
|
|
2051
|
+
const scale = {};
|
|
2052
|
+
BRAND_STEPS.forEach((step, i) => {
|
|
2053
|
+
if (i === baseIndex) {
|
|
2054
|
+
scale[step] = toHex2(input);
|
|
2055
|
+
return;
|
|
2056
|
+
}
|
|
2057
|
+
const taper = Math.max(0, 1 - Math.abs(i - baseIndex) / 4);
|
|
2058
|
+
scale[step] = lchToHex([TARGET_L[i] + shift * taper, peak * CHROMA[i], H]);
|
|
2059
|
+
});
|
|
2060
|
+
return { scale, base: BRAND_STEPS[baseIndex] };
|
|
2061
|
+
}
|
|
2062
|
+
var at = (i) => BRAND_STEPS[Math.min(BRAND_STEPS.length - 1, Math.max(0, i))];
|
|
2063
|
+
var LIGHT_SURFACES = ["#ffffff", "#fafafa"];
|
|
2064
|
+
var DARK_SURFACES = ["#1f1f22", "#0f0f11"];
|
|
2065
|
+
var TEXT_AA = 4.5;
|
|
2066
|
+
var UI_AA = 3;
|
|
2067
|
+
var passes = (fg, surfaces, min) => surfaces.every((bg) => contrastRatio(fg, bg) >= min);
|
|
2068
|
+
function firstPassing(scale, steps, surfaces, min) {
|
|
2069
|
+
for (const s of steps) if (passes(scale[s], surfaces, min)) return scale[s];
|
|
2070
|
+
return scale[steps[steps.length - 1]];
|
|
2071
|
+
}
|
|
2072
|
+
function onColour(bg, dark) {
|
|
2073
|
+
return contrastRatio(bg, "#ffffff") >= contrastRatio(bg, dark) ? "#ffffff" : dark;
|
|
2074
|
+
}
|
|
2075
|
+
function readableBase(scale, from, dir) {
|
|
2076
|
+
for (let i = from; i >= 0 && i < BRAND_STEPS.length; i += dir) {
|
|
2077
|
+
const bg = scale[BRAND_STEPS[i]];
|
|
2078
|
+
if (contrastRatio(bg, onColour(bg, scale[950])) >= TEXT_AA) return i;
|
|
2079
|
+
}
|
|
2080
|
+
return from;
|
|
2081
|
+
}
|
|
2082
|
+
var DARK_LABEL_MIN = 7;
|
|
2083
|
+
function brightForDarkLabel(scale, i) {
|
|
2084
|
+
const fg = (k) => onColour(scale[at(k)], scale[950]);
|
|
2085
|
+
if (fg(i) === "#ffffff") return i;
|
|
2086
|
+
for (let k = i; k >= 1; k--) {
|
|
2087
|
+
if (fg(k) !== "#ffffff" && contrastRatio(scale[at(k)], scale[950]) >= DARK_LABEL_MIN) return k;
|
|
2088
|
+
}
|
|
2089
|
+
return i;
|
|
2090
|
+
}
|
|
2091
|
+
function stateStep(scale, base, fg, n) {
|
|
2092
|
+
const dir = fg === "#ffffff" ? 1 : -1;
|
|
2093
|
+
for (let k = n; k >= 1; k--) {
|
|
2094
|
+
const c = scale[at(base + dir * k)];
|
|
2095
|
+
if (contrastRatio(c, fg) >= TEXT_AA) return c;
|
|
2096
|
+
}
|
|
2097
|
+
return scale[at(base)];
|
|
2098
|
+
}
|
|
2099
|
+
function brandTokens(hex) {
|
|
2100
|
+
const { scale, base } = brandScale(hex);
|
|
2101
|
+
const b = brightForDarkLabel(scale, readableBase(scale, BRAND_STEPS.indexOf(base), 1));
|
|
2102
|
+
const lightBase = scale[at(b)];
|
|
2103
|
+
const d = brightForDarkLabel(scale, readableBase(scale, Math.min(BRAND_STEPS.indexOf(base), BRAND_STEPS.indexOf(400)), -1));
|
|
2104
|
+
const darkBase = scale[at(d)];
|
|
2105
|
+
const lightFg = onColour(lightBase, scale[950]), darkFg = onColour(darkBase, scale[950]);
|
|
2106
|
+
const light = {
|
|
2107
|
+
"color-bg-brand-primary": lightBase,
|
|
2108
|
+
"color-bg-brand-primary-hover": stateStep(scale, b, lightFg, 1),
|
|
2109
|
+
"color-bg-brand-primary-pressed": stateStep(scale, b, lightFg, 2),
|
|
2110
|
+
"color-text-onbrand-primary": lightFg,
|
|
2111
|
+
...accentLight(scale)
|
|
2112
|
+
};
|
|
2113
|
+
const dark = {
|
|
2114
|
+
"color-bg-brand-primary": darkBase,
|
|
2115
|
+
"color-bg-brand-primary-hover": stateStep(scale, d, darkFg, 1),
|
|
2116
|
+
"color-bg-brand-primary-pressed": stateStep(scale, d, darkFg, 2),
|
|
2117
|
+
"color-text-onbrand-primary": darkFg,
|
|
2118
|
+
...accentDark(scale)
|
|
2119
|
+
};
|
|
2120
|
+
return { scale, base, light, dark };
|
|
2121
|
+
}
|
|
2122
|
+
function accentLight(scale) {
|
|
2123
|
+
return {
|
|
2124
|
+
"color-bg-accent-primary": firstPassing(scale, [600, 700, 800, 900], LIGHT_SURFACES, UI_AA),
|
|
2125
|
+
"color-text-accent-primary": firstPassing(scale, [700, 800, 900, 950], LIGHT_SURFACES, TEXT_AA),
|
|
2126
|
+
"color-bg-accent-secondary": scale[50]
|
|
2127
|
+
};
|
|
2128
|
+
}
|
|
2129
|
+
function accentDark(scale) {
|
|
2130
|
+
return {
|
|
2131
|
+
"color-bg-accent-primary": firstPassing(scale, [500, 400, 300, 200], DARK_SURFACES, UI_AA),
|
|
2132
|
+
"color-text-accent-primary": firstPassing(scale, [300, 200, 100, 50], DARK_SURFACES, TEXT_AA),
|
|
2133
|
+
"color-bg-accent-secondary": scale[950]
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
function accentTokens(hex) {
|
|
2137
|
+
const { scale } = brandScale(hex);
|
|
2138
|
+
return {
|
|
2139
|
+
scale,
|
|
2140
|
+
light: { ...accentLight(scale), "chart-2": scale[500], "chart-compare": scale[400] },
|
|
2141
|
+
dark: { ...accentDark(scale), "chart-2": scale[400], "chart-compare": scale[500] }
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
2144
|
+
function brandCss(hex, id = "custom", options = {}) {
|
|
2145
|
+
const primary = hex ? brandTokens(hex) : null;
|
|
2146
|
+
const accent = options.accent ? accentTokens(options.accent) : null;
|
|
2147
|
+
const light = { ...primary ? primary.light : {}, ...accent ? accent.light : {} };
|
|
2148
|
+
const dark = { ...primary ? primary.dark : {}, ...accent ? accent.dark : {} };
|
|
2149
|
+
const sel = `[data-brand="${id}"]`;
|
|
2150
|
+
const decls = (theme) => Object.entries(theme).map(([k, v]) => ` --${k}: ${v};`).join("\n");
|
|
2151
|
+
const scales = [
|
|
2152
|
+
...primary ? BRAND_STEPS.map((s) => ` --brand-${s}: ${primary.scale[s]};`) : [],
|
|
2153
|
+
...accent ? BRAND_STEPS.map((s) => ` --accent-${s}: ${accent.scale[s]};`) : []
|
|
2154
|
+
].join("\n");
|
|
2155
|
+
return [
|
|
2156
|
+
`${sel} {
|
|
2157
|
+
${scales ? scales + "\n" : ""}${decls(light)}
|
|
2158
|
+
}`,
|
|
2159
|
+
// The theme can sit on the brand element itself or on any ancestor (e.g. <html>), so a brand scoped to one section still follows it.
|
|
2160
|
+
`${sel}[data-theme="light"], ${sel}.light, [data-theme="light"] ${sel}, .light ${sel} {
|
|
2161
|
+
${decls(light)}
|
|
2162
|
+
}`,
|
|
2163
|
+
`${sel}[data-theme="dark"], ${sel}.dark, [data-theme="dark"] ${sel}, .dark ${sel} {
|
|
2164
|
+
${decls(dark)}
|
|
2165
|
+
}`,
|
|
2166
|
+
`@media (prefers-color-scheme: dark) {
|
|
2167
|
+
${sel}:not([data-theme="light"]):not(.light):not([data-theme="light"] *):not(.light *) {
|
|
2168
|
+
${decls(dark).replace(/^/gm, " ")}
|
|
2169
|
+
}
|
|
2170
|
+
}`
|
|
2171
|
+
].join("\n");
|
|
2172
|
+
}
|
|
2173
|
+
export {
|
|
2174
|
+
Accordion,
|
|
2175
|
+
Alert,
|
|
2176
|
+
Avatar,
|
|
2177
|
+
BRAND_STEPS,
|
|
2178
|
+
Badge,
|
|
2179
|
+
BarChart,
|
|
2180
|
+
Breadcrumb,
|
|
2181
|
+
Button,
|
|
2182
|
+
Card,
|
|
2183
|
+
Checkbox,
|
|
2184
|
+
ChipGroup,
|
|
2185
|
+
ColorPicker,
|
|
2186
|
+
Dialog,
|
|
2187
|
+
Divider,
|
|
2188
|
+
DonutChart,
|
|
2189
|
+
DropdownMenu,
|
|
2190
|
+
Heading,
|
|
2191
|
+
Icon2 as Icon,
|
|
2192
|
+
IconButton,
|
|
2193
|
+
IconSetProvider,
|
|
2194
|
+
Input,
|
|
2195
|
+
Kbd,
|
|
2196
|
+
Label,
|
|
2197
|
+
LineChart,
|
|
2198
|
+
ListRow,
|
|
2199
|
+
Pagination,
|
|
2200
|
+
Popover,
|
|
2201
|
+
Progress,
|
|
2202
|
+
RadioCards,
|
|
2203
|
+
RadioGroup,
|
|
2204
|
+
SegmentedControl,
|
|
2205
|
+
Select,
|
|
2206
|
+
Sheet,
|
|
2207
|
+
Skeleton,
|
|
2208
|
+
Slider,
|
|
2209
|
+
Sparkline,
|
|
2210
|
+
Stat,
|
|
2211
|
+
Switch,
|
|
2212
|
+
Table,
|
|
2213
|
+
Tabs,
|
|
2214
|
+
Text,
|
|
2215
|
+
Textarea,
|
|
2216
|
+
Toast,
|
|
2217
|
+
Tooltip,
|
|
2218
|
+
accentTokens,
|
|
2219
|
+
brandCss,
|
|
2220
|
+
brandScale,
|
|
2221
|
+
brandTokens,
|
|
2222
|
+
contrastRatio,
|
|
2223
|
+
parseColor
|
|
2224
|
+
};
|