Skip to content

The Open Standard for Generative UI

8.9 KB
Raw Blame
import type { CSSProperties } from "react";
import { FONT, MONO, useTheme, type ThemeTokens } from "../theme";

export { FONT, MONO };

export function debugStyles(t: ThemeTokens) {
  return {
    toolbar: {
      display: "flex",
      alignItems: "center",
      gap: 10,
      flexWrap: "wrap",
      flexShrink: 0,
      padding: "8px 16px",
      borderBottom: `1px solid ${t.borderSubtle}`,
      background: t.bg,
    },
    field: {
      display: "flex",
      alignItems: "center",
      gap: 6,
    },
    label: {
      color: t.fgMuted,
      fontSize: 11,
      fontWeight: 500,
    },
    select: {
      border: `1px solid ${t.controlBorder}`,
      borderRadius: 8,
      background: t.controlBg,
      color: t.fg,
      fontFamily: FONT,
      fontSize: 12,
      // The native chevron sits flush against the label otherwise, so the inline
      // end gets its own gutter; the start is padded to balance it.
      padding: "4px 24px 4px 12px",
    },
    seedInput: {
      width: 64,
      border: `1px solid ${t.controlBorder}`,
      borderRadius: 8,
      background: t.controlBg,
      color: t.fg,
      fontFamily: FONT,
      fontSize: 12,
      padding: "4px 8px",
    },
    btnGroup: {
      display: "inline-flex",
      alignItems: "stretch",
    },
    groupButton: {
      display: "inline-flex",
      alignItems: "center",
      justifyContent: "center",
      width: 28,
      height: 26,
      border: `1px solid ${t.controlBorder}`,
      background: t.controlBg,
      color: t.fgTertiary,
      cursor: "pointer",
      padding: 0,
    },
    groupButtonDisabled: {
      opacity: 0.45,
      cursor: "not-allowed",
    },
    progress: {
      color: t.fgMuted,
      fontSize: 11,
      fontFamily: MONO,
    },
    tabStrip: {
      display: "flex",
      gap: 2,
      padding: "6px 12px",
      borderBottom: `1px solid ${t.borderSubtle}`,
      flexShrink: 0,
    },
    tab: {
      border: "none",
      background: "transparent",
      color: t.fgMuted,
      fontFamily: FONT,
      fontSize: 12,
      fontWeight: 500,
      padding: "6px 8px",
      borderRadius: 8,
      cursor: "pointer",
    },
    tabActive: {
      color: t.fg,
      background: t.bgSubtle,
    },
    panelScroll: {
      overflow: "auto",
      padding: 16,
      flex: 1,
      minHeight: 0,
    },
    panelEmpty: {
      padding: 32,
      color: t.fgFaint,
      textAlign: "center",
      fontSize: 12,
    },
    metaStrip: {
      display: "flex",
      gap: 6,
      flexWrap: "wrap",
      marginBottom: 16,
    },
    tag: {
      display: "inline-flex",
      alignItems: "center",
      borderRadius: 999,
      padding: "2px 8px",
      fontSize: 11,
      fontWeight: 500,
      background: t.bgSubtle,
      color: t.fgTertiary,
    },
    tagSuccess: {
      background: t.successBg,
      color: t.success,
    },
    tagWarning: {
      background: t.warningBg,
      color: t.warning,
    },
    allClear: {
      color: t.success,
      fontWeight: 500,
      display: "flex",
      alignItems: "center",
      gap: 6,
      fontSize: 13,
    },
    errorGroup: {
      marginBottom: 20,
    },
    errorGroupTitle: {
      fontSize: 13,
      margin: "0 0 8px",
      fontWeight: 600,
    },
    count: {
      color: t.fgFaint,
      fontWeight: 400,
    },
    errorList: {
      listStyle: "none",
      margin: 0,
      padding: 0,
    },
    errorRow: {
      padding: 8,
      border: `1px solid ${t.border}`,
      borderRadius: 6,
      marginBottom: 8,
      minWidth: 0,
      overflowWrap: "anywhere",
      wordBreak: "break-word",
      whiteSpace: "pre-wrap",
    },
    errHead: {
      display: "flex",
      alignItems: "center",
      flexWrap: "wrap",
      gap: 8,
      minWidth: 0,
    },
    errComponent: {
      fontWeight: 600,
      fontFamily: MONO,
      fontSize: 12,
      overflowWrap: "anywhere",
    },
    errPath: {
      color: t.fgMuted,
      fontFamily: MONO,
      fontSize: 12,
      overflowWrap: "anywhere",
    },
    errMessage: {
      margin: "4px 0 0",
      fontSize: 12,
      overflowWrap: "anywhere",
      wordBreak: "break-word",
      whiteSpace: "pre-wrap",
    },
    errHint: {
      margin: "4px 0 0",
      fontSize: 12,
      color: t.info,
      overflowWrap: "anywhere",
      wordBreak: "break-word",
      whiteSpace: "pre-wrap",
    },
    fatalCard: {
      border: `1px solid ${t.dangerBorder}`,
      borderRadius: 8,
      padding: 16,
      color: t.danger,
      fontSize: 12,
    },
    fatalPre: {
      margin: "8px 0 0",
      fontFamily: MONO,
      whiteSpace: "pre-wrap",
    },
    renderPanel: {
      display: "flex",
      flexDirection: "column",
      flex: 1,
      minHeight: 0,
      overflow: "auto",
    },
    mockNote: {
      display: "flex",
      alignItems: "flex-start",
      gap: 6,
      padding: "8px 16px",
      color: t.info,
      background: t.infoBg,
      fontSize: 12,
    },
    renderCanvas: {
      padding: 16,
      flex: 1,
    },
    renderDetails: {
      borderTop: `1px solid ${t.borderSubtle}`,
      padding: "8px 16px",
      fontSize: 12,
      color: t.fgSecondary,
      minWidth: 0,
      overflowWrap: "anywhere",
    },
    treeHeader: {
      display: "inline-flex",
      alignItems: "center",
      gap: 6,
      border: "none",
      background: "none",
      cursor: "pointer",
      color: "inherit",
      font: "inherit",
      padding: "2px 0",
    },
    treeType: {
      fontFamily: MONO,
      fontWeight: 600,
      fontSize: 12,
    },
    treeProps: {
      margin: "0 0 0 24px",
      borderLeft: `1px solid ${t.border}`,
      paddingLeft: 10,
      minWidth: 0,
    },
    treeProp: {
      display: "flex",
      flexWrap: "wrap",
      gap: "2px 10px",
      alignItems: "baseline",
      padding: "1px 0",
      minWidth: 0,
    },
    treeDt: {
      color: t.fgMuted,
      fontFamily: MONO,
      fontSize: 11,
      flex: "0 0 auto",
      margin: 0,
    },
    treeDd: {
      margin: 0,
      minWidth: 0,
      // Own row once the remaining slot is too narrow for a readable value.
      flex: "1 1 12em",
    },
    treeScalar: {
      display: "block",
      maxWidth: "100%",
      minWidth: 0,
      fontFamily: MONO,
      fontSize: 11,
      overflowWrap: "anywhere",
      wordBreak: "break-word",
      whiteSpace: "pre-wrap",
    },
    treeExpr: {
      fontFamily: MONO,
      fontSize: 11,
      color: t.info,
    },
    treeExtra: {
      marginTop: 24,
    },
    treeExtraTitle: {
      fontSize: 13,
      margin: "0 0 8px",
    },
    treeJson: {
      fontFamily: MONO,
      fontSize: 11,
      whiteSpace: "pre-wrap",
      wordBreak: "break-word",
      margin: 0,
    },
    convergence: {
      padding: "8px 12px",
      borderRadius: 6,
      marginBottom: 16,
      fontWeight: 600,
      display: "flex",
      alignItems: "center",
      gap: 6,
      fontSize: 12,
    },
    convergenceOk: {
      background: t.successBg,
      color: t.success,
    },
    convergenceBad: {
      background: t.dangerBg,
      color: t.danger,
    },
    traceTable: {
      width: "100%",
      borderCollapse: "collapse",
      fontSize: 11,
      tableLayout: "fixed",
    },
    traceTh: {
      textAlign: "left",
      color: t.fgMuted,
      fontWeight: 500,
      padding: "2px 8px",
      borderBottom: `1px solid ${t.borderSubtle}`,
    },
    traceTd: {
      padding: "2px 8px",
      borderBottom: `1px solid ${t.borderSubtle}`,
      fontFamily: MONO,
      overflow: "hidden",
      textOverflow: "ellipsis",
    },
    rowAppeared: {
      background: t.successBg,
    },
    rowDropped: {
      background: t.dangerBg,
    },
    rootCell: {
      display: "flex",
      alignItems: "center",
      gap: 6,
    },
    helpOverlay: {
      position: "absolute",
      inset: 0,
      background: t.overlay,
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      zIndex: 5,
      padding: 24,
    },
    helpDialog: {
      background: t.bg,
      border: `1px solid ${t.border}`,
      borderRadius: 12,
      boxShadow: t.shadow,
      maxWidth: 440,
      width: "100%",
      maxHeight: "80%",
      display: "flex",
      flexDirection: "column",
      overflow: "hidden",
    },
    // Same treatment as the Inspect tray header, with the dialog's wider gutter.
    helpHeader: {
      display: "flex",
      alignItems: "center",
      justifyContent: "space-between",
      gap: 8,
      padding: "14px 20px 0",
      fontWeight: 600,
      fontSize: 14,
    },
    helpBody: {
      padding: "20px 20px 24px",
      overflowY: "auto",
      fontSize: 13,
      lineHeight: 1.55,
      fontWeight: 400,
      color: t.fgTertiary,
    },
    editorLock: {
      position: "absolute",
      bottom: 10,
      right: 10,
      background: t.bgSubtle,
      border: `1px solid ${t.border}`,
      borderRadius: 999,
      padding: "2px 10px",
      fontSize: 10,
      color: t.fgMuted,
    },
  } satisfies Record<string, CSSProperties>;
}

export function useDebugStyles() {
  return debugStyles(useTheme());
}