Skip to content

Open source CapCut alternative.

TypeScript

fix(site): draw classic scrollbars thin

David Le89574ba8d067
diff --git a/site/src/app/[locale]/layout.tsx b/site/src/app/[locale]/layout.tsx
index 9f96c479..8c1eb262 100644
--- a/site/src/app/[locale]/layout.tsx
+++ b/site/src/app/[locale]/layout.tsx
@@ -11,6 +11,7 @@ import { DONKEYCUT_CANONICAL } from "@/cut/lib/hosts";
import { IntlScope } from "@/i18n/IntlScope";
import { LOCALES, isLocale } from "@/i18n/locales";
import { THEME_HEAD_SCRIPT } from "@/lib/theme";
+import { SCROLLBARS_HEAD_SCRIPT } from "@/lib/scrollbars";
import { QueryProvider } from "@/queries/QueryProvider";
import { MetaPageView } from "@/app/_components/MetaPageView";
import { PlanTermsProvider } from "@/app/_components/PlanTermsProvider";
@@ -71,6 +72,7 @@ export default async function RootLayout({
>
<head>
<script dangerouslySetInnerHTML={{ __html: THEME_HEAD_SCRIPT }} />
+ <script dangerouslySetInnerHTML={{ __html: SCROLLBARS_HEAD_SCRIPT }} />
</head>
<body className="min-h-full flex flex-col">
<PostHogProvider>
diff --git a/site/src/app/globals.css b/site/src/app/globals.css
index cfad2e91..65515603 100644
--- a/site/src/app/globals.css
+++ b/site/src/app/globals.css
@@ -292,3 +292,38 @@ html:has(.app-surface) {
animation: none;
}
}
+
+/* Classic scrollbars draw as the ScrollArea's hairline: a 4px rounded thumb
+ inset in a 10px clear track. The head script sets the flag
+ (lib/scrollbars.ts). */
+[data-scrollbars=classic]::-webkit-scrollbar,
+[data-scrollbars=classic] ::-webkit-scrollbar {
+ width: 10px;
+ height: 10px;
+}
+
+[data-scrollbars=classic]::-webkit-scrollbar-track,
+[data-scrollbars=classic] ::-webkit-scrollbar-track,
+[data-scrollbars=classic]::-webkit-scrollbar-corner,
+[data-scrollbars=classic] ::-webkit-scrollbar-corner {
+ background: transparent;
+}
+
+[data-scrollbars=classic]::-webkit-scrollbar-thumb,
+[data-scrollbars=classic] ::-webkit-scrollbar-thumb {
+ border: 3px solid transparent;
+ border-radius: 9999px;
+ background-clip: padding-box;
+ background-color: color-mix(in oklab, var(--foreground) 25%, transparent);
+}
+
+[data-scrollbars=classic]::-webkit-scrollbar-thumb:hover,
+[data-scrollbars=classic] ::-webkit-scrollbar-thumb:hover {
+ background-color: color-mix(in oklab, var(--foreground) 40%, transparent);
+}
+
+@supports not selector(::-webkit-scrollbar) {
+ [data-scrollbars=classic] * {
+ scrollbar-width: thin;
+ }
+}
diff --git a/site/src/clients/chatgpt/ui/main.tsx b/site/src/clients/chatgpt/ui/main.tsx
index 4d5105ea..88e35255 100644
--- a/site/src/clients/chatgpt/ui/main.tsx
+++ b/site/src/clients/chatgpt/ui/main.tsx
@@ -1,5 +1,8 @@
import { createRoot } from "react-dom/client";
+import { markClassicScrollbars } from "@/lib/scrollbars";
import { WidgetIntl } from "./intl";
import { PreviewApp } from "./PreviewApp";
+markClassicScrollbars(document);
+
createRoot(document.getElementById("root")!).render(<WidgetIntl><PreviewApp /></WidgetIntl>);
diff --git a/site/src/clients/chatgpt/ui/preview.css b/site/src/clients/chatgpt/ui/preview.css
index 2e9813be..43c6fead 100644
--- a/site/src/clients/chatgpt/ui/preview.css
+++ b/site/src/clients/chatgpt/ui/preview.css
@@ -15,3 +15,5 @@
/* The site's skeleton (globals.css): an opaque slab breathing between two neutrals with a highlight sweeping across it. */
.slab{display:block;position:relative;overflow:hidden;border-radius:6px;background:var(--slab);animation:slab-pulse 1.6s ease-in-out infinite}.slab::after{content:"";position:absolute;inset:0;background:linear-gradient(90deg,transparent,var(--slab-highlight) 50%,transparent);animation:slab-shimmer 1.6s ease-in-out infinite}
@keyframes slab-shimmer{0%{transform:translateX(-100%)}to{transform:translateX(100%)}}@keyframes slab-pulse{0%,to{background-color:var(--slab)}50%{background-color:var(--slab-pulse)}}@media (prefers-reduced-motion:reduce){.slab,.slab::after{animation:none}}
+/* Classic scrollbars draw as the editor's hairline (globals.css). */
+[data-scrollbars=classic]::-webkit-scrollbar,[data-scrollbars=classic] ::-webkit-scrollbar{width:10px;height:10px}[data-scrollbars=classic]::-webkit-scrollbar-track,[data-scrollbars=classic] ::-webkit-scrollbar-track,[data-scrollbars=classic]::-webkit-scrollbar-corner,[data-scrollbars=classic] ::-webkit-scrollbar-corner{background:transparent}[data-scrollbars=classic]::-webkit-scrollbar-thumb,[data-scrollbars=classic] ::-webkit-scrollbar-thumb{border:3px solid transparent;border-radius:9999px;background-clip:padding-box;background-color:color-mix(in oklab,var(--editor-fg) 25%,transparent)}[data-scrollbars=classic]::-webkit-scrollbar-thumb:hover,[data-scrollbars=classic] ::-webkit-scrollbar-thumb:hover{background-color:color-mix(in oklab,var(--editor-fg) 40%,transparent)}
diff --git a/site/src/lib/scrollbars.test.ts b/site/src/lib/scrollbars.test.ts
new file mode 100644
index 00000000..43601227
--- /dev/null
+++ b/site/src/lib/scrollbars.test.ts
@@ -0,0 +1,48 @@
+import { describe, expect, test } from "bun:test";
+import { readFileSync } from "node:fs";
+import postcss from "postcss";
+import { markClassicScrollbars, SCROLLBARS_HEAD_SCRIPT } from "@/lib/scrollbars";
+
+const STYLESHEETS = ["../app/globals.css", "../clients/chatgpt/ui/preview.css"];
+const THIN_MAX_PX = 10;
+
+// A page whose probe reports the given scrollbar gutter.
+function fakeDocument(gutter: number) {
+ const root = { dataset: {} as Record<string, string>, appendChild: () => {} };
+ const probe = { style: { cssText: "" }, offsetWidth: 50, clientWidth: 50 - gutter, remove: () => {} };
+ return { documentElement: root, createElement: () => probe } as unknown as Document;
+}
+
+describe("classic scrollbars", () => {
+ test("a page with classic bars is flagged", () => {
+ const doc = fakeDocument(15);
+ markClassicScrollbars(doc);
+ expect(doc.documentElement.dataset.scrollbars).toBe("classic");
+ });
+
+ test("overlay bars stay native", () => {
+ const doc = fakeDocument(0);
+ markClassicScrollbars(doc);
+ expect(doc.documentElement.dataset.scrollbars).toBeUndefined();
+ });
+
+ test("the head script runs the same check", () => {
+ expect(SCROLLBARS_HEAD_SCRIPT).toContain("classic");
+ });
+
+ // Every surface draws classic bars as the thin ScrollArea hairline.
+ for (const file of STYLESHEETS) {
+ test(`${file} draws flagged bars thin`, () => {
+ const css = postcss.parse(readFileSync(new URL(file, import.meta.url), "utf8"));
+ const widths: number[] = [];
+ css.walkRules((rule) => {
+ if (!rule.selector.includes("[data-scrollbars=classic]") || !rule.selector.endsWith("::-webkit-scrollbar")) {
+ return;
+ }
+ rule.walkDecls("width", (decl) => { widths.push(parseFloat(decl.value)); });
+ });
+ expect(widths.length).toBeGreaterThan(0);
+ expect(Math.max(...widths)).toBeLessThanOrEqual(THIN_MAX_PX);
+ });
+ }
+});
diff --git a/site/src/lib/scrollbars.ts b/site/src/lib/scrollbars.ts
new file mode 100644
index 00000000..e29161da
--- /dev/null
+++ b/site/src/lib/scrollbars.ts
@@ -0,0 +1,22 @@
+/**
+ * Classic scrollbars — macOS with a mouse attached, Windows, Linux — take a
+ * 15px gutter from every native scroller and draw a fat bar. The page flags
+ * itself when they are in use, and the stylesheet draws them as the thin
+ * ScrollArea hairline. Overlay scrollbars already float, so they stay native.
+ */
+export function markClassicScrollbars(doc: Document) {
+ try {
+ const probe = doc.createElement("div");
+ probe.style.cssText = "position:absolute;top:-100px;width:50px;height:50px;overflow:scroll";
+ doc.documentElement.appendChild(probe);
+ if (probe.offsetWidth > probe.clientWidth) {
+ doc.documentElement.dataset.scrollbars = "classic";
+ }
+ probe.remove();
+ } catch {
+ // A page that cannot measure keeps the native bars.
+ }
+}
+
+/** The same check, run in the head so the first paint already has thin bars. */
+export const SCROLLBARS_HEAD_SCRIPT = `(${markClassicScrollbars.toString()})(document)`;