@stll/folio-core 0.33.1 → 0.33.2
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/apply.d.ts +15 -0
- package/dist/ai-edits/apply.js +134 -25
- package/dist/ai-edits/headless.d.ts +47 -3
- package/dist/ai-edits/headless.js +53 -3
- package/dist/ai-edits/index.d.ts +1 -1
- package/dist/ai-edits/snapshot.d.ts +19 -1
- package/dist/ai-edits/snapshot.js +25 -3
- package/dist/ai-edits/table-geometry.d.ts +56 -0
- package/dist/ai-edits/table-geometry.js +217 -0
- package/dist/ai-edits/table-row-column-mutations.d.ts +34 -16
- package/dist/ai-edits/table-row-column-mutations.js +12 -4
- package/dist/ai-edits/table-template.d.ts +60 -0
- package/dist/ai-edits/table-template.js +176 -0
- package/dist/ai-edits/types.d.ts +7 -0
- package/dist/compare/__fixtures__/body-sequence.d.ts +61 -2
- package/dist/compare/__fixtures__/body-sequence.js +94 -6
- package/dist/compare/compare.d.ts +14 -7
- package/dist/compare/compare.js +136 -38
- package/dist/compare/plan.d.ts +31 -1
- package/dist/compare/plan.js +233 -66
- package/dist/compare/types.d.ts +9 -7
- package/dist/compare/types.js +7 -5
- package/dist/compare/verification.d.ts +31 -12
- package/dist/compare/verification.js +88 -17
- package/dist/compat/eigenpal.d.ts +4 -4
- package/dist/compat/eigenpal.js +2 -2
- package/dist/display-list/primitives.d.ts +1 -1
- package/dist/document-operations.d.ts +10 -1
- package/dist/document-operations.js +3 -2
- package/dist/docx/appVersionNormalization.d.ts +49 -0
- package/dist/docx/appVersionNormalization.js +74 -0
- package/dist/docx/blockContentParser.js +3 -2
- package/dist/docx/drawingUtils.js +4 -3
- package/dist/docx/paragraphParser.js +3 -2
- package/dist/docx/rezip.d.ts +10 -4
- package/dist/docx/rezip.js +54 -18
- package/dist/docx/runParser.js +9 -8
- package/dist/docx/sdtProperties.js +4 -3
- package/dist/docx/selectiveSave.js +7 -6
- package/dist/docx/serializer/commentSerializer.d.ts +1 -1
- package/dist/docx/serializer/commentSerializer.js +43 -19
- package/dist/docx/serializer/documentSerializer.d.ts +3 -1
- package/dist/docx/serializer/documentSerializer.js +42 -78
- package/dist/docx/serializer/fontTableSerializer.js +8 -5
- package/dist/docx/serializer/headerFooterSerializer.d.ts +4 -1
- package/dist/docx/serializer/headerFooterSerializer.js +34 -29
- package/dist/docx/serializer/noteSerializer.js +34 -30
- package/dist/docx/serializer/numberingSerializer.js +8 -4
- package/dist/docx/serializer/paragraphSerializer.js +3 -3
- package/dist/docx/serializer/partNamespaces.d.ts +78 -0
- package/dist/docx/serializer/partNamespaces.js +324 -0
- package/dist/docx/serializer/runSerializer.js +1 -1
- package/dist/docx/serializer/settingsSerializer.js +8 -2
- package/dist/docx/serializer/stylesSerializer.js +8 -5
- package/dist/docx/serializer/tableSerializer.js +83 -18
- package/dist/docx/serializer/themeSerializer.js +10 -2
- package/dist/docx/server/build.d.ts +1 -1
- package/dist/docx/strictValueEncodings.gen.d.ts +15 -0
- package/dist/docx/strictValueEncodings.gen.js +275 -0
- package/dist/docx/tableParser.d.ts +0 -6
- package/dist/docx/tableParser.js +52 -7
- package/dist/docx/transitionalSpelling.d.ts +23 -0
- package/dist/docx/transitionalSpelling.js +36 -0
- package/dist/docx/universalMeasure.d.ts +20 -0
- package/dist/docx/universalMeasure.js +32 -0
- package/dist/docx/verbatimCapture.d.ts +20 -0
- package/dist/docx/verbatimCapture.js +131 -0
- package/dist/docx/vmlImageParser.js +4 -3
- package/dist/docx/watermarkParser.js +4 -3
- package/dist/docx/xmlParser.d.ts +23 -2
- package/dist/docx/xmlParser.js +43 -11
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/model.d.ts +3 -3
- package/dist/model.js +2 -2
- package/dist/prosemirror/commands/comments.js +2 -1
- package/dist/prosemirror/containerFinalParagraph.d.ts +47 -0
- package/dist/prosemirror/containerFinalParagraph.js +92 -0
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +8 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +15 -4
- package/dist/prosemirror/conversion/toProseDoc.js +12 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +5 -0
- package/dist/prosemirror/schema/marks.d.ts +1 -1
- package/dist/prosemirror/schema/nodes.d.ts +22 -0
- package/dist/server.d.ts +1 -1
- package/dist/types/block-id.d.ts +12 -1
- package/dist/types/block-id.js +17 -1
- package/dist/utils/canonicalJson.d.ts +14 -0
- package/dist/utils/canonicalJson.js +19 -0
- package/dist/utils/formatToStyle.d.ts +1 -1
- package/package.json +2 -2
package/dist/docx/tableParser.js
CHANGED
|
@@ -3,7 +3,8 @@ import { appendBookmarkMarkerToLastParagraphInBlocks, appendBookmarkMarkerToLast
|
|
|
3
3
|
import { parseParagraph } from "./paragraphParser.js";
|
|
4
4
|
import { enrichParagraphTextBoxes } from "./paragraphTextBoxEnrichment.js";
|
|
5
5
|
import { BorderStyleSchema, FloatingTableXSpecSchema, FloatingTableYSpecSchema, ShadingPatternSchema, TableCellTextDirectionSchema, ThemeColorSlotSchema, narrowEnum } from "./parserEnums.js";
|
|
6
|
-
import {
|
|
6
|
+
import { captureVerbatimXml } from "./verbatimCapture.js";
|
|
7
|
+
import { cloneElement, findChild, findChildByLocalName, findChildren, getAttribute, getChildElements, getLocalName, mergeXmlnsDeclarations, parseBooleanElement, parseNumericAttribute, parseTableMeasurementValue } from "./xmlParser.js";
|
|
7
8
|
import { normalizeRevisionId } from "@stll/docx-core/model";
|
|
8
9
|
//#region src/docx/tableParser.ts
|
|
9
10
|
/**
|
|
@@ -47,8 +48,22 @@ function parseTrackedChangeInfo(node) {
|
|
|
47
48
|
};
|
|
48
49
|
if (date.length > 0) info.date = date;
|
|
49
50
|
if (initials.length > 0) info.initials = initials;
|
|
51
|
+
const utcDate = utcDateAttribute(node);
|
|
52
|
+
if (utcDate) info.utcDate = utcDate;
|
|
50
53
|
return info;
|
|
51
54
|
}
|
|
55
|
+
/** `w16du:dateUtc` under whatever prefix the document bound it to. */
|
|
56
|
+
const utcDateAttribute = (node) => {
|
|
57
|
+
for (const [attribute, value] of Object.entries(node.attributes ?? {})) {
|
|
58
|
+
if (typeof value !== "string" || getLocalName(attribute) !== "dateUtc") continue;
|
|
59
|
+
const trimmed = value.trim();
|
|
60
|
+
if (trimmed.length > 0) return {
|
|
61
|
+
attribute,
|
|
62
|
+
value: trimmed
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
};
|
|
52
67
|
function parsePropertyChangeInfo(node) {
|
|
53
68
|
const base = parseTrackedChangeInfo(node);
|
|
54
69
|
const rsid = (getAttribute(node, "w", "rsid") ?? "").trim();
|
|
@@ -245,6 +260,31 @@ function parseFloatingTableProperties(tblpPrElement) {
|
|
|
245
260
|
* @param tblPrElement - The w:tblPr element
|
|
246
261
|
* @returns Parsed table formatting
|
|
247
262
|
*/
|
|
263
|
+
/**
|
|
264
|
+
* Children of a property element that record a revision rather than a
|
|
265
|
+
* property. They are parsed into records of their own and written back from
|
|
266
|
+
* those, so the capture leaves them out: a capture that kept them would put a
|
|
267
|
+
* resolved revision back into the document after it was accepted.
|
|
268
|
+
*/
|
|
269
|
+
const REVISION_PROPERTY_CHILDREN = /* @__PURE__ */ new Set([
|
|
270
|
+
"tblPrChange",
|
|
271
|
+
"trPrChange",
|
|
272
|
+
"tcPrChange",
|
|
273
|
+
"ins",
|
|
274
|
+
"del",
|
|
275
|
+
"cellIns",
|
|
276
|
+
"cellDel",
|
|
277
|
+
"cellMerge"
|
|
278
|
+
]);
|
|
279
|
+
/**
|
|
280
|
+
* The property element a formatting object was parsed from, kept beside the
|
|
281
|
+
* typed values so a save that did not touch them writes the element back
|
|
282
|
+
* exactly as it arrived.
|
|
283
|
+
*/
|
|
284
|
+
const withSourceXml = (formatting, element) => ({
|
|
285
|
+
...formatting,
|
|
286
|
+
sourceXml: captureVerbatimXml(cloneElement(element, { elements: (element.elements ?? []).filter((child) => !REVISION_PROPERTY_CHILDREN.has(getLocalName(child.name))) }))
|
|
287
|
+
});
|
|
248
288
|
function parseTableProperties(tblPrElement) {
|
|
249
289
|
if (!tblPrElement) return;
|
|
250
290
|
const formatting = {};
|
|
@@ -287,7 +327,7 @@ function parseTableProperties(tblPrElement) {
|
|
|
287
327
|
const bidiVisual = findChild(tblPrElement, "w", "bidiVisual");
|
|
288
328
|
if (bidiVisual) formatting.bidi = parseBooleanElement(bidiVisual);
|
|
289
329
|
if (Object.keys(formatting).length === 0) return;
|
|
290
|
-
return formatting;
|
|
330
|
+
return withSourceXml(formatting, tblPrElement);
|
|
291
331
|
}
|
|
292
332
|
function parseTablePropertyChanges(tblPrElement, currentFormatting) {
|
|
293
333
|
if (!tblPrElement) return;
|
|
@@ -415,7 +455,7 @@ function parseTableRowProperties(trPrElement) {
|
|
|
415
455
|
const conditionalFormat = parseConditionalFormatStyle(findChild(trPrElement, "w", "cnfStyle"));
|
|
416
456
|
if (conditionalFormat) formatting.conditionalFormat = conditionalFormat;
|
|
417
457
|
if (Object.keys(formatting).length === 0) return;
|
|
418
|
-
return formatting;
|
|
458
|
+
return withSourceXml(formatting, trPrElement);
|
|
419
459
|
}
|
|
420
460
|
/**
|
|
421
461
|
* Parse conditional format style (for table style conditional formatting)
|
|
@@ -505,12 +545,12 @@ function parseTableCellProperties(tcPrElement) {
|
|
|
505
545
|
else formatting.vMerge = "continue";
|
|
506
546
|
if (parseBooleanElement(findChild(tcPrElement, "w", "tcFitText"))) formatting.fitText = true;
|
|
507
547
|
if (parseBooleanElement(findChild(tcPrElement, "w", "noWrap"))) formatting.noWrap = true;
|
|
508
|
-
const
|
|
509
|
-
if (
|
|
548
|
+
const hideMarkElement = findChild(tcPrElement, "w", "hideMark");
|
|
549
|
+
if (hideMarkElement) formatting.hideMark = parseBooleanElement(hideMarkElement);
|
|
510
550
|
const conditionalFormat = parseConditionalFormatStyle(findChild(tcPrElement, "w", "cnfStyle"));
|
|
511
551
|
if (conditionalFormat) formatting.conditionalFormat = conditionalFormat;
|
|
512
552
|
if (Object.keys(formatting).length === 0) return;
|
|
513
|
-
return formatting;
|
|
553
|
+
return withSourceXml(formatting, tcPrElement);
|
|
514
554
|
}
|
|
515
555
|
/**
|
|
516
556
|
* Accumulate a table container's own `xmlns:*` onto the inherited in-scope set,
|
|
@@ -731,8 +771,13 @@ function parseTable(tblElement, styles, theme, numbering, rels, media, options)
|
|
|
731
771
|
if (formatting) table.formatting = formatting;
|
|
732
772
|
const tblPropChanges = parseTablePropertyChanges(tblPrElement, formatting);
|
|
733
773
|
if (tblPropChanges !== void 0) table.propertyChanges = tblPropChanges;
|
|
734
|
-
const
|
|
774
|
+
const gridElement = findChild(tblElement, "w", "tblGrid");
|
|
775
|
+
const columnWidths = parseTableGrid(gridElement);
|
|
735
776
|
if (columnWidths) table.columnWidths = columnWidths;
|
|
777
|
+
if (gridElement) table.formatting = {
|
|
778
|
+
...table.formatting,
|
|
779
|
+
gridSourceXml: captureVerbatimXml(gridElement)
|
|
780
|
+
};
|
|
736
781
|
const tableOptions = withContainerXmlns(options, tblElement);
|
|
737
782
|
const rowsWithGridOffsets = /* @__PURE__ */ new Set();
|
|
738
783
|
const parseTableChild = (child) => {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SlotEncoding } from "./strictValueEncodings.gen.js";
|
|
2
|
+
//#region src/docx/transitionalSpelling.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The Transitional URI a Strict one stands for, or the URI unchanged.
|
|
5
|
+
*
|
|
6
|
+
* Also used when a rebuilt part falls back to a binding its source declared:
|
|
7
|
+
* declaring a Strict URI on a Transitional root puts every element under that
|
|
8
|
+
* prefix back into the wrong vocabulary.
|
|
9
|
+
*/
|
|
10
|
+
declare const toTransitionalNamespaceUri: (uri: string) => string;
|
|
11
|
+
/** True for a namespace ECMA-376 Part 4 republished under `purl.oclc.org`. */
|
|
12
|
+
declare const isStrictNamespaceUri: (uri: string) => boolean;
|
|
13
|
+
/** Namespaces ECMA-376 Part 4 republished; nothing else starts with this. */
|
|
14
|
+
declare const STRICT_URI_PREFIX = "http://purl.oclc.org/ooxml/";
|
|
15
|
+
/**
|
|
16
|
+
* How one slot's Transitional type spells its value as a number.
|
|
17
|
+
*
|
|
18
|
+
* `namespaceUri` is the element's, in either conformance class; the lookup
|
|
19
|
+
* translates it. Omit `attributeLocalName` for element text content.
|
|
20
|
+
*/
|
|
21
|
+
declare const transitionalSlotEncoding: (namespaceUri: string | undefined, elementLocalName: string, attributeLocalName?: string) => SlotEncoding | undefined;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { STRICT_URI_PREFIX, isStrictNamespaceUri, toTransitionalNamespaceUri, transitionalSlotEncoding };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TRANSITIONAL_NAMESPACE_BY_STRICT_URI, TRANSITIONAL_SLOT_ENCODINGS } from "./strictValueEncodings.gen.js";
|
|
2
|
+
//#region src/docx/transitionalSpelling.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reading a Strict-spelled value as the Transitional number it stands for.
|
|
5
|
+
*
|
|
6
|
+
* Two places need it: the verbatim-capture conversion, which rewrites a
|
|
7
|
+
* fragment on its way into a rebuilt part, and the typed projection, which has
|
|
8
|
+
* to reach the same number so the model and the markup do not disagree about a
|
|
9
|
+
* width. Both go through {@link transitionalSlotEncoding} rather than deciding
|
|
10
|
+
* for themselves which attributes carry a unit.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The Transitional URI a Strict one stands for, or the URI unchanged.
|
|
14
|
+
*
|
|
15
|
+
* Also used when a rebuilt part falls back to a binding its source declared:
|
|
16
|
+
* declaring a Strict URI on a Transitional root puts every element under that
|
|
17
|
+
* prefix back into the wrong vocabulary.
|
|
18
|
+
*/
|
|
19
|
+
const toTransitionalNamespaceUri = (uri) => TRANSITIONAL_NAMESPACE_BY_STRICT_URI.get(uri) ?? uri;
|
|
20
|
+
/** True for a namespace ECMA-376 Part 4 republished under `purl.oclc.org`. */
|
|
21
|
+
const isStrictNamespaceUri = (uri) => TRANSITIONAL_NAMESPACE_BY_STRICT_URI.has(uri);
|
|
22
|
+
/** Namespaces ECMA-376 Part 4 republished; nothing else starts with this. */
|
|
23
|
+
const STRICT_URI_PREFIX = "http://purl.oclc.org/ooxml/";
|
|
24
|
+
/**
|
|
25
|
+
* How one slot's Transitional type spells its value as a number.
|
|
26
|
+
*
|
|
27
|
+
* `namespaceUri` is the element's, in either conformance class; the lookup
|
|
28
|
+
* translates it. Omit `attributeLocalName` for element text content.
|
|
29
|
+
*/
|
|
30
|
+
const transitionalSlotEncoding = (namespaceUri, elementLocalName, attributeLocalName) => {
|
|
31
|
+
if (namespaceUri === void 0) return;
|
|
32
|
+
const slot = `${toTransitionalNamespaceUri(namespaceUri)} ${elementLocalName}`;
|
|
33
|
+
return TRANSITIONAL_SLOT_ENCODINGS.get(attributeLocalName === void 0 ? slot : `${slot} @${attributeLocalName}`);
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { STRICT_URI_PREFIX, isStrictNamespaceUri, toTransitionalNamespaceUri, transitionalSlotEncoding };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/docx/universalMeasure.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* ECMA-376's unit-carrying length, and the numbers Transitional counts it in.
|
|
4
|
+
*
|
|
5
|
+
* `ST_UniversalMeasure` spells a length as a decimal with its unit attached
|
|
6
|
+
* (`155.85pt`, `2.54cm`). Strict producers write it wherever the type allows;
|
|
7
|
+
* Transitional attributes are read as plain numbers in a fixed unit, so both
|
|
8
|
+
* the verbatim-capture conversion and the typed projection have to agree on
|
|
9
|
+
* what one of those strings is worth. They share this module so they cannot.
|
|
10
|
+
*/
|
|
11
|
+
/** The unit a Transitional attribute's number is counted in. */
|
|
12
|
+
type MeasureUnit = "emu" | "halfPoints" | "hundredthPoints" | "twips";
|
|
13
|
+
/** Round half away from zero, so a negative offset keeps a positive one's magnitude. */
|
|
14
|
+
declare const roundHalfAwayFromZero: (value: number) => number;
|
|
15
|
+
/** The value of a universal measure in points, or `undefined` if it is not one. */
|
|
16
|
+
declare const universalMeasureInPoints: (value: string) => number | undefined;
|
|
17
|
+
/** A universal measure as the whole number a Transitional attribute of `unit` holds. */
|
|
18
|
+
declare const universalMeasureAs: (value: string, unit: MeasureUnit) => number | undefined;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { MeasureUnit, roundHalfAwayFromZero, universalMeasureAs, universalMeasureInPoints };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/docx/universalMeasure.ts
|
|
2
|
+
/** `-?123.45pt`: the one shape ECMA-376 gives a length that carries its unit. */
|
|
3
|
+
const UNIVERSAL_MEASURE = /^(-?[0-9]+(?:\.[0-9]+)?)(mm|cm|in|pt|pc|pi)$/u;
|
|
4
|
+
const POINTS_PER_UNIT = {
|
|
5
|
+
cm: 72 / 2.54,
|
|
6
|
+
in: 72,
|
|
7
|
+
mm: 72 / 25.4,
|
|
8
|
+
pc: 12,
|
|
9
|
+
pi: 12,
|
|
10
|
+
pt: 1
|
|
11
|
+
};
|
|
12
|
+
const NUMBERS_PER_POINT = {
|
|
13
|
+
emu: 12700,
|
|
14
|
+
halfPoints: 2,
|
|
15
|
+
hundredthPoints: 100,
|
|
16
|
+
twips: 20
|
|
17
|
+
};
|
|
18
|
+
/** Round half away from zero, so a negative offset keeps a positive one's magnitude. */
|
|
19
|
+
const roundHalfAwayFromZero = (value) => value < 0 ? -Math.round(-value) : Math.round(value);
|
|
20
|
+
/** The value of a universal measure in points, or `undefined` if it is not one. */
|
|
21
|
+
const universalMeasureInPoints = (value) => {
|
|
22
|
+
const match = UNIVERSAL_MEASURE.exec(value);
|
|
23
|
+
if (match === null) return;
|
|
24
|
+
return Number(match[1]) * POINTS_PER_UNIT[match[2]];
|
|
25
|
+
};
|
|
26
|
+
/** A universal measure as the whole number a Transitional attribute of `unit` holds. */
|
|
27
|
+
const universalMeasureAs = (value, unit) => {
|
|
28
|
+
const points = universalMeasureInPoints(value);
|
|
29
|
+
return points === void 0 ? void 0 : roundHalfAwayFromZero(points * NUMBERS_PER_POINT[unit]);
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { roundHalfAwayFromZero, universalMeasureAs, universalMeasureInPoints };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { XmlElement } from "./xmlParser.js";
|
|
2
|
+
//#region src/docx/verbatimCapture.d.ts
|
|
3
|
+
declare const UntranslatableStrictNamespaceError_base: import("better-result").TaggedErrorClass<"UntranslatableStrictNamespaceError">;
|
|
4
|
+
/** A Strict fragment uses a namespace that has no Transitional counterpart. */
|
|
5
|
+
declare class UntranslatableStrictNamespaceError extends UntranslatableStrictNamespaceError_base<{
|
|
6
|
+
message: string;
|
|
7
|
+
uri: string;
|
|
8
|
+
}> {}
|
|
9
|
+
/**
|
|
10
|
+
* Serialize parsed markup for replay inside a rebuilt Transitional part.
|
|
11
|
+
*
|
|
12
|
+
* Every verbatim capture goes through here — a lint rule keeps
|
|
13
|
+
* {@link elementToXml} out of reach of the parsers — so a replay path added
|
|
14
|
+
* later cannot skip the conversion. Markup that binds no Strict namespace,
|
|
15
|
+
* anywhere in scope or in the fragment itself, is serialized once and returned
|
|
16
|
+
* unchanged.
|
|
17
|
+
*/
|
|
18
|
+
declare const captureVerbatimXml: (element: XmlElement) => string;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { UntranslatableStrictNamespaceError, captureVerbatimXml };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { TRANSITIONAL_NAMESPACE_BY_STRICT_URI } from "./strictValueEncodings.gen.js";
|
|
2
|
+
import { isStrictNamespaceUri, toTransitionalNamespaceUri, transitionalSlotEncoding } from "./transitionalSpelling.js";
|
|
3
|
+
import { roundHalfAwayFromZero, universalMeasureAs } from "./universalMeasure.js";
|
|
4
|
+
import { elementToXml, getLocalName } from "./xmlParser.js";
|
|
5
|
+
import { TaggedError } from "better-result";
|
|
6
|
+
//#region src/docx/verbatimCapture.ts
|
|
7
|
+
/**
|
|
8
|
+
* The one way to turn parsed markup into a string a rebuilt part replays.
|
|
9
|
+
*
|
|
10
|
+
* folio parses Strict and Transitional packages and rebuilds every package as
|
|
11
|
+
* Transitional. Modeled properties are re-serialized, so they come out
|
|
12
|
+
* Transitional whatever the source was; content the parser keeps verbatim —
|
|
13
|
+
* raw property XML, drawing and shape bodies, text-box markup, unmodeled
|
|
14
|
+
* extensions — does not, and a Strict fragment copied under a Transitional root
|
|
15
|
+
* changes meaning: the namespaces it declares stay Strict while the root is
|
|
16
|
+
* not, and its values are spelled the way Strict spells them (`155.85pt`,
|
|
17
|
+
* `20%`) where the Transitional attribute is a number.
|
|
18
|
+
*
|
|
19
|
+
* A fragment is therefore converted here, at capture, where its own namespace
|
|
20
|
+
* scope still says which conformance class produced it. Nothing downstream has
|
|
21
|
+
* to know: {@link captureVerbatimXml} is the only producer of replayed markup,
|
|
22
|
+
* and a fragment that carries no Strict namespace passes through byte for byte.
|
|
23
|
+
*/
|
|
24
|
+
/** A Strict fragment uses a namespace that has no Transitional counterpart. */
|
|
25
|
+
var UntranslatableStrictNamespaceError = class extends TaggedError("UntranslatableStrictNamespaceError") {};
|
|
26
|
+
const TRANSITIONAL_URIS = new Set(TRANSITIONAL_NAMESPACE_BY_STRICT_URI.values());
|
|
27
|
+
/**
|
|
28
|
+
* Drawing extensions the repository has no schema for.
|
|
29
|
+
*
|
|
30
|
+
* `wp14:pctWidth` and its siblings are Microsoft vocabularies, but they are
|
|
31
|
+
* DrawingML by construction and DrawingML has one integer encoding for a
|
|
32
|
+
* percentage, so a Strict producer's `20%` there converts like `a:alpha`'s.
|
|
33
|
+
* Lengths are left alone: only an attribute's own type says what unit its
|
|
34
|
+
* number counts, and guessing one would corrupt the value silently.
|
|
35
|
+
*/
|
|
36
|
+
const DRAWING_EXTENSION_MARKERS = [
|
|
37
|
+
"/wordprocessingCanvas",
|
|
38
|
+
"/wordprocessingDrawing",
|
|
39
|
+
"/wordprocessingGroup",
|
|
40
|
+
"/wordprocessingInk",
|
|
41
|
+
"/wordprocessingShape"
|
|
42
|
+
];
|
|
43
|
+
const isUnschemadDrawingNamespace = (uri) => !TRANSITIONAL_URIS.has(uri) && DRAWING_EXTENSION_MARKERS.some((marker) => uri.includes(marker));
|
|
44
|
+
/** `-?12.5%`: the one shape ECMA-376 gives a percentage that carries its unit. */
|
|
45
|
+
const PERCENTAGE = /^(-?[0-9]+(?:\.[0-9]+)?)%$/u;
|
|
46
|
+
const NUMBERS_PER_PERCENT = {
|
|
47
|
+
fiftiethPercent: 50,
|
|
48
|
+
thousandthPercent: 1e3,
|
|
49
|
+
wholePercent: 1
|
|
50
|
+
};
|
|
51
|
+
/** The Transitional spelling of one Strict-produced value, or the value unchanged. */
|
|
52
|
+
const transitionalValue = (value, namespaceUri, encoding) => {
|
|
53
|
+
const measureUnit = encoding?.measure;
|
|
54
|
+
if (measureUnit !== void 0) {
|
|
55
|
+
const measure = universalMeasureAs(value, measureUnit);
|
|
56
|
+
if (measure !== void 0) return String(measure);
|
|
57
|
+
}
|
|
58
|
+
const percentage = PERCENTAGE.exec(value);
|
|
59
|
+
if (percentage === null) return value;
|
|
60
|
+
const percentUnit = encoding?.percent ?? (isUnschemadDrawingNamespace(namespaceUri) ? "thousandthPercent" : void 0);
|
|
61
|
+
if (percentUnit === void 0) return value;
|
|
62
|
+
return String(roundHalfAwayFromZero(Number(percentage[1]) * NUMBERS_PER_PERCENT[percentUnit]));
|
|
63
|
+
};
|
|
64
|
+
const originOf = (element, inherited) => {
|
|
65
|
+
const uri = element.namespaceUri;
|
|
66
|
+
if (uri === void 0) return inherited;
|
|
67
|
+
if (isStrictNamespaceUri(uri)) return "strict";
|
|
68
|
+
if (uri.startsWith("http://purl.oclc.org/ooxml/")) throw new UntranslatableStrictNamespaceError({
|
|
69
|
+
message: `Strict namespace ${uri} has no Transitional counterpart; folio will not replay it under a Transitional root.`,
|
|
70
|
+
uri
|
|
71
|
+
});
|
|
72
|
+
return TRANSITIONAL_URIS.has(uri) ? "transitional" : inherited;
|
|
73
|
+
};
|
|
74
|
+
const convertAttributes = (element, namespaceUri, localName) => {
|
|
75
|
+
const attributes = element.attributes ?? {};
|
|
76
|
+
let converted;
|
|
77
|
+
for (const [name, raw] of Object.entries(attributes)) {
|
|
78
|
+
if (typeof raw !== "string") continue;
|
|
79
|
+
const next = name === "xmlns" || name.startsWith("xmlns:") ? toTransitionalNamespaceUri(raw) : transitionalValue(raw, namespaceUri, transitionalSlotEncoding(element.namespaceUri, localName, getLocalName(name)));
|
|
80
|
+
if (next === raw) continue;
|
|
81
|
+
converted ??= { ...attributes };
|
|
82
|
+
converted[name] = next;
|
|
83
|
+
}
|
|
84
|
+
return converted;
|
|
85
|
+
};
|
|
86
|
+
const childWithValue = (child, text) => text === child.text ? child : {
|
|
87
|
+
...child,
|
|
88
|
+
text
|
|
89
|
+
};
|
|
90
|
+
const toTransitional = (element, inherited) => {
|
|
91
|
+
if (element.type === "text") return element;
|
|
92
|
+
const origin = originOf(element, inherited);
|
|
93
|
+
const namespaceUri = element.namespaceUri === void 0 ? "" : toTransitionalNamespaceUri(element.namespaceUri);
|
|
94
|
+
const localName = getLocalName(element.name);
|
|
95
|
+
const textEncoding = transitionalSlotEncoding(element.namespaceUri, localName);
|
|
96
|
+
const attributes = origin === "strict" && element.attributes ? convertAttributes(element, namespaceUri, localName) : void 0;
|
|
97
|
+
let elements;
|
|
98
|
+
for (const [index, child] of (element.elements ?? []).entries()) {
|
|
99
|
+
const next = origin === "strict" && child.type === "text" && typeof child.text === "string" ? childWithValue(child, transitionalValue(child.text, namespaceUri, textEncoding)) : toTransitional(child, origin);
|
|
100
|
+
if (next === child) continue;
|
|
101
|
+
elements ??= [...element.elements ?? []];
|
|
102
|
+
elements[index] = next;
|
|
103
|
+
}
|
|
104
|
+
if (attributes === void 0 && elements === void 0) return element;
|
|
105
|
+
return {
|
|
106
|
+
...element,
|
|
107
|
+
...attributes === void 0 ? {} : { attributes },
|
|
108
|
+
...elements === void 0 ? {} : { elements }
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
/** True when any binding in scope, including inherited ones, is a Strict namespace. */
|
|
112
|
+
const scopeDeclaresStrict = (scope) => {
|
|
113
|
+
for (let current = scope; current; current = current.parent) for (const uri of current.bindings.values()) if (uri.startsWith("http://purl.oclc.org/ooxml/")) return true;
|
|
114
|
+
return false;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Serialize parsed markup for replay inside a rebuilt Transitional part.
|
|
118
|
+
*
|
|
119
|
+
* Every verbatim capture goes through here — a lint rule keeps
|
|
120
|
+
* {@link elementToXml} out of reach of the parsers — so a replay path added
|
|
121
|
+
* later cannot skip the conversion. Markup that binds no Strict namespace,
|
|
122
|
+
* anywhere in scope or in the fragment itself, is serialized once and returned
|
|
123
|
+
* unchanged.
|
|
124
|
+
*/
|
|
125
|
+
const captureVerbatimXml = (element) => {
|
|
126
|
+
const xml = elementToXml(element);
|
|
127
|
+
if (!xml.includes("http://purl.oclc.org/ooxml/") && !scopeDeclaresStrict(element.namespaceScope)) return xml;
|
|
128
|
+
return elementToXml(toTransitional(element, "transitional"));
|
|
129
|
+
};
|
|
130
|
+
//#endregion
|
|
131
|
+
export { UntranslatableStrictNamespaceError, captureVerbatimXml };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { sanitizeImageSrc } from "../utils/sanitizeImageSrc.js";
|
|
2
2
|
import { pixelsToEmu } from "../utils/units.js";
|
|
3
3
|
import { resolveImageData } from "./imageParser.js";
|
|
4
|
+
import { captureVerbatimXml } from "./verbatimCapture.js";
|
|
4
5
|
import { isValidVmlPreviewDimension, parseVmlNumber, parseVmlStyle, renderStandaloneVmlPreview, renderVmlGroupPreview, vmlCssLengthToPx, vmlSvgDataUrl } from "./vmlPreview.js";
|
|
5
6
|
import { isWatermarkShape } from "./watermarkParser.js";
|
|
6
|
-
import { cloneWithXmlnsDeclarations,
|
|
7
|
+
import { cloneWithXmlnsDeclarations, findAllDeep, findChild, getAttribute, getChildElements, getLocalName } from "./xmlParser.js";
|
|
7
8
|
//#region src/docx/vmlImageParser.ts
|
|
8
9
|
const VML_POSITION_ABSOLUTE = "absolute";
|
|
9
10
|
const IMAGE_WRAP_INLINE = "inline";
|
|
@@ -90,7 +91,7 @@ const previewImage = (pictElement, svg, widthPx, heightPx, style, rootXmlns) =>
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
},
|
|
93
|
-
rawXml:
|
|
94
|
+
rawXml: captureVerbatimXml(cloneWithXmlnsDeclarations(pictElement, rootXmlns))
|
|
94
95
|
};
|
|
95
96
|
};
|
|
96
97
|
const previewDrawing = (pictElement, preview, rootXmlns) => {
|
|
@@ -154,7 +155,7 @@ function parseVmlImageContent(pictElement, rels, media, rootXmlns = {}) {
|
|
|
154
155
|
return {
|
|
155
156
|
type: "drawing",
|
|
156
157
|
image,
|
|
157
|
-
rawXml:
|
|
158
|
+
rawXml: captureVerbatimXml(cloneWithXmlnsDeclarations(pictElement, rootXmlns))
|
|
158
159
|
};
|
|
159
160
|
}
|
|
160
161
|
for (const child of getChildElements(pictElement)) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { captureVerbatimXml } from "./verbatimCapture.js";
|
|
2
|
+
import { cloneWithXmlnsDeclarations, collectXmlnsDeclarations, findChild, findChildren, findDeep, getAttribute, getLocalName, getTextContent } from "./xmlParser.js";
|
|
2
3
|
//#region src/docx/watermarkParser.ts
|
|
3
4
|
const VML_TEXT_WATERMARK_SHAPETYPE = "#_x0000_t136";
|
|
4
5
|
/**
|
|
@@ -38,7 +39,7 @@ function parseWatermark(header) {
|
|
|
38
39
|
const hosting = findEnclosingParagraph(header, shape);
|
|
39
40
|
if (hosting) return {
|
|
40
41
|
watermark,
|
|
41
|
-
rawParagraphXml:
|
|
42
|
+
rawParagraphXml: captureVerbatimXml(cloneWithXmlnsDeclarations(hosting, headerXmlns)),
|
|
42
43
|
hostingParagraph: hosting,
|
|
43
44
|
blockIndex: blockIndexOf(header, hosting)
|
|
44
45
|
};
|
|
@@ -50,7 +51,7 @@ function parseWatermark(header) {
|
|
|
50
51
|
const hosting = findEnclosingParagraph(header, anchor);
|
|
51
52
|
if (hosting) return {
|
|
52
53
|
watermark,
|
|
53
|
-
rawParagraphXml:
|
|
54
|
+
rawParagraphXml: captureVerbatimXml(cloneWithXmlnsDeclarations(hosting, headerXmlns)),
|
|
54
55
|
hostingParagraph: hosting,
|
|
55
56
|
blockIndex: blockIndexOf(header, hosting)
|
|
56
57
|
};
|
package/dist/docx/xmlParser.d.ts
CHANGED
|
@@ -77,7 +77,18 @@ declare const NAMESPACES: {
|
|
|
77
77
|
* @param xml - XML string to parse
|
|
78
78
|
* @returns Parsed element tree
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* The prefix bindings a WordprocessingML part declares on its root.
|
|
82
|
+
*
|
|
83
|
+
* A property element captured out of a document carries no `xmlns` of its
|
|
84
|
+
* own, so parsing it on its own resolves no prefix and every lookup by
|
|
85
|
+
* namespace URI misses. Parsing it under this scope puts it back in the
|
|
86
|
+
* context it was written in. A part that binds `w` to something else — or
|
|
87
|
+
* binds it to a prefix this map does not know — simply fails to match, and
|
|
88
|
+
* the caller falls back to whatever it does without the capture.
|
|
89
|
+
*/
|
|
90
|
+
declare const OOXML_NAMESPACE_SCOPE: XmlNamespaceScope;
|
|
91
|
+
declare function parseXml(xml: string, inheritedNamespaceScope?: XmlNamespaceScope): XmlElement;
|
|
81
92
|
/**
|
|
82
93
|
* Serialize an XmlElement back to an XML string
|
|
83
94
|
*/
|
|
@@ -345,5 +356,15 @@ declare function mergeXmlnsDeclarations(inherited: Record<string, string>, eleme
|
|
|
345
356
|
* canonical binding so the detached subtree is valid on its first replay.
|
|
346
357
|
*/
|
|
347
358
|
declare function cloneWithXmlnsDeclarations(element: XmlElement, xmlnsDecls: Record<string, string>): XmlElement;
|
|
359
|
+
/**
|
|
360
|
+
* Shallow clone of an element that keeps its resolved namespace metadata.
|
|
361
|
+
*
|
|
362
|
+
* `namespaceUri` and `namespaceScope` are non-enumerable so structural
|
|
363
|
+
* comparisons stay stable, which also means a plain spread drops them and
|
|
364
|
+
* every namespace-URI lookup on the copy misses. Re-attaching over the
|
|
365
|
+
* original's scope leaves resolution unchanged whether or not the clone
|
|
366
|
+
* carries `xmlns` attributes of its own.
|
|
367
|
+
*/
|
|
368
|
+
declare function cloneElement(element: XmlElement, overrides: Partial<XmlElement>): XmlElement;
|
|
348
369
|
//#endregion
|
|
349
|
-
export { NAMESPACES, WORDPROCESSINGML_NAMESPACE_URIS, XmlAttributeMatch, XmlElement, XmlNamespaceScope, attachXmlNamespaceContext, cloneWithXmlnsDeclarations, collectXmlnsDeclarations, elementToXml, findAllDeep, findAttributeByNamespaceUri, findByFullName, findChild, findChildByLocalName, findChildByNamespaceUri, findChildren, findChildrenByLocalName, findDeep, getAttribute, getAttributeAny, getAttributeAnyPrefix, getAttributeByNamespaceUri, getAttributes, getChildElements, getLocalName, getNamespacePrefix, getNamespaceUri, getTextContent, hasChild, hasFlag, matchesName, mergeXmlnsDeclarations, parseBooleanElement, parseColorElement, parseNumberingLevelAttribute, parseNumericAttribute, parseOnOffValue, parseTableMeasurementValue, parseXml, parseXmlDocument };
|
|
370
|
+
export { NAMESPACES, OOXML_NAMESPACE_SCOPE, WORDPROCESSINGML_NAMESPACE_URIS, XmlAttributeMatch, XmlElement, XmlNamespaceScope, attachXmlNamespaceContext, cloneElement, cloneWithXmlnsDeclarations, collectXmlnsDeclarations, elementToXml, findAllDeep, findAttributeByNamespaceUri, findByFullName, findChild, findChildByLocalName, findChildByNamespaceUri, findChildren, findChildrenByLocalName, findDeep, getAttribute, getAttributeAny, getAttributeAnyPrefix, getAttributeByNamespaceUri, getAttributes, getChildElements, getLocalName, getNamespacePrefix, getNamespaceUri, getTextContent, hasChild, hasFlag, matchesName, mergeXmlnsDeclarations, parseBooleanElement, parseColorElement, parseNumberingLevelAttribute, parseNumericAttribute, parseOnOffValue, parseTableMeasurementValue, parseXml, parseXmlDocument };
|
package/dist/docx/xmlParser.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { transitionalSlotEncoding } from "./transitionalSpelling.js";
|
|
2
|
+
import { universalMeasureAs } from "./universalMeasure.js";
|
|
1
3
|
import { XMLBuilder, XMLParser } from "fast-xml-parser";
|
|
2
4
|
import { OOXML_NS } from "@stll/docx-utils";
|
|
3
5
|
//#region src/docx/xmlParser.ts
|
|
@@ -130,8 +132,8 @@ function fxpNodeToElement(node, inheritedNamespaceScope = EMPTY_NAMESPACE_SCOPE)
|
|
|
130
132
|
* XmlElement that matches xml-js's non-compact root structure:
|
|
131
133
|
* `{ elements: [...] }`.
|
|
132
134
|
*/
|
|
133
|
-
function fxpToRootElement(nodes) {
|
|
134
|
-
for (let index = 0; index < nodes.length; index += 1) nodes[index] = fxpNodeToElement(nodes[index]);
|
|
135
|
+
function fxpToRootElement(nodes, inheritedNamespaceScope = EMPTY_NAMESPACE_SCOPE) {
|
|
136
|
+
for (let index = 0; index < nodes.length; index += 1) nodes[index] = fxpNodeToElement(nodes[index], inheritedNamespaceScope);
|
|
135
137
|
return { elements: nodes };
|
|
136
138
|
}
|
|
137
139
|
/**
|
|
@@ -156,8 +158,19 @@ const NAMESPACES = OOXML_NS;
|
|
|
156
158
|
* @param xml - XML string to parse
|
|
157
159
|
* @returns Parsed element tree
|
|
158
160
|
*/
|
|
159
|
-
|
|
160
|
-
|
|
161
|
+
/**
|
|
162
|
+
* The prefix bindings a WordprocessingML part declares on its root.
|
|
163
|
+
*
|
|
164
|
+
* A property element captured out of a document carries no `xmlns` of its
|
|
165
|
+
* own, so parsing it on its own resolves no prefix and every lookup by
|
|
166
|
+
* namespace URI misses. Parsing it under this scope puts it back in the
|
|
167
|
+
* context it was written in. A part that binds `w` to something else — or
|
|
168
|
+
* binds it to a prefix this map does not know — simply fails to match, and
|
|
169
|
+
* the caller falls back to whatever it does without the capture.
|
|
170
|
+
*/
|
|
171
|
+
const OOXML_NAMESPACE_SCOPE = { bindings: new Map(Object.entries(OOXML_NS)) };
|
|
172
|
+
function parseXml(xml, inheritedNamespaceScope = EMPTY_NAMESPACE_SCOPE) {
|
|
173
|
+
return fxpToRootElement((xml.includes("binData") ? fxpParserWithStopNodes : fxpParser).parse(xml), inheritedNamespaceScope);
|
|
161
174
|
}
|
|
162
175
|
/**
|
|
163
176
|
* Serialize an XmlElement back to an XML string
|
|
@@ -495,6 +508,9 @@ function parseColorElement(element) {
|
|
|
495
508
|
function parseNumericAttribute(element, namespace, name, scale = 1) {
|
|
496
509
|
const value = getAttribute(element, namespace, name);
|
|
497
510
|
if (value === null) return;
|
|
511
|
+
const unit = transitionalSlotEncoding(element?.namespaceUri, getLocalName(element?.name), name)?.measure;
|
|
512
|
+
const measure = unit === void 0 ? void 0 : universalMeasureAs(value, unit);
|
|
513
|
+
if (measure !== void 0) return measure * scale;
|
|
498
514
|
const num = Number.parseInt(value, 10);
|
|
499
515
|
if (Number.isNaN(num)) return;
|
|
500
516
|
return num * scale;
|
|
@@ -523,6 +539,8 @@ function parseTableMeasurementValue(element, widthType) {
|
|
|
523
539
|
const pct = Number.parseFloat(trimmed.slice(0, -1));
|
|
524
540
|
if (!Number.isNaN(pct)) return Math.round(pct * 50);
|
|
525
541
|
}
|
|
542
|
+
const measure = universalMeasureAs(trimmed, "twips");
|
|
543
|
+
if (measure !== void 0) return measure;
|
|
526
544
|
const num = Number.parseInt(trimmed, 10);
|
|
527
545
|
return Number.isNaN(num) ? void 0 : num;
|
|
528
546
|
}
|
|
@@ -741,14 +759,28 @@ function cloneWithXmlnsDeclarations(element, xmlnsDecls) {
|
|
|
741
759
|
if (!prefix || attributes[name] !== void 0 || additions[name] !== void 0 || !isCanonicalNamespacePrefix(prefix)) continue;
|
|
742
760
|
additions[name] = NAMESPACES[prefix];
|
|
743
761
|
}
|
|
744
|
-
for (const _key in additions) return {
|
|
762
|
+
for (const _key in additions) return cloneElement(element, { attributes: {
|
|
763
|
+
...attributes,
|
|
764
|
+
...additions
|
|
765
|
+
} });
|
|
766
|
+
return element;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Shallow clone of an element that keeps its resolved namespace metadata.
|
|
770
|
+
*
|
|
771
|
+
* `namespaceUri` and `namespaceScope` are non-enumerable so structural
|
|
772
|
+
* comparisons stay stable, which also means a plain spread drops them and
|
|
773
|
+
* every namespace-URI lookup on the copy misses. Re-attaching over the
|
|
774
|
+
* original's scope leaves resolution unchanged whether or not the clone
|
|
775
|
+
* carries `xmlns` attributes of its own.
|
|
776
|
+
*/
|
|
777
|
+
function cloneElement(element, overrides) {
|
|
778
|
+
const clone = {
|
|
745
779
|
...element,
|
|
746
|
-
|
|
747
|
-
...attributes,
|
|
748
|
-
...additions
|
|
749
|
-
}
|
|
780
|
+
...overrides
|
|
750
781
|
};
|
|
751
|
-
|
|
782
|
+
attachXmlNamespaceContext(clone, element.namespaceScope);
|
|
783
|
+
return clone;
|
|
752
784
|
}
|
|
753
785
|
//#endregion
|
|
754
|
-
export { NAMESPACES, WORDPROCESSINGML_NAMESPACE_URIS, attachXmlNamespaceContext, cloneWithXmlnsDeclarations, collectXmlnsDeclarations, elementToXml, findAllDeep, findAttributeByNamespaceUri, findByFullName, findChild, findChildByLocalName, findChildByNamespaceUri, findChildren, findChildrenByLocalName, findDeep, getAttribute, getAttributeAny, getAttributeAnyPrefix, getAttributeByNamespaceUri, getAttributes, getChildElements, getLocalName, getNamespacePrefix, getNamespaceUri, getTextContent, hasChild, hasFlag, matchesName, mergeXmlnsDeclarations, parseBooleanElement, parseColorElement, parseNumberingLevelAttribute, parseNumericAttribute, parseOnOffValue, parseTableMeasurementValue, parseXml, parseXmlDocument };
|
|
786
|
+
export { NAMESPACES, OOXML_NAMESPACE_SCOPE, WORDPROCESSINGML_NAMESPACE_URIS, attachXmlNamespaceContext, cloneElement, cloneWithXmlnsDeclarations, collectXmlnsDeclarations, elementToXml, findAllDeep, findAttributeByNamespaceUri, findByFullName, findChild, findChildByLocalName, findChildByNamespaceUri, findChildren, findChildrenByLocalName, findDeep, getAttribute, getAttributeAny, getAttributeAnyPrefix, getAttributeByNamespaceUri, getAttributes, getChildElements, getLocalName, getNamespacePrefix, getNamespaceUri, getTextContent, hasChild, hasFlag, matchesName, mergeXmlnsDeclarations, parseBooleanElement, parseColorElement, parseNumberingLevelAttribute, parseNumericAttribute, parseOnOffValue, parseTableMeasurementValue, parseXml, parseXmlDocument };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { document_d_exports } from "./types/document.js";
|
|
1
2
|
import { FolioAIBlock, FolioAIBlockAnchor, FolioAIBlockKind, FolioAIBlockPreviewRun, FolioAIBlockTableLocation, FolioAIComment, FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditNormalization, FolioAIEditNormalizationCode, FolioAIEditOperation, FolioAIEditPrecondition, FolioAIEditReviewMeta, FolioAIEditSeverity, FolioAIEditSkipReason, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAISignatureParty } from "./ai-edits/types.js";
|
|
2
3
|
import { WORD_DIFF_GRANULARITIES, WordDiffGranularity, WordDiffNormalization, WordDiffOptions, WordDiffSegment, diffWordSegments } from "./ai-edits/word-diff.js";
|
|
3
4
|
import { FolioAIEditApplyOutcome, FolioRevisionStamp, FolioWordDiffOptions, applyFolioAIEditOperations } from "./ai-edits/apply.js";
|
|
4
|
-
import { document_d_exports } from "./types/document.js";
|
|
5
5
|
import { ApplyFolioDocumentOperationsOptions, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FolioDocumentOperation, FolioDocumentOperationAffectedTarget, FolioDocumentOperationBatch, FolioDocumentOperationCapabilities, FolioDocumentOperationIssue, FolioDocumentOperationMode, FolioDocumentOperationPrecondition, FolioDocumentOperationReceipt, FolioDocumentOperationRecovery, FolioDocumentOperationResult, FolioDocumentOperationResultBase, FolioDocumentOperationStatus, FolioDocumentOperationStory, FolioDocumentOperationType, FolioDocumentOperationUndoFailureReason, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, applyFolioDocumentOperations, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch } from "./document-operations.js";
|
|
6
6
|
import { createFolioAIEditSnapshot, hashFolioAIBlockText, isFolioAIContentBlock, normalizeFolioAIBlockText } from "./ai-edits/snapshot.js";
|
|
7
|
-
import { DeriveBlockIdInput, FolioBlockId, deriveBlockId, getFolioParaIdFromBlockId, isFolioBlockId, isSequentialFolioBlockId } from "./types/block-id.js";
|
|
7
|
+
import { DeriveBlockIdInput, FolioBlockId, currentFolioBlockId, deriveBlockId, getFolioParaIdFromBlockId, isFolioBlockId, isSequentialFolioBlockId } from "./types/block-id.js";
|
|
8
8
|
import "./ai-edits/index.js";
|
|
9
9
|
import { AIBarStatus, AIChatMode, AICitation, AICitationSource, AIGenerateInput, AISuggestion, AISuggestionApplyMode, AISuggestionPreset, AISuggestionSeverity, AISuggestionStatus, DEFAULT_AI_SUGGESTION_PRESETS } from "./ai-suggestions/types.js";
|
|
10
10
|
import { ApplyResult, applySuggestions } from "./ai-suggestions/apply.js";
|
|
11
11
|
import { ResolvedAnchor, isSuggestionStale, resolveSuggestionAnchor } from "./ai-suggestions/conflict.js";
|
|
12
12
|
import { PositionalText, buildPositionalText } from "./ai-suggestions/text-positions.js";
|
|
13
|
-
import { COMPARE_VERIFICATION_CAUSES, COMPARE_VERIFICATION_INVARIANTS, CompareVerification, CompareVerificationCause, CompareVerificationFailure, CompareVerificationInvariant,
|
|
13
|
+
import { COMPARE_VERIFICATION_CAUSES, COMPARE_VERIFICATION_INVARIANTS, CompareVerification, CompareVerificationCause, CompareVerificationFailure, CompareVerificationInvariant, FinalParagraphMarkRevision } from "./compare/verification.js";
|
|
14
14
|
import { COMPARE_UNSUPPORTED_REASONS, CompareChange, CompareChangeLocation, CompareDocxApplyError, CompareDocxError, CompareDocxFinalParagraphMarkError, CompareDocxOperationLimitError, CompareDocxOptions, CompareDocxParseError, CompareDocxRoundTripError, CompareDocxSerializeError, CompareFormatRange, CompareResult, CompareUnsupportedPart, CompareUnsupportedReason, InvalidCompareDocxOptionsError } from "./compare/types.js";
|
|
15
15
|
import { MAX_COMPARE_OPERATIONS, compareDocx } from "./compare/compare.js";
|
|
16
16
|
import { DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DocumentPreset, DocumentStyleSet } from "./style-sets/types.js";
|
|
@@ -38,4 +38,4 @@ import { getGoogleFontsEnabled, setEmbeddedFontFamilyMap, setGoogleFontsEnabled
|
|
|
38
38
|
import { DOCX_CONFORMANCE_CLASSES } from "@stll/docx-core/model";
|
|
39
39
|
type Document = document_d_exports.Document;
|
|
40
40
|
type DocxConformanceClass = document_d_exports.DocxConformanceClass;
|
|
41
|
-
export { type AIBarStatus, type AIChatMode, type AICitation, type AICitationRange, type AICitationSource, type AIGenerateInput, type AISuggestion, type AISuggestionApplyMode, type AISuggestionPreset, type AISuggestionSeverity, type AISuggestionStatus, type AcceptAutocompleteResult, type AnonymizationMatch, type AnonymizationTerm, type ApplyFolioDocumentOperationsOptions, type ApplyResult, type AutocompleteSuggestionPluginOptions, type AutocompleteSuggestionState, type AutocompleteSuggestionStatus, type AutocompleteTriggerCheck, type AutocompleteTriggerOptions, type AutocompleteTriggerSkipReason, type BlockRect, COMPARE_UNSUPPORTED_REASONS, COMPARE_VERIFICATION_CAUSES, COMPARE_VERIFICATION_INVARIANTS, type CompareChange, type CompareChangeLocation, CompareDocxApplyError, type CompareDocxError, CompareDocxFinalParagraphMarkError, CompareDocxOperationLimitError, type CompareDocxOptions, CompareDocxParseError, CompareDocxRoundTripError, CompareDocxSerializeError, type CompareFormatRange, type CompareResult, type CompareUnsupportedPart, type CompareUnsupportedReason, type CompareVerification, type CompareVerificationCause, type CompareVerificationFailure, type CompareVerificationInvariant, type CreateEmptyDocumentOptions, DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, type DeriveBlockIdInput, type DirectiveKind, type DirectiveRange, type Document, type DocumentPreset, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, type DocxCompatibility, type DocxCompatibilityContext, type DocxCompatibilityIssue, type DocxCompatibilityLocation, type DocxCompatibilityPart, type DocxConformanceClass, type EmbeddedFont, type EmbeddedFontParts, type ExtractDocumentStyleSetOptions, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, type
|
|
41
|
+
export { type AIBarStatus, type AIChatMode, type AICitation, type AICitationRange, type AICitationSource, type AIGenerateInput, type AISuggestion, type AISuggestionApplyMode, type AISuggestionPreset, type AISuggestionSeverity, type AISuggestionStatus, type AcceptAutocompleteResult, type AnonymizationMatch, type AnonymizationTerm, type ApplyFolioDocumentOperationsOptions, type ApplyResult, type AutocompleteSuggestionPluginOptions, type AutocompleteSuggestionState, type AutocompleteSuggestionStatus, type AutocompleteTriggerCheck, type AutocompleteTriggerOptions, type AutocompleteTriggerSkipReason, type BlockRect, COMPARE_UNSUPPORTED_REASONS, COMPARE_VERIFICATION_CAUSES, COMPARE_VERIFICATION_INVARIANTS, type CompareChange, type CompareChangeLocation, CompareDocxApplyError, type CompareDocxError, CompareDocxFinalParagraphMarkError, CompareDocxOperationLimitError, type CompareDocxOptions, CompareDocxParseError, CompareDocxRoundTripError, CompareDocxSerializeError, type CompareFormatRange, type CompareResult, type CompareUnsupportedPart, type CompareUnsupportedReason, type CompareVerification, type CompareVerificationCause, type CompareVerificationFailure, type CompareVerificationInvariant, type CreateEmptyDocumentOptions, DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, type DeriveBlockIdInput, type DirectiveKind, type DirectiveRange, type Document, type DocumentPreset, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, type DocxCompatibility, type DocxCompatibilityContext, type DocxCompatibilityIssue, type DocxCompatibilityLocation, type DocxCompatibilityPart, type DocxConformanceClass, type EmbeddedFont, type EmbeddedFontParts, type ExtractDocumentStyleSetOptions, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, type FinalParagraphMarkRevision, type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIBlockTableLocation, type FolioAIComment, type FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyOutcome, type FolioAIEditApplyResult, type FolioAIEditNormalization, type FolioAIEditNormalizationCode, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAISignatureParty, type FolioBlockId, type FolioDocumentOperation, type FolioDocumentOperationAffectedTarget, type FolioDocumentOperationBatch, type FolioDocumentOperationCapabilities, type FolioDocumentOperationIssue, type FolioDocumentOperationMode, type FolioDocumentOperationPrecondition, type FolioDocumentOperationReceipt, type FolioDocumentOperationRecovery, type FolioDocumentOperationResult, type FolioDocumentOperationResultBase, type FolioDocumentOperationStatus, type FolioDocumentOperationStory, type FolioDocumentOperationType, type FolioDocumentOperationUndoFailureReason, type FolioDocumentOperationUndoHandle, type FolioDocumentOperationUndoResult, type FolioDocxCompatibilityHost, type FolioDocxCompatibilityProfile, type FolioRevisionStamp, type FolioWordDiffOptions, type ImageMeta, type ImageRef, type InspectDocxCompatibilityOptions, InvalidCompareDocxOptionsError, InvalidFolioDocumentOperationBatchError, MAX_COMPARE_OPERATIONS, type MarkdownOptions, type MarkdownResult, type PositionalText, type ResolvedAnchor, STELLA_STYLE_SET_NAME, type TemplatePreviewSpan, type TemplatePreviewValue, type TemplatePreviewValues, type TemplateSlashMenuKeyAction, type TemplateSlashMenuState, UnsupportedFolioDocumentOperationVersionError, WORD_DIFF_GRANULARITIES, type WordDiffGranularity, type WordDiffNormalization, type WordDiffOptions, type WordDiffSegment, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, compareDocx, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, currentFolioBlockId, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, isFolioAIContentBlock, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSuggestionStale, isSupportedFolioDocumentOperationVersion, mergeDocumentContent, normalizeFolioAIBlockText, parseFolioDocumentOperationBatch, resetTemplateSlashQuery, resolveSuggestionAnchor, scanDirectives, scopeEmbeddedFontFamily, scrollFolioPositionIntoView, setAICitationsMeta, setAISuggestionsMeta, setActiveCitationMeta, setAnonymizationTermsMeta, setEmbeddedFontFamilyMap, setFocusedSuggestionMeta, setGoogleFontsEnabled, setTemplatePreviewValues, shouldTriggerAutocomplete, startAutocompleteSuggestion, templateSlashMenuKey, toMarkdown, toMarkdownResult };
|