@stll/folio-core 0.75.0 → 0.77.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/headless.d.ts +8 -5
- package/dist/ai-edits/headless.js +49 -26
- package/dist/ai-edits/pending-suggestions.d.ts +9 -0
- package/dist/ai-edits/pending-suggestions.js +13 -3
- package/dist/ai-edits/read.js +33 -4
- package/dist/ai-edits/table-geometry.js +12 -4
- package/dist/ai-edits/types.d.ts +9 -4
- package/dist/canonical/batchCommentReferences.js +2 -1
- package/dist/canonical/canonicalBatchReview.js +5 -8
- package/dist/canonical/canonicalComments.js +8 -2
- package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
- package/dist/canonical/canonicalCompilerRefusal.js +20 -14
- package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
- package/dist/canonical/canonicalInlineProjection.js +2 -2
- package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
- package/dist/canonical/canonicalPublicOperations.js +214 -107
- package/dist/canonical/canonicalSeedContent.d.ts +18 -3
- package/dist/canonical/canonicalSeedContent.js +28 -15
- package/dist/canonical/canonicalSession.d.ts +22 -12
- package/dist/canonical/canonicalSession.js +181 -187
- package/dist/controller/canonicalClipboard.d.ts +3 -2
- package/dist/controller/canonicalClipboard.js +377 -58
- package/dist/controller/canonicalComposition.js +67 -14
- package/dist/controller/canonicalContentControlValue.js +7 -7
- package/dist/controller/canonicalReview.d.ts +21 -0
- package/dist/controller/canonicalReview.js +44 -9
- package/dist/controller/canonicalStoryEditor.js +2 -0
- package/dist/controller/canonicalStructure.d.ts +1 -2
- package/dist/controller/canonicalStructure.js +51 -24
- package/dist/controller/fontReadiness.js +50 -23
- package/dist/controller/hiddenEditorManager.js +7 -20
- package/dist/docx/bulletMarkers.d.ts +8 -0
- package/dist/docx/bulletMarkers.js +9 -1
- package/dist/docx/canonicalSessionInput.js +25 -11
- package/dist/docx/ensureParaIds.d.ts +31 -0
- package/dist/docx/ensureParaIds.js +57 -32
- package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
- package/dist/docx/ensureUniqueControlIds.js +47 -29
- package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
- package/dist/docx/ensureUniqueRevisionIds.js +52 -29
- package/dist/docx/importedIdCollisions.js +29 -4
- package/dist/docx/server/templatePlan/apply.js +108 -9
- package/dist/docx/server/templatePlan/blocks.d.ts +77 -5
- package/dist/docx/server/templatePlan/blocks.js +281 -14
- package/dist/docx/server/templatePlan/builders.d.ts +22 -1
- package/dist/docx/server/templatePlan/builders.js +37 -3
- package/dist/docx/server/templatePlan/effects.d.ts +27 -0
- package/dist/docx/server/templatePlan/effects.js +188 -0
- package/dist/docx/server/templatePlan/emit.d.ts +4 -1
- package/dist/docx/server/templatePlan/emit.js +152 -8
- package/dist/docx/server/templatePlan/inspect.js +21 -1
- package/dist/docx/server/templatePlan/labels.js +16 -1
- package/dist/docx/server/templatePlan/plan.d.ts +35 -3
- package/dist/docx/server/templatePlan/plan.js +197 -20
- package/dist/docx/server/templatePlan/planShape.js +58 -22
- package/dist/docx/server/templatePlan/revisions.d.ts +101 -0
- package/dist/docx/server/templatePlan/revisions.js +681 -0
- package/dist/docx/server/templatePlan/story.d.ts +61 -2
- package/dist/docx/server/templatePlan/story.js +175 -13
- package/dist/docx/server/templatePlan/types.d.ts +313 -1
- package/dist/docx/server/templatePlan/verify.js +175 -12
- package/dist/docx/server/templatePlan/xml.d.ts +3 -0
- package/dist/docx/server/templatePlan/xml.js +4 -1
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
- package/dist/docx/tableGridXml.d.ts +3 -7
- package/dist/docx/tableGridXml.js +5 -13
- package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
- package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
- package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
- package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -3
- package/dist/prosemirror/commands/comments.d.ts +6 -234
- package/dist/prosemirror/commands/comments.js +5 -2464
- package/dist/prosemirror/commands/index.d.ts +4 -2
- package/dist/prosemirror/commands/index.js +4 -2
- package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
- package/dist/prosemirror/conversion/markupViewSource.js +11 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
- package/dist/prosemirror/conversion/toProseDoc.js +31 -14
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
- package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
- package/dist/prosemirror/hyperlinkRemoval.js +24 -15
- package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
- package/dist/prosemirror/independentMarkupProjection.js +147 -0
- package/dist/prosemirror/markupViewNotes.d.ts +1 -1
- package/dist/prosemirror/markupViewNotes.js +24 -27
- package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
- package/dist/prosemirror/markupViewPositionMap.js +316 -0
- package/dist/prosemirror/markupViewProjection.d.ts +3 -46
- package/dist/prosemirror/markupViewProjection.js +90 -17
- package/dist/prosemirror/paraIds.d.ts +1 -14
- package/dist/prosemirror/paraIds.js +1 -14
- package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
- package/dist/prosemirror/paragraphMarkJoin.js +3 -46
- package/dist/prosemirror/projectionReview.d.ts +49 -0
- package/dist/prosemirror/projectionReview.js +292 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
- package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
- package/dist/prosemirror/replacedAnnotations.d.ts +6 -83
- package/dist/prosemirror/replacedAnnotations.js +11 -203
- package/dist/prosemirror/revisionCarriers.d.ts +9 -1
- package/dist/prosemirror/revisionCarriers.js +15 -1
- package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
- package/dist/prosemirror/revisionRangeQueries.js +76 -0
- package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
- package/dist/prosemirror/runFormattingMarkNames.js +1 -1
- package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
- package/dist/prosemirror/styles/styleResolver.js +4 -1
- package/dist/prosemirror/suggestionQueries.d.ts +114 -0
- package/dist/prosemirror/suggestionQueries.js +320 -0
- package/dist/prosemirror/tableGridMutation.d.ts +1 -16
- package/dist/prosemirror/tableGridMutation.js +1 -78
- package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
- package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
- package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +4 -35
- package/dist/types/canonicalCapabilities.js +4 -33
- package/package.json +2 -2
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
- package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
- package/dist/internal/revisionResolutionEdits.d.ts +0 -11
- package/dist/internal/revisionResolutionEdits.js +0 -18
- package/dist/internal/revisionResolutionInline.d.ts +0 -24
- package/dist/internal/revisionResolutionInline.js +0 -302
- package/dist/internal/revisionResolutionStep.d.ts +0 -32
- package/dist/internal/revisionResolutionStep.js +0 -282
- package/dist/internal/revisionResolutionTracking.d.ts +0 -9
- package/dist/internal/revisionResolutionTracking.js +0 -124
- package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
- package/dist/internal/wholeStoryRevisionResolution.js +0 -783
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
- package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -18
- package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -207
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
- package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
- package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
- package/dist/prosemirror/rejoinRunCarriers.js +0 -65
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
- package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
|
@@ -3,13 +3,14 @@ import { RELATIONSHIP_TYPES } from "../../relsParser.js";
|
|
|
3
3
|
import { spliceXml } from "../../selectiveXmlPatch.js";
|
|
4
4
|
import { NAMESPACES, getLocalName } from "../../xmlParser.js";
|
|
5
5
|
import { appendToXmlRoot } from "../../xmlRootInsertion.js";
|
|
6
|
-
import { analyzeDocument } from "./blocks.js";
|
|
7
|
-
import { freezeFields, sectionPropertiesXml, setKeepShiftReturnSpacing, setUpdateFieldsOnOpen, withoutContained } from "./builders.js";
|
|
6
|
+
import { analyzeDocument, analyzeSource, viewOf } from "./blocks.js";
|
|
7
|
+
import { bookmarkIdsOf, freezeFields, inheritedReferencesXml, sectionPropertiesXml, setKeepShiftReturnSpacing, setTrackingOff, setUpdateFieldsOnOpen, withoutContained } from "./builders.js";
|
|
8
|
+
import { removeInvisibleEffects } from "./effects.js";
|
|
8
9
|
import { createRelationshipsEditor, noteXml, paragraphContentXml, paragraphXml, tableXml, templateCharacterStyles } from "./emit.js";
|
|
9
10
|
import { readHeaderFooterParts } from "./inspect.js";
|
|
10
11
|
import { styleNumbering } from "./labels.js";
|
|
11
12
|
import { guarded, readPartText, relationshipsPathFor } from "./package.js";
|
|
12
|
-
import { resolvePlan } from "./plan.js";
|
|
13
|
+
import { fieldSeparatorRun, resolvePlan } from "./plan.js";
|
|
13
14
|
import { readStoryResources } from "./resources.js";
|
|
14
15
|
import { TemplatePlanError } from "./types.js";
|
|
15
16
|
import { reportTemplatePlanOutput } from "./verify.js";
|
|
@@ -68,6 +69,8 @@ const RANGE_MARKERS = [["bookmarkStart", "bookmarkEnd"], ["commentRangeStart", "
|
|
|
68
69
|
* Splices removing range markers whose other half the output does not carry:
|
|
69
70
|
* a bookmark or comment range that started in a block the plan dropped.
|
|
70
71
|
*/
|
|
72
|
+
/** How far above the bookmarks' ids the ids of kept tracked changes start. */
|
|
73
|
+
const REVISION_ID_OFFSET = 1e5;
|
|
71
74
|
const orphanMarkerSplices = ({ kept, replaced }) => {
|
|
72
75
|
const splices = [];
|
|
73
76
|
for (const [startName, endName] of RANGE_MARKERS) {
|
|
@@ -159,6 +162,32 @@ const levelPropertiesXml = ({ part, level, w, indent }) => {
|
|
|
159
162
|
const at = (later === void 0 || later === null ? null : rangeOf(later))?.start ?? inner.end;
|
|
160
163
|
return `${part.xml.slice(range.start, at)}${indentXml}${part.xml.slice(at, range.end)}`;
|
|
161
164
|
};
|
|
165
|
+
/**
|
|
166
|
+
* The `w:rPr` of a level with its label set in `font`. Whatever else the
|
|
167
|
+
* level's run properties state is kept; the face is named for every script
|
|
168
|
+
* a label is written in, and no theme face is left to override it.
|
|
169
|
+
*/
|
|
170
|
+
const levelRunPropertiesXml = ({ part, level, w, font }) => {
|
|
171
|
+
const face = escapeXmlAttribute(font);
|
|
172
|
+
const fontsXml = `<${w}:rFonts ${w}:ascii="${face}" ${w}:hAnsi="${face}" ${w}:eastAsia="${face}" ${w}:cs="${face}" ${w}:hint="default"/>`;
|
|
173
|
+
const properties = wChild(level, "rPr");
|
|
174
|
+
const range = properties === null ? null : rangeOf(properties);
|
|
175
|
+
if (properties === null || range === null) return `<${w}:rPr>${fontsXml}</${w}:rPr>`;
|
|
176
|
+
const existing = wChild(properties, "rFonts");
|
|
177
|
+
const existingRange = existing === null ? null : rangeOf(existing);
|
|
178
|
+
if (existingRange !== null) return sliceWithSplices(part.xml, range, [{
|
|
179
|
+
...existingRange,
|
|
180
|
+
newXml: fontsXml
|
|
181
|
+
}]);
|
|
182
|
+
const inner = innerRangeOf(part.xml, properties);
|
|
183
|
+
if (inner === null) {
|
|
184
|
+
const name = properties.name ?? `${w}:rPr`;
|
|
185
|
+
return `${part.xml.slice(range.start, range.end - 2).trimEnd()}>${fontsXml}</${name}>`;
|
|
186
|
+
}
|
|
187
|
+
const style = wChild(properties, "rStyle");
|
|
188
|
+
const at = (style === null ? null : rangeOf(style))?.end ?? inner.start;
|
|
189
|
+
return `${part.xml.slice(range.start, at)}${fontsXml}${part.xml.slice(at, range.end)}`;
|
|
190
|
+
};
|
|
162
191
|
/** The template numbering part with level patches and new list instances. */
|
|
163
192
|
const editNumbering = (part, { patches, mints }) => {
|
|
164
193
|
const prefixes = partPrefixes(part.root);
|
|
@@ -188,13 +217,20 @@ const editNumbering = (part, { patches, mints }) => {
|
|
|
188
217
|
w,
|
|
189
218
|
indent: patch.indent
|
|
190
219
|
});
|
|
191
|
-
|
|
220
|
+
const runProperties = patch.font === void 0 ? void 0 : levelRunPropertiesXml({
|
|
221
|
+
part,
|
|
222
|
+
level,
|
|
223
|
+
w,
|
|
224
|
+
font: patch.font
|
|
225
|
+
});
|
|
226
|
+
if (properties === null || runProperties === null) return Result.err(unreadable(part.path, "The numbering part could not be patched."));
|
|
192
227
|
const planned = {
|
|
193
228
|
...patch.start === void 0 ? {} : { start: valued("start", String(patch.start)) },
|
|
194
229
|
...patch.numFmt === void 0 ? {} : { numFmt: valued("numFmt", patch.numFmt) },
|
|
195
230
|
...patch.suff === void 0 ? {} : { suff: valued("suff", patch.suff) },
|
|
196
231
|
...patch.lvlText === void 0 ? {} : { lvlText: valued("lvlText", patch.lvlText) },
|
|
197
|
-
...properties === void 0 ? {} : { pPr: properties }
|
|
232
|
+
...properties === void 0 ? {} : { pPr: properties },
|
|
233
|
+
...runProperties === void 0 ? {} : { rPr: runProperties }
|
|
198
234
|
};
|
|
199
235
|
const inner = innerRangeOf(part.xml, level);
|
|
200
236
|
for (const [index, name] of LEVEL_CHILD_ORDER.entries()) {
|
|
@@ -329,6 +365,7 @@ const writeOutput = async ({ source, template, plan, resolved }) => {
|
|
|
329
365
|
const media = /* @__PURE__ */ new Map();
|
|
330
366
|
const mediaPaths = /* @__PURE__ */ new Set();
|
|
331
367
|
let unsupportedMedia = null;
|
|
368
|
+
let revisionId = maxOf(bookmarkIdsOf(template.document.root), 0) + REVISION_ID_OFFSET;
|
|
332
369
|
let drawingId = 0;
|
|
333
370
|
const noteDrawingIds = (root) => {
|
|
334
371
|
walkElements(root, (element) => {
|
|
@@ -379,6 +416,10 @@ const writeOutput = async ({ source, template, plan, resolved }) => {
|
|
|
379
416
|
nextDrawingId: () => {
|
|
380
417
|
drawingId += 1;
|
|
381
418
|
return drawingId;
|
|
419
|
+
},
|
|
420
|
+
nextRevisionId: () => {
|
|
421
|
+
revisionId += 1;
|
|
422
|
+
return revisionId;
|
|
382
423
|
}
|
|
383
424
|
};
|
|
384
425
|
const documentContext = {
|
|
@@ -389,6 +430,7 @@ const writeOutput = async ({ source, template, plan, resolved }) => {
|
|
|
389
430
|
const instructions = new Map(resolved.references.map(({ reference, instruction }) => [reference, instruction]));
|
|
390
431
|
const instructionOf = (segment) => segment.kind === "reference" ? instructions.get(segment.reference) ?? null : null;
|
|
391
432
|
const bodySection = wChild(template.body, "sectPr");
|
|
433
|
+
const inherited = bodySection === null ? [] : inheritedReferencesXml(template.document.xml, template.body, bodySection);
|
|
392
434
|
const sectionEnds = resolved.items.flatMap((item) => item.kind === "paragraph" && item.paragraph.endsSection !== null ? [item.paragraph] : []);
|
|
393
435
|
const sectionXmlOf = /* @__PURE__ */ new Map();
|
|
394
436
|
for (const [position, paragraph] of sectionEnds.entries()) {
|
|
@@ -396,7 +438,8 @@ const writeOutput = async ({ source, template, plan, resolved }) => {
|
|
|
396
438
|
const xml = bodySection === null || section === null ? null : sectionPropertiesXml(template.document.xml, bodySection, documentContext.prefixes.w, {
|
|
397
439
|
first: position === 0,
|
|
398
440
|
page: section.page,
|
|
399
|
-
start: position === 0 ? null : section.start ?? "nextPage"
|
|
441
|
+
start: position === 0 ? null : section.start ?? "nextPage",
|
|
442
|
+
inherited
|
|
400
443
|
});
|
|
401
444
|
if (xml === null) return Result.err(unreadable(pkg.documentPath, "A section could not be built."));
|
|
402
445
|
sectionXmlOf.set(paragraph, xml);
|
|
@@ -438,6 +481,36 @@ const writeOutput = async ({ source, template, plan, resolved }) => {
|
|
|
438
481
|
end: inner.end
|
|
439
482
|
});
|
|
440
483
|
}
|
|
484
|
+
for (const { element } of resolved.emptied) {
|
|
485
|
+
const inner = innerRangeOf(template.document.xml, element);
|
|
486
|
+
if (inner === null) continue;
|
|
487
|
+
const properties = wChild(element, "pPr");
|
|
488
|
+
const start = (properties === null ? null : rangeOf(properties)?.end) ?? inner.start;
|
|
489
|
+
templateSplices.push({
|
|
490
|
+
start,
|
|
491
|
+
end: inner.end,
|
|
492
|
+
newXml: ""
|
|
493
|
+
});
|
|
494
|
+
replaced.push({
|
|
495
|
+
start,
|
|
496
|
+
end: inner.end
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
for (const { element } of resolved.emptiedContents.keys()) {
|
|
500
|
+
const start = rangeOf(fieldSeparatorRun(element) ?? element)?.end;
|
|
501
|
+
const inner = innerRangeOf(template.document.xml, element);
|
|
502
|
+
if (start === void 0 || inner === null) continue;
|
|
503
|
+
const { w } = documentContext.prefixes;
|
|
504
|
+
templateSplices.push({
|
|
505
|
+
start,
|
|
506
|
+
end: inner.end,
|
|
507
|
+
newXml: `<${w}:r><${w}:fldChar ${w}:fldCharType="end"/></${w}:r>`
|
|
508
|
+
});
|
|
509
|
+
replaced.push({
|
|
510
|
+
start,
|
|
511
|
+
end: inner.end
|
|
512
|
+
});
|
|
513
|
+
}
|
|
441
514
|
const keptElements = [
|
|
442
515
|
...resolved.keptTemplateBlocks.map(({ element }) => element),
|
|
443
516
|
...resolved.items.flatMap((item) => item.kind === "slot" ? [item.templateBlock.element] : []),
|
|
@@ -486,10 +559,11 @@ const writeOutput = async ({ source, template, plan, resolved }) => {
|
|
|
486
559
|
}
|
|
487
560
|
if (bodySection !== null) {
|
|
488
561
|
const { lastSection } = plan;
|
|
489
|
-
const rebuilt = sectionEnds.length > 0 || lastSection !== void 0 ? sectionPropertiesXml(template.document.xml, bodySection, documentContext.prefixes.w, {
|
|
562
|
+
const rebuilt = sectionEnds.length > 0 || lastSection !== void 0 || inherited.length > 0 ? sectionPropertiesXml(template.document.xml, bodySection, documentContext.prefixes.w, {
|
|
490
563
|
first: sectionEnds.length === 0,
|
|
491
564
|
page: lastSection?.page,
|
|
492
|
-
start: sectionEnds.length === 0 ? null : lastSection?.start ?? null
|
|
565
|
+
start: sectionEnds.length === 0 ? null : lastSection?.start ?? null,
|
|
566
|
+
inherited
|
|
493
567
|
}) : null;
|
|
494
568
|
const section = rebuilt === null ? keptXml(bodySection) : Result.ok(rebuilt);
|
|
495
569
|
if (Result.isError(section)) return section;
|
|
@@ -633,6 +707,31 @@ const writeOutput = async ({ source, template, plan, resolved }) => {
|
|
|
633
707
|
if (settings === null) return Result.err(unreadable(settingsPath, "The settings part could not be updated."));
|
|
634
708
|
if (settings !== settingsXml.value) parts.set(settingsPath, settings);
|
|
635
709
|
}
|
|
710
|
+
if (plan.trackedChanges === "keep") {
|
|
711
|
+
const settingsPath = pkg.partPath("settings");
|
|
712
|
+
const written = settingsPath === null ? void 0 : parts.get(settingsPath);
|
|
713
|
+
const settingsXml = typeof written === "string" ? Result.ok(written) : await readTemplateText(settingsPath);
|
|
714
|
+
if (Result.isError(settingsXml)) return settingsXml;
|
|
715
|
+
const settings = settingsXml.value === null ? null : setTrackingOff(settingsXml.value);
|
|
716
|
+
if (settingsPath !== null && settings !== null && settings !== settingsXml.value) parts.set(settingsPath, settings);
|
|
717
|
+
}
|
|
718
|
+
if (plan.textEffects !== "keep") {
|
|
719
|
+
const kept = [
|
|
720
|
+
[pkg.documentPath, documentXml],
|
|
721
|
+
[template.numberingPath, template.numberingXml],
|
|
722
|
+
[template.stylesPath, template.stylesXml],
|
|
723
|
+
...headerFooterParts.map(({ path, xml }) => [path, xml])
|
|
724
|
+
];
|
|
725
|
+
for (const [path, original] of kept) {
|
|
726
|
+
const written = path === null ? void 0 : parts.get(path);
|
|
727
|
+
const xml = typeof written === "string" ? written : original;
|
|
728
|
+
if (path === null || xml === null) continue;
|
|
729
|
+
const part = readRawPart(path, xml);
|
|
730
|
+
const plain = part === null ? null : removeInvisibleEffects(part);
|
|
731
|
+
if (plain === null) return Result.err(unreadable(path, "A part could not be read for its text effects."));
|
|
732
|
+
if (plain.removed.length > 0) parts.set(path, plain.xml);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
636
735
|
return await Result.tryPromise({
|
|
637
736
|
try: async () => {
|
|
638
737
|
const zip = await ZipArchive.read(pkg.bytes);
|
|
@@ -650,7 +749,7 @@ const writeOutput = async ({ source, template, plan, resolved }) => {
|
|
|
650
749
|
});
|
|
651
750
|
};
|
|
652
751
|
const applyUnguarded = async ({ source, template, plan, options }) => {
|
|
653
|
-
const analyzedSource = await
|
|
752
|
+
const analyzedSource = await analyzeSource(source, viewOf(plan));
|
|
654
753
|
if (Result.isError(analyzedSource)) return analyzedSource;
|
|
655
754
|
const analyzedTemplate = await analyzeDocument(template);
|
|
656
755
|
if (Result.isError(analyzedTemplate)) return analyzedTemplate;
|
|
@@ -7,7 +7,7 @@ import { Emphasis } from "./emphasis.js";
|
|
|
7
7
|
import { LabelCounter, ParagraphLabel } from "./labels.js";
|
|
8
8
|
import { LoadedPackage } from "./package.js";
|
|
9
9
|
import { ParagraphRead, StoryState } from "./story.js";
|
|
10
|
-
import { DocxBlock, DocxBlockManifest, DocxSection, TemplatePlanError } from "./types.js";
|
|
10
|
+
import { DocxBlock, DocxBlockManifest, DocxSection, TemplatePlanError, TemplatePlanTrackedChanges } from "./types.js";
|
|
11
11
|
import { RawPart } from "./xml.js";
|
|
12
12
|
import { Result } from "better-result";
|
|
13
13
|
export declare const blockHash: (text: string, label: string | null) => string;
|
|
@@ -46,13 +46,50 @@ type StoryResources = {
|
|
|
46
46
|
numbering: NumberingMap | null;
|
|
47
47
|
/** The alignment each paragraph style states for itself (`w:jc`). */
|
|
48
48
|
alignments?: ReadonlyMap<string, string>;
|
|
49
|
+
/** The indent each list level states, by definition and level. */
|
|
50
|
+
levelIndents?: ReadonlyMap<string, IndentSides>;
|
|
51
|
+
/** The indent the document's defaults give every paragraph. */
|
|
52
|
+
defaultIndent?: IndentSides;
|
|
49
53
|
};
|
|
50
54
|
/** The heading level a style outlines its paragraphs at, 0 being the highest. */
|
|
51
55
|
export declare const styleOutlineLevel: (style: document_d_exports.Style | undefined) => number | null;
|
|
56
|
+
type IndentSides = {
|
|
57
|
+
left: number | null;
|
|
58
|
+
firstLine: number | null;
|
|
59
|
+
};
|
|
52
60
|
/** The alignment each style of a styles part states for itself (`w:jc`). */
|
|
53
61
|
export declare const statedAlignments: (stylesPath: string | null, stylesXml: string | null) => Map<string, string>;
|
|
54
62
|
/** The alignment of the nearest style in the `basedOn` chain that states one. */
|
|
55
63
|
export declare const styleAlignment: (styleId: string | null, styles: StyleMap, stated: ReadonlyMap<string, string>) => string | null;
|
|
64
|
+
/** What a style states of the look of its text; null where it states
|
|
65
|
+
* nothing. */
|
|
66
|
+
type StatedLook = {
|
|
67
|
+
bold: boolean | null;
|
|
68
|
+
/** In half-points. */
|
|
69
|
+
size: number | null;
|
|
70
|
+
keepNext: boolean | null;
|
|
71
|
+
/** In twentieths of a point. */
|
|
72
|
+
indentLeft: number | null;
|
|
73
|
+
};
|
|
74
|
+
/** The look each style of the styles part states itself, by style id, and
|
|
75
|
+
* the look the document's defaults state. */
|
|
76
|
+
export declare const statedLooks: (stylesPath: string | null, stylesXml: string | null) => {
|
|
77
|
+
styles: Map<string, StatedLook>;
|
|
78
|
+
defaults: StatedLook;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The look a style gives its text: each property from the nearest style in
|
|
82
|
+
* the `basedOn` chain that states it, then from the document's defaults.
|
|
83
|
+
* Without a statement text is not bold and a paragraph is not kept with the
|
|
84
|
+
* next; the size and the left indent stay null, which leaves the size to
|
|
85
|
+
* the application and the indent to a list level, if the style has one.
|
|
86
|
+
*/
|
|
87
|
+
export declare const styleLook: (styleId: string | null, styles: StyleMap, { styles: stated, defaults }: ReturnType<typeof statedLooks>) => {
|
|
88
|
+
bold: boolean;
|
|
89
|
+
size: number | null;
|
|
90
|
+
keepNext: boolean;
|
|
91
|
+
indentLeft: number | null;
|
|
92
|
+
};
|
|
56
93
|
/**
|
|
57
94
|
* The sections of a story with what each states. A body without section
|
|
58
95
|
* properties of its own still ends in a section, which states nothing.
|
|
@@ -62,9 +99,11 @@ type AnalyzeStoryOptions = {
|
|
|
62
99
|
container: XmlElement;
|
|
63
100
|
resources: StoryResources;
|
|
64
101
|
counter?: LabelCounter;
|
|
102
|
+
/** Read inline insertions and deletions as tagged atoms. */
|
|
103
|
+
keepsRevisions?: boolean;
|
|
65
104
|
};
|
|
66
105
|
/** Read the blocks under `container` into ids, text, labels and hashes. */
|
|
67
|
-
export declare const analyzeStory: ({ container, resources, counter }: AnalyzeStoryOptions) => AnalyzedStory;
|
|
106
|
+
export declare const analyzeStory: ({ container, resources, counter, keepsRevisions }: AnalyzeStoryOptions) => AnalyzedStory;
|
|
68
107
|
export type AnalyzedNote = {
|
|
69
108
|
id: string;
|
|
70
109
|
element: XmlElement;
|
|
@@ -103,10 +142,43 @@ export type AnalyzedDocument = {
|
|
|
103
142
|
manifest: DocxBlockManifest;
|
|
104
143
|
};
|
|
105
144
|
/** Open a package and analyse its main story, notes, styles and numbering. */
|
|
106
|
-
export declare const analyzeDocument: (bytes: Uint8Array
|
|
145
|
+
export declare const analyzeDocument: (bytes: Uint8Array, { keepsRevisions }?: {
|
|
146
|
+
keepsRevisions?: boolean;
|
|
147
|
+
}) => Promise<Result<AnalyzedDocument, TemplatePlanError>>;
|
|
148
|
+
/** The view a plan states, when what was handed in is shaped like a plan
|
|
149
|
+
* at all; its shape is checked where the plan is resolved. */
|
|
150
|
+
export declare const viewOf: (plan: unknown) => TemplatePlanTrackedChanges | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* A source read with its tracked changes kept: the blocks are those of the
|
|
153
|
+
* accepted view, and the atoms of an insertion or a deletion carry its tag,
|
|
154
|
+
* a paragraph mark's among them; an inserted table row keeps its record and
|
|
155
|
+
* a deleted one is set aside whole. A change that is not carried yet (a
|
|
156
|
+
* table cell, a move) or cannot be tagged is refused with what stands in the
|
|
157
|
+
* way, for the caller to offer one view instead.
|
|
158
|
+
*/
|
|
159
|
+
/**
|
|
160
|
+
* A document read with its tracked changes kept, source or output alike:
|
|
161
|
+
* deleted paragraph marks carried as deletions inside the joined paragraph,
|
|
162
|
+
* inline insertions and deletions as tagged atoms. The manifest keeps the
|
|
163
|
+
* hash of the bytes that were given.
|
|
164
|
+
*/
|
|
165
|
+
export declare const analyzeKeptForm: (bytes: Uint8Array) => Promise<Result<AnalyzedDocument, TemplatePlanError>>;
|
|
166
|
+
/**
|
|
167
|
+
* Analyse a source in the view a caller chose of its tracked changes, or
|
|
168
|
+
* as it stands. In a view, the package that is analysed is the resolved
|
|
169
|
+
* one, while the manifest keeps the hash of the bytes that were given: a
|
|
170
|
+
* plan pins the file, not a rewriting of it. Without a view, a document
|
|
171
|
+
* that tracks changes says what it tracks.
|
|
172
|
+
*/
|
|
173
|
+
export declare const analyzeSource: (bytes: Uint8Array, view: TemplatePlanTrackedChanges | undefined) => Promise<Result<AnalyzedDocument, TemplatePlanError>>;
|
|
107
174
|
/**
|
|
108
175
|
* Read a DOCX into the blocks a template plan addresses: ids, visible text,
|
|
109
|
-
* rendered list labels, styles and a hash per block, plus its notes.
|
|
176
|
+
* rendered list labels, styles and a hash per block, plus its notes. With
|
|
177
|
+
* `trackedChanges`, the blocks are those of that view of a document with
|
|
178
|
+
* tracked changes; with `keep`, those of the accepted view, read off the
|
|
179
|
+
* document as it stands, or the refusal a plan that keeps them would get.
|
|
110
180
|
*/
|
|
111
|
-
export declare const analyzeDocxBlocks: (docx: Uint8Array
|
|
181
|
+
export declare const analyzeDocxBlocks: (docx: Uint8Array, options?: {
|
|
182
|
+
trackedChanges?: TemplatePlanTrackedChanges;
|
|
183
|
+
}) => Promise<Result<DocxBlockManifest, TemplatePlanError>>;
|
|
112
184
|
export {};
|