@stll/folio-core 0.53.0 → 0.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-edits/apply.js +415 -166
- package/dist/ai-edits/batch-claims.d.ts +21 -6
- package/dist/ai-edits/batch-claims.js +47 -16
- package/dist/ai-edits/headless.d.ts +20 -0
- package/dist/ai-edits/headless.js +140 -11
- package/dist/ai-edits/pending-suggestions.js +1 -1
- package/dist/ai-edits/read.d.ts +5 -3
- package/dist/ai-edits/read.js +97 -47
- package/dist/ai-edits/revisionStretches.d.ts +17 -0
- package/dist/ai-edits/revisionStretches.js +80 -0
- package/dist/ai-edits/snapshot.js +3 -2
- package/dist/ai-edits/table-cell-mutations.d.ts +3 -1
- package/dist/ai-edits/table-cell-mutations.js +2 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +6 -1
- package/dist/ai-edits/table-row-column-mutations.js +27 -10
- package/dist/compare/content-alignment.d.ts +5 -1
- package/dist/compare/content-alignment.js +39 -32
- package/dist/compare/inline-provenance.js +1 -1
- package/dist/controller/layoutPipeline.js +3 -2
- package/dist/docx/archiveInflation.d.ts +127 -0
- package/dist/docx/archiveInflation.js +181 -0
- package/dist/docx/metadataPrivacy.js +24 -1
- package/dist/docx/noteReferenceMark.d.ts +15 -0
- package/dist/docx/noteReferenceMark.js +48 -0
- package/dist/docx/paragraphParser.js +5 -3
- package/dist/docx/paragraphPropertySource.d.ts +1 -1
- package/dist/docx/paragraphPropertySource.js +4 -2
- package/dist/docx/parser.js +2 -2
- package/dist/docx/rezip.js +4 -2
- package/dist/docx/selectiveXmlPatch.d.ts +3 -1
- package/dist/docx/selectiveXmlPatch.js +81 -3
- package/dist/docx/server/boundedArchive.d.ts +8 -13
- package/dist/docx/server/boundedArchive.js +70 -59
- package/dist/docx/server/extractDocxText.d.ts +8 -2
- package/dist/docx/server/extractDocxText.js +2 -2
- package/dist/docx/server/validateDocxConformance.d.ts +1 -1
- package/dist/docx/server/validateDocxConformance.js +1 -0
- package/dist/docx/unzip.d.ts +19 -2
- package/dist/docx/unzip.js +135 -24
- package/dist/docx/verticalMergeProjection.d.ts +17 -0
- package/dist/docx/verticalMergeProjection.js +120 -0
- package/dist/fonts/embeddedFonts.js +1 -1
- package/dist/i18n/messages/catalogs.gen.d.ts +34 -34
- package/dist/i18n/messages/catalogs.gen.js +34 -34
- package/dist/i18n/messages/messages.gen.d.ts +2 -2
- package/dist/internal/wholeStoryRevisionResolution.js +95 -25
- package/dist/layout-engine/measure/measureParagraph.js +2 -2
- package/dist/layout-engine/measure/paragraphMeasureShared.d.ts +12 -1
- package/dist/layout-engine/measure/paragraphMeasureShared.js +14 -1
- package/dist/markdown/escape.d.ts +2 -2
- package/dist/markdown/escape.js +4 -5
- package/dist/markdown/renderBlock.js +91 -25
- package/dist/markdown/renderRuns.d.ts +10 -1
- package/dist/markdown/renderRuns.js +320 -59
- package/dist/prosemirror/clearRunColor.d.ts +6 -0
- package/dist/prosemirror/clearRunColor.js +46 -0
- package/dist/prosemirror/commands/comments.js +62 -22
- package/dist/prosemirror/commands/formatPainter.js +1 -1
- package/dist/prosemirror/commands/hyperlink.js +2 -1
- package/dist/prosemirror/commands/propertyChangeScope.d.ts +3 -2
- package/dist/prosemirror/commands/propertyChangeScope.js +28 -4
- package/dist/prosemirror/commands/resolveAllTableChanges.js +40 -41
- package/dist/prosemirror/commands/resolveParagraphProperties.js +33 -8
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +7 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.js +39 -20
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +61 -0
- package/dist/prosemirror/commands/tableMergeFoldDecisions.js +79 -0
- package/dist/prosemirror/containerFinalParagraph.d.ts +11 -5
- package/dist/prosemirror/containerFinalParagraph.js +7 -6
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -13
- package/dist/prosemirror/conversion/fromProseDoc.js +12 -590
- package/dist/prosemirror/conversion/toProseDoc.d.ts +1 -13
- package/dist/prosemirror/conversion/toProseDoc.js +28 -262
- package/dist/prosemirror/documentSchema.d.ts +8 -0
- package/dist/prosemirror/documentSchema.js +18 -0
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +104 -63
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +24 -3
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.js +43 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +10 -9
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +2 -4
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +14 -8
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +8 -4
- package/dist/prosemirror/extensions/marks/StrikeExtension.js +2 -2
- package/dist/prosemirror/extensions/marks/SubscriptExtension.js +2 -2
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +2 -2
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +4 -3
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +8 -6
- package/dist/prosemirror/extensions/marks/markUtils.js +17 -8
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +3 -1
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +12 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +2 -2
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +5 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +104 -210
- package/dist/prosemirror/extensions/types.d.ts +7 -0
- package/dist/prosemirror/hyperlinkRemoval.d.ts +9 -0
- package/dist/prosemirror/hyperlinkRemoval.js +129 -0
- package/dist/prosemirror/index.d.ts +2 -1
- package/dist/prosemirror/index.js +2 -1
- package/dist/prosemirror/listNumbering.d.ts +3 -21
- package/dist/prosemirror/listNumbering.js +24 -39
- package/dist/prosemirror/listRendering.d.ts +29 -0
- package/dist/prosemirror/listRendering.js +26 -0
- package/dist/prosemirror/markupViewNotes.d.ts +8 -0
- package/dist/prosemirror/markupViewNotes.js +49 -0
- package/dist/prosemirror/markupViewProjection.d.ts +3 -1
- package/dist/prosemirror/markupViewProjection.js +7 -2
- package/dist/prosemirror/noteReferenceReview.d.ts +77 -0
- package/dist/prosemirror/noteReferenceReview.js +332 -0
- package/dist/prosemirror/paragraphIndentation.js +5 -2
- package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -4
- package/dist/prosemirror/paragraphMarkJoin.js +21 -19
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +64 -0
- package/dist/prosemirror/paragraphPropertyCarry.js +155 -0
- package/dist/prosemirror/plugins/documentStyleState.d.ts +26 -0
- package/dist/prosemirror/plugins/documentStyleState.js +32 -0
- package/dist/prosemirror/plugins/documentStyles.d.ts +2 -21
- package/dist/prosemirror/plugins/documentStyles.js +66 -29
- package/dist/prosemirror/plugins/index.d.ts +2 -1
- package/dist/prosemirror/plugins/index.js +2 -1
- package/dist/prosemirror/plugins/paragraphStyleResolution.d.ts +15 -0
- package/dist/prosemirror/plugins/paragraphStyleResolution.js +230 -0
- package/dist/prosemirror/plugins/suggestionMode.d.ts +12 -2
- package/dist/prosemirror/plugins/suggestionMode.js +387 -28
- package/dist/prosemirror/plugins/templateDirectives.d.ts +6 -0
- package/dist/prosemirror/plugins/templateDirectives.js +21 -7
- package/dist/prosemirror/plugins/templatePreviewValues.js +14 -21
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +22 -2
- package/dist/prosemirror/rebaseParagraphRunFormatting.js +39 -13
- package/dist/prosemirror/rebaseParagraphRuns.d.ts +36 -0
- package/dist/prosemirror/rebaseParagraphRuns.js +99 -0
- package/dist/prosemirror/runFormattingFromMarks.d.ts +18 -0
- package/dist/prosemirror/runFormattingFromMarks.js +567 -0
- package/dist/prosemirror/runFormattingReconciliation.js +10 -9
- package/dist/prosemirror/schema/nodes.d.ts +2 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +59 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +145 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +21 -2
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +38 -1
- package/dist/prosemirror/styles/tableStyleRegions.d.ts +31 -0
- package/dist/prosemirror/styles/tableStyleRegions.js +55 -0
- package/dist/prosemirror/tableCellPaste.d.ts +74 -0
- package/dist/prosemirror/tableCellPaste.js +525 -0
- package/dist/prosemirror/tableGridMutation.d.ts +53 -14
- package/dist/prosemirror/tableGridMutation.js +166 -18
- package/dist/prosemirror/tableRunIn.d.ts +51 -0
- package/dist/prosemirror/tableRunIn.js +165 -0
- package/dist/prosemirror/textInput.js +11 -2
- package/dist/prosemirror/trackedRevisionPath.d.ts +17 -0
- package/dist/prosemirror/trackedRevisionPath.js +32 -0
- package/dist/server.d.ts +2 -2
- package/package.json +6 -6
|
@@ -13,11 +13,10 @@ import { createStyleEngine } from "../../style-engine/styleEngine.js";
|
|
|
13
13
|
import { normalizeShapeTextAnchor, presetDashForOutlineAttr } from "../../types/documentEnumValues.js";
|
|
14
14
|
import { presetDashForCssBorderStyle } from "../../utils/borderCss.js";
|
|
15
15
|
import { canonicalJson } from "../../utils/canonicalJson.js";
|
|
16
|
-
import { normalizeHorizontalScalePercent } from "../../utils/horizontalScale.js";
|
|
17
16
|
import { mergeTextFormatting } from "../../utils/textFormattingMerge.js";
|
|
18
17
|
import { emuToPixels, emuToStrokePixels, pixelsToEmu } from "../../utils/units.js";
|
|
19
18
|
import { unchangedAlternateContentXml } from "../alternateContentAttrs.js";
|
|
20
|
-
import { expectBlockCustomXmlAttrs, expectBlockSdtAttrs,
|
|
19
|
+
import { expectBlockCustomXmlAttrs, expectBlockSdtAttrs, expectCharacterStyleMarkAttrs, expectCommentMarkAttrs, expectFieldAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectInlineWrapperMarkAttrs, expectMathAttrs, expectPageBreakRunAttrs, expectParagraphAttrs, expectPreservedBlockAttrs, expectPreservedXmlAttrs, expectRunIdentityMarkAttrs, expectRunPropertyChangeMarkAttrs, expectSdtAttrs, expectShapeAttrs, expectSymbolAttrs, expectTabAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTrackedChangeMarkAttrs } from "../attrs/index.js";
|
|
21
20
|
import { readAuthoredTransform } from "../authoredTransformAttrs.js";
|
|
22
21
|
import { autospacingMatchesBase, hasAutospacingBaseSide } from "../autospacingBase.js";
|
|
23
22
|
import { bookmarkMarkerFromAttrs, expectBookmarkBoundaryAttrs } from "../bookmarkBoundaryAttrs.js";
|
|
@@ -25,7 +24,6 @@ import { paragraphRejectAttrPatch, paragraphRejectOriginalFormatting, removePara
|
|
|
25
24
|
import { expectCommentReferenceAttrs } from "../commentReferenceAttrs.js";
|
|
26
25
|
import { enclosingRevisionIds } from "../contentControlRevisions.js";
|
|
27
26
|
import { INLINE_WRAPPER_MARK_NAME } from "../extensions/marks/InlineWrapperExtension.js";
|
|
28
|
-
import { applyRunFormattingOverrideAttrs, buildRunFormattingOverrideAttrs } from "../extensions/marks/RunFormattingOverrideExtension.js";
|
|
29
27
|
import { textFormattingToMarks } from "../extensions/marks/markUtils.js";
|
|
30
28
|
import "../extensions/nodes/MoveRangeBoundaryExtension.js";
|
|
31
29
|
import "../extensions/nodes/RangeAnchorExtension.js";
|
|
@@ -38,18 +36,17 @@ import { directParagraphAlignment } from "../paragraphAlignment.js";
|
|
|
38
36
|
import { directionToAuthoredBidi } from "../paragraphDirection.js";
|
|
39
37
|
import { directParagraphSpacing } from "../paragraphSpacing.js";
|
|
40
38
|
import { expectRangeAnchorAttrs } from "../rangeAnchorAttrs.js";
|
|
39
|
+
import { marksToTextFormatting, sameFormattingValue } from "../runFormattingFromMarks.js";
|
|
41
40
|
import { RUN_FORMATTING_MARK_NAMES } from "../runFormattingMarkNames.js";
|
|
42
|
-
import { authoredRunFormattingFromAttrs, hasAuthoredRunFormattingProvenance } from "../runFormattingProvenance.js";
|
|
43
41
|
import { RUN_IDENTITY_MARK_NAME } from "../runIdentity.js";
|
|
44
|
-
import { paragraphFormattingForRun, paragraphRunStyleContext, resolveEffectiveRunStyleFormatting
|
|
45
|
-
import { schema } from "../schema/index.js";
|
|
42
|
+
import { paragraphFormattingForRun, paragraphRunStyleContext, resolveEffectiveRunStyleFormatting } from "../runStyleFormatting.js";
|
|
46
43
|
import { PRESERVED_XML_LEVELS } from "../schema/nodes.js";
|
|
47
44
|
import { parseShapeGeometryAdjustments } from "../shapeGeometryAdjustments.js";
|
|
48
45
|
import { expectTextBoxAnchorAttrs } from "../textBoxAnchorAttrs.js";
|
|
49
46
|
import { textBoxHostParagraph } from "../textBoxHostParagraph.js";
|
|
47
|
+
import { enclosingInsertionAncestors, inlineWrapperStackOf } from "../trackedRevisionPath.js";
|
|
50
48
|
import { assertValidProseMirrorDocument } from "../validation.js";
|
|
51
49
|
import { hasSinkChildren } from "./preservedSinkCarriers.js";
|
|
52
|
-
import { runShadingAttrsToShading, shadingToRunShadingAttrs } from "./runShadingMark.js";
|
|
53
50
|
import { decodeSdtListItems, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs } from "./sdtAttrs.js";
|
|
54
51
|
import { panic } from "better-result";
|
|
55
52
|
import { DRAWING_RAW_XML_MODES, relationshipIdOf } from "@stll/docx-core/model";
|
|
@@ -336,7 +333,7 @@ function stripSuggestedInlineMarks(marks, { baseParagraphFormatting, inheritedFo
|
|
|
336
333
|
styleResolver
|
|
337
334
|
}) : paragraphFormatting, previousFormatting);
|
|
338
335
|
next = next.filter((mark) => !RUN_FORMATTING_MARK_NAMES.has(mark.type.name));
|
|
339
|
-
for (const restored of textFormattingToMarks(effectivePreviousFormatting, schema, {
|
|
336
|
+
for (const restored of textFormattingToMarks(effectivePreviousFormatting, suggestedRunPropertyChange.type.schema, {
|
|
340
337
|
overrideFormatting: previousFormatting,
|
|
341
338
|
directFormatting: previousFormatting
|
|
342
339
|
})) next = restored.addToSet(next);
|
|
@@ -1125,9 +1122,11 @@ function paragraphAttrsToFormatting(attrs) {
|
|
|
1125
1122
|
const outlineLevel = authored("outlineLevel", Reflect.get(attrs, "outlineLevel"));
|
|
1126
1123
|
const bidi = authored("bidi", directionToAuthoredBidi(attrs.direction));
|
|
1127
1124
|
const snapToGrid = authored("snapToGrid", attrs.snapToGrid);
|
|
1128
|
-
const
|
|
1125
|
+
const numbered = paragraphNumberingReferenceId$1(attrs.numPr ?? void 0) !== void 0;
|
|
1126
|
+
const statedIndent = (value) => value === 0 && !numbered ? void 0 : value;
|
|
1127
|
+
const indentLeft = statedIndent(authored("indentLeft", attrs.indentLeft));
|
|
1129
1128
|
const indentRight = authored("indentRight", attrs.indentRight);
|
|
1130
|
-
const indentFirstLine = authored("indentFirstLine", attrs.indentFirstLine);
|
|
1129
|
+
const indentFirstLine = statedIndent(authored("indentFirstLine", attrs.indentFirstLine));
|
|
1131
1130
|
const borders = authored("borders", attrs.borders);
|
|
1132
1131
|
const shading = authored("shading", attrs.shading);
|
|
1133
1132
|
const tabs = authored("tabs", attrs.tabs);
|
|
@@ -1140,7 +1139,7 @@ function paragraphAttrsToFormatting(attrs) {
|
|
|
1140
1139
|
const kinsoku = authored("kinsoku", attrs.kinsoku);
|
|
1141
1140
|
const overflowPunctuation = authored("overflowPunctuation", attrs.overflowPunctuation);
|
|
1142
1141
|
const suppressAutoHyphens = authored("suppressAutoHyphens", attrs.suppressAutoHyphens);
|
|
1143
|
-
if (!(directAlignment !== void 0 || shouldSerializeSpaceBefore || shouldSerializeSpaceAfter || beforeAutospacingEdited || afterAutospacingEdited || hasDirectLineSpacing || hasDirectLineSpacingRule || snapToGrid != null || indentLeft || indentRight || indentFirstLine || attrs.numPr || attrs.styleId || borders || shading || tabs || outlineLevel !== void 0 || contextualSpacing || attrs.spacingExplicit || bidi != null || pageBreakBefore != null || widowControl != null || keepNext != null || keepLines != null || runInWithNext != null || kinsoku != null || overflowPunctuation != null || suppressAutoHyphens != null)) return;
|
|
1142
|
+
if (!(directAlignment !== void 0 || shouldSerializeSpaceBefore || shouldSerializeSpaceAfter || beforeAutospacingEdited || afterAutospacingEdited || hasDirectLineSpacing || hasDirectLineSpacingRule || snapToGrid != null || indentLeft !== void 0 || indentRight || indentFirstLine !== void 0 || attrs.numPr || attrs.styleId || borders || shading || tabs || outlineLevel !== void 0 || contextualSpacing || attrs.spacingExplicit || bidi != null || pageBreakBefore != null || widowControl != null || keepNext != null || keepLines != null || runInWithNext != null || kinsoku != null || overflowPunctuation != null || suppressAutoHyphens != null)) return;
|
|
1144
1143
|
const f = {};
|
|
1145
1144
|
if (directAlignment !== void 0) f.alignment = directAlignment;
|
|
1146
1145
|
if (shouldSerializeSpaceBefore) f.spaceBefore = spaceBefore;
|
|
@@ -1151,9 +1150,9 @@ function paragraphAttrsToFormatting(attrs) {
|
|
|
1151
1150
|
if (hasDirectLineSpacingRule && attrs.lineSpacingRule) f.lineSpacingRule = attrs.lineSpacingRule;
|
|
1152
1151
|
if (snapToGrid != null) f.snapToGrid = snapToGrid;
|
|
1153
1152
|
if (attrs.spacingExplicit) f.spacingExplicit = attrs.spacingExplicit;
|
|
1154
|
-
if (indentLeft) f.indentLeft = indentLeft;
|
|
1153
|
+
if (indentLeft !== void 0) f.indentLeft = indentLeft;
|
|
1155
1154
|
if (indentRight) f.indentRight = indentRight;
|
|
1156
|
-
if (indentFirstLine) f.indentFirstLine = indentFirstLine;
|
|
1155
|
+
if (indentFirstLine !== void 0) f.indentFirstLine = indentFirstLine;
|
|
1157
1156
|
if (attrs.hangingIndent && indentFirstLine) f.hangingIndent = attrs.hangingIndent;
|
|
1158
1157
|
if (attrs.numPr !== void 0 && !isStyleSourcedParagraphNumbering(attrs.numPr, attrs.numPrFromStyle)) f.numPr = attrs.numPr;
|
|
1159
1158
|
if (attrs.styleId) f.styleId = attrs.styleId;
|
|
@@ -1205,11 +1204,6 @@ function createTrackedRunWrapper(type, info, child) {
|
|
|
1205
1204
|
* document each time the same one is saved.
|
|
1206
1205
|
*/
|
|
1207
1206
|
const byCommentId = (ids) => [...ids].toSorted((a, b) => a - b);
|
|
1208
|
-
/** The wrappers `node` sits inside, outermost first; empty when it sits in none. */
|
|
1209
|
-
const inlineWrapperStackOf = (node) => {
|
|
1210
|
-
const mark = node.marks.find((candidate) => candidate.type.name === INLINE_WRAPPER_MARK_NAME);
|
|
1211
|
-
return mark ? expectInlineWrapperMarkAttrs(mark).stack : [];
|
|
1212
|
-
};
|
|
1213
1207
|
/** The authored hyperlink that owns a suffix of the node's wrapper stack. */
|
|
1214
1208
|
const inlineWrapperHyperlinkOriginOf = (node) => {
|
|
1215
1209
|
const mark = node.marks.find((candidate) => candidate.type.name === INLINE_WRAPPER_MARK_NAME);
|
|
@@ -1279,21 +1273,6 @@ const nestRevisionAwareInlineWrappers = (items, stack, revisionOuterWrapperCount
|
|
|
1279
1273
|
return nested;
|
|
1280
1274
|
};
|
|
1281
1275
|
const sameRevisionLayer = (left, right) => left.type === right.type && left.revisionId === right.revisionId && left.author === right.author && left.date === right.date && left.utcDate === right.utcDate && left.initials === right.initials && left.outerWrapperCount === right.outerWrapperCount;
|
|
1282
|
-
/** The deletion's ancestor path, with the insertion it sits in as the outermost layer. */
|
|
1283
|
-
const enclosingInsertionAncestors = ({ insertionMark, ancestors, node }) => {
|
|
1284
|
-
if (!insertionMark) return ancestors;
|
|
1285
|
-
const attrs = expectTrackedChangeMarkAttrs(insertionMark);
|
|
1286
|
-
if (ancestors.some(({ revisionId }) => revisionId === attrs.revisionId)) return ancestors;
|
|
1287
|
-
return [{
|
|
1288
|
-
type: attrs.moveKind === "moveTo" ? "moveTo" : "insertion",
|
|
1289
|
-
revisionId: attrs.revisionId,
|
|
1290
|
-
author: attrs.author || "Unknown",
|
|
1291
|
-
...attrs.date ? { date: attrs.date } : {},
|
|
1292
|
-
...attrs.utcDate ? { utcDate: attrs.utcDate } : {},
|
|
1293
|
-
...attrs.initials ? { initials: attrs.initials } : {},
|
|
1294
|
-
outerWrapperCount: attrs._docxOuterWrapperCount ?? inlineWrapperStackOf(node).length
|
|
1295
|
-
}, ...ancestors];
|
|
1296
|
-
};
|
|
1297
1276
|
const revisionInfoFromLayer = (layer) => ({
|
|
1298
1277
|
id: layer.revisionId,
|
|
1299
1278
|
author: layer.author,
|
|
@@ -2711,563 +2690,6 @@ function createShapeRun(node) {
|
|
|
2711
2690
|
restoreRunRecord(run, node.marks);
|
|
2712
2691
|
return run;
|
|
2713
2692
|
}
|
|
2714
|
-
const RUN_FORMATTING_VISUAL_GROUPS = {
|
|
2715
|
-
bold: "bold",
|
|
2716
|
-
boldCs: null,
|
|
2717
|
-
italic: "italic",
|
|
2718
|
-
italicCs: null,
|
|
2719
|
-
underline: "underline",
|
|
2720
|
-
strike: "strike",
|
|
2721
|
-
doubleStrike: "strike",
|
|
2722
|
-
vertAlign: "vertAlign",
|
|
2723
|
-
smallCaps: "smallCaps",
|
|
2724
|
-
allCaps: "allCaps",
|
|
2725
|
-
hidden: "hidden",
|
|
2726
|
-
noProof: null,
|
|
2727
|
-
color: "color",
|
|
2728
|
-
highlight: "highlight",
|
|
2729
|
-
shading: "shading",
|
|
2730
|
-
fontSize: "fontSize",
|
|
2731
|
-
fontSizeCs: null,
|
|
2732
|
-
fontFamily: "fontFamily",
|
|
2733
|
-
language: "language",
|
|
2734
|
-
spacing: "characterSpacing",
|
|
2735
|
-
position: "characterSpacing",
|
|
2736
|
-
scale: "characterSpacing",
|
|
2737
|
-
kerning: "characterSpacing",
|
|
2738
|
-
effect: "effect",
|
|
2739
|
-
emphasisMark: "emphasisMark",
|
|
2740
|
-
emboss: "emboss",
|
|
2741
|
-
imprint: "imprint",
|
|
2742
|
-
outline: "outline",
|
|
2743
|
-
shadow: "shadow",
|
|
2744
|
-
rtl: "rtl",
|
|
2745
|
-
cs: null,
|
|
2746
|
-
styleId: null,
|
|
2747
|
-
preserved: null
|
|
2748
|
-
};
|
|
2749
|
-
const RUN_FORMATTING_FAST_PATH_DISPOSITION = {
|
|
2750
|
-
bold: "visual",
|
|
2751
|
-
boldCs: "structural",
|
|
2752
|
-
italic: "visual",
|
|
2753
|
-
italicCs: "structural",
|
|
2754
|
-
underline: "visual",
|
|
2755
|
-
strike: "visual",
|
|
2756
|
-
doubleStrike: "visual",
|
|
2757
|
-
vertAlign: "visual",
|
|
2758
|
-
smallCaps: "visual",
|
|
2759
|
-
allCaps: "visual",
|
|
2760
|
-
hidden: "visual",
|
|
2761
|
-
noProof: "structural",
|
|
2762
|
-
color: "visual",
|
|
2763
|
-
highlight: "visual",
|
|
2764
|
-
shading: "visual",
|
|
2765
|
-
fontSize: "visual",
|
|
2766
|
-
fontSizeCs: "structural",
|
|
2767
|
-
fontFamily: "visual",
|
|
2768
|
-
language: "visual",
|
|
2769
|
-
spacing: "visual",
|
|
2770
|
-
position: "visual",
|
|
2771
|
-
scale: "visual",
|
|
2772
|
-
kerning: "visual",
|
|
2773
|
-
effect: "visual",
|
|
2774
|
-
emphasisMark: "visual",
|
|
2775
|
-
emboss: "visual",
|
|
2776
|
-
imprint: "visual",
|
|
2777
|
-
outline: "visual",
|
|
2778
|
-
shadow: "visual",
|
|
2779
|
-
rtl: "visual",
|
|
2780
|
-
cs: "structural",
|
|
2781
|
-
styleId: "character-style",
|
|
2782
|
-
preserved: "structural"
|
|
2783
|
-
};
|
|
2784
|
-
const hasOnlyCarrierlessVisualFormatting = (formatting) => {
|
|
2785
|
-
for (const property of Object.keys(formatting)) if (RUN_FORMATTING_FAST_PATH_DISPOSITION[property] !== "visual") return false;
|
|
2786
|
-
return true;
|
|
2787
|
-
};
|
|
2788
|
-
const visibleUnderline = (formatting) => {
|
|
2789
|
-
const underline = formatting?.underline;
|
|
2790
|
-
return underline?.style === "none" ? void 0 : underline;
|
|
2791
|
-
};
|
|
2792
|
-
const visibleStrike = (formatting) => {
|
|
2793
|
-
if (formatting?.doubleStrike === true) return "double";
|
|
2794
|
-
return formatting?.strike === true ? "single" : void 0;
|
|
2795
|
-
};
|
|
2796
|
-
const visibleColor = (formatting) => formatting?.color?.auto === true ? void 0 : formatting?.color;
|
|
2797
|
-
const visibleValue = (value) => value === "none" ? void 0 : value;
|
|
2798
|
-
/**
|
|
2799
|
-
* Compare the exact presentation encoded by PM run marks without allocating the
|
|
2800
|
-
* intermediate maps used by reconciliation. Non-visual authored state is
|
|
2801
|
-
* deliberately absent here: the carrierless fast path below excludes every
|
|
2802
|
-
* structural carrier before calling this predicate.
|
|
2803
|
-
*/
|
|
2804
|
-
const sameVisualFormatting = (left, right) => {
|
|
2805
|
-
if (left?.bold === true !== (right?.bold === true) || left?.italic === true !== (right?.italic === true) || !sameFormattingValue(visibleUnderline(left), visibleUnderline(right)) || visibleStrike(left) !== visibleStrike(right) || !sameFormattingValue(visibleColor(left), visibleColor(right)) || visibleValue(left?.highlight) !== visibleValue(right?.highlight) || (left?.fontSize || void 0) !== (right?.fontSize || void 0) || !sameFormattingValue(left?.fontFamily, right?.fontFamily) || !sameFormattingValue(left?.language, right?.language) || (left?.vertAlign === "superscript" || left?.vertAlign === "subscript" ? left.vertAlign : void 0) !== (right?.vertAlign === "superscript" || right?.vertAlign === "subscript" ? right.vertAlign : void 0) || left?.allCaps === true !== (right?.allCaps === true) || left?.smallCaps === true !== (right?.smallCaps === true) || left?.hidden === true !== (right?.hidden === true) || left?.emboss === true !== (right?.emboss === true) || left?.imprint === true !== (right?.imprint === true) || left?.shadow === true !== (right?.shadow === true) || left?.outline === true !== (right?.outline === true) || left?.rtl === true !== (right?.rtl === true) || (typeof left?.spacing === "number" ? left.spacing : null) !== (typeof right?.spacing === "number" ? right.spacing : null) || (typeof left?.position === "number" ? left.position : null) !== (typeof right?.position === "number" ? right.position : null) || (normalizeHorizontalScalePercent(left?.scale) ?? null) !== (normalizeHorizontalScalePercent(right?.scale) ?? null) || (typeof left?.kerning === "number" ? left.kerning : null) !== (typeof right?.kerning === "number" ? right.kerning : null) || visibleValue(left?.effect) !== visibleValue(right?.effect) || visibleValue(left?.emphasisMark) !== visibleValue(right?.emphasisMark)) return false;
|
|
2806
|
-
return sameFormattingValue(shadingToRunShadingAttrs(left?.shading), shadingToRunShadingAttrs(right?.shading));
|
|
2807
|
-
};
|
|
2808
|
-
const visualFormattingGroups = (formatting) => {
|
|
2809
|
-
const groups = /* @__PURE__ */ new Map();
|
|
2810
|
-
if (!formatting) return groups;
|
|
2811
|
-
if (formatting.bold) groups.set("bold", true);
|
|
2812
|
-
if (formatting.italic) groups.set("italic", true);
|
|
2813
|
-
if (formatting.underline && formatting.underline.style !== "none") groups.set("underline", {
|
|
2814
|
-
style: formatting.underline.style || "single",
|
|
2815
|
-
...formatting.underline.color ? { color: formatting.underline.color } : {}
|
|
2816
|
-
});
|
|
2817
|
-
if (formatting.strike || formatting.doubleStrike) groups.set("strike", formatting.doubleStrike ? "double" : "single");
|
|
2818
|
-
if (formatting.color && !formatting.color.auto) {
|
|
2819
|
-
const { rgb, themeColor, themeTint, themeShade } = formatting.color;
|
|
2820
|
-
groups.set("color", {
|
|
2821
|
-
...rgb ? { rgb } : {},
|
|
2822
|
-
...themeColor ? { themeColor } : {},
|
|
2823
|
-
...themeTint ? { themeTint } : {},
|
|
2824
|
-
...themeShade ? { themeShade } : {}
|
|
2825
|
-
});
|
|
2826
|
-
}
|
|
2827
|
-
if (formatting.highlight && formatting.highlight !== "none") groups.set("highlight", formatting.highlight);
|
|
2828
|
-
const shadingAttrs = shadingToRunShadingAttrs(formatting.shading);
|
|
2829
|
-
if (shadingAttrs) groups.set("shading", runShadingAttrsToShading(shadingAttrs));
|
|
2830
|
-
if (formatting.fontSize) groups.set("fontSize", formatting.fontSize);
|
|
2831
|
-
if (formatting.fontFamily) {
|
|
2832
|
-
const { ascii, hAnsi, eastAsia, cs, hint, asciiTheme, hAnsiTheme, eastAsiaTheme, csTheme } = formatting.fontFamily;
|
|
2833
|
-
groups.set("fontFamily", {
|
|
2834
|
-
...ascii ? { ascii } : {},
|
|
2835
|
-
...hAnsi ? { hAnsi } : {},
|
|
2836
|
-
...eastAsia ? { eastAsia } : {},
|
|
2837
|
-
...cs ? { cs } : {},
|
|
2838
|
-
...hint ? { hint } : {},
|
|
2839
|
-
...asciiTheme ? { asciiTheme } : {},
|
|
2840
|
-
...hAnsiTheme ? { hAnsiTheme } : {},
|
|
2841
|
-
...eastAsiaTheme ? { eastAsiaTheme } : {},
|
|
2842
|
-
...csTheme ? { csTheme } : {}
|
|
2843
|
-
});
|
|
2844
|
-
}
|
|
2845
|
-
if (formatting.language) {
|
|
2846
|
-
const { val, eastAsia, bidi } = formatting.language;
|
|
2847
|
-
groups.set("language", {
|
|
2848
|
-
...val ? { val } : {},
|
|
2849
|
-
...eastAsia ? { eastAsia } : {},
|
|
2850
|
-
...bidi ? { bidi } : {}
|
|
2851
|
-
});
|
|
2852
|
-
}
|
|
2853
|
-
if (formatting.vertAlign === "superscript" || formatting.vertAlign === "subscript") groups.set("vertAlign", formatting.vertAlign);
|
|
2854
|
-
for (const [property, group] of [
|
|
2855
|
-
["allCaps", "allCaps"],
|
|
2856
|
-
["smallCaps", "smallCaps"],
|
|
2857
|
-
["hidden", "hidden"],
|
|
2858
|
-
["emboss", "emboss"],
|
|
2859
|
-
["imprint", "imprint"],
|
|
2860
|
-
["shadow", "shadow"],
|
|
2861
|
-
["outline", "outline"],
|
|
2862
|
-
["rtl", "rtl"]
|
|
2863
|
-
]) if (formatting[property]) groups.set(group, true);
|
|
2864
|
-
const spacing = typeof formatting.spacing === "number" ? formatting.spacing : null;
|
|
2865
|
-
const position = typeof formatting.position === "number" ? formatting.position : null;
|
|
2866
|
-
const scale = normalizeHorizontalScalePercent(formatting.scale) ?? null;
|
|
2867
|
-
const kerning = typeof formatting.kerning === "number" ? formatting.kerning : null;
|
|
2868
|
-
if (spacing !== null || position !== null || scale !== null || kerning !== null) groups.set("characterSpacing", {
|
|
2869
|
-
spacing,
|
|
2870
|
-
position,
|
|
2871
|
-
scale,
|
|
2872
|
-
kerning
|
|
2873
|
-
});
|
|
2874
|
-
if (formatting.effect && formatting.effect !== "none") groups.set("effect", formatting.effect);
|
|
2875
|
-
if (formatting.emphasisMark && formatting.emphasisMark !== "none") groups.set("emphasisMark", formatting.emphasisMark);
|
|
2876
|
-
return groups;
|
|
2877
|
-
};
|
|
2878
|
-
const expectedRunFormattingOverrideAttrs = (authoredFormatting) => {
|
|
2879
|
-
const attrs = buildRunFormattingOverrideAttrs(authoredFormatting, {
|
|
2880
|
-
type: "authored-baseline",
|
|
2881
|
-
formatting: authoredFormatting
|
|
2882
|
-
});
|
|
2883
|
-
const hasDirectFormatting = Object.keys(authoredFormatting).some((property) => property !== "styleId");
|
|
2884
|
-
if (!attrs && !hasDirectFormatting) return;
|
|
2885
|
-
const expected = { ...attrs };
|
|
2886
|
-
const directFontProperties = [
|
|
2887
|
-
"color",
|
|
2888
|
-
"fontFamily",
|
|
2889
|
-
"fontSize"
|
|
2890
|
-
].filter((property) => authoredFormatting[property] !== void 0);
|
|
2891
|
-
if (directFontProperties.length > 0) expected.directFontProperties = directFontProperties;
|
|
2892
|
-
const complexScriptPropertyAbsences = [
|
|
2893
|
-
["bold", "boldCs"],
|
|
2894
|
-
["italic", "italicCs"],
|
|
2895
|
-
["fontSize", "fontSizeCs"]
|
|
2896
|
-
].filter(([ordinary, complex]) => authoredFormatting[ordinary] !== void 0 && authoredFormatting[complex] === void 0).map(([, complex]) => complex);
|
|
2897
|
-
if (complexScriptPropertyAbsences.length > 0) expected.complexScriptPropertyAbsences = complexScriptPropertyAbsences;
|
|
2898
|
-
return Object.keys(expected).length > 0 ? expected : void 0;
|
|
2899
|
-
};
|
|
2900
|
-
const changedVisualFormattingGroups = (observedFormatting, expectedFormatting) => {
|
|
2901
|
-
const actual = visualFormattingGroups(observedFormatting);
|
|
2902
|
-
const expected = visualFormattingGroups(expectedFormatting);
|
|
2903
|
-
const changed = /* @__PURE__ */ new Set();
|
|
2904
|
-
for (const group of /* @__PURE__ */ new Set([...actual.keys(), ...expected.keys()])) {
|
|
2905
|
-
const actualValue = actual.get(group);
|
|
2906
|
-
const expectedValue = expected.get(group);
|
|
2907
|
-
if (!sameFormattingValue(actualValue, expectedValue)) changed.add(group);
|
|
2908
|
-
}
|
|
2909
|
-
return changed;
|
|
2910
|
-
};
|
|
2911
|
-
const VISUAL_BOOLEAN_FORMATTING_PROPERTIES = /* @__PURE__ */ new Set([
|
|
2912
|
-
"allCaps",
|
|
2913
|
-
"bold",
|
|
2914
|
-
"doubleStrike",
|
|
2915
|
-
"emboss",
|
|
2916
|
-
"hidden",
|
|
2917
|
-
"imprint",
|
|
2918
|
-
"italic",
|
|
2919
|
-
"outline",
|
|
2920
|
-
"rtl",
|
|
2921
|
-
"shadow",
|
|
2922
|
-
"smallCaps",
|
|
2923
|
-
"strike"
|
|
2924
|
-
]);
|
|
2925
|
-
const fontFamilyDifference = (actual, inherited) => {
|
|
2926
|
-
const difference = {};
|
|
2927
|
-
for (const property of [
|
|
2928
|
-
"ascii",
|
|
2929
|
-
"hAnsi",
|
|
2930
|
-
"eastAsia",
|
|
2931
|
-
"cs",
|
|
2932
|
-
"hint",
|
|
2933
|
-
"asciiTheme",
|
|
2934
|
-
"hAnsiTheme",
|
|
2935
|
-
"eastAsiaTheme",
|
|
2936
|
-
"csTheme"
|
|
2937
|
-
]) {
|
|
2938
|
-
const value = actual[property];
|
|
2939
|
-
if (value !== void 0 && value !== inherited?.[property]) Reflect.set(difference, property, value);
|
|
2940
|
-
}
|
|
2941
|
-
return Object.keys(difference).length > 0 ? difference : void 0;
|
|
2942
|
-
};
|
|
2943
|
-
const DIRECT_OVERRIDE_FORMATTING_PROPERTIES = [
|
|
2944
|
-
"allCaps",
|
|
2945
|
-
"bold",
|
|
2946
|
-
"boldCs",
|
|
2947
|
-
"cs",
|
|
2948
|
-
"doubleStrike",
|
|
2949
|
-
"emboss",
|
|
2950
|
-
"fontSizeCs",
|
|
2951
|
-
"hidden",
|
|
2952
|
-
"noProof",
|
|
2953
|
-
"imprint",
|
|
2954
|
-
"italic",
|
|
2955
|
-
"italicCs",
|
|
2956
|
-
"outline",
|
|
2957
|
-
"rtl",
|
|
2958
|
-
"shadow",
|
|
2959
|
-
"smallCaps",
|
|
2960
|
-
"strike",
|
|
2961
|
-
"underline"
|
|
2962
|
-
];
|
|
2963
|
-
const POSITIVE_OVERRIDE_PROPERTIES_REPRESENTED_BY_VISUAL_MARKS = /* @__PURE__ */ new Set([
|
|
2964
|
-
"allCaps",
|
|
2965
|
-
"emboss",
|
|
2966
|
-
"hidden",
|
|
2967
|
-
"imprint",
|
|
2968
|
-
"outline",
|
|
2969
|
-
"rtl",
|
|
2970
|
-
"shadow",
|
|
2971
|
-
"smallCaps",
|
|
2972
|
-
"strike"
|
|
2973
|
-
]);
|
|
2974
|
-
const setFormattingFromOverrideSignal = (formatting, property, value) => {
|
|
2975
|
-
Reflect.deleteProperty(formatting, property);
|
|
2976
|
-
if (value === void 0) return;
|
|
2977
|
-
if (property === "underline") {
|
|
2978
|
-
formatting.underline = { style: "none" };
|
|
2979
|
-
return;
|
|
2980
|
-
}
|
|
2981
|
-
Reflect.set(formatting, property, value);
|
|
2982
|
-
};
|
|
2983
|
-
const sameFormattingValue = (left, right) => {
|
|
2984
|
-
if (left === right) return true;
|
|
2985
|
-
if (typeof left !== "object" || left === null || typeof right !== "object" || right === null) return false;
|
|
2986
|
-
if (Array.isArray(left) || Array.isArray(right)) {
|
|
2987
|
-
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
2988
|
-
return left.every((value, index) => sameFormattingValue(value, right[index]));
|
|
2989
|
-
}
|
|
2990
|
-
const leftKeys = Object.keys(left);
|
|
2991
|
-
const rightKeys = Object.keys(right);
|
|
2992
|
-
if (leftKeys.length !== rightKeys.length) return false;
|
|
2993
|
-
return leftKeys.every((key) => Object.prototype.hasOwnProperty.call(right, key) && sameFormattingValue(Reflect.get(left, key), Reflect.get(right, key)));
|
|
2994
|
-
};
|
|
2995
|
-
const reconcileOverrideSignals = (formatting, current, expected, inheritedFormatting, observedFormatting) => {
|
|
2996
|
-
for (const property of DIRECT_OVERRIDE_FORMATTING_PROPERTIES) {
|
|
2997
|
-
if (sameFormattingValue(current?.[property], expected?.[property])) continue;
|
|
2998
|
-
if (current?.[property] === void 0 && expected?.[property] === true && POSITIVE_OVERRIDE_PROPERTIES_REPRESENTED_BY_VISUAL_MARKS.has(property)) continue;
|
|
2999
|
-
if (current && hasAuthoredRunFormattingProvenance(current) && expected?.[property] === void 0 && sameFormattingValue(current[property], inheritedFormatting?.[property])) continue;
|
|
3000
|
-
setFormattingFromOverrideSignal(formatting, property, current?.[property]);
|
|
3001
|
-
}
|
|
3002
|
-
for (const property of [
|
|
3003
|
-
"color",
|
|
3004
|
-
"fontFamily",
|
|
3005
|
-
"fontSize"
|
|
3006
|
-
]) {
|
|
3007
|
-
const currentIsDirect = current?.directFontProperties?.includes(property) === true;
|
|
3008
|
-
if (currentIsDirect === (expected?.directFontProperties?.includes(property) === true)) continue;
|
|
3009
|
-
if (!currentIsDirect) {
|
|
3010
|
-
Reflect.deleteProperty(formatting, property);
|
|
3011
|
-
continue;
|
|
3012
|
-
}
|
|
3013
|
-
const observed = observedFormatting[property];
|
|
3014
|
-
if (observed !== void 0) Reflect.set(formatting, property, observed);
|
|
3015
|
-
}
|
|
3016
|
-
for (const property of [
|
|
3017
|
-
"boldCs",
|
|
3018
|
-
"italicCs",
|
|
3019
|
-
"fontSizeCs"
|
|
3020
|
-
]) {
|
|
3021
|
-
const currentIsAbsent = current?.complexScriptPropertyAbsences?.includes(property) === true;
|
|
3022
|
-
if (currentIsAbsent !== (expected?.complexScriptPropertyAbsences?.includes(property) === true) && currentIsAbsent) Reflect.deleteProperty(formatting, property);
|
|
3023
|
-
}
|
|
3024
|
-
};
|
|
3025
|
-
/**
|
|
3026
|
-
* Reconcile source-authored provenance with the current visual mark set at the
|
|
3027
|
-
* one save boundary shared by editor commands, raw transactions and compare.
|
|
3028
|
-
* Unchanged groups keep exact source state (including equal direct values and
|
|
3029
|
-
* otherwise invisible sentinels); changed groups derive the smallest direct
|
|
3030
|
-
* override needed relative to the current style cascade.
|
|
3031
|
-
*/
|
|
3032
|
-
const reconcileAuthoredFormatting = ({ authoredFormatting, carrierlessContext, currentOverrideAttrs, inheritedFormatting, observedFormatting }) => {
|
|
3033
|
-
const hasAuthoredFormatting = Object.keys(authoredFormatting).length > 0;
|
|
3034
|
-
if (carrierlessContext === "ordinary" && currentOverrideAttrs === void 0 && !hasAuthoredFormatting && hasOnlyCarrierlessVisualFormatting(observedFormatting)) {
|
|
3035
|
-
if (sameVisualFormatting(observedFormatting, inheritedFormatting)) return authoredFormatting;
|
|
3036
|
-
if (observedFormatting.fontFamily === void 0 && sameVisualFormatting(inheritedFormatting, void 0)) return observedFormatting;
|
|
3037
|
-
}
|
|
3038
|
-
const expectedFormatting = hasAuthoredFormatting ? mergeTextFormatting(inheritedFormatting, authoredFormatting) : inheritedFormatting;
|
|
3039
|
-
const changedGroups = changedVisualFormattingGroups(observedFormatting, expectedFormatting);
|
|
3040
|
-
const reconciled = { ...authoredFormatting };
|
|
3041
|
-
for (const property of Object.keys(RUN_FORMATTING_VISUAL_GROUPS)) {
|
|
3042
|
-
const group = RUN_FORMATTING_VISUAL_GROUPS[property];
|
|
3043
|
-
if (group === null || !changedGroups.has(group)) continue;
|
|
3044
|
-
Reflect.deleteProperty(reconciled, property);
|
|
3045
|
-
if (VISUAL_BOOLEAN_FORMATTING_PROPERTIES.has(property)) {
|
|
3046
|
-
const observed = observedFormatting[property] === true;
|
|
3047
|
-
if (observed !== (inheritedFormatting?.[property] === true)) Reflect.set(reconciled, property, observed);
|
|
3048
|
-
continue;
|
|
3049
|
-
}
|
|
3050
|
-
const observed = observedFormatting[property];
|
|
3051
|
-
if (observed === void 0) continue;
|
|
3052
|
-
if (property === "fontFamily") {
|
|
3053
|
-
const difference = fontFamilyDifference(observed, inheritedFormatting?.fontFamily);
|
|
3054
|
-
if (difference) reconciled.fontFamily = difference;
|
|
3055
|
-
continue;
|
|
3056
|
-
}
|
|
3057
|
-
if (!sameFormattingValue(observed, inheritedFormatting?.[property])) Reflect.set(reconciled, property, observed);
|
|
3058
|
-
}
|
|
3059
|
-
if (currentOverrideAttrs !== void 0) reconcileOverrideSignals(reconciled, currentOverrideAttrs, expectedRunFormattingOverrideAttrs(authoredFormatting), inheritedFormatting, observedFormatting);
|
|
3060
|
-
return reconciled;
|
|
3061
|
-
};
|
|
3062
|
-
const formattingAuthorshipCost = (formatting) => {
|
|
3063
|
-
let cost = 0;
|
|
3064
|
-
const visit = (value) => {
|
|
3065
|
-
if (value === void 0) return;
|
|
3066
|
-
if (value === null || typeof value !== "object") {
|
|
3067
|
-
cost++;
|
|
3068
|
-
return;
|
|
3069
|
-
}
|
|
3070
|
-
const entries = Object.entries(value);
|
|
3071
|
-
if (entries.length === 0) {
|
|
3072
|
-
cost++;
|
|
3073
|
-
return;
|
|
3074
|
-
}
|
|
3075
|
-
for (const [, nested] of entries) visit(nested);
|
|
3076
|
-
};
|
|
3077
|
-
for (const [property, value] of Object.entries(formatting)) if (property !== "styleId") visit(value);
|
|
3078
|
-
return cost;
|
|
3079
|
-
};
|
|
3080
|
-
function marksToTextFormatting(marks, options) {
|
|
3081
|
-
const formatting = {};
|
|
3082
|
-
let directOverrideFormatting;
|
|
3083
|
-
let directFontProperties;
|
|
3084
|
-
let characterStyleId;
|
|
3085
|
-
let runFormattingOverrideMark;
|
|
3086
|
-
let currentOverrideAttrs;
|
|
3087
|
-
for (const mark of marks) switch (mark.type.name) {
|
|
3088
|
-
case "bold":
|
|
3089
|
-
formatting.bold = true;
|
|
3090
|
-
break;
|
|
3091
|
-
case "italic":
|
|
3092
|
-
formatting.italic = true;
|
|
3093
|
-
break;
|
|
3094
|
-
case "underline": {
|
|
3095
|
-
const attrs = expectUnderlineMarkAttrs(mark);
|
|
3096
|
-
const uline = { style: attrs.style || "single" };
|
|
3097
|
-
if (attrs.color) uline.color = attrs.color;
|
|
3098
|
-
formatting.underline = uline;
|
|
3099
|
-
break;
|
|
3100
|
-
}
|
|
3101
|
-
case "strike":
|
|
3102
|
-
if (expectStrikeMarkAttrs(mark).double) formatting.doubleStrike = true;
|
|
3103
|
-
else formatting.strike = true;
|
|
3104
|
-
break;
|
|
3105
|
-
case "textColor": {
|
|
3106
|
-
const attrs = expectTextColorMarkAttrs(mark);
|
|
3107
|
-
const colorVal = {};
|
|
3108
|
-
if (attrs.rgb) colorVal.rgb = attrs.rgb;
|
|
3109
|
-
if (attrs.themeColor) colorVal.themeColor = attrs.themeColor;
|
|
3110
|
-
if (attrs.themeTint) colorVal.themeTint = attrs.themeTint;
|
|
3111
|
-
if (attrs.themeShade) colorVal.themeShade = attrs.themeShade;
|
|
3112
|
-
formatting.color = colorVal;
|
|
3113
|
-
break;
|
|
3114
|
-
}
|
|
3115
|
-
case "highlight":
|
|
3116
|
-
formatting.highlight = expectHighlightMarkAttrs(mark).color;
|
|
3117
|
-
break;
|
|
3118
|
-
case "runShading":
|
|
3119
|
-
formatting.shading = runShadingAttrsToShading(expectRunShadingMarkAttrs(mark));
|
|
3120
|
-
break;
|
|
3121
|
-
case "fontSize":
|
|
3122
|
-
formatting.fontSize = expectFontSizeMarkAttrs(mark).size;
|
|
3123
|
-
break;
|
|
3124
|
-
case "fontFamily": {
|
|
3125
|
-
const attrs = expectFontFamilyMarkAttrs(mark);
|
|
3126
|
-
const ff = {};
|
|
3127
|
-
if (attrs.ascii) ff.ascii = attrs.ascii;
|
|
3128
|
-
if (attrs.hAnsi) ff.hAnsi = attrs.hAnsi;
|
|
3129
|
-
if (attrs.eastAsia) ff.eastAsia = attrs.eastAsia;
|
|
3130
|
-
if (attrs.hint) ff.hint = attrs.hint;
|
|
3131
|
-
if (attrs.cs) ff.cs = attrs.cs;
|
|
3132
|
-
if (attrs.asciiTheme) ff.asciiTheme = attrs.asciiTheme;
|
|
3133
|
-
if (attrs.hAnsiTheme) ff.hAnsiTheme = attrs.hAnsiTheme;
|
|
3134
|
-
if (attrs.eastAsiaTheme) ff.eastAsiaTheme = attrs.eastAsiaTheme;
|
|
3135
|
-
if (attrs.csTheme) ff.csTheme = attrs.csTheme;
|
|
3136
|
-
formatting.fontFamily = ff;
|
|
3137
|
-
break;
|
|
3138
|
-
}
|
|
3139
|
-
case "language": {
|
|
3140
|
-
const attrs = expectLanguageMarkAttrs(mark);
|
|
3141
|
-
formatting.language = {
|
|
3142
|
-
...attrs.val ? { val: attrs.val } : {},
|
|
3143
|
-
...attrs.eastAsia ? { eastAsia: attrs.eastAsia } : {},
|
|
3144
|
-
...attrs.bidi ? { bidi: attrs.bidi } : {}
|
|
3145
|
-
};
|
|
3146
|
-
break;
|
|
3147
|
-
}
|
|
3148
|
-
case "superscript":
|
|
3149
|
-
formatting.vertAlign = "superscript";
|
|
3150
|
-
break;
|
|
3151
|
-
case "subscript":
|
|
3152
|
-
formatting.vertAlign = "subscript";
|
|
3153
|
-
break;
|
|
3154
|
-
case "allCaps":
|
|
3155
|
-
formatting.allCaps = true;
|
|
3156
|
-
break;
|
|
3157
|
-
case "smallCaps":
|
|
3158
|
-
formatting.smallCaps = true;
|
|
3159
|
-
break;
|
|
3160
|
-
case "characterSpacing": {
|
|
3161
|
-
const attrs = expectCharacterSpacingMarkAttrs(mark);
|
|
3162
|
-
if (attrs.spacing !== void 0) formatting.spacing = attrs.spacing;
|
|
3163
|
-
if (attrs.position !== void 0) formatting.position = attrs.position;
|
|
3164
|
-
const horizontalScale = normalizeHorizontalScalePercent(attrs.scale);
|
|
3165
|
-
if (horizontalScale !== void 0) formatting.scale = horizontalScale;
|
|
3166
|
-
if (attrs.kerning !== void 0) formatting.kerning = attrs.kerning;
|
|
3167
|
-
break;
|
|
3168
|
-
}
|
|
3169
|
-
case "emboss":
|
|
3170
|
-
formatting.emboss = true;
|
|
3171
|
-
break;
|
|
3172
|
-
case "imprint":
|
|
3173
|
-
formatting.imprint = true;
|
|
3174
|
-
break;
|
|
3175
|
-
case "hidden":
|
|
3176
|
-
formatting.hidden = true;
|
|
3177
|
-
break;
|
|
3178
|
-
case "textShadow":
|
|
3179
|
-
formatting.shadow = true;
|
|
3180
|
-
break;
|
|
3181
|
-
case "emphasisMark":
|
|
3182
|
-
formatting.emphasisMark = expectEmphasisMarkAttrs(mark).type || "dot";
|
|
3183
|
-
break;
|
|
3184
|
-
case "textOutline":
|
|
3185
|
-
formatting.outline = true;
|
|
3186
|
-
break;
|
|
3187
|
-
case "rtl":
|
|
3188
|
-
formatting.rtl = true;
|
|
3189
|
-
break;
|
|
3190
|
-
case "textEffect":
|
|
3191
|
-
formatting.effect = expectTextEffectMarkAttrs(mark).effect;
|
|
3192
|
-
break;
|
|
3193
|
-
case "runFormattingOverride":
|
|
3194
|
-
runFormattingOverrideMark = mark;
|
|
3195
|
-
break;
|
|
3196
|
-
case "characterStyle": {
|
|
3197
|
-
const attrs = expectCharacterStyleMarkAttrs(mark);
|
|
3198
|
-
formatting.styleId = attrs.styleId;
|
|
3199
|
-
characterStyleId = attrs.styleId;
|
|
3200
|
-
break;
|
|
3201
|
-
}
|
|
3202
|
-
default: break;
|
|
3203
|
-
}
|
|
3204
|
-
let authoredFormatting = {};
|
|
3205
|
-
if (runFormattingOverrideMark) {
|
|
3206
|
-
const overrideAttrs = expectRunFormattingOverrideMarkAttrs(runFormattingOverrideMark);
|
|
3207
|
-
currentOverrideAttrs = overrideAttrs;
|
|
3208
|
-
directFontProperties = overrideAttrs.directFontProperties;
|
|
3209
|
-
directOverrideFormatting = {};
|
|
3210
|
-
applyRunFormattingOverrideAttrs(directOverrideFormatting, overrideAttrs);
|
|
3211
|
-
for (const property of directFontProperties ?? []) {
|
|
3212
|
-
const value = formatting[property];
|
|
3213
|
-
if (value !== void 0) Reflect.set(directOverrideFormatting, property, value);
|
|
3214
|
-
}
|
|
3215
|
-
authoredFormatting = authoredRunFormattingFromAttrs(overrideAttrs) ?? directOverrideFormatting;
|
|
3216
|
-
}
|
|
3217
|
-
if (characterStyleId !== void 0 && !options?.styleResolver) {
|
|
3218
|
-
const conservativeFormatting = mergeTextFormatting(formatting, directOverrideFormatting) ?? {};
|
|
3219
|
-
for (const property of currentOverrideAttrs?.complexScriptPropertyAbsences ?? []) Reflect.deleteProperty(conservativeFormatting, property);
|
|
3220
|
-
return {
|
|
3221
|
-
...conservativeFormatting,
|
|
3222
|
-
styleId: characterStyleId
|
|
3223
|
-
};
|
|
3224
|
-
}
|
|
3225
|
-
const inheritedFormatting = resolveEffectiveRunStyleFormatting({
|
|
3226
|
-
marks,
|
|
3227
|
-
paragraphFormatting: paragraphFormattingForRun({
|
|
3228
|
-
context: {
|
|
3229
|
-
baseParagraphFormatting: options?.baseParagraphFormatting,
|
|
3230
|
-
paragraphFormatting: options?.inheritedFormatting,
|
|
3231
|
-
paragraphMarkFormatting: options?.paragraphMarkFormatting,
|
|
3232
|
-
paragraphMarkPrecedesStyle: options?.paragraphMarkPrecedesStyle ?? false
|
|
3233
|
-
},
|
|
3234
|
-
directFormatting: authoredFormatting,
|
|
3235
|
-
marks
|
|
3236
|
-
}),
|
|
3237
|
-
...options?.styleResolver !== void 0 ? { styleResolver: options.styleResolver } : {}
|
|
3238
|
-
});
|
|
3239
|
-
let reconciled = reconcileAuthoredFormatting({
|
|
3240
|
-
authoredFormatting,
|
|
3241
|
-
carrierlessContext: options?.paragraphMarkFormatting === void 0 ? "ordinary" : "paragraph-mark",
|
|
3242
|
-
currentOverrideAttrs,
|
|
3243
|
-
inheritedFormatting,
|
|
3244
|
-
observedFormatting: formatting
|
|
3245
|
-
});
|
|
3246
|
-
if (runFormattingOverrideMark === void 0 && characterStyleId === void 0 && options?.paragraphMarkFormatting !== void 0) {
|
|
3247
|
-
const suppressedInheritedFormatting = resolveEffectiveRunStyleFormatting({
|
|
3248
|
-
marks,
|
|
3249
|
-
paragraphFormatting: suppressParagraphMarkFormatting({
|
|
3250
|
-
baseFormatting: options.baseParagraphFormatting,
|
|
3251
|
-
directFormatting: authoredFormatting,
|
|
3252
|
-
paragraphMarkFormatting: options.paragraphMarkFormatting,
|
|
3253
|
-
paragraphMarkPrecedesStyle: options.paragraphMarkPrecedesStyle ?? false
|
|
3254
|
-
}),
|
|
3255
|
-
...options.styleResolver !== void 0 ? { styleResolver: options.styleResolver } : {}
|
|
3256
|
-
});
|
|
3257
|
-
const suppressed = reconcileAuthoredFormatting({
|
|
3258
|
-
authoredFormatting,
|
|
3259
|
-
carrierlessContext: "paragraph-mark",
|
|
3260
|
-
currentOverrideAttrs,
|
|
3261
|
-
inheritedFormatting: suppressedInheritedFormatting,
|
|
3262
|
-
observedFormatting: formatting
|
|
3263
|
-
});
|
|
3264
|
-
if (formattingAuthorshipCost(suppressed) < formattingAuthorshipCost(reconciled)) reconciled = suppressed;
|
|
3265
|
-
}
|
|
3266
|
-
return {
|
|
3267
|
-
...reconciled,
|
|
3268
|
-
...characterStyleId !== void 0 ? { styleId: characterStyleId } : {}
|
|
3269
|
-
};
|
|
3270
|
-
}
|
|
3271
2693
|
/**
|
|
3272
2694
|
* Convert a ProseMirror table node to our Table type
|
|
3273
2695
|
*/
|