documents.js 1.34.0 → 1.34.2

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/dist/index.js CHANGED
@@ -1,238 +1,31 @@
1
- import { AlignmentSchema, AttributeSchema, BinaryPartSchema, BoxSchema, COLOR_BLACK, ColorSchema as LayoutColorSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PageSizeSchema, PartSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag, colorToRgbHex, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, resolveRelationships, resolveRelationships as resolveRelationships$1, rgbHexToColor, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
1
+ import { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, PackageSchema, PartSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, resolveRelationships, resolveRelationships as resolveRelationships$1, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
2
+ import { COLOR_BLACK, ContentBlockSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentSectionSchema as ContentSectionSchema$1, ContentShapeSchema, ContentSlideSchema, ContentSlideSchema as ContentSlideSchema$1, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, LAYOUT_FORMAT_VERSION, LAYOUT_FORMAT_VERSION as LAYOUT_FORMAT_VERSION$1, LayoutDocumentSchema, LayoutMetadataSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, colorToRgbHex, isContentBlock, rgbHexToColor } from "document-content-model";
2
3
  import { z } from "zod";
3
4
  import { Unzlib, inflateSync, unzlibSync, zlibSync } from "fflate";
4
- //#region src/model/geometry.ts
5
- function flipY(box, containerHeightPt) {
6
- return {
7
- xPt: box.xPt,
8
- yPt: containerHeightPt - box.yPt - box.heightPt,
9
- widthPt: box.widthPt,
10
- heightPt: box.heightPt
11
- };
12
- }
13
- //#endregion
14
- //#region src/model/style.ts
15
- const LayoutFontSchema = z.object({
16
- family: z.string(),
17
- weight: z.enum(["normal", "bold"]),
18
- style: z.enum(["normal", "italic"])
19
- });
20
- const DEFAULT_LAYOUT_FONT = {
21
- family: "Helvetica",
22
- weight: "normal",
23
- style: "normal"
24
- };
25
- //#endregion
26
- //#region src/model/layout.ts
27
- const LAYOUT_FORMAT_VERSION = 1;
28
- const LayoutTextSchema = z.object({
29
- kind: z.literal("text"),
30
- text: z.string(),
31
- xPt: z.number(),
32
- yPt: z.number(),
33
- font: LayoutFontSchema,
34
- sizePt: z.number().positive(),
35
- color: LayoutColorSchema,
36
- widthPt: z.number().nonnegative().optional(),
37
- rotationDeg: z.number().optional(),
38
- underline: z.boolean().optional()
39
- });
40
- const LayoutImageSchema = z.object({
41
- kind: z.literal("image"),
42
- imageId: z.string(),
43
- xPt: z.number(),
44
- yPt: z.number(),
45
- widthPt: z.number().positive(),
46
- heightPt: z.number().positive(),
47
- rotationDeg: z.number().optional()
48
- });
49
- const LayoutRectSchema = z.object({
50
- kind: z.literal("rect"),
51
- xPt: z.number(),
52
- yPt: z.number(),
53
- widthPt: z.number().nonnegative(),
54
- heightPt: z.number().nonnegative(),
55
- fill: LayoutColorSchema.optional(),
56
- stroke: z.object({
57
- color: LayoutColorSchema,
58
- widthPt: z.number().positive()
59
- }).optional()
60
- });
61
- const LayoutLineSchema = z.object({
62
- kind: z.literal("line"),
63
- x1Pt: z.number(),
64
- y1Pt: z.number(),
65
- x2Pt: z.number(),
66
- y2Pt: z.number(),
67
- color: LayoutColorSchema,
68
- widthPt: z.number().positive()
69
- });
70
- const LayoutEllipseSchema = z.object({
71
- kind: z.literal("ellipse"),
72
- xPt: z.number(),
73
- yPt: z.number(),
74
- widthPt: z.number().positive(),
75
- heightPt: z.number().positive(),
76
- fill: LayoutColorSchema.optional(),
77
- stroke: z.object({
78
- color: LayoutColorSchema,
79
- widthPt: z.number().positive()
80
- }).optional()
81
- });
82
- const LayoutLinkSchema = z.object({
83
- kind: z.literal("link"),
84
- uri: z.string(),
85
- xPt: z.number(),
86
- yPt: z.number(),
87
- widthPt: z.number().nonnegative(),
88
- heightPt: z.number().nonnegative()
89
- });
90
- const LayoutItemSchema = z.discriminatedUnion("kind", [
91
- LayoutTextSchema,
92
- LayoutImageSchema,
93
- LayoutRectSchema,
94
- LayoutLineSchema,
95
- LayoutEllipseSchema,
96
- LayoutLinkSchema
97
- ]);
98
- const LayoutPageSchema = z.object({
99
- widthPt: z.number().positive(),
100
- heightPt: z.number().positive(),
101
- items: z.array(LayoutItemSchema),
102
- notes: z.string().optional()
103
- });
104
- const LayoutImageAssetSchema = z.object({
105
- format: z.enum(["png", "jpeg"]),
106
- base64: z.string(),
107
- widthPx: z.number().int().positive(),
108
- heightPx: z.number().int().positive()
109
- });
110
- const LayoutMetadataSchema = z.object({
111
- title: z.string().optional(),
112
- author: z.string().optional(),
113
- subject: z.string().optional(),
114
- keywords: z.array(z.string()).optional(),
115
- creator: z.string().optional(),
116
- producer: z.string().optional(),
117
- createdIso: z.string().optional(),
118
- modifiedIso: z.string().optional()
119
- });
120
- const LayoutDocumentSchema = z.object({
121
- formatVersion: z.literal(1),
122
- metadata: LayoutMetadataSchema,
123
- pages: z.array(LayoutPageSchema),
124
- images: z.record(z.string(), LayoutImageAssetSchema)
125
- });
126
- //#endregion
127
5
  //#region src/model/content.ts
128
6
  const CONTENT_FORMAT_VERSION = 1;
129
- const ContentRunSchema = z.object({
130
- text: z.string(),
131
- bold: z.boolean().optional(),
132
- italic: z.boolean().optional(),
133
- underline: z.boolean().optional(),
134
- strike: z.boolean().optional(),
135
- fontFamily: z.string().optional(),
136
- sizePt: z.number().positive().optional(),
137
- color: LayoutColorSchema.optional(),
138
- hyperlink: z.string().optional()
139
- });
140
- const ContentListMembershipSchema = z.object({
141
- numId: z.string(),
142
- level: z.number().int().nonnegative()
143
- });
144
- const ContentParagraphSchema = z.object({
145
- kind: z.literal("paragraph"),
146
- runs: z.array(ContentRunSchema),
147
- styleId: z.string().optional(),
148
- alignment: AlignmentSchema.optional(),
149
- list: ContentListMembershipSchema.optional(),
150
- spacingBeforePt: z.number().optional(),
151
- spacingAfterPt: z.number().optional(),
152
- lineSpacing: z.number().positive().optional(),
153
- indentLeftPt: z.number().optional(),
154
- indentFirstLinePt: z.number().optional()
155
- });
156
- const ContentImageBlockSchema = z.object({
157
- kind: z.literal("image"),
158
- format: z.enum(["png", "jpeg"]),
159
- base64: z.string(),
160
- widthPt: z.number().positive(),
161
- heightPt: z.number().positive(),
162
- altText: z.string().optional()
163
- });
164
- const ContentPageBreakSchema = z.object({ kind: z.literal("pageBreak") });
165
- function isRecord(value) {
166
- return typeof value === "object" && value !== null && !Array.isArray(value);
167
- }
168
- function isContentRun(value) {
169
- return isRecord(value) && typeof value.text === "string";
170
- }
171
- function isContentTableCell(value) {
172
- return isRecord(value) && Array.isArray(value.blocks) && value.blocks.every(isContentBlock);
173
- }
174
- function isContentTableRow(value) {
175
- return isRecord(value) && Array.isArray(value.cells) && value.cells.every(isContentTableCell) && (value.heightPt === void 0 || typeof value.heightPt === "number");
176
- }
177
- function isContentBlock(value) {
178
- if (!isRecord(value)) return false;
179
- const kind = value.kind;
180
- if (kind === "paragraph") return Array.isArray(value.runs) && value.runs.every(isContentRun);
181
- if (kind === "image") return (value.format === "png" || value.format === "jpeg") && typeof value.base64 === "string" && typeof value.widthPt === "number" && typeof value.heightPt === "number";
182
- if (kind === "pageBreak") return true;
183
- if (kind === "table") return Array.isArray(value.rows) && value.rows.every(isContentTableRow) && Array.isArray(value.columnWidthsPt) && value.columnWidthsPt.every((w) => typeof w === "number");
184
- return false;
185
- }
186
- const ContentBlockSchema = z.custom(isContentBlock);
187
- const ContentTableCellSchema = z.object({
188
- blocks: z.array(ContentBlockSchema),
189
- colSpan: z.number().int().positive().optional(),
190
- rowSpan: z.number().int().positive().optional(),
191
- background: LayoutColorSchema.optional()
192
- });
193
- const ContentTableRowSchema = z.object({
194
- cells: z.array(ContentTableCellSchema),
195
- heightPt: z.number().positive().optional()
196
- });
197
- const ContentTableSchema = z.object({
198
- kind: z.literal("table"),
199
- rows: z.array(ContentTableRowSchema),
200
- columnWidthsPt: z.array(z.number().positive())
201
- });
202
- const ContentSectionSchema = z.object({
203
- pageSize: PageSizeSchema,
204
- margins: MarginsSchema,
205
- blocks: z.array(ContentBlockSchema)
206
- });
207
- const ContentShapeSchema = z.object({
208
- name: z.string().optional(),
209
- frame: BoxSchema,
210
- rotationDeg: z.number().optional(),
211
- insetLeftPt: z.number().nonnegative(),
212
- insetTopPt: z.number().nonnegative(),
213
- insetRightPt: z.number().nonnegative(),
214
- insetBottomPt: z.number().nonnegative(),
215
- fontScale: z.number().positive().optional(),
216
- lineSpacingReduction: z.number().nonnegative().optional(),
217
- blocks: z.array(ContentBlockSchema)
218
- });
219
- const ContentSlideSchema = z.object({
220
- size: PageSizeSchema,
221
- shapes: z.array(ContentShapeSchema),
222
- notes: z.string()
223
- });
224
7
  const ContentDocumentSchema = z.discriminatedUnion("kind", [z.object({
225
8
  kind: z.literal("wordprocessing"),
226
9
  formatVersion: z.literal(1),
227
10
  metadata: LayoutMetadataSchema,
228
- sections: z.array(ContentSectionSchema)
11
+ sections: z.array(ContentSectionSchema$1)
229
12
  }), z.object({
230
13
  kind: z.literal("presentation"),
231
14
  formatVersion: z.literal(1),
232
15
  metadata: LayoutMetadataSchema,
233
- slides: z.array(ContentSlideSchema)
16
+ slides: z.array(ContentSlideSchema$1)
234
17
  })]);
235
18
  //#endregion
19
+ //#region src/model/geometry.ts
20
+ function flipY(box, containerHeightPt) {
21
+ return {
22
+ xPt: box.xPt,
23
+ yPt: containerHeightPt - box.yPt - box.heightPt,
24
+ widthPt: box.widthPt,
25
+ heightPt: box.heightPt
26
+ };
27
+ }
28
+ //#endregion
236
29
  //#region src/model/bytes.ts
237
30
  const ZIP_LOCAL_FILE_HEADER = [
238
31
  80,
@@ -6563,7 +6356,7 @@ function readPdf(bytes, options) {
6563
6356
  return readPage(pageDict, resolver, fontResolver, images, imageIdCache, sink);
6564
6357
  });
6565
6358
  return {
6566
- formatVersion: 1,
6359
+ formatVersion: LAYOUT_FORMAT_VERSION$1,
6567
6360
  metadata: readMetadata(doc.trailer, resolver),
6568
6361
  pages,
6569
6362
  images
@@ -7361,7 +7154,7 @@ function convertWordprocessingToLayout(doc, options) {
7361
7154
  const pages = [];
7362
7155
  for (const section of doc.sections) paginateSection(section, options.measurer, images, pages);
7363
7156
  return {
7364
- formatVersion: 1,
7157
+ formatVersion: LAYOUT_FORMAT_VERSION$1,
7365
7158
  metadata: doc.metadata,
7366
7159
  pages,
7367
7160
  images
@@ -7512,7 +7305,7 @@ function convertPresentationToLayout(doc, options) {
7512
7305
  const images = {};
7513
7306
  const pages = doc.slides.map((slide) => convertSlide(slide, options.measurer, images));
7514
7307
  return {
7515
- formatVersion: 1,
7308
+ formatVersion: LAYOUT_FORMAT_VERSION$1,
7516
7309
  metadata: doc.metadata,
7517
7310
  pages,
7518
7311
  images
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "documents.js",
3
- "version": "1.34.0",
3
+ "version": "1.34.2",
4
4
  "description": "Bidirectional docx/pptx <-> PDF conversion and a read+write editable OOXML document model, built on ooxml.js and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -64,6 +64,7 @@
64
64
  "license": "MIT",
65
65
  "packageManager": "pnpm@11.6.0",
66
66
  "dependencies": {
67
+ "document-content-model": "^1.0.0",
67
68
  "fflate": "^0.8.3",
68
69
  "ooxml.js": "^2.0.0",
69
70
  "zod": "^4.4.3"