macbetter 0.0.0-stage → 0.1.0-beta.2
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 +201 -0
- package/README.md +92 -2
- package/dist/components/accessory-tile.d.ts +50 -0
- package/dist/components/accessory-tile.js +46 -0
- package/dist/components/activity-indicator.d.ts +15 -0
- package/dist/components/activity-indicator.js +15 -0
- package/dist/components/alert.d.ts +29 -0
- package/dist/components/alert.js +30 -0
- package/dist/components/artifact-card.d.ts +41 -0
- package/dist/components/artifact-card.js +57 -0
- package/dist/components/artwork.d.ts +44 -0
- package/dist/components/artwork.js +935 -0
- package/dist/components/attachment.d.ts +48 -0
- package/dist/components/attachment.js +65 -0
- package/dist/components/automation-row.d.ts +24 -0
- package/dist/components/automation-row.js +12 -0
- package/dist/components/avatar.d.ts +33 -0
- package/dist/components/avatar.js +45 -0
- package/dist/components/badge.d.ts +24 -0
- package/dist/components/badge.js +19 -0
- package/dist/components/button.d.ts +20 -0
- package/dist/components/button.js +10 -0
- package/dist/components/calendar.d.ts +30 -0
- package/dist/components/calendar.js +47 -0
- package/dist/components/camera-view.d.ts +40 -0
- package/dist/components/camera-view.js +44 -0
- package/dist/components/card.d.ts +14 -0
- package/dist/components/card.js +21 -0
- package/dist/components/carousel.d.ts +18 -0
- package/dist/components/carousel.js +33 -0
- package/dist/components/chat.d.ts +29 -0
- package/dist/components/chat.js +29 -0
- package/dist/components/checkbox.d.ts +13 -0
- package/dist/components/checkbox.js +16 -0
- package/dist/components/code-block.d.ts +39 -0
- package/dist/components/code-block.js +65 -0
- package/dist/components/code-field.d.ts +16 -0
- package/dist/components/code-field.js +29 -0
- package/dist/components/color-well.d.ts +23 -0
- package/dist/components/color-well.js +27 -0
- package/dist/components/combo-box.d.ts +42 -0
- package/dist/components/combo-box.js +102 -0
- package/dist/components/command-palette.d.ts +33 -0
- package/dist/components/command-palette.js +55 -0
- package/dist/components/confirmation.d.ts +24 -0
- package/dist/components/confirmation.js +50 -0
- package/dist/components/content-unavailable.d.ts +19 -0
- package/dist/components/content-unavailable.js +21 -0
- package/dist/components/context-menu.d.ts +9 -0
- package/dist/components/context-menu.js +15 -0
- package/dist/components/date-picker.d.ts +53 -0
- package/dist/components/date-picker.js +86 -0
- package/dist/components/description-list.d.ts +18 -0
- package/dist/components/description-list.js +17 -0
- package/dist/components/device-frame.d.ts +18 -0
- package/dist/components/device-frame.js +16 -0
- package/dist/components/dialog.d.ts +27 -0
- package/dist/components/dialog.js +35 -0
- package/dist/components/disclosure.d.ts +32 -0
- package/dist/components/disclosure.js +35 -0
- package/dist/components/dock.d.ts +28 -0
- package/dist/components/dock.js +80 -0
- package/dist/components/door-control.d.ts +20 -0
- package/dist/components/door-control.js +43 -0
- package/dist/components/energy-readout.d.ts +32 -0
- package/dist/components/energy-readout.js +27 -0
- package/dist/components/field.d.ts +28 -0
- package/dist/components/field.js +32 -0
- package/dist/components/gauge.d.ts +25 -0
- package/dist/components/gauge.js +42 -0
- package/dist/components/generated-image.d.ts +39 -0
- package/dist/components/generated-image.js +47 -0
- package/dist/components/glass.d.ts +34 -0
- package/dist/components/glass.js +31 -0
- package/dist/components/home-backdrop.d.ts +23 -0
- package/dist/components/home-backdrop.js +12 -0
- package/dist/components/home-section.d.ts +19 -0
- package/dist/components/home-section.js +21 -0
- package/dist/components/home-status.d.ts +24 -0
- package/dist/components/home-status.js +14 -0
- package/dist/components/hover-card.d.ts +14 -0
- package/dist/components/hover-card.js +16 -0
- package/dist/components/inspector.d.ts +29 -0
- package/dist/components/inspector.js +40 -0
- package/dist/components/level-control.d.ts +19 -0
- package/dist/components/level-control.js +13 -0
- package/dist/components/light-color-picker.d.ts +33 -0
- package/dist/components/light-color-picker.js +56 -0
- package/dist/components/list.d.ts +42 -0
- package/dist/components/list.js +42 -0
- package/dist/components/listbox.d.ts +16 -0
- package/dist/components/listbox.js +28 -0
- package/dist/components/lock-control.d.ts +20 -0
- package/dist/components/lock-control.js +35 -0
- package/dist/components/menu-bar.d.ts +14 -0
- package/dist/components/menu-bar.js +16 -0
- package/dist/components/menu.d.ts +40 -0
- package/dist/components/menu.js +54 -0
- package/dist/components/message.d.ts +65 -0
- package/dist/components/message.js +69 -0
- package/dist/components/model-picker.d.ts +61 -0
- package/dist/components/model-picker.js +59 -0
- package/dist/components/navigation-bar.d.ts +24 -0
- package/dist/components/navigation-bar.js +54 -0
- package/dist/components/outline.d.ts +21 -0
- package/dist/components/outline.js +40 -0
- package/dist/components/page-control.d.ts +10 -0
- package/dist/components/page-control.js +8 -0
- package/dist/components/plan.d.ts +25 -0
- package/dist/components/plan.js +43 -0
- package/dist/components/popover.d.ts +16 -0
- package/dist/components/popover.js +24 -0
- package/dist/components/progress.d.ts +27 -0
- package/dist/components/progress.js +27 -0
- package/dist/components/prompt-input.d.ts +93 -0
- package/dist/components/prompt-input.js +172 -0
- package/dist/components/radio.d.ts +16 -0
- package/dist/components/radio.js +13 -0
- package/dist/components/rating.d.ts +10 -0
- package/dist/components/rating.js +12 -0
- package/dist/components/reasoning.d.ts +28 -0
- package/dist/components/reasoning.js +52 -0
- package/dist/components/response.d.ts +14 -0
- package/dist/components/response.js +14 -0
- package/dist/components/scene-tile.d.ts +22 -0
- package/dist/components/scene-tile.js +13 -0
- package/dist/components/scroll-view.d.ts +21 -0
- package/dist/components/scroll-view.js +13 -0
- package/dist/components/search-field.d.ts +16 -0
- package/dist/components/search-field.js +12 -0
- package/dist/components/secure-field.d.ts +23 -0
- package/dist/components/secure-field.js +21 -0
- package/dist/components/segmented-control.d.ts +12 -0
- package/dist/components/segmented-control.js +10 -0
- package/dist/components/select.d.ts +45 -0
- package/dist/components/select.js +79 -0
- package/dist/components/sensor-readout.d.ts +29 -0
- package/dist/components/sensor-readout.js +12 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +11 -0
- package/dist/components/setup-code.d.ts +29 -0
- package/dist/components/setup-code.js +47 -0
- package/dist/components/sheet.d.ts +31 -0
- package/dist/components/sheet.js +51 -0
- package/dist/components/shimmer.d.ts +18 -0
- package/dist/components/shimmer.js +17 -0
- package/dist/components/sidebar.d.ts +30 -0
- package/dist/components/sidebar.js +26 -0
- package/dist/components/slider.d.ts +27 -0
- package/dist/components/slider.js +43 -0
- package/dist/components/sources.d.ts +51 -0
- package/dist/components/sources.js +46 -0
- package/dist/components/split-view.d.ts +11 -0
- package/dist/components/split-view.js +13 -0
- package/dist/components/squircle.d.ts +41 -0
- package/dist/components/squircle.js +63 -0
- package/dist/components/stepper.d.ts +30 -0
- package/dist/components/stepper.js +28 -0
- package/dist/components/suggestion.d.ts +23 -0
- package/dist/components/suggestion.js +29 -0
- package/dist/components/switch.d.ts +10 -0
- package/dist/components/switch.js +10 -0
- package/dist/components/tab-bar.d.ts +20 -0
- package/dist/components/tab-bar.js +17 -0
- package/dist/components/table.d.ts +49 -0
- package/dist/components/table.js +179 -0
- package/dist/components/tabs.d.ts +16 -0
- package/dist/components/tabs.js +19 -0
- package/dist/components/text-area.d.ts +14 -0
- package/dist/components/text-area.js +9 -0
- package/dist/components/text-field.d.ts +26 -0
- package/dist/components/text-field.js +23 -0
- package/dist/components/thermostat-control.d.ts +30 -0
- package/dist/components/thermostat-control.js +139 -0
- package/dist/components/toast.d.ts +30 -0
- package/dist/components/toast.js +114 -0
- package/dist/components/toggle.d.ts +21 -0
- package/dist/components/toggle.js +19 -0
- package/dist/components/token-field.d.ts +31 -0
- package/dist/components/token-field.js +78 -0
- package/dist/components/tool-call.d.ts +48 -0
- package/dist/components/tool-call.js +77 -0
- package/dist/components/toolbar.d.ts +27 -0
- package/dist/components/toolbar.js +39 -0
- package/dist/components/tooltip.d.ts +11 -0
- package/dist/components/tooltip.js +18 -0
- package/dist/components/window.d.ts +56 -0
- package/dist/components/window.js +61 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.js +98 -0
- package/dist/lib/agent-glyphs.d.ts +10 -0
- package/dist/lib/agent-glyphs.js +19 -0
- package/dist/lib/cx.d.ts +9 -0
- package/dist/lib/cx.js +14 -0
- package/dist/lib/derive.d.ts +53 -0
- package/dist/lib/derive.js +255 -0
- package/dist/lib/field-glyphs.d.ts +13 -0
- package/dist/lib/field-glyphs.js +28 -0
- package/dist/lib/menu-glyphs.d.ts +6 -0
- package/dist/lib/menu-glyphs.js +15 -0
- package/dist/lib/platform.d.ts +18 -0
- package/dist/lib/platform.js +17 -0
- package/dist/lib/squircle.d.ts +23 -0
- package/dist/lib/squircle.js +69 -0
- package/dist/lib/theme.d.ts +42 -0
- package/dist/lib/theme.js +62 -0
- package/dist/styles/base.css +115 -0
- package/dist/styles/components/accessory-tile.css +461 -0
- package/dist/styles/components/activity-indicator.css +63 -0
- package/dist/styles/components/alert.css +433 -0
- package/dist/styles/components/artifact-card.css +238 -0
- package/dist/styles/components/artwork.css +380 -0
- package/dist/styles/components/attachment.css +540 -0
- package/dist/styles/components/automation-row.css +52 -0
- package/dist/styles/components/avatar.css +230 -0
- package/dist/styles/components/badge.css +204 -0
- package/dist/styles/components/button.css +298 -0
- package/dist/styles/components/calendar.css +287 -0
- package/dist/styles/components/camera-view.css +239 -0
- package/dist/styles/components/card.css +100 -0
- package/dist/styles/components/carousel.css +210 -0
- package/dist/styles/components/chat.css +209 -0
- package/dist/styles/components/checkbox.css +212 -0
- package/dist/styles/components/code-block.css +162 -0
- package/dist/styles/components/code-field.css +163 -0
- package/dist/styles/components/color-well.css +452 -0
- package/dist/styles/components/combo-box.css +222 -0
- package/dist/styles/components/command-palette.css +379 -0
- package/dist/styles/components/confirmation.css +189 -0
- package/dist/styles/components/content-unavailable.css +105 -0
- package/dist/styles/components/context-menu.css +43 -0
- package/dist/styles/components/date-picker.css +356 -0
- package/dist/styles/components/description-list.css +92 -0
- package/dist/styles/components/device-frame.css +202 -0
- package/dist/styles/components/dialog.css +366 -0
- package/dist/styles/components/disclosure.css +197 -0
- package/dist/styles/components/dock.css +404 -0
- package/dist/styles/components/door-control.css +187 -0
- package/dist/styles/components/energy-readout.css +161 -0
- package/dist/styles/components/field.css +175 -0
- package/dist/styles/components/gauge.css +239 -0
- package/dist/styles/components/generated-image.css +248 -0
- package/dist/styles/components/glass.css +113 -0
- package/dist/styles/components/home-backdrop.css +81 -0
- package/dist/styles/components/home-section.css +100 -0
- package/dist/styles/components/home-status.css +215 -0
- package/dist/styles/components/hover-card.css +145 -0
- package/dist/styles/components/index.css +94 -0
- package/dist/styles/components/inspector.css +236 -0
- package/dist/styles/components/level-control.css +247 -0
- package/dist/styles/components/light-color-picker.css +94 -0
- package/dist/styles/components/list.css +411 -0
- package/dist/styles/components/listbox.css +168 -0
- package/dist/styles/components/lock-control.css +164 -0
- package/dist/styles/components/menu-bar.css +94 -0
- package/dist/styles/components/menu.css +454 -0
- package/dist/styles/components/message.css +236 -0
- package/dist/styles/components/model-picker.css +64 -0
- package/dist/styles/components/navigation-bar.css +249 -0
- package/dist/styles/components/outline.css +248 -0
- package/dist/styles/components/page-control.css +127 -0
- package/dist/styles/components/plan.css +212 -0
- package/dist/styles/components/popover.css +186 -0
- package/dist/styles/components/progress.css +228 -0
- package/dist/styles/components/prompt-input.css +503 -0
- package/dist/styles/components/radio.css +281 -0
- package/dist/styles/components/rating.css +122 -0
- package/dist/styles/components/reasoning.css +214 -0
- package/dist/styles/components/response.css +303 -0
- package/dist/styles/components/scene-tile.css +295 -0
- package/dist/styles/components/scroll-view.css +195 -0
- package/dist/styles/components/search-field.css +128 -0
- package/dist/styles/components/secure-field.css +189 -0
- package/dist/styles/components/segmented-control.css +183 -0
- package/dist/styles/components/select.css +290 -0
- package/dist/styles/components/sensor-readout.css +231 -0
- package/dist/styles/components/separator.css +62 -0
- package/dist/styles/components/setup-code.css +138 -0
- package/dist/styles/components/sheet.css +345 -0
- package/dist/styles/components/shimmer.css +60 -0
- package/dist/styles/components/sidebar.css +261 -0
- package/dist/styles/components/slider.css +208 -0
- package/dist/styles/components/sources.css +349 -0
- package/dist/styles/components/split-view.css +75 -0
- package/dist/styles/components/squircle.css +44 -0
- package/dist/styles/components/stepper.css +278 -0
- package/dist/styles/components/suggestion.css +203 -0
- package/dist/styles/components/switch.css +115 -0
- package/dist/styles/components/tab-bar.css +223 -0
- package/dist/styles/components/table.css +313 -0
- package/dist/styles/components/tabs.css +262 -0
- package/dist/styles/components/text-area.css +94 -0
- package/dist/styles/components/text-field.css +294 -0
- package/dist/styles/components/thermostat-control.css +214 -0
- package/dist/styles/components/toast.css +418 -0
- package/dist/styles/components/toggle.css +312 -0
- package/dist/styles/components/token-field.css +193 -0
- package/dist/styles/components/tool-call.css +391 -0
- package/dist/styles/components/toolbar.css +370 -0
- package/dist/styles/components/tooltip.css +69 -0
- package/dist/styles/components/window.css +428 -0
- package/dist/styles/index.css +17 -0
- package/dist/styles/materials.css +263 -0
- package/dist/styles/platforms.css +214 -0
- package/dist/styles/themes/ember.css +24 -0
- package/dist/styles/themes/graphite.css +16 -0
- package/dist/styles/themes/nebula.css +16 -0
- package/dist/styles/themes/system.css +28 -0
- package/dist/styles/tokens.css +299 -0
- package/package.json +82 -3
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Color math for building themes: hex <-> OKLCH, gamut mapping, alpha
|
|
3
|
+
* compositing, contrast fixing and a whole theme generated from one accent.
|
|
4
|
+
* Pure functions, no DOM, so they can be unit tested.
|
|
5
|
+
*/
|
|
6
|
+
import { contrastRatio } from "./theme.js";
|
|
7
|
+
const colorKeys = [
|
|
8
|
+
"accent",
|
|
9
|
+
"onAccent",
|
|
10
|
+
"accentText",
|
|
11
|
+
"accentSecondary",
|
|
12
|
+
"ink",
|
|
13
|
+
"bg",
|
|
14
|
+
"bgSecondary",
|
|
15
|
+
"bgTertiary",
|
|
16
|
+
"bgElevated",
|
|
17
|
+
"bgSidebar",
|
|
18
|
+
"tint",
|
|
19
|
+
"green",
|
|
20
|
+
"red",
|
|
21
|
+
];
|
|
22
|
+
/* ── Hex ─────────────────────────────────────────────────────────── */
|
|
23
|
+
const hexPattern = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
24
|
+
/** `#abc`, `abc`, `#aabbcc` → `#aabbcc`; anything else → null. Alpha is dropped from 8-digit hex. */
|
|
25
|
+
function normalizeHex(input) {
|
|
26
|
+
let value = input.trim().toLowerCase();
|
|
27
|
+
if (/^#?[0-9a-f]{8}$/.test(value))
|
|
28
|
+
value = value.replace("#", "").slice(0, 6);
|
|
29
|
+
const match = hexPattern.exec(value);
|
|
30
|
+
if (!match)
|
|
31
|
+
return null;
|
|
32
|
+
const digits = match[1];
|
|
33
|
+
const full = digits.length === 3 ? [...digits].map((d) => d + d).join("") : digits;
|
|
34
|
+
return `#${full}`;
|
|
35
|
+
}
|
|
36
|
+
function hexToRgb(hex) {
|
|
37
|
+
const value = normalizeHex(hex);
|
|
38
|
+
if (!value)
|
|
39
|
+
throw new Error(`Not a hex color: ${hex}`);
|
|
40
|
+
return [1, 3, 5].map((i) => parseInt(value.slice(i, i + 2), 16) / 255);
|
|
41
|
+
}
|
|
42
|
+
function rgbToHex(rgb) {
|
|
43
|
+
return `#${rgb
|
|
44
|
+
.map((c) => Math.round(Math.min(1, Math.max(0, c)) * 255).toString(16).padStart(2, "0"))
|
|
45
|
+
.join("")}`;
|
|
46
|
+
}
|
|
47
|
+
/* ── OKLab / OKLCH (Björn Ottosson) ──────────────────────────────── */
|
|
48
|
+
const toLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
49
|
+
const toGamma = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
50
|
+
function linearToOklab([r, g, b]) {
|
|
51
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
52
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
53
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
54
|
+
return [
|
|
55
|
+
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
56
|
+
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
57
|
+
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
function oklabToLinear([L, a, b]) {
|
|
61
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
62
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
63
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
64
|
+
return [
|
|
65
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
66
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
67
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
function hexToOklch(hex) {
|
|
71
|
+
const [L, a, b] = linearToOklab(hexToRgb(hex).map(toLinear));
|
|
72
|
+
const c = Math.hypot(a, b);
|
|
73
|
+
let h = (Math.atan2(b, a) * 180) / Math.PI;
|
|
74
|
+
if (h < 0)
|
|
75
|
+
h += 360;
|
|
76
|
+
// Grays have no meaningful hue; report 0 so callers can tell.
|
|
77
|
+
return { l: L, c: c < 1e-4 ? 0 : c, h: c < 1e-4 ? 0 : h };
|
|
78
|
+
}
|
|
79
|
+
function oklchToLinear({ l, c, h }) {
|
|
80
|
+
const rad = (h * Math.PI) / 180;
|
|
81
|
+
return oklabToLinear([l, c * Math.cos(rad), c * Math.sin(rad)]);
|
|
82
|
+
}
|
|
83
|
+
const inGamut = (rgb) => rgb.every((v) => v >= -1e-4 && v <= 1 + 1e-4);
|
|
84
|
+
/** OKLCH → hex, reducing chroma (keeping lightness and hue) until the color fits in sRGB. */
|
|
85
|
+
function oklchToHex(color) {
|
|
86
|
+
const l = Math.min(1, Math.max(0, color.l));
|
|
87
|
+
const target = { ...color, l };
|
|
88
|
+
if (inGamut(oklchToLinear(target)))
|
|
89
|
+
return rgbToHex(oklchToLinear(target).map(toGamma));
|
|
90
|
+
let lo = 0;
|
|
91
|
+
let hi = target.c;
|
|
92
|
+
for (let i = 0; i < 24; i++) {
|
|
93
|
+
const mid = (lo + hi) / 2;
|
|
94
|
+
if (inGamut(oklchToLinear({ ...target, c: mid })))
|
|
95
|
+
lo = mid;
|
|
96
|
+
else
|
|
97
|
+
hi = mid;
|
|
98
|
+
}
|
|
99
|
+
return rgbToHex(oklchToLinear({ ...target, c: lo }).map(toGamma));
|
|
100
|
+
}
|
|
101
|
+
/* ── Compositing and contrast ────────────────────────────────────── */
|
|
102
|
+
/** `fg` at `alpha` over an opaque `bg`, composited in sRGB as the browser paints it. */
|
|
103
|
+
function composite(fg, bg, alpha) {
|
|
104
|
+
const a = hexToRgb(fg);
|
|
105
|
+
const b = hexToRgb(bg);
|
|
106
|
+
return rgbToHex(a.map((c, i) => c * alpha + b[i] * (1 - alpha)));
|
|
107
|
+
}
|
|
108
|
+
function relativeLuminance(hex) {
|
|
109
|
+
const [r, g, b] = hexToRgb(hex).map(toLinear);
|
|
110
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Moves `fg`'s OKLCH lightness away from `bg` until the pair reaches `target`,
|
|
114
|
+
* keeping hue and as much chroma as fits. Returns `fg` unchanged if it already passes.
|
|
115
|
+
*/
|
|
116
|
+
function ensureContrast(fg, bg, target = 4.5) {
|
|
117
|
+
if (contrastRatio(fg, bg) >= target)
|
|
118
|
+
return normalizeHex(fg);
|
|
119
|
+
const color = hexToOklch(fg);
|
|
120
|
+
const darker = relativeLuminance(bg) > 0.18;
|
|
121
|
+
const end = darker ? 0 : 1;
|
|
122
|
+
if (contrastRatio(oklchToHex({ ...color, l: end }), bg) < target)
|
|
123
|
+
return oklchToHex({ ...color, l: end });
|
|
124
|
+
let near = color.l;
|
|
125
|
+
let far = end;
|
|
126
|
+
for (let i = 0; i < 28; i++) {
|
|
127
|
+
const mid = (near + far) / 2;
|
|
128
|
+
if (contrastRatio(oklchToHex({ ...color, l: mid }), bg) >= target)
|
|
129
|
+
far = mid;
|
|
130
|
+
else
|
|
131
|
+
near = mid;
|
|
132
|
+
}
|
|
133
|
+
return oklchToHex({ ...color, l: far });
|
|
134
|
+
}
|
|
135
|
+
/** Of `candidates`, the one with the most contrast against `bg`. */
|
|
136
|
+
function bestContrast(bg, candidates) {
|
|
137
|
+
return candidates.reduce((best, next) => (contrastRatio(next, bg) > contrastRatio(best, bg) ? next : best));
|
|
138
|
+
}
|
|
139
|
+
/* ── A theme from one accent ─────────────────────────────────────── */
|
|
140
|
+
const systemRed = { light: "#e5372b", dark: "#ff5a4f" };
|
|
141
|
+
const systemGreen = { light: "#248a3d", dark: "#30d158" };
|
|
142
|
+
/**
|
|
143
|
+
* A complete set of color seeds from one accent: the accent kept as given in
|
|
144
|
+
* light and lifted for dark, text on it chosen by contrast, the accent as text
|
|
145
|
+
* pushed to 4.5:1, and neutrals tinted toward the accent's hue.
|
|
146
|
+
*/
|
|
147
|
+
function deriveFromAccent(input) {
|
|
148
|
+
const accentLight = normalizeHex(input) ?? "#0071e3";
|
|
149
|
+
const base = hexToOklch(accentLight);
|
|
150
|
+
const h = base.h;
|
|
151
|
+
// How much of the hue the neutrals carry: a hint, never a color.
|
|
152
|
+
const hint = Math.min(base.c, 0.16) / 0.16;
|
|
153
|
+
const n = (l, c) => oklchToHex({ l, c: c * hint, h });
|
|
154
|
+
const accentDark = oklchToHex({
|
|
155
|
+
l: Math.min(0.84, Math.max(base.l + 0.06, 0.68)),
|
|
156
|
+
c: Math.min(base.c * 1.05, 0.22),
|
|
157
|
+
h,
|
|
158
|
+
});
|
|
159
|
+
const bg = { light: "#ffffff", dark: n(0.18, 0.03) };
|
|
160
|
+
const ink = { light: n(0.2, 0.025), dark: n(0.97, 0.008) };
|
|
161
|
+
const deep = { light: n(0.2, 0.05), dark: n(0.16, 0.04) };
|
|
162
|
+
const onAccent = {
|
|
163
|
+
light: bestContrast(accentLight, ["#ffffff", deep.light]),
|
|
164
|
+
dark: bestContrast(accentDark, ["#ffffff", deep.dark]),
|
|
165
|
+
};
|
|
166
|
+
const secondaryHue = (h + 150) % 360;
|
|
167
|
+
const secondary = {
|
|
168
|
+
light: oklchToHex({ l: 0.56, c: Math.min(Math.max(base.c, 0.08), 0.14), h: secondaryHue }),
|
|
169
|
+
dark: oklchToHex({ l: 0.76, c: Math.min(Math.max(base.c, 0.08), 0.13), h: secondaryHue }),
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
172
|
+
accent: { light: accentLight, dark: accentDark },
|
|
173
|
+
onAccent,
|
|
174
|
+
accentText: {
|
|
175
|
+
light: ensureContrast(accentLight, bg.light, 4.6),
|
|
176
|
+
dark: ensureContrast(accentDark, bg.dark, 4.6),
|
|
177
|
+
},
|
|
178
|
+
accentSecondary: secondary,
|
|
179
|
+
ink,
|
|
180
|
+
bg,
|
|
181
|
+
bgSecondary: { light: n(0.965, 0.008), dark: n(0.15, 0.028) },
|
|
182
|
+
bgTertiary: { light: "#ffffff", dark: n(0.235, 0.034) },
|
|
183
|
+
bgElevated: { light: "#ffffff", dark: n(0.22, 0.034) },
|
|
184
|
+
bgSidebar: { light: n(0.945, 0.012), dark: n(0.165, 0.03) },
|
|
185
|
+
tint: { light: n(0.52, 0.03), dark: n(0.68, 0.04) },
|
|
186
|
+
green: systemGreen,
|
|
187
|
+
red: systemRed,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// The alphas tokens.css mixes labels and edges at, per scheme.
|
|
191
|
+
const secondaryAlpha = { light: 0.66, dark: 0.68 };
|
|
192
|
+
const borderAlpha = { light: 0.48, dark: 0.46 };
|
|
193
|
+
function contrastChecks(colors, scheme) {
|
|
194
|
+
const c = (key) => colors[key][scheme];
|
|
195
|
+
const bg = c("bg");
|
|
196
|
+
const rows = [
|
|
197
|
+
{ id: "on-accent", label: "Text on accent", fix: "onAccent", fg: c("onAccent"), bg: c("accent"), target: 4.5 },
|
|
198
|
+
{ id: "accent-text", label: "Accent as text", fix: "accentText", fg: c("accentText"), bg, target: 4.5 },
|
|
199
|
+
{ id: "ink", label: "Primary text", fix: "ink", fg: c("ink"), bg, target: 4.5 },
|
|
200
|
+
{
|
|
201
|
+
id: "label-secondary",
|
|
202
|
+
label: "Secondary text",
|
|
203
|
+
fix: "ink",
|
|
204
|
+
fg: composite(c("ink"), bg, secondaryAlpha[scheme]),
|
|
205
|
+
bg,
|
|
206
|
+
target: 4.5,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
id: "control-border",
|
|
210
|
+
label: "Control edges",
|
|
211
|
+
fix: "ink",
|
|
212
|
+
fg: composite(c("ink"), bg, borderAlpha[scheme]),
|
|
213
|
+
bg,
|
|
214
|
+
target: 3,
|
|
215
|
+
},
|
|
216
|
+
];
|
|
217
|
+
return rows.map((row) => {
|
|
218
|
+
const ratio = contrastRatio(row.fg, row.bg);
|
|
219
|
+
return { ...row, ratio, pass: ratio >= row.target };
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/** Adjusts the seed behind a failing check so it passes, leaving everything else alone. */
|
|
223
|
+
function fixCheck(colors, scheme, id) {
|
|
224
|
+
const c = (key) => colors[key][scheme];
|
|
225
|
+
const set = (key, value) => ({
|
|
226
|
+
...colors,
|
|
227
|
+
[key]: { ...colors[key], [scheme]: value },
|
|
228
|
+
});
|
|
229
|
+
switch (id) {
|
|
230
|
+
case "on-accent": {
|
|
231
|
+
const best = bestContrast(c("accent"), [c("onAccent"), "#ffffff", ensureContrast(c("onAccent"), c("accent"), 4.6)]);
|
|
232
|
+
return set("onAccent", best);
|
|
233
|
+
}
|
|
234
|
+
case "accent-text":
|
|
235
|
+
return set("accentText", ensureContrast(c("accentText"), c("bg"), 4.6));
|
|
236
|
+
case "ink":
|
|
237
|
+
return set("ink", ensureContrast(c("ink"), c("bg"), 4.6));
|
|
238
|
+
case "label-secondary":
|
|
239
|
+
case "control-border": {
|
|
240
|
+
// Both are alphas of ink, so only a stronger ink moves them.
|
|
241
|
+
const target = id === "label-secondary" ? 4.6 : 3.1;
|
|
242
|
+
const alpha = id === "label-secondary" ? secondaryAlpha[scheme] : borderAlpha[scheme];
|
|
243
|
+
const ink = hexToOklch(c("ink"));
|
|
244
|
+
const end = relativeLuminance(c("bg")) > 0.18 ? 0 : 1;
|
|
245
|
+
for (let step = 0; step <= 40; step++) {
|
|
246
|
+
const l = ink.l + ((end - ink.l) * step) / 40;
|
|
247
|
+
const candidate = oklchToHex({ ...ink, l });
|
|
248
|
+
if (contrastRatio(composite(candidate, c("bg"), alpha), c("bg")) >= target)
|
|
249
|
+
return set("ink", candidate);
|
|
250
|
+
}
|
|
251
|
+
return set("ink", oklchToHex({ ...ink, l: end }));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
export { bestContrast, colorKeys, composite, contrastChecks, deriveFromAccent, ensureContrast, fixCheck, hexToOklch, hexToRgb, normalizeHex, oklchToHex, relativeLuminance, rgbToHex, };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
type GlyphProps = React.ComponentProps<"svg">;
|
|
3
|
+
/** SF Symbols' magnifyingglass. */
|
|
4
|
+
declare function MagnifierGlyph(props: GlyphProps): React.JSX.Element;
|
|
5
|
+
/** xmark.circle.fill, with the cross cut out so the field shows through. */
|
|
6
|
+
declare function ClearGlyph(props: GlyphProps): React.JSX.Element;
|
|
7
|
+
declare function EyeGlyph(props: GlyphProps): React.JSX.Element;
|
|
8
|
+
declare function EyeSlashGlyph(props: GlyphProps): React.JSX.Element;
|
|
9
|
+
declare function CalendarGlyph(props: GlyphProps): React.JSX.Element;
|
|
10
|
+
declare function ChevronGlyph({ direction, ...props }: GlyphProps & {
|
|
11
|
+
direction: "left" | "right";
|
|
12
|
+
}): React.JSX.Element;
|
|
13
|
+
export { CalendarGlyph, ChevronGlyph, ClearGlyph, EyeGlyph, EyeSlashGlyph, MagnifierGlyph };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
const base = {
|
|
3
|
+
"aria-hidden": true,
|
|
4
|
+
focusable: false,
|
|
5
|
+
viewBox: "0 0 16 16",
|
|
6
|
+
fill: "none",
|
|
7
|
+
};
|
|
8
|
+
/** SF Symbols' magnifyingglass. */
|
|
9
|
+
function MagnifierGlyph(props) {
|
|
10
|
+
return (_jsxs("svg", { ...base, ...props, children: [_jsx("circle", { cx: "6.75", cy: "6.75", r: "4.75", stroke: "currentColor", strokeWidth: "1.6" }), _jsx("path", { d: "m10.3 10.3 3.7 3.7", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round" })] }));
|
|
11
|
+
}
|
|
12
|
+
/** xmark.circle.fill, with the cross cut out so the field shows through. */
|
|
13
|
+
function ClearGlyph(props) {
|
|
14
|
+
return (_jsx("svg", { ...base, ...props, children: _jsx("path", { fill: "currentColor", fillRule: "evenodd", d: "M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14ZM9.59 5.35l1.06 1.06L9.06 8l1.59 1.59-1.06 1.06L8 9.06l-1.59 1.59-1.06-1.06L6.94 8 5.35 6.41l1.06-1.06L8 6.94Z" }) }));
|
|
15
|
+
}
|
|
16
|
+
function EyeGlyph(props) {
|
|
17
|
+
return (_jsxs("svg", { ...base, ...props, children: [_jsx("path", { d: "M1.5 8S4 3.25 8 3.25 14.5 8 14.5 8 12 12.75 8 12.75 1.5 8 1.5 8Z", stroke: "currentColor", strokeWidth: "1.4", strokeLinejoin: "round" }), _jsx("circle", { cx: "8", cy: "8", r: "2.25", fill: "currentColor" })] }));
|
|
18
|
+
}
|
|
19
|
+
function EyeSlashGlyph(props) {
|
|
20
|
+
return (_jsxs("svg", { ...base, ...props, children: [_jsx("path", { d: "M4.1 4.6C2.4 5.8 1.5 8 1.5 8S4 12.75 8 12.75c1.2 0 2.3-.4 3.2-1M6.4 3.45c.5-.13 1.05-.2 1.6-.2 4 0 6.5 4.75 6.5 4.75s-.55 1.05-1.6 2.2", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M6.45 6.5a2.25 2.25 0 0 0 3.05 3.05", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }), _jsx("path", { d: "m2.5 1.75 11 12.5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })] }));
|
|
21
|
+
}
|
|
22
|
+
function CalendarGlyph(props) {
|
|
23
|
+
return (_jsxs("svg", { ...base, ...props, children: [_jsx("rect", { x: "1.75", y: "2.75", width: "12.5", height: "11.5", rx: "2.25", stroke: "currentColor", strokeWidth: "1.3" }), _jsx("path", { d: "M1.75 6h12.5", stroke: "currentColor", strokeWidth: "1.3" }), _jsx("path", { d: "M5 1.25v2.5M11 1.25v2.5", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round" }), _jsx("circle", { cx: "5", cy: "8.75", r: ".85", fill: "currentColor" }), _jsx("circle", { cx: "8", cy: "8.75", r: ".85", fill: "currentColor" }), _jsx("circle", { cx: "11", cy: "8.75", r: ".85", fill: "currentColor" }), _jsx("circle", { cx: "5", cy: "11.5", r: ".85", fill: "currentColor" }), _jsx("circle", { cx: "8", cy: "11.5", r: ".85", fill: "currentColor" })] }));
|
|
24
|
+
}
|
|
25
|
+
function ChevronGlyph({ direction, ...props }) {
|
|
26
|
+
return (_jsx("svg", { ...base, ...props, children: _jsx("path", { d: direction === "left" ? "M10 2.75 4.75 8 10 13.25" : "M6 2.75 11.25 8 6 13.25", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
27
|
+
}
|
|
28
|
+
export { CalendarGlyph, ChevronGlyph, ClearGlyph, EyeGlyph, EyeSlashGlyph, MagnifierGlyph };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare function CheckGlyph(): import("react").JSX.Element;
|
|
2
|
+
declare function ChevronGlyph({ direction }: {
|
|
3
|
+
direction: "down" | "right" | "up-down";
|
|
4
|
+
}): import("react").JSX.Element;
|
|
5
|
+
declare function SearchGlyph(): import("react").JSX.Element;
|
|
6
|
+
export { CheckGlyph, ChevronGlyph, SearchGlyph };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
function CheckGlyph() {
|
|
3
|
+
return (_jsx("svg", { viewBox: "0 0 12 12", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M2.25 6.4 4.9 9.1 9.9 2.9", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
4
|
+
}
|
|
5
|
+
function ChevronGlyph({ direction }) {
|
|
6
|
+
return (_jsx("svg", { viewBox: "0 0 12 12", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: direction === "down"
|
|
7
|
+
? "M3 4.6 6 7.6 9 4.6"
|
|
8
|
+
: direction === "right"
|
|
9
|
+
? "M4.6 3 7.6 6 4.6 9"
|
|
10
|
+
: "M3.6 4.7 6 2.4 8.4 4.7M3.6 7.3 6 9.6 8.4 7.3", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
11
|
+
}
|
|
12
|
+
function SearchGlyph() {
|
|
13
|
+
return (_jsxs("svg", { viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: [_jsx("circle", { cx: "8.6", cy: "8.6", r: "5.6", stroke: "currentColor", strokeWidth: "1.9" }), _jsx("path", { d: "m12.9 12.9 4.1 4.1", stroke: "currentColor", strokeWidth: "1.9", strokeLinecap: "round" })] }));
|
|
14
|
+
}
|
|
15
|
+
export { CheckGlyph, ChevronGlyph, SearchGlyph };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type Platform = "macos" | "ipados" | "ios";
|
|
2
|
+
type PlatformChoice = Platform | "auto";
|
|
3
|
+
/** What "auto" means on this device: touch picks iOS or iPadOS by width, a pointer picks macOS. */
|
|
4
|
+
declare function resolvePlatform(view?: Window): Platform;
|
|
5
|
+
type MacbetterScriptProps = {
|
|
6
|
+
/** The platform to render, or `auto` to follow the device. */
|
|
7
|
+
platform?: PlatformChoice;
|
|
8
|
+
/** localStorage key that holds a saved platform choice, if you let people pick. */
|
|
9
|
+
storageKey?: string;
|
|
10
|
+
nonce?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Sets `data-platform` on <html> before first paint, so the page never
|
|
14
|
+
* flashes macOS metrics on a phone. Render it in <head> or first in <body>.
|
|
15
|
+
*/
|
|
16
|
+
declare function MacbetterScript({ platform, storageKey, nonce }: MacbetterScriptProps): import("react").JSX.Element;
|
|
17
|
+
export { resolvePlatform, MacbetterScript };
|
|
18
|
+
export type { Platform, PlatformChoice, MacbetterScriptProps };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** What "auto" means on this device: touch picks iOS or iPadOS by width, a pointer picks macOS. */
|
|
3
|
+
function resolvePlatform(view = window) {
|
|
4
|
+
const coarse = view.matchMedia("(pointer: coarse)").matches;
|
|
5
|
+
if (!coarse)
|
|
6
|
+
return "macos";
|
|
7
|
+
return view.matchMedia("(min-width: 744px)").matches ? "ipados" : "ios";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Sets `data-platform` on <html> before first paint, so the page never
|
|
11
|
+
* flashes macOS metrics on a phone. Render it in <head> or first in <body>.
|
|
12
|
+
*/
|
|
13
|
+
function MacbetterScript({ platform = "auto", storageKey, nonce }) {
|
|
14
|
+
const code = `(function(){try{var d=document.documentElement,p=${JSON.stringify(platform)},k=${JSON.stringify(storageKey ?? null)};if(k){var s=localStorage.getItem(k);if(s==="macos"||s==="ipados"||s==="ios"||s==="auto")p=s}if(p==="auto"){p=matchMedia("(pointer: coarse)").matches?(matchMedia("(min-width: 744px)").matches?"ipados":"ios"):"macos"}d.setAttribute("data-platform",p)}catch(e){}})()`;
|
|
15
|
+
return _jsx("script", { nonce: nonce, dangerouslySetInnerHTML: { __html: code } });
|
|
16
|
+
}
|
|
17
|
+
export { resolvePlatform, MacbetterScript };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apple's continuous corner as an SVG path.
|
|
3
|
+
*
|
|
4
|
+
* Each corner is a circular arc eased into both edges by a cubic Bézier, the
|
|
5
|
+
* construction Figma calls "corner smoothing". `smoothing` stretches the ease:
|
|
6
|
+
* the curve starts `(1 + smoothing) × radius` from the corner. At 0.77 it
|
|
7
|
+
* traces iOS's continuous corner to within 0.15px on a 360px app icon
|
|
8
|
+
* (measured against the UIBezierPath outline; Figma's "iOS" preset of 0.6 is
|
|
9
|
+
* about twice as far off). When the box is too small for the full ease, the
|
|
10
|
+
* smoothing gives way first and the radius second, so the largest radius
|
|
11
|
+
* (half the shorter side) is a capsule, or a circle in a square.
|
|
12
|
+
*/
|
|
13
|
+
/** Corner smoothing that matches iOS: app icons, cards, sheets, buttons. */
|
|
14
|
+
declare const SQUIRCLE_SMOOTHING = 0.77;
|
|
15
|
+
/** An app icon's corner radius as a fraction of its side. */
|
|
16
|
+
declare const SQUIRCLE_ICON_RATIO = 0.2237;
|
|
17
|
+
/**
|
|
18
|
+
* The outline of a `width` × `height` rectangle with continuous corners, as an
|
|
19
|
+
* SVG path starting at the top edge and running clockwise, in user units with
|
|
20
|
+
* the origin at the top-left corner.
|
|
21
|
+
*/
|
|
22
|
+
declare function squirclePath(width: number, height: number, radius: number, smoothing?: number): string;
|
|
23
|
+
export { SQUIRCLE_ICON_RATIO, SQUIRCLE_SMOOTHING, squirclePath };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apple's continuous corner as an SVG path.
|
|
3
|
+
*
|
|
4
|
+
* Each corner is a circular arc eased into both edges by a cubic Bézier, the
|
|
5
|
+
* construction Figma calls "corner smoothing". `smoothing` stretches the ease:
|
|
6
|
+
* the curve starts `(1 + smoothing) × radius` from the corner. At 0.77 it
|
|
7
|
+
* traces iOS's continuous corner to within 0.15px on a 360px app icon
|
|
8
|
+
* (measured against the UIBezierPath outline; Figma's "iOS" preset of 0.6 is
|
|
9
|
+
* about twice as far off). When the box is too small for the full ease, the
|
|
10
|
+
* smoothing gives way first and the radius second, so the largest radius
|
|
11
|
+
* (half the shorter side) is a capsule, or a circle in a square.
|
|
12
|
+
*/
|
|
13
|
+
/** Corner smoothing that matches iOS: app icons, cards, sheets, buttons. */
|
|
14
|
+
const SQUIRCLE_SMOOTHING = 0.77;
|
|
15
|
+
/** An app icon's corner radius as a fraction of its side. */
|
|
16
|
+
const SQUIRCLE_ICON_RATIO = 0.2237;
|
|
17
|
+
function round(value) {
|
|
18
|
+
const rounded = Math.round(value * 1000) / 1000;
|
|
19
|
+
return Object.is(rounded, -0) ? 0 : rounded;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The outline of a `width` × `height` rectangle with continuous corners, as an
|
|
23
|
+
* SVG path starting at the top edge and running clockwise, in user units with
|
|
24
|
+
* the origin at the top-left corner.
|
|
25
|
+
*/
|
|
26
|
+
function squirclePath(width, height, radius, smoothing = SQUIRCLE_SMOOTHING) {
|
|
27
|
+
const w = Number.isFinite(width) && width > 0 ? width : 0;
|
|
28
|
+
const h = Number.isFinite(height) && height > 0 ? height : 0;
|
|
29
|
+
const budget = Math.min(w, h) / 2;
|
|
30
|
+
const r = Math.min(Number.isFinite(radius) && radius > 0 ? radius : 0, budget);
|
|
31
|
+
let s = Math.min(Math.max(Number.isFinite(smoothing) ? smoothing : 0, 0), 1);
|
|
32
|
+
if (r === 0)
|
|
33
|
+
return `M0 0H${round(w)}V${round(h)}H0Z`;
|
|
34
|
+
// The ease can't reach past the middle of a side: shrink it before the radius.
|
|
35
|
+
const p = Math.min((1 + s) * r, budget);
|
|
36
|
+
s = Math.min(s, budget / r - 1);
|
|
37
|
+
const rad = Math.PI / 180;
|
|
38
|
+
const arcAngle = 90 * (1 - s);
|
|
39
|
+
const arc = Math.sin((arcAngle / 2) * rad) * r * Math.SQRT2;
|
|
40
|
+
const alpha = (90 - arcAngle) / 2;
|
|
41
|
+
const p3p4 = r * Math.tan((alpha / 2) * rad);
|
|
42
|
+
const beta = 45 * s;
|
|
43
|
+
const c = p3p4 * Math.cos(beta * rad);
|
|
44
|
+
const d = c * Math.tan(beta * rad);
|
|
45
|
+
const b = (p - arc - c - d) / 3;
|
|
46
|
+
const a = 2 * b;
|
|
47
|
+
const n = round;
|
|
48
|
+
const A = `a${n(r)} ${n(r)} 0 0 1`;
|
|
49
|
+
return [
|
|
50
|
+
`M${n(w - p)} 0`,
|
|
51
|
+
`c${n(a)} 0 ${n(a + b)} 0 ${n(a + b + c)} ${n(d)}`,
|
|
52
|
+
`${A} ${n(arc)} ${n(arc)}`,
|
|
53
|
+
`c${n(d)} ${n(c)} ${n(d)} ${n(b + c)} ${n(d)} ${n(a + b + c)}`,
|
|
54
|
+
`L${n(w)} ${n(h - p)}`,
|
|
55
|
+
`c0 ${n(a)} 0 ${n(a + b)} ${n(-d)} ${n(a + b + c)}`,
|
|
56
|
+
`${A} ${n(-arc)} ${n(arc)}`,
|
|
57
|
+
`c${n(-c)} ${n(d)} ${n(-(b + c))} ${n(d)} ${n(-(a + b + c))} ${n(d)}`,
|
|
58
|
+
`L${n(p)} ${n(h)}`,
|
|
59
|
+
`c${n(-a)} 0 ${n(-(a + b))} 0 ${n(-(a + b + c))} ${n(-d)}`,
|
|
60
|
+
`${A} ${n(-arc)} ${n(-arc)}`,
|
|
61
|
+
`c${n(-d)} ${n(-c)} ${n(-d)} ${n(-(b + c))} ${n(-d)} ${n(-(a + b + c))}`,
|
|
62
|
+
`L0 ${n(p)}`,
|
|
63
|
+
`c0 ${n(-a)} 0 ${n(-(a + b))} ${n(d)} ${n(-(a + b + c))}`,
|
|
64
|
+
`${A} ${n(arc)} ${n(-arc)}`,
|
|
65
|
+
`c${n(c)} ${n(-d)} ${n(b + c)} ${n(-d)} ${n(a + b + c)} ${n(-d)}`,
|
|
66
|
+
"Z",
|
|
67
|
+
].join("");
|
|
68
|
+
}
|
|
69
|
+
export { SQUIRCLE_ICON_RATIO, SQUIRCLE_SMOOTHING, squirclePath };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
type ColorPair = string | {
|
|
2
|
+
light: string;
|
|
3
|
+
dark: string;
|
|
4
|
+
};
|
|
5
|
+
type ThemeSeeds = {
|
|
6
|
+
/** The brand's action color: filled buttons, selection, focus. */
|
|
7
|
+
accent: ColorPair;
|
|
8
|
+
/** Text and icons on the accent. Must hold 4.5:1 against it. */
|
|
9
|
+
onAccent?: ColorPair;
|
|
10
|
+
/** The accent, adjusted to hold 4.5:1 as text on the background. */
|
|
11
|
+
accentText?: ColorPair;
|
|
12
|
+
accentSecondary?: ColorPair;
|
|
13
|
+
/** Text color at full strength. Labels are opacities of it. */
|
|
14
|
+
ink?: ColorPair;
|
|
15
|
+
bg?: ColorPair;
|
|
16
|
+
bgSecondary?: ColorPair;
|
|
17
|
+
bgTertiary?: ColorPair;
|
|
18
|
+
bgElevated?: ColorPair;
|
|
19
|
+
bgSidebar?: ColorPair;
|
|
20
|
+
/** The gray that fills and materials are mixed from. Tint it toward the brand. */
|
|
21
|
+
tint?: ColorPair;
|
|
22
|
+
/** Overrides for the system palette: red, orange, yellow, green, mint, teal, cyan, blue, indigo, purple, pink, brown. */
|
|
23
|
+
palette?: Partial<Record<SystemColor, ColorPair>>;
|
|
24
|
+
/** 1 is Apple's corners. Lower is squarer, higher is rounder. */
|
|
25
|
+
radiusScale?: number;
|
|
26
|
+
font?: string;
|
|
27
|
+
fontDisplay?: string;
|
|
28
|
+
fontRounded?: string;
|
|
29
|
+
fontMono?: string;
|
|
30
|
+
};
|
|
31
|
+
type SystemColor = "red" | "orange" | "yellow" | "green" | "mint" | "teal" | "cyan" | "blue" | "indigo" | "purple" | "pink" | "brown";
|
|
32
|
+
/** The custom properties a theme sets, ready for a `style` prop or a stylesheet. */
|
|
33
|
+
declare function themeVariables(seeds: ThemeSeeds): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* A theme as CSS. Put it after macbetter's stylesheet and turn it on with
|
|
36
|
+
* `data-theme="<name>"` on any element.
|
|
37
|
+
*/
|
|
38
|
+
declare function createTheme(name: string, seeds: ThemeSeeds): string;
|
|
39
|
+
/** WCAG contrast ratio of two sRGB hex colors, for checking a theme's pairs. */
|
|
40
|
+
declare function contrastRatio(a: string, b: string): number;
|
|
41
|
+
export { contrastRatio, createTheme, themeVariables };
|
|
42
|
+
export type { ColorPair, SystemColor, ThemeSeeds };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const seedNames = [
|
|
2
|
+
["accent", "--mb-accent"],
|
|
3
|
+
["onAccent", "--mb-on-accent"],
|
|
4
|
+
["accentText", "--mb-accent-text"],
|
|
5
|
+
["accentSecondary", "--mb-accent-secondary"],
|
|
6
|
+
["ink", "--mb-ink"],
|
|
7
|
+
["bg", "--mb-bg"],
|
|
8
|
+
["bgSecondary", "--mb-bg-secondary"],
|
|
9
|
+
["bgTertiary", "--mb-bg-tertiary"],
|
|
10
|
+
["bgElevated", "--mb-bg-elevated"],
|
|
11
|
+
["bgSidebar", "--mb-bg-sidebar"],
|
|
12
|
+
["tint", "--mb-tint"],
|
|
13
|
+
];
|
|
14
|
+
function color(value) {
|
|
15
|
+
return typeof value === "string" ? value : `light-dark(${value.light}, ${value.dark})`;
|
|
16
|
+
}
|
|
17
|
+
/** The custom properties a theme sets, ready for a `style` prop or a stylesheet. */
|
|
18
|
+
function themeVariables(seeds) {
|
|
19
|
+
const variables = {};
|
|
20
|
+
for (const [key, name] of seedNames) {
|
|
21
|
+
const value = seeds[key];
|
|
22
|
+
if (value !== undefined)
|
|
23
|
+
variables[name] = color(value);
|
|
24
|
+
}
|
|
25
|
+
for (const [name, value] of Object.entries(seeds.palette ?? {})) {
|
|
26
|
+
variables[`--mb-${name}`] = color(value);
|
|
27
|
+
}
|
|
28
|
+
if (seeds.radiusScale !== undefined)
|
|
29
|
+
variables["--mb-radius-scale"] = String(seeds.radiusScale);
|
|
30
|
+
if (seeds.font)
|
|
31
|
+
variables["--mb-font"] = seeds.font;
|
|
32
|
+
if (seeds.fontDisplay)
|
|
33
|
+
variables["--mb-font-display"] = seeds.fontDisplay;
|
|
34
|
+
if (seeds.fontRounded)
|
|
35
|
+
variables["--mb-font-rounded"] = seeds.fontRounded;
|
|
36
|
+
if (seeds.fontMono)
|
|
37
|
+
variables["--mb-font-mono"] = seeds.fontMono;
|
|
38
|
+
return variables;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A theme as CSS. Put it after macbetter's stylesheet and turn it on with
|
|
42
|
+
* `data-theme="<name>"` on any element.
|
|
43
|
+
*/
|
|
44
|
+
function createTheme(name, seeds) {
|
|
45
|
+
const lines = Object.entries(themeVariables(seeds)).map(([key, value]) => ` ${key}: ${value};`);
|
|
46
|
+
return `[data-theme="${name}"] {\n${lines.join("\n")}\n}\n`;
|
|
47
|
+
}
|
|
48
|
+
/** WCAG contrast ratio of two sRGB hex colors, for checking a theme's pairs. */
|
|
49
|
+
function contrastRatio(a, b) {
|
|
50
|
+
const [la, lb] = [luminance(a), luminance(b)];
|
|
51
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
52
|
+
}
|
|
53
|
+
function luminance(hex) {
|
|
54
|
+
const value = hex.replace("#", "");
|
|
55
|
+
const full = value.length === 3 ? [...value].map((c) => c + c).join("") : value;
|
|
56
|
+
const channels = [0, 2, 4].map((i) => {
|
|
57
|
+
const c = parseInt(full.slice(i, i + 2), 16) / 255;
|
|
58
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
59
|
+
});
|
|
60
|
+
return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2];
|
|
61
|
+
}
|
|
62
|
+
export { contrastRatio, createTheme, themeVariables };
|