diff --git a/localinfra/pds-theme.css b/localinfra/pds-theme.css new file mode 100644 index 000000000..537b9b3fd --- /dev/null +++ b/localinfra/pds-theme.css @@ -0,0 +1,168 @@ +@font-face { + font-family: "InterVariable"; + src: url("/@atproto/oauth-provider/~assets/InterVariable.woff2") format("woff2-variations"); + font-weight: 100 900; + font-style: normal; + font-display: swap; +} + +:root { + --font-sans: "InterVariable", "system-ui", sans-serif, ui-sans-serif; + --default-font-feature-settings: "kern" 1, "liga" 1, "cv05" 1, "tnum" 1; + --font-weight-medium: 510; + --font-weight-semibold: 590; + --radius-2xl: var(--radius); + + --background: #f3f4f6; + --foreground: #111827; + --card: #ffffff; + --card-foreground: #111827; + --popover: #ffffff; + --popover-foreground: #111827; + --secondary: #f3f4f6; + --secondary-foreground: #111827; + --muted: #f3f4f6; + --muted-foreground: #4b5563; + --accent: #f3f4f6; + --accent-foreground: #111827; + --border: #e5e7eb; + --input: #e5e7eb; + --ring: #d1d5db; + --sidebar: #f9fafb; + --sidebar-foreground: #111827; + --sidebar-accent: #f3f4f6; + --sidebar-accent-foreground: #111827; + --sidebar-border: #e5e7eb; + + --page: #ffffff; + --subtle: #f9fafb; + --subtle-foreground: #6b7280; + --placeholder: #9ca3af; +} + +@media (prefers-color-scheme: dark) { + :root { + --background: #111827; + --foreground: #f3f4f6; + --card: #1f2937; + --card-foreground: #f3f4f6; + --popover: #1f2937; + --popover-foreground: #f3f4f6; + --secondary: #3d4756; + --secondary-foreground: #f3f4f6; + --muted: #3d4756; + --muted-foreground: #9ca3af; + --accent: #3d4756; + --accent-foreground: #f3f4f6; + --border: #374151; + --input: #374151; + --ring: #6b7280; + --sidebar: #374151; + --sidebar-foreground: #f3f4f6; + --sidebar-accent: #3d4756; + --sidebar-accent-foreground: #f3f4f6; + --sidebar-border: #374151; + + --page: #111827; + --subtle: #374151; + } + + img[src$="/logotype.svg"] { + filter: invert(1); + } +} + +html.auth-background { + background-color: var(--page); +} + +.max-w-auth-card { + max-width: 28rem; +} + +[data-slot="card"] { + background-color: transparent; + box-shadow: none; + padding-block: 0; +} + +[data-slot="card"] > * { + padding-inline: 0; +} + +[data-slot="card"] > div:has(> img[src$="/logotype.svg"]) { + flex-direction: column; + padding-top: 0; +} + +[data-slot="card"] > div:has(> img[src$="/logotype.svg"])::after { + content: "tightly-knit social coding."; + font-size: 1.25rem; + line-height: 1.75rem; + font-style: italic; + font-weight: 400; + text-align: center; +} + +img[src$="/logotype.svg"] { + width: 12rem; + height: 6rem; + max-width: none; +} + +[data-slot="card-content"] label { + font-size: 0.75rem; + line-height: 1rem; + font-weight: 400; +} + +[data-slot="card-content"] p, +[data-slot="card-footer"] a, +[data-slot="card-footer"] [data-slot="select-trigger"] { + font-size: 0.75rem; + line-height: 1rem; + color: var(--subtle-foreground); +} + +input[data-slot="input"] { + height: 2.25rem; + font-size: 1rem; + line-height: 1.5rem; + background-color: var(--card); + border-color: var(--border); +} + +input[data-slot="input"]::placeholder { + color: var(--placeholder); +} + +input[data-slot="input"]:focus-visible { + border-color: var(--ring); + box-shadow: 0 0 0 1px var(--ring); +} + +button[data-slot="button"] { + font-size: 0.8125rem; + line-height: 1.25rem; + font-weight: 400; +} + +button[data-slot="button"].bg-primary { + height: 2rem; + color: var(--foreground); + background-color: var(--card); + border-color: var(--border); +} + +button[data-slot="button"].bg-primary:hover { + background-color: var(--subtle); +} + +button[data-slot="button"].bg-secondary { + height: 2rem; + background-color: transparent; +} + +button[data-slot="button"].bg-secondary:hover { + background-color: var(--muted); +} diff --git a/localinfra/pds-theme.mjs b/localinfra/pds-theme.mjs index 0daacea74..d28158f4f 100644 --- a/localinfra/pds-theme.mjs +++ b/localinfra/pds-theme.mjs @@ -1,30 +1,57 @@ import { createHash } from "node:crypto"; -import { readFileSync, writeFileSync } from "node:fs"; -import { dirname, join } from "node:path"; - -const replacements = [ - ["--radius:.625rem", "--radius:.25rem"], - [ - "--primary-foreground:rgb(var(--branding-color-primary-contrast,255 255 255))", - "--primary-foreground:rgb(255 255 255)", - ], -]; - -const manifestPath = process.argv[2]; -const manifest = JSON.parse(readFileSync(manifestPath, "utf8")); +import { copyFileSync, readFileSync, writeFileSync } from "node:fs"; +import { basename, dirname, join } from "node:path"; + +const [uiManifestPath, providerDir, themePath, fontPath] = process.argv.slice(2); + +const sha256 = (data) => createHash("sha256").update(data).digest("base64"); + +function patch(path, replacements, append = "") { + let text = readFileSync(path, "utf8"); + for (const [from, to] of replacements) { + if (!text.includes(from)) throw new Error(`${path}: ${from} not found`); + text = text.replaceAll(from, to); + } + text += append; + writeFileSync(path, text); + return text; +} + +patch(join(providerDir, "lib/csp/index.js"), [[" 'default-src',\n", " 'default-src',\n 'font-src',\n"]]); +patch(join(providerDir, "router/assets/assets.js"), [ + [`'connect-src': ["'self'"],`, `'connect-src': ["'self'"],\n 'font-src': ["'self'"],`], +]); +patch(join(providerDir, "router/assets/assets-manifest.js"), [ + ["[null, 'document', 'style', 'script']", "[null, 'document', 'style', 'script', 'font']"], +]); + +const uiDir = dirname(uiManifestPath); +const manifest = JSON.parse(readFileSync(uiManifestPath, "utf8")); const styles = Object.entries(manifest).filter(([, asset]) => asset.mime === "text/css"); -if (styles.length === 0) throw new Error(`${manifestPath}: no stylesheet in manifest`); +if (styles.length === 0) throw new Error(`${uiManifestPath}: no stylesheet in manifest`); +const theme = readFileSync(themePath, "utf8"); for (const [filename, asset] of styles) { if (asset.data) throw new Error(`${filename}: inlined in manifest`); - const path = join(dirname(manifestPath), filename); - let css = readFileSync(path, "utf8"); - for (const [from, to] of replacements) { - if (!css.includes(from)) throw new Error(`${filename}: ${from} not found`); - css = css.replaceAll(from, to); - } - writeFileSync(path, css); - asset.sha256 = createHash("sha256").update(css).digest("base64"); + const css = patch( + join(uiDir, filename), + [ + ["--radius:.625rem", "--radius:.25rem"], + ["calc(var(--radius) + 4px)", "var(--radius)"], + ["calc(var(--radius) - 2px)", "var(--radius)"], + ["calc(var(--radius) - 4px)", "var(--radius)"], + [ + "--primary-foreground:rgb(var(--branding-color-primary-contrast,255 255 255))", + "--primary-foreground:rgb(255 255 255)", + ], + ], + theme, + ); + asset.sha256 = sha256(css); } -writeFileSync(manifestPath, JSON.stringify(manifest)); +const font = basename(fontPath); +copyFileSync(fontPath, join(uiDir, font)); +manifest[font] = { type: "asset", mime: "font/woff2", sha256: sha256(readFileSync(fontPath)) }; + +writeFileSync(uiManifestPath, JSON.stringify(manifest)); diff --git a/localinfra/pds.Dockerfile b/localinfra/pds.Dockerfile index c3a0b9d8e..2775d81e9 100644 --- a/localinfra/pds.Dockerfile +++ b/localinfra/pds.Dockerfile @@ -1,5 +1,5 @@ # Development only. Not for production use. -ARG PDS_IMAGE=ghcr.io/bluesky-social/pds:0.4.5034 +ARG PDS_IMAGE=ghcr.io/bluesky-social/pds:0.4.5036 FROM ${PDS_IMAGE} # the oauth provider caches client metadata (and jwks) in memory for 10min with no @@ -11,11 +11,19 @@ RUN set -eu; \ sed -i "s/ttl: 600e3/ttl: 1e3/g" "$f"; \ ! grep -q "ttl: 600e3" "$f" -COPY pds-theme.mjs /tmp/pds-theme.mjs +ADD https://github.com/rsms/inter/releases/download/v4.1/Inter-4.1.zip /tmp/pds-theme/inter.zip +COPY pds-theme.mjs pds-theme.css /tmp/pds-theme/ RUN set -eu; \ + cd /tmp/pds-theme; \ + unzip -q -j inter.zip web/InterVariable.woff2; \ m=$(find /app/node_modules/.pnpm \ -path '*@atproto/oauth-provider-ui/dist/bundle-manifest.json' \ | head -1); \ [ -n "$m" ] || { echo "oauth-provider-ui manifest not found; pds layout changed" >&2; exit 1; }; \ - node /tmp/pds-theme.mjs "$m"; \ - rm /tmp/pds-theme.mjs + p=$(find /app/node_modules/.pnpm \ + -path '*@atproto/oauth-provider/dist/router/assets/assets.js' \ + | head -1); \ + [ -n "$p" ] || { echo "oauth-provider assets not found; pds layout changed" >&2; exit 1; }; \ + node pds-theme.mjs "$m" "${p%/router/assets/assets.js}" pds-theme.css InterVariable.woff2; \ + cd /; \ + rm -r /tmp/pds-theme diff --git a/localinfra/pds.env b/localinfra/pds.env index ea006ec5a..3d69d8fdb 100644 --- a/localinfra/pds.env +++ b/localinfra/pds.env @@ -18,7 +18,7 @@ PDS_REPO_BACKFILL_LIMIT_MS=31536000000 # PDS_CRAWLERS=https://relay.tngl.boltless.dev PDS_SERVICE_NAME=Tangled -PDS_LOGO_URL=https://next.tangled.org/favicon.svg +PDS_LOGO_URL=https://next.tangled.org/logos/logotype.svg PDS_HOME_URL=https://tangled.org PDS_TERMS_OF_SERVICE_URL=https://tangled.org/terms PDS_PRIVACY_POLICY_URL=https://tangled.org/privacy