document-outline.js 1.0.0 → 1.0.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 +86 -44
- package/dist/index.js +87 -45
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -11,38 +11,73 @@ function buildOutline(pkg) {
|
|
|
11
11
|
case "formula": return formulaOutline(pkg.children[0]);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const walk = (children) => {
|
|
20
|
-
for (const child of children) if ((0, document_schema_js.isHeadingGroupNode)(child)) {
|
|
21
|
-
listStack.length = 0;
|
|
22
|
-
const level = child.node.headingLevel;
|
|
23
|
-
for (let top = headingStack.at(-1); top !== void 0 && top.level >= level; top = headingStack.at(-1)) headingStack.pop();
|
|
24
|
-
const node = {
|
|
25
|
-
text: paragraphText(child.node),
|
|
26
|
-
level,
|
|
27
|
-
children: []
|
|
28
|
-
};
|
|
29
|
-
const parent = headingStack.at(-1);
|
|
30
|
-
(parent !== void 0 ? parent.children : root).push(node);
|
|
31
|
-
headingStack.push(node);
|
|
32
|
-
walk(child.children);
|
|
33
|
-
} else if ((0, document_schema_js.isListGroupNode)(child)) {
|
|
34
|
-
openListGroup(listStack, headingScope(), paragraphText(child.node), child.node.list.level);
|
|
35
|
-
walk(child.children);
|
|
36
|
-
} else if (child.kind === "paragraph") {
|
|
37
|
-
listStack.length = 0;
|
|
38
|
-
headingScope().push(child);
|
|
39
|
-
} else {
|
|
40
|
-
const parent = listStack.at(-1);
|
|
41
|
-
(parent !== void 0 ? parent.children : headingScope()).push(child);
|
|
42
|
-
}
|
|
14
|
+
function freshSectionFlowScope() {
|
|
15
|
+
return {
|
|
16
|
+
root: [],
|
|
17
|
+
headingStack: [],
|
|
18
|
+
listStack: []
|
|
43
19
|
};
|
|
44
|
-
|
|
45
|
-
|
|
20
|
+
}
|
|
21
|
+
function headingScopeOf(scope) {
|
|
22
|
+
return scope.headingStack.at(-1)?.children ?? scope.root;
|
|
23
|
+
}
|
|
24
|
+
function walkSectionFlow(scope, children) {
|
|
25
|
+
for (const child of children) if ((0, document_schema_js.isHeadingGroupNode)(child)) {
|
|
26
|
+
scope.listStack.length = 0;
|
|
27
|
+
const level = child.node.headingLevel;
|
|
28
|
+
for (let top = scope.headingStack.at(-1); top !== void 0 && top.level >= level; top = scope.headingStack.at(-1)) scope.headingStack.pop();
|
|
29
|
+
const node = {
|
|
30
|
+
text: paragraphText(child.node),
|
|
31
|
+
level,
|
|
32
|
+
children: []
|
|
33
|
+
};
|
|
34
|
+
const parent = scope.headingStack.at(-1);
|
|
35
|
+
(parent !== void 0 ? parent.children : scope.root).push(node);
|
|
36
|
+
scope.headingStack.push(node);
|
|
37
|
+
walkSectionFlow(scope, child.children);
|
|
38
|
+
} else if ((0, document_schema_js.isListGroupNode)(child)) {
|
|
39
|
+
openListGroup(scope.listStack, headingScopeOf(scope), paragraphText(child.node), child.node.list.level);
|
|
40
|
+
walkSectionFlow(scope, child.children);
|
|
41
|
+
} else if ((0, document_schema_js.isSectionConstructGroupNode)(child)) {
|
|
42
|
+
const parent = scope.listStack.at(-1);
|
|
43
|
+
(parent !== void 0 ? parent.children : headingScopeOf(scope)).push(...projectSectionFlow(child.children));
|
|
44
|
+
} else if (child.kind === "paragraph") {
|
|
45
|
+
scope.listStack.length = 0;
|
|
46
|
+
headingScopeOf(scope).push(child);
|
|
47
|
+
} else {
|
|
48
|
+
const parent = scope.listStack.at(-1);
|
|
49
|
+
(parent !== void 0 ? parent.children : headingScopeOf(scope)).push(child);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function projectSectionFlow(children) {
|
|
53
|
+
const scope = freshSectionFlowScope();
|
|
54
|
+
walkSectionFlow(scope, children);
|
|
55
|
+
return scope.root;
|
|
56
|
+
}
|
|
57
|
+
function wordprocessingOutline(sections) {
|
|
58
|
+
const scope = freshSectionFlowScope();
|
|
59
|
+
for (const section of sections) walkSectionFlow(scope, section.children);
|
|
60
|
+
return scope.root;
|
|
61
|
+
}
|
|
62
|
+
function walkShapeFlow(listStack, scope, children) {
|
|
63
|
+
for (const child of children) if ((0, document_schema_js.isListGroupNode)(child)) {
|
|
64
|
+
openListGroup(listStack, scope, paragraphText(child.node), child.node.list.level);
|
|
65
|
+
walkShapeFlow(listStack, scope, child.children);
|
|
66
|
+
} else if ((0, document_schema_js.isShapeConstructGroupNode)(child)) {
|
|
67
|
+
const parent = listStack.at(-1);
|
|
68
|
+
(parent !== void 0 ? parent.children : scope).push(...projectShapeFlow(child.children));
|
|
69
|
+
} else if (child.kind === "paragraph") {
|
|
70
|
+
listStack.length = 0;
|
|
71
|
+
scope.push(child);
|
|
72
|
+
} else {
|
|
73
|
+
const parent = listStack.at(-1);
|
|
74
|
+
(parent !== void 0 ? parent.children : scope).push(child);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function projectShapeFlow(children) {
|
|
78
|
+
const scope = [];
|
|
79
|
+
walkShapeFlow([], scope, children);
|
|
80
|
+
return scope;
|
|
46
81
|
}
|
|
47
82
|
function presentationOutline(slides) {
|
|
48
83
|
return slides.map((slide, index) => {
|
|
@@ -52,19 +87,7 @@ function presentationOutline(slides) {
|
|
|
52
87
|
children: []
|
|
53
88
|
};
|
|
54
89
|
const listStack = [];
|
|
55
|
-
const
|
|
56
|
-
for (const child of children) if ((0, document_schema_js.isListGroupNode)(child)) {
|
|
57
|
-
openListGroup(listStack, group.children, paragraphText(child.node), child.node.list.level);
|
|
58
|
-
walk(child.children);
|
|
59
|
-
} else if (child.kind === "paragraph") {
|
|
60
|
-
listStack.length = 0;
|
|
61
|
-
group.children.push(child);
|
|
62
|
-
} else {
|
|
63
|
-
const parent = listStack.at(-1);
|
|
64
|
-
(parent !== void 0 ? parent.children : group.children).push(child);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
for (const shape of slide.children) walk(shape.children);
|
|
90
|
+
for (const shape of slide.children) walkShapeFlow(listStack, group.children, shape.children);
|
|
68
91
|
return group;
|
|
69
92
|
});
|
|
70
93
|
}
|
|
@@ -88,6 +111,7 @@ function flattenShapeChildren(group) {
|
|
|
88
111
|
function flattenListFlow(children) {
|
|
89
112
|
const leaves = [];
|
|
90
113
|
for (const child of children) if ((0, document_schema_js.isListGroupNode)(child)) leaves.push(child.node, ...flattenListFlow(child.children));
|
|
114
|
+
else if ((0, document_schema_js.isShapeConstructGroupNode)(child)) leaves.push(...flattenListFlow(child.children));
|
|
91
115
|
else leaves.push(child);
|
|
92
116
|
return leaves;
|
|
93
117
|
}
|
|
@@ -197,6 +221,22 @@ function resolveShapeGroup(styles, chain, group) {
|
|
|
197
221
|
children
|
|
198
222
|
};
|
|
199
223
|
}
|
|
224
|
+
function resolveSectionConstructGroup(styles, chain, group) {
|
|
225
|
+
const children = resolveSectionChildren(styles, chainWithRef(chain, group), group.children);
|
|
226
|
+
if (group.style === void 0 && children === group.children) return group;
|
|
227
|
+
return {
|
|
228
|
+
node: group.node,
|
|
229
|
+
children
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function resolveShapeConstructGroup(styles, chain, group) {
|
|
233
|
+
const children = resolveListChildren(styles, chainWithRef(chain, group), group.children);
|
|
234
|
+
if (group.style === void 0 && children === group.children) return group;
|
|
235
|
+
return {
|
|
236
|
+
node: group.node,
|
|
237
|
+
children
|
|
238
|
+
};
|
|
239
|
+
}
|
|
200
240
|
function resolveHeadingGroup(styles, chain, group) {
|
|
201
241
|
const own = chainWithRef(chain, group);
|
|
202
242
|
const entry = own.length > 0 ? (0, document_schema_js.resolveStyleChain)(styles, own) : void 0;
|
|
@@ -242,6 +282,7 @@ function resolveSectionChildren(styles, chain, children) {
|
|
|
242
282
|
let resolved;
|
|
243
283
|
if ((0, document_schema_js.isHeadingGroupNode)(child)) resolved = resolveHeadingGroup(styles, chain, child);
|
|
244
284
|
else if ((0, document_schema_js.isListGroupNode)(child)) resolved = resolveListGroup(styles, chain, child);
|
|
285
|
+
else if ((0, document_schema_js.isSectionConstructGroupNode)(child)) resolved = resolveSectionConstructGroup(styles, chain, child);
|
|
245
286
|
else if (child.kind === "paragraph") resolved = resolveParagraphLeaf(styles, chain, child);
|
|
246
287
|
else resolved = child;
|
|
247
288
|
changed ||= resolved !== child;
|
|
@@ -255,6 +296,7 @@ function resolveListChildren(styles, chain, children) {
|
|
|
255
296
|
for (const child of children) {
|
|
256
297
|
let resolved;
|
|
257
298
|
if ((0, document_schema_js.isListGroupNode)(child)) resolved = resolveListGroup(styles, chain, child);
|
|
299
|
+
else if ((0, document_schema_js.isShapeConstructGroupNode)(child)) resolved = resolveShapeConstructGroup(styles, chain, child);
|
|
258
300
|
else if (child.kind === "paragraph") resolved = resolveParagraphLeaf(styles, chain, child);
|
|
259
301
|
else resolved = child;
|
|
260
302
|
changed ||= resolved !== child;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyParagraphStyleProperties, applyRunStyleProperties, isHeadingGroupNode, isListGroupNode, isPackageLeaf, isShapeGroupNode, resolveStyleChain } from "document-schema.js";
|
|
1
|
+
import { applyParagraphStyleProperties, applyRunStyleProperties, isHeadingGroupNode, isListGroupNode, isPackageLeaf, isSectionConstructGroupNode, isShapeConstructGroupNode, isShapeGroupNode, resolveStyleChain } from "document-schema.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
//#region src/outline/build.ts
|
|
4
4
|
function buildOutline(pkg) {
|
|
@@ -10,38 +10,73 @@ function buildOutline(pkg) {
|
|
|
10
10
|
case "formula": return formulaOutline(pkg.children[0]);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const walk = (children) => {
|
|
19
|
-
for (const child of children) if (isHeadingGroupNode(child)) {
|
|
20
|
-
listStack.length = 0;
|
|
21
|
-
const level = child.node.headingLevel;
|
|
22
|
-
for (let top = headingStack.at(-1); top !== void 0 && top.level >= level; top = headingStack.at(-1)) headingStack.pop();
|
|
23
|
-
const node = {
|
|
24
|
-
text: paragraphText(child.node),
|
|
25
|
-
level,
|
|
26
|
-
children: []
|
|
27
|
-
};
|
|
28
|
-
const parent = headingStack.at(-1);
|
|
29
|
-
(parent !== void 0 ? parent.children : root).push(node);
|
|
30
|
-
headingStack.push(node);
|
|
31
|
-
walk(child.children);
|
|
32
|
-
} else if (isListGroupNode(child)) {
|
|
33
|
-
openListGroup(listStack, headingScope(), paragraphText(child.node), child.node.list.level);
|
|
34
|
-
walk(child.children);
|
|
35
|
-
} else if (child.kind === "paragraph") {
|
|
36
|
-
listStack.length = 0;
|
|
37
|
-
headingScope().push(child);
|
|
38
|
-
} else {
|
|
39
|
-
const parent = listStack.at(-1);
|
|
40
|
-
(parent !== void 0 ? parent.children : headingScope()).push(child);
|
|
41
|
-
}
|
|
13
|
+
function freshSectionFlowScope() {
|
|
14
|
+
return {
|
|
15
|
+
root: [],
|
|
16
|
+
headingStack: [],
|
|
17
|
+
listStack: []
|
|
42
18
|
};
|
|
43
|
-
|
|
44
|
-
|
|
19
|
+
}
|
|
20
|
+
function headingScopeOf(scope) {
|
|
21
|
+
return scope.headingStack.at(-1)?.children ?? scope.root;
|
|
22
|
+
}
|
|
23
|
+
function walkSectionFlow(scope, children) {
|
|
24
|
+
for (const child of children) if (isHeadingGroupNode(child)) {
|
|
25
|
+
scope.listStack.length = 0;
|
|
26
|
+
const level = child.node.headingLevel;
|
|
27
|
+
for (let top = scope.headingStack.at(-1); top !== void 0 && top.level >= level; top = scope.headingStack.at(-1)) scope.headingStack.pop();
|
|
28
|
+
const node = {
|
|
29
|
+
text: paragraphText(child.node),
|
|
30
|
+
level,
|
|
31
|
+
children: []
|
|
32
|
+
};
|
|
33
|
+
const parent = scope.headingStack.at(-1);
|
|
34
|
+
(parent !== void 0 ? parent.children : scope.root).push(node);
|
|
35
|
+
scope.headingStack.push(node);
|
|
36
|
+
walkSectionFlow(scope, child.children);
|
|
37
|
+
} else if (isListGroupNode(child)) {
|
|
38
|
+
openListGroup(scope.listStack, headingScopeOf(scope), paragraphText(child.node), child.node.list.level);
|
|
39
|
+
walkSectionFlow(scope, child.children);
|
|
40
|
+
} else if (isSectionConstructGroupNode(child)) {
|
|
41
|
+
const parent = scope.listStack.at(-1);
|
|
42
|
+
(parent !== void 0 ? parent.children : headingScopeOf(scope)).push(...projectSectionFlow(child.children));
|
|
43
|
+
} else if (child.kind === "paragraph") {
|
|
44
|
+
scope.listStack.length = 0;
|
|
45
|
+
headingScopeOf(scope).push(child);
|
|
46
|
+
} else {
|
|
47
|
+
const parent = scope.listStack.at(-1);
|
|
48
|
+
(parent !== void 0 ? parent.children : headingScopeOf(scope)).push(child);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function projectSectionFlow(children) {
|
|
52
|
+
const scope = freshSectionFlowScope();
|
|
53
|
+
walkSectionFlow(scope, children);
|
|
54
|
+
return scope.root;
|
|
55
|
+
}
|
|
56
|
+
function wordprocessingOutline(sections) {
|
|
57
|
+
const scope = freshSectionFlowScope();
|
|
58
|
+
for (const section of sections) walkSectionFlow(scope, section.children);
|
|
59
|
+
return scope.root;
|
|
60
|
+
}
|
|
61
|
+
function walkShapeFlow(listStack, scope, children) {
|
|
62
|
+
for (const child of children) if (isListGroupNode(child)) {
|
|
63
|
+
openListGroup(listStack, scope, paragraphText(child.node), child.node.list.level);
|
|
64
|
+
walkShapeFlow(listStack, scope, child.children);
|
|
65
|
+
} else if (isShapeConstructGroupNode(child)) {
|
|
66
|
+
const parent = listStack.at(-1);
|
|
67
|
+
(parent !== void 0 ? parent.children : scope).push(...projectShapeFlow(child.children));
|
|
68
|
+
} else if (child.kind === "paragraph") {
|
|
69
|
+
listStack.length = 0;
|
|
70
|
+
scope.push(child);
|
|
71
|
+
} else {
|
|
72
|
+
const parent = listStack.at(-1);
|
|
73
|
+
(parent !== void 0 ? parent.children : scope).push(child);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function projectShapeFlow(children) {
|
|
77
|
+
const scope = [];
|
|
78
|
+
walkShapeFlow([], scope, children);
|
|
79
|
+
return scope;
|
|
45
80
|
}
|
|
46
81
|
function presentationOutline(slides) {
|
|
47
82
|
return slides.map((slide, index) => {
|
|
@@ -51,19 +86,7 @@ function presentationOutline(slides) {
|
|
|
51
86
|
children: []
|
|
52
87
|
};
|
|
53
88
|
const listStack = [];
|
|
54
|
-
const
|
|
55
|
-
for (const child of children) if (isListGroupNode(child)) {
|
|
56
|
-
openListGroup(listStack, group.children, paragraphText(child.node), child.node.list.level);
|
|
57
|
-
walk(child.children);
|
|
58
|
-
} else if (child.kind === "paragraph") {
|
|
59
|
-
listStack.length = 0;
|
|
60
|
-
group.children.push(child);
|
|
61
|
-
} else {
|
|
62
|
-
const parent = listStack.at(-1);
|
|
63
|
-
(parent !== void 0 ? parent.children : group.children).push(child);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
for (const shape of slide.children) walk(shape.children);
|
|
89
|
+
for (const shape of slide.children) walkShapeFlow(listStack, group.children, shape.children);
|
|
67
90
|
return group;
|
|
68
91
|
});
|
|
69
92
|
}
|
|
@@ -87,6 +110,7 @@ function flattenShapeChildren(group) {
|
|
|
87
110
|
function flattenListFlow(children) {
|
|
88
111
|
const leaves = [];
|
|
89
112
|
for (const child of children) if (isListGroupNode(child)) leaves.push(child.node, ...flattenListFlow(child.children));
|
|
113
|
+
else if (isShapeConstructGroupNode(child)) leaves.push(...flattenListFlow(child.children));
|
|
90
114
|
else leaves.push(child);
|
|
91
115
|
return leaves;
|
|
92
116
|
}
|
|
@@ -196,6 +220,22 @@ function resolveShapeGroup(styles, chain, group) {
|
|
|
196
220
|
children
|
|
197
221
|
};
|
|
198
222
|
}
|
|
223
|
+
function resolveSectionConstructGroup(styles, chain, group) {
|
|
224
|
+
const children = resolveSectionChildren(styles, chainWithRef(chain, group), group.children);
|
|
225
|
+
if (group.style === void 0 && children === group.children) return group;
|
|
226
|
+
return {
|
|
227
|
+
node: group.node,
|
|
228
|
+
children
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function resolveShapeConstructGroup(styles, chain, group) {
|
|
232
|
+
const children = resolveListChildren(styles, chainWithRef(chain, group), group.children);
|
|
233
|
+
if (group.style === void 0 && children === group.children) return group;
|
|
234
|
+
return {
|
|
235
|
+
node: group.node,
|
|
236
|
+
children
|
|
237
|
+
};
|
|
238
|
+
}
|
|
199
239
|
function resolveHeadingGroup(styles, chain, group) {
|
|
200
240
|
const own = chainWithRef(chain, group);
|
|
201
241
|
const entry = own.length > 0 ? resolveStyleChain(styles, own) : void 0;
|
|
@@ -241,6 +281,7 @@ function resolveSectionChildren(styles, chain, children) {
|
|
|
241
281
|
let resolved;
|
|
242
282
|
if (isHeadingGroupNode(child)) resolved = resolveHeadingGroup(styles, chain, child);
|
|
243
283
|
else if (isListGroupNode(child)) resolved = resolveListGroup(styles, chain, child);
|
|
284
|
+
else if (isSectionConstructGroupNode(child)) resolved = resolveSectionConstructGroup(styles, chain, child);
|
|
244
285
|
else if (child.kind === "paragraph") resolved = resolveParagraphLeaf(styles, chain, child);
|
|
245
286
|
else resolved = child;
|
|
246
287
|
changed ||= resolved !== child;
|
|
@@ -254,6 +295,7 @@ function resolveListChildren(styles, chain, children) {
|
|
|
254
295
|
for (const child of children) {
|
|
255
296
|
let resolved;
|
|
256
297
|
if (isListGroupNode(child)) resolved = resolveListGroup(styles, chain, child);
|
|
298
|
+
else if (isShapeConstructGroupNode(child)) resolved = resolveShapeConstructGroup(styles, chain, child);
|
|
257
299
|
else if (child.kind === "paragraph") resolved = resolveParagraphLeaf(styles, chain, child);
|
|
258
300
|
else resolved = child;
|
|
259
301
|
changed ||= resolved !== child;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-outline.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Utilities for consumers holding a tree-form DocumentPackage - the TOC outline projection, effective-property resolution, and flatten/leaf-text/stable-hash helpers, the outline package for the documents.js family.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/ExaDev/
|
|
8
|
+
"url": "git+https://github.com/ExaDev/documents.js.git",
|
|
9
|
+
"directory": "packages/document-outline.js"
|
|
9
10
|
},
|
|
10
11
|
"homepage": "https://github.com/ExaDev/document-outline.js#readme",
|
|
11
12
|
"bugs": {
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
},
|
|
64
65
|
"packageManager": "pnpm@11.6.0",
|
|
65
66
|
"dependencies": {
|
|
66
|
-
"document-schema.js": "^4.
|
|
67
|
+
"document-schema.js": "^4.3.4",
|
|
67
68
|
"zod": "^4.4.3"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|