Skip to content

Repository files navigation

document-content-model

GitHub npm Release CI

The canonical, format-agnostic content and layout schema pivot shared by ooxml.js, odf.js, and documents.js.

Both ooxml.js and documents.js independently arrived at the same content vocabulary -- paragraphs, runs, tables, images, shapes, slides -- because documents.js's docx/pptx-to-PDF pipeline needed a richer model than ooxml.js's own readers originally produced, and that model was later ported back into ooxml.js itself. The result was two field-identical copies maintained in two places. This package is the fix: one schema, imported by every format package instead of redefined by each. It also sidesteps a circular dependency that would otherwise appear once odf.js exists, since documents.js depends on both ooxml.js and odf.js.

It contains only Zod schemas, their inferred types, and a handful of trivial schema-attached helpers (hex-colour conversion, a recursive structural type guard for the mutually-recursive table/block types). There is no XML, ZIP, PDF, or other binary handling here, and no zod dependency other than zod itself.

Usage

import { ContentDocumentSchema, LayoutDocumentSchema } from 'document-content-model';

const content = ContentDocumentSchema.parse(someWordprocessingOrPresentationValue);
const layout = LayoutDocumentSchema.parse(somePageLayoutValue);

Used by

  • ooxml.js — its readDocx/readPptx return ContentSection[]/ContentSlide[] typed against this package's own schemas, not a locally-defined lookalike.
  • odf.js — its ODF typed readers (readOdt, readOdp, readOdg, …) return the same shared types, so an ODF document and an OOXML document speak the identical pivot.
  • documents.js — the primary consumer of both ContentDocument (the semantic pivot) and LayoutDocument (the PDF-rendering pivot), which it converts between via its layout engines and PDF codec.

None of these three packages depend on each other for this vocabulary — each depends on document-content-model directly, which is the whole point: one schema, not three independently-maintained, drift-prone copies.

License

MIT

About

The canonical, format-agnostic content and layout schema pivot shared by ooxml.js, odf.js, and documents.js.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages