document-model.js 3.3.0 → 4.1.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.
Files changed (47) hide show
  1. package/README.md +141 -30
  2. package/dist/codec.d.cts +2 -7
  3. package/dist/codec.d.ts +2 -7
  4. package/dist/construct-CdQuI9f5.d.cts +204 -0
  5. package/dist/construct-CdQuI9f5.d.ts +204 -0
  6. package/dist/construct.cjs +106 -0
  7. package/dist/construct.d.cts +2 -0
  8. package/dist/construct.d.ts +2 -0
  9. package/dist/construct.js +93 -0
  10. package/dist/content-BN0PWqpt.d.cts +2393 -0
  11. package/dist/content-CiZf6Fqn.d.ts +2393 -0
  12. package/dist/content-json-schema-defs.cjs +1227 -0
  13. package/dist/content-json-schema-defs.js +1227 -0
  14. package/dist/content.cjs +1 -7
  15. package/dist/content.d.cts +2 -2354
  16. package/dist/content.d.ts +2 -2354
  17. package/dist/content.js +1 -7
  18. package/dist/definitions.cjs +109 -0
  19. package/dist/definitions.d.cts +115 -0
  20. package/dist/definitions.d.ts +115 -0
  21. package/dist/definitions.js +99 -0
  22. package/dist/index.cjs +60 -18
  23. package/dist/index.d.cts +8 -6
  24. package/dist/index.d.ts +8 -6
  25. package/dist/index.js +7 -5
  26. package/dist/package-node-BiUEzIzl.d.cts +456 -0
  27. package/dist/package-node-DLUobcDQ.d.ts +456 -0
  28. package/dist/package-node.cjs +133 -0
  29. package/dist/package-node.d.cts +2 -0
  30. package/dist/package-node.d.ts +2 -0
  31. package/dist/package-node.js +102 -0
  32. package/dist/package.cjs +40 -7
  33. package/dist/package.d.cts +497 -755
  34. package/dist/package.d.ts +497 -755
  35. package/dist/package.js +42 -8
  36. package/dist/schema-io.cjs +55 -25
  37. package/dist/schema-io.d.cts +13 -11
  38. package/dist/schema-io.d.ts +13 -11
  39. package/dist/schema-io.js +54 -25
  40. package/package.json +2 -2
  41. package/schemas/content-document.schema.json +1813 -68
  42. package/schemas/document-package.schema.json +3528 -30
  43. package/dist/layout.cjs +0 -150
  44. package/dist/layout.d.cts +0 -684
  45. package/dist/layout.d.ts +0 -684
  46. package/dist/layout.js +0 -136
  47. package/schemas/layout-document.schema.json +0 -760
@@ -0,0 +1,102 @@
1
+ import { ConstructDescriptorSchema } from "./construct.js";
2
+ import { ContentBlockSchema, ContentDrawPageSchema, ContentEmbeddedObjectSchema, ContentFormulaSchema, ContentListMembershipSchema, ContentParagraphSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetImageSchema, ContentSheetSchema, ContentSlideSchema, ContentVectorSchema } from "./content.js";
3
+ import { z } from "zod";
4
+ //#region src/package-node.ts
5
+ const SectionDescriptorSchema = ContentSectionSchema.omit({ blocks: true }).extend({ kind: z.literal("section") }).strict();
6
+ const SlideDescriptorSchema = ContentSlideSchema.omit({ shapes: true }).extend({ kind: z.literal("slide") }).strict();
7
+ const SheetDescriptorSchema = ContentSheetSchema.omit({
8
+ images: true,
9
+ embeddedObjects: true
10
+ }).extend({ kind: z.literal("sheet") }).strict();
11
+ const DrawPageDescriptorSchema = ContentDrawPageSchema.omit({
12
+ shapes: true,
13
+ vectors: true
14
+ }).extend({ kind: z.literal("drawPage") }).strict();
15
+ const ShapeDescriptorSchema = ContentShapeSchema.omit({ blocks: true }).strict();
16
+ const HeadingParagraphSchema = ContentParagraphSchema.extend({ headingLevel: z.number().int().positive() });
17
+ const ListParagraphSchema = ContentParagraphSchema.extend({ list: ContentListMembershipSchema });
18
+ function isRecord(value) {
19
+ return typeof value === "object" && value !== null && !Array.isArray(value);
20
+ }
21
+ function isGroupWrapper(value, isChild) {
22
+ if (!isRecord(value.node)) return false;
23
+ if (value.style !== void 0 && typeof value.style !== "string") return false;
24
+ if (!Object.keys(value).every((key) => key === "node" || key === "style" || key === "children")) return false;
25
+ return Array.isArray(value.children) && value.children.every(isChild);
26
+ }
27
+ function isLeafChild(schema, value) {
28
+ if (isRecord(value) && "style" in value) return false;
29
+ return schema.safeParse(value).success;
30
+ }
31
+ function isSectionChild(value) {
32
+ return isHeadingGroupNode(value) || isListGroupNode(value) || isSectionConstructGroupNode(value) || isLeafChild(ContentBlockSchema, value);
33
+ }
34
+ function isShapeChild(value) {
35
+ return isListGroupNode(value) || isShapeConstructGroupNode(value) || isLeafChild(ContentBlockSchema, value);
36
+ }
37
+ function isListChild(value) {
38
+ return isListGroupNode(value) || isShapeConstructGroupNode(value) || isLeafChild(ContentBlockSchema, value);
39
+ }
40
+ function isSheetChild(value) {
41
+ return isLeafChild(ContentSheetImageSchema, value) || isLeafChild(ContentEmbeddedObjectSchema, value);
42
+ }
43
+ function isDrawPageChild(value) {
44
+ return isShapeGroupNode(value) || isLeafChild(ContentVectorSchema, value);
45
+ }
46
+ function isSectionGroupNode(value) {
47
+ return isRecord(value) && SectionDescriptorSchema.safeParse(value.node).success && isGroupWrapper(value, isSectionChild);
48
+ }
49
+ function isSlideGroupNode(value) {
50
+ return isRecord(value) && SlideDescriptorSchema.safeParse(value.node).success && isGroupWrapper(value, isShapeGroupNode);
51
+ }
52
+ function isSheetGroupNode(value) {
53
+ return isRecord(value) && SheetDescriptorSchema.safeParse(value.node).success && isGroupWrapper(value, isSheetChild);
54
+ }
55
+ function isDrawPageGroupNode(value) {
56
+ return isRecord(value) && DrawPageDescriptorSchema.safeParse(value.node).success && isGroupWrapper(value, isDrawPageChild);
57
+ }
58
+ function isShapeGroupNode(value) {
59
+ return isRecord(value) && ShapeDescriptorSchema.safeParse(value.node).success && isGroupWrapper(value, isShapeChild);
60
+ }
61
+ function isHeadingGroupNode(value) {
62
+ return isRecord(value) && HeadingParagraphSchema.safeParse(value.node).success && isGroupWrapper(value, isSectionChild);
63
+ }
64
+ function isListGroupNode(value) {
65
+ return isRecord(value) && ListParagraphSchema.safeParse(value.node).success && isGroupWrapper(value, isListChild);
66
+ }
67
+ function isSectionConstructGroupNode(value) {
68
+ return isRecord(value) && ConstructDescriptorSchema.safeParse(value.node).success && isGroupWrapper(value, isSectionChild);
69
+ }
70
+ function isShapeConstructGroupNode(value) {
71
+ return isRecord(value) && ConstructDescriptorSchema.safeParse(value.node).success && isGroupWrapper(value, isShapeChild);
72
+ }
73
+ const packageLeafUnion = z.union([
74
+ ContentBlockSchema,
75
+ ContentSheetImageSchema,
76
+ ContentEmbeddedObjectSchema,
77
+ ContentVectorSchema,
78
+ ContentFormulaSchema
79
+ ]);
80
+ function isPackageLeaf(value) {
81
+ return packageLeafUnion.safeParse(value).success;
82
+ }
83
+ function isPackageGroup(value) {
84
+ return isSectionGroupNode(value) || isSlideGroupNode(value) || isSheetGroupNode(value) || isDrawPageGroupNode(value) || isShapeGroupNode(value) || isHeadingGroupNode(value) || isListGroupNode(value) || isSectionConstructGroupNode(value) || isShapeConstructGroupNode(value);
85
+ }
86
+ function isPackageNode(value) {
87
+ return isPackageGroup(value) || isPackageLeaf(value);
88
+ }
89
+ const SectionGroupSchema = z.custom(isSectionGroupNode);
90
+ const SlideGroupSchema = z.custom(isSlideGroupNode);
91
+ const SheetGroupSchema = z.custom(isSheetGroupNode);
92
+ const DrawPageGroupSchema = z.custom(isDrawPageGroupNode);
93
+ const ShapeGroupSchema = z.custom(isShapeGroupNode);
94
+ const HeadingGroupSchema = z.custom(isHeadingGroupNode);
95
+ const ListGroupSchema = z.custom(isListGroupNode);
96
+ const SectionConstructGroupSchema = z.custom(isSectionConstructGroupNode);
97
+ const ShapeConstructGroupSchema = z.custom(isShapeConstructGroupNode);
98
+ const PackageGroupSchema = z.custom(isPackageGroup);
99
+ const PackageLeafSchema = z.custom(isPackageLeaf);
100
+ const PackageNodeSchema = z.custom(isPackageNode);
101
+ //#endregion
102
+ export { DrawPageDescriptorSchema, DrawPageGroupSchema, HeadingGroupSchema, HeadingParagraphSchema, ListGroupSchema, ListParagraphSchema, PackageGroupSchema, PackageLeafSchema, PackageNodeSchema, SectionConstructGroupSchema, SectionDescriptorSchema, SectionGroupSchema, ShapeConstructGroupSchema, ShapeDescriptorSchema, ShapeGroupSchema, SheetDescriptorSchema, SheetGroupSchema, SlideDescriptorSchema, SlideGroupSchema, isDrawPageGroupNode, isHeadingGroupNode, isListGroupNode, isPackageGroup, isPackageLeaf, isPackageNode, isSectionConstructGroupNode, isSectionGroupNode, isShapeConstructGroupNode, isShapeGroupNode, isSheetGroupNode, isSlideGroupNode };
package/dist/package.cjs CHANGED
@@ -1,14 +1,47 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_geometry = require("./geometry.cjs");
3
+ const require_metadata = require("./metadata.cjs");
3
4
  const require_content = require("./content.cjs");
5
+ const require_definitions = require("./definitions.cjs");
6
+ const require_package_node = require("./package-node.cjs");
4
7
  let zod = require("zod");
5
8
  //#region src/package.ts
6
- const DOCUMENT_PACKAGE_FORMAT_VERSION = 2;
7
- const DocumentPackageSchema = zod.z.object({
8
- formatVersion: zod.z.literal(2),
9
- content: require_content.ContentDocumentSchema,
10
- pages: zod.z.array(require_geometry.PageSizeSchema).optional()
11
- });
9
+ const packageEnvelopeFields = {
10
+ metadata: require_metadata.LayoutMetadataSchema,
11
+ ...require_content.contentDocumentSharedFields,
12
+ pages: zod.z.array(require_geometry.PageSizeSchema).optional(),
13
+ styles: require_definitions.StylesTableSchema.optional(),
14
+ definitions: require_definitions.DefinitionsTableSchema.optional(),
15
+ layers: require_definitions.DefinitionsTableSchema.optional(),
16
+ attachments: require_definitions.DefinitionsTableSchema.optional(),
17
+ destinations: require_definitions.DefinitionsTableSchema.optional()
18
+ };
19
+ const DocumentPackageSchema = zod.z.discriminatedUnion("kind", [
20
+ zod.z.object({
21
+ kind: zod.z.literal("wordprocessing"),
22
+ ...packageEnvelopeFields,
23
+ children: zod.z.array(require_package_node.SectionGroupSchema)
24
+ }),
25
+ zod.z.object({
26
+ kind: zod.z.literal("presentation"),
27
+ ...packageEnvelopeFields,
28
+ children: zod.z.array(require_package_node.SlideGroupSchema)
29
+ }),
30
+ zod.z.object({
31
+ kind: zod.z.literal("spreadsheet"),
32
+ ...packageEnvelopeFields,
33
+ children: zod.z.array(require_package_node.SheetGroupSchema)
34
+ }),
35
+ zod.z.object({
36
+ kind: zod.z.literal("drawing"),
37
+ ...packageEnvelopeFields,
38
+ children: zod.z.array(require_package_node.DrawPageGroupSchema)
39
+ }),
40
+ zod.z.object({
41
+ kind: zod.z.literal("formula"),
42
+ ...packageEnvelopeFields,
43
+ children: zod.z.array(require_content.ContentFormulaSchema).length(1)
44
+ })
45
+ ]);
12
46
  //#endregion
13
- exports.DOCUMENT_PACKAGE_FORMAT_VERSION = DOCUMENT_PACKAGE_FORMAT_VERSION;
14
47
  exports.DocumentPackageSchema = DocumentPackageSchema;