document-content-model 1.4.0 → 1.5.0

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.
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/dist/index.d.cts CHANGED
@@ -46,12 +46,12 @@ type Alignment = z.infer<typeof AlignmentSchema>;
46
46
  declare const LayoutFontSchema: z.ZodObject<{
47
47
  family: z.ZodString;
48
48
  weight: z.ZodEnum<{
49
- normal: "normal";
50
49
  bold: "bold";
50
+ normal: "normal";
51
51
  }>;
52
52
  style: z.ZodEnum<{
53
- normal: "normal";
54
53
  italic: "italic";
54
+ normal: "normal";
55
55
  }>;
56
56
  }, z.core.$strip>;
57
57
  type LayoutFont = z.infer<typeof LayoutFontSchema>;
@@ -1264,12 +1264,12 @@ declare const LayoutTextSchema: z.ZodObject<{
1264
1264
  font: z.ZodObject<{
1265
1265
  family: z.ZodString;
1266
1266
  weight: z.ZodEnum<{
1267
- normal: "normal";
1268
1267
  bold: "bold";
1268
+ normal: "normal";
1269
1269
  }>;
1270
1270
  style: z.ZodEnum<{
1271
- normal: "normal";
1272
1271
  italic: "italic";
1272
+ normal: "normal";
1273
1273
  }>;
1274
1274
  }, z.core.$strip>;
1275
1275
  sizePt: z.ZodNumber;
@@ -1445,12 +1445,12 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1445
1445
  font: z.ZodObject<{
1446
1446
  family: z.ZodString;
1447
1447
  weight: z.ZodEnum<{
1448
- normal: "normal";
1449
1448
  bold: "bold";
1449
+ normal: "normal";
1450
1450
  }>;
1451
1451
  style: z.ZodEnum<{
1452
- normal: "normal";
1453
1452
  italic: "italic";
1453
+ normal: "normal";
1454
1454
  }>;
1455
1455
  }, z.core.$strip>;
1456
1456
  sizePt: z.ZodNumber;
@@ -1584,12 +1584,12 @@ declare const LayoutPageSchema: z.ZodObject<{
1584
1584
  font: z.ZodObject<{
1585
1585
  family: z.ZodString;
1586
1586
  weight: z.ZodEnum<{
1587
- normal: "normal";
1588
1587
  bold: "bold";
1588
+ normal: "normal";
1589
1589
  }>;
1590
1590
  style: z.ZodEnum<{
1591
- normal: "normal";
1592
1591
  italic: "italic";
1592
+ normal: "normal";
1593
1593
  }>;
1594
1594
  }, z.core.$strip>;
1595
1595
  sizePt: z.ZodNumber;
@@ -1747,12 +1747,12 @@ declare const LayoutDocumentSchema: z.ZodObject<{
1747
1747
  font: z.ZodObject<{
1748
1748
  family: z.ZodString;
1749
1749
  weight: z.ZodEnum<{
1750
- normal: "normal";
1751
1750
  bold: "bold";
1751
+ normal: "normal";
1752
1752
  }>;
1753
1753
  style: z.ZodEnum<{
1754
- normal: "normal";
1755
1754
  italic: "italic";
1755
+ normal: "normal";
1756
1756
  }>;
1757
1757
  }, z.core.$strip>;
1758
1758
  sizePt: z.ZodNumber;
@@ -2271,12 +2271,12 @@ declare const DocumentPackageSchema: z.ZodObject<{
2271
2271
  font: z.ZodObject<{
2272
2272
  family: z.ZodString;
2273
2273
  weight: z.ZodEnum<{
2274
- normal: "normal";
2275
2274
  bold: "bold";
2275
+ normal: "normal";
2276
2276
  }>;
2277
2277
  style: z.ZodEnum<{
2278
- normal: "normal";
2279
2278
  italic: "italic";
2279
+ normal: "normal";
2280
2280
  }>;
2281
2281
  }, z.core.$strip>;
2282
2282
  sizePt: z.ZodNumber;
package/dist/index.d.ts CHANGED
@@ -46,12 +46,12 @@ type Alignment = z.infer<typeof AlignmentSchema>;
46
46
  declare const LayoutFontSchema: z.ZodObject<{
47
47
  family: z.ZodString;
48
48
  weight: z.ZodEnum<{
49
- normal: "normal";
50
49
  bold: "bold";
50
+ normal: "normal";
51
51
  }>;
52
52
  style: z.ZodEnum<{
53
- normal: "normal";
54
53
  italic: "italic";
54
+ normal: "normal";
55
55
  }>;
56
56
  }, z.core.$strip>;
57
57
  type LayoutFont = z.infer<typeof LayoutFontSchema>;
@@ -1264,12 +1264,12 @@ declare const LayoutTextSchema: z.ZodObject<{
1264
1264
  font: z.ZodObject<{
1265
1265
  family: z.ZodString;
1266
1266
  weight: z.ZodEnum<{
1267
- normal: "normal";
1268
1267
  bold: "bold";
1268
+ normal: "normal";
1269
1269
  }>;
1270
1270
  style: z.ZodEnum<{
1271
- normal: "normal";
1272
1271
  italic: "italic";
1272
+ normal: "normal";
1273
1273
  }>;
1274
1274
  }, z.core.$strip>;
1275
1275
  sizePt: z.ZodNumber;
@@ -1445,12 +1445,12 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1445
1445
  font: z.ZodObject<{
1446
1446
  family: z.ZodString;
1447
1447
  weight: z.ZodEnum<{
1448
- normal: "normal";
1449
1448
  bold: "bold";
1449
+ normal: "normal";
1450
1450
  }>;
1451
1451
  style: z.ZodEnum<{
1452
- normal: "normal";
1453
1452
  italic: "italic";
1453
+ normal: "normal";
1454
1454
  }>;
1455
1455
  }, z.core.$strip>;
1456
1456
  sizePt: z.ZodNumber;
@@ -1584,12 +1584,12 @@ declare const LayoutPageSchema: z.ZodObject<{
1584
1584
  font: z.ZodObject<{
1585
1585
  family: z.ZodString;
1586
1586
  weight: z.ZodEnum<{
1587
- normal: "normal";
1588
1587
  bold: "bold";
1588
+ normal: "normal";
1589
1589
  }>;
1590
1590
  style: z.ZodEnum<{
1591
- normal: "normal";
1592
1591
  italic: "italic";
1592
+ normal: "normal";
1593
1593
  }>;
1594
1594
  }, z.core.$strip>;
1595
1595
  sizePt: z.ZodNumber;
@@ -1747,12 +1747,12 @@ declare const LayoutDocumentSchema: z.ZodObject<{
1747
1747
  font: z.ZodObject<{
1748
1748
  family: z.ZodString;
1749
1749
  weight: z.ZodEnum<{
1750
- normal: "normal";
1751
1750
  bold: "bold";
1751
+ normal: "normal";
1752
1752
  }>;
1753
1753
  style: z.ZodEnum<{
1754
- normal: "normal";
1755
1754
  italic: "italic";
1755
+ normal: "normal";
1756
1756
  }>;
1757
1757
  }, z.core.$strip>;
1758
1758
  sizePt: z.ZodNumber;
@@ -2271,12 +2271,12 @@ declare const DocumentPackageSchema: z.ZodObject<{
2271
2271
  font: z.ZodObject<{
2272
2272
  family: z.ZodString;
2273
2273
  weight: z.ZodEnum<{
2274
- normal: "normal";
2275
2274
  bold: "bold";
2275
+ normal: "normal";
2276
2276
  }>;
2277
2277
  style: z.ZodEnum<{
2278
- normal: "normal";
2279
2278
  italic: "italic";
2279
+ normal: "normal";
2280
2280
  }>;
2281
2281
  }, z.core.$strip>;
2282
2282
  sizePt: z.ZodNumber;
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.0",
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
  ".": {
@@ -30,24 +30,12 @@
30
30
  "publishConfig": {
31
31
  "access": "public",
32
32
  "provenance": true,
33
- "registry": "https://registry.npmjs.org/"
33
+ "registry": "https://registry.npmjs.org"
34
34
  },
35
35
  "sideEffects": false,
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
+ }