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