@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
sources={[ mdxSource({ id, preset, root }) ]}
slug?
theme?
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 | Theme path override for this Press. New work should keep tokens and font loading under `press/ | |
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";
export default function ReportPress() {
return (
<Press
title="Transport models in dense networks"
page="a4"
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="campaign"
title="Campaign Card"
page={{ id: "campaign-card", label: "Campaign Card", width: "1080px", height: "1350px" }}
>
<Frame frameKey="cover" role="social.card">
<CampaignCard />
</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.