Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

2.9 KB
Raw Blame
/**
 * Same-origin Integrations iframe theme bridge.
 *
 * Iframes do not inherit CSS custom properties from AppShell. Copy only the
 * reviewed visual tokens needed by the generated Integrations resource so its
 * Settings-like content follows the active shell preset/accent dynamically.
 */
export const INTEGRATION_FRAME_TOKEN_MAP = [
  ["--feature-padding", "--feature-padding"],
  ["--feature-gap", "--feature-gap"],
  ["--feature-sidebar-width", "--feature-sidebar-width"],
  ["--ui-control-height", "--ui-control-height"],
  ["--ui-control-padding", "--ui-control-padding"],
  ["--text", "--text"],
  ["--text-dim", "--text-dim"],
  ["--text-faint", "--text-faint"],
  ["--sep", "--sep"],
  ["--sep-strong", "--sep-strong"],
  ["--os-accent", "--accent"],
  ["--accent-text", "--accent-text"],
  ["--grouped", "--grouped"],
  ["--fill", "--fill"],
  ["--fill2", "--fill2"],
  ["--window-bg", "--window-bg"],
  ["--surface", "--surface"],
  ["--field", "--field"],
  ["--hover", "--hover"],
  ["--hover-strong", "--hover-strong"],
  ["--inset", "--inset"],
  ["--shadow-pop", "--shadow-pop"],
  ["--warning", "--warning"],
  ["--info", "--info"],
  ["--destructive-text", "--destructive-text"],
  ["--sidebar", "--sidebar"],
  ["--radius", "--radius"],
  ["--blur", "--blur"],
  ["--background", "--background"],
  ["--foreground", "--foreground"],
  ["--card", "--card"],
  ["--primary", "--primary"],
  ["--primary-foreground", "--primary-foreground"],
  ["--secondary", "--secondary"],
  ["--secondary-foreground", "--secondary-foreground"],
  ["--muted", "--muted"],
  ["--muted-foreground", "--muted-foreground"],
  ["--border", "--border"],
  ["--input", "--input"],
  ["--font-family", "--shell-font"],
] as const;

export type IntegrationTokenReader = (name: string) => string;

export function integrationFrameTokens(read: IntegrationTokenReader): Record<string, string> {
  return Object.fromEntries(
    INTEGRATION_FRAME_TOKEN_MAP
      .map(([local, shell]) => [local, read(shell).trim()] as const)
      .filter(([, value]) => value.length > 0),
  );
}

export function syncIntegrationFrameTokens(frame: HTMLIFrameElement): void {
  try {
    const target = frame.contentDocument?.documentElement;
    if (!target) return;
    const source = getComputedStyle(document.documentElement);
    const values = integrationFrameTokens((name) => source.getPropertyValue(name));
    for (const [name, value] of Object.entries(values)) target.style.setProperty(name, value);
    if (source.fontSize) target.style.fontSize = source.fontSize;
    target.dataset.shell = document.getElementById("main-content")?.dataset.shell ?? "macos";
    const theme = document.documentElement.dataset.theme;
    if (theme === "light" || theme === "dark") target.dataset.theme = theme;
    else target.removeAttribute("data-theme");
  } catch {
    // The production manager is same-origin. Fail closed/no-op if an embedding
    // context changes that contract rather than attempting cross-origin access.
  }
}