document-content-model 1.1.0 → 1.2.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/dist/index.js CHANGED
@@ -152,6 +152,15 @@ function isContentTableCell(value) {
152
152
  function isContentTableRow(value) {
153
153
  return isRecord(value) && Array.isArray(value.cells) && value.cells.every(isContentTableCell) && (value.heightPt === void 0 || typeof value.heightPt === "number");
154
154
  }
155
+ function isContentEmbeddedObjectKind(value) {
156
+ return value === "formula" || value === "wordprocessing" || value === "presentation" || value === "spreadsheet" || value === "drawing";
157
+ }
158
+ function isContentEmbeddedObject(value) {
159
+ return isRecord(value) && isContentEmbeddedObjectKind(value.objectKind) && BoxSchema.safeParse(value.frame).success && ContentDocumentSchema.safeParse(value.document).success;
160
+ }
161
+ function isContentEmbeddedObjectBlock(value) {
162
+ return isRecord(value) && value.kind === "embeddedObject" && isContentEmbeddedObject(value);
163
+ }
155
164
  function isContentBlock(value) {
156
165
  if (!isRecord(value)) return false;
157
166
  const kind = value.kind;
@@ -159,9 +168,12 @@ function isContentBlock(value) {
159
168
  if (kind === "image") return (value.format === "png" || value.format === "jpeg") && typeof value.base64 === "string" && typeof value.widthPt === "number" && typeof value.heightPt === "number";
160
169
  if (kind === "pageBreak") return true;
161
170
  if (kind === "table") return Array.isArray(value.rows) && value.rows.every(isContentTableRow) && Array.isArray(value.columnWidthsPt) && value.columnWidthsPt.every((w) => typeof w === "number");
171
+ if (kind === "embeddedObject") return isContentEmbeddedObject(value);
162
172
  return false;
163
173
  }
164
174
  const ContentBlockSchema = z.custom(isContentBlock);
175
+ const ContentEmbeddedObjectSchema = z.custom(isContentEmbeddedObject);
176
+ const ContentEmbeddedObjectBlockSchema = z.custom(isContentEmbeddedObjectBlock);
165
177
  const ContentTableCellSchema = z.object({
166
178
  blocks: z.array(ContentBlockSchema),
167
179
  colSpan: z.number().int().positive().optional(),
@@ -201,18 +213,192 @@ const ContentSlideSchema = z.object({
201
213
  shapes: z.array(ContentShapeSchema),
202
214
  notes: z.string()
203
215
  });
204
- const CONTENT_FORMAT_VERSION = 1;
205
- const ContentDocumentSchema = z.discriminatedUnion("kind", [z.object({
206
- kind: z.literal("wordprocessing"),
207
- formatVersion: z.literal(1),
208
- metadata: LayoutMetadataSchema,
209
- sections: z.array(ContentSectionSchema)
216
+ const ContentCellValueSchema = z.discriminatedUnion("kind", [
217
+ z.object({
218
+ kind: z.literal("number"),
219
+ value: z.number()
220
+ }),
221
+ z.object({
222
+ kind: z.literal("percentage"),
223
+ value: z.number()
224
+ }),
225
+ z.object({
226
+ kind: z.literal("currency"),
227
+ value: z.number(),
228
+ currency: z.string().optional()
229
+ }),
230
+ z.object({
231
+ kind: z.literal("boolean"),
232
+ value: z.boolean()
233
+ }),
234
+ z.object({
235
+ kind: z.literal("date"),
236
+ value: z.string()
237
+ }),
238
+ z.object({
239
+ kind: z.literal("time"),
240
+ value: z.string()
241
+ }),
242
+ z.object({
243
+ kind: z.literal("string"),
244
+ value: z.string()
245
+ }),
246
+ z.object({
247
+ kind: z.literal("error"),
248
+ value: z.string()
249
+ }),
250
+ z.object({ kind: z.literal("empty") })
251
+ ]);
252
+ const ContentSheetCellSchema = z.object({
253
+ row: z.number().int().nonnegative(),
254
+ column: z.number().int().nonnegative(),
255
+ value: ContentCellValueSchema,
256
+ formula: z.string().optional(),
257
+ displayText: z.string(),
258
+ runs: z.array(ContentRunSchema).optional(),
259
+ colSpan: z.number().int().positive().optional(),
260
+ rowSpan: z.number().int().positive().optional()
261
+ });
262
+ const ContentSheetColumnSchema = z.object({
263
+ index: z.number().int().nonnegative(),
264
+ widthPt: z.number().nonnegative(),
265
+ hidden: z.boolean().optional()
266
+ });
267
+ const ContentSheetRowSchema = z.object({
268
+ index: z.number().int().nonnegative(),
269
+ heightPt: z.number().nonnegative(),
270
+ hidden: z.boolean().optional()
271
+ });
272
+ const ContentSheetPrintRangeSchema = z.object({
273
+ startRow: z.number().int().nonnegative(),
274
+ startColumn: z.number().int().nonnegative(),
275
+ endRow: z.number().int().nonnegative(),
276
+ endColumn: z.number().int().nonnegative()
277
+ });
278
+ const ContentSheetRepeatRangeSchema = z.object({
279
+ start: z.number().int().nonnegative(),
280
+ end: z.number().int().nonnegative()
281
+ });
282
+ const ContentSheetPrintSettingsSchema = z.object({
283
+ pageSize: PageSizeSchema,
284
+ margins: MarginsSchema,
285
+ printRange: ContentSheetPrintRangeSchema.optional(),
286
+ scale: z.number().positive().optional(),
287
+ fitToPages: z.object({
288
+ width: z.number().int().positive(),
289
+ height: z.number().int().positive()
290
+ }).optional(),
291
+ repeatRows: ContentSheetRepeatRangeSchema.optional(),
292
+ repeatColumns: ContentSheetRepeatRangeSchema.optional(),
293
+ gridlines: z.boolean(),
294
+ headers: z.boolean(),
295
+ pageOrder: z.enum(["downThenOver", "overThenDown"]),
296
+ manualBreaks: z.object({
297
+ rows: z.array(z.number().int().nonnegative()),
298
+ columns: z.array(z.number().int().nonnegative())
299
+ }).optional()
300
+ });
301
+ const ContentSheetImageSchema = ContentImageBlockSchema.extend({
302
+ anchorRow: z.number().int().nonnegative(),
303
+ anchorColumn: z.number().int().nonnegative(),
304
+ offsetXPt: z.number(),
305
+ offsetYPt: z.number()
306
+ });
307
+ const ContentSheetSchema = z.object({
308
+ name: z.string(),
309
+ cells: z.array(ContentSheetCellSchema),
310
+ columns: z.array(ContentSheetColumnSchema),
311
+ rows: z.array(ContentSheetRowSchema),
312
+ images: z.array(ContentSheetImageSchema),
313
+ printSettings: ContentSheetPrintSettingsSchema,
314
+ embeddedObjects: z.array(ContentEmbeddedObjectSchema).optional()
315
+ });
316
+ const ContentStrokeSchema = z.object({
317
+ color: ColorSchema,
318
+ widthPt: z.number().positive()
319
+ });
320
+ const ContentPathPointSchema = z.object({
321
+ xPt: z.number(),
322
+ yPt: z.number()
323
+ });
324
+ const ContentPathSegmentSchema = z.discriminatedUnion("kind", [z.object({
325
+ kind: z.literal("line"),
326
+ to: ContentPathPointSchema
210
327
  }), z.object({
211
- kind: z.literal("presentation"),
212
- formatVersion: z.literal(1),
213
- metadata: LayoutMetadataSchema,
214
- slides: z.array(ContentSlideSchema)
328
+ kind: z.literal("cubic"),
329
+ control1: ContentPathPointSchema,
330
+ control2: ContentPathPointSchema,
331
+ to: ContentPathPointSchema
215
332
  })]);
333
+ const ContentSubpathSchema = z.object({
334
+ start: ContentPathPointSchema,
335
+ segments: z.array(ContentPathSegmentSchema),
336
+ closed: z.boolean()
337
+ });
338
+ const ContentVectorSchema = z.discriminatedUnion("kind", [
339
+ z.object({
340
+ kind: z.literal("rect"),
341
+ frame: BoxSchema,
342
+ fill: ColorSchema.optional(),
343
+ stroke: ContentStrokeSchema.optional(),
344
+ sourcePath: z.string().optional()
345
+ }),
346
+ z.object({
347
+ kind: z.literal("ellipse"),
348
+ frame: BoxSchema,
349
+ fill: ColorSchema.optional(),
350
+ stroke: ContentStrokeSchema.optional(),
351
+ sourcePath: z.string().optional()
352
+ }),
353
+ z.object({
354
+ kind: z.literal("line"),
355
+ from: ContentPathPointSchema,
356
+ to: ContentPathPointSchema,
357
+ stroke: ContentStrokeSchema,
358
+ sourcePath: z.string().optional()
359
+ }),
360
+ z.object({
361
+ kind: z.literal("path"),
362
+ frame: BoxSchema,
363
+ subpaths: z.array(ContentSubpathSchema),
364
+ fill: ColorSchema.optional(),
365
+ fillRule: z.enum(["nonzero", "evenodd"]).optional(),
366
+ stroke: ContentStrokeSchema.optional(),
367
+ sourcePath: z.string().optional()
368
+ })
369
+ ]);
370
+ const ContentDrawPageSchema = z.object({
371
+ size: PageSizeSchema,
372
+ shapes: z.array(ContentShapeSchema),
373
+ vectors: z.array(ContentVectorSchema)
374
+ });
375
+ const CONTENT_FORMAT_VERSION = 1;
376
+ const ContentDocumentSchema = z.discriminatedUnion("kind", [
377
+ z.object({
378
+ kind: z.literal("wordprocessing"),
379
+ formatVersion: z.literal(1),
380
+ metadata: LayoutMetadataSchema,
381
+ sections: z.array(ContentSectionSchema)
382
+ }),
383
+ z.object({
384
+ kind: z.literal("presentation"),
385
+ formatVersion: z.literal(1),
386
+ metadata: LayoutMetadataSchema,
387
+ slides: z.array(ContentSlideSchema)
388
+ }),
389
+ z.object({
390
+ kind: z.literal("spreadsheet"),
391
+ formatVersion: z.literal(1),
392
+ metadata: LayoutMetadataSchema,
393
+ sheets: z.array(ContentSheetSchema)
394
+ }),
395
+ z.object({
396
+ kind: z.literal("drawing"),
397
+ formatVersion: z.literal(1),
398
+ metadata: LayoutMetadataSchema,
399
+ pages: z.array(ContentDrawPageSchema)
400
+ })
401
+ ]);
216
402
  //#endregion
217
403
  //#region src/layout.ts
218
404
  const LAYOUT_FORMAT_VERSION = 1;
@@ -311,4 +497,4 @@ const LayoutDocumentSchema = z.object({
311
497
  images: z.record(z.string(), LayoutImageAssetSchema)
312
498
  });
313
499
  //#endregion
314
- export { AlignmentSchema, BoxSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, ColorSchema, ContentBlockSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentListMembershipSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, LAYOUT_FORMAT_VERSION, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFontSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutItemSchema, LayoutLineSchema, LayoutLinkSchema, LayoutMetadataSchema, LayoutPageSchema, LayoutRectSchema, LayoutTextSchema, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, colorToRgbHex, isContentBlock, rgbHexToColor };
500
+ export { AlignmentSchema, BoxSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, ColorSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentDrawPageSchema, ContentEmbeddedObjectBlockSchema, ContentEmbeddedObjectSchema, ContentImageBlockSchema, ContentListMembershipSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetImageSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DEFAULT_LAYOUT_FONT, LAYOUT_FORMAT_VERSION, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFontSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutItemSchema, LayoutLineSchema, LayoutLinkSchema, LayoutMetadataSchema, LayoutPageSchema, LayoutRectSchema, LayoutTextSchema, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, colorToRgbHex, isContentBlock, rgbHexToColor };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-content-model",
3
- "version": "1.1.0",
3
+ "version": "1.2.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": {