@stll/folio-core 0.73.0 → 0.75.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/dist/ai-edits/clean-text.d.ts +4 -1
- package/dist/ai-edits/clean-text.js +21 -7
- package/dist/ai-edits/headless.d.ts +5 -2
- package/dist/ai-edits/headless.js +20 -14
- package/dist/ai-edits/note-references.d.ts +1 -1
- package/dist/ai-edits/note-references.js +1 -1
- package/dist/ai-edits/pending-suggestions.d.ts +9 -7
- package/dist/ai-edits/pending-suggestions.js +134 -88
- package/dist/ai-edits/pendingJoin.d.ts +5 -1
- package/dist/ai-edits/pendingJoin.js +12 -3
- package/dist/ai-edits/result-validation.js +1 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +2 -2
- package/dist/ai-edits/retired-comment-receipts.js +3 -18
- package/dist/ai-edits/snapshot.js +1 -1
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +6 -10
- package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
- package/dist/canonical/canonicalBatchReview.d.ts +4 -1
- package/dist/canonical/canonicalBatchReview.js +32 -14
- package/dist/canonical/canonicalComments.d.ts +6 -2
- package/dist/canonical/canonicalComments.js +8 -4
- package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
- package/dist/canonical/canonicalInlineGaps.js +118 -0
- package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
- package/dist/canonical/canonicalInlineProjection.js +6 -28
- package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
- package/dist/canonical/canonicalPublicOperations.js +99 -36
- package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
- package/dist/canonical/canonicalRefusalGrounds.js +56 -0
- package/dist/canonical/canonicalSelection.js +1 -1
- package/dist/canonical/canonicalSession.d.ts +12 -6
- package/dist/canonical/canonicalSession.js +129 -141
- package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
- package/dist/compare/inline-atoms.d.ts +35 -41
- package/dist/compare/inline-atoms.js +2 -465
- package/dist/compare/section-boundary-properties.d.ts +3 -30
- package/dist/compare/section-boundary-properties.js +4 -72
- package/dist/controller/autocompleteSuggestion.js +1 -1
- package/dist/controller/canonicalClipboard.js +45 -44
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +6 -6
- package/dist/controller/canonicalInput.d.ts +4 -2
- package/dist/controller/canonicalInput.js +34 -17
- package/dist/controller/canonicalPresence.js +1 -1
- package/dist/controller/canonicalRoomAuthority.js +1 -1
- package/dist/controller/canonicalRoomWire.js +1 -1
- package/dist/controller/canonicalStoryEditor.d.ts +2 -3
- package/dist/controller/canonicalStoryEditor.js +43 -25
- package/dist/controller/canonicalStructure.d.ts +19 -2
- package/dist/controller/canonicalStructure.js +140 -43
- package/dist/controller/canonicalTabRoom.js +1 -1
- package/dist/controller/canonicalYjsRoom.js +1 -1
- package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
- package/dist/controller/deferredDisplayListPainter.js +34 -0
- package/dist/controller/folioEditor.js +4 -2
- package/dist/controller/headerFooterEditorManager.js +3 -17
- package/dist/controller/hiddenEditorApi.d.ts +24 -3
- package/dist/controller/hiddenEditorApi.js +4 -17
- package/dist/controller/hiddenEditorManager.js +136 -197
- package/dist/controller/layoutPipeline.d.ts +4 -86
- package/dist/controller/layoutPipeline.js +8 -727
- package/dist/controller/layoutPipelineExecution.d.ts +94 -0
- package/dist/controller/layoutPipelineExecution.js +730 -0
- package/dist/controller/noteEditorManager.js +3 -16
- package/dist/document-operations.js +1 -1
- package/dist/docx/blockContentParser.d.ts +1 -3
- package/dist/docx/blockContentParser.js +3 -10
- package/dist/docx/canonicalSave.d.ts +4 -3
- package/dist/docx/canonicalSave.js +4 -3
- package/dist/docx/canonicalSessionInput.js +1 -1
- package/dist/docx/containerChildren.js +1 -1
- package/dist/docx/createDocx.d.ts +4 -0
- package/dist/docx/createDocx.js +6 -0
- package/dist/docx/listMarkerComputation.d.ts +24 -17
- package/dist/docx/listMarkerComputation.js +31 -60
- package/dist/docx/listModelNormalization.js +8 -15
- package/dist/docx/modelValidation.js +1 -1
- package/dist/docx/parser.js +1 -1
- package/dist/docx/reviewResolutionProvenance.js +1 -1
- package/dist/docx/rezip.d.ts +16 -3
- package/dist/docx/rezip.js +36 -10
- package/dist/docx/selectiveSave.js +13 -5
- package/dist/docx/serializer/borderSerializer.js +1 -1
- package/dist/docx/serializer/commentSerializer.js +1 -1
- package/dist/docx/serializer/documentSerializer.js +1 -1
- package/dist/docx/serializer/paragraphSerializer.js +3 -3
- package/dist/docx/serializer/runSerializer.js +1 -1
- package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +1 -1
- package/dist/docx/serializer/textFormattingSerializer.js +1 -1
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
- package/dist/docx/server/templatePlan/apply.js +107 -14
- package/dist/docx/server/templatePlan/blocks.d.ts +16 -1
- package/dist/docx/server/templatePlan/blocks.js +93 -7
- package/dist/docx/server/templatePlan/builders.d.ts +37 -2
- package/dist/docx/server/templatePlan/builders.js +196 -5
- package/dist/docx/server/templatePlan/emit.d.ts +2 -0
- package/dist/docx/server/templatePlan/emit.js +2 -0
- package/dist/docx/server/templatePlan/inspect.js +81 -61
- package/dist/docx/server/templatePlan/labels.d.ts +16 -2
- package/dist/docx/server/templatePlan/labels.js +131 -20
- package/dist/docx/server/templatePlan/plan.d.ts +15 -1
- package/dist/docx/server/templatePlan/plan.js +62 -13
- package/dist/docx/server/templatePlan/planShape.js +52 -4
- package/dist/docx/server/templatePlan/story.d.ts +8 -0
- package/dist/docx/server/templatePlan/story.js +11 -1
- package/dist/docx/server/templatePlan/types.d.ts +176 -18
- package/dist/docx/server/templatePlan/types.js +1 -0
- package/dist/docx/server/templatePlan/verify.js +60 -11
- package/dist/docx/server/templatePlan/xml.d.ts +5 -0
- package/dist/docx/server/templatePlan/xml.js +7 -1
- package/dist/docx/storyBlockReplay.js +1 -1
- package/dist/docx/xmlParser.js +1 -1
- package/dist/i18n/loadMessages.d.ts +5 -0
- package/dist/i18n/loadMessages.js +46 -0
- package/dist/i18n/locales.d.ts +3 -0
- package/dist/i18n/locales.js +17 -0
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/i18n/messages.d.ts +3 -2
- package/dist/i18n/messages.js +4 -16
- package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
- package/dist/internal/clipboardTransformPlugin.js +13 -0
- package/dist/internal/extensionRuntime.d.ts +7 -0
- package/dist/internal/extensionRuntime.js +28 -0
- package/dist/internal/paragraphFormattingSerialization.js +1 -1
- package/dist/internal/starterKitExtensions.d.ts +20 -0
- package/dist/internal/starterKitExtensions.js +123 -0
- package/dist/internal/wholeStoryRevisionResolution.js +2 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
- package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
- package/dist/prosemirror/attrs/index.js +1 -1
- package/dist/prosemirror/canonicalSelectionRange.js +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -1
- package/dist/prosemirror/commands/comments.js +3 -3
- package/dist/prosemirror/commands/contentControls.js +1 -1
- package/dist/prosemirror/commands/pastePlainText.js +2 -3
- package/dist/prosemirror/commands/replaceRangeText.js +1 -1
- package/dist/prosemirror/commentRecords.js +2 -2
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
- package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/index.js +2 -2
- package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
- package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
- package/dist/prosemirror/extensions/StarterKit.js +29 -115
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +2 -2
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/index.d.ts +2 -1
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +7 -40
- package/dist/prosemirror/hyperlinkRemoval.js +7 -2
- package/dist/prosemirror/index.d.ts +2 -2
- package/dist/prosemirror/index.js +2 -2
- package/dist/prosemirror/keptRangeBoundaries.js +1 -1
- package/dist/prosemirror/listMarker.d.ts +1 -6
- package/dist/prosemirror/listMarker.js +4 -56
- package/dist/prosemirror/listNumbering.js +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
- package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
- package/dist/prosemirror/noteReferenceReview.js +2 -243
- package/dist/prosemirror/pastedCommentCopies.js +1 -1
- package/dist/prosemirror/plugins/documentNumbering.js +1 -1
- package/dist/prosemirror/plugins/documentStyles.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -1
- package/dist/prosemirror/suggestionCommands.d.ts +47 -0
- package/dist/prosemirror/suggestionCommands.js +31 -0
- package/dist/prosemirror/tableCellPaste.js +1 -1
- package/dist/prosemirror/tableRunIn.js +1 -1
- package/dist/prosemirror/textInput.js +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +42 -93
- package/dist/types/canonicalCapabilities.js +53 -91
- package/dist/types/canonicalComments.d.ts +2 -2
- package/dist/types/canonicalSections.d.ts +2 -2
- package/dist/utils/clipboard.d.ts +2 -28
- package/dist/utils/clipboard.js +1 -96
- package/dist/utils/clipboardFiles.d.ts +27 -0
- package/dist/utils/clipboardFiles.js +98 -0
- package/dist/utils/rulerControl.d.ts +1 -0
- package/dist/utils/rulerControl.js +2 -1
- package/package.json +2 -2
- package/dist/ai-edits/apply.d.ts +0 -94
- package/dist/ai-edits/apply.js +0 -6637
- package/dist/ai-edits/note-story-inventory.d.ts +0 -5
- package/dist/ai-edits/note-story-inventory.js +0 -10
- package/dist/ai-edits/revisionStretches.d.ts +0 -32
- package/dist/ai-edits/revisionStretches.js +0 -147
- package/dist/document-operations-apply.d.ts +0 -15
- package/dist/document-operations-apply.js +0 -280
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -12
- package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -114
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +0 -23
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -270
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -51
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -411
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
- package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
- package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NumberingMap } from "../../numberingParser.js";
|
|
2
2
|
import { StyleMap } from "../../styleParser.js";
|
|
3
3
|
import { DocxBlockNumbering } from "./types.js";
|
|
4
|
-
import { ParagraphNumberingOverride } from "@stll/docx-core/model";
|
|
4
|
+
import { LevelSuffix, ParagraphNumberingOverride } from "@stll/docx-core/model";
|
|
5
5
|
export type ParagraphLabel = {
|
|
6
6
|
label: string | null;
|
|
7
7
|
numbering: DocxBlockNumbering | null;
|
|
@@ -12,6 +12,16 @@ export type ParagraphLabel = {
|
|
|
12
12
|
numberOnly: string | null;
|
|
13
13
|
/** The label as a `REF \n` field shows it: without a trailing period. */
|
|
14
14
|
paragraphNumber: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* The label and what its list puts after it, when the label can stand as
|
|
17
|
+
* text: it reads the same wherever the file is opened. Null for a bullet,
|
|
18
|
+
* whose glyph belongs to a font, for a number a language spells out, and
|
|
19
|
+
* for an ordinal in a language whose way of writing it is not known.
|
|
20
|
+
*/
|
|
21
|
+
asText: {
|
|
22
|
+
label: string;
|
|
23
|
+
suffix: LevelSuffix;
|
|
24
|
+
} | null;
|
|
15
25
|
};
|
|
16
26
|
/**
|
|
17
27
|
* The numbering a style binds its paragraphs to. A style that names a list
|
|
@@ -23,6 +33,8 @@ export type LabelCounter = {
|
|
|
23
33
|
next: (paragraph: {
|
|
24
34
|
styleId: string | null;
|
|
25
35
|
numPr: ParagraphNumberingOverride | undefined;
|
|
36
|
+
/** The language the paragraph mark states itself, or null. */
|
|
37
|
+
language?: string | null;
|
|
26
38
|
}) => ParagraphLabel;
|
|
27
39
|
};
|
|
28
40
|
type LabelCounterOptions = {
|
|
@@ -30,7 +42,9 @@ type LabelCounterOptions = {
|
|
|
30
42
|
styles: StyleMap;
|
|
31
43
|
/** The style a paragraph without `w:pStyle` takes. */
|
|
32
44
|
defaultStyleId: string | null;
|
|
45
|
+
/** The language the document defaults give every run. */
|
|
46
|
+
defaultLanguage?: string | null;
|
|
33
47
|
};
|
|
34
48
|
/** A counter over one story; call `next` for every paragraph in document order. */
|
|
35
|
-
export declare const createLabelCounter: ({ numbering, styles, defaultStyleId }: LabelCounterOptions) => LabelCounter;
|
|
49
|
+
export declare const createLabelCounter: ({ numbering, styles, defaultStyleId, defaultLanguage }: LabelCounterOptions) => LabelCounter;
|
|
36
50
|
export {};
|
|
@@ -12,7 +12,29 @@ const NO_LABEL = {
|
|
|
12
12
|
label: null,
|
|
13
13
|
numbering: null,
|
|
14
14
|
numberOnly: null,
|
|
15
|
-
paragraphNumber: null
|
|
15
|
+
paragraphNumber: null,
|
|
16
|
+
asText: null
|
|
17
|
+
};
|
|
18
|
+
/** Counter formats every consumer and language writes with the same characters. */
|
|
19
|
+
const PLAIN_FORMATS = /* @__PURE__ */ new Set([
|
|
20
|
+
"decimal",
|
|
21
|
+
"decimalZero",
|
|
22
|
+
"upperRoman",
|
|
23
|
+
"lowerRoman",
|
|
24
|
+
"upperLetter",
|
|
25
|
+
"lowerLetter"
|
|
26
|
+
]);
|
|
27
|
+
const LEVEL_PLACEHOLDER = /%([1-9])/gu;
|
|
28
|
+
const labelAsText = ({ label, template, levelFormats, suffix, ordinalKnown }) => {
|
|
29
|
+
if (label.trim() === "") return null;
|
|
30
|
+
for (const [, digit] of template.matchAll(LEVEL_PLACEHOLDER)) {
|
|
31
|
+
const format = levelFormats?.[Number(digit) - 1];
|
|
32
|
+
if (!(format !== void 0 && (PLAIN_FORMATS.has(format) || format === "ordinal" && ordinalKnown))) return null;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
label,
|
|
36
|
+
suffix: suffix ?? "tab"
|
|
37
|
+
};
|
|
16
38
|
};
|
|
17
39
|
/**
|
|
18
40
|
* The numbering a style binds its paragraphs to. A style that names a list
|
|
@@ -40,17 +62,69 @@ const styleNumbering = (styleId, styles, numbering) => {
|
|
|
40
62
|
return stated;
|
|
41
63
|
};
|
|
42
64
|
const stripTrailingPeriods = (value) => value.replace(/\.+$/u, "");
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
65
|
+
/**
|
|
66
|
+
* The `ordinal` format by the language of the paragraph mark, as the
|
|
67
|
+
* reference consumer prints it: Czech and German write the number with a
|
|
68
|
+
* period, French `1er` and `2e`, English `1st`. A language not listed here
|
|
69
|
+
* has no entry: its ordinals are not known to be any of these.
|
|
70
|
+
*/
|
|
71
|
+
const ORDINALS = {
|
|
72
|
+
cs: (value) => `${String(value)}.`,
|
|
73
|
+
de: (value) => `${String(value)}.`,
|
|
74
|
+
fr: (value) => value === 1 ? "1er" : `${String(value)}e`
|
|
75
|
+
};
|
|
76
|
+
const primaryLanguage = (language) => language === null ? null : language.split(/[-_]/u).at(0)?.toLowerCase() ?? null;
|
|
77
|
+
/** A level text over its counters, ordinals written by the language. */
|
|
78
|
+
const renderLabel = ({ template, counters, levelFormats, forceDecimal, language }) => {
|
|
79
|
+
const rendered = resolveListTemplateWithComponents({
|
|
46
80
|
template,
|
|
47
81
|
counters,
|
|
48
82
|
levelFormats,
|
|
49
83
|
forceDecimal
|
|
50
84
|
});
|
|
85
|
+
const isOrdinal = (level) => !forceDecimal && levelFormats?.[level] === "ordinal";
|
|
86
|
+
const hasOrdinal = rendered.components.some(({ level }) => isOrdinal(level));
|
|
87
|
+
const primary = primaryLanguage(language);
|
|
88
|
+
const ordinal = primary === null ? void 0 : ORDINALS[primary];
|
|
89
|
+
if (!hasOrdinal || ordinal === void 0) return {
|
|
90
|
+
...rendered,
|
|
91
|
+
byLanguage: hasOrdinal,
|
|
92
|
+
known: !hasOrdinal || primary === "en"
|
|
93
|
+
};
|
|
94
|
+
let value = "";
|
|
95
|
+
let cursor = 0;
|
|
96
|
+
const components = rendered.components.map((component) => {
|
|
97
|
+
const { level, start, end } = component;
|
|
98
|
+
value += rendered.value.slice(cursor, start);
|
|
99
|
+
cursor = end;
|
|
100
|
+
const written = isOrdinal(level) ? ordinal(counters[level] ?? 0) : rendered.value.slice(start, end);
|
|
101
|
+
const moved = {
|
|
102
|
+
...component,
|
|
103
|
+
start: value.length
|
|
104
|
+
};
|
|
105
|
+
value += written;
|
|
106
|
+
return {
|
|
107
|
+
...moved,
|
|
108
|
+
end: value.length
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
value += rendered.value.slice(cursor);
|
|
112
|
+
return {
|
|
113
|
+
value,
|
|
114
|
+
components,
|
|
115
|
+
byLanguage: true,
|
|
116
|
+
known: true
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Drop the literal runs of a level text that hold a letter. Of the others
|
|
121
|
+
* a `\t` field keeps the delimiters and drops the blanks: `Part %1 -` gives
|
|
122
|
+
* `B-`.
|
|
123
|
+
*/
|
|
124
|
+
const numberOnlyLabel = ({ value, components }) => {
|
|
51
125
|
let out = "";
|
|
52
126
|
let cursor = 0;
|
|
53
|
-
const literal = (text) => /\p{L}/u.test(text) ? "" : text;
|
|
127
|
+
const literal = (text) => /\p{L}/u.test(text) ? "" : text.replaceAll(/\s+/gu, "");
|
|
54
128
|
for (const { start, end } of components) {
|
|
55
129
|
out += literal(value.slice(cursor, start)) + value.slice(start, end);
|
|
56
130
|
cursor = end;
|
|
@@ -58,20 +132,47 @@ const numberOnlyLabel = ({ template, counters, levelFormats, forceDecimal }) =>
|
|
|
58
132
|
out += literal(value.slice(cursor));
|
|
59
133
|
return stripTrailingPeriods(out.trim());
|
|
60
134
|
};
|
|
135
|
+
/**
|
|
136
|
+
* The language each style gives a paragraph mark: its own, or the one of
|
|
137
|
+
* the nearest style it is based on. Resolved once per style, so a long
|
|
138
|
+
* `basedOn` chain is walked once however many paragraphs use it.
|
|
139
|
+
*/
|
|
140
|
+
const createStyleLanguages = (styles) => {
|
|
141
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
142
|
+
return (styleId) => {
|
|
143
|
+
if (styleId === null) return null;
|
|
144
|
+
const walked = /* @__PURE__ */ new Set();
|
|
145
|
+
let language = null;
|
|
146
|
+
let cursor = styleId;
|
|
147
|
+
while (cursor !== void 0 && !walked.has(cursor)) {
|
|
148
|
+
const known = resolved.get(cursor);
|
|
149
|
+
if (known !== void 0) {
|
|
150
|
+
language = known;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
walked.add(cursor);
|
|
154
|
+
const style = styles.get(cursor);
|
|
155
|
+
const stated = style?.rPr?.language?.val;
|
|
156
|
+
if (stated !== void 0) {
|
|
157
|
+
language = stated;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
cursor = style?.basedOn;
|
|
161
|
+
}
|
|
162
|
+
for (const id of walked) resolved.set(id, language);
|
|
163
|
+
return language;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
61
166
|
/** A counter over one story; call `next` for every paragraph in document order. */
|
|
62
|
-
const createLabelCounter = ({ numbering, styles, defaultStyleId }) => {
|
|
167
|
+
const createLabelCounter = ({ numbering, styles, defaultStyleId, defaultLanguage = null }) => {
|
|
63
168
|
const counters = {
|
|
64
169
|
numbering,
|
|
65
170
|
listCounters: /* @__PURE__ */ new Map(),
|
|
66
171
|
abstractCounters: /* @__PURE__ */ new Map(),
|
|
67
|
-
|
|
68
|
-
previousList: {
|
|
69
|
-
abstractNumId: null,
|
|
70
|
-
fromStyle: false,
|
|
71
|
-
numId: null
|
|
72
|
-
}
|
|
172
|
+
startedLevels: /* @__PURE__ */ new Set()
|
|
73
173
|
};
|
|
74
|
-
|
|
174
|
+
const styleLanguage = createStyleLanguages(styles);
|
|
175
|
+
return { next: ({ styleId, numPr, language = null }) => {
|
|
75
176
|
const fromStyle = styleNumbering(styleId ?? defaultStyleId, styles, numbering);
|
|
76
177
|
const inherits = fromStyle !== void 0 && (numPr === void 0 || numPr.kind === "levelOnly");
|
|
77
178
|
const effective = inherits ? mergeParagraphNumbering(fromStyle, numPr) : numPr;
|
|
@@ -94,7 +195,14 @@ const createLabelCounter = ({ numbering, styles, defaultStyleId }) => {
|
|
|
94
195
|
const advance = computeListMarker(paragraph, counters);
|
|
95
196
|
if (advance === null || listRendering === null || numbering === null || resolved.kind !== "reference") return NO_LABEL;
|
|
96
197
|
const abstractNumId = numbering.getAbstractNumId(resolved.numId);
|
|
97
|
-
const
|
|
198
|
+
const rendered = renderLabel({
|
|
199
|
+
template,
|
|
200
|
+
counters: advance.counters,
|
|
201
|
+
levelFormats: listRendering.levelNumFmts,
|
|
202
|
+
forceDecimal: listRendering.isLegal === true,
|
|
203
|
+
language: language ?? styleLanguage(styleId ?? defaultStyleId) ?? defaultLanguage
|
|
204
|
+
});
|
|
205
|
+
const label = rendered.byLanguage && rendered.known ? rendered.value : listRendering.marker;
|
|
98
206
|
const numberingInfo = abstractNumId === null ? null : {
|
|
99
207
|
numId: resolved.numId,
|
|
100
208
|
ilvl: resolved.ilvl,
|
|
@@ -108,18 +216,21 @@ const createLabelCounter = ({ numbering, styles, defaultStyleId }) => {
|
|
|
108
216
|
label,
|
|
109
217
|
numbering: numberingInfo,
|
|
110
218
|
numberOnly: null,
|
|
111
|
-
paragraphNumber: null
|
|
219
|
+
paragraphNumber: null,
|
|
220
|
+
asText: null
|
|
112
221
|
};
|
|
113
222
|
return {
|
|
114
223
|
label,
|
|
115
224
|
numbering: numberingInfo,
|
|
116
|
-
|
|
117
|
-
|
|
225
|
+
asText: labelAsText({
|
|
226
|
+
label,
|
|
118
227
|
template,
|
|
119
|
-
counters: advance.counters,
|
|
120
228
|
levelFormats: listRendering.levelNumFmts,
|
|
121
|
-
|
|
122
|
-
|
|
229
|
+
suffix: listRendering.markerSuffix,
|
|
230
|
+
ordinalKnown: rendered.known
|
|
231
|
+
}),
|
|
232
|
+
paragraphNumber: stripTrailingPeriods(label.trim()),
|
|
233
|
+
numberOnly: numberOnlyLabel(rendered)
|
|
123
234
|
};
|
|
124
235
|
} };
|
|
125
236
|
};
|
|
@@ -9,7 +9,7 @@ import { AnalyzedBlock, AnalyzedDocument } from "./blocks.js";
|
|
|
9
9
|
import { BookmarkWrap } from "./builders.js";
|
|
10
10
|
import { StoryOrigin } from "./resources.js";
|
|
11
11
|
import { AtomKind, AtomLink, InlineAtom, ParagraphRead, StoryField } from "./story.js";
|
|
12
|
-
import { TemplatePlan, TemplatePlanError, TemplatePlanOmitReason, TemplatePlanReference } from "./types.js";
|
|
12
|
+
import { TemplatePlan, TemplatePlanError, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection } from "./types.js";
|
|
13
13
|
import { Result } from "better-result";
|
|
14
14
|
export type ExpectedPiece = {
|
|
15
15
|
kind: AtomKind;
|
|
@@ -53,6 +53,8 @@ export type ResolvedNumbering = {
|
|
|
53
53
|
export type ResolvedPart = {
|
|
54
54
|
block: AnalyzedBlock;
|
|
55
55
|
strippedPrefix: string;
|
|
56
|
+
/** The automatic label written as text before the part, or null. */
|
|
57
|
+
labelAsText: string | null;
|
|
56
58
|
};
|
|
57
59
|
export type ResolvedParagraph = {
|
|
58
60
|
parts: ResolvedPart[];
|
|
@@ -65,10 +67,22 @@ export type ResolvedParagraph = {
|
|
|
65
67
|
signatures: string[];
|
|
66
68
|
inlineObjects: number;
|
|
67
69
|
placement: "body" | "nested" | "slot";
|
|
70
|
+
/** Whether the paragraph starts on a new page. */
|
|
71
|
+
pageBreakBefore: boolean;
|
|
72
|
+
/** The section the paragraph is the last of, or null. */
|
|
73
|
+
endsSection: TemplatePlanSection | null;
|
|
68
74
|
};
|
|
69
75
|
export type ResolvedItem = {
|
|
70
76
|
kind: "template";
|
|
71
77
|
block: AnalyzedBlock;
|
|
78
|
+
} |
|
|
79
|
+
/**
|
|
80
|
+
* An empty paragraph the writer adds, in no plan: between two tables that
|
|
81
|
+
* would otherwise stand next to each other and read as one, and after a
|
|
82
|
+
* table that would end the body.
|
|
83
|
+
*/
|
|
84
|
+
{
|
|
85
|
+
kind: "separator";
|
|
72
86
|
} | {
|
|
73
87
|
kind: "paragraph";
|
|
74
88
|
paragraph: ResolvedParagraph;
|
|
@@ -6,7 +6,7 @@ import { emphasisDeviation, emphasisSignature, paragraphBaseline, readDirectEmph
|
|
|
6
6
|
import { styleNumbering } from "./labels.js";
|
|
7
7
|
import { PLAN_HIGHLIGHT_COLORS, planShapeIssue } from "./planShape.js";
|
|
8
8
|
import { TemplatePlanError } from "./types.js";
|
|
9
|
-
import { isW, maxOf, wAttr, wChildVal, walkElements } from "./xml.js";
|
|
9
|
+
import { isW, maxOf, wAttr, wChild, wChildVal, walkElements } from "./xml.js";
|
|
10
10
|
import { Result } from "better-result";
|
|
11
11
|
// src/docx/server/templatePlan/plan.ts
|
|
12
12
|
/**
|
|
@@ -300,6 +300,30 @@ const piecesContent = (pieces) => {
|
|
|
300
300
|
signatures
|
|
301
301
|
};
|
|
302
302
|
};
|
|
303
|
+
const isTableItem = (item) => item.kind === "table" || item.kind === "template" && item.block.block.kind === "table";
|
|
304
|
+
/** Puts a separator between two neighbouring tables and after a last one. */
|
|
305
|
+
const partTables = (items) => {
|
|
306
|
+
for (let index = items.length - 1; index >= 0; index -= 1) {
|
|
307
|
+
const item = items[index];
|
|
308
|
+
const next = items[index + 1];
|
|
309
|
+
if (item !== void 0 && isTableItem(item) && (next === void 0 || isTableItem(next))) items.splice(index + 1, 0, { kind: "separator" });
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
const plainPiece = (kind, text) => ({
|
|
313
|
+
kind,
|
|
314
|
+
text,
|
|
315
|
+
signature: "",
|
|
316
|
+
link: null,
|
|
317
|
+
atom: null,
|
|
318
|
+
origin: "document"
|
|
319
|
+
});
|
|
320
|
+
/** A label written as text: the label, then what its list puts after it. */
|
|
321
|
+
const labelPieces = ({ label, suffix }) => {
|
|
322
|
+
const pieces = [plainPiece("text", label)];
|
|
323
|
+
if (suffix === "tab") pieces.push(plainPiece("tab", " "));
|
|
324
|
+
else if (suffix === "space") pieces.push(plainPiece("text", " "));
|
|
325
|
+
return pieces;
|
|
326
|
+
};
|
|
303
327
|
const SHA256 = /^[0-9a-f]{64}$/u;
|
|
304
328
|
const TRANSITIONAL_WORDPROCESSINGML = NAMESPACES.w;
|
|
305
329
|
const groupByBlock = (entries) => {
|
|
@@ -437,7 +461,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
437
461
|
placed.add(id);
|
|
438
462
|
return Result.ok(void 0);
|
|
439
463
|
};
|
|
440
|
-
const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal }) => {
|
|
464
|
+
const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, endsSection }) => {
|
|
441
465
|
const first = parts.at(0);
|
|
442
466
|
if (first === void 0) return invalid("A plan item names no source block.");
|
|
443
467
|
const firstId = first.block.block.id;
|
|
@@ -452,7 +476,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
452
476
|
if (Result.isError(resolvedNumbering)) return resolvedNumbering;
|
|
453
477
|
const segments = [];
|
|
454
478
|
const resolvedParts = [];
|
|
455
|
-
for (const [index,
|
|
479
|
+
for (const [index, planned] of parts.entries()) {
|
|
480
|
+
const { block, stripLabel } = planned;
|
|
456
481
|
const { id, text } = block.block;
|
|
457
482
|
if (block.read === null) return invalid(`Block ${id} is a table and cannot be joined or slotted.`);
|
|
458
483
|
const placedOnce = place(block);
|
|
@@ -490,10 +515,24 @@ const resolvePlan = (source, template, plan) => {
|
|
|
490
515
|
piece: separator
|
|
491
516
|
});
|
|
492
517
|
}
|
|
518
|
+
const written = planned.labelAsText ? block.label?.asText ?? null : null;
|
|
519
|
+
if (planned.labelAsText) {
|
|
520
|
+
if (written === null) return Result.err(refuse({
|
|
521
|
+
code: "label-not-writable",
|
|
522
|
+
message: `Block ${id} shows no automatic label that can be written as text.`,
|
|
523
|
+
blockId: id
|
|
524
|
+
}));
|
|
525
|
+
if (stripLabel !== void 0 || index === 0 && resolvedNumbering.value.kind !== "none") return invalid(`Block ${id} takes its label as text and can neither lose a typed label nor join a list.`);
|
|
526
|
+
segments.push(...labelPieces(written).map((piece) => ({
|
|
527
|
+
kind: "piece",
|
|
528
|
+
piece
|
|
529
|
+
})));
|
|
530
|
+
}
|
|
493
531
|
segments.push(...part.value);
|
|
494
532
|
resolvedParts.push({
|
|
495
533
|
block,
|
|
496
|
-
strippedPrefix
|
|
534
|
+
strippedPrefix,
|
|
535
|
+
labelAsText: written?.label ?? null
|
|
497
536
|
});
|
|
498
537
|
}
|
|
499
538
|
const pieces = segmentPieces(segments);
|
|
@@ -513,7 +552,9 @@ const resolvePlan = (source, template, plan) => {
|
|
|
513
552
|
segments,
|
|
514
553
|
...piecesContent(pieces),
|
|
515
554
|
inlineObjects: pieces.filter(({ kind }) => kind === "object").length,
|
|
516
|
-
placement
|
|
555
|
+
placement,
|
|
556
|
+
pageBreakBefore,
|
|
557
|
+
endsSection: endsSection ?? null
|
|
517
558
|
};
|
|
518
559
|
for (const { block } of resolvedParts) byBlockId.set(block.block.id, paragraph);
|
|
519
560
|
return Result.ok(paragraph);
|
|
@@ -529,7 +570,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
529
570
|
};
|
|
530
571
|
const resolveTable = (block, item, tableOrdinal) => {
|
|
531
572
|
const { id } = block.block;
|
|
532
|
-
if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
|
|
573
|
+
if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.labelAsText !== void 0 || item.pageBreakBefore !== void 0 || item.endsSection !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
|
|
533
574
|
if (item.styleId !== void 0 && template.styles.get(item.styleId)?.type !== "table") return Result.err(refuse({
|
|
534
575
|
code: "style-unknown",
|
|
535
576
|
message: `The template has no table style ${item.styleId}.`,
|
|
@@ -551,7 +592,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
551
592
|
const paragraph = resolveParagraph({
|
|
552
593
|
parts: [{
|
|
553
594
|
block: nested,
|
|
554
|
-
stripLabel: override?.stripLabel
|
|
595
|
+
stripLabel: override?.stripLabel,
|
|
596
|
+
labelAsText: override?.labelAsText === true
|
|
555
597
|
}],
|
|
556
598
|
separators: [],
|
|
557
599
|
styleId: override?.styleId ?? item.cellStyleId,
|
|
@@ -624,7 +666,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
624
666
|
}
|
|
625
667
|
const parts = [{
|
|
626
668
|
block: block.value,
|
|
627
|
-
stripLabel: item.stripLabel
|
|
669
|
+
stripLabel: item.stripLabel,
|
|
670
|
+
labelAsText: item.labelAsText === true
|
|
628
671
|
}];
|
|
629
672
|
const separators = [];
|
|
630
673
|
let merge = item.mergeNext;
|
|
@@ -641,15 +684,16 @@ const resolvePlan = (source, template, plan) => {
|
|
|
641
684
|
message: `Block ${next.blockId} does not have the hash the plan pins.`,
|
|
642
685
|
blockId: next.blockId
|
|
643
686
|
}));
|
|
644
|
-
if (next.styleId !== void 0 || next.numbering !== void 0 || next.cellStyleId !== void 0 || next.nested !== void 0) return Result.err(refuse({
|
|
687
|
+
if (next.styleId !== void 0 || next.numbering !== void 0 || next.cellStyleId !== void 0 || next.nested !== void 0 || next.pageBreakBefore !== void 0 || next.endsSection !== void 0) return Result.err(refuse({
|
|
645
688
|
code: "merge-invalid",
|
|
646
|
-
message: `Block ${next.blockId} joins the paragraph before it and cannot carry a style
|
|
689
|
+
message: `Block ${next.blockId} joins the paragraph before it and cannot carry a style, a list, a page start or a section end of its own.`,
|
|
647
690
|
blockId: next.blockId
|
|
648
691
|
}));
|
|
649
692
|
separators.push(merge);
|
|
650
693
|
parts.push({
|
|
651
694
|
block: nextBlock.value,
|
|
652
|
-
stripLabel: next.stripLabel
|
|
695
|
+
stripLabel: next.stripLabel,
|
|
696
|
+
labelAsText: next.labelAsText === true
|
|
653
697
|
});
|
|
654
698
|
merge = next.mergeNext;
|
|
655
699
|
index += 1;
|
|
@@ -660,7 +704,9 @@ const resolvePlan = (source, template, plan) => {
|
|
|
660
704
|
styleId: item.styleId,
|
|
661
705
|
numbering: item.numbering,
|
|
662
706
|
placement: "body",
|
|
663
|
-
ordinal
|
|
707
|
+
ordinal,
|
|
708
|
+
pageBreakBefore: item.pageBreakBefore === true,
|
|
709
|
+
endsSection: item.endsSection
|
|
664
710
|
});
|
|
665
711
|
if (Result.isError(paragraph)) return paragraph;
|
|
666
712
|
items.push({
|
|
@@ -688,7 +734,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
688
734
|
if (Result.isError(block)) return block;
|
|
689
735
|
parts.push({
|
|
690
736
|
block: block.value,
|
|
691
|
-
stripLabel: void 0
|
|
737
|
+
stripLabel: void 0,
|
|
738
|
+
labelAsText: false
|
|
692
739
|
});
|
|
693
740
|
}
|
|
694
741
|
const paragraph = resolveParagraph({
|
|
@@ -722,6 +769,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
722
769
|
}));
|
|
723
770
|
nestedSlots.push(slot);
|
|
724
771
|
}
|
|
772
|
+
partTables(items);
|
|
773
|
+
if ((plan.lastSection !== void 0 || items.some((item) => item.kind === "paragraph" && item.paragraph.endsSection !== null)) && wChild(template.body, "sectPr") === null) return invalid("The template has no last section to build the plan's sections from.");
|
|
725
774
|
const keptPosition = /* @__PURE__ */ new Map();
|
|
726
775
|
for (const [position, item] of items.entries()) if (item.kind === "template") keptPosition.set(item.block.block.id, position);
|
|
727
776
|
const templateOrder = template.story.topLevel.map(({ block }) => block.id);
|
|
@@ -29,6 +29,7 @@ const FIELD_KIND = /^[A-Z][A-Z0-9]*$/u;
|
|
|
29
29
|
const MAX_LIST_LEVEL = 8;
|
|
30
30
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
31
|
const isString = (value) => typeof value === "string";
|
|
32
|
+
const isOptionalBoolean = (value) => value === void 0 || typeof value === "boolean";
|
|
32
33
|
const isOptionalString = (value) => value === void 0 || isString(value);
|
|
33
34
|
const isCount = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
34
35
|
/** A list id a plan may name: the first real one is 1. */
|
|
@@ -63,6 +64,29 @@ const numberingIssue = (value, where) => {
|
|
|
63
64
|
if (group !== void 0 && !(isString(group) && group !== "")) return `${where} names a malformed list group.`;
|
|
64
65
|
return null;
|
|
65
66
|
};
|
|
67
|
+
const SECTION_STARTS = /* @__PURE__ */ new Set([
|
|
68
|
+
"nextPage",
|
|
69
|
+
"evenPage",
|
|
70
|
+
"oddPage"
|
|
71
|
+
]);
|
|
72
|
+
const ORIENTATIONS = /* @__PURE__ */ new Set(["portrait", "landscape"]);
|
|
73
|
+
const isTwips = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
74
|
+
/** Why `section` is not a section of a plan, or null when it is one. */
|
|
75
|
+
const sectionIssue = (section, where) => {
|
|
76
|
+
if (section === void 0) return null;
|
|
77
|
+
if (!isObject(section)) return `${where} describes a malformed section.`;
|
|
78
|
+
const { page, start } = section;
|
|
79
|
+
if (start !== void 0 && !(isString(start) && SECTION_STARTS.has(start))) return `${where} names an unknown section start.`;
|
|
80
|
+
if (page === void 0) return null;
|
|
81
|
+
if (!isObject(page) || !(isString(page["orientation"]) && ORIENTATIONS.has(page["orientation"])) || !isTwips(page["width"]) || !isTwips(page["height"]) || page["width"] === 0 || page["height"] === 0) return `${where} describes a malformed page.`;
|
|
82
|
+
const margins = page["margins"];
|
|
83
|
+
return margins === void 0 || isObject(margins) && [
|
|
84
|
+
"top",
|
|
85
|
+
"right",
|
|
86
|
+
"bottom",
|
|
87
|
+
"left"
|
|
88
|
+
].every((side) => isTwips(margins[side])) ? null : `${where} describes malformed page margins.`;
|
|
89
|
+
};
|
|
66
90
|
const sourceItemIssue = (item, where) => {
|
|
67
91
|
if (!isString(item["blockId"]) || !isString(item["hash"])) return `${where} names no source block and hash.`;
|
|
68
92
|
for (const key of [
|
|
@@ -70,8 +94,11 @@ const sourceItemIssue = (item, where) => {
|
|
|
70
94
|
"cellStyleId",
|
|
71
95
|
"stripLabel"
|
|
72
96
|
]) if (!isOptionalString(item[key])) return `${where} carries a malformed ${key}.`;
|
|
97
|
+
for (const key of ["labelAsText", "pageBreakBefore"]) if (!isOptionalBoolean(item[key])) return `${where} carries a malformed ${key}.`;
|
|
73
98
|
const merge = item["mergeNext"];
|
|
74
99
|
if (merge !== void 0 && !(isString(merge) && MERGES.has(merge))) return `${where} names an unknown merge.`;
|
|
100
|
+
const section = sectionIssue(item["endsSection"], where);
|
|
101
|
+
if (section !== null) return section;
|
|
75
102
|
const numbering = numberingIssue(item["numbering"], where);
|
|
76
103
|
if (numbering !== null) return numbering;
|
|
77
104
|
const nested = item["nested"];
|
|
@@ -82,7 +109,7 @@ const sourceItemIssue = (item, where) => {
|
|
|
82
109
|
if (!isObject(entry) || !isString(entry["blockId"])) return `${where} carries a nested placement without a block.`;
|
|
83
110
|
if (seen.has(entry["blockId"])) return `${where} places nested block ${entry["blockId"]} twice.`;
|
|
84
111
|
seen.add(entry["blockId"]);
|
|
85
|
-
if (!isOptionalString(entry["styleId"]) || !isOptionalString(entry["stripLabel"])) return `${where} carries a malformed nested placement.`;
|
|
112
|
+
if (!isOptionalString(entry["styleId"]) || !isOptionalString(entry["stripLabel"]) || !isOptionalBoolean(entry["labelAsText"])) return `${where} carries a malformed nested placement.`;
|
|
86
113
|
const nestedNumbering = numberingIssue(entry["numbering"], where);
|
|
87
114
|
if (nestedNumbering !== null) return nestedNumbering;
|
|
88
115
|
}
|
|
@@ -115,6 +142,23 @@ const omitIssue = (omit) => {
|
|
|
115
142
|
for (const entry of omit) if (!isObject(entry) || !isString(entry["blockId"]) || !isString(entry["reason"]) || !OMIT_REASONS.has(entry["reason"])) return "The plan omits a block without an id or for an unknown reason.";
|
|
116
143
|
return null;
|
|
117
144
|
};
|
|
145
|
+
const INDENT_KEYS = /* @__PURE__ */ new Set([
|
|
146
|
+
"left",
|
|
147
|
+
"hanging",
|
|
148
|
+
"firstLine"
|
|
149
|
+
]);
|
|
150
|
+
/** The widest indent a patch may state: the widest page WordprocessingML allows. */
|
|
151
|
+
const MAX_INDENT = 31680;
|
|
152
|
+
/**
|
|
153
|
+
* Whether `value` is a level indent a patch may state: at least one of
|
|
154
|
+
* `left`, `hanging` and `firstLine`, each a whole number of twentieths of a
|
|
155
|
+
* point, and not both a hanging and a first-line indent.
|
|
156
|
+
*/
|
|
157
|
+
const isLevelIndent = (value) => {
|
|
158
|
+
if (!isObject(value)) return false;
|
|
159
|
+
const keys = Object.keys(value);
|
|
160
|
+
return keys.length > 0 && keys.every((key) => INDENT_KEYS.has(key) && isCount(value[key]) && value[key] <= MAX_INDENT) && !(value["hanging"] !== void 0 && value["firstLine"] !== void 0);
|
|
161
|
+
};
|
|
118
162
|
const patchesIssue = (patches) => {
|
|
119
163
|
if (patches === void 0) return null;
|
|
120
164
|
if (!Array.isArray(patches)) return "The plan's numbering patches are malformed.";
|
|
@@ -124,8 +168,8 @@ const patchesIssue = (patches) => {
|
|
|
124
168
|
const key = `${String(patch["abstractNumId"])}:${String(patch["ilvl"])}`;
|
|
125
169
|
if (seen.has(key)) return `Two numbering patches change level ${String(patch["ilvl"])} of list definition ${String(patch["abstractNumId"])}.`;
|
|
126
170
|
seen.add(key);
|
|
127
|
-
const { numFmt, lvlText, start, suff } = patch;
|
|
128
|
-
if (numFmt !== void 0 && !(isString(numFmt) && NUMBER_FORMATS.has(numFmt)) || lvlText !== void 0 && !(isString(lvlText) && isPlainText(lvlText)) || start !== void 0 && !isCount(start) || suff !== void 0 && !(isString(suff) && SUFFIXES.has(suff))) return "A numbering patch carries a malformed value.";
|
|
171
|
+
const { numFmt, lvlText, start, suff, indent } = patch;
|
|
172
|
+
if (numFmt !== void 0 && !(isString(numFmt) && NUMBER_FORMATS.has(numFmt)) || lvlText !== void 0 && !(isString(lvlText) && isPlainText(lvlText)) || start !== void 0 && !isCount(start) || suff !== void 0 && !(isString(suff) && SUFFIXES.has(suff)) || indent !== void 0 && !isLevelIndent(indent)) return "A numbering patch carries a malformed value.";
|
|
129
173
|
}
|
|
130
174
|
return null;
|
|
131
175
|
};
|
|
@@ -153,9 +197,13 @@ const fieldsIssue = (fields) => {
|
|
|
153
197
|
if (updateOnOpen !== void 0 && typeof updateOnOpen !== "boolean") return "The plan's update-on-open choice is not a boolean.";
|
|
154
198
|
return null;
|
|
155
199
|
};
|
|
200
|
+
const compatIssue = (compat) => {
|
|
201
|
+
if (compat === void 0) return null;
|
|
202
|
+
return isObject(compat) && isOptionalBoolean(compat["doNotExpandShiftReturn"]) ? null : "The plan's compatibility settings are malformed.";
|
|
203
|
+
};
|
|
156
204
|
/** Why `plan` is not a version 1 template plan, or null when it is one. */
|
|
157
205
|
const planShapeIssue = (plan) => {
|
|
158
206
|
if (!isObject(plan) || plan["version"] !== 1 || !isString(plan["sourceSha256"]) || !isString(plan["templateSha256"])) return "The plan is not a version 1 template plan.";
|
|
159
|
-
return bodyIssue(plan["body"]) ?? omitIssue(plan["omit"]) ?? patchesIssue(plan["numberingPatches"]) ?? spansIssue(plan) ?? fieldsIssue(plan["fields"]);
|
|
207
|
+
return bodyIssue(plan["body"]) ?? omitIssue(plan["omit"]) ?? patchesIssue(plan["numberingPatches"]) ?? spansIssue(plan) ?? fieldsIssue(plan["fields"]) ?? compatIssue(plan["compat"]) ?? sectionIssue(plan["lastSection"], "The plan's last section");
|
|
160
208
|
};
|
|
161
209
|
export { OMIT_REASONS, PLAN_HIGHLIGHT_COLORS, isPlainText, planShapeIssue };
|
|
@@ -89,6 +89,8 @@ export type ParagraphRead = {
|
|
|
89
89
|
element: XmlElement;
|
|
90
90
|
ordinal: number;
|
|
91
91
|
styleId: string | null;
|
|
92
|
+
/** The language the paragraph mark states (`w:pPr/w:rPr/w:lang`), or null. */
|
|
93
|
+
language: string | null;
|
|
92
94
|
numPr: ParagraphNumberingOverride | undefined;
|
|
93
95
|
paraId: string | null;
|
|
94
96
|
outlineLevel: number | null;
|
|
@@ -104,9 +106,15 @@ export type ParagraphRead = {
|
|
|
104
106
|
/** Names of content the reader has no text for and the transfer cannot carry. */
|
|
105
107
|
unsupported: string[];
|
|
106
108
|
hasSectionBreak: boolean;
|
|
109
|
+
/** `w:pageBreakBefore` as the paragraph itself states it; null when it does not. */
|
|
110
|
+
pageBreakBefore: boolean | null;
|
|
111
|
+
/** `w:jc` as the paragraph itself states it, or null. */
|
|
112
|
+
alignment: string | null;
|
|
107
113
|
/** Whether the paragraph mark is a tracked insertion or deletion. */
|
|
108
114
|
hasTrackedMark: boolean;
|
|
109
115
|
};
|
|
116
|
+
/** An on/off property as its element states it; null without the element. */
|
|
117
|
+
export declare const toggleOf: (element: XmlElement | null) => boolean | null;
|
|
110
118
|
/** Read one `w:p`, advancing the story's field and revision state. */
|
|
111
119
|
export declare const readParagraph: (element: XmlElement, state: StoryState) => ParagraphRead;
|
|
112
120
|
export type StoryBlockVisitor = {
|
|
@@ -24,6 +24,13 @@ const endStory = (state) => {
|
|
|
24
24
|
state.strayFieldEnds += state.open.length;
|
|
25
25
|
state.open = [];
|
|
26
26
|
};
|
|
27
|
+
const TOGGLE_OFF = /* @__PURE__ */ new Set([
|
|
28
|
+
"0",
|
|
29
|
+
"false",
|
|
30
|
+
"off"
|
|
31
|
+
]);
|
|
32
|
+
/** An on/off property as its element states it; null without the element. */
|
|
33
|
+
const toggleOf = (element) => element === null ? null : !TOGGLE_OFF.has(wAttr(element, "val") ?? "1");
|
|
27
34
|
const REVISION_INCLUDED = /* @__PURE__ */ new Set(["ins", "moveTo"]);
|
|
28
35
|
const REVISION_EXCLUDED = /* @__PURE__ */ new Set(["del", "moveFrom"]);
|
|
29
36
|
const TRANSPARENT_WRAPPERS = /* @__PURE__ */ new Set([
|
|
@@ -323,6 +330,7 @@ const readParagraph = (element, state) => {
|
|
|
323
330
|
element,
|
|
324
331
|
ordinal: state.paragraphOrdinal,
|
|
325
332
|
styleId: wChildVal(properties, "pStyle"),
|
|
333
|
+
language: wChildVal(wChild(properties, "rPr"), "lang"),
|
|
326
334
|
numPr: readParagraphNumbering(wChild(properties, "numPr")),
|
|
327
335
|
paraId: paraIdAttribute(element) ?? null,
|
|
328
336
|
outlineLevel: headingLevelOf(outline),
|
|
@@ -335,6 +343,8 @@ const readParagraph = (element, state) => {
|
|
|
335
343
|
inlineObjects: 0,
|
|
336
344
|
unsupported: [],
|
|
337
345
|
hasSectionBreak: wChild(properties, "sectPr") !== null,
|
|
346
|
+
pageBreakBefore: toggleOf(wChild(properties, "pageBreakBefore")),
|
|
347
|
+
alignment: wChildVal(properties, "jc"),
|
|
338
348
|
hasTrackedMark
|
|
339
349
|
};
|
|
340
350
|
state.paragraphOrdinal += 1;
|
|
@@ -437,4 +447,4 @@ const walkBlocks = (container, visitor, depth = 0) => {
|
|
|
437
447
|
} else if (name === null || !IGNORED_BLOCK_CHILDREN.has(name)) visitor.unread(child);
|
|
438
448
|
}
|
|
439
449
|
};
|
|
440
|
-
export { NOTE_REFERENCE_MARK, createStoryState, endStory, readParagraph, walkBlocks };
|
|
450
|
+
export { NOTE_REFERENCE_MARK, createStoryState, endStory, readParagraph, toggleOf, walkBlocks };
|