documents.js 3.1.4 → 4.0.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.
@@ -1,18 +0,0 @@
1
- //#region src/convert/canonicalise.ts
2
- function canonicalise(value) {
3
- if (Array.isArray(value)) return value.map(canonicalise);
4
- if (isRecord(value)) {
5
- const sorted = {};
6
- for (const key of Object.keys(value).sort()) sorted[key] = canonicalise(value[key]);
7
- return sorted;
8
- }
9
- return value;
10
- }
11
- function isRecord(value) {
12
- return typeof value === "object" && value !== null && !Array.isArray(value);
13
- }
14
- function canonicalKey(value) {
15
- return JSON.stringify(canonicalise(value));
16
- }
17
- //#endregion
18
- export { canonicalKey, canonicalise };
@@ -1,186 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let document_schema_js = require("document-schema.js");
3
- //#region src/convert/decompose.ts
4
- function isHeadingParagraph(paragraph) {
5
- return paragraph.headingLevel !== void 0;
6
- }
7
- function isListParagraph(paragraph) {
8
- return paragraph.list !== void 0;
9
- }
10
- var ConstructMarkerImbalanceError = class extends Error {
11
- imbalance;
12
- constructor(imbalance) {
13
- super(imbalance.kind === "unmatchedEnd" ? `decompose: the constructEnd marker at index ${imbalance.index} of this container's block flow closes no open construct` : `decompose: the constructStart marker at index ${imbalance.index} of this container's block flow is never closed`);
14
- this.name = "ConstructMarkerImbalanceError";
15
- this.imbalance = imbalance;
16
- }
17
- };
18
- function decompose(content) {
19
- switch (content.kind) {
20
- case "wordprocessing": return content.sections.map(decomposeSection);
21
- case "presentation": return content.slides.map(decomposeSlide);
22
- case "spreadsheet": return content.sheets.map(decomposeSheet);
23
- case "drawing": return content.pages.map(decomposeDrawPage);
24
- case "formula": return [content.formula];
25
- }
26
- }
27
- function decomposeSection(section) {
28
- const { blocks, ...rest } = section;
29
- return {
30
- node: {
31
- kind: "section",
32
- ...rest
33
- },
34
- children: decomposeSectionBlocks(blocks)
35
- };
36
- }
37
- function assertBalancedConstructMarkers(blocks) {
38
- const imbalance = (0, document_schema_js.findConstructMarkerImbalance)(blocks);
39
- if (imbalance !== void 0) throw new ConstructMarkerImbalanceError(imbalance);
40
- }
41
- function decomposeSectionBlocks(blocks) {
42
- assertBalancedConstructMarkers(blocks);
43
- return walkSectionBlocks(blocks.values());
44
- }
45
- function walkSectionBlocks(cursor) {
46
- const root = [];
47
- const headingStack = [];
48
- const listStack = [];
49
- const headingScope = () => headingStack.at(-1)?.children ?? root;
50
- for (let step = cursor.next(); step.done !== true; step = cursor.next()) {
51
- const block = step.value;
52
- if (block.kind === "constructEnd") return root;
53
- if (block.kind === "constructStart") {
54
- openConstructGroup(block.descriptor, cursor, listStack, headingScope());
55
- continue;
56
- }
57
- if (block.kind !== "paragraph") {
58
- const parent = listStack.at(-1);
59
- (parent !== void 0 ? parent.children : headingScope()).push(block);
60
- continue;
61
- }
62
- if (isHeadingParagraph(block)) {
63
- listStack.length = 0;
64
- const level = block.headingLevel;
65
- for (let top = headingStack.at(-1); top !== void 0 && top.node.headingLevel >= level; top = headingStack.at(-1)) headingStack.pop();
66
- const group = {
67
- node: block,
68
- children: []
69
- };
70
- const parent = headingStack.at(-1);
71
- (parent !== void 0 ? parent.children : root).push(group);
72
- headingStack.push(group);
73
- } else if (isListParagraph(block)) openListGroup(listStack, headingScope(), block);
74
- else {
75
- listStack.length = 0;
76
- headingScope().push(block);
77
- }
78
- }
79
- return root;
80
- }
81
- function decomposeSlide(slide) {
82
- const { shapes, ...rest } = slide;
83
- return {
84
- node: {
85
- kind: "slide",
86
- ...rest
87
- },
88
- children: shapes.map(decomposeShape)
89
- };
90
- }
91
- function decomposeSheet(sheet) {
92
- const { images, embeddedObjects, ...rest } = sheet;
93
- const children = [...images, ...embeddedObjects ?? []];
94
- return {
95
- node: {
96
- kind: "sheet",
97
- ...rest
98
- },
99
- children
100
- };
101
- }
102
- function decomposeDrawPage(page) {
103
- const { shapes, vectors, ...rest } = page;
104
- const children = [...shapes.map(decomposeShape), ...vectors];
105
- return {
106
- node: {
107
- kind: "drawPage",
108
- ...rest
109
- },
110
- children
111
- };
112
- }
113
- function decomposeShape(shape) {
114
- const { blocks, ...rest } = shape;
115
- return {
116
- node: rest,
117
- children: decomposeShapeBlocks(blocks)
118
- };
119
- }
120
- function decomposeShapeBlocks(blocks) {
121
- assertBalancedConstructMarkers(blocks);
122
- return walkShapeBlocks(blocks.values());
123
- }
124
- function walkShapeBlocks(cursor) {
125
- const root = [];
126
- const listStack = [];
127
- for (let step = cursor.next(); step.done !== true; step = cursor.next()) {
128
- const block = step.value;
129
- if (block.kind === "constructEnd") return root;
130
- if (block.kind === "constructStart") {
131
- const parent = listStack.at(-1);
132
- (parent !== void 0 ? parent.children : root).push({
133
- node: block.descriptor,
134
- children: walkShapeBlocks(cursor)
135
- });
136
- continue;
137
- }
138
- if (block.kind !== "paragraph") {
139
- const parent = listStack.at(-1);
140
- (parent !== void 0 ? parent.children : root).push(block);
141
- continue;
142
- }
143
- if (isListParagraph(block)) {
144
- openListGroup(listStack, root, block);
145
- continue;
146
- }
147
- listStack.length = 0;
148
- root.push(block);
149
- }
150
- return root;
151
- }
152
- function openConstructGroup(descriptor, cursor, listStack, headingScope) {
153
- const parent = listStack.at(-1);
154
- if (parent === void 0) {
155
- headingScope.push({
156
- node: descriptor,
157
- children: walkSectionBlocks(cursor)
158
- });
159
- return;
160
- }
161
- parent.children.push({
162
- node: descriptor,
163
- children: walkShapeBlocks(cursor)
164
- });
165
- }
166
- function openListGroup(listStack, scopeChildren, paragraph) {
167
- const level = paragraph.list.level;
168
- for (let top = listStack.at(-1); top !== void 0 && top.node.list.level >= level; top = listStack.at(-1)) listStack.pop();
169
- const group = {
170
- node: paragraph,
171
- children: []
172
- };
173
- const parent = listStack.at(-1);
174
- (parent !== void 0 ? parent.children : scopeChildren).push(group);
175
- listStack.push(group);
176
- }
177
- //#endregion
178
- exports.ConstructMarkerImbalanceError = ConstructMarkerImbalanceError;
179
- exports.decompose = decompose;
180
- exports.decomposeDrawPage = decomposeDrawPage;
181
- exports.decomposeSection = decomposeSection;
182
- exports.decomposeShape = decomposeShape;
183
- exports.decomposeSheet = decomposeSheet;
184
- exports.decomposeSlide = decomposeSlide;
185
- exports.isHeadingParagraph = isHeadingParagraph;
186
- exports.isListParagraph = isListParagraph;
@@ -1,17 +0,0 @@
1
- import { ConstructMarkerImbalance, ContentDocument, ContentDrawPage, ContentFormula, ContentParagraph, ContentSection, ContentShape, ContentSheet, ContentSlide, DrawPageGroupNode, HeadingParagraph, ListParagraph, SectionGroupNode, ShapeGroupNode, SheetGroupNode, SlideGroupNode } from "document-schema.js";
2
- //#region src/convert/decompose.d.ts
3
- declare function isHeadingParagraph(paragraph: ContentParagraph): paragraph is HeadingParagraph;
4
- declare function isListParagraph(paragraph: ContentParagraph): paragraph is ListParagraph;
5
- declare class ConstructMarkerImbalanceError extends Error {
6
- readonly imbalance: ConstructMarkerImbalance;
7
- constructor(imbalance: ConstructMarkerImbalance);
8
- }
9
- type PackageChildren = SectionGroupNode[] | SlideGroupNode[] | SheetGroupNode[] | DrawPageGroupNode[] | ContentFormula[];
10
- declare function decompose(content: ContentDocument): PackageChildren;
11
- declare function decomposeSection(section: ContentSection): SectionGroupNode;
12
- declare function decomposeSlide(slide: ContentSlide): SlideGroupNode;
13
- declare function decomposeSheet(sheet: ContentSheet): SheetGroupNode;
14
- declare function decomposeDrawPage(page: ContentDrawPage): DrawPageGroupNode;
15
- declare function decomposeShape(shape: ContentShape): ShapeGroupNode;
16
- //#endregion
17
- export { ConstructMarkerImbalanceError, PackageChildren, decompose, decomposeDrawPage, decomposeSection, decomposeShape, decomposeSheet, decomposeSlide, isHeadingParagraph, isListParagraph };
@@ -1,17 +0,0 @@
1
- import { ConstructMarkerImbalance, ContentDocument, ContentDrawPage, ContentFormula, ContentParagraph, ContentSection, ContentShape, ContentSheet, ContentSlide, DrawPageGroupNode, HeadingParagraph, ListParagraph, SectionGroupNode, ShapeGroupNode, SheetGroupNode, SlideGroupNode } from "document-schema.js";
2
- //#region src/convert/decompose.d.ts
3
- declare function isHeadingParagraph(paragraph: ContentParagraph): paragraph is HeadingParagraph;
4
- declare function isListParagraph(paragraph: ContentParagraph): paragraph is ListParagraph;
5
- declare class ConstructMarkerImbalanceError extends Error {
6
- readonly imbalance: ConstructMarkerImbalance;
7
- constructor(imbalance: ConstructMarkerImbalance);
8
- }
9
- type PackageChildren = SectionGroupNode[] | SlideGroupNode[] | SheetGroupNode[] | DrawPageGroupNode[] | ContentFormula[];
10
- declare function decompose(content: ContentDocument): PackageChildren;
11
- declare function decomposeSection(section: ContentSection): SectionGroupNode;
12
- declare function decomposeSlide(slide: ContentSlide): SlideGroupNode;
13
- declare function decomposeSheet(sheet: ContentSheet): SheetGroupNode;
14
- declare function decomposeDrawPage(page: ContentDrawPage): DrawPageGroupNode;
15
- declare function decomposeShape(shape: ContentShape): ShapeGroupNode;
16
- //#endregion
17
- export { ConstructMarkerImbalanceError, PackageChildren, decompose, decomposeDrawPage, decomposeSection, decomposeShape, decomposeSheet, decomposeSlide, isHeadingParagraph, isListParagraph };
@@ -1,177 +0,0 @@
1
- import { findConstructMarkerImbalance } from "document-schema.js";
2
- //#region src/convert/decompose.ts
3
- function isHeadingParagraph(paragraph) {
4
- return paragraph.headingLevel !== void 0;
5
- }
6
- function isListParagraph(paragraph) {
7
- return paragraph.list !== void 0;
8
- }
9
- var ConstructMarkerImbalanceError = class extends Error {
10
- imbalance;
11
- constructor(imbalance) {
12
- super(imbalance.kind === "unmatchedEnd" ? `decompose: the constructEnd marker at index ${imbalance.index} of this container's block flow closes no open construct` : `decompose: the constructStart marker at index ${imbalance.index} of this container's block flow is never closed`);
13
- this.name = "ConstructMarkerImbalanceError";
14
- this.imbalance = imbalance;
15
- }
16
- };
17
- function decompose(content) {
18
- switch (content.kind) {
19
- case "wordprocessing": return content.sections.map(decomposeSection);
20
- case "presentation": return content.slides.map(decomposeSlide);
21
- case "spreadsheet": return content.sheets.map(decomposeSheet);
22
- case "drawing": return content.pages.map(decomposeDrawPage);
23
- case "formula": return [content.formula];
24
- }
25
- }
26
- function decomposeSection(section) {
27
- const { blocks, ...rest } = section;
28
- return {
29
- node: {
30
- kind: "section",
31
- ...rest
32
- },
33
- children: decomposeSectionBlocks(blocks)
34
- };
35
- }
36
- function assertBalancedConstructMarkers(blocks) {
37
- const imbalance = findConstructMarkerImbalance(blocks);
38
- if (imbalance !== void 0) throw new ConstructMarkerImbalanceError(imbalance);
39
- }
40
- function decomposeSectionBlocks(blocks) {
41
- assertBalancedConstructMarkers(blocks);
42
- return walkSectionBlocks(blocks.values());
43
- }
44
- function walkSectionBlocks(cursor) {
45
- const root = [];
46
- const headingStack = [];
47
- const listStack = [];
48
- const headingScope = () => headingStack.at(-1)?.children ?? root;
49
- for (let step = cursor.next(); step.done !== true; step = cursor.next()) {
50
- const block = step.value;
51
- if (block.kind === "constructEnd") return root;
52
- if (block.kind === "constructStart") {
53
- openConstructGroup(block.descriptor, cursor, listStack, headingScope());
54
- continue;
55
- }
56
- if (block.kind !== "paragraph") {
57
- const parent = listStack.at(-1);
58
- (parent !== void 0 ? parent.children : headingScope()).push(block);
59
- continue;
60
- }
61
- if (isHeadingParagraph(block)) {
62
- listStack.length = 0;
63
- const level = block.headingLevel;
64
- for (let top = headingStack.at(-1); top !== void 0 && top.node.headingLevel >= level; top = headingStack.at(-1)) headingStack.pop();
65
- const group = {
66
- node: block,
67
- children: []
68
- };
69
- const parent = headingStack.at(-1);
70
- (parent !== void 0 ? parent.children : root).push(group);
71
- headingStack.push(group);
72
- } else if (isListParagraph(block)) openListGroup(listStack, headingScope(), block);
73
- else {
74
- listStack.length = 0;
75
- headingScope().push(block);
76
- }
77
- }
78
- return root;
79
- }
80
- function decomposeSlide(slide) {
81
- const { shapes, ...rest } = slide;
82
- return {
83
- node: {
84
- kind: "slide",
85
- ...rest
86
- },
87
- children: shapes.map(decomposeShape)
88
- };
89
- }
90
- function decomposeSheet(sheet) {
91
- const { images, embeddedObjects, ...rest } = sheet;
92
- const children = [...images, ...embeddedObjects ?? []];
93
- return {
94
- node: {
95
- kind: "sheet",
96
- ...rest
97
- },
98
- children
99
- };
100
- }
101
- function decomposeDrawPage(page) {
102
- const { shapes, vectors, ...rest } = page;
103
- const children = [...shapes.map(decomposeShape), ...vectors];
104
- return {
105
- node: {
106
- kind: "drawPage",
107
- ...rest
108
- },
109
- children
110
- };
111
- }
112
- function decomposeShape(shape) {
113
- const { blocks, ...rest } = shape;
114
- return {
115
- node: rest,
116
- children: decomposeShapeBlocks(blocks)
117
- };
118
- }
119
- function decomposeShapeBlocks(blocks) {
120
- assertBalancedConstructMarkers(blocks);
121
- return walkShapeBlocks(blocks.values());
122
- }
123
- function walkShapeBlocks(cursor) {
124
- const root = [];
125
- const listStack = [];
126
- for (let step = cursor.next(); step.done !== true; step = cursor.next()) {
127
- const block = step.value;
128
- if (block.kind === "constructEnd") return root;
129
- if (block.kind === "constructStart") {
130
- const parent = listStack.at(-1);
131
- (parent !== void 0 ? parent.children : root).push({
132
- node: block.descriptor,
133
- children: walkShapeBlocks(cursor)
134
- });
135
- continue;
136
- }
137
- if (block.kind !== "paragraph") {
138
- const parent = listStack.at(-1);
139
- (parent !== void 0 ? parent.children : root).push(block);
140
- continue;
141
- }
142
- if (isListParagraph(block)) {
143
- openListGroup(listStack, root, block);
144
- continue;
145
- }
146
- listStack.length = 0;
147
- root.push(block);
148
- }
149
- return root;
150
- }
151
- function openConstructGroup(descriptor, cursor, listStack, headingScope) {
152
- const parent = listStack.at(-1);
153
- if (parent === void 0) {
154
- headingScope.push({
155
- node: descriptor,
156
- children: walkSectionBlocks(cursor)
157
- });
158
- return;
159
- }
160
- parent.children.push({
161
- node: descriptor,
162
- children: walkShapeBlocks(cursor)
163
- });
164
- }
165
- function openListGroup(listStack, scopeChildren, paragraph) {
166
- const level = paragraph.list.level;
167
- for (let top = listStack.at(-1); top !== void 0 && top.node.list.level >= level; top = listStack.at(-1)) listStack.pop();
168
- const group = {
169
- node: paragraph,
170
- children: []
171
- };
172
- const parent = listStack.at(-1);
173
- (parent !== void 0 ? parent.children : scopeChildren).push(group);
174
- listStack.push(group);
175
- }
176
- //#endregion
177
- export { ConstructMarkerImbalanceError, decompose, decomposeDrawPage, decomposeSection, decomposeShape, decomposeSheet, decomposeSlide, isHeadingParagraph, isListParagraph };