@open-press/core
Press
A single document. <Press> declares its title, page geometry, sources, source root, and a React tree of Frames + utilities underneath it. Projects that follow folder conventions export a single Press from press/<slug>/press.tsx.
The <Press> component defines the core configuration, content sources, and component structure of a single document. The engine uses this declaration to establish isolated document boundaries within the Workspace.
1.0 Contract: The system relies on the press/*/press.tsx folder convention to discover publications. Each entry file must have a default export that returns a single <Press> instance, and the slug must match the folder name.
Configures and encapsulates the context, layout, and data sources for a single document. Serves as the host for `Frame`s and utility components during rendering.
import { Press } from "@open-press/core"; <Press
title="..."
page="a4" | "social-square" | "slide-16-9" | PageGeometry
theme={documentTheme | slideTheme}
sources={[ mdxSource({ id, preset, root }) ]}
slug?
componentsDir?
mediaDir?
>
{/* Frames + Manuscript Utilities */}
</Press> Metadata & Routing
| Name | Type | Default | Description |
|---|---|---|---|
title required | string | Full document name. Automatically bound to HTML ` | |
slug | string | URL route and output directory identifier. Automatically inferred from the outer directory name by default (e.g., `press/report` corresponds to `report`). |
Resource Registration
| Name | Type | Default | Description |
|---|---|---|---|
page required | "a4" | "social-square" | "slide-16-9" | PageGeometry | Per-Press page geometry. Use generic presets for common formats, or pass a custom `{ id, label, width, height }` object for project-specific sizes. The exporter compiles the resolved geometry into `--openpress-page-*` CSS variables. | |
sources required | SourceRegistration[] | List of data sources initialized by `mdxSource()`. The `id`s defined within are consumed by ` | |
theme | string | DefinedDocumentTheme | DefinedSlideTheme | DefinedBareTheme | Theme object or theme path override for this Press. Page-based Presses should pass `defineDocumentTheme()`. Slide Presses should pass `defineSlideTheme()`. A string path is still supported when pointing to a non-default theme directory. | |
componentsDir | string | string[] | Physical directory for auto-loaded MDX components. Defaults to `./components`. Components in the directory can be used in MDX without an `import`. | |
mediaDir | string | string[] | Local media files directory. Defaults to `./media`. | |
children required | ReactNode | The tree structure of ``s and utility components (like ` |
Example: Declaring a Single Document
import { Press, Frame } from "@open-press/core";
import { mdxSource } from "@open-press/core/mdx";
import { Sections, Toc } from "@open-press/core/manuscript";
import { defineDocumentTheme } from "@open-press/core/theme";
const documentTheme = defineDocumentTheme({
name: "Transport Report",
colors: { paper: "#ffffff", ink: "#16161d", accent: "#0d5f89" },
typography: {
heading: { font: "serif", size: "28pt", lineHeight: 1.18, color: "ink" },
body: { font: "body", size: "10.5pt", lineHeight: 1.7, color: "ink" },
},
});
export default function ReportPress() {
return (
<Press
title="Transport models in dense networks"
page="a4"
theme={documentTheme}
sources={[
mdxSource({ id: "story", preset: "section-folders", root: "report/chapters" }),
]}
>
<Frame frameKey="cover" role="document.cover">
<Cover />
</Frame>
<Toc source="story" maxLevel={2} />
<Sections source="story" />
</Press>
);
}Example: Custom Project Geometry
<Press
slug="field-guide"
title="Field Guide"
page={{ id: "field-guide-card", label: "Field Guide Card", width: "148mm", height: "210mm" }}
theme={documentTheme}
>
<Frame frameKey="cover" role="document.cover">
<FieldGuideCover />
</Frame>
</Press> Runtime Contract and Constraints
The engine adheres to the following invariants when processing <Press>:
- Single Root Rule: All visible and structural content of the document must be descendants of a single
<Press>. - Configuration Consistency: Document settings are entirely encapsulated in props; there are no parallel frontend config files.
- Order Constraints: The order of top-level components in the tree structure (like cover, TOC, body paragraphs) directly corresponds to the output page order.
- Stateless Rendering: The rendering phase utilizes multiple passes (calculating space, arranging blocks, etc.); developers must not trigger side effects (like network reads/writes, random number generation, or cache operations) within the component tree.