@underpin/ui 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +45 -2
- package/components/autocomplete.d.ts +25 -0
- package/components/autocomplete.js +71 -0
- package/components/autocomplete.js.map +1 -0
- package/components/avatar.d.ts +5 -0
- package/components/avatar.js +26 -0
- package/components/avatar.js.map +1 -0
- package/components/badge.d.ts +36 -0
- package/components/badge.js +140 -0
- package/components/badge.js.map +1 -0
- package/components/bar-list.d.ts +133 -0
- package/components/bar-list.js +204 -0
- package/components/bar-list.js.map +1 -0
- package/components/breakdown-card.d.ts +30 -0
- package/components/breakdown-card.js +43 -0
- package/components/breakdown-card.js.map +1 -0
- package/components/button-group.d.ts +17 -0
- package/components/button-group.js +27 -0
- package/components/button-group.js.map +1 -0
- package/components/button.d.ts +39 -0
- package/components/button.js +128 -0
- package/components/button.js.map +1 -0
- package/components/calendar.d.ts +27 -0
- package/components/calendar.js +95 -0
- package/components/calendar.js.map +1 -0
- package/components/callout.d.ts +26 -0
- package/components/callout.js +71 -0
- package/components/callout.js.map +1 -0
- package/components/card.d.ts +55 -0
- package/components/card.js +96 -0
- package/components/card.js.map +1 -0
- package/components/chart.d.ts +32 -0
- package/components/chart.js +43 -0
- package/components/chart.js.map +1 -0
- package/components/checkbox.d.ts +15 -0
- package/components/checkbox.js +42 -0
- package/components/checkbox.js.map +1 -0
- package/components/code-block.d.ts +21 -0
- package/components/code-block.js +35 -0
- package/components/code-block.js.map +1 -0
- package/components/collapse.d.ts +14 -0
- package/components/collapse.js +25 -0
- package/components/collapse.js.map +1 -0
- package/components/combobox.d.ts +71 -0
- package/components/combobox.js +155 -0
- package/components/combobox.js.map +1 -0
- package/components/copy-button.d.ts +29 -0
- package/components/copy-button.js +100 -0
- package/components/copy-button.js.map +1 -0
- package/components/copy-input.d.ts +15 -0
- package/components/copy-input.js +51 -0
- package/components/copy-input.js.map +1 -0
- package/components/date-picker-trigger.d.ts +12 -0
- package/components/date-picker-trigger.js +30 -0
- package/components/date-picker-trigger.js.map +1 -0
- package/components/date-picker.d.ts +36 -0
- package/components/date-picker.js +70 -0
- package/components/date-picker.js.map +1 -0
- package/components/detail-row.d.ts +51 -0
- package/components/detail-row.js +77 -0
- package/components/detail-row.js.map +1 -0
- package/components/dialog.d.ts +121 -0
- package/components/dialog.js +327 -0
- package/components/dialog.js.map +1 -0
- package/components/disabled-reason.d.ts +31 -0
- package/components/disabled-reason.js +67 -0
- package/components/disabled-reason.js.map +1 -0
- package/components/empty-state.d.ts +41 -0
- package/components/empty-state.js +84 -0
- package/components/empty-state.js.map +1 -0
- package/components/entity-avatar.d.ts +54 -0
- package/components/entity-avatar.js +68 -0
- package/components/entity-avatar.js.map +1 -0
- package/components/form-section.d.ts +22 -0
- package/components/form-section.js +38 -0
- package/components/form-section.js.map +1 -0
- package/components/form.d.ts +199 -0
- package/components/form.js +456 -0
- package/components/form.js.map +1 -0
- package/components/formatted-number.d.ts +21 -0
- package/components/formatted-number.js +13 -0
- package/components/formatted-number.js.map +1 -0
- package/components/heading.d.ts +23 -0
- package/components/heading.js +44 -0
- package/components/heading.js.map +1 -0
- package/components/icon-swap.d.ts +15 -0
- package/components/icon-swap.js +29 -0
- package/components/icon-swap.js.map +1 -0
- package/components/inline-action.d.ts +21 -0
- package/components/inline-action.js +36 -0
- package/components/inline-action.js.map +1 -0
- package/components/input.d.ts +51 -0
- package/components/input.js +52 -0
- package/components/input.js.map +1 -0
- package/components/kbd.d.ts +17 -0
- package/components/kbd.js +34 -0
- package/components/kbd.js.map +1 -0
- package/components/label.d.ts +10 -0
- package/components/label.js +20 -0
- package/components/label.js.map +1 -0
- package/components/menu.d.ts +77 -0
- package/components/menu.js +189 -0
- package/components/menu.js.map +1 -0
- package/components/nav-button.d.ts +34 -0
- package/components/nav-button.js +71 -0
- package/components/nav-button.js.map +1 -0
- package/components/nav.d.ts +39 -0
- package/components/nav.js +68 -0
- package/components/nav.js.map +1 -0
- package/components/number-input.d.ts +16 -0
- package/components/number-input.js +25 -0
- package/components/number-input.js.map +1 -0
- package/components/page.d.ts +14 -0
- package/components/page.js +23 -0
- package/components/page.js.map +1 -0
- package/components/pagination.d.ts +15 -0
- package/components/pagination.js +63 -0
- package/components/pagination.js.map +1 -0
- package/components/ping.d.ts +38 -0
- package/components/ping.js +50 -0
- package/components/ping.js.map +1 -0
- package/components/popover.d.ts +5 -0
- package/components/popover.js +25 -0
- package/components/popover.js.map +1 -0
- package/components/radio-group.d.ts +35 -0
- package/components/radio-group.js +81 -0
- package/components/radio-group.js.map +1 -0
- package/components/relative-time.d.ts +25 -0
- package/components/relative-time.js +51 -0
- package/components/relative-time.js.map +1 -0
- package/components/saved-mark.d.ts +15 -0
- package/components/saved-mark.js +45 -0
- package/components/saved-mark.js.map +1 -0
- package/components/search-input.d.ts +13 -0
- package/components/search-input.js +44 -0
- package/components/search-input.js.map +1 -0
- package/components/section-header.d.ts +83 -0
- package/components/section-header.js +170 -0
- package/components/section-header.js.map +1 -0
- package/components/segmented-control.d.ts +24 -0
- package/components/segmented-control.js +70 -0
- package/components/segmented-control.js.map +1 -0
- package/components/select.d.ts +28 -0
- package/components/select.js +129 -0
- package/components/select.js.map +1 -0
- package/components/shortcut-keys.d.ts +14 -0
- package/components/shortcut-keys.js +32 -0
- package/components/shortcut-keys.js.map +1 -0
- package/components/shortcuts-dialog.d.ts +10 -0
- package/components/shortcuts-dialog.js +92 -0
- package/components/shortcuts-dialog.js.map +1 -0
- package/components/skeleton.d.ts +8 -0
- package/components/skeleton.js +23 -0
- package/components/skeleton.js.map +1 -0
- package/components/sparkline.d.ts +25 -0
- package/components/sparkline.js +70 -0
- package/components/sparkline.js.map +1 -0
- package/components/stack.d.ts +21 -0
- package/components/stack.js +45 -0
- package/components/stack.js.map +1 -0
- package/components/stat-strip.d.ts +43 -0
- package/components/stat-strip.js +151 -0
- package/components/stat-strip.js.map +1 -0
- package/components/steps.d.ts +19 -0
- package/components/steps.js +25 -0
- package/components/steps.js.map +1 -0
- package/components/switch.d.ts +16 -0
- package/components/switch.js +29 -0
- package/components/switch.js.map +1 -0
- package/components/tabs.d.ts +18 -0
- package/components/tabs.js +65 -0
- package/components/tabs.js.map +1 -0
- package/components/text-link.d.ts +16 -0
- package/components/text-link.js +32 -0
- package/components/text-link.js.map +1 -0
- package/components/textarea.d.ts +10 -0
- package/components/textarea.js +23 -0
- package/components/textarea.js.map +1 -0
- package/components/theme.d.ts +28 -0
- package/components/theme.js +158 -0
- package/components/theme.js.map +1 -0
- package/components/time-series-chart.d.ts +122 -0
- package/components/time-series-chart.js +722 -0
- package/components/time-series-chart.js.map +1 -0
- package/components/toaster.d.ts +3 -0
- package/components/toaster.js +44 -0
- package/components/toaster.js.map +1 -0
- package/components/tooltip.d.ts +64 -0
- package/components/tooltip.js +126 -0
- package/components/tooltip.js.map +1 -0
- package/components/view-picker.d.ts +20 -0
- package/components/view-picker.js +24 -0
- package/components/view-picker.js.map +1 -0
- package/fonts/inter-OFL.txt +93 -0
- package/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/fonts/inter-cyrillic.woff2 +0 -0
- package/fonts/inter-greek-ext.woff2 +0 -0
- package/fonts/inter-greek.woff2 +0 -0
- package/fonts/inter-latin-ext.woff2 +0 -0
- package/fonts/inter-latin.woff2 +0 -0
- package/fonts/inter-vietnamese.woff2 +0 -0
- package/fonts.css +83 -0
- package/lib/animation.d.ts +14 -0
- package/lib/animation.js +20 -0
- package/lib/animation.js.map +1 -0
- package/lib/aria.d.ts +5 -0
- package/lib/aria.js +12 -0
- package/lib/aria.js.map +1 -0
- package/lib/chart-curve.d.ts +13 -0
- package/lib/chart-curve.js +79 -0
- package/lib/chart-curve.js.map +1 -0
- package/lib/classes.d.ts +134 -0
- package/lib/classes.js +152 -0
- package/lib/classes.js.map +1 -0
- package/lib/color.d.ts +25 -0
- package/lib/color.js +149 -0
- package/lib/color.js.map +1 -0
- package/lib/day.d.ts +9 -0
- package/lib/day.js +20 -0
- package/lib/day.js.map +1 -0
- package/lib/design-tokens.d.ts +56 -0
- package/lib/design-tokens.js +196 -0
- package/lib/design-tokens.js.map +1 -0
- package/lib/icon.d.ts +17 -0
- package/lib/icon.js +34 -0
- package/lib/icon.js.map +1 -0
- package/lib/icons.d.ts +23 -0
- package/lib/icons.js +28 -0
- package/lib/icons.js.map +1 -0
- package/lib/interactive.d.ts +21 -0
- package/lib/interactive.js +31 -0
- package/lib/interactive.js.map +1 -0
- package/lib/media.d.ts +58 -0
- package/lib/media.js +116 -0
- package/lib/media.js.map +1 -0
- package/lib/segmented.d.ts +57 -0
- package/lib/segmented.js +83 -0
- package/lib/segmented.js.map +1 -0
- package/lib/shortcuts.d.ts +94 -0
- package/lib/shortcuts.js +271 -0
- package/lib/shortcuts.js.map +1 -0
- package/lib/slot.d.ts +9 -0
- package/lib/slot.js +18 -0
- package/lib/slot.js.map +1 -0
- package/lib/time-series.d.ts +100 -0
- package/lib/time-series.js +144 -0
- package/lib/time-series.js.map +1 -0
- package/lib/tone.d.ts +6 -0
- package/lib/tone.js +0 -0
- package/lib/variants.d.ts +12 -0
- package/lib/variants.js +14 -0
- package/lib/variants.js.map +1 -0
- package/package.json +116 -4
- package/styles.css +619 -0
- package/tokens.d.ts +104 -0
- package/tokens.js +108 -0
- package/tokens.js.map +1 -0
package/lib/color.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// src/lib/color.ts
|
|
2
|
+
const THEMES = ["light", "dark"];
|
|
3
|
+
function collapseWhitespace(value) {
|
|
4
|
+
return value.replace(/\s+/g, " ").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
|
|
5
|
+
}
|
|
6
|
+
/** The stylesheet without its comments, which quote declarations (`--gray-chroma: 0`) as prose. */
|
|
7
|
+
function stripComments(css) {
|
|
8
|
+
return css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
9
|
+
}
|
|
10
|
+
function createLookup(css) {
|
|
11
|
+
const code = stripComments(css);
|
|
12
|
+
return (name) => {
|
|
13
|
+
const value = code.match(new RegExp(`--${name}:\\s*([^;]+);`))?.[1];
|
|
14
|
+
if (value === void 0) return;
|
|
15
|
+
return collapseWhitespace(value);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Splits `value` on each top-level `separator` (a comma by default), not those in nested calls. */
|
|
19
|
+
function splitTopLevel(value, separator = ",") {
|
|
20
|
+
const parts = [];
|
|
21
|
+
let depth = 0;
|
|
22
|
+
let current = "";
|
|
23
|
+
for (const character of value) {
|
|
24
|
+
if (character === "(") depth++;
|
|
25
|
+
if (character === ")") depth--;
|
|
26
|
+
if (character === separator && depth === 0) {
|
|
27
|
+
parts.push(current.trim());
|
|
28
|
+
current = "";
|
|
29
|
+
} else current += character;
|
|
30
|
+
}
|
|
31
|
+
parts.push(current.trim());
|
|
32
|
+
return parts;
|
|
33
|
+
}
|
|
34
|
+
/** `value` with every `var(--name)` replaced by what that variable holds, all the way down. */
|
|
35
|
+
function substitute(value, lookup, depth = 0) {
|
|
36
|
+
if (depth > 8) throw new Error(`var() nests too deep in ${value}`);
|
|
37
|
+
return value.replace(/var\(--([a-z0-9-]+)\)/g, (_match, name) => {
|
|
38
|
+
const resolved = lookup(name);
|
|
39
|
+
if (resolved === void 0) throw new Error(`--${name} is not declared`);
|
|
40
|
+
return substitute(resolved, lookup, depth + 1);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** A number, or a `calc()` that multiplies numbers, which is all the stylesheet's colours use. */
|
|
44
|
+
function evaluate(expression) {
|
|
45
|
+
const body = expression.match(/^calc\((.+)\)$/)?.[1];
|
|
46
|
+
const value = (body ? body.split("*") : [expression]).reduce((result, factor) => result * Number.parseFloat(factor.trim()), 1);
|
|
47
|
+
if (Number.isNaN(value)) throw new Error(`Cannot evaluate ${expression}`);
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
function readAlpha(value) {
|
|
51
|
+
if (value === void 0) return 1;
|
|
52
|
+
return value.endsWith("%") ? Number.parseFloat(value) / 100 : Number.parseFloat(value);
|
|
53
|
+
}
|
|
54
|
+
/** One side of a colour expression with no `var()` left in it. */
|
|
55
|
+
function parseColor(expression, theme) {
|
|
56
|
+
const [, name, body = ""] = expression.match(/^([a-z-]+)\((.*)\)$/s) ?? [];
|
|
57
|
+
if (name === "light-dark") {
|
|
58
|
+
const [light = "", dark = ""] = splitTopLevel(body);
|
|
59
|
+
return parseColor(theme === "light" ? light : dark, theme);
|
|
60
|
+
}
|
|
61
|
+
if (name === "color-mix") {
|
|
62
|
+
const [space, mixed = "", other] = splitTopLevel(body);
|
|
63
|
+
const [, color = "", strength = ""] = mixed.match(/^(.+)\s+([\d.]+)%$/s) ?? [];
|
|
64
|
+
if (space !== "in oklab" || other !== "transparent" || !color) throw new Error(`Only a colour mixed with transparent in oklab is read: ${expression}`);
|
|
65
|
+
const base = parseColor(color, theme);
|
|
66
|
+
return {
|
|
67
|
+
...base,
|
|
68
|
+
alpha: base.alpha * (Number.parseFloat(strength) / 100)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (name === "oklch") {
|
|
72
|
+
const [channels = "", alpha] = splitTopLevel(body, "/");
|
|
73
|
+
const [lightness = "", chroma = "", hue = ""] = splitTopLevel(channels, " ");
|
|
74
|
+
return {
|
|
75
|
+
lightness: evaluate(lightness),
|
|
76
|
+
chroma: evaluate(chroma),
|
|
77
|
+
hue: evaluate(hue),
|
|
78
|
+
alpha: readAlpha(alpha)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`Not an oklch colour, pair or mix: ${expression}`);
|
|
82
|
+
}
|
|
83
|
+
/** A token's two sides, following `var()` to a gray setting, a gray step or another token. */
|
|
84
|
+
function readToken(css, name) {
|
|
85
|
+
const lookup = createLookup(css);
|
|
86
|
+
const value = lookup(name);
|
|
87
|
+
if (!value) throw new Error(`--${name} is not declared`);
|
|
88
|
+
const expression = substitute(value, lookup);
|
|
89
|
+
return {
|
|
90
|
+
light: parseColor(expression, "light"),
|
|
91
|
+
dark: parseColor(expression, "dark")
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** OKLCH to gamma-encoded sRGB in 0 to 1, clipped to the gamut. */
|
|
95
|
+
function toSrgb({ lightness, chroma, hue }) {
|
|
96
|
+
const radians = hue * Math.PI / 180;
|
|
97
|
+
const greenRed = chroma * Math.cos(radians);
|
|
98
|
+
const blueYellow = chroma * Math.sin(radians);
|
|
99
|
+
const long = (lightness + .3963377774 * greenRed + .2158037573 * blueYellow) ** 3;
|
|
100
|
+
const medium = (lightness - .1055613458 * greenRed - .0638541728 * blueYellow) ** 3;
|
|
101
|
+
const short = (lightness - .0894841775 * greenRed - 1.291485548 * blueYellow) ** 3;
|
|
102
|
+
return [
|
|
103
|
+
4.0767416621 * long - 3.3077115913 * medium + .2309699292 * short,
|
|
104
|
+
-1.2684380046 * long + 2.6097574011 * medium - .3413193965 * short,
|
|
105
|
+
-.0041960863 * long - .7034186147 * medium + 1.707614701 * short
|
|
106
|
+
].map((channel) => {
|
|
107
|
+
const clipped = Math.min(1, Math.max(0, channel));
|
|
108
|
+
return clipped <= .0031308 ? 12.92 * clipped : 1.055 * clipped ** (1 / 2.4) - .055;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function formatHex(rgb) {
|
|
112
|
+
return `#${rgb.map((channel) => Math.round(channel * 255).toString(16).padStart(2, "0")).join("")}`;
|
|
113
|
+
}
|
|
114
|
+
/** `color` at `alpha` over `ground`, mixed in gamma-encoded sRGB as a browser blends a paint. */
|
|
115
|
+
function blend(color, alpha, ground) {
|
|
116
|
+
return color.map((channel, index) => channel * alpha + (ground[index] ?? 0) * (1 - alpha));
|
|
117
|
+
}
|
|
118
|
+
/** The colour tokens and gray steps the stylesheet declares, in its order. */
|
|
119
|
+
function readColorNames(css) {
|
|
120
|
+
const names = [...stripComments(css).matchAll(/--((?:color-[a-z0-9-]+)|(?:gray-\d+)):/g)].map((match) => match[1] ?? "");
|
|
121
|
+
return [...new Set(names)];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Every opaque colour token and gray step as hex, per theme. A translucent edge is the hex it
|
|
125
|
+
* makes over a card's surface, which is where code that cannot blend (an email) draws its lines.
|
|
126
|
+
* Any other translucent token (a `-subtle` tint, a coloured `-edge`, the scrim) has no single hex
|
|
127
|
+
* and is left out.
|
|
128
|
+
*/
|
|
129
|
+
function readOpaqueTokens(css) {
|
|
130
|
+
const tokens = {
|
|
131
|
+
light: {},
|
|
132
|
+
dark: {}
|
|
133
|
+
};
|
|
134
|
+
const surface = readToken(css, "color-surface");
|
|
135
|
+
for (const name of readColorNames(css)) {
|
|
136
|
+
const value = readToken(css, name);
|
|
137
|
+
const key = name.replace(/^color-/, "");
|
|
138
|
+
const translucent = value.light.alpha < 1 || value.dark.alpha < 1;
|
|
139
|
+
if (translucent && !key.startsWith("edge")) continue;
|
|
140
|
+
for (const theme of THEMES) {
|
|
141
|
+
const color = toSrgb(value[theme]);
|
|
142
|
+
tokens[theme][key] = formatHex(translucent ? blend(color, value[theme].alpha, toSrgb(surface[theme])) : color);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return tokens;
|
|
146
|
+
}
|
|
147
|
+
export { THEMES, formatHex, readColorNames, readOpaqueTokens, readToken, splitTopLevel, toSrgb };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=color.js.map
|
package/lib/color.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","names":[],"sources":["../../src/lib/color.ts"],"sourcesContent":["/*\n * The stylesheet's colour tokens read as data, for the places that cannot run CSS: an email, an\n * Open Graph image, a JSON config. `styles.css` stays the only place a colour is written.\n */\n\nexport type Rgb = [number, number, number]\nexport type Theme = \"light\" | \"dark\"\n\nexport interface Oklch {\n lightness: number\n chroma: number\n hue: number\n alpha: number\n}\n\n/** What a custom property holds in the stylesheet, by name. */\ntype Lookup = (name: string) => string | undefined\n\nexport const THEMES: Theme[] = [\"light\", \"dark\"]\n\nfunction collapseWhitespace(value: string) {\n return value.replace(/\\s+/g, \" \").replace(/\\(\\s+/g, \"(\").replace(/\\s+\\)/g, \")\").trim()\n}\n\n/** The stylesheet without its comments, which quote declarations (`--gray-chroma: 0`) as prose. */\nfunction stripComments(css: string) {\n return css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\")\n}\n\nfunction createLookup(css: string): Lookup {\n const code = stripComments(css)\n\n return name => {\n const value = code.match(new RegExp(`--${name}:\\\\s*([^;]+);`))?.[1]\n if (value === undefined) return\n return collapseWhitespace(value)\n }\n}\n\n/** Splits `value` on each top-level `separator` (a comma by default), not those in nested calls. */\nexport function splitTopLevel(value: string, separator = \",\") {\n const parts: string[] = []\n let depth = 0\n let current = \"\"\n\n for (const character of value) {\n if (character === \"(\") depth++\n if (character === \")\") depth--\n if (character === separator && depth === 0) {\n parts.push(current.trim())\n current = \"\"\n } else {\n current += character\n }\n }\n\n parts.push(current.trim())\n return parts\n}\n\n/** `value` with every `var(--name)` replaced by what that variable holds, all the way down. */\nfunction substitute(value: string, lookup: Lookup, depth = 0): string {\n if (depth > 8) throw new Error(`var() nests too deep in ${value}`)\n\n return value.replace(/var\\(--([a-z0-9-]+)\\)/g, (_match, name: string) => {\n const resolved = lookup(name)\n if (resolved === undefined) throw new Error(`--${name} is not declared`)\n return substitute(resolved, lookup, depth + 1)\n })\n}\n\n/** A number, or a `calc()` that multiplies numbers, which is all the stylesheet's colours use. */\nfunction evaluate(expression: string) {\n const body = expression.match(/^calc\\((.+)\\)$/)?.[1]\n const factors = body ? body.split(\"*\") : [expression]\n const value = factors.reduce((result, factor) => result * Number.parseFloat(factor.trim()), 1)\n if (Number.isNaN(value)) throw new Error(`Cannot evaluate ${expression}`)\n return value\n}\n\nfunction readAlpha(value: string | undefined) {\n if (value === undefined) return 1\n return value.endsWith(\"%\") ? Number.parseFloat(value) / 100 : Number.parseFloat(value)\n}\n\n/** One side of a colour expression with no `var()` left in it. */\nfunction parseColor(expression: string, theme: Theme): Oklch {\n const [, name, body = \"\"] = expression.match(/^([a-z-]+)\\((.*)\\)$/s) ?? []\n\n if (name === \"light-dark\") {\n const [light = \"\", dark = \"\"] = splitTopLevel(body)\n return parseColor(theme === \"light\" ? light : dark, theme)\n }\n\n // `color-mix(in oklab, <colour> N%, transparent)`: the colour at N% of its strength.\n if (name === \"color-mix\") {\n const [space, mixed = \"\", other] = splitTopLevel(body)\n const [, color = \"\", strength = \"\"] = mixed.match(/^(.+)\\s+([\\d.]+)%$/s) ?? []\n if (space !== \"in oklab\" || other !== \"transparent\" || !color) {\n throw new Error(`Only a colour mixed with transparent in oklab is read: ${expression}`)\n }\n const base = parseColor(color, theme)\n return { ...base, alpha: base.alpha * (Number.parseFloat(strength) / 100) }\n }\n\n if (name === \"oklch\") {\n const [channels = \"\", alpha] = splitTopLevel(body, \"/\")\n const [lightness = \"\", chroma = \"\", hue = \"\"] = splitTopLevel(channels, \" \")\n return {\n lightness: evaluate(lightness),\n chroma: evaluate(chroma),\n hue: evaluate(hue),\n alpha: readAlpha(alpha),\n }\n }\n\n throw new Error(`Not an oklch colour, pair or mix: ${expression}`)\n}\n\n/** A token's two sides, following `var()` to a gray setting, a gray step or another token. */\nexport function readToken(css: string, name: string): Record<Theme, Oklch> {\n const lookup = createLookup(css)\n const value = lookup(name)\n if (!value) throw new Error(`--${name} is not declared`)\n\n const expression = substitute(value, lookup)\n return { light: parseColor(expression, \"light\"), dark: parseColor(expression, \"dark\") }\n}\n\n/** OKLCH to gamma-encoded sRGB in 0 to 1, clipped to the gamut. */\nexport function toSrgb({ lightness, chroma, hue }: Oklch): Rgb {\n const radians = (hue * Math.PI) / 180\n const greenRed = chroma * Math.cos(radians)\n const blueYellow = chroma * Math.sin(radians)\n const long = (lightness + 0.3963377774 * greenRed + 0.2158037573 * blueYellow) ** 3\n const medium = (lightness - 0.1055613458 * greenRed - 0.0638541728 * blueYellow) ** 3\n const short = (lightness - 0.0894841775 * greenRed - 1.291485548 * blueYellow) ** 3\n const linear = [\n 4.0767416621 * long - 3.3077115913 * medium + 0.2309699292 * short,\n -1.2684380046 * long + 2.6097574011 * medium - 0.3413193965 * short,\n -0.0041960863 * long - 0.7034186147 * medium + 1.707614701 * short,\n ]\n\n return linear.map(channel => {\n const clipped = Math.min(1, Math.max(0, channel))\n return clipped <= 0.0031308 ? 12.92 * clipped : 1.055 * clipped ** (1 / 2.4) - 0.055\n }) as Rgb\n}\n\nexport function formatHex(rgb: Rgb) {\n return `#${rgb\n .map(channel =>\n Math.round(channel * 255)\n .toString(16)\n .padStart(2, \"0\"),\n )\n .join(\"\")}`\n}\n\n/** `color` at `alpha` over `ground`, mixed in gamma-encoded sRGB as a browser blends a paint. */\nfunction blend(color: Rgb, alpha: number, ground: Rgb): Rgb {\n return color.map((channel, index) => channel * alpha + (ground[index] ?? 0) * (1 - alpha)) as Rgb\n}\n\n/** The colour tokens and gray steps the stylesheet declares, in its order. */\nexport function readColorNames(css: string) {\n const names = [...stripComments(css).matchAll(/--((?:color-[a-z0-9-]+)|(?:gray-\\d+)):/g)].map(\n match => match[1] ?? \"\",\n )\n return [...new Set(names)]\n}\n\n/**\n * Every opaque colour token and gray step as hex, per theme. A translucent edge is the hex it\n * makes over a card's surface, which is where code that cannot blend (an email) draws its lines.\n * Any other translucent token (a `-subtle` tint, a coloured `-edge`, the scrim) has no single hex\n * and is left out.\n */\nexport function readOpaqueTokens(css: string): Record<Theme, Record<string, string>> {\n const tokens: Record<Theme, Record<string, string>> = { light: {}, dark: {} }\n const surface = readToken(css, \"color-surface\")\n\n for (const name of readColorNames(css)) {\n const value = readToken(css, name)\n const key = name.replace(/^color-/, \"\")\n const translucent = value.light.alpha < 1 || value.dark.alpha < 1\n if (translucent && !key.startsWith(\"edge\")) continue\n\n for (const theme of THEMES) {\n const color = toSrgb(value[theme])\n tokens[theme][key] = formatHex(\n translucent ? blend(color, value[theme].alpha, toSrgb(surface[theme])) : color,\n )\n }\n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U,UAAU,SAAS,OAAO,UAAU,MAAM,IAAI,MAAM;AAC3F;;AAGA,SAAgB,eAAe,KAAa;CAC1C,MAAM,QAAQ,CAAC,GAAG,cAAc,GAAG,CAAC,CAAC,SAAS,yCAAyC,CAAC,CAAC,CAAC,KACxF,UAAS,MAAM,MAAM,EACvB;CACA,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC;AAC3B;;;;;;;AAQA,SAAgB,iBAAiB,KAAoD;CACnF,MAAM,SAAgD;EAAE,OAAO,CAAC;EAAG,MAAM,CAAC;CAAE;CAC5E,MAAM,UAAU,UAAU,KAAK,eAAe;CAE9C,KAAK,MAAM,QAAQ,eAAe,GAAG,GAAG;EACtC,MAAM,QAAQ,UAAU,KAAK,IAAI;EACjC,MAAM,MAAM,KAAK,QAAQ,WAAW,EAAE;EACtC,MAAM,cAAc,MAAM,MAAM,QAAQ,KAAK,MAAM,KAAK,QAAQ;EAChE,IAAI,eAAe,CAAC,IAAI,WAAW,MAAM,GAAG;EAE5C,KAAK,MAAM,SAAS,QAAQ;GAC1B,MAAM,QAAQ,OAAO,MAAM,MAAM;GACjC,OAAO,MAAM,CAAC,OAAO,UACnB,cAAc,MAAM,OAAO,MAAM,MAAM,CAAC,OAAO,OAAO,QAAQ,MAAM,CAAC,IAAI,KAC3E;EACF;CACF;CAEA,OAAO;AACT"}
|
package/lib/day.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A calendar day as "YYYY-MM-DD" — the shape `<input type="date">` uses, and the one a date
|
|
3
|
+
* without a time of day should travel in. Turning it into a `Date` at *local* midnight keeps
|
|
4
|
+
* the day intact: parsing the string directly reads it as UTC, which lands on the day before
|
|
5
|
+
* anywhere west of Greenwich.
|
|
6
|
+
*/
|
|
7
|
+
export declare function dayToDate(day: string | undefined): Date | undefined;
|
|
8
|
+
/** The inverse of `dayToDate`, reading the date's own calendar fields rather than its instant. */
|
|
9
|
+
export declare function dateToDay(date: Date): string;
|
package/lib/day.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/lib/day.ts
|
|
2
|
+
/**
|
|
3
|
+
* A calendar day as "YYYY-MM-DD" — the shape `<input type="date">` uses, and the one a date
|
|
4
|
+
* without a time of day should travel in. Turning it into a `Date` at *local* midnight keeps
|
|
5
|
+
* the day intact: parsing the string directly reads it as UTC, which lands on the day before
|
|
6
|
+
* anywhere west of Greenwich.
|
|
7
|
+
*/
|
|
8
|
+
function dayToDate(day) {
|
|
9
|
+
const [year, month, date] = (day ?? "").split("-").map(Number);
|
|
10
|
+
return year && month && date ? new Date(year, month - 1, date) : void 0;
|
|
11
|
+
}
|
|
12
|
+
/** The inverse of `dayToDate`, reading the date's own calendar fields rather than its instant. */
|
|
13
|
+
function dateToDay(date) {
|
|
14
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
15
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
16
|
+
return `${date.getFullYear()}-${month}-${day}`;
|
|
17
|
+
}
|
|
18
|
+
export { dateToDay, dayToDate };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=day.js.map
|
package/lib/day.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"day.js","names":[],"sources":["../../src/lib/day.ts"],"sourcesContent":["/**\n * A calendar day as \"YYYY-MM-DD\" — the shape `<input type=\"date\">` uses, and the one a date\n * without a time of day should travel in. Turning it into a `Date` at *local* midnight keeps\n * the day intact: parsing the string directly reads it as UTC, which lands on the day before\n * anywhere west of Greenwich.\n */\nexport function dayToDate(day: string | undefined): Date | undefined {\n const [year, month, date] = (day ?? \"\").split(\"-\").map(Number)\n return year && month && date ? new Date(year, month - 1, date) : undefined\n}\n\n/** The inverse of `dayToDate`, reading the date's own calendar fields rather than its instant. */\nexport function dateToDay(date: Date): string {\n const month = String(date.getMonth() + 1).padStart(2, \"0\")\n const day = String(date.getDate()).padStart(2, \"0\")\n return `${date.getFullYear()}-${month}-${day}`\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,UAAU,KAA2C;CACnE,MAAM,CAAC,MAAM,OAAO,SAAS,OAAO,GAAA,CAAI,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAC7D,OAAO,QAAQ,SAAS,OAAO,IAAI,KAAK,MAAM,QAAQ,GAAG,IAAI,IAAI,KAAA;AACnE;;AAGA,SAAgB,UAAU,MAAoB;CAC5C,MAAM,QAAQ,OAAO,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;CACzD,MAAM,MAAM,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;CAClD,OAAO,GAAG,KAAK,YAAY,EAAE,GAAG,MAAM,GAAG;AAC3C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
interface Paint {
|
|
2
|
+
hex: string;
|
|
3
|
+
alpha: number;
|
|
4
|
+
}
|
|
5
|
+
interface ColorToken {
|
|
6
|
+
name: string;
|
|
7
|
+
css: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
/** The Figma variable this one points at, when the CSS value is a bare `var()` of another. */
|
|
10
|
+
alias?: string;
|
|
11
|
+
light: Paint;
|
|
12
|
+
dark: Paint;
|
|
13
|
+
}
|
|
14
|
+
interface ShadowLayer {
|
|
15
|
+
offsetX: number;
|
|
16
|
+
offsetY: number;
|
|
17
|
+
blur: number;
|
|
18
|
+
spread: number;
|
|
19
|
+
/** Drawn inside the box rather than under it. */
|
|
20
|
+
inset?: boolean;
|
|
21
|
+
/** The colour variable the layer is bound to; `light` and `dark` are its resolved values. */
|
|
22
|
+
variable?: string;
|
|
23
|
+
light: Paint;
|
|
24
|
+
dark: Paint;
|
|
25
|
+
}
|
|
26
|
+
interface ShadowToken {
|
|
27
|
+
name: string;
|
|
28
|
+
css: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
layers: ShadowLayer[];
|
|
31
|
+
}
|
|
32
|
+
interface TextToken {
|
|
33
|
+
name: string;
|
|
34
|
+
css: string;
|
|
35
|
+
size: number;
|
|
36
|
+
lineHeight: number;
|
|
37
|
+
}
|
|
38
|
+
interface NumberToken {
|
|
39
|
+
name: string;
|
|
40
|
+
css: string;
|
|
41
|
+
value: number;
|
|
42
|
+
}
|
|
43
|
+
export interface DesignTokens {
|
|
44
|
+
fonts: {
|
|
45
|
+
sans: string;
|
|
46
|
+
mono: string;
|
|
47
|
+
};
|
|
48
|
+
colors: ColorToken[];
|
|
49
|
+
shadows: ShadowToken[];
|
|
50
|
+
text: TextToken[];
|
|
51
|
+
tracking: NumberToken[];
|
|
52
|
+
radius: NumberToken[];
|
|
53
|
+
spacing: NumberToken[];
|
|
54
|
+
}
|
|
55
|
+
export declare function readDesignTokens(css: string, tailwindTheme: string): DesignTokens;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { formatHex, readColorNames, readToken, splitTopLevel, toSrgb } from "./color.js";
|
|
2
|
+
// src/lib/design-tokens.ts
|
|
3
|
+
const REM = 16;
|
|
4
|
+
const TAILWIND_TEXT = [
|
|
5
|
+
"xs",
|
|
6
|
+
"sm",
|
|
7
|
+
"base",
|
|
8
|
+
"lg",
|
|
9
|
+
"xl",
|
|
10
|
+
"2xl",
|
|
11
|
+
"3xl",
|
|
12
|
+
"4xl"
|
|
13
|
+
];
|
|
14
|
+
const RADIUS_STEPS = [
|
|
15
|
+
"xs",
|
|
16
|
+
"sm",
|
|
17
|
+
"md",
|
|
18
|
+
"lg",
|
|
19
|
+
"xl"
|
|
20
|
+
];
|
|
21
|
+
const SPACING_STEPS = [
|
|
22
|
+
.5,
|
|
23
|
+
1,
|
|
24
|
+
1.5,
|
|
25
|
+
2,
|
|
26
|
+
2.5,
|
|
27
|
+
3,
|
|
28
|
+
3.5,
|
|
29
|
+
4,
|
|
30
|
+
5,
|
|
31
|
+
6,
|
|
32
|
+
8,
|
|
33
|
+
10,
|
|
34
|
+
12
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* Every custom property in a stylesheet, in source order, with the comment above its group.
|
|
38
|
+
* A comment applies to the declarations under it until a blank line.
|
|
39
|
+
*/
|
|
40
|
+
function readDeclarations(css) {
|
|
41
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
42
|
+
let comment;
|
|
43
|
+
for (const match of css.matchAll(/(\/\*[\s\S]*?\*\/)|(\n\s*\n)|--([a-z0-9-]+):\s*([^;]+);/g)) {
|
|
44
|
+
const [, block, blank, name, value] = match;
|
|
45
|
+
if (block) comment = block.replace(/^\/\*+|\*+\/$/g, "").split("\n").map((line) => line.replace(/^\s*\*\s?/, "").trim()).filter(Boolean).join(" ");
|
|
46
|
+
else if (blank) comment = void 0;
|
|
47
|
+
else if (name && value && !declarations.has(name)) declarations.set(name, {
|
|
48
|
+
value: value.replace(/\s+/g, " ").trim(),
|
|
49
|
+
description: comment
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return declarations;
|
|
53
|
+
}
|
|
54
|
+
function toPaint(oklch) {
|
|
55
|
+
return {
|
|
56
|
+
hex: formatHex(toSrgb(oklch)),
|
|
57
|
+
alpha: Math.round(oklch.alpha * 1e3) / 1e3
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function toPaints(color) {
|
|
61
|
+
return {
|
|
62
|
+
light: toPaint(color.light),
|
|
63
|
+
dark: toPaint(color.dark)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function toFigmaName(name) {
|
|
67
|
+
return name.replace(/^(color|gray|shadow|text|tracking|radius|spacing)-/, "$1/");
|
|
68
|
+
}
|
|
69
|
+
function readPixels(value) {
|
|
70
|
+
return Number.parseFloat(value) * (value.endsWith("rem") ? REM : 1);
|
|
71
|
+
}
|
|
72
|
+
function readShadowLayers(css, name, declarations) {
|
|
73
|
+
const value = declarations.get(name)?.value ?? "";
|
|
74
|
+
return splitTopLevel(value).flatMap((layer) => {
|
|
75
|
+
const nested = layer.match(/^var\(--(shadow-[a-z0-9-]+)\)$/)?.[1];
|
|
76
|
+
if (nested) return readShadowLayers(css, nested, declarations);
|
|
77
|
+
const inset = layer.startsWith("inset ");
|
|
78
|
+
const [, lengths = "", color = ""] = layer.replace(/^inset /, "").match(/^([-\d.px ]+?)\s+((?:var|rgb)\(.+\))$/) ?? [];
|
|
79
|
+
const [offsetX = 0, offsetY = 0, blur = 0, spread = 0] = lengths.trim().split(/\s+/).map(readPixels);
|
|
80
|
+
const variable = color.match(/^var\(--([a-z0-9-]+)\)$/)?.[1];
|
|
81
|
+
if (variable) return [{
|
|
82
|
+
offsetX,
|
|
83
|
+
offsetY,
|
|
84
|
+
blur,
|
|
85
|
+
spread,
|
|
86
|
+
...inset && { inset },
|
|
87
|
+
variable: toFigmaName(variable),
|
|
88
|
+
...toPaints(readToken(css, variable))
|
|
89
|
+
}];
|
|
90
|
+
const [red = 0, green = 0, blue = 0, alpha = "100%"] = color.match(/^rgb\((\d+) (\d+) (\d+) \/ ([\d.]+%)\)$/)?.slice(1) ?? [];
|
|
91
|
+
const rgb = [
|
|
92
|
+
red,
|
|
93
|
+
green,
|
|
94
|
+
blue
|
|
95
|
+
].map((channel) => Number(channel) / 255);
|
|
96
|
+
const paint = {
|
|
97
|
+
hex: formatHex(rgb),
|
|
98
|
+
alpha: Number.parseFloat(alpha) / 100
|
|
99
|
+
};
|
|
100
|
+
return [{
|
|
101
|
+
offsetX,
|
|
102
|
+
offsetY,
|
|
103
|
+
blur,
|
|
104
|
+
spread,
|
|
105
|
+
...inset && { inset },
|
|
106
|
+
light: paint,
|
|
107
|
+
dark: paint
|
|
108
|
+
}];
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** A line height in pixels: a length, a multiplier, a `calc(a / b)` multiplier or a `var()`. */
|
|
112
|
+
function readLineHeight(value, size, declarations) {
|
|
113
|
+
const alias = value.match(/^var\(--([a-z0-9-]+)\)$/)?.[1];
|
|
114
|
+
if (alias) return readLineHeight(declarations.get(alias)?.value ?? "", size, declarations);
|
|
115
|
+
const ratio = value.match(/^calc\(([\d.]+) \/ ([\d.]+)\)$/);
|
|
116
|
+
if (ratio?.[1] && ratio[2]) return Math.round(size * (Number(ratio[1]) / Number(ratio[2])));
|
|
117
|
+
if (/(px|rem)$/.test(value)) return readPixels(value);
|
|
118
|
+
return Math.round(size * Number(value) * 100) / 100;
|
|
119
|
+
}
|
|
120
|
+
function readText(name, declarations) {
|
|
121
|
+
const size = readPixels(declarations.get(`text-${name}`)?.value ?? "");
|
|
122
|
+
const lineHeight = declarations.get(`text-${name}--line-height`)?.value ?? "";
|
|
123
|
+
return {
|
|
124
|
+
name: `text/${name}`,
|
|
125
|
+
css: `var(--text-${name})`,
|
|
126
|
+
size,
|
|
127
|
+
lineHeight: readLineHeight(lineHeight, size, declarations)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function readFamily(value = "") {
|
|
131
|
+
return value.split(",")[0]?.replaceAll("\"", "").replace(/ Variable$/, "") ?? "";
|
|
132
|
+
}
|
|
133
|
+
function readDesignTokens(css, tailwindTheme) {
|
|
134
|
+
const declarations = readDeclarations(css);
|
|
135
|
+
const tailwind = readDeclarations(tailwindTheme);
|
|
136
|
+
const names = [...declarations.keys()];
|
|
137
|
+
const colorNames = readColorNames(css);
|
|
138
|
+
const colors = colorNames.map((name) => {
|
|
139
|
+
const { value, description } = declarations.get(name) ?? { value: "" };
|
|
140
|
+
const target = value.match(/^var\(--([a-z0-9-]+)\)$/)?.[1];
|
|
141
|
+
return {
|
|
142
|
+
name: toFigmaName(name),
|
|
143
|
+
css: `var(--${name})`,
|
|
144
|
+
...description && { description },
|
|
145
|
+
...target && colorNames.includes(target) && { alias: toFigmaName(target) },
|
|
146
|
+
...toPaints(readToken(css, name))
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
const shadows = names.filter((name) => name.startsWith("shadow-")).map((name) => {
|
|
150
|
+
const description = declarations.get(name)?.description;
|
|
151
|
+
return {
|
|
152
|
+
name: toFigmaName(name),
|
|
153
|
+
css: `var(--${name})`,
|
|
154
|
+
...description && { description },
|
|
155
|
+
layers: readShadowLayers(css, name, declarations)
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
const customText = names.filter((name) => /^text-[a-z0-9]+$/.test(name)).map((name) => name.replace(/^text-/, ""));
|
|
159
|
+
const allText = new Map([...tailwind, ...declarations]);
|
|
160
|
+
const spacingBase = readPixels(tailwind.get("spacing")?.value ?? "");
|
|
161
|
+
return {
|
|
162
|
+
fonts: {
|
|
163
|
+
sans: readFamily(declarations.get("font-sans")?.value),
|
|
164
|
+
mono: readFamily(declarations.get("font-mono")?.value)
|
|
165
|
+
},
|
|
166
|
+
colors,
|
|
167
|
+
shadows,
|
|
168
|
+
text: [...TAILWIND_TEXT, ...customText].map((name) => readText(name, allText)),
|
|
169
|
+
tracking: names.filter((name) => name.startsWith("tracking-")).map((name) => ({
|
|
170
|
+
name: toFigmaName(name),
|
|
171
|
+
css: `var(--${name})`,
|
|
172
|
+
value: Number.parseFloat(declarations.get(name)?.value ?? "")
|
|
173
|
+
})),
|
|
174
|
+
radius: [...RADIUS_STEPS.map((step) => ({
|
|
175
|
+
name: `radius/${step}`,
|
|
176
|
+
css: `var(--radius-${step})`,
|
|
177
|
+
value: readPixels((declarations.get(`radius-${step}`) ?? tailwind.get(`radius-${step}`))?.value ?? "")
|
|
178
|
+
})), {
|
|
179
|
+
name: "radius/full",
|
|
180
|
+
css: "calc(infinity * 1px)",
|
|
181
|
+
value: 9999
|
|
182
|
+
}],
|
|
183
|
+
spacing: [...SPACING_STEPS.map((step) => ({
|
|
184
|
+
name: `spacing/${String(step).replace(".", "-")}`,
|
|
185
|
+
css: `--spacing(${step})`,
|
|
186
|
+
value: step * spacingBase
|
|
187
|
+
})), ...names.filter((name) => name.startsWith("spacing-")).map((name) => ({
|
|
188
|
+
name: toFigmaName(name),
|
|
189
|
+
css: `var(--${name})`,
|
|
190
|
+
value: readPixels(declarations.get(name)?.value ?? "")
|
|
191
|
+
}))]
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
export { readDesignTokens };
|
|
195
|
+
|
|
196
|
+
//# sourceMappingURL=design-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-tokens.js","names":[],"sources":["../../src/lib/design-tokens.ts"],"sourcesContent":["import {\n formatHex,\n readColorNames,\n readToken,\n splitTopLevel,\n toSrgb,\n type Oklch,\n type Rgb,\n type Theme,\n} from \"./color\"\n\n/*\n * The stylesheet's tokens as one JSON document for the Figma library: every colour per theme,\n * every shadow layer, the type scale, radii and spacing. Figma names follow the CSS names by one\n * rule, the prefix becomes the group (`--color-ink-muted` is `color/ink-muted`), so a script can\n * apply the document to the library and nobody names a variable by hand. Radii, spacing and\n * Tailwind's own type steps come from Tailwind's `theme.css`, which the stylesheet builds on.\n */\n\ninterface Paint {\n hex: string\n alpha: number\n}\n\ninterface ColorToken {\n name: string\n css: string\n description?: string\n /** The Figma variable this one points at, when the CSS value is a bare `var()` of another. */\n alias?: string\n light: Paint\n dark: Paint\n}\n\ninterface ShadowLayer {\n offsetX: number\n offsetY: number\n blur: number\n spread: number\n /** Drawn inside the box rather than under it. */\n inset?: boolean\n /** The colour variable the layer is bound to; `light` and `dark` are its resolved values. */\n variable?: string\n light: Paint\n dark: Paint\n}\n\ninterface ShadowToken {\n name: string\n css: string\n description?: string\n layers: ShadowLayer[]\n}\n\ninterface TextToken {\n name: string\n css: string\n size: number\n lineHeight: number\n}\n\ninterface NumberToken {\n name: string\n css: string\n value: number\n}\n\ninterface Declaration {\n value: string\n description?: string\n}\n\nexport interface DesignTokens {\n fonts: { sans: string; mono: string }\n colors: ColorToken[]\n shadows: ShadowToken[]\n text: TextToken[]\n tracking: NumberToken[]\n radius: NumberToken[]\n spacing: NumberToken[]\n}\n\nconst REM = 16\n// Tailwind's steps the library draws with. Tailwind holds their values.\nconst TAILWIND_TEXT = [\"xs\", \"sm\", \"base\", \"lg\", \"xl\", \"2xl\", \"3xl\", \"4xl\"]\nconst RADIUS_STEPS = [\"xs\", \"sm\", \"md\", \"lg\", \"xl\"]\nconst SPACING_STEPS = [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 8, 10, 12]\n\n/**\n * Every custom property in a stylesheet, in source order, with the comment above its group.\n * A comment applies to the declarations under it until a blank line.\n */\nfunction readDeclarations(css: string) {\n const declarations = new Map<string, Declaration>()\n let comment: string | undefined\n\n for (const match of css.matchAll(/(\\/\\*[\\s\\S]*?\\*\\/)|(\\n\\s*\\n)|--([a-z0-9-]+):\\s*([^;]+);/g)) {\n const [, block, blank, name, value] = match\n if (block) {\n comment = block\n .replace(/^\\/\\*+|\\*+\\/$/g, \"\")\n .split(\"\\n\")\n .map(line => line.replace(/^\\s*\\*\\s?/, \"\").trim())\n .filter(Boolean)\n .join(\" \")\n } else if (blank) {\n comment = undefined\n } else if (name && value && !declarations.has(name)) {\n declarations.set(name, { value: value.replace(/\\s+/g, \" \").trim(), description: comment })\n }\n }\n\n return declarations\n}\n\nfunction toPaint(oklch: Oklch): Paint {\n return { hex: formatHex(toSrgb(oklch)), alpha: Math.round(oklch.alpha * 1000) / 1000 }\n}\n\nfunction toPaints(color: Record<Theme, Oklch>): Record<Theme, Paint> {\n return { light: toPaint(color.light), dark: toPaint(color.dark) }\n}\n\nfunction toFigmaName(name: string) {\n return name.replace(/^(color|gray|shadow|text|tracking|radius|spacing)-/, \"$1/\")\n}\n\nfunction readPixels(value: string) {\n return Number.parseFloat(value) * (value.endsWith(\"rem\") ? REM : 1)\n}\n\nfunction readShadowLayers(\n css: string,\n name: string,\n declarations: Map<string, Declaration>,\n): ShadowLayer[] {\n const value = declarations.get(name)?.value ?? \"\"\n\n return splitTopLevel(value).flatMap(layer => {\n const nested = layer.match(/^var\\(--(shadow-[a-z0-9-]+)\\)$/)?.[1]\n if (nested) return readShadowLayers(css, nested, declarations)\n\n const inset = layer.startsWith(\"inset \")\n const [, lengths = \"\", color = \"\"] =\n layer.replace(/^inset /, \"\").match(/^([-\\d.px ]+?)\\s+((?:var|rgb)\\(.+\\))$/) ?? []\n const [offsetX = 0, offsetY = 0, blur = 0, spread = 0] = lengths\n .trim()\n .split(/\\s+/)\n .map(readPixels)\n const variable = color.match(/^var\\(--([a-z0-9-]+)\\)$/)?.[1]\n if (variable) {\n return [\n {\n offsetX,\n offsetY,\n blur,\n spread,\n ...(inset && { inset }),\n variable: toFigmaName(variable),\n ...toPaints(readToken(css, variable)),\n },\n ]\n }\n\n const [red = 0, green = 0, blue = 0, alpha = \"100%\"] =\n color.match(/^rgb\\((\\d+) (\\d+) (\\d+) \\/ ([\\d.]+%)\\)$/)?.slice(1) ?? []\n const rgb = [red, green, blue].map(channel => Number(channel) / 255) as Rgb\n const paint = { hex: formatHex(rgb), alpha: Number.parseFloat(alpha) / 100 }\n return [{ offsetX, offsetY, blur, spread, ...(inset && { inset }), light: paint, dark: paint }]\n })\n}\n\n/** A line height in pixels: a length, a multiplier, a `calc(a / b)` multiplier or a `var()`. */\nfunction readLineHeight(value: string, size: number, declarations: Map<string, Declaration>) {\n const alias = value.match(/^var\\(--([a-z0-9-]+)\\)$/)?.[1]\n if (alias) return readLineHeight(declarations.get(alias)?.value ?? \"\", size, declarations)\n\n const ratio = value.match(/^calc\\(([\\d.]+) \\/ ([\\d.]+)\\)$/)\n if (ratio?.[1] && ratio[2]) return Math.round(size * (Number(ratio[1]) / Number(ratio[2])))\n if (/(px|rem)$/.test(value)) return readPixels(value)\n return Math.round(size * Number(value) * 100) / 100\n}\n\nfunction readText(name: string, declarations: Map<string, Declaration>): TextToken {\n const size = readPixels(declarations.get(`text-${name}`)?.value ?? \"\")\n const lineHeight = declarations.get(`text-${name}--line-height`)?.value ?? \"\"\n return {\n name: `text/${name}`,\n css: `var(--text-${name})`,\n size,\n lineHeight: readLineHeight(lineHeight, size, declarations),\n }\n}\n\nfunction readFamily(value = \"\") {\n return (\n value\n .split(\",\")[0]\n ?.replaceAll('\"', \"\")\n .replace(/ Variable$/, \"\") ?? \"\"\n )\n}\n\nexport function readDesignTokens(css: string, tailwindTheme: string): DesignTokens {\n const declarations = readDeclarations(css)\n const tailwind = readDeclarations(tailwindTheme)\n const names = [...declarations.keys()]\n\n const colorNames = readColorNames(css)\n const colors = colorNames.map(name => {\n const { value, description } = declarations.get(name) ?? { value: \"\" }\n const target = value.match(/^var\\(--([a-z0-9-]+)\\)$/)?.[1]\n return {\n name: toFigmaName(name),\n css: `var(--${name})`,\n ...(description && { description }),\n ...(target && colorNames.includes(target) && { alias: toFigmaName(target) }),\n ...toPaints(readToken(css, name)),\n }\n })\n\n const shadows = names\n .filter(name => name.startsWith(\"shadow-\"))\n .map(name => {\n const description = declarations.get(name)?.description\n return {\n name: toFigmaName(name),\n css: `var(--${name})`,\n ...(description && { description }),\n layers: readShadowLayers(css, name, declarations),\n }\n })\n\n const customText = names\n .filter(name => /^text-[a-z0-9]+$/.test(name))\n .map(name => name.replace(/^text-/, \"\"))\n const allText = new Map([...tailwind, ...declarations])\n\n const spacingBase = readPixels(tailwind.get(\"spacing\")?.value ?? \"\")\n\n return {\n fonts: {\n sans: readFamily(declarations.get(\"font-sans\")?.value),\n mono: readFamily(declarations.get(\"font-mono\")?.value),\n },\n colors,\n shadows,\n text: [...TAILWIND_TEXT, ...customText].map(name => readText(name, allText)),\n tracking: names\n .filter(name => name.startsWith(\"tracking-\"))\n .map(name => ({\n name: toFigmaName(name),\n css: `var(--${name})`,\n value: Number.parseFloat(declarations.get(name)?.value ?? \"\"),\n })),\n radius: [\n ...RADIUS_STEPS.map(step => ({\n name: `radius/${step}`,\n css: `var(--radius-${step})`,\n value: readPixels(\n (declarations.get(`radius-${step}`) ?? tailwind.get(`radius-${step}`))?.value ?? \"\",\n ),\n })),\n { name: \"radius/full\", css: \"calc(infinity * 1px)\", value: 9999 },\n ],\n spacing: [\n ...SPACING_STEPS.map(step => ({\n name: `spacing/${String(step).replace(\".\", \"-\")}`,\n css: `--spacing(${step})`,\n value: step * spacingBase,\n })),\n ...names\n .filter(name => name.startsWith(\"spacing-\"))\n .map(name => ({\n name: toFigmaName(name),\n css: `var(--${name})`,\n value: readPixels(declarations.get(name)?.value ?? \"\"),\n })),\n ],\n }\n}\n"],"mappings":";;AAkFA,MAAM,MAAM;AAEZ,MAAM,gBAAgB;CAAC;CAAM;CAAM;CAAQ;CAAM;CAAM;CAAO;CAAO;AAAK;AAC1E,MAAM,eAAe;CAAC;CAAM;CAAM;CAAM;CAAM;AAAI;AAClD,MAAM,gBAAgB;CAAC;CAAK;CAAG;CAAK;CAAG;CAAK;CAAG;CAAK;CAAG;CAAG;CAAG;CAAG;CAAI;AAAE;;;;;AAMtE,SAAS,iBAAiB,KAAa;CACrC,MAAM,+BAAe,IAAI,IAAyB;CAClD,IAAI;CAEJ,KAAK,MAAM,SAAS,IAAI,SAAS,0DAA0D,GAAG;EAC5F,MAAM,GAAG,OAAO,OAAO,MAAM,SAAS;EACtC,IAAI,OACF,UAAU,MACP,QAAQ,kBAAkB,EAAE,CAAC,CAC7B,MAAM,IAAI,CAAC,CACX,KAAI,SAAQ,KAAK,QAAQ,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CACjD,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;OACN,IAAI,OACT,UAAU,KAAA;OACL,IAAI,QAAQ,SAAS,CAAC,aAAa,IAAI,IAAI,GAChD,aAAa,IAAI,MAAM;GAAE,OAAO,MAAM,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;GAAG,aAAa;EAAQ,CAAC;CAE7F;CAEA,OAAO;AACT;AAEA,SAAS,QAAQ,OAAqB;CACpC,OAAO;EAAE,KAAK,UAAU,OAAO,KAAK,CAAC;EAAG,OAAO,KAAK,MAAM,MAAM,QAAQ,GAAI,IAAI;CAAK;AACvF;AAEA,SAAS,SAAS,OAAmD;CACnE,OAAO;EAAE,OAAO,QAAQ,MAAM,KAAK;EAAG,MAAM,QAAQ,MAAM,IAAI;CAAE;AAClE;AAEA,SAAS,YAAY,MAAc;C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AAE;EAC9D,EAAE;EACJ,QAAQ,CACN,GAAG,aAAa,KAAI,UAAS;GAC3B,MAAM,UAAU;GAChB,KAAK,gBAAgB,KAAK;GAC1B,OAAO,YACJ,aAAa,IAAI,UAAU,MAAM,KAAK,SAAS,IAAI,UAAU,MAAM,EAAA,EAAI,SAAS,EACnF;EACF,EAAE,GACF;GAAE,MAAM;GAAe,KAAK;GAAwB,OAAO;EAAK,CAClE;EACA,SAAS,CACP,GAAG,cAAc,KAAI,UAAS;GAC5B,MAAM,WAAW,OAAO,IAAI,CAAC,CAAC,QAAQ,KAAK,GAAG;GAC9C,KAAK,aAAa,KAAK;GACvB,OAAO,OAAO;EAChB,EAAE,GACF,GAAG,MACA,QAAO,SAAQ,KAAK,WAAW,UAAU,CAAC,CAAC,CAC3C,KAAI,UAAS;GACZ,MAAM,YAAY,IAAI;GACtB,KAAK,SAAS,KAAK;GACnB,OAAO,WAAW,aAAa,IAAI,IAAI,CAAC,EAAE,SAAS,EAAE;EACvD,EAAE,CACN;CACF;AACF"}
|
package/lib/icon.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentType } from "react";
|
|
2
|
+
import { HugeiconsProps, IconSvgElement } from "@hugeicons/react";
|
|
3
|
+
export type IconProps = Omit<HugeiconsProps, "icon" | "altIcon" | "showAlt">;
|
|
4
|
+
export type IconComponent = ComponentType<IconProps>;
|
|
5
|
+
/**
|
|
6
|
+
* Wraps a Hugeicons definition as a plain icon component, so call sites render `<CheckIcon />`.
|
|
7
|
+
* The package ships no icon registry of its own: icon choice belongs to each consuming app,
|
|
8
|
+
* which names every glyph it renders once with this helper.
|
|
9
|
+
*
|
|
10
|
+
* Sized to `1em`, so a `size-*` class or the surrounding font size drives it, at the 1.75
|
|
11
|
+
* stroke of the design's icon grid. Decorative by default, since an icon almost always sits
|
|
12
|
+
* beside the label that already names it; an icon that carries the meaning on its own
|
|
13
|
+
* overrides with `aria-hidden={false}`, `role="img"` and an `aria-label`. `defaults` sets props
|
|
14
|
+
* every use of one glyph shares. Memoised, since a glyph almost never changes with the
|
|
15
|
+
* component that renders it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function icon(def: IconSvgElement, name: string, defaults?: IconProps): IconComponent;
|
package/lib/icon.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import { HugeiconsIcon } from "@hugeicons/react";
|
|
4
|
+
// src/lib/icon.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Wraps a Hugeicons definition as a plain icon component, so call sites render `<CheckIcon />`.
|
|
7
|
+
* The package ships no icon registry of its own: icon choice belongs to each consuming app,
|
|
8
|
+
* which names every glyph it renders once with this helper.
|
|
9
|
+
*
|
|
10
|
+
* Sized to `1em`, so a `size-*` class or the surrounding font size drives it, at the 1.75
|
|
11
|
+
* stroke of the design's icon grid. Decorative by default, since an icon almost always sits
|
|
12
|
+
* beside the label that already names it; an icon that carries the meaning on its own
|
|
13
|
+
* overrides with `aria-hidden={false}`, `role="img"` and an `aria-label`. `defaults` sets props
|
|
14
|
+
* every use of one glyph shares. Memoised, since a glyph almost never changes with the
|
|
15
|
+
* component that renders it.
|
|
16
|
+
*/
|
|
17
|
+
function icon(def, name, defaults) {
|
|
18
|
+
function Icon(props) {
|
|
19
|
+
return /* @__PURE__ */ jsx(HugeiconsIcon, {
|
|
20
|
+
icon: def,
|
|
21
|
+
size: "1em",
|
|
22
|
+
strokeWidth: 1.75,
|
|
23
|
+
"aria-hidden": true,
|
|
24
|
+
focusable: "false",
|
|
25
|
+
...defaults,
|
|
26
|
+
...props
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
Icon.displayName = name;
|
|
30
|
+
return memo(Icon);
|
|
31
|
+
}
|
|
32
|
+
export { icon };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=icon.js.map
|
package/lib/icon.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon.js","names":[],"sources":["../../src/lib/icon.tsx"],"sourcesContent":["import { HugeiconsIcon, type HugeiconsProps, type IconSvgElement } from \"@hugeicons/react\"\nimport { type ComponentType, memo } from \"react\"\n\nexport type IconProps = Omit<HugeiconsProps, \"icon\" | \"altIcon\" | \"showAlt\">\nexport type IconComponent = ComponentType<IconProps>\n\n/**\n * Wraps a Hugeicons definition as a plain icon component, so call sites render `<CheckIcon />`.\n * The package ships no icon registry of its own: icon choice belongs to each consuming app,\n * which names every glyph it renders once with this helper.\n *\n * Sized to `1em`, so a `size-*` class or the surrounding font size drives it, at the 1.75\n * stroke of the design's icon grid. Decorative by default, since an icon almost always sits\n * beside the label that already names it; an icon that carries the meaning on its own\n * overrides with `aria-hidden={false}`, `role=\"img\"` and an `aria-label`. `defaults` sets props\n * every use of one glyph shares. Memoised, since a glyph almost never changes with the\n * component that renders it.\n */\nexport function icon(def: IconSvgElement, name: string, defaults?: IconProps): IconComponent {\n function Icon(props: IconProps) {\n return (\n <HugeiconsIcon\n icon={def}\n size=\"1em\"\n strokeWidth={1.75}\n aria-hidden={true}\n focusable=\"false\"\n {...defaults}\n {...props}\n />\n )\n }\n\n Icon.displayName = name\n\n return memo(Icon)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,KAAK,KAAqB,MAAc,UAAqC;CAC3F,SAAS,KAAK,OAAkB;EAC9B,OACE,oBAAC,eAAD;GACE,MAAM;GACN,MAAK;GACL,aAAa;GACb,eAAa;GACb,WAAU;GACV,GAAI;GACJ,GAAI;EACL,CAAA;CAEL;CAEA,KAAK,cAAc;CAEnB,OAAO,KAAK,IAAI;AAClB"}
|
package/lib/icons.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IconComponent } from "./icon.js";
|
|
2
|
+
export declare const AlertIcon: IconComponent;
|
|
3
|
+
export declare const AlertCircleIcon: IconComponent;
|
|
4
|
+
export declare const ArrowUpRightIcon: IconComponent;
|
|
5
|
+
export declare const CalendarIcon: IconComponent;
|
|
6
|
+
export declare const CancelIcon: IconComponent;
|
|
7
|
+
export declare const CancelCircleIcon: IconComponent;
|
|
8
|
+
export declare const CheckIcon: IconComponent;
|
|
9
|
+
export declare const CheckCircleIcon: IconComponent;
|
|
10
|
+
export declare const ChevronDownIcon: IconComponent;
|
|
11
|
+
export declare const ChevronLeftIcon: IconComponent;
|
|
12
|
+
export declare const ChevronRightIcon: IconComponent;
|
|
13
|
+
export declare const ChevronUpIcon: IconComponent;
|
|
14
|
+
export declare const ChevronsUpDownIcon: IconComponent;
|
|
15
|
+
export declare const ComputerIcon: IconComponent;
|
|
16
|
+
export declare const CopyIcon: IconComponent;
|
|
17
|
+
export declare const DashIcon: IconComponent;
|
|
18
|
+
export declare const HelpIcon: IconComponent;
|
|
19
|
+
export declare const InfoIcon: IconComponent;
|
|
20
|
+
export declare const LoadingIcon: IconComponent;
|
|
21
|
+
export declare const MoonIcon: IconComponent;
|
|
22
|
+
export declare const SearchIcon: IconComponent;
|
|
23
|
+
export declare const SunIcon: IconComponent;
|
package/lib/icons.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { icon } from "./icon.js";
|
|
2
|
+
import { Alert02Icon, AlertCircleIcon as AlertCircleIcon$1, ArrowDown01Icon, ArrowLeft01Icon, ArrowRight01Icon, ArrowUp01Icon, ArrowUpRight01Icon, Calendar03Icon, Cancel01Icon, CancelCircleIcon as CancelCircleIcon$1, CheckmarkCircle02Icon, ComputerIcon as ComputerIcon$1, Copy01Icon, HelpCircleIcon, InformationCircleIcon, Loading03Icon, Moon02Icon, Remove01Icon, Search01Icon, Sun03Icon, Tick02Icon, UnfoldMoreIcon } from "@hugeicons/core-free-icons";
|
|
3
|
+
// src/lib/icons.tsx
|
|
4
|
+
const AlertIcon = icon(Alert02Icon, "AlertIcon");
|
|
5
|
+
const AlertCircleIcon = icon(AlertCircleIcon$1, "AlertCircleIcon");
|
|
6
|
+
const ArrowUpRightIcon = icon(ArrowUpRight01Icon, "ArrowUpRightIcon");
|
|
7
|
+
const CalendarIcon = icon(Calendar03Icon, "CalendarIcon");
|
|
8
|
+
const CancelIcon = icon(Cancel01Icon, "CancelIcon");
|
|
9
|
+
const CancelCircleIcon = icon(CancelCircleIcon$1, "CancelCircleIcon");
|
|
10
|
+
const CheckIcon = icon(Tick02Icon, "CheckIcon");
|
|
11
|
+
const CheckCircleIcon = icon(CheckmarkCircle02Icon, "CheckCircleIcon");
|
|
12
|
+
const ChevronDownIcon = icon(ArrowDown01Icon, "ChevronDownIcon");
|
|
13
|
+
const ChevronLeftIcon = icon(ArrowLeft01Icon, "ChevronLeftIcon");
|
|
14
|
+
const ChevronRightIcon = icon(ArrowRight01Icon, "ChevronRightIcon");
|
|
15
|
+
const ChevronUpIcon = icon(ArrowUp01Icon, "ChevronUpIcon");
|
|
16
|
+
const ChevronsUpDownIcon = icon(UnfoldMoreIcon, "ChevronsUpDownIcon");
|
|
17
|
+
const ComputerIcon = icon(ComputerIcon$1, "ComputerIcon");
|
|
18
|
+
const CopyIcon = icon(Copy01Icon, "CopyIcon");
|
|
19
|
+
const DashIcon = icon(Remove01Icon, "DashIcon");
|
|
20
|
+
const HelpIcon = icon(HelpCircleIcon, "HelpIcon");
|
|
21
|
+
const InfoIcon = icon(InformationCircleIcon, "InfoIcon");
|
|
22
|
+
const LoadingIcon = icon(Loading03Icon, "LoadingIcon");
|
|
23
|
+
const MoonIcon = icon(Moon02Icon, "MoonIcon");
|
|
24
|
+
const SearchIcon = icon(Search01Icon, "SearchIcon");
|
|
25
|
+
const SunIcon = icon(Sun03Icon, "SunIcon");
|
|
26
|
+
export { AlertCircleIcon, AlertIcon, ArrowUpRightIcon, CalendarIcon, CancelCircleIcon, CancelIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsUpDownIcon, ComputerIcon, CopyIcon, DashIcon, HelpIcon, InfoIcon, LoadingIcon, MoonIcon, SearchIcon, SunIcon };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=icons.js.map
|
package/lib/icons.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.js","names":["AlertCircleDef","CancelCircleDef","ComputerDef"],"sources":["../../src/lib/icons.tsx"],"sourcesContent":["import {\n Alert02Icon,\n AlertCircleIcon as AlertCircleDef,\n ArrowDown01Icon,\n ArrowLeft01Icon,\n ArrowRight01Icon,\n ArrowUp01Icon,\n ArrowUpRight01Icon,\n Calendar03Icon,\n Cancel01Icon,\n CancelCircleIcon as CancelCircleDef,\n CheckmarkCircle02Icon,\n ComputerIcon as ComputerDef,\n Copy01Icon,\n HelpCircleIcon,\n InformationCircleIcon,\n Loading03Icon,\n Moon02Icon,\n Remove01Icon,\n Search01Icon,\n Sun03Icon,\n Tick02Icon,\n UnfoldMoreIcon,\n} from \"@hugeicons/core-free-icons\"\nimport { icon } from \"./icon\"\n\n// The handful of structural glyphs the package's own components render. This file lives in\n// `lib/` rather than `components/` so the `\"./*\"` wildcard export, which maps into\n// `components/`, never exposes it.\n\nexport const AlertIcon = icon(Alert02Icon, \"AlertIcon\")\nexport const AlertCircleIcon = icon(AlertCircleDef, \"AlertCircleIcon\")\nexport const ArrowUpRightIcon = icon(ArrowUpRight01Icon, \"ArrowUpRightIcon\")\nexport const CalendarIcon = icon(Calendar03Icon, \"CalendarIcon\")\nexport const CancelIcon = icon(Cancel01Icon, \"CancelIcon\")\nexport const CancelCircleIcon = icon(CancelCircleDef, \"CancelCircleIcon\")\nexport const CheckIcon = icon(Tick02Icon, \"CheckIcon\")\nexport const CheckCircleIcon = icon(CheckmarkCircle02Icon, \"CheckCircleIcon\")\nexport const ChevronDownIcon = icon(ArrowDown01Icon, \"ChevronDownIcon\")\nexport const ChevronLeftIcon = icon(ArrowLeft01Icon, \"ChevronLeftIcon\")\nexport const ChevronRightIcon = icon(ArrowRight01Icon, \"ChevronRightIcon\")\nexport const ChevronUpIcon = icon(ArrowUp01Icon, \"ChevronUpIcon\")\nexport const ChevronsUpDownIcon = icon(UnfoldMoreIcon, \"ChevronsUpDownIcon\")\nexport const ComputerIcon = icon(ComputerDef, \"ComputerIcon\")\nexport const CopyIcon = icon(Copy01Icon, \"CopyIcon\")\nexport const DashIcon = icon(Remove01Icon, \"DashIcon\")\nexport const HelpIcon = icon(HelpCircleIcon, \"HelpIcon\")\nexport const InfoIcon = icon(InformationCircleIcon, \"InfoIcon\")\nexport const LoadingIcon = icon(Loading03Icon, \"LoadingIcon\")\nexport const MoonIcon = icon(Moon02Icon, \"MoonIcon\")\nexport const SearchIcon = icon(Search01Icon, \"SearchIcon\")\nexport const SunIcon = icon(Sun03Icon, \"SunIcon\")\n"],"mappings":";;;AA8BA,MAAa,YAAY,KAAK,aAAa,WAAW;AACtD,MAAa,kBAAkB,KAAKA,mBAAgB,iBAAiB;AACrE,MAAa,mBAAmB,KAAK,oBAAoB,kBAAkB;AAC3E,MAAa,eAAe,KAAK,gBAAgB,cAAc;AAC/D,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,mBAAmB,KAAKC,oBAAiB,kBAAkB;AACxE,MAAa,YAAY,KAAK,YAAY,WAAW;AACrD,MAAa,kBAAkB,KAAK,uBAAuB,iBAAiB;AAC5E,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,mBAAmB,KAAK,kBAAkB,kBAAkB;AACzE,MAAa,gBAAgB,KAAK,eAAe,eAAe;AAChE,MAAa,qBAAqB,KAAK,gBAAgB,oBAAoB;AAC3E,MAAa,eAAe,KAAKC,gBAAa,cAAc;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AACnD,MAAa,WAAW,KAAK,cAAc,UAAU;AACrD,MAAa,WAAW,KAAK,gBAAgB,UAAU;AACvD,MAAa,WAAW,KAAK,uBAAuB,UAAU;AAC9D,MAAa,cAAc,KAAK,eAAe,aAAa;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AACnD,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,UAAU,KAAK,WAAW,SAAS"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared chrome for every interactive surface (buttons, inputs, select triggers, switches,
|
|
3
|
+
* tabs): a snappy colour transition, a pointer cursor when `interactive`, and, when `bordered`,
|
|
4
|
+
* the strong 1px border, which darkens under the pointer, plus the subtle fill when the control
|
|
5
|
+
* is clicked rather than typed into. Components layer their own fill and text colours on top
|
|
6
|
+
* with `cn`. An `aria-disabled` control keeps the pointer for its reason's tooltip, so it shows
|
|
7
|
+
* the not-allowed cursor and no hover fill or edge.
|
|
8
|
+
*
|
|
9
|
+
* Focus is not a variant: every focusable element gets the one focus ring from `styles.css`
|
|
10
|
+
* (`:focus-visible`), so there is nothing to opt into here. An invalid control
|
|
11
|
+
* (`aria-invalid`, set by a form field with an error) turns its border to the danger tone and
|
|
12
|
+
* keeps it while focused, so the field the message belongs to reads at a glance.
|
|
13
|
+
*/
|
|
14
|
+
export declare const interactiveVariants: import("tailwind-variants").TVReturnType<{
|
|
15
|
+
interactive: {
|
|
16
|
+
true: string;
|
|
17
|
+
};
|
|
18
|
+
bordered: {
|
|
19
|
+
true: string;
|
|
20
|
+
};
|
|
21
|
+
}, undefined, "transition-[color,background-color,border-color,box-shadow,opacity,filter] duration-75 ease-out aria-invalid:border-danger aria-invalid:focus:border-danger", undefined, undefined, undefined>;
|