Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

3.8 KB
Raw Blame
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="/favicon.ico" />
    <!-- Preload is necessary because we show these images when we disconnect from the server,
    but at that point we cannot load these images from the server -->
    <link rel="preload" href="/src/assets/gradient.png" as="image" />
    <link rel="preload" href="/src/assets/noise.png" as="image" />
    <!-- Preload the fonts -->
    <link rel="preload" href="/src/fonts/Lora/Lora-VariableFont_wght.woff2" as="font" type="font/woff2" crossorigin="anonymous" />
    <link rel="preload" href="/src/fonts/PT_Sans/PTSans-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous" />
    <link rel="preload" href="/src/fonts/PT_Sans/PTSans-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous" />
    <link rel="preload" href="/src/fonts/Fira_Mono/FiraMono-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous" />
    <link rel="preload" href="/src/fonts/Fira_Mono/FiraMono-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous" />
    <link rel="preload" href="/src/fonts/Fira_Mono/FiraMono-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous" />

    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta name="description" content="a marimo app" />
    <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
    <link rel="manifest" href="/manifest.json" />

    <script data-marimo="true">
      function __resizeIframe(obj) {
        const scrollbarHeight = 20; // Max between windows, mac, and linux

        function setHeight() {
          // Guard against race condition where iframe isn't ready
          if (!obj.contentWindow?.document?.documentElement) {
            return;
          }
          const element = obj.contentWindow.document.documentElement;
          // If there is no vertical scrollbar, we don't need to resize the iframe
          if (element.scrollHeight === element.clientHeight) {
            return;
          }

          // Create a new height that includes the scrollbar height if it's visible
          const hasHorizontalScrollbar = element.scrollWidth > element.clientWidth;
          const newHeight = element.scrollHeight + (hasHorizontalScrollbar ? scrollbarHeight : 0);

          // Only update the height if it's different from the current height
          if (obj.style.height !== `${newHeight}px`) {
            obj.style.height = `${newHeight}px`;
          }
        }

        // Resize the iframe to the height of the content and bottom scrollbar height
        setHeight();

        // Resize the iframe when the content changes
        const resizeObserver = new ResizeObserver((_entries) => {
          setHeight();
        });
        // Only observe if iframe content is ready
        if (obj.contentWindow?.document?.body) {
          resizeObserver.observe(obj.contentWindow.document.body);
        }
      }
    </script>
    <marimo-filename hidden>{{ filename }}</marimo-filename>
    <!-- TODO(Trevor): Legacy, required by VS Code plugin. Remove when plugin is updated (see marimo/server/_templates/template.py) -->
    <marimo-version data-version="{{ version }}" hidden></marimo-version>
    <marimo-user-config data-config="{{ user_config }}" hidden></marimo-user-config>
    <marimo-server-token data-token="{{ server_token }}" hidden></marimo-server-token>
    <!-- /TODO -->
    <title>{{ title }}</title>
  </head>
  <body>
    <div id="root"></div>
    <script data-marimo="true">
      Object.defineProperty(window, "__MARIMO_MOUNT_CONFIG__", {
        value: Object.freeze('{{ mount_config }}'),
        writable: false,
        configurable: false,
      });
    </script>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>