@syncfusion/ej2-office-common 35.1.37 → 35.1.42

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 (226) hide show
  1. package/dist/ej2-office-common.umd.min.js +2 -2
  2. package/dist/ej2-office-common.umd.min.js.map +1 -1
  3. package/dist/es6/ej2-office-common.es2015.js +5421 -6017
  4. package/dist/es6/ej2-office-common.es2015.js.map +1 -1
  5. package/dist/es6/ej2-office-common.es5.js +6270 -7203
  6. package/dist/es6/ej2-office-common.es5.js.map +1 -1
  7. package/dist/global/ej2-office-common.min.js +2 -2
  8. package/dist/global/ej2-office-common.min.js.map +1 -1
  9. package/dist/global/index.d.ts +1 -1
  10. package/office-common.js +4 -0
  11. package/package.json +11 -7
  12. package/src/index.d.ts +3 -17
  13. package/src/index.js +3 -18
  14. package/src/office-common/features/index.d.ts +6 -0
  15. package/src/office-common/features/index.js +6 -0
  16. package/src/office-common/features/mathml/index.d.ts +25 -0
  17. package/src/office-common/features/mathml/index.js +22 -0
  18. package/src/office-common/features/mathml/latex/latex-generator.d.ts +8 -0
  19. package/src/office-common/features/mathml/latex/latex-generator.js +357 -0
  20. package/src/office-common/features/mathml/latex/latex-parser.d.ts +87 -0
  21. package/src/office-common/features/mathml/latex/latex-parser.js +1206 -0
  22. package/src/office-common/features/mathml/latex/latex-symbols.d.ts +13 -0
  23. package/src/office-common/features/mathml/latex/latex-symbols.js +681 -0
  24. package/src/office-common/features/mathml/math-settings.d.ts +54 -0
  25. package/src/office-common/features/mathml/math-settings.js +174 -0
  26. package/src/office-common/features/mathml/office-math/adapter.d.ts +59 -0
  27. package/src/office-common/features/mathml/office-math/adapter.js +6 -0
  28. package/src/office-common/features/mathml/office-math/basic.d.ts +91 -0
  29. package/src/office-common/features/mathml/office-math/basic.js +93 -0
  30. package/src/office-common/features/mathml/office-math/break.d.ts +30 -0
  31. package/src/office-common/features/mathml/office-math/break.js +75 -0
  32. package/src/office-common/features/mathml/office-math/collection.d.ts +104 -0
  33. package/src/office-common/features/mathml/office-math/collection.js +170 -0
  34. package/src/office-common/features/mathml/office-math/entity.d.ts +12 -0
  35. package/src/office-common/features/mathml/office-math/entity.js +3 -0
  36. package/src/office-common/features/mathml/office-math/enums.d.ts +97 -0
  37. package/src/office-common/features/mathml/office-math/enums.js +108 -0
  38. package/src/office-common/features/mathml/office-math/format.d.ts +28 -0
  39. package/src/office-common/features/mathml/office-math/format.js +90 -0
  40. package/src/office-common/features/mathml/office-math/function-base.d.ts +27 -0
  41. package/src/office-common/features/mathml/office-math/function-base.js +69 -0
  42. package/src/office-common/features/mathml/office-math/function-collection.d.ts +29 -0
  43. package/src/office-common/features/mathml/office-math/function-collection.js +76 -0
  44. package/src/office-common/features/mathml/office-math/functions-basic.d.ts +118 -0
  45. package/src/office-common/features/mathml/office-math/functions-basic.js +331 -0
  46. package/src/office-common/features/mathml/office-math/functions-multi.d.ts +156 -0
  47. package/src/office-common/features/mathml/office-math/functions-multi.js +407 -0
  48. package/src/office-common/features/mathml/office-math/index.d.ts +27 -0
  49. package/src/office-common/features/mathml/office-math/index.js +25 -0
  50. package/src/office-common/features/mathml/office-math/keys.d.ts +6 -0
  51. package/src/office-common/features/mathml/office-math/keys.js +20 -0
  52. package/src/office-common/features/mathml/office-math/math-clone.d.ts +20 -0
  53. package/src/office-common/features/mathml/office-math/math-clone.js +203 -0
  54. package/src/office-common/features/mathml/office-math/math-collection.d.ts +19 -0
  55. package/src/office-common/features/mathml/office-math/math-collection.js +41 -0
  56. package/src/office-common/features/mathml/office-math/math-equality.d.ts +21 -0
  57. package/src/office-common/features/mathml/office-math/math-equality.js +115 -0
  58. package/src/office-common/features/mathml/office-math/math-paragraph.d.ts +58 -0
  59. package/src/office-common/features/mathml/office-math/math-paragraph.js +126 -0
  60. package/src/office-common/features/mathml/office-math/math-traversal.d.ts +23 -0
  61. package/src/office-common/features/mathml/office-math/math-traversal.js +95 -0
  62. package/src/office-common/features/mathml/office-math/matrix-collections.d.ts +54 -0
  63. package/src/office-common/features/mathml/office-math/matrix-collections.js +113 -0
  64. package/src/office-common/features/mathml/office-math/matrix-column.d.ts +43 -0
  65. package/src/office-common/features/mathml/office-math/matrix-column.js +96 -0
  66. package/src/office-common/features/mathml/office-math/matrix-row.d.ts +38 -0
  67. package/src/office-common/features/mathml/office-math/matrix-row.js +71 -0
  68. package/src/office-common/features/mathml/office-math/matrix.d.ts +62 -0
  69. package/src/office-common/features/mathml/office-math/matrix.js +158 -0
  70. package/src/office-common/features/mathml/office-math/office-math.d.ts +55 -0
  71. package/src/office-common/features/mathml/office-math/office-math.js +116 -0
  72. package/src/office-common/features/mathml/office-math/owner-holder.d.ts +42 -0
  73. package/src/office-common/features/mathml/office-math/owner-holder.js +87 -0
  74. package/src/office-common/features/mathml/office-math/property-store.d.ts +66 -0
  75. package/src/office-common/features/mathml/office-math/property-store.js +99 -0
  76. package/src/office-common/features/mathml/office-math/run-element.d.ts +31 -0
  77. package/src/office-common/features/mathml/office-math/run-element.js +97 -0
  78. package/src/office-common/features/mathml/office-math/unknown-element.d.ts +37 -0
  79. package/src/office-common/features/mathml/office-math/unknown-element.js +62 -0
  80. package/src/office-common/features/mathml/office-math/xml-equal.d.ts +13 -0
  81. package/src/office-common/features/mathml/office-math/xml-equal.js +24 -0
  82. package/src/office-common/features/mathml/parse/office-math-parser.d.ts +24 -0
  83. package/src/office-common/features/mathml/parse/office-math-parser.js +396 -0
  84. package/src/office-common/features/mathml/parse/office-math-properties.d.ts +165 -0
  85. package/src/office-common/features/mathml/parse/office-math-properties.js +432 -0
  86. package/src/office-common/features/mathml/parse/parse-options.d.ts +22 -0
  87. package/src/office-common/features/mathml/parse/parse-options.js +3 -0
  88. package/src/office-common/features/mathml/serialize/office-math-properties-writer.d.ts +38 -0
  89. package/src/office-common/features/mathml/serialize/office-math-properties-writer.js +267 -0
  90. package/src/office-common/features/mathml/serialize/office-math-serializer.d.ts +23 -0
  91. package/src/office-common/features/mathml/serialize/office-math-serializer.js +306 -0
  92. package/src/office-common/features/mathml/serialize/omml-writer.d.ts +123 -0
  93. package/src/office-common/features/mathml/serialize/omml-writer.js +135 -0
  94. package/src/office-common/index.d.ts +10 -0
  95. package/src/office-common/index.js +10 -0
  96. package/.eslintrc.json +0 -263
  97. package/.prettierrc.json +0 -5
  98. package/api-extractor.json +0 -35
  99. package/core.js +0 -4
  100. package/encryption.js +0 -4
  101. package/features.js +0 -4
  102. package/global.json +0 -6
  103. package/nuget.config +0 -7
  104. package/src/all.d.ts +0 -41
  105. package/src/all.js +0 -38
  106. package/src/features/index.d.ts +0 -11
  107. package/src/features/index.js +0 -11
  108. package/src/features/mathml/index.d.ts +0 -30
  109. package/src/features/mathml/index.js +0 -22
  110. package/src/features/mathml/math-factory.d.ts +0 -26
  111. package/src/features/mathml/math-factory.js +0 -568
  112. package/src/features/mathml/model/controls.d.ts +0 -896
  113. package/src/features/mathml/model/controls.js +0 -1541
  114. package/src/features/mathml/model/math-element.d.ts +0 -173
  115. package/src/features/mathml/model/math-element.js +0 -315
  116. package/src/features/mathml/model/roots.d.ts +0 -82
  117. package/src/features/mathml/model/roots.js +0 -177
  118. package/src/features/mathml/parse/math-parser.d.ts +0 -43
  119. package/src/features/mathml/parse/math-parser.js +0 -636
  120. package/src/features/mathml/serialize/math-serializer.d.ts +0 -34
  121. package/src/features/mathml/serialize/math-serializer.js +0 -749
  122. package/tsconfig.build.json +0 -13
  123. package/tsconfig.harness.json +0 -32
  124. package/tslint.json +0 -111
  125. /package/src/{core → office-common/core}/index.d.ts +0 -0
  126. /package/src/{core → office-common/core}/index.js +0 -0
  127. /package/src/{core → office-common/core}/xml/index.d.ts +0 -0
  128. /package/src/{core → office-common/core}/xml/index.js +0 -0
  129. /package/src/{core → office-common/core}/xml/model.d.ts +0 -0
  130. /package/src/{core → office-common/core}/xml/model.js +0 -0
  131. /package/src/{encryption → office-common/encryption}/agile-constants.d.ts +0 -0
  132. /package/src/{encryption → office-common/encryption}/agile-constants.js +0 -0
  133. /package/src/{encryption → office-common/encryption}/agile-encryption-info.d.ts +0 -0
  134. /package/src/{encryption → office-common/encryption}/agile-encryption-info.js +0 -0
  135. /package/src/{encryption → office-common/encryption}/agile-password.d.ts +0 -0
  136. /package/src/{encryption → office-common/encryption}/agile-password.js +0 -0
  137. /package/src/{encryption → office-common/encryption}/cfb-reader.d.ts +0 -0
  138. /package/src/{encryption → office-common/encryption}/cfb-reader.js +0 -0
  139. /package/src/{encryption → office-common/encryption}/crypto-primitives.d.ts +0 -0
  140. /package/src/{encryption → office-common/encryption}/crypto-primitives.js +0 -0
  141. /package/src/{encryption → office-common/encryption}/decrypt-encrypted-package.d.ts +0 -0
  142. /package/src/{encryption → office-common/encryption}/decrypt-encrypted-package.js +0 -0
  143. /package/src/{encryption → office-common/encryption}/encryption-info-xml.d.ts +0 -0
  144. /package/src/{encryption → office-common/encryption}/encryption-info-xml.js +0 -0
  145. /package/src/{encryption → office-common/encryption}/errors.d.ts +0 -0
  146. /package/src/{encryption → office-common/encryption}/errors.js +0 -0
  147. /package/src/{encryption → office-common/encryption}/index.d.ts +0 -0
  148. /package/src/{encryption → office-common/encryption}/index.js +0 -0
  149. /package/src/{features → office-common/features}/diagrams/constants.d.ts +0 -0
  150. /package/src/{features → office-common/features}/diagrams/constants.js +0 -0
  151. /package/src/{features → office-common/features}/diagrams/diagram-data-model.d.ts +0 -0
  152. /package/src/{features → office-common/features}/diagrams/diagram-data-model.js +0 -0
  153. /package/src/{features → office-common/features}/diagrams/diagram-parsers.d.ts +0 -0
  154. /package/src/{features → office-common/features}/diagrams/diagram-parsers.js +0 -0
  155. /package/src/{features → office-common/features}/diagrams/diagram-serializers.d.ts +0 -0
  156. /package/src/{features → office-common/features}/diagrams/diagram-serializers.js +0 -0
  157. /package/src/{features → office-common/features}/diagrams/diagram-views.d.ts +0 -0
  158. /package/src/{features → office-common/features}/diagrams/diagram-views.js +0 -0
  159. /package/src/{features → office-common/features}/diagrams/element-tree.d.ts +0 -0
  160. /package/src/{features → office-common/features}/diagrams/element-tree.js +0 -0
  161. /package/src/{features → office-common/features}/diagrams/errors.d.ts +0 -0
  162. /package/src/{features → office-common/features}/diagrams/errors.js +0 -0
  163. /package/src/{features → office-common/features}/diagrams/index.d.ts +0 -0
  164. /package/src/{features → office-common/features}/diagrams/index.js +0 -0
  165. /package/src/{features → office-common/features}/diagrams/smart-art-catalog.d.ts +0 -0
  166. /package/src/{features → office-common/features}/diagrams/smart-art-catalog.js +0 -0
  167. /package/src/{features → office-common/features}/diagrams/smart-art-diagram.d.ts +0 -0
  168. /package/src/{features → office-common/features}/diagrams/smart-art-diagram.js +0 -0
  169. /package/src/{features → office-common/features}/ink/constants.d.ts +0 -0
  170. /package/src/{features → office-common/features}/ink/constants.js +0 -0
  171. /package/src/{features → office-common/features}/ink/index.d.ts +0 -0
  172. /package/src/{features → office-common/features}/ink/index.js +0 -0
  173. /package/src/{features → office-common/features}/ink/ink-effects.d.ts +0 -0
  174. /package/src/{features → office-common/features}/ink/ink-effects.js +0 -0
  175. /package/src/{features → office-common/features}/ink/ink-model.d.ts +0 -0
  176. /package/src/{features → office-common/features}/ink/ink-model.js +0 -0
  177. /package/src/{features → office-common/features}/ink/ink-parser.d.ts +0 -0
  178. /package/src/{features → office-common/features}/ink/ink-parser.js +0 -0
  179. /package/src/{features → office-common/features}/ink/ink-serializer.d.ts +0 -0
  180. /package/src/{features → office-common/features}/ink/ink-serializer.js +0 -0
  181. /package/src/{features → office-common/features}/ink/ink-units.d.ts +0 -0
  182. /package/src/{features → office-common/features}/ink/ink-units.js +0 -0
  183. /package/src/{features → office-common/features}/ink/ink-xml.d.ts +0 -0
  184. /package/src/{features → office-common/features}/ink/ink-xml.js +0 -0
  185. /package/src/{features → office-common/features}/ink/trace-codec.d.ts +0 -0
  186. /package/src/{features → office-common/features}/ink/trace-codec.js +0 -0
  187. /package/src/{features → office-common/features}/mathml/constants.d.ts +0 -0
  188. /package/src/{features → office-common/features}/mathml/constants.js +0 -0
  189. /package/src/{features → office-common/features}/mathml/errors.d.ts +0 -0
  190. /package/src/{features → office-common/features}/mathml/errors.js +0 -0
  191. /package/src/{features → office-common/features}/mathml/model/enums.d.ts +0 -0
  192. /package/src/{features → office-common/features}/mathml/model/enums.js +0 -0
  193. /package/src/{features → office-common/features}/mathml/openxml.d.ts +0 -0
  194. /package/src/{features → office-common/features}/mathml/openxml.js +0 -0
  195. /package/src/{features → office-common/features}/smart-art/diagram-xml.d.ts +0 -0
  196. /package/src/{features → office-common/features}/smart-art/diagram-xml.js +0 -0
  197. /package/src/{features → office-common/features}/smart-art/errors.d.ts +0 -0
  198. /package/src/{features → office-common/features}/smart-art/errors.js +0 -0
  199. /package/src/{features → office-common/features}/smart-art/index.d.ts +0 -0
  200. /package/src/{features → office-common/features}/smart-art/index.js +0 -0
  201. /package/src/{features → office-common/features}/smart-art/minimal-samples.d.ts +0 -0
  202. /package/src/{features → office-common/features}/smart-art/minimal-samples.js +0 -0
  203. /package/src/{features → office-common/features}/smart-art/mutators.d.ts +0 -0
  204. /package/src/{features → office-common/features}/smart-art/mutators.js +0 -0
  205. /package/src/{features → office-common/features}/smart-art/namespaces.d.ts +0 -0
  206. /package/src/{features → office-common/features}/smart-art/namespaces.js +0 -0
  207. /package/src/{features → office-common/features}/smart-art/package-graph.d.ts +0 -0
  208. /package/src/{features → office-common/features}/smart-art/package-graph.js +0 -0
  209. /package/src/{features → office-common/features}/smart-art/parse-colors.d.ts +0 -0
  210. /package/src/{features → office-common/features}/smart-art/parse-colors.js +0 -0
  211. /package/src/{features → office-common/features}/smart-art/parse-data.d.ts +0 -0
  212. /package/src/{features → office-common/features}/smart-art/parse-data.js +0 -0
  213. /package/src/{features → office-common/features}/smart-art/parse-layout.d.ts +0 -0
  214. /package/src/{features → office-common/features}/smart-art/parse-layout.js +0 -0
  215. /package/src/{features → office-common/features}/smart-art/parse-rel-ids.d.ts +0 -0
  216. /package/src/{features → office-common/features}/smart-art/parse-rel-ids.js +0 -0
  217. /package/src/{features → office-common/features}/smart-art/parse-style.d.ts +0 -0
  218. /package/src/{features → office-common/features}/smart-art/parse-style.js +0 -0
  219. /package/src/{features → office-common/features}/smart-art/point-text.d.ts +0 -0
  220. /package/src/{features → office-common/features}/smart-art/point-text.js +0 -0
  221. /package/src/{features → office-common/features}/smart-art/register.d.ts +0 -0
  222. /package/src/{features → office-common/features}/smart-art/register.js +0 -0
  223. /package/src/{features → office-common/features}/smart-art/serialize.d.ts +0 -0
  224. /package/src/{features → office-common/features}/smart-art/serialize.js +0 -0
  225. /package/src/{features → office-common/features}/smart-art/types.d.ts +0 -0
  226. /package/src/{features → office-common/features}/smart-art/types.js +0 -0
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Writers that turn explicit Office Math properties into `m:*Pr` children.
3
+ *
4
+ * Source: ECMA-376-1 §22.1.2 (shared-math.xsd). Only explicitly set properties are written, in schema order.
5
+ */
6
+ var _a;
7
+ import { MathFunctionType } from '../office-math/enums';
8
+ import { K } from '../office-math/keys';
9
+ import { invalid, mathAttribute, mathElement, token, unsigned, valueElement, writeFlags, writeValue } from './omml-writer';
10
+ var FRACTION = ['bar', 'noBar', 'skw', 'lin'];
11
+ var VERTICAL = ['center', 'top', 'bottom'];
12
+ var HORIZONTAL = ['center', 'left', 'right'];
13
+ var SHAPE = ['centered', 'match'];
14
+ var FONT = ['double-struck', 'fraktur', 'monospace', 'roman', 'sans-serif', 'script'];
15
+ var STYLE = ['i', 'bi', 'b', 'p'];
16
+ /** Element name of the property container of each function. @private */
17
+ export var PROPERTY_ELEMENT = (_a = {},
18
+ _a[MathFunctionType.Accent] = 'accPr',
19
+ _a[MathFunctionType.Bar] = 'barPr',
20
+ _a[MathFunctionType.BorderBox] = 'borderBoxPr',
21
+ _a[MathFunctionType.Box] = 'boxPr',
22
+ _a[MathFunctionType.Delimiter] = 'dPr',
23
+ _a[MathFunctionType.EquationArray] = 'eqArrPr',
24
+ _a[MathFunctionType.Fraction] = 'fPr',
25
+ _a[MathFunctionType.Function] = 'funcPr',
26
+ _a[MathFunctionType.GroupCharacter] = 'groupChrPr',
27
+ _a[MathFunctionType.Matrix] = 'mPr',
28
+ _a[MathFunctionType.NArray] = 'naryPr',
29
+ _a[MathFunctionType.Phantom] = 'phantPr',
30
+ _a[MathFunctionType.Radical] = 'radPr',
31
+ _a[MathFunctionType.LeftSubSuperscript] = 'sPrePr',
32
+ _a[MathFunctionType.RightSubSuperscript] = 'sSubSupPr',
33
+ _a);
34
+ /**
35
+ * Writes `m:brk` when the break has an explicit alignment point, otherwise an empty `m:brk`. @private
36
+ *
37
+ * @param {WriteContext} ctx The write context.
38
+ * @param {OfficeMathBreak} brk The break.
39
+ * @returns {OpenXmlChild} The element.
40
+ */
41
+ export function writeBreak(ctx, brk) {
42
+ if (!brk.isExplicit(K.AlignAt)) {
43
+ return mathElement(ctx, 'brk');
44
+ }
45
+ if (!Number.isInteger(brk.alignAt) || brk.alignAt < 1 || brk.alignAt > 255) {
46
+ invalid('alnAt must be an integer in 1..255, got ' + String(brk.alignAt), 'brk.alnAt', 'value-range');
47
+ }
48
+ return mathElement(ctx, 'brk', [], [mathAttribute(ctx, 'alnAt', String(brk.alignAt))]);
49
+ }
50
+ /**
51
+ * Writes the children of `m:rPr`. `m:nor` excludes `m:scr`/`m:sty` per the schema choice. @private
52
+ *
53
+ * @param {WriteContext} ctx The write context.
54
+ * @param {OfficeMathFormat} format The Math run format.
55
+ * @returns {OpenXmlChild[]} The children.
56
+ */
57
+ export function runFormatChildren(ctx, format) {
58
+ var out = [];
59
+ writeFlags(ctx, out, format, [[K.HasLiteral, 'lit', format.hasLiteral]]);
60
+ var normal = format.isExplicit(K.HasNormalText) && (format.hasNormalText || !isScriptStyle(format));
61
+ if (normal) {
62
+ writeFlags(ctx, out, format, [[K.HasNormalText, 'nor', format.hasNormalText]]);
63
+ }
64
+ else {
65
+ writeValue(ctx, out, format, K.Script, 'scr', function () { return token(FONT, format.font, 'rPr.scr', 'ST_Script'); });
66
+ writeValue(ctx, out, format, K.Style, 'sty', function () { return token(STYLE, format.style, 'rPr.sty', 'ST_Style'); });
67
+ }
68
+ if (format.break !== undefined) {
69
+ out.push(writeBreak(ctx, format.break));
70
+ }
71
+ writeFlags(ctx, out, format, [[K.HasAlignment, 'aln', format.hasAlignment]]);
72
+ return out;
73
+ }
74
+ /**
75
+ * Implementation helper. @private
76
+ *
77
+ * @param {OfficeMathFormat} format The Math run format.
78
+ * @returns {boolean} True when a script or style is explicit.
79
+ */
80
+ function isScriptStyle(format) {
81
+ return format.isExplicit(K.Script) || format.isExplicit(K.Style);
82
+ }
83
+ /**
84
+ * Implementation helper. @private
85
+ *
86
+ * @param {number} rule The spacing rule.
87
+ * @param {string} path The element path.
88
+ * @returns {string} The decimal text.
89
+ */
90
+ function ruleText(rule, path) {
91
+ return rule >= 0 && rule <= 4 && Number.isInteger(rule) ? String(rule) : invalid('Illegal spacing rule ' + String(rule), path, 'enum-value');
92
+ }
93
+ /**
94
+ * Implementation helper. @private
95
+ *
96
+ * @param {WriteContext} ctx The write context.
97
+ * @param {OpenXmlChild[]} out The children being built.
98
+ * @param {OfficeMathEquationArray | OfficeMathMatrix} fn The function.
99
+ * @param {string} path The element path.
100
+ * @returns {void}
101
+ */
102
+ function rowSpacing(ctx, out, fn, path) {
103
+ writeValue(ctx, out, fn, K.RowSpacingRule, 'rSpRule', function () { return ruleText(fn.rowSpacingRule, path + '.rSpRule'); });
104
+ }
105
+ /**
106
+ * Implementation helper. @private
107
+ *
108
+ * @param {WriteContext} ctx The write context.
109
+ * @param {OpenXmlChild[]} out The children being built.
110
+ * @param {OfficeMathEquationArray} fn The equation array.
111
+ * @returns {void}
112
+ */
113
+ function equationArray(ctx, out, fn) {
114
+ writeValue(ctx, out, fn, K.EqArrAlign, 'baseJc', function () { return token(VERTICAL, fn.verticalAlignment, 'eqArrPr.baseJc', 'ST_YAlign'); });
115
+ writeFlags(ctx, out, fn, [[K.MaxDist, 'maxDist', fn.expandEquationContainer], [K.ObjDist, 'objDist', fn.expandEquationContent]]);
116
+ rowSpacing(ctx, out, fn, 'eqArrPr');
117
+ writeValue(ctx, out, fn, K.RowSpacing, 'rSp', function () { return unsigned(fn.rowSpacing, 'eqArrPr.rSp'); });
118
+ }
119
+ /**
120
+ * Implementation helper. @private
121
+ *
122
+ * @param {WriteContext} ctx The write context.
123
+ * @param {OpenXmlChild[]} out The children being built.
124
+ * @param {OfficeMathMatrix} fn The matrix.
125
+ * @returns {void}
126
+ */
127
+ function matrix(ctx, out, fn) {
128
+ writeValue(ctx, out, fn, K.MatrixAlign, 'baseJc', function () { return token(VERTICAL, fn.verticalAlignment, 'mPr.baseJc', 'ST_YAlign'); });
129
+ writeFlags(ctx, out, fn, [[K.PlaceHoldHidden, 'plcHide', fn.hidePlaceholder]]);
130
+ rowSpacing(ctx, out, fn, 'mPr');
131
+ writeValue(ctx, out, fn, K.ColumnGapRule, 'cGpRule', function () { return ruleText(fn.columnGapRule, 'mPr.cGpRule'); });
132
+ writeValue(ctx, out, fn, K.RowSpacing, 'rSp', function () { return unsigned(fn.rowSpacing, 'mPr.rSp'); });
133
+ writeValue(ctx, out, fn, K.ColumnSpacing, 'cSp', function () { return unsigned(fn.columnSpacing, 'mPr.cSp'); });
134
+ writeValue(ctx, out, fn, K.ColumnGap, 'cGp', function () { return unsigned(fn.columnGap, 'mPr.cGp'); });
135
+ var columns = matrixColumns(ctx, fn);
136
+ if (columns !== undefined) {
137
+ out.push(columns);
138
+ }
139
+ }
140
+ /**
141
+ * Writes `m:mcs`, grouping consecutive columns with the same explicit alignment. Omitted when no column
142
+ * alignment is explicit, because the parser recreates default columns from the row cells. @private
143
+ *
144
+ * @param {WriteContext} ctx The write context.
145
+ * @param {OfficeMathMatrix} fn The matrix.
146
+ * @returns {OpenXmlChild | undefined} The element, if needed.
147
+ */
148
+ function matrixColumns(ctx, fn) {
149
+ var columns = fn.columns.toArray();
150
+ if (!columns.some(function (c) { return c.isExplicit(K.MatrixAlign); })) {
151
+ return undefined;
152
+ }
153
+ var groups = [];
154
+ columns.forEach(function (column) {
155
+ var last = groups[groups.length - 1];
156
+ var same = last !== undefined && last.column.isExplicit(K.MatrixAlign) === column.isExplicit(K.MatrixAlign)
157
+ && (!column.isExplicit(K.MatrixAlign) || last.column.horizontalAlignment === column.horizontalAlignment);
158
+ if (same && last !== undefined && last.count < 255) {
159
+ last.count++;
160
+ }
161
+ else {
162
+ groups.push({ column: column, count: 1 });
163
+ }
164
+ });
165
+ return mathElement(ctx, 'mcs', groups.map(function (g) {
166
+ var kids = [valueElement(ctx, 'count', String(g.count))];
167
+ writeValue(ctx, kids, g.column, K.MatrixAlign, 'mcJc', function () { return token(HORIZONTAL, g.column.horizontalAlignment, 'mcPr.mcJc', 'ST_XAlign'); });
168
+ return mathElement(ctx, 'mc', [mathElement(ctx, 'mcPr', kids)]);
169
+ }));
170
+ }
171
+ /**
172
+ * Implementation helper. @private
173
+ *
174
+ * @param {WriteContext} ctx The write context.
175
+ * @param {OpenXmlChild[]} out The children being built.
176
+ * @param {OfficeMathFunctionBase} fn The function.
177
+ * @returns {void}
178
+ */
179
+ function multiProperties(ctx, out, fn) {
180
+ if (fn.type === MathFunctionType.Delimiter) {
181
+ var d_1 = fn;
182
+ writeValue(ctx, out, d_1, K.BegChar, 'begChr', function () { return d_1.beginCharacter; });
183
+ writeValue(ctx, out, d_1, K.SeparatorChar, 'sepChr', function () { return d_1.separator; });
184
+ writeValue(ctx, out, d_1, K.EndChar, 'endChr', function () { return d_1.endCharacter; });
185
+ writeFlags(ctx, out, d_1, [[K.Grow, 'grow', d_1.isGrow]]);
186
+ writeValue(ctx, out, d_1, K.Shape, 'shp', function () { return token(SHAPE, d_1.delimiterShape, 'dPr.shp', 'ST_Shp'); });
187
+ }
188
+ else if (fn.type === MathFunctionType.EquationArray) {
189
+ equationArray(ctx, out, fn);
190
+ }
191
+ else if (fn.type === MathFunctionType.Fraction) {
192
+ var f_1 = fn;
193
+ writeValue(ctx, out, f_1, K.FractionType, 'type', function () { return token(FRACTION, f_1.fractionType, 'fPr.type', 'ST_FType'); });
194
+ }
195
+ else if (fn.type === MathFunctionType.Matrix) {
196
+ matrix(ctx, out, fn);
197
+ }
198
+ else if (fn.type === MathFunctionType.NArray) {
199
+ var n_1 = fn;
200
+ writeValue(ctx, out, n_1, K.NAryChar, 'chr', function () { return n_1.nArrayCharacter; });
201
+ writeValue(ctx, out, n_1, K.SubSupLimit, 'limLoc', function () { return n_1.subSuperscriptLimit ? 'subSup' : 'undOvr'; });
202
+ writeFlags(ctx, out, n_1, [[K.HasGrow, 'grow', n_1.hasGrow], [K.HideSubscript, 'subHide', n_1.hideLowerLimit],
203
+ [K.HideSuperscript, 'supHide', n_1.hideUpperLimit]]);
204
+ }
205
+ else if (fn.type === MathFunctionType.RightSubSuperscript) {
206
+ writeFlags(ctx, out, fn, [[K.SkipAlign, 'alnScr', fn.isSkipAlign]]);
207
+ }
208
+ }
209
+ /**
210
+ * Implementation helper. @private
211
+ *
212
+ * @param {WriteContext} ctx The write context.
213
+ * @param {OpenXmlChild[]} out The children being built.
214
+ * @param {OfficeMathFunctionBase} fn The function.
215
+ * @returns {void}
216
+ */
217
+ function basicProperties(ctx, out, fn) {
218
+ if (fn.type === MathFunctionType.Accent) {
219
+ writeValue(ctx, out, fn, K.AccentChar, 'chr', function () { return fn.accentCharacter; });
220
+ }
221
+ else if (fn.type === MathFunctionType.Bar) {
222
+ writeValue(ctx, out, fn, K.BarTop, 'pos', function () { return fn.barTop ? 'top' : 'bot'; });
223
+ }
224
+ else if (fn.type === MathFunctionType.BorderBox) {
225
+ var b = fn;
226
+ writeFlags(ctx, out, b, [[K.HideTop, 'hideTop', b.hideTop], [K.HideBottom, 'hideBot', b.hideBottom],
227
+ [K.HideLeft, 'hideLeft', b.hideLeft], [K.HideRight, 'hideRight', b.hideRight],
228
+ [K.StrikeHorizontal, 'strikeH', b.strikeHorizontal], [K.StrikeVertical, 'strikeV', b.strikeVertical],
229
+ [K.StrikeBLTR, 'strikeBLTR', b.strikeDiagonalUp], [K.StrikeTLBR, 'strikeTLBR', b.strikeDiagonalDown]]);
230
+ }
231
+ else if (fn.type === MathFunctionType.Box) {
232
+ var b = fn;
233
+ writeFlags(ctx, out, b, [[K.OperatorEmulator, 'opEmu', b.operatorEmulator], [K.NoBreak, 'noBreak', b.noBreak],
234
+ [K.EnableDifferential, 'diff', b.enableDifferential]]);
235
+ if (b.break !== undefined) {
236
+ out.push(writeBreak(ctx, b.break));
237
+ }
238
+ writeFlags(ctx, out, b, [[K.BoxAlign, 'aln', b.alignment]]);
239
+ }
240
+ else if (fn.type === MathFunctionType.GroupCharacter) {
241
+ var g_1 = fn;
242
+ writeValue(ctx, out, g_1, K.GroupChar, 'chr', function () { return g_1.groupCharacter; });
243
+ writeValue(ctx, out, g_1, K.HasCharTop, 'pos', function () { return g_1.hasCharacterTop ? 'top' : 'bot'; });
244
+ writeValue(ctx, out, g_1, K.HasAlignTop, 'vertJc', function () { return g_1.hasAlignTop ? 'top' : 'bot'; });
245
+ }
246
+ else if (fn.type === MathFunctionType.Phantom) {
247
+ var p = fn;
248
+ writeFlags(ctx, out, p, [[K.Show, 'show', p.show], [K.ZeroWidth, 'zeroWid', p.zeroWidth],
249
+ [K.ZeroAscent, 'zeroAsc', p.zeroAscent], [K.ZeroDescent, 'zeroDesc', p.zeroDescent], [K.Transparent, 'transp', p.transparent]]);
250
+ }
251
+ else if (fn.type === MathFunctionType.Radical) {
252
+ writeFlags(ctx, out, fn, [[K.HideDegree, 'degHide', fn.hideDegree]]);
253
+ }
254
+ }
255
+ /**
256
+ * Writes the explicit properties of a function in schema order, excluding `m:ctrlPr`. @private
257
+ *
258
+ * @param {WriteContext} ctx The write context.
259
+ * @param {OfficeMathFunctionBase} fn The function.
260
+ * @returns {OpenXmlChild[]} The property children.
261
+ */
262
+ export function functionProperties(ctx, fn) {
263
+ var out = [];
264
+ basicProperties(ctx, out, fn);
265
+ multiProperties(ctx, out, fn);
266
+ return out;
267
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Office Math model → OMML serializer.
3
+ *
4
+ * Source: ECMA-376-1 §22.1 (shared-math.xsd). Writes only explicitly set properties, in schema order, and
5
+ * re-emits {@link OfficeMathUnknownElement} content verbatim. Throws {@link MathmlValidationError} for
6
+ * structures the schema forbids (for example a delimiter without an `m:e`).
7
+ */
8
+ import { OpenXmlElement } from '../openxml';
9
+ import { OfficeMathParagraph } from '../office-math/math-paragraph';
10
+ import { SerializeOfficeMathOptions } from './omml-writer';
11
+ export { SerializeOfficeMathOptions } from './omml-writer';
12
+ /**
13
+ * Serializes an {@link OfficeMathParagraph} to `m:oMathPara`, or to a bare `m:oMath` for an inline
14
+ * paragraph (one equation, no explicit justification). A paragraph that holds a verbatim-preserved malformed
15
+ * root re-emits that root unchanged.
16
+ *
17
+ * @param {OfficeMathParagraph} paragraph The model.
18
+ * @param {SerializeOfficeMathOptions} options Optional serializer options.
19
+ * @returns {OpenXmlElement} The `m:oMathPara` or `m:oMath` element.
20
+ * @throws {MathmlValidationError} When the model violates the schema.
21
+ * @public
22
+ */
23
+ export declare function serializeOfficeMathParagraph(paragraph: OfficeMathParagraph, options?: SerializeOfficeMathOptions): OpenXmlElement;
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Office Math model → OMML serializer.
3
+ *
4
+ * Source: ECMA-376-1 §22.1 (shared-math.xsd). Writes only explicitly set properties, in schema order, and
5
+ * re-emits {@link OfficeMathUnknownElement} content verbatim. Throws {@link MathmlValidationError} for
6
+ * structures the schema forbids (for example a delimiter without an `m:e`).
7
+ */
8
+ import { MATH_NAMESPACE, XML_NAMESPACE } from '../constants';
9
+ import { createText } from '../openxml';
10
+ import { MathFunctionType, MathLimitType, MathScriptType } from '../office-math/enums';
11
+ import { BasicRun, BasicRunFormat } from '../office-math/basic';
12
+ import { K } from '../office-math/keys';
13
+ import { OfficeMathUnknownElement } from '../office-math/unknown-element';
14
+ import { invalid, mathElement, resolveMathPrefix, token, valueElement } from './omml-writer';
15
+ import { functionProperties, PROPERTY_ELEMENT, runFormatChildren } from './office-math-properties-writer';
16
+ var JUSTIFICATION = ['centerGroup', 'center', 'left', 'right'];
17
+ /**
18
+ * Implementation helper. @private
19
+ *
20
+ * @param {OfficeMathFunctionBase} fn The function.
21
+ * @returns {Layout | undefined} The layout, or undefined for list/matrix/run/unknown functions.
22
+ */
23
+ function layoutOf(fn) {
24
+ switch (fn.type) {
25
+ case MathFunctionType.Accent: return { name: 'acc', pr: 'accPr', args: [['e', fn.equation]] };
26
+ case MathFunctionType.Bar: return { name: 'bar', pr: 'barPr', args: [['e', fn.equation]] };
27
+ case MathFunctionType.BorderBox: return { name: 'borderBox', pr: 'borderBoxPr', args: [['e', fn.equation]] };
28
+ case MathFunctionType.Box: return { name: 'box', pr: 'boxPr', args: [['e', fn.equation]] };
29
+ case MathFunctionType.GroupCharacter:
30
+ return { name: 'groupChr', pr: 'groupChrPr', args: [['e', fn.equation]] };
31
+ case MathFunctionType.Phantom: return { name: 'phant', pr: 'phantPr', args: [['e', fn.equation]] };
32
+ case MathFunctionType.Radical:
33
+ return { name: 'rad', pr: 'radPr', args: [['deg', fn.degree], ['e', fn.equation]] };
34
+ case MathFunctionType.Fraction:
35
+ return { name: 'f', pr: 'fPr', args: [['num', fn.numerator], ['den', fn.denominator]] };
36
+ case MathFunctionType.Function:
37
+ return { name: 'func', pr: 'funcPr', args: [['fName', fn.functionName], ['e', fn.equation]] };
38
+ default: return layoutOfScripts(fn);
39
+ }
40
+ }
41
+ /**
42
+ * Implementation helper. @private
43
+ *
44
+ * @param {OfficeMathFunctionBase} fn The function.
45
+ * @returns {Layout | undefined} The layout, or undefined when `fn` is not a limit, n-ary or script function.
46
+ */
47
+ function layoutOfScripts(fn) {
48
+ if (fn.type === MathFunctionType.Limit) {
49
+ var l = fn;
50
+ var upper = l.limitType === MathLimitType.UpperLimit;
51
+ return { name: upper ? 'limUpp' : 'limLow', pr: upper ? 'limUppPr' : 'limLowPr', args: [['e', l.equation], ['lim', l.limit]] };
52
+ }
53
+ if (fn.type === MathFunctionType.NArray) {
54
+ var n = fn;
55
+ return { name: 'nary', pr: 'naryPr', args: [['sub', n.subscript], ['sup', n.superscript], ['e', n.equation]] };
56
+ }
57
+ if (fn.type === MathFunctionType.SubSuperscript) {
58
+ var s = fn;
59
+ var sub = s.scriptType === MathScriptType.Subscript;
60
+ return { name: sub ? 'sSub' : 'sSup', pr: sub ? 'sSubPr' : 'sSupPr', args: [['e', s.equation], [sub ? 'sub' : 'sup', s.script]] };
61
+ }
62
+ if (fn.type === MathFunctionType.RightSubSuperscript) {
63
+ var r = fn;
64
+ return { name: 'sSubSup', pr: 'sSubSupPr', args: [['e', r.equation], ['sub', r.subscript], ['sup', r.superscript]] };
65
+ }
66
+ if (fn.type === MathFunctionType.LeftSubSuperscript) {
67
+ var p = fn;
68
+ return { name: 'sPre', pr: 'sPrePr', args: [['sub', p.subscript], ['sup', p.superscript], ['e', p.equation]] };
69
+ }
70
+ return undefined;
71
+ }
72
+ /**
73
+ * Builds the `m:ctrlPr` of a function from its control properties. @private
74
+ *
75
+ * @param {WriteContext} ctx The write context.
76
+ * @param {OfficeMathFunctionBase} fn The function.
77
+ * @returns {OpenXmlChild[]} Zero or one element.
78
+ */
79
+ function controlProperties(ctx, fn) {
80
+ if (!fn.hasControlProperties) {
81
+ return [];
82
+ }
83
+ if (ctx.adapter !== undefined) {
84
+ var kids = ctx.adapter.serializeControlProperties(fn.controlProperties);
85
+ return kids.length > 0 ? [mathElement(ctx, 'ctrlPr', kids)] : [];
86
+ }
87
+ var format = fn.controlProperties instanceof BasicRunFormat ? fn.controlProperties : undefined;
88
+ return format !== undefined && format.preservedXml !== undefined ? [format.preservedXml] : [];
89
+ }
90
+ /**
91
+ * Writes the property container (`m:*Pr`) of a function, or nothing when it would be empty. @private
92
+ *
93
+ * @param {WriteContext} ctx The write context.
94
+ * @param {OfficeMathFunctionBase} fn The function.
95
+ * @param {string} prName The container element name.
96
+ * @returns {OpenXmlChild[]} Zero or one element.
97
+ */
98
+ function propertyContainer(ctx, fn, prName) {
99
+ var kids = functionProperties(ctx, fn).concat(controlProperties(ctx, fn));
100
+ return kids.length > 0 ? [mathElement(ctx, prName, kids)] : [];
101
+ }
102
+ /**
103
+ * Writes an argument element (`m:e`, `m:num`, …). @private
104
+ *
105
+ * @param {WriteContext} ctx The write context.
106
+ * @param {string} name The element name.
107
+ * @param {OfficeMath} math The argument content.
108
+ * @param {string} path The element path for diagnostics.
109
+ * @returns {OpenXmlElement} The element.
110
+ */
111
+ function writeArgument(ctx, name, math, path) {
112
+ var kids = [];
113
+ if (math.isExplicit(K.ArgumentSize)) {
114
+ kids.push(mathElement(ctx, 'argPr', [valueElement(ctx, 'argSz', String(math.argumentSize))]));
115
+ }
116
+ writeContent(ctx, math, path).forEach(function (e) { return kids.push(e); });
117
+ if (math.preservedControlProperties !== undefined) {
118
+ kids.push(math.preservedControlProperties);
119
+ }
120
+ return mathElement(ctx, name, kids);
121
+ }
122
+ /**
123
+ * Implementation helper. @private
124
+ *
125
+ * @param {WriteContext} ctx The write context.
126
+ * @param {OfficeMath} math The equation.
127
+ * @param {string} path The element path for diagnostics.
128
+ * @returns {OpenXmlElement[]} The serialized functions.
129
+ */
130
+ function writeContent(ctx, math, path) {
131
+ return math.functions.toArray().map(function (fn, i) { return writeFunction(ctx, fn, path + '[' + String(i) + ']'); });
132
+ }
133
+ /**
134
+ * Implementation helper. @private
135
+ *
136
+ * @param {WriteContext} ctx The write context.
137
+ * @param {string} name The element name (`d` or `eqArr`).
138
+ * @param {OfficeMathDelimiter | OfficeMathEquationArray} fn The function.
139
+ * @param {string} prName The property container name.
140
+ * @param {string} path The element path for diagnostics.
141
+ * @returns {OpenXmlElement} The element.
142
+ */
143
+ function writeList(ctx, name, fn, prName, path) {
144
+ if (fn.equations.count < 1) {
145
+ invalid('m:' + name + ' requires at least one m:e', path, 'required-child');
146
+ }
147
+ var kids = propertyContainer(ctx, fn, prName);
148
+ fn.equations.toArray().forEach(function (e, i) { return kids.push(writeArgument(ctx, 'e', e, path + '.e[' + String(i) + ']')); });
149
+ return mathElement(ctx, name, kids);
150
+ }
151
+ /**
152
+ * Implementation helper. @private
153
+ *
154
+ * @param {WriteContext} ctx The write context.
155
+ * @param {OfficeMathMatrix} fn The matrix.
156
+ * @param {string} path The element path for diagnostics.
157
+ * @returns {OpenXmlElement} The element.
158
+ */
159
+ function writeMatrix(ctx, fn, path) {
160
+ if (fn.rows.count < 1) {
161
+ invalid('m:m requires at least one m:mr', path, 'required-child');
162
+ }
163
+ var kids = propertyContainer(ctx, fn, PROPERTY_ELEMENT[MathFunctionType.Matrix]);
164
+ fn.rowItems.forEach(function (row, r) {
165
+ var cells = row.arguments.toArray()
166
+ .map(function (cell, c) { return writeArgument(ctx, 'e', cell, path + '.mr[' + String(r) + '].e[' + String(c) + ']'); });
167
+ kids.push(mathElement(ctx, 'mr', cells));
168
+ });
169
+ return mathElement(ctx, 'm', kids);
170
+ }
171
+ /**
172
+ * Implementation helper. @private
173
+ *
174
+ * @param {string} value The text.
175
+ * @returns {boolean} True when leading or trailing whitespace needs `xml:space="preserve"`.
176
+ */
177
+ function needsPreserve(value) {
178
+ return value.length === 0 || /^\s|\s$/.test(value);
179
+ }
180
+ /**
181
+ * Implementation helper. @private
182
+ *
183
+ * @param {WriteContext} ctx The write context.
184
+ * @param {BasicRunPart} part The run part.
185
+ * @returns {OpenXmlChild} The serialized part.
186
+ */
187
+ function writeRunPart(ctx, part) {
188
+ if (part.kind === 'xml') {
189
+ return part.element;
190
+ }
191
+ var space = part.space !== undefined ? part.space : needsPreserve(part.value) ? 'preserve' : undefined;
192
+ var attrs = space === undefined ? [] : [{ namespaceUri: XML_NAMESPACE, localName: 'space', prefix: 'xml', value: space }];
193
+ return mathElement(ctx, 't', [createText(part.value)], attrs);
194
+ }
195
+ /**
196
+ * Writes `m:r`: `m:rPr`, then the host/WordprocessingML run content. @private
197
+ *
198
+ * @param {WriteContext} ctx The write context.
199
+ * @param {OfficeMathRunElement} run The run element.
200
+ * @returns {OpenXmlElement} The element.
201
+ */
202
+ function writeRun(ctx, run) {
203
+ var kids = [];
204
+ var format = runFormatChildren(ctx, run.mathFormat);
205
+ if (format.length > 0) {
206
+ kids.push(mathElement(ctx, 'rPr', format));
207
+ }
208
+ if (ctx.adapter !== undefined) {
209
+ ctx.adapter.serializeMathRun(run).forEach(function (e) { return kids.push(e); });
210
+ }
211
+ else if (run.item instanceof BasicRun) {
212
+ if (run.item.runProperties !== undefined) {
213
+ kids.push(run.item.runProperties);
214
+ }
215
+ run.item.parts.forEach(function (part) { return kids.push(writeRunPart(ctx, part)); });
216
+ }
217
+ return mathElement(ctx, 'r', kids);
218
+ }
219
+ /**
220
+ * Serializes one function. @private
221
+ *
222
+ * @param {WriteContext} ctx The write context.
223
+ * @param {OfficeMathFunctionBase} fn The function.
224
+ * @param {string} path The element path for diagnostics.
225
+ * @returns {OpenXmlElement} The element.
226
+ */
227
+ function writeFunction(ctx, fn, path) {
228
+ if (fn instanceof OfficeMathUnknownElement) {
229
+ return fn.preservedXml;
230
+ }
231
+ if (fn.type === MathFunctionType.RunElement) {
232
+ return writeRun(ctx, fn);
233
+ }
234
+ if (fn.type === MathFunctionType.Delimiter) {
235
+ return writeList(ctx, 'd', fn, 'dPr', path);
236
+ }
237
+ if (fn.type === MathFunctionType.EquationArray) {
238
+ return writeList(ctx, 'eqArr', fn, 'eqArrPr', path);
239
+ }
240
+ if (fn.type === MathFunctionType.Matrix) {
241
+ return writeMatrix(ctx, fn, path);
242
+ }
243
+ var layout = layoutOf(fn);
244
+ if (layout === undefined) {
245
+ return invalid('Unsupported Math function type ' + String(fn.type), path, 'enum-value');
246
+ }
247
+ var kids = propertyContainer(ctx, fn, layout.pr);
248
+ layout.args.forEach(function (a) { return kids.push(writeArgument(ctx, a[0], a[1], path + '.' + a[0])); });
249
+ return mathElement(ctx, layout.name, kids);
250
+ }
251
+ /**
252
+ * Implementation helper. @private
253
+ *
254
+ * @param {OfficeMathParagraph} paragraph The paragraph.
255
+ * @returns {OpenXmlElement | undefined} A malformed root that the parser preserved verbatim, if that is all the paragraph holds.
256
+ */
257
+ function preservedRoot(paragraph) {
258
+ if (paragraph.maths.count !== 1 || paragraph.maths.getItem(0).functions.count !== 1) {
259
+ return undefined;
260
+ }
261
+ var only = paragraph.maths.getItem(0).functions.getItem(0);
262
+ var isRoot = only instanceof OfficeMathUnknownElement && only.preservedXml.namespaceUri === MATH_NAMESPACE
263
+ && (only.localName === 'oMath' || only.localName === 'oMathPara');
264
+ return isRoot ? only.preservedXml : undefined;
265
+ }
266
+ /**
267
+ * Serializes an {@link OfficeMathParagraph} to `m:oMathPara`, or to a bare `m:oMath` for an inline
268
+ * paragraph (one equation, no explicit justification). A paragraph that holds a verbatim-preserved malformed
269
+ * root re-emits that root unchanged.
270
+ *
271
+ * @param {OfficeMathParagraph} paragraph The model.
272
+ * @param {SerializeOfficeMathOptions} options Optional serializer options.
273
+ * @returns {OpenXmlElement} The `m:oMathPara` or `m:oMath` element.
274
+ * @throws {MathmlValidationError} When the model violates the schema.
275
+ * @public
276
+ */
277
+ export function serializeOfficeMathParagraph(paragraph, options) {
278
+ var adapter = paragraph.adapter;
279
+ var ctx = { prefix: resolveMathPrefix(options), adapter: adapter };
280
+ var preserved = preservedRoot(paragraph);
281
+ if (preserved !== undefined) {
282
+ return preserved;
283
+ }
284
+ var display = options !== undefined && options.display !== undefined
285
+ ? options.display : paragraph.hasExplicitJustification || paragraph.maths.count !== 1;
286
+ var maths = paragraph.maths.toArray();
287
+ if (maths.length < 1) {
288
+ invalid('An equation paragraph requires at least one m:oMath', 'oMathPara', 'required-child');
289
+ }
290
+ if (!display) {
291
+ if (maths.length > 1) {
292
+ invalid('A bare m:oMath holds exactly one equation', 'oMath', 'child-order');
293
+ }
294
+ return mathElement(ctx, 'oMath', writeContent(ctx, maths[0], 'oMath'));
295
+ }
296
+ var kids = [];
297
+ if (paragraph.hasExplicitJustification) {
298
+ var jc = token(JUSTIFICATION, paragraph.justification, 'oMathParaPr.jc', 'ST_Jc');
299
+ kids.push(mathElement(ctx, 'oMathParaPr', [valueElement(ctx, 'jc', jc)]));
300
+ }
301
+ maths.forEach(function (m, i) {
302
+ var path = 'oMathPara.oMath[' + String(i) + ']';
303
+ kids.push(mathElement(ctx, 'oMath', writeContent(ctx, m, path)));
304
+ });
305
+ return mathElement(ctx, 'oMathPara', kids);
306
+ }