@portone/docx-editor 0.2.1 → 0.3.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/CHANGELOG.md +109 -0
- package/CONTRIBUTING.md +5 -1
- package/dist/DocxEditor.d.ts +6 -0
- package/dist/DocxEditor.js +12 -29
- package/dist/core.d.ts +23 -8
- package/dist/core.js +9 -4
- package/dist/docx/cloning.d.ts +38 -0
- package/dist/docx/cloning.js +74 -0
- package/dist/docx/commentOnlyChange.d.ts +12 -7
- package/dist/docx/commentOnlyChange.js +9 -156
- package/dist/docx/comments/constants.d.ts +0 -1
- package/dist/docx/comments/constants.js +0 -2
- package/dist/docx/comments/grammar.d.ts +10 -4
- package/dist/docx/comments/grammar.js +12 -2
- package/dist/docx/comments/{verifying.d.ts → parts.d.ts} +26 -18
- package/dist/docx/comments/parts.js +279 -0
- package/dist/docx/comments/people.d.ts +11 -2
- package/dist/docx/comments/people.js +16 -92
- package/dist/docx/comments/policy.d.ts +7 -0
- package/dist/docx/comments/policy.js +43 -0
- package/dist/docx/comments/reading.js +8 -10
- package/dist/docx/comments/writing.d.ts +19 -7
- package/dist/docx/comments/writing.js +52 -111
- package/dist/docx/documentSettings.d.ts +7 -0
- package/dist/docx/documentSettings.js +10 -2
- package/dist/docx/exportDocx.d.ts +40 -5
- package/dist/docx/exportDocx.js +69 -71
- package/dist/docx/exportRefs.d.ts +5 -2
- package/dist/docx/exportRefs.js +3 -1
- package/dist/docx/fidelity.d.ts +43 -0
- package/dist/docx/fidelity.js +64 -0
- package/dist/docx/formatting/attrs.d.ts +27 -0
- package/dist/docx/formatting/attrs.js +31 -0
- package/dist/docx/formatting/context.d.ts +31 -0
- package/dist/docx/formatting/context.js +42 -0
- package/dist/docx/formatting/direct.d.ts +6 -5
- package/dist/docx/formatting/direct.js +52 -78
- package/dist/docx/formatting/resolve.d.ts +45 -0
- package/dist/docx/formatting/resolve.js +140 -0
- package/dist/docx/formatting/runProperties.d.ts +93 -0
- package/dist/docx/formatting/runProperties.js +316 -0
- package/dist/docx/formatting/styles.js +3 -3
- package/dist/docx/formatting/tabStops.js +7 -22
- package/dist/docx/formatting.d.ts +4 -1
- package/dist/docx/formatting.js +4 -1
- package/dist/docx/headersFooters.js +6 -13
- package/dist/docx/identities.d.ts +67 -0
- package/dist/docx/identities.js +174 -0
- package/dist/docx/importDocx.d.ts +12 -1
- package/dist/docx/importDocx.js +72 -79
- package/dist/docx/importParagraph.d.ts +1 -1
- package/dist/docx/importParagraph.js +4 -3
- package/dist/docx/importTable.d.ts +1 -1
- package/dist/docx/importTable.js +17 -1
- package/dist/docx/invariants.d.ts +33 -0
- package/dist/docx/invariants.js +256 -0
- package/dist/docx/media.d.ts +6 -4
- package/dist/docx/media.js +6 -37
- package/dist/docx/newLists.d.ts +20 -0
- package/dist/docx/newLists.js +36 -0
- package/dist/docx/notes.js +3 -7
- package/dist/docx/numberingPlanner.d.ts +8 -0
- package/dist/docx/numberingPlanner.js +19 -0
- package/dist/docx/packageParts.d.ts +42 -0
- package/dist/docx/packageParts.js +135 -0
- package/dist/docx/pageGeometry.d.ts +2 -0
- package/dist/docx/pageGeometry.js +18 -9
- package/dist/docx/paraProps.d.ts +10 -22
- package/dist/docx/paraProps.js +47 -76
- package/dist/docx/partPlan.d.ts +36 -0
- package/dist/docx/partPlan.js +59 -0
- package/dist/docx/protectionPolicy.d.ts +127 -0
- package/dist/docx/protectionPolicy.js +169 -0
- package/dist/docx/relationships.d.ts +1 -1
- package/dist/docx/relationships.js +8 -13
- package/dist/docx/runProps.d.ts +9 -22
- package/dist/docx/runProps.js +15 -168
- package/dist/docx/scan.js +20 -52
- package/dist/docx/sdt.js +9 -34
- package/dist/docx/sdtProps.d.ts +8 -1
- package/dist/docx/sdtProps.js +10 -0
- package/dist/docx/serializeBlock.d.ts +2 -0
- package/dist/docx/serializeBlock.js +8 -5
- package/dist/docx/serializeTable.js +32 -15
- package/dist/docx/session.d.ts +42 -14
- package/dist/docx/session.js +43 -17
- package/dist/docx/tableFormatting/editing.js +108 -139
- package/dist/docx/tableFormatting/reading.d.ts +16 -6
- package/dist/docx/tableFormatting/reading.js +40 -20
- package/dist/docx/tableTemplate.js +18 -7
- package/dist/download.d.ts +8 -5
- package/dist/download.js +2 -0
- package/dist/editor/clipboard/inlineFormatting.js +19 -30
- package/dist/editor/commands/comments/editing.d.ts +6 -2
- package/dist/editor/commands/comments/editing.js +19 -31
- package/dist/editor/commands/exportQueries.d.ts +15 -0
- package/dist/editor/commands/exportQueries.js +14 -0
- package/dist/editor/commands/fidelityQueries.d.ts +12 -0
- package/dist/editor/commands/fidelityQueries.js +8 -0
- package/dist/editor/commands/formatting/editing.d.ts +2 -2
- package/dist/editor/commands/formatting/editing.js +26 -108
- package/dist/editor/commands/formatting/propertyCommands.d.ts +21 -0
- package/dist/editor/commands/formatting/propertyCommands.js +103 -0
- package/dist/editor/commands/formatting/shared.d.ts +3 -3
- package/dist/editor/commands/formatting/shared.js +5 -2
- package/dist/editor/commands/indentCommands.js +5 -4
- package/dist/editor/commands/index.d.ts +11 -0
- package/dist/editor/commands/index.js +5 -0
- package/dist/editor/commands/linkCommands.js +5 -6
- package/dist/editor/commands/listCommands.js +8 -10
- package/dist/editor/commands/lockCommands.d.ts +7 -1
- package/dist/editor/commands/lockCommands.js +35 -46
- package/dist/editor/commands/paragraphCommands.js +28 -31
- package/dist/editor/commands/spacingCommands.js +1 -1
- package/dist/editor/createEditor.d.ts +17 -29
- package/dist/editor/createEditor.js +58 -58
- package/dist/editor/documentStyles.d.ts +11 -35
- package/dist/editor/documentStyles.js +9 -52
- package/dist/editor/editorDocument.d.ts +56 -0
- package/dist/editor/editorDocument.js +74 -0
- package/dist/editor/externalClipboard.js +16 -45
- package/dist/editor/insertTable.js +4 -3
- package/dist/editor/paragraphEdits.d.ts +11 -18
- package/dist/editor/paragraphEdits.js +7 -16
- package/dist/editor/plugins/displayDerivation.d.ts +47 -0
- package/dist/editor/plugins/displayDerivation.js +78 -0
- package/dist/editor/plugins/imagePaste.js +4 -3
- package/dist/editor/plugins/keymap.js +18 -3
- package/dist/editor/plugins/numberingDecorations.d.ts +5 -11
- package/dist/editor/plugins/numberingDecorations.js +7 -17
- package/dist/editor/plugins/paragraphDisplay.d.ts +7 -0
- package/dist/editor/plugins/paragraphDisplay.js +51 -0
- package/dist/editor/plugins/tabLayout.js +1 -1
- package/dist/editor/plugins/tableDisplay.d.ts +6 -0
- package/dist/editor/plugins/tableDisplay.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/model/format.d.ts +30 -8
- package/dist/model/format.js +35 -22
- package/dist/model/tabStops.d.ts +9 -0
- package/dist/model/tabStops.js +18 -0
- package/dist/numbering/listTemplate.js +24 -7
- package/dist/numbering/parseNumbering.d.ts +14 -1
- package/dist/numbering/parseNumbering.js +35 -22
- package/dist/numbering/writeNumbering.d.ts +3 -4
- package/dist/numbering/writeNumbering.js +14 -25
- package/dist/ooxml/childOrder.d.ts +34 -0
- package/dist/ooxml/childOrder.js +496 -0
- package/dist/ooxml/element.d.ts +24 -11
- package/dist/ooxml/element.js +31 -12
- package/dist/ooxml/errors.d.ts +3 -2
- package/dist/ooxml/image.d.ts +4 -0
- package/dist/ooxml/image.js +2 -5
- package/dist/ooxml/partSplice.d.ts +67 -0
- package/dist/ooxml/partSplice.js +169 -0
- package/dist/ooxml/props.d.ts +112 -0
- package/dist/{docx/propsXml.js → ooxml/props.js} +72 -200
- package/dist/ooxml/simpleTypes.d.ts +103 -0
- package/dist/ooxml/simpleTypes.js +182 -0
- package/dist/ooxml/tabStops.js +8 -27
- package/dist/ooxml/tagScan.d.ts +34 -0
- package/dist/ooxml/tagScan.js +108 -0
- package/dist/ooxml/units.d.ts +25 -13
- package/dist/ooxml/units.js +65 -31
- package/dist/ooxml/xml.d.ts +27 -6
- package/dist/ooxml/xml.js +37 -5
- package/dist/page/blockKinds.d.ts +61 -0
- package/dist/page/blockKinds.js +11 -0
- package/dist/page/kinds/index.d.ts +6 -0
- package/dist/page/kinds/index.js +10 -0
- package/dist/page/kinds/paragraphKind.d.ts +10 -0
- package/dist/page/kinds/paragraphKind.js +71 -0
- package/dist/page/kinds/tableKind.d.ts +10 -0
- package/dist/page/kinds/tableKind.js +178 -0
- package/dist/page/measureBlocks.d.ts +3 -14
- package/dist/page/measureBlocks.js +24 -45
- package/dist/page/pageDecorations.d.ts +27 -44
- package/dist/page/pageDecorations.js +70 -152
- package/dist/page/pageLayout.d.ts +2 -19
- package/dist/page/pageLayout.js +36 -6
- package/dist/page/usePageLayout.d.ts +2 -17
- package/dist/page/usePageLayout.js +3 -39
- package/dist/schema/attrRoles.d.ts +25 -18
- package/dist/schema/attrRoles.js +102 -67
- package/dist/schema/displayDerivation.d.ts +82 -0
- package/dist/schema/displayDerivation.js +130 -0
- package/dist/schema/docxSchema.d.ts +3 -0
- package/dist/schema/docxSchema.js +26 -14
- package/dist/schema/editGuard.d.ts +1 -1
- package/dist/schema/guards.d.ts +37 -14
- package/dist/schema/guards.js +29 -3
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +2 -0
- package/dist/schema/locks.d.ts +11 -44
- package/dist/schema/locks.js +0 -9
- package/dist/schema/preservedGuards.d.ts +26 -6
- package/dist/schema/preservedGuards.js +31 -1
- package/dist/schema/protection.d.ts +7 -1
- package/dist/schema/protection.js +2 -1
- package/dist/schema/sourceEquality.d.ts +1 -9
- package/dist/schema/sourceEquality.js +1 -27
- package/dist/styles/inlineStyle.js +15 -6
- package/dist/table/cellFormatting.d.ts +8 -1
- package/dist/table/cellFormatting.js +10 -18
- package/dist/table/commands.js +20 -18
- package/dist/table/format.d.ts +3 -0
- package/dist/table/format.js +3 -9
- package/dist/table/gridBorders.d.ts +14 -16
- package/dist/table/gridBorders.js +3 -41
- package/dist/table/merge.d.ts +2 -6
- package/dist/table/merge.js +5 -5
- package/package.json +7 -3
- package/dist/docx/comments/contentTypes.d.ts +0 -7
- package/dist/docx/comments/contentTypes.js +0 -38
- package/dist/docx/comments/verifying.js +0 -206
- package/dist/docx/formatting/effectiveParagraph.d.ts +0 -15
- package/dist/docx/formatting/effectiveParagraph.js +0 -81
- package/dist/docx/propsXml.d.ts +0 -67
- package/dist/docx/uniqueControls.d.ts +0 -14
- package/dist/docx/uniqueControls.js +0 -62
- package/dist/editor/plugins/commentReservations.d.ts +0 -5
- package/dist/editor/plugins/commentReservations.js +0 -26
- package/dist/editor/plugins/styledParagraphs.d.ts +0 -15
- package/dist/editor/plugins/styledParagraphs.js +0 -65
- package/dist/page/tableMeasurements.d.ts +0 -18
- package/dist/page/tableMeasurements.js +0 -119
|
@@ -5,6 +5,7 @@ import { keydownHandler } from "prosemirror-keymap";
|
|
|
5
5
|
import { Plugin } from "prosemirror-state";
|
|
6
6
|
import { goToNextCell } from "prosemirror-tables";
|
|
7
7
|
import { canSplit } from "prosemirror-transform";
|
|
8
|
+
import { splitParagraphAttrs } from "../../docx/cloning.js";
|
|
8
9
|
import { toParagraphFormat } from "../../model/format.js";
|
|
9
10
|
import { docxSchema } from "../../schema/index.js";
|
|
10
11
|
import { insertLineBreak, insertPageBreak } from "../commands/breakCommands.js";
|
|
@@ -42,13 +43,27 @@ var splitParagraph = (state, dispatch) => {
|
|
|
42
43
|
const tr = state.tr;
|
|
43
44
|
if (!state.selection.empty) tr.deleteSelection();
|
|
44
45
|
const at = tr.mapping.map(state.selection.$from.pos);
|
|
45
|
-
const
|
|
46
|
+
const $at = tr.doc.resolve(at);
|
|
47
|
+
const parent = $at.parent;
|
|
46
48
|
if (parent.type !== docxSchema.nodes.paragraph) return false;
|
|
47
|
-
const
|
|
49
|
+
const { before, after } = splitParagraphAttrs(parent);
|
|
50
|
+
const types = [{ type: docxSchema.nodes.paragraph, attrs: after }];
|
|
48
51
|
if (!canSplit(tr.doc, at, 1, types)) return false;
|
|
49
|
-
if (dispatch)
|
|
52
|
+
if (dispatch) {
|
|
53
|
+
const beforePos = $at.before();
|
|
54
|
+
tr.split(at, 1, types);
|
|
55
|
+
if (!keptEveryAttr(parent, before)) {
|
|
56
|
+
tr.setNodeMarkup(beforePos, null, before);
|
|
57
|
+
}
|
|
58
|
+
dispatch(tr.scrollIntoView());
|
|
59
|
+
}
|
|
50
60
|
return true;
|
|
51
61
|
};
|
|
62
|
+
function keptEveryAttr(paragraph, attrs) {
|
|
63
|
+
return Object.keys(paragraph.attrs).every(
|
|
64
|
+
(name) => attrs[name] === paragraph.attrs[name]
|
|
65
|
+
);
|
|
66
|
+
}
|
|
52
67
|
var preserveTableFollowingParagraph = (state) => {
|
|
53
68
|
const { $from } = state.selection;
|
|
54
69
|
if (!state.selection.empty || $from.depth !== 1 || $from.parent.type !== docxSchema.nodes.paragraph || $from.parent.content.size !== 0 || $from.parentOffset !== 0) {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Draws list markers and inherited indentation as decorations so display-only values never create
|
|
3
|
-
* new OOXML on export. The
|
|
3
|
+
* new OOXML on export. The definitions the markers are drawn from belong to the document
|
|
4
|
+
* snapshot, and the readers list commands ask stand here beside the drawing.
|
|
4
5
|
*/
|
|
5
6
|
import type { Node as PMNode } from "prosemirror-model";
|
|
6
7
|
import { type EditorState, Plugin } from "prosemirror-state";
|
|
7
8
|
import { DecorationSet } from "prosemirror-view";
|
|
8
|
-
import {
|
|
9
|
+
import type { Numbering } from "../../numbering/parseNumbering";
|
|
9
10
|
/** A number to draw on screen and the paragraph position it attaches to */
|
|
10
11
|
export interface PlacedMarker {
|
|
11
12
|
from: number;
|
|
@@ -22,13 +23,6 @@ export interface PlacedMarker {
|
|
|
22
23
|
/** Walks a document to find the paragraphs that get numbers and what those numbers are */
|
|
23
24
|
export declare function paragraphMarkers(doc: PMNode, numbering: Numbering): PlacedMarker[];
|
|
24
25
|
export declare function markerDecorations(doc: PMNode, numbering: Numbering): DecorationSet;
|
|
25
|
-
/** What the plugin holds: the document's list definitions and the numbers to draw right now */
|
|
26
|
-
interface NumberingState {
|
|
27
|
-
numbering: Numbering;
|
|
28
|
-
/** Whether the document has a place (numbering.xml) to write the definition of a new list */
|
|
29
|
-
canStartNewList: boolean;
|
|
30
|
-
decorations: DecorationSet;
|
|
31
|
-
}
|
|
32
26
|
/** This document's list definitions. Empty when the editor does not know them */
|
|
33
27
|
export declare function documentNumbering(state: EditorState): Numbering;
|
|
34
28
|
/**
|
|
@@ -38,5 +32,5 @@ export declare function documentNumbering(state: EditorState): Numbering;
|
|
|
38
32
|
* in the first place.
|
|
39
33
|
*/
|
|
40
34
|
export declare function canStartNewList(state: EditorState): boolean;
|
|
41
|
-
|
|
42
|
-
export
|
|
35
|
+
/** Draws the numbers this document's lists put in front of their paragraphs */
|
|
36
|
+
export declare function numberingMarkers(): Plugin<DecorationSet>;
|
|
@@ -3,10 +3,8 @@ import { Plugin, PluginKey } from "prosemirror-state";
|
|
|
3
3
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
4
4
|
import { toParagraphFormat } from "../../model/format.js";
|
|
5
5
|
import { computeMarkers } from "../../numbering/markers.js";
|
|
6
|
-
import {
|
|
7
|
-
EMPTY_NUMBERING
|
|
8
|
-
} from "../../numbering/parseNumbering.js";
|
|
9
6
|
import { editorAttributes, editorCssVariables } from "../../styles/classNames.js";
|
|
7
|
+
import { documentOf } from "../editorDocument.js";
|
|
10
8
|
var FALLBACK_MARKER_WIDTH_PT = 18;
|
|
11
9
|
function paragraphSpots(doc) {
|
|
12
10
|
const spots = [];
|
|
@@ -76,28 +74,20 @@ function markerDecorations(doc, numbering) {
|
|
|
76
74
|
}
|
|
77
75
|
var numberingKey = new PluginKey("docxEditorNumbering");
|
|
78
76
|
function documentNumbering(state) {
|
|
79
|
-
return
|
|
77
|
+
return documentOf(state).formatting.numbering;
|
|
80
78
|
}
|
|
81
79
|
function canStartNewList(state) {
|
|
82
|
-
return
|
|
80
|
+
return documentOf(state).canStartNewList;
|
|
83
81
|
}
|
|
84
|
-
function numberingMarkers(
|
|
82
|
+
function numberingMarkers() {
|
|
85
83
|
return new Plugin({
|
|
86
84
|
key: numberingKey,
|
|
87
85
|
state: {
|
|
88
|
-
init: (_config, state) => (
|
|
89
|
-
|
|
90
|
-
canStartNewList: canStartNewList2,
|
|
91
|
-
decorations: markerDecorations(state.doc, numbering)
|
|
92
|
-
}),
|
|
93
|
-
apply: (tr, current) => tr.docChanged ? {
|
|
94
|
-
numbering,
|
|
95
|
-
canStartNewList: canStartNewList2,
|
|
96
|
-
decorations: markerDecorations(tr.doc, numbering)
|
|
97
|
-
} : current
|
|
86
|
+
init: (_config, state) => markerDecorations(state.doc, documentOf(state).formatting.numbering),
|
|
87
|
+
apply: (tr, current, _old, state) => tr.docChanged ? markerDecorations(tr.doc, documentOf(state).formatting.numbering) : current
|
|
98
88
|
},
|
|
99
89
|
props: {
|
|
100
|
-
decorations: (state) => numberingKey.getState(state)
|
|
90
|
+
decorations: (state) => numberingKey.getState(state)
|
|
101
91
|
}
|
|
102
92
|
});
|
|
103
93
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The values a paragraph draws with, read out of the document's styles along the same path the
|
|
3
|
+
* import takes (`docx/formatting`), so that a paragraph an edit built, one it re-aligned and one
|
|
4
|
+
* the file arrived with all carry the same values for the same properties.
|
|
5
|
+
*/
|
|
6
|
+
import type { DocumentDeriver } from "./displayDerivation";
|
|
7
|
+
export declare const paragraphDisplay: DocumentDeriver;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/editor/plugins/paragraphDisplay.ts
|
|
2
|
+
import {
|
|
3
|
+
paragraphAttrsOf,
|
|
4
|
+
resolveParagraph,
|
|
5
|
+
resolveRun
|
|
6
|
+
} from "../../docx/formatting.js";
|
|
7
|
+
import { docxSchema } from "../../schema/index.js";
|
|
8
|
+
import { paragraphPPr } from "../paragraphEdits.js";
|
|
9
|
+
function carriesNothing(node) {
|
|
10
|
+
return node.attrs.format === null && node.attrs.styleRun === null;
|
|
11
|
+
}
|
|
12
|
+
function stands(node, previous) {
|
|
13
|
+
return previous !== null && previous.attrs.pPr === node.attrs.pPr && !carriesNothing(node);
|
|
14
|
+
}
|
|
15
|
+
function holdsComposition(node, pos, composing) {
|
|
16
|
+
return composing !== null && composing >= pos && composing <= pos + node.nodeSize;
|
|
17
|
+
}
|
|
18
|
+
var paragraphDisplay = {
|
|
19
|
+
name: "paragraph",
|
|
20
|
+
nodeTypes: ["paragraph"],
|
|
21
|
+
derive(node, pos, _doc, context, previous) {
|
|
22
|
+
if (stands(node, previous) || holdsComposition(node, pos, context.composingAt)) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const formatting = context.document.formatting;
|
|
26
|
+
const paragraph = resolveParagraph(paragraphPPr(node), formatting);
|
|
27
|
+
const derived = [
|
|
28
|
+
{ pos, attrs: paragraphAttrsOf(paragraph) }
|
|
29
|
+
];
|
|
30
|
+
node.forEach((child, offset) => {
|
|
31
|
+
const mark = docxSchema.marks.run.isInSet(child.marks);
|
|
32
|
+
if (!mark) return;
|
|
33
|
+
const rPr = mark.attrs.rPr;
|
|
34
|
+
derived.push({
|
|
35
|
+
pos: pos + 1 + offset,
|
|
36
|
+
mark: { type: mark.type, to: pos + 1 + offset + child.nodeSize },
|
|
37
|
+
attrs: {
|
|
38
|
+
format: resolveRun(
|
|
39
|
+
typeof rPr === "string" ? rPr : null,
|
|
40
|
+
paragraph,
|
|
41
|
+
formatting
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return derived;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
paragraphDisplay
|
|
51
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/editor/plugins/tabLayout.ts
|
|
2
2
|
import { Plugin } from "prosemirror-state";
|
|
3
3
|
import { DEFAULT_TAB_STOP_PT } from "../../docx/documentSettings.js";
|
|
4
|
+
import { PX_PER_PT } from "../../docx/pageGeometry.js";
|
|
4
5
|
import { toParagraphFormat } from "../../model/format.js";
|
|
5
6
|
import { docxSchema } from "../../schema/index.js";
|
|
6
7
|
import { editorClassNames, editorCssVariables } from "../../styles/classNames.js";
|
|
7
8
|
import { documentDefaultTabStopPt } from "../documentStyles.js";
|
|
8
9
|
import { setTabWidths, tabWidths } from "./tabDecorations.js";
|
|
9
|
-
var PX_PER_PT = 96 / 72;
|
|
10
10
|
var POSITION_EPSILON_PT = 0.01;
|
|
11
11
|
var WIDTH_EPSILON_PX = 0.1;
|
|
12
12
|
var NATURAL_WIDTH_PX = 1e5;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lines a table's cells draw because of where they sit in the grid (`table/gridBorders`),
|
|
3
|
+
* derived again once the grid or the border inputs of the table moved.
|
|
4
|
+
*/
|
|
5
|
+
import type { DocumentDeriver } from "./displayDerivation";
|
|
6
|
+
export declare const tableDisplay: DocumentDeriver;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/editor/plugins/tableDisplay.ts
|
|
2
|
+
import { cellFixes, sameFormattingInputs } from "../../table/gridBorders.js";
|
|
3
|
+
var tableDisplay = {
|
|
4
|
+
name: "table",
|
|
5
|
+
nodeTypes: ["table"],
|
|
6
|
+
derive(table, pos, _doc, _context, previous) {
|
|
7
|
+
if (previous !== null && sameFormattingInputs(previous, table)) return [];
|
|
8
|
+
return cellFixes(table).map((fix) => ({
|
|
9
|
+
pos: pos + 1 + fix.pos,
|
|
10
|
+
attrs: fix.attrs
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
tableDisplay
|
|
16
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export { EditorView } from "prosemirror-view";
|
|
|
15
15
|
export type { DocxEditorHandle, DocxEditorMode, DocxEditorProps, } from "./DocxEditor";
|
|
16
16
|
export { DocxEditor } from "./DocxEditor";
|
|
17
17
|
export type { DocxBytes, DocxSource } from "./docx/importDocx";
|
|
18
|
+
/** What the handle and a `blocked` download report: each reason the document cannot be written, under the code `DocxExportError` would throw it with */
|
|
19
|
+
export type { ExportProblem } from "./docx/invariants";
|
|
18
20
|
export type { DownloadDocxOptions, DownloadDocxResult, } from "./download";
|
|
19
21
|
export { downloadDocx } from "./download";
|
|
20
22
|
export type { CommentAuthor } from "./editor/commands/commentCommands";
|
package/dist/model/format.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* declaration, the checks that let through only the shapes the read functions produce
|
|
12
12
|
* live here alongside them.
|
|
13
13
|
*/
|
|
14
|
-
import type
|
|
14
|
+
import { type TabStop } from "./tabStops";
|
|
15
15
|
declare const ALIGNS: readonly ["left", "center", "right", "justify"];
|
|
16
16
|
export type ParagraphAlign = (typeof ALIGNS)[number];
|
|
17
17
|
declare const VERTICAL_ALIGNS: readonly ["superscript", "subscript"];
|
|
@@ -103,6 +103,11 @@ export interface ParagraphFormat {
|
|
|
103
103
|
* page boundary guides
|
|
104
104
|
*/
|
|
105
105
|
pageBreakBefore?: true;
|
|
106
|
+
/**
|
|
107
|
+
* Set when the document asks for this paragraph to stand on the same page as the start of the
|
|
108
|
+
* block after it (`w:keepNext`). Read by the page boundary guides
|
|
109
|
+
*/
|
|
110
|
+
keepNext?: boolean;
|
|
106
111
|
/** A CSS border in the form `1pt solid #000000` */
|
|
107
112
|
borderTop?: string;
|
|
108
113
|
borderBottom?: string;
|
|
@@ -110,15 +115,26 @@ export interface ParagraphFormat {
|
|
|
110
115
|
borderRight?: string;
|
|
111
116
|
background?: string;
|
|
112
117
|
}
|
|
113
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* The character formatting to render on screen.
|
|
120
|
+
*
|
|
121
|
+
* A toggle the run switches off outright (`w:val="0"`) is false rather than absent: absent means
|
|
122
|
+
* the run says nothing and what the style laid down stands, false is the run beating that style.
|
|
123
|
+
*/
|
|
114
124
|
export interface RunFormat {
|
|
115
|
-
bold?:
|
|
116
|
-
italic?:
|
|
117
|
-
/** The underline kind. Absent
|
|
118
|
-
underline?: UnderlineKind;
|
|
119
|
-
strike?:
|
|
120
|
-
|
|
125
|
+
bold?: boolean;
|
|
126
|
+
italic?: boolean;
|
|
127
|
+
/** The underline kind, or `none` for an underline switched off outright. Absent when the run says nothing */
|
|
128
|
+
underline?: UnderlineKind | "none";
|
|
129
|
+
strike?: boolean;
|
|
130
|
+
/** Two lines through the text (`w:dstrike`). Read from the document and not drawn or edited yet */
|
|
131
|
+
doubleStrike?: boolean;
|
|
132
|
+
smallCaps?: boolean;
|
|
133
|
+
/** Every letter drawn as a capital (`w:caps`). Read from the document and not drawn or edited yet */
|
|
134
|
+
caps?: boolean;
|
|
121
135
|
fontSizePt?: number;
|
|
136
|
+
/** The room added between characters (`w:spacing`), below zero where they are drawn closer. Read from the document and not drawn or edited yet */
|
|
137
|
+
characterSpacingPt?: number;
|
|
122
138
|
/** A CSS font name list in the form `"맑은 고딕","Malgun Gothic"` */
|
|
123
139
|
fontFamily?: string;
|
|
124
140
|
color?: string;
|
|
@@ -133,6 +149,12 @@ export interface RunFormat {
|
|
|
133
149
|
*/
|
|
134
150
|
lang?: string;
|
|
135
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Every key of `RunFormat`, in the order a run's properties are read. The run property table
|
|
154
|
+
* (`docx/formatting/runProperties`) walks this list, which lives here because `model` imports
|
|
155
|
+
* nothing above it.
|
|
156
|
+
*/
|
|
157
|
+
export declare const RUN_FORMAT_KEYS: readonly ["bold", "italic", "strike", "doubleStrike", "smallCaps", "caps", "underline", "fontSizePt", "characterSpacingPt", "fontFamily", "color", "highlight", "background", "verticalAlign", "lang"];
|
|
136
158
|
/**
|
|
137
159
|
* The table formatting to render on screen. The inner lines between cells are folded
|
|
138
160
|
* into the cell formatting
|
package/dist/model/format.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/model/format.ts
|
|
2
|
+
import { TAB_LEADERS, TAB_STOP_ALIGNMENTS } from "./tabStops.js";
|
|
2
3
|
var ALIGNS = ["left", "center", "right", "justify"];
|
|
3
4
|
var VERTICAL_ALIGNS = ["superscript", "subscript"];
|
|
4
5
|
var CELL_VERTICAL_ALIGNS = ["top", "center", "bottom"];
|
|
@@ -56,6 +57,23 @@ function withWidthNumber(width, value) {
|
|
|
56
57
|
if (width.type === "pct") return { type: "pct", fiftieths: value };
|
|
57
58
|
return width;
|
|
58
59
|
}
|
|
60
|
+
var RUN_FORMAT_KEYS = [
|
|
61
|
+
"bold",
|
|
62
|
+
"italic",
|
|
63
|
+
"strike",
|
|
64
|
+
"doubleStrike",
|
|
65
|
+
"smallCaps",
|
|
66
|
+
"caps",
|
|
67
|
+
"underline",
|
|
68
|
+
"fontSizePt",
|
|
69
|
+
"characterSpacingPt",
|
|
70
|
+
"fontFamily",
|
|
71
|
+
"color",
|
|
72
|
+
"highlight",
|
|
73
|
+
"background",
|
|
74
|
+
"verticalAlign",
|
|
75
|
+
"lang"
|
|
76
|
+
];
|
|
59
77
|
function isRecord(value) {
|
|
60
78
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
61
79
|
}
|
|
@@ -89,22 +107,6 @@ function toNumberingRef(value) {
|
|
|
89
107
|
if (typeof numId !== "number" || typeof ilvl !== "number") return null;
|
|
90
108
|
return { numId, ilvl };
|
|
91
109
|
}
|
|
92
|
-
var TAB_ALIGNMENTS = [
|
|
93
|
-
"start",
|
|
94
|
-
"center",
|
|
95
|
-
"end",
|
|
96
|
-
"decimal",
|
|
97
|
-
"num",
|
|
98
|
-
"bar"
|
|
99
|
-
];
|
|
100
|
-
var TAB_LEADERS = [
|
|
101
|
-
"none",
|
|
102
|
-
"dot",
|
|
103
|
-
"hyphen",
|
|
104
|
-
"underscore",
|
|
105
|
-
"heavy",
|
|
106
|
-
"middleDot"
|
|
107
|
-
];
|
|
108
110
|
function toTabStops(value) {
|
|
109
111
|
if (!Array.isArray(value)) return null;
|
|
110
112
|
const stops = [];
|
|
@@ -112,7 +114,9 @@ function toTabStops(value) {
|
|
|
112
114
|
if (!isRecord(entry) || typeof entry.positionPt !== "number" || !Number.isFinite(entry.positionPt)) {
|
|
113
115
|
continue;
|
|
114
116
|
}
|
|
115
|
-
const align =
|
|
117
|
+
const align = TAB_STOP_ALIGNMENTS.find(
|
|
118
|
+
(candidate) => candidate === entry.align
|
|
119
|
+
);
|
|
116
120
|
if (!align) continue;
|
|
117
121
|
const leader = TAB_LEADERS.find((candidate) => candidate === entry.leader);
|
|
118
122
|
stops.push({
|
|
@@ -150,6 +154,7 @@ function toParagraphFormat(value) {
|
|
|
150
154
|
const tabStops = toTabStops(value.tabStops);
|
|
151
155
|
if (tabStops) format.tabStops = tabStops;
|
|
152
156
|
if (value.pageBreakBefore === true) format.pageBreakBefore = true;
|
|
157
|
+
if (typeof value.keepNext === "boolean") format.keepNext = value.keepNext;
|
|
153
158
|
copyBorders(value, format);
|
|
154
159
|
const background = matching(FILL, value.background);
|
|
155
160
|
if (background) format.background = background;
|
|
@@ -158,13 +163,20 @@ function toParagraphFormat(value) {
|
|
|
158
163
|
function toRunFormat(value) {
|
|
159
164
|
if (!isRecord(value)) return null;
|
|
160
165
|
const format = {};
|
|
161
|
-
if (value.bold ===
|
|
162
|
-
if (value.italic ===
|
|
163
|
-
if (value.strike ===
|
|
164
|
-
if (value.
|
|
165
|
-
|
|
166
|
+
if (typeof value.bold === "boolean") format.bold = value.bold;
|
|
167
|
+
if (typeof value.italic === "boolean") format.italic = value.italic;
|
|
168
|
+
if (typeof value.strike === "boolean") format.strike = value.strike;
|
|
169
|
+
if (typeof value.doubleStrike === "boolean")
|
|
170
|
+
format.doubleStrike = value.doubleStrike;
|
|
171
|
+
if (typeof value.smallCaps === "boolean") format.smallCaps = value.smallCaps;
|
|
172
|
+
if (typeof value.caps === "boolean") format.caps = value.caps;
|
|
173
|
+
if (isUnderlineKind(value.underline) || value.underline === "none") {
|
|
174
|
+
format.underline = value.underline;
|
|
175
|
+
}
|
|
166
176
|
if (typeof value.fontSizePt === "number")
|
|
167
177
|
format.fontSizePt = value.fontSizePt;
|
|
178
|
+
if (typeof value.characterSpacingPt === "number")
|
|
179
|
+
format.characterSpacingPt = value.characterSpacingPt;
|
|
168
180
|
const fontFamily = matching(FONT_FAMILY, value.fontFamily);
|
|
169
181
|
if (fontFamily) format.fontFamily = fontFamily;
|
|
170
182
|
const color = matching(HEX_COLOR, value.color);
|
|
@@ -287,6 +299,7 @@ function spanCount(value) {
|
|
|
287
299
|
}
|
|
288
300
|
export {
|
|
289
301
|
NO_FILL,
|
|
302
|
+
RUN_FORMAT_KEYS,
|
|
290
303
|
isHighlightName,
|
|
291
304
|
isUnderlineKind,
|
|
292
305
|
spanCount,
|
package/dist/model/tabStops.d.ts
CHANGED
|
@@ -6,6 +6,15 @@ export interface TabStop {
|
|
|
6
6
|
align: TabAlignment | "bar";
|
|
7
7
|
leader?: TabLeader;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* What a stop may be aligned to, and what it may draw the space it covers with.
|
|
11
|
+
*
|
|
12
|
+
* These are the members of the two unions above, listed so that a reader checking a value against
|
|
13
|
+
* them cannot fall out of step with the types. `ooxml/simpleTypes` builds `ST_TabJc` and
|
|
14
|
+
* `ST_TabTlc` on them, adding the spellings the document writes that the model does not keep.
|
|
15
|
+
*/
|
|
16
|
+
export declare const TAB_STOP_ALIGNMENTS: readonly TabStop["align"][];
|
|
17
|
+
export declare const TAB_LEADERS: readonly TabLeader[];
|
|
9
18
|
/** A tab entry before the paragraph-property hierarchy has been resolved. */
|
|
10
19
|
export type TabStopDirective = TabStop | {
|
|
11
20
|
positionPt: number;
|
package/dist/model/tabStops.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
// src/model/tabStops.ts
|
|
2
|
+
var TAB_STOP_ALIGNMENTS = [
|
|
3
|
+
"start",
|
|
4
|
+
"center",
|
|
5
|
+
"end",
|
|
6
|
+
"decimal",
|
|
7
|
+
"num",
|
|
8
|
+
"bar"
|
|
9
|
+
];
|
|
10
|
+
var TAB_LEADERS = [
|
|
11
|
+
"none",
|
|
12
|
+
"dot",
|
|
13
|
+
"hyphen",
|
|
14
|
+
"underscore",
|
|
15
|
+
"heavy",
|
|
16
|
+
"middleDot"
|
|
17
|
+
];
|
|
2
18
|
function layerTabStopDirectives(base, over) {
|
|
3
19
|
const stops = /* @__PURE__ */ new Map();
|
|
4
20
|
for (const stop of base) {
|
|
@@ -17,6 +33,8 @@ function mergeTabStops(base, over) {
|
|
|
17
33
|
);
|
|
18
34
|
}
|
|
19
35
|
export {
|
|
36
|
+
TAB_LEADERS,
|
|
37
|
+
TAB_STOP_ALIGNMENTS,
|
|
20
38
|
layerTabStopDirectives,
|
|
21
39
|
mergeTabStops
|
|
22
40
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/numbering/listTemplate.ts
|
|
2
2
|
import { elementXml } from "../ooxml/element.js";
|
|
3
3
|
import { wName } from "../ooxml/names.js";
|
|
4
|
+
import { orderedElement } from "../ooxml/props.js";
|
|
4
5
|
var LEVEL_COUNT = 9;
|
|
5
6
|
var MAX_ILVL = LEVEL_COUNT - 1;
|
|
6
7
|
var NUMBER_CYCLE = [
|
|
@@ -61,19 +62,35 @@ function indXml(indent) {
|
|
|
61
62
|
];
|
|
62
63
|
const attrs = slots.filter((slot) => slot[1] !== null).map(([name, twips]) => [wName(name), `${twips}`]);
|
|
63
64
|
if (attrs.length === 0) return "";
|
|
64
|
-
return
|
|
65
|
+
return orderedElement(
|
|
66
|
+
wName("pPr"),
|
|
67
|
+
[],
|
|
68
|
+
[{ name: "ind", xml: elementXml(wName("ind"), attrs) }]
|
|
69
|
+
);
|
|
65
70
|
}
|
|
66
71
|
function levelXml(ilvl, level) {
|
|
67
72
|
const ind = indXml(level.indent);
|
|
68
|
-
return
|
|
73
|
+
return orderedElement(
|
|
69
74
|
wName("lvl"),
|
|
70
75
|
[[wName("ilvl"), `${ilvl}`]],
|
|
71
76
|
[
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
{
|
|
78
|
+
name: "start",
|
|
79
|
+
xml: elementXml(wName("start"), [[wName("val"), `${level.start}`]])
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "numFmt",
|
|
83
|
+
xml: elementXml(wName("numFmt"), [[wName("val"), level.format]])
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "lvlText",
|
|
87
|
+
xml: elementXml(wName("lvlText"), [[wName("val"), level.text]])
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "lvlJc",
|
|
91
|
+
xml: elementXml(wName("lvlJc"), [[wName("val"), "left"]])
|
|
92
|
+
},
|
|
93
|
+
...ind === "" ? [] : [{ name: "pPr", xml: ind }]
|
|
77
94
|
]
|
|
78
95
|
);
|
|
79
96
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* disturbs the file.
|
|
7
7
|
*/
|
|
8
8
|
import type { TabStopDirective } from "../model/tabStops";
|
|
9
|
+
import { type XmlParser } from "../ooxml/xml";
|
|
9
10
|
/** The number formats actually used across every fixture */
|
|
10
11
|
declare const NUMBER_FORMATS: readonly ["decimal", "bullet", "lowerLetter", "upperLetter", "lowerRoman"];
|
|
11
12
|
export type NumberFormat = (typeof NUMBER_FORMATS)[number];
|
|
@@ -61,5 +62,17 @@ export declare const NO_LEVEL_INDENT: LevelIndentPt;
|
|
|
61
62
|
* OOXML rule).
|
|
62
63
|
*/
|
|
63
64
|
export declare function levelIndentPt(indent: LevelIndent | null): LevelIndentPt;
|
|
64
|
-
|
|
65
|
+
/** What a caller may say about reading numbering beyond handing over the XML */
|
|
66
|
+
export interface NumberingOptions {
|
|
67
|
+
/**
|
|
68
|
+
* The parser the numbering XML is read through. Left out, the `DOMParser` global is used, and a
|
|
69
|
+
* runtime carrying none refuses the read with `no-xml-parser`.
|
|
70
|
+
*/
|
|
71
|
+
xmlParser?: XmlParser;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The lists this numbering XML defines. `null` is the document that has no numbering part, which
|
|
75
|
+
* defines none and asks nothing of a parser.
|
|
76
|
+
*/
|
|
77
|
+
export declare function parseNumbering(xml: string | null, options?: NumberingOptions): Numbering;
|
|
65
78
|
export {};
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
// src/numbering/parseNumbering.ts
|
|
2
|
+
import {
|
|
3
|
+
ST_DecimalNumber,
|
|
4
|
+
ST_SignedTwipsMeasure,
|
|
5
|
+
ST_TwipsMeasure
|
|
6
|
+
} from "../ooxml/simpleTypes.js";
|
|
2
7
|
import { readTabStopDirectives } from "../ooxml/tabStops.js";
|
|
3
|
-
import { childValue,
|
|
4
|
-
import {
|
|
8
|
+
import { childValue, twipsToPt, wAttr } from "../ooxml/units.js";
|
|
9
|
+
import {
|
|
10
|
+
childByLocalName,
|
|
11
|
+
elementChildren,
|
|
12
|
+
parseXml,
|
|
13
|
+
withXmlParser
|
|
14
|
+
} from "../ooxml/xml.js";
|
|
5
15
|
var NUMBER_FORMATS = [
|
|
6
16
|
"decimal",
|
|
7
17
|
"bullet",
|
|
@@ -10,11 +20,6 @@ var NUMBER_FORMATS = [
|
|
|
10
20
|
"lowerRoman"
|
|
11
21
|
];
|
|
12
22
|
var EMPTY_NUMBERING = { lists: /* @__PURE__ */ new Map() };
|
|
13
|
-
function toInteger(value) {
|
|
14
|
-
if (value === null) return null;
|
|
15
|
-
const parsed = Number.parseInt(value, 10);
|
|
16
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
17
|
-
}
|
|
18
23
|
function isNumberFormat(value) {
|
|
19
24
|
return NUMBER_FORMATS.some((format) => format === value);
|
|
20
25
|
}
|
|
@@ -22,13 +27,17 @@ function indentOf(lvl) {
|
|
|
22
27
|
const pPr = childByLocalName(lvl, "pPr");
|
|
23
28
|
const ind = pPr ? childByLocalName(pPr, "ind") : null;
|
|
24
29
|
if (!ind) return null;
|
|
25
|
-
const startTwips =
|
|
26
|
-
|
|
30
|
+
const startTwips = ST_SignedTwipsMeasure.parse(
|
|
31
|
+
wAttr(ind, "start") ?? wAttr(ind, "left")
|
|
32
|
+
);
|
|
33
|
+
const endTwips = ST_SignedTwipsMeasure.parse(
|
|
34
|
+
wAttr(ind, "end") ?? wAttr(ind, "right")
|
|
35
|
+
);
|
|
27
36
|
const indent = {
|
|
28
37
|
startTwips,
|
|
29
38
|
endTwips,
|
|
30
|
-
hangingTwips:
|
|
31
|
-
firstLineTwips:
|
|
39
|
+
hangingTwips: ST_TwipsMeasure.parse(wAttr(ind, "hanging")),
|
|
40
|
+
firstLineTwips: ST_TwipsMeasure.parse(wAttr(ind, "firstLine"))
|
|
32
41
|
};
|
|
33
42
|
const empty = startTwips === null && endTwips === null && indent.hangingTwips === null && indent.firstLineTwips === null;
|
|
34
43
|
return empty ? null : indent;
|
|
@@ -38,9 +47,6 @@ var NO_LEVEL_INDENT = {
|
|
|
38
47
|
endPt: null,
|
|
39
48
|
textIndentPt: null
|
|
40
49
|
};
|
|
41
|
-
function twipsToPt(twips) {
|
|
42
|
-
return twips === null ? null : round(twips / 20);
|
|
43
|
-
}
|
|
44
50
|
function levelIndentPt(indent) {
|
|
45
51
|
if (!indent) return NO_LEVEL_INDENT;
|
|
46
52
|
const hangingPt = twipsToPt(indent.hangingTwips);
|
|
@@ -57,7 +63,7 @@ function readLevel(lvl) {
|
|
|
57
63
|
return {
|
|
58
64
|
format: isNumberFormat(format) ? format : "decimal",
|
|
59
65
|
text: childValue(lvl, "lvlText") ?? "",
|
|
60
|
-
start:
|
|
66
|
+
start: ST_DecimalNumber.parse(childValue(lvl, "start")) ?? 1,
|
|
61
67
|
indent: indentOf(lvl),
|
|
62
68
|
...tabStops.length === 0 ? {} : { tabStops }
|
|
63
69
|
};
|
|
@@ -66,23 +72,27 @@ function readLevels(parent) {
|
|
|
66
72
|
const levels = /* @__PURE__ */ new Map();
|
|
67
73
|
for (const child of elementChildren(parent)) {
|
|
68
74
|
if (child.localName !== "lvl") continue;
|
|
69
|
-
const ilvl =
|
|
75
|
+
const ilvl = ST_DecimalNumber.parse(wAttr(child, "ilvl"));
|
|
70
76
|
if (ilvl !== null) levels.set(ilvl, readLevel(child));
|
|
71
77
|
}
|
|
72
78
|
return levels;
|
|
73
79
|
}
|
|
74
80
|
function readList(num, abstractLevels) {
|
|
75
|
-
const abstractNumId =
|
|
81
|
+
const abstractNumId = ST_DecimalNumber.parse(
|
|
82
|
+
childValue(num, "abstractNumId")
|
|
83
|
+
);
|
|
76
84
|
if (abstractNumId === null) return null;
|
|
77
85
|
const levels = new Map(abstractLevels.get(abstractNumId) ?? []);
|
|
78
86
|
for (const child of elementChildren(num)) {
|
|
79
87
|
if (child.localName !== "lvlOverride") continue;
|
|
80
|
-
const ilvl =
|
|
88
|
+
const ilvl = ST_DecimalNumber.parse(wAttr(child, "ilvl"));
|
|
81
89
|
if (ilvl === null) continue;
|
|
82
90
|
const replacement = childByLocalName(child, "lvl");
|
|
83
91
|
const base = replacement ? readLevel(replacement) : levels.get(ilvl);
|
|
84
92
|
if (!base) continue;
|
|
85
|
-
const startOverride =
|
|
93
|
+
const startOverride = ST_DecimalNumber.parse(
|
|
94
|
+
childValue(child, "startOverride")
|
|
95
|
+
);
|
|
86
96
|
levels.set(
|
|
87
97
|
ilvl,
|
|
88
98
|
startOverride === null ? base : { ...base, start: startOverride }
|
|
@@ -90,19 +100,22 @@ function readList(num, abstractLevels) {
|
|
|
90
100
|
}
|
|
91
101
|
return { levels };
|
|
92
102
|
}
|
|
93
|
-
function parseNumbering(xml) {
|
|
103
|
+
function parseNumbering(xml, options) {
|
|
94
104
|
if (xml === null) return EMPTY_NUMBERING;
|
|
105
|
+
return withXmlParser(options?.xmlParser, () => readNumbering(xml));
|
|
106
|
+
}
|
|
107
|
+
function readNumbering(xml) {
|
|
95
108
|
const root = parseXml(xml).documentElement;
|
|
96
109
|
const abstractLevels = /* @__PURE__ */ new Map();
|
|
97
110
|
for (const child of elementChildren(root)) {
|
|
98
111
|
if (child.localName !== "abstractNum") continue;
|
|
99
|
-
const id =
|
|
112
|
+
const id = ST_DecimalNumber.parse(wAttr(child, "abstractNumId"));
|
|
100
113
|
if (id !== null) abstractLevels.set(id, readLevels(child));
|
|
101
114
|
}
|
|
102
115
|
const lists = /* @__PURE__ */ new Map();
|
|
103
116
|
for (const child of elementChildren(root)) {
|
|
104
117
|
if (child.localName !== "num") continue;
|
|
105
|
-
const numId =
|
|
118
|
+
const numId = ST_DecimalNumber.parse(wAttr(child, "numId"));
|
|
106
119
|
const list = numId === null ? null : readList(child, abstractLevels);
|
|
107
120
|
if (numId !== null && list) lists.set(numId, list);
|
|
108
121
|
}
|