Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

5.7 KB
Raw Blame
/**
 * Credits page: the fonts the app bundles, which themes set them, and the licence each ships
 * under, with the licence's full text one click away. The list comes from the UI package's font
 * metadata (the same record its licence files and build scripts are checked against), so a face
 * added or dropped there appears or disappears here without an edit.
 *
 * MiSans's licence asks software that uses the face to credit it, and this page is where the
 * app does: the face is listed with its licence for every account and every backend, which is
 * why the page itself is visible to everyone, the desktop shell's window included. The page is
 * the list and nothing else; the rail already names it.
 *
 * The themes are the page's other half, and for the same reason: a theme is a work someone
 * chose, and its licence is not visible anywhere else in the product. The three the app ships
 * come with it, and the four in the library are fetched from a directory Adelie does not own —
 * both are Apache-2.0, which is stated here rather than assumed from the app's own licence.
 *
 * Each licence text is a disclosure (the WAI-ARIA pattern: a real button with `aria-expanded`
 * and `aria-controls`, the panel kept in the DOM and `hidden` while folded). A licence runs to
 * pages, so the open panel scrolls inside a capped height rather than pushing the next font a
 * screen away.
 */
import { useId, useState } from "react";
import { FONT_CREDITS } from "@adelie/ui/fonts-credits";
import type { FontCredit } from "@adelie/ui/fonts-credits";
import type { ThemeId } from "@adelie/ui";
import { Chevron, ICON_GAP } from "@adelie/ui";
import { S } from "../../lib/strings";

/** A theme id in the reader's words. */
function themeName(id: ThemeId): string {
  return S.settings.themeNames[id];
}

function LicenseText({ text }: { text: string }) {
  const [open, setOpen] = useState(false);
  const panelId = useId();
  return (
    <div className="mt-2">
      <button
        type="button"
        aria-expanded={open}
        aria-controls={panelId}
        onClick={() => setOpen((v) => !v)}
        className={`flex items-center ${ICON_GAP.row} text-xs text-gray-500 transition-colors duration-150 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200`}
      >
        <Chevron open={open} size={12} />
        {S.settings.creditsLicenseText}
      </button>
      <pre
        id={panelId}
        hidden={!open}
        className="mt-2 max-h-64 overflow-auto whitespace-pre-wrap rounded-md bg-gray-50 px-3 py-2 font-mono text-xs leading-5 text-gray-600 dark:bg-gray-900 dark:text-gray-300"
      >
        {text}
      </pre>
    </div>
  );
}

function CreditRow({ font }: { font: FontCredit }) {
  return (
    <li className="py-3.5 first:pt-0 last:pb-0">
      <p className="text-sm font-medium">{font.family}</p>
      <dl className="mt-1 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs">
        <dt className="text-gray-500 dark:text-gray-400">{S.settings.creditsThemes}</dt>
        {/* A face no theme sets by default (IBM Plex Sans Condensed) still ships, so it is
            listed and licensed like the rest, and says so rather than leaving the line blank. */}
        <dd>
          {font.themes.length > 0
            ? font.themes.map(themeName).join(" · ")
            : S.settings.creditsNoTheme}
        </dd>
        <dt className="text-gray-500 dark:text-gray-400">{S.settings.creditsLicense}</dt>
        <dd>{font.licenseTitle}</dd>
        {/* The link goes to the type's own project, not to the npm package it reaches us
            through: "@fontsource-variable/mona-sans" is not a URL, and it is not who the licence
            credits either. How the file got here is the line under it. */}
        <dt className="text-gray-500 dark:text-gray-400">{S.settings.creditsSource}</dt>
        <dd className="min-w-0 break-all">
          <a
            href={font.upstream}
            target="_blank"
            rel="noreferrer"
            className="text-link underline-offset-2 hover:underline"
          >
            {font.upstream}
          </a>
        </dd>
        {font.source !== font.upstream && (
          <>
            <dt className="text-gray-500 dark:text-gray-400">{S.settings.creditsPackaged}</dt>
            <dd className="min-w-0 font-mono break-all">{font.source}</dd>
          </>
        )}
      </dl>
      <LicenseText text={font.licenseText} />
    </li>
  );
}

export function CreditsSection() {
  return (
    <div className="space-y-6">
      <ul className="divide-y divide-gray-100 dark:divide-gray-800/60">
        {FONT_CREDITS.map((font) => (
          <CreditRow key={font.id} font={font} />
        ))}
      </ul>
      <ThemeCredit />
    </div>
  );
}

/** The theme library's own project page, linked like a font's upstream (see ThemeCredit). */
const THEME_LIBRARY_URL = "https://github.com/lmliheng/adelie-themes";

/**
 * Where the themes come from and what licence they carry. Static words rather than a fetch: the
 * library is a directory this app reads on demand, and the page that must stay readable offline —
 * and answerable for what the app itself ships — cannot depend on it being reachable. The live
 * list of what the library holds is the Appearance page's, next to the picker.
 */
function ThemeCredit() {
  return (
    <div>
      <p className="text-sm font-medium">{S.settings.creditsThemeLibrary}</p>
      <p className="mt-1 text-xs leading-5 text-gray-500 dark:text-gray-400">
        {S.settings.creditsThemeLibraryInfo}
      </p>
      <a
        href={THEME_LIBRARY_URL}
        target="_blank"
        rel="noreferrer"
        className="text-link mt-1 inline-block text-xs break-all underline-offset-2 hover:underline"
      >
        {THEME_LIBRARY_URL}
      </a>
    </div>
  );
}