document-content-model 1.4.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +13 -8
  2. package/package.json +15 -18
package/README.md CHANGED
@@ -1,29 +1,34 @@
1
- # document-content-model
1
+ # document-schema.js
2
2
 
3
- [![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=white)](https://github.com/ExaDev/document-content-model) [![npm](https://img.shields.io/badge/npm-CB3837?logo=npm&logoColor=white)](https://www.npmjs.com/package/document-content-model) [![Release](https://img.shields.io/github/v/release/ExaDev/document-content-model)](https://github.com/ExaDev/document-content-model/releases/latest) [![CI](https://img.shields.io/github/actions/workflow/status/ExaDev/document-content-model/ci.yml?branch=main)](https://github.com/ExaDev/document-content-model/actions)
3
+ [![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=white)](https://github.com/ExaDev/document-schema.js) [![npm](https://img.shields.io/badge/npm-CB3837?logo=npm&logoColor=white)](https://www.npmjs.com/package/document-schema.js) [![Release](https://img.shields.io/github/v/release/ExaDev/document-schema.js)](https://github.com/ExaDev/document-schema.js/releases/latest) [![CI](https://img.shields.io/github/actions/workflow/status/ExaDev/document-schema.js/ci.yml?branch=main)](https://github.com/ExaDev/document-schema.js/actions)
4
4
 
5
5
  > The canonical, format-agnostic content and layout schema pivot shared by [ooxml.js](https://github.com/ExaDev/ooxml.js), [odf.js](https://github.com/ExaDev/odf.js), and [documents.js](https://github.com/ExaDev/documents.js).
6
6
 
7
7
  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`.
8
8
 
9
- It contains only [Zod](https://zod.dev) 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.
9
+ `ContentDocument` (the semantic pivot) is a discriminated union of four kinds: `wordprocessing` (docx/odt-style sections of paragraphs/runs/tables/images), `presentation` (pptx/odp-style slides of shapes), `spreadsheet` (xlsx/ods-style sheets of cells, columns, rows, and print settings), and `drawing` (odg-style pages of shapes plus vector primitives -- rect/ellipse/line/path). `ContentEmbeddedObjectSchema` lets any of the four embed another whole `ContentDocument`. `LayoutDocument` (the PDF-rendering pivot) is pages of positioned `LayoutItem`s -- `text`/`image`/`rect`/`line`/`ellipse`/`path`/`link` -- in PDF user-space coordinates, with `LayoutPathSchema` modelling a general vector path rather than only axis-aligned rectangles. `DocumentPackageSchema` is a small envelope pairing the two: `content` required, `layout` optional (it's a derived artifact, absent until something lays the content out), correlated via each item's own `sourcePath` when both are present -- a pairing this schema does not itself keep in sync or detect as stale.
10
+
11
+ It contains only [Zod](https://zod.dev) 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/embedded-object types). There is no XML, ZIP, PDF, or other binary handling here, and no `zod` dependency other than `zod` itself.
12
+
13
+ The GitHub repository is [`ExaDev/document-schema.js`](https://github.com/ExaDev/document-schema.js), matching the published npm package name; `document-content-model` (the repository's original name, kept resolving), `doc-model.js`, `doc-schema.js`, `document-schema`, and `document-model.js` republish the identical build as aliases on npmjs.org, alongside a scoped `@exadev/document-content-model` alias on GitHub Packages. A CI matrix job (`publish-aliases` in `.github/workflows/ci.yml`) rewrites `package.json`'s `name` and registry via `npm pkg set` after each release and publishes under each alias in turn -- install whichever name you already depend on.
10
14
 
11
15
  ## Usage
12
16
 
13
17
  ```ts
14
- import { ContentDocumentSchema, LayoutDocumentSchema } from 'document-content-model';
18
+ import { ContentDocumentSchema, DocumentPackageSchema, LayoutDocumentSchema } from 'document-schema.js';
15
19
 
16
20
  const content = ContentDocumentSchema.parse(someWordprocessingOrPresentationValue);
17
21
  const layout = LayoutDocumentSchema.parse(somePageLayoutValue);
22
+ const pkg = DocumentPackageSchema.parse({ formatVersion: 1, content, layout });
18
23
  ```
19
24
 
20
25
  ## Used by
21
26
 
22
- - [ooxml.js](https://github.com/ExaDev/ooxml.js) — its `readDocx`/`readPptx` return `ContentSection[]`/`ContentSlide[]` typed against this package's own schemas, not a locally-defined lookalike.
23
- - [odf.js](https://github.com/ExaDev/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.
24
- - [documents.js](https://github.com/ExaDev/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.
27
+ - [ooxml.js](https://github.com/ExaDev/ooxml.js) — its `readDocx`/`readPptx`/`readXlsxContent` return `ContentSection[]`/`ContentSlide[]`/spreadsheet `ContentSheet[]` typed against this package's own schemas, not a locally-defined lookalike.
28
+ - [odf.js](https://github.com/ExaDev/odf.js) — its ODF typed readers (`readOdt`, `readOdp`, `readOds`, `readOdg`, …) return the same shared types, so an ODF document and an OOXML document speak the identical pivot.
29
+ - [documents.js](https://github.com/ExaDev/documents.js) — the primary consumer of both `ContentDocument` and `LayoutDocument`, which it converts between via its layout engines and PDF codec, and of `DocumentPackage` as the `onDocument` side-channel value its conversion functions hand back.
25
30
 
26
- 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.
31
+ None of these three packages depend on each other for this vocabulary — each depends on `document-schema.js` (or one of its aliases above) directly, which is the whole point: one schema, not three independently-maintained, drift-prone copies.
27
32
 
28
33
  ## License
29
34
 
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "document-content-model",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "The canonical, format-agnostic content and layout schemas shared by ooxml.js, odf.js, and documents.js -- pure Zod schemas, no behaviour.",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/ExaDev/document-content-model.git"
8
+ "url": "git+https://github.com/ExaDev/document-schema.js.git"
9
9
  },
10
- "homepage": "https://github.com/ExaDev/document-content-model#readme",
10
+ "homepage": "https://github.com/ExaDev/document-schema.js#readme",
11
11
  "bugs": {
12
- "url": "https://github.com/ExaDev/document-content-model/issues"
12
+ "url": "https://github.com/ExaDev/document-schema.js/issues"
13
13
  },
14
14
  "exports": {
15
15
  ".": {
@@ -36,18 +36,6 @@
36
36
  "engines": {
37
37
  "node": ">=20"
38
38
  },
39
- "scripts": {
40
- "build": "tsdown",
41
- "prepublishOnly": "pnpm run lint && pnpm run typecheck && tsdown && publint && attw --pack",
42
- "lint": "eslint . --max-warnings 0",
43
- "typecheck": "tsc --noEmit",
44
- "test": "vitest run --project unit",
45
- "test:watch": "vitest --project unit",
46
- "test:coverage": "vitest run --project unit --coverage",
47
- "test:smoke": "tsdown && vitest run --project smoke",
48
- "prepare": "husky",
49
- "release": "semantic-release"
50
- },
51
39
  "keywords": [
52
40
  "document",
53
41
  "content-model",
@@ -61,7 +49,6 @@
61
49
  "ods"
62
50
  ],
63
51
  "license": "MIT",
64
- "packageManager": "pnpm@11.6.0",
65
52
  "dependencies": {
66
53
  "zod": "^4.4.3"
67
54
  },
@@ -84,5 +71,15 @@
84
71
  "typescript": "^6.0.3",
85
72
  "typescript-eslint": "^8.65.0",
86
73
  "vitest": "^4.1.10"
74
+ },
75
+ "scripts": {
76
+ "build": "tsdown",
77
+ "lint": "eslint . --max-warnings 0",
78
+ "typecheck": "tsc --noEmit",
79
+ "test": "vitest run --project unit",
80
+ "test:watch": "vitest --project unit",
81
+ "test:coverage": "vitest run --project unit --coverage",
82
+ "test:smoke": "tsdown && vitest run --project smoke",
83
+ "release": "semantic-release"
87
84
  }
88
- }
85
+ }