roosterjs-content-model-api 0.25.0 → 0.26.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.
Files changed (112) hide show
  1. package/lib/index.d.ts +5 -0
  2. package/lib/index.js +11 -1
  3. package/lib/index.js.map +1 -1
  4. package/lib/modelApi/block/setModelIndentation.d.ts +4 -1
  5. package/lib/modelApi/block/setModelIndentation.js +114 -23
  6. package/lib/modelApi/block/setModelIndentation.js.map +1 -1
  7. package/lib/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  8. package/lib/modelApi/entity/insertEntityModel.d.ts +2 -2
  9. package/lib/modelApi/entity/insertEntityModel.js +4 -0
  10. package/lib/modelApi/entity/insertEntityModel.js.map +1 -1
  11. package/lib/modelApi/list/findListItemsInSameThread.d.ts +3 -1
  12. package/lib/modelApi/list/findListItemsInSameThread.js +3 -1
  13. package/lib/modelApi/list/findListItemsInSameThread.js.map +1 -1
  14. package/lib/modelApi/list/setListType.js +1 -1
  15. package/lib/modelApi/list/setListType.js.map +1 -1
  16. package/lib/modelApi/table/clearSelectedCells.d.ts +8 -0
  17. package/lib/modelApi/table/clearSelectedCells.js +27 -0
  18. package/lib/modelApi/table/clearSelectedCells.js.map +1 -0
  19. package/lib/modelApi/table/insertTableColumn.d.ts +3 -1
  20. package/lib/modelApi/table/insertTableColumn.js +8 -2
  21. package/lib/modelApi/table/insertTableColumn.js.map +1 -1
  22. package/lib/modelApi/table/insertTableRow.d.ts +3 -1
  23. package/lib/modelApi/table/insertTableRow.js +8 -2
  24. package/lib/modelApi/table/insertTableRow.js.map +1 -1
  25. package/lib/publicApi/entity/insertEntity.js +7 -2
  26. package/lib/publicApi/entity/insertEntity.js.map +1 -1
  27. package/lib/publicApi/format/getFormatState.js +2 -2
  28. package/lib/publicApi/format/getFormatState.js.map +1 -1
  29. package/lib/publicApi/table/editTable.js +52 -77
  30. package/lib/publicApi/table/editTable.js.map +1 -1
  31. package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  32. package/lib/publicApi/utils/formatTableWithContentModel.d.ts +9 -0
  33. package/lib/publicApi/utils/formatTableWithContentModel.js +44 -0
  34. package/lib/publicApi/utils/formatTableWithContentModel.js.map +1 -0
  35. package/lib-amd/index.d.ts +5 -0
  36. package/lib-amd/index.js +7 -2
  37. package/lib-amd/index.js.map +1 -1
  38. package/lib-amd/modelApi/block/setModelIndentation.d.ts +4 -1
  39. package/lib-amd/modelApi/block/setModelIndentation.js +114 -24
  40. package/lib-amd/modelApi/block/setModelIndentation.js.map +1 -1
  41. package/lib-amd/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  42. package/lib-amd/modelApi/entity/insertEntityModel.d.ts +2 -2
  43. package/lib-amd/modelApi/entity/insertEntityModel.js +4 -0
  44. package/lib-amd/modelApi/entity/insertEntityModel.js.map +1 -1
  45. package/lib-amd/modelApi/list/findListItemsInSameThread.d.ts +3 -1
  46. package/lib-amd/modelApi/list/findListItemsInSameThread.js +3 -1
  47. package/lib-amd/modelApi/list/findListItemsInSameThread.js.map +1 -1
  48. package/lib-amd/modelApi/list/setListType.js +1 -1
  49. package/lib-amd/modelApi/list/setListType.js.map +1 -1
  50. package/lib-amd/modelApi/table/clearSelectedCells.d.ts +8 -0
  51. package/lib-amd/modelApi/table/clearSelectedCells.js +28 -0
  52. package/lib-amd/modelApi/table/clearSelectedCells.js.map +1 -0
  53. package/lib-amd/modelApi/table/insertTableColumn.d.ts +3 -1
  54. package/lib-amd/modelApi/table/insertTableColumn.js +8 -3
  55. package/lib-amd/modelApi/table/insertTableColumn.js.map +1 -1
  56. package/lib-amd/modelApi/table/insertTableRow.d.ts +3 -1
  57. package/lib-amd/modelApi/table/insertTableRow.js +8 -3
  58. package/lib-amd/modelApi/table/insertTableRow.js.map +1 -1
  59. package/lib-amd/publicApi/entity/insertEntity.js +7 -2
  60. package/lib-amd/publicApi/entity/insertEntity.js.map +1 -1
  61. package/lib-amd/publicApi/format/getFormatState.js +2 -2
  62. package/lib-amd/publicApi/format/getFormatState.js.map +1 -1
  63. package/lib-amd/publicApi/table/editTable.js +52 -74
  64. package/lib-amd/publicApi/table/editTable.js.map +1 -1
  65. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  66. package/lib-amd/publicApi/utils/formatTableWithContentModel.d.ts +9 -0
  67. package/lib-amd/publicApi/utils/formatTableWithContentModel.js +42 -0
  68. package/lib-amd/publicApi/utils/formatTableWithContentModel.js.map +1 -0
  69. package/lib-mjs/index.d.ts +5 -0
  70. package/lib-mjs/index.js +5 -0
  71. package/lib-mjs/index.js.map +1 -1
  72. package/lib-mjs/modelApi/block/setModelIndentation.d.ts +4 -1
  73. package/lib-mjs/modelApi/block/setModelIndentation.js +115 -24
  74. package/lib-mjs/modelApi/block/setModelIndentation.js.map +1 -1
  75. package/lib-mjs/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  76. package/lib-mjs/modelApi/entity/insertEntityModel.d.ts +2 -2
  77. package/lib-mjs/modelApi/entity/insertEntityModel.js +4 -0
  78. package/lib-mjs/modelApi/entity/insertEntityModel.js.map +1 -1
  79. package/lib-mjs/modelApi/list/findListItemsInSameThread.d.ts +3 -1
  80. package/lib-mjs/modelApi/list/findListItemsInSameThread.js +3 -1
  81. package/lib-mjs/modelApi/list/findListItemsInSameThread.js.map +1 -1
  82. package/lib-mjs/modelApi/list/setListType.js +1 -1
  83. package/lib-mjs/modelApi/list/setListType.js.map +1 -1
  84. package/lib-mjs/modelApi/table/clearSelectedCells.d.ts +8 -0
  85. package/lib-mjs/modelApi/table/clearSelectedCells.js +23 -0
  86. package/lib-mjs/modelApi/table/clearSelectedCells.js.map +1 -0
  87. package/lib-mjs/modelApi/table/insertTableColumn.d.ts +3 -1
  88. package/lib-mjs/modelApi/table/insertTableColumn.js +8 -2
  89. package/lib-mjs/modelApi/table/insertTableColumn.js.map +1 -1
  90. package/lib-mjs/modelApi/table/insertTableRow.d.ts +3 -1
  91. package/lib-mjs/modelApi/table/insertTableRow.js +8 -2
  92. package/lib-mjs/modelApi/table/insertTableRow.js.map +1 -1
  93. package/lib-mjs/publicApi/entity/insertEntity.js +7 -2
  94. package/lib-mjs/publicApi/entity/insertEntity.js.map +1 -1
  95. package/lib-mjs/publicApi/format/getFormatState.js +1 -1
  96. package/lib-mjs/publicApi/format/getFormatState.js.map +1 -1
  97. package/lib-mjs/publicApi/table/editTable.js +52 -77
  98. package/lib-mjs/publicApi/table/editTable.js.map +1 -1
  99. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  100. package/lib-mjs/publicApi/utils/formatTableWithContentModel.d.ts +9 -0
  101. package/lib-mjs/publicApi/utils/formatTableWithContentModel.js +40 -0
  102. package/lib-mjs/publicApi/utils/formatTableWithContentModel.js.map +1 -0
  103. package/package.json +4 -4
  104. package/lib/modelApi/common/retrieveModelFormatState.d.ts +0 -5
  105. package/lib/modelApi/common/retrieveModelFormatState.js +0 -171
  106. package/lib/modelApi/common/retrieveModelFormatState.js.map +0 -1
  107. package/lib-amd/modelApi/common/retrieveModelFormatState.d.ts +0 -5
  108. package/lib-amd/modelApi/common/retrieveModelFormatState.js +0 -171
  109. package/lib-amd/modelApi/common/retrieveModelFormatState.js.map +0 -1
  110. package/lib-mjs/modelApi/common/retrieveModelFormatState.d.ts +0 -5
  111. package/lib-mjs/modelApi/common/retrieveModelFormatState.js +0 -167
  112. package/lib-mjs/modelApi/common/retrieveModelFormatState.js.map +0 -1
@@ -1,167 +0,0 @@
1
- import { parseValueWithUnit } from 'roosterjs-content-model-dom';
2
- import { extractBorderValues, getClosestAncestorBlockGroupIndex, isBold, iterateSelections, updateTableMetadata, } from 'roosterjs-content-model-core';
3
- /**
4
- * @internal
5
- */
6
- export function retrieveModelFormatState(model, pendingFormat, formatState) {
7
- var firstTableContext;
8
- var firstBlock;
9
- var isFirst = true;
10
- var isFirstImage = true;
11
- var isFirstSegment = true;
12
- iterateSelections(model, function (path, tableContext, block, segments) {
13
- // Structure formats
14
- retrieveStructureFormat(formatState, path, isFirst);
15
- // Multiple line format
16
- if (block) {
17
- if (firstBlock) {
18
- formatState.isMultilineSelection = true;
19
- }
20
- else {
21
- firstBlock = block;
22
- }
23
- }
24
- if ((block === null || block === void 0 ? void 0 : block.blockType) == 'Paragraph') {
25
- // Paragraph formats
26
- retrieveParagraphFormat(formatState, block, isFirst);
27
- // Segment formats
28
- segments === null || segments === void 0 ? void 0 : segments.forEach(function (segment) {
29
- var _a, _b, _c;
30
- if (isFirstSegment || segment.segmentType != 'SelectionMarker') {
31
- var modelFormat = Object.assign({}, model.format);
32
- modelFormat === null || modelFormat === void 0 ? true : delete modelFormat.italic;
33
- modelFormat === null || modelFormat === void 0 ? true : delete modelFormat.underline;
34
- modelFormat === null || modelFormat === void 0 ? true : delete modelFormat.fontWeight;
35
- retrieveSegmentFormat(formatState, isFirst, Object.assign({}, modelFormat, block.format, (_a = block.decorator) === null || _a === void 0 ? void 0 : _a.format, segment.format, (_b = segment.code) === null || _b === void 0 ? void 0 : _b.format, (_c = segment.link) === null || _c === void 0 ? void 0 : _c.format, pendingFormat));
36
- mergeValue(formatState, 'isCodeInline', !!(segment === null || segment === void 0 ? void 0 : segment.code), isFirst);
37
- }
38
- // We only care the format of selection marker when it is the first selected segment. This is because when selection marker
39
- // is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line
40
- // is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to
41
- // ignore it
42
- isFirstSegment = false;
43
- formatState.canUnlink = formatState.canUnlink || !!segment.link;
44
- formatState.canAddImageAltText =
45
- formatState.canAddImageAltText ||
46
- segments.some(function (segment) { return segment.segmentType == 'Image'; });
47
- isFirst = false;
48
- if (segment.segmentType === 'Image') {
49
- if (isFirstImage) {
50
- retrieveImageFormat(segment, formatState);
51
- isFirstImage = false;
52
- }
53
- else {
54
- formatState.imageFormat = undefined;
55
- }
56
- }
57
- });
58
- isFirst = false;
59
- }
60
- if (tableContext) {
61
- if (firstTableContext) {
62
- var table = firstTableContext.table, colIndex = firstTableContext.colIndex, rowIndex = firstTableContext.rowIndex;
63
- // Merge table format
64
- if (tableContext.table == table &&
65
- (tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)) {
66
- formatState.canMergeTableCell = true;
67
- formatState.isMultilineSelection = true;
68
- }
69
- }
70
- else {
71
- // Table formats
72
- retrieveTableFormat(tableContext, formatState);
73
- firstTableContext = tableContext;
74
- }
75
- }
76
- }, {
77
- includeListFormatHolder: 'never',
78
- });
79
- if (formatState.fontSize) {
80
- formatState.fontSize = px2Pt(formatState.fontSize);
81
- }
82
- }
83
- function retrieveSegmentFormat(result, isFirst, mergedFormat) {
84
- var _a, _b;
85
- var superOrSubscript = (_b = (_a = mergedFormat.superOrSubScriptSequence) === null || _a === void 0 ? void 0 : _a.split(' ')) === null || _b === void 0 ? void 0 : _b.pop();
86
- mergeValue(result, 'isBold', isBold(mergedFormat.fontWeight), isFirst);
87
- mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);
88
- mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);
89
- mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);
90
- mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);
91
- mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);
92
- mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);
93
- mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);
94
- mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst, function (val) { return parseValueWithUnit(val, undefined, 'pt') + 'pt'; });
95
- mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);
96
- mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);
97
- mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);
98
- mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);
99
- }
100
- function retrieveParagraphFormat(result, paragraph, isFirst) {
101
- var _a;
102
- var headingLevel = parseInt((((_a = paragraph.decorator) === null || _a === void 0 ? void 0 : _a.tagName) || '').substring(1));
103
- var validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;
104
- mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);
105
- mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);
106
- mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);
107
- mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);
108
- mergeValue(result, 'direction', paragraph.format.direction, isFirst);
109
- }
110
- function retrieveStructureFormat(result, path, isFirst) {
111
- var _a, _b;
112
- var listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem'], []);
113
- var containerIndex = getClosestAncestorBlockGroupIndex(path, ['FormatContainer'], []);
114
- if (listItemIndex >= 0) {
115
- var listItem = path[listItemIndex];
116
- var listType = (_a = listItem === null || listItem === void 0 ? void 0 : listItem.levels[listItem.levels.length - 1]) === null || _a === void 0 ? void 0 : _a.listType;
117
- mergeValue(result, 'isBullet', listType == 'UL', isFirst);
118
- mergeValue(result, 'isNumbering', listType == 'OL', isFirst);
119
- }
120
- mergeValue(result, 'isBlockQuote', containerIndex >= 0 &&
121
- ((_b = path[containerIndex]) === null || _b === void 0 ? void 0 : _b.tagName) == 'blockquote', isFirst);
122
- }
123
- function retrieveTableFormat(tableContext, result) {
124
- var tableFormat = updateTableMetadata(tableContext.table);
125
- result.isInTable = true;
126
- result.tableHasHeader = tableContext.table.rows.some(function (row) {
127
- return row.cells.some(function (cell) { return cell.isHeader; });
128
- });
129
- if (tableFormat) {
130
- result.tableFormat = tableFormat;
131
- }
132
- }
133
- function retrieveImageFormat(image, result) {
134
- var format = image.format;
135
- var borderKey = 'borderTop';
136
- var extractedBorder = extractBorderValues(format[borderKey]);
137
- var borderColor = extractedBorder.color;
138
- var borderWidth = extractedBorder.width;
139
- var borderStyle = extractedBorder.style;
140
- result.imageFormat = {
141
- borderColor: borderColor,
142
- borderWidth: borderWidth,
143
- borderStyle: borderStyle,
144
- boxShadow: format.boxShadow,
145
- borderRadius: format.borderRadius,
146
- };
147
- }
148
- function mergeValue(format, key, newValue, isFirst, parseFn) {
149
- if (parseFn === void 0) { parseFn = function (val) { return val; }; }
150
- if (isFirst) {
151
- if (newValue !== undefined) {
152
- format[key] = newValue;
153
- }
154
- }
155
- else if (parseFn(newValue) !== parseFn(format[key])) {
156
- delete format[key];
157
- }
158
- }
159
- function px2Pt(px) {
160
- if (px && px.indexOf('px') == px.length - 2) {
161
- // Edge may not handle the floating computing well which causes the calculated value is a little less than actual value
162
- // So add 0.05 to fix it
163
- return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';
164
- }
165
- return px;
166
- }
167
- //# sourceMappingURL=retrieveModelFormatState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retrieveModelFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/common/retrieveModelFormatState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EACH,mBAAmB,EACnB,iCAAiC,EACjC,MAAM,EACN,iBAAiB,EACjB,mBAAmB,GACtB,MAAM,8BAA8B,CAAC;AActC;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACpC,KAA2B,EAC3B,aAA+C,EAC/C,WAAoC;IAEpC,IAAI,iBAAoD,CAAC;IACzD,IAAI,UAAyC,CAAC;IAC9C,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,IAAI,cAAc,GAAG,IAAI,CAAC;IAE1B,iBAAiB,CACb,KAAK,EACL,UAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ;QAChC,oBAAoB;QACpB,uBAAuB,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAEpD,uBAAuB;QACvB,IAAI,KAAK,EAAE;YACP,IAAI,UAAU,EAAE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ockGroupIndex,\n isBold,\n iterateSelections,\n updateTableMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n ContentModelFormatState,\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelImage,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function retrieveModelFormatState(\n model: ContentModelDocument,\n pendingFormat: ContentModelSegmentFormat | null,\n formatState: ContentModelFormatState\n) {\n let firstTableContext: TableSelectionContext | undefined;\n let firstBlock: ContentModelBlock | undefined;\n let isFirst = true;\n let isFirstImage = true;\n let isFirstSegment = true;\n\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n // Structure formats\n retrieveStructureFormat(formatState, path, isFirst);\n\n // Multiple line format\n if (block) {\n if (firstBlock) {\n formatState.isMultilineSelection = true;\n } else {\n firstBlock = block;\n }\n }\n\n if (block?.blockType == 'Paragraph') {\n // Paragraph formats\n retrieveParagraphFormat(formatState, block, isFirst);\n\n // Segment formats\n segments?.forEach(segment => {\n if (isFirstSegment || segment.segmentType != 'SelectionMarker') {\n const modelFormat = Object.assign({}, model.format);\n delete modelFormat?.italic;\n delete modelFormat?.underline;\n delete modelFormat?.fontWeight;\n\n retrieveSegmentFormat(\n formatState,\n isFirst,\n Object.assign(\n {},\n modelFormat,\n block.format,\n block.decorator?.format,\n segment.format,\n segment.code?.format,\n segment.link?.format,\n pendingFormat\n )\n );\n\n mergeValue(formatState, 'isCodeInline', !!segment?.code, isFirst);\n }\n\n // We only care the format of selection marker when it is the first selected segment. This is because when selection marker\n // is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line\n // is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to\n // ignore it\n isFirstSegment = false;\n\n formatState.canUnlink = formatState.canUnlink || !!segment.link;\n formatState.canAddImageAltText =\n formatState.canAddImageAltText ||\n segments.some(segment => segment.segmentType == 'Image');\n\n isFirst = false;\n\n if (segment.segmentType === 'Image') {\n if (isFirstImage) {\n retrieveImageFormat(segment, formatState);\n isFirstImage = false;\n } else {\n formatState.imageFormat = undefined;\n }\n }\n });\n\n isFirst = false;\n }\n\n if (tableContext) {\n if (firstTableContext) {\n const { table, colIndex, rowIndex } = firstTableContext;\n\n // Merge table format\n if (\n tableContext.table == table &&\n (tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)\n ) {\n formatState.canMergeTableCell = true;\n formatState.isMultilineSelection = true;\n }\n } else {\n // Table formats\n retrieveTableFormat(tableContext, formatState);\n firstTableContext = tableContext;\n }\n }\n },\n {\n includeListFormatHolder: 'never',\n }\n );\n\n if (formatState.fontSize) {\n formatState.fontSize = px2Pt(formatState.fontSize);\n }\n}\n\nfunction retrieveSegmentFormat(\n result: ContentModelFormatState,\n isFirst: boolean,\n mergedFormat: ContentModelSegmentFormat\n) {\n const superOrSubscript = mergedFormat.superOrSubScriptSequence?.split(' ')?.pop();\n\n mergeValue(result, 'isBold', isBold(mergedFormat.fontWeight), isFirst);\n mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);\n mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);\n mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);\n mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);\n mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);\n mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);\n\n mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);\n mergeValue(\n result,\n 'fontSize',\n mergedFormat.fontSize,\n isFirst,\n val => parseValueWithUnit(val, undefined, 'pt') + 'pt'\n );\n mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);\n mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);\n mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);\n mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);\n}\n\nfunction retrieveParagraphFormat(\n result: ContentModelFormatState,\n paragraph: ContentModelParagraph,\n isFirst: boolean\n) {\n const headingLevel = parseInt((paragraph.decorator?.tagName || '').substring(1));\n const validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;\n\n mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);\n mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);\n mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);\n mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);\n mergeValue(result, 'direction', paragraph.format.direction, isFirst);\n}\n\nfunction retrieveStructureFormat(\n result: ContentModelFormatState,\n path: ContentModelBlockGroup[],\n isFirst: boolean\n) {\n const listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem'], []);\n const containerIndex = getClosestAncestorBlockGroupIndex(path, ['FormatContainer'], []);\n\n if (listItemIndex >= 0) {\n const listItem = path[listItemIndex] as ContentModelListItem;\n const listType = listItem?.levels[listItem.levels.length - 1]?.listType;\n\n mergeValue(result, 'isBullet', listType == 'UL', isFirst);\n mergeValue(result, 'isNumbering', listType == 'OL', isFirst);\n }\n\n mergeValue(\n result,\n 'isBlockQuote',\n containerIndex >= 0 &&\n (path[containerIndex] as ContentModelFormatContainer)?.tagName == 'blockquote',\n isFirst\n );\n}\n\nfunction retrieveTableFormat(tableContext: TableSelectionContext, result: ContentModelFormatState) {\n const tableFormat = updateTableMetadata(tableContext.table);\n\n result.isInTable = true;\n result.tableHasHeader = tableContext.table.rows.some(row =>\n row.cells.some(cell => cell.isHeader)\n );\n\n if (tableFormat) {\n result.tableFormat = tableFormat;\n }\n}\n\nfunction retrieveImageFormat(image: ContentModelImage, result: ContentModelFormatState) {\n const { format } = image;\n const borderKey = 'borderTop';\n const extractedBorder = extractBorderValues(format[borderKey]);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n result.imageFormat = {\n borderColor,\n borderWidth,\n borderStyle,\n boxShadow: format.boxShadow,\n borderRadius: format.borderRadius,\n };\n}\n\nfunction mergeValue<K extends keyof ContentModelFormatState>(\n format: ContentModelFormatState,\n key: K,\n newValue: ContentModelFormatState[K] | undefined,\n isFirst: boolean,\n parseFn: (val: ContentModelFormatState[K]) => ContentModelFormatState[K] = val => val\n) {\n if (isFirst) {\n if (newValue !== undefined) {\n format[key] = newValue;\n }\n } else if (parseFn(newValue) !== parseFn(format[key])) {\n delete format[key];\n }\n}\n\nfunction px2Pt(px: string) {\n if (px && px.indexOf('px') == px.length - 2) {\n // Edge may not handle the floating computing well which causes the calculated value is a little less than actual value\n // So add 0.05 to fix it\n return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';\n }\n return px;\n}\n"]}