@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.
- package/dist/ej2-office-common.umd.min.js +2 -2
- package/dist/ej2-office-common.umd.min.js.map +1 -1
- package/dist/es6/ej2-office-common.es2015.js +5421 -6017
- package/dist/es6/ej2-office-common.es2015.js.map +1 -1
- package/dist/es6/ej2-office-common.es5.js +6270 -7203
- package/dist/es6/ej2-office-common.es5.js.map +1 -1
- package/dist/global/ej2-office-common.min.js +2 -2
- package/dist/global/ej2-office-common.min.js.map +1 -1
- package/dist/global/index.d.ts +1 -1
- package/office-common.js +4 -0
- package/package.json +11 -7
- package/src/index.d.ts +3 -17
- package/src/index.js +3 -18
- package/src/office-common/features/index.d.ts +6 -0
- package/src/office-common/features/index.js +6 -0
- package/src/office-common/features/mathml/index.d.ts +25 -0
- package/src/office-common/features/mathml/index.js +22 -0
- package/src/office-common/features/mathml/latex/latex-generator.d.ts +8 -0
- package/src/office-common/features/mathml/latex/latex-generator.js +357 -0
- package/src/office-common/features/mathml/latex/latex-parser.d.ts +87 -0
- package/src/office-common/features/mathml/latex/latex-parser.js +1206 -0
- package/src/office-common/features/mathml/latex/latex-symbols.d.ts +13 -0
- package/src/office-common/features/mathml/latex/latex-symbols.js +681 -0
- package/src/office-common/features/mathml/math-settings.d.ts +54 -0
- package/src/office-common/features/mathml/math-settings.js +174 -0
- package/src/office-common/features/mathml/office-math/adapter.d.ts +59 -0
- package/src/office-common/features/mathml/office-math/adapter.js +6 -0
- package/src/office-common/features/mathml/office-math/basic.d.ts +91 -0
- package/src/office-common/features/mathml/office-math/basic.js +93 -0
- package/src/office-common/features/mathml/office-math/break.d.ts +30 -0
- package/src/office-common/features/mathml/office-math/break.js +75 -0
- package/src/office-common/features/mathml/office-math/collection.d.ts +104 -0
- package/src/office-common/features/mathml/office-math/collection.js +170 -0
- package/src/office-common/features/mathml/office-math/entity.d.ts +12 -0
- package/src/office-common/features/mathml/office-math/entity.js +3 -0
- package/src/office-common/features/mathml/office-math/enums.d.ts +97 -0
- package/src/office-common/features/mathml/office-math/enums.js +108 -0
- package/src/office-common/features/mathml/office-math/format.d.ts +28 -0
- package/src/office-common/features/mathml/office-math/format.js +90 -0
- package/src/office-common/features/mathml/office-math/function-base.d.ts +27 -0
- package/src/office-common/features/mathml/office-math/function-base.js +69 -0
- package/src/office-common/features/mathml/office-math/function-collection.d.ts +29 -0
- package/src/office-common/features/mathml/office-math/function-collection.js +76 -0
- package/src/office-common/features/mathml/office-math/functions-basic.d.ts +118 -0
- package/src/office-common/features/mathml/office-math/functions-basic.js +331 -0
- package/src/office-common/features/mathml/office-math/functions-multi.d.ts +156 -0
- package/src/office-common/features/mathml/office-math/functions-multi.js +407 -0
- package/src/office-common/features/mathml/office-math/index.d.ts +27 -0
- package/src/office-common/features/mathml/office-math/index.js +25 -0
- package/src/office-common/features/mathml/office-math/keys.d.ts +6 -0
- package/src/office-common/features/mathml/office-math/keys.js +20 -0
- package/src/office-common/features/mathml/office-math/math-clone.d.ts +20 -0
- package/src/office-common/features/mathml/office-math/math-clone.js +203 -0
- package/src/office-common/features/mathml/office-math/math-collection.d.ts +19 -0
- package/src/office-common/features/mathml/office-math/math-collection.js +41 -0
- package/src/office-common/features/mathml/office-math/math-equality.d.ts +21 -0
- package/src/office-common/features/mathml/office-math/math-equality.js +115 -0
- package/src/office-common/features/mathml/office-math/math-paragraph.d.ts +58 -0
- package/src/office-common/features/mathml/office-math/math-paragraph.js +126 -0
- package/src/office-common/features/mathml/office-math/math-traversal.d.ts +23 -0
- package/src/office-common/features/mathml/office-math/math-traversal.js +95 -0
- package/src/office-common/features/mathml/office-math/matrix-collections.d.ts +54 -0
- package/src/office-common/features/mathml/office-math/matrix-collections.js +113 -0
- package/src/office-common/features/mathml/office-math/matrix-column.d.ts +43 -0
- package/src/office-common/features/mathml/office-math/matrix-column.js +96 -0
- package/src/office-common/features/mathml/office-math/matrix-row.d.ts +38 -0
- package/src/office-common/features/mathml/office-math/matrix-row.js +71 -0
- package/src/office-common/features/mathml/office-math/matrix.d.ts +62 -0
- package/src/office-common/features/mathml/office-math/matrix.js +158 -0
- package/src/office-common/features/mathml/office-math/office-math.d.ts +55 -0
- package/src/office-common/features/mathml/office-math/office-math.js +116 -0
- package/src/office-common/features/mathml/office-math/owner-holder.d.ts +42 -0
- package/src/office-common/features/mathml/office-math/owner-holder.js +87 -0
- package/src/office-common/features/mathml/office-math/property-store.d.ts +66 -0
- package/src/office-common/features/mathml/office-math/property-store.js +99 -0
- package/src/office-common/features/mathml/office-math/run-element.d.ts +31 -0
- package/src/office-common/features/mathml/office-math/run-element.js +97 -0
- package/src/office-common/features/mathml/office-math/unknown-element.d.ts +37 -0
- package/src/office-common/features/mathml/office-math/unknown-element.js +62 -0
- package/src/office-common/features/mathml/office-math/xml-equal.d.ts +13 -0
- package/src/office-common/features/mathml/office-math/xml-equal.js +24 -0
- package/src/office-common/features/mathml/parse/office-math-parser.d.ts +24 -0
- package/src/office-common/features/mathml/parse/office-math-parser.js +396 -0
- package/src/office-common/features/mathml/parse/office-math-properties.d.ts +165 -0
- package/src/office-common/features/mathml/parse/office-math-properties.js +432 -0
- package/src/office-common/features/mathml/parse/parse-options.d.ts +22 -0
- package/src/office-common/features/mathml/parse/parse-options.js +3 -0
- package/src/office-common/features/mathml/serialize/office-math-properties-writer.d.ts +38 -0
- package/src/office-common/features/mathml/serialize/office-math-properties-writer.js +267 -0
- package/src/office-common/features/mathml/serialize/office-math-serializer.d.ts +23 -0
- package/src/office-common/features/mathml/serialize/office-math-serializer.js +306 -0
- package/src/office-common/features/mathml/serialize/omml-writer.d.ts +123 -0
- package/src/office-common/features/mathml/serialize/omml-writer.js +135 -0
- package/src/office-common/index.d.ts +10 -0
- package/src/office-common/index.js +10 -0
- package/.eslintrc.json +0 -263
- package/.prettierrc.json +0 -5
- package/api-extractor.json +0 -35
- package/core.js +0 -4
- package/encryption.js +0 -4
- package/features.js +0 -4
- package/global.json +0 -6
- package/nuget.config +0 -7
- package/src/all.d.ts +0 -41
- package/src/all.js +0 -38
- package/src/features/index.d.ts +0 -11
- package/src/features/index.js +0 -11
- package/src/features/mathml/index.d.ts +0 -30
- package/src/features/mathml/index.js +0 -22
- package/src/features/mathml/math-factory.d.ts +0 -26
- package/src/features/mathml/math-factory.js +0 -568
- package/src/features/mathml/model/controls.d.ts +0 -896
- package/src/features/mathml/model/controls.js +0 -1541
- package/src/features/mathml/model/math-element.d.ts +0 -173
- package/src/features/mathml/model/math-element.js +0 -315
- package/src/features/mathml/model/roots.d.ts +0 -82
- package/src/features/mathml/model/roots.js +0 -177
- package/src/features/mathml/parse/math-parser.d.ts +0 -43
- package/src/features/mathml/parse/math-parser.js +0 -636
- package/src/features/mathml/serialize/math-serializer.d.ts +0 -34
- package/src/features/mathml/serialize/math-serializer.js +0 -749
- package/tsconfig.build.json +0 -13
- package/tsconfig.harness.json +0 -32
- package/tslint.json +0 -111
- /package/src/{core → office-common/core}/index.d.ts +0 -0
- /package/src/{core → office-common/core}/index.js +0 -0
- /package/src/{core → office-common/core}/xml/index.d.ts +0 -0
- /package/src/{core → office-common/core}/xml/index.js +0 -0
- /package/src/{core → office-common/core}/xml/model.d.ts +0 -0
- /package/src/{core → office-common/core}/xml/model.js +0 -0
- /package/src/{encryption → office-common/encryption}/agile-constants.d.ts +0 -0
- /package/src/{encryption → office-common/encryption}/agile-constants.js +0 -0
- /package/src/{encryption → office-common/encryption}/agile-encryption-info.d.ts +0 -0
- /package/src/{encryption → office-common/encryption}/agile-encryption-info.js +0 -0
- /package/src/{encryption → office-common/encryption}/agile-password.d.ts +0 -0
- /package/src/{encryption → office-common/encryption}/agile-password.js +0 -0
- /package/src/{encryption → office-common/encryption}/cfb-reader.d.ts +0 -0
- /package/src/{encryption → office-common/encryption}/cfb-reader.js +0 -0
- /package/src/{encryption → office-common/encryption}/crypto-primitives.d.ts +0 -0
- /package/src/{encryption → office-common/encryption}/crypto-primitives.js +0 -0
- /package/src/{encryption → office-common/encryption}/decrypt-encrypted-package.d.ts +0 -0
- /package/src/{encryption → office-common/encryption}/decrypt-encrypted-package.js +0 -0
- /package/src/{encryption → office-common/encryption}/encryption-info-xml.d.ts +0 -0
- /package/src/{encryption → office-common/encryption}/encryption-info-xml.js +0 -0
- /package/src/{encryption → office-common/encryption}/errors.d.ts +0 -0
- /package/src/{encryption → office-common/encryption}/errors.js +0 -0
- /package/src/{encryption → office-common/encryption}/index.d.ts +0 -0
- /package/src/{encryption → office-common/encryption}/index.js +0 -0
- /package/src/{features → office-common/features}/diagrams/constants.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/constants.js +0 -0
- /package/src/{features → office-common/features}/diagrams/diagram-data-model.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/diagram-data-model.js +0 -0
- /package/src/{features → office-common/features}/diagrams/diagram-parsers.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/diagram-parsers.js +0 -0
- /package/src/{features → office-common/features}/diagrams/diagram-serializers.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/diagram-serializers.js +0 -0
- /package/src/{features → office-common/features}/diagrams/diagram-views.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/diagram-views.js +0 -0
- /package/src/{features → office-common/features}/diagrams/element-tree.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/element-tree.js +0 -0
- /package/src/{features → office-common/features}/diagrams/errors.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/errors.js +0 -0
- /package/src/{features → office-common/features}/diagrams/index.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/index.js +0 -0
- /package/src/{features → office-common/features}/diagrams/smart-art-catalog.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/smart-art-catalog.js +0 -0
- /package/src/{features → office-common/features}/diagrams/smart-art-diagram.d.ts +0 -0
- /package/src/{features → office-common/features}/diagrams/smart-art-diagram.js +0 -0
- /package/src/{features → office-common/features}/ink/constants.d.ts +0 -0
- /package/src/{features → office-common/features}/ink/constants.js +0 -0
- /package/src/{features → office-common/features}/ink/index.d.ts +0 -0
- /package/src/{features → office-common/features}/ink/index.js +0 -0
- /package/src/{features → office-common/features}/ink/ink-effects.d.ts +0 -0
- /package/src/{features → office-common/features}/ink/ink-effects.js +0 -0
- /package/src/{features → office-common/features}/ink/ink-model.d.ts +0 -0
- /package/src/{features → office-common/features}/ink/ink-model.js +0 -0
- /package/src/{features → office-common/features}/ink/ink-parser.d.ts +0 -0
- /package/src/{features → office-common/features}/ink/ink-parser.js +0 -0
- /package/src/{features → office-common/features}/ink/ink-serializer.d.ts +0 -0
- /package/src/{features → office-common/features}/ink/ink-serializer.js +0 -0
- /package/src/{features → office-common/features}/ink/ink-units.d.ts +0 -0
- /package/src/{features → office-common/features}/ink/ink-units.js +0 -0
- /package/src/{features → office-common/features}/ink/ink-xml.d.ts +0 -0
- /package/src/{features → office-common/features}/ink/ink-xml.js +0 -0
- /package/src/{features → office-common/features}/ink/trace-codec.d.ts +0 -0
- /package/src/{features → office-common/features}/ink/trace-codec.js +0 -0
- /package/src/{features → office-common/features}/mathml/constants.d.ts +0 -0
- /package/src/{features → office-common/features}/mathml/constants.js +0 -0
- /package/src/{features → office-common/features}/mathml/errors.d.ts +0 -0
- /package/src/{features → office-common/features}/mathml/errors.js +0 -0
- /package/src/{features → office-common/features}/mathml/model/enums.d.ts +0 -0
- /package/src/{features → office-common/features}/mathml/model/enums.js +0 -0
- /package/src/{features → office-common/features}/mathml/openxml.d.ts +0 -0
- /package/src/{features → office-common/features}/mathml/openxml.js +0 -0
- /package/src/{features → office-common/features}/smart-art/diagram-xml.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/diagram-xml.js +0 -0
- /package/src/{features → office-common/features}/smart-art/errors.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/errors.js +0 -0
- /package/src/{features → office-common/features}/smart-art/index.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/index.js +0 -0
- /package/src/{features → office-common/features}/smart-art/minimal-samples.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/minimal-samples.js +0 -0
- /package/src/{features → office-common/features}/smart-art/mutators.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/mutators.js +0 -0
- /package/src/{features → office-common/features}/smart-art/namespaces.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/namespaces.js +0 -0
- /package/src/{features → office-common/features}/smart-art/package-graph.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/package-graph.js +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-colors.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-colors.js +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-data.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-data.js +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-layout.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-layout.js +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-rel-ids.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-rel-ids.js +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-style.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/parse-style.js +0 -0
- /package/src/{features → office-common/features}/smart-art/point-text.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/point-text.js +0 -0
- /package/src/{features → office-common/features}/smart-art/register.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/register.js +0 -0
- /package/src/{features → office-common/features}/smart-art/serialize.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/serialize.js +0 -0
- /package/src/{features → office-common/features}/smart-art/types.d.ts +0 -0
- /package/src/{features → office-common/features}/smart-art/types.js +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run element (`m:r`) holding a document-native run.
|
|
3
|
+
*/
|
|
4
|
+
var __extends = (this && this.__extends) || (function () {
|
|
5
|
+
var extendStatics = function (d, b) {
|
|
6
|
+
extendStatics = Object.setPrototypeOf ||
|
|
7
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
8
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
9
|
+
return extendStatics(d, b);
|
|
10
|
+
};
|
|
11
|
+
return function (d, b) {
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
import { MathFunctionType } from './enums';
|
|
18
|
+
import { OfficeMathFunctionBase } from './function-base';
|
|
19
|
+
import { OfficeMathFormat } from './format';
|
|
20
|
+
import { BasicRun } from './basic';
|
|
21
|
+
/**
|
|
22
|
+
* Math run: native document run plus Math format (`m:rPr`).
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
var OfficeMathRunElement = /** @class */ (function (_super) {
|
|
27
|
+
__extends(OfficeMathRunElement, _super);
|
|
28
|
+
function OfficeMathRunElement(owner) {
|
|
29
|
+
var _this = _super.call(this, owner) || this;
|
|
30
|
+
_this.type = MathFunctionType.RunElement;
|
|
31
|
+
_this._mathFormat = new OfficeMathFormat(_this);
|
|
32
|
+
return _this;
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(OfficeMathRunElement.prototype, "item", {
|
|
35
|
+
/** The native document run. */
|
|
36
|
+
get: function () { return this._item; },
|
|
37
|
+
set: function (value) {
|
|
38
|
+
this._item = value;
|
|
39
|
+
if (value !== undefined) {
|
|
40
|
+
value.ownerMathRunElement = this;
|
|
41
|
+
}
|
|
42
|
+
this.notifyMutated();
|
|
43
|
+
},
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(OfficeMathRunElement.prototype, "text", {
|
|
48
|
+
/**
|
|
49
|
+
* Text of the run (`m:t`). Uses the host adapter when the run is attached to a paragraph
|
|
50
|
+
* that has one, otherwise a standalone run. Empty when no run exists yet.
|
|
51
|
+
*
|
|
52
|
+
* @returns {string} The run text.
|
|
53
|
+
*/
|
|
54
|
+
get: function () {
|
|
55
|
+
var adapter = this.findAdapter();
|
|
56
|
+
if (this._item === undefined) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
return adapter !== undefined ? adapter.getRunText(this._item) : this._item.text;
|
|
60
|
+
},
|
|
61
|
+
set: function (value) {
|
|
62
|
+
var adapter = this.findAdapter();
|
|
63
|
+
if (this._item === undefined) {
|
|
64
|
+
this.item = adapter !== undefined ? adapter.createRun(this) : new BasicRun();
|
|
65
|
+
}
|
|
66
|
+
if (adapter !== undefined) {
|
|
67
|
+
adapter.setRunText(this._item, value);
|
|
68
|
+
this.notifyMutated();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this._item.text = value;
|
|
72
|
+
this.notifyMutated();
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true
|
|
77
|
+
});
|
|
78
|
+
OfficeMathRunElement.prototype.findAdapter = function () {
|
|
79
|
+
var entity = this.ownerMathEntity;
|
|
80
|
+
while (entity !== undefined) {
|
|
81
|
+
var candidate = entity;
|
|
82
|
+
if (candidate.adapter !== undefined) {
|
|
83
|
+
return candidate.adapter;
|
|
84
|
+
}
|
|
85
|
+
entity = entity.ownerMathEntity;
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
};
|
|
89
|
+
Object.defineProperty(OfficeMathRunElement.prototype, "mathFormat", {
|
|
90
|
+
/** Math run format (`m:rPr`). */
|
|
91
|
+
get: function () { return this._mathFormat; },
|
|
92
|
+
enumerable: true,
|
|
93
|
+
configurable: true
|
|
94
|
+
});
|
|
95
|
+
return OfficeMathRunElement;
|
|
96
|
+
}(OfficeMathFunctionBase));
|
|
97
|
+
export { OfficeMathRunElement };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preservation of unrecognized Math elements.
|
|
3
|
+
*/
|
|
4
|
+
import { MathFunctionType } from './enums';
|
|
5
|
+
import { OfficeMathFunctionBase } from './function-base';
|
|
6
|
+
import { OfficeMathEntity } from './entity';
|
|
7
|
+
import { OpenXmlElement } from '../openxml';
|
|
8
|
+
/**
|
|
9
|
+
* An unrecognized `m:*` element kept verbatim so a load and save does not lose content.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare class OfficeMathUnknownElement extends OfficeMathFunctionBase {
|
|
14
|
+
readonly type: MathFunctionType;
|
|
15
|
+
private readonly _localName;
|
|
16
|
+
private readonly _xml;
|
|
17
|
+
/**
|
|
18
|
+
* Creates the preserved element.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} localName Local name of the element.
|
|
21
|
+
* @param {OpenXmlElement} xml The original element tree.
|
|
22
|
+
* @param {OfficeMathEntity} owner Optional owner.
|
|
23
|
+
*/
|
|
24
|
+
constructor(localName: string, xml: OpenXmlElement, owner?: OfficeMathEntity);
|
|
25
|
+
/**
|
|
26
|
+
* Local name of the preserved element.
|
|
27
|
+
*
|
|
28
|
+
* @returns {string} The local name.
|
|
29
|
+
*/
|
|
30
|
+
readonly localName: string;
|
|
31
|
+
/**
|
|
32
|
+
* The preserved element tree, re-serialized verbatim.
|
|
33
|
+
*
|
|
34
|
+
* @returns {OpenXmlElement} The original element tree.
|
|
35
|
+
*/
|
|
36
|
+
readonly preservedXml: OpenXmlElement;
|
|
37
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preservation of unrecognized Math elements.
|
|
3
|
+
*/
|
|
4
|
+
var __extends = (this && this.__extends) || (function () {
|
|
5
|
+
var extendStatics = function (d, b) {
|
|
6
|
+
extendStatics = Object.setPrototypeOf ||
|
|
7
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
8
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
9
|
+
return extendStatics(d, b);
|
|
10
|
+
};
|
|
11
|
+
return function (d, b) {
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
import { MathFunctionType } from './enums';
|
|
18
|
+
import { OfficeMathFunctionBase } from './function-base';
|
|
19
|
+
/**
|
|
20
|
+
* An unrecognized `m:*` element kept verbatim so a load and save does not lose content.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
var OfficeMathUnknownElement = /** @class */ (function (_super) {
|
|
25
|
+
__extends(OfficeMathUnknownElement, _super);
|
|
26
|
+
/**
|
|
27
|
+
* Creates the preserved element.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} localName Local name of the element.
|
|
30
|
+
* @param {OpenXmlElement} xml The original element tree.
|
|
31
|
+
* @param {OfficeMathEntity} owner Optional owner.
|
|
32
|
+
*/
|
|
33
|
+
function OfficeMathUnknownElement(localName, xml, owner) {
|
|
34
|
+
var _this = _super.call(this, owner) || this;
|
|
35
|
+
_this.type = MathFunctionType.Unknown;
|
|
36
|
+
_this._localName = localName;
|
|
37
|
+
_this._xml = xml;
|
|
38
|
+
return _this;
|
|
39
|
+
}
|
|
40
|
+
Object.defineProperty(OfficeMathUnknownElement.prototype, "localName", {
|
|
41
|
+
/**
|
|
42
|
+
* Local name of the preserved element.
|
|
43
|
+
*
|
|
44
|
+
* @returns {string} The local name.
|
|
45
|
+
*/
|
|
46
|
+
get: function () { return this._localName; },
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(OfficeMathUnknownElement.prototype, "preservedXml", {
|
|
51
|
+
/**
|
|
52
|
+
* The preserved element tree, re-serialized verbatim.
|
|
53
|
+
*
|
|
54
|
+
* @returns {OpenXmlElement} The original element tree.
|
|
55
|
+
*/
|
|
56
|
+
get: function () { return this._xml; },
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true
|
|
59
|
+
});
|
|
60
|
+
return OfficeMathUnknownElement;
|
|
61
|
+
}(OfficeMathFunctionBase));
|
|
62
|
+
export { OfficeMathUnknownElement };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural equality of preserved XML trees.
|
|
3
|
+
*/
|
|
4
|
+
import { OpenXmlChild } from '../openxml';
|
|
5
|
+
/**
|
|
6
|
+
* Compares two XML nodes structurally (names, attributes, children, text).
|
|
7
|
+
*
|
|
8
|
+
* @param {OpenXmlChild} a First node.
|
|
9
|
+
* @param {OpenXmlChild} b Second node.
|
|
10
|
+
* @returns {boolean} True when both nodes are structurally identical.
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
export declare function xmlEqual(a: OpenXmlChild, b: OpenXmlChild): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural equality of preserved XML trees.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Compares two XML nodes structurally (names, attributes, children, text).
|
|
6
|
+
*
|
|
7
|
+
* @param {OpenXmlChild} a First node.
|
|
8
|
+
* @param {OpenXmlChild} b Second node.
|
|
9
|
+
* @returns {boolean} True when both nodes are structurally identical.
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export function xmlEqual(a, b) {
|
|
13
|
+
if (a.kind === 'text' || b.kind === 'text') {
|
|
14
|
+
return a.kind === b.kind && a.value === b.value;
|
|
15
|
+
}
|
|
16
|
+
var x = a;
|
|
17
|
+
var y = b;
|
|
18
|
+
return x.namespaceUri === y.namespaceUri && x.localName === y.localName
|
|
19
|
+
&& x.attributes.length === y.attributes.length
|
|
20
|
+
&& x.attributes.every(function (at, i) { return at.localName === y.attributes[i].localName
|
|
21
|
+
&& at.namespaceUri === y.attributes[i].namespaceUri && at.value === y.attributes[i].value; })
|
|
22
|
+
&& x.children.length === y.children.length
|
|
23
|
+
&& x.children.every(function (c, i) { return xmlEqual(c, y.children[i]); });
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tolerant OMML → Office Math model parser.
|
|
3
|
+
*
|
|
4
|
+
* Source: ECMA-376-1 §22.1 (shared-math.xsd). Never throws on load: unknown elements and
|
|
5
|
+
* structures missing required children are kept verbatim as {@link OfficeMathUnknownElement}.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenXmlElement } from '../openxml';
|
|
8
|
+
import { MathDocumentAdapter } from '../office-math/adapter';
|
|
9
|
+
import { OfficeMathParagraph } from '../office-math/math-paragraph';
|
|
10
|
+
import { ParseMathOptions } from './parse-options';
|
|
11
|
+
/**
|
|
12
|
+
* Parses an `m:oMathPara` (or a bare `m:oMath`) into an {@link OfficeMathParagraph}.
|
|
13
|
+
*
|
|
14
|
+
* Tolerant: never throws. A bare `m:oMath` is wrapped in a paragraph that has no explicit justification.
|
|
15
|
+
* A malformed `m:oMathPara` (foreign children, text, or no `m:oMath`) is preserved verbatim as a single
|
|
16
|
+
* `OfficeMathUnknownElement` and reported through `onDiagnostic`.
|
|
17
|
+
*
|
|
18
|
+
* @param {OpenXmlElement} root The `m:oMathPara` or `m:oMath` element.
|
|
19
|
+
* @param {MathDocumentAdapter} adapter Optional host adapter supplying native runs and formats.
|
|
20
|
+
* @param {ParseMathOptions} options Optional parser options.
|
|
21
|
+
* @returns {OfficeMathParagraph} The populated model.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseOfficeMathParagraph(root: OpenXmlElement, adapter?: MathDocumentAdapter, options?: ParseMathOptions): OfficeMathParagraph;
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tolerant OMML → Office Math model parser.
|
|
3
|
+
*
|
|
4
|
+
* Source: ECMA-376-1 §22.1 (shared-math.xsd). Never throws on load: unknown elements and
|
|
5
|
+
* structures missing required children are kept verbatim as {@link OfficeMathUnknownElement}.
|
|
6
|
+
*/
|
|
7
|
+
import { MATH_NAMESPACE, WML_TRANSITIONAL_NAMESPACE, XML_NAMESPACE } from '../constants';
|
|
8
|
+
import { attrValue, attrValueNs, childElements, textContent } from '../openxml';
|
|
9
|
+
import { MathFunctionType, MathJustification, MathLimitType, MathScriptType } from '../office-math/enums';
|
|
10
|
+
import { BasicRun, BasicRunFormat } from '../office-math/basic';
|
|
11
|
+
import { OfficeMathParagraph } from '../office-math/math-paragraph';
|
|
12
|
+
import { OfficeMathUnknownElement } from '../office-math/unknown-element';
|
|
13
|
+
import * as P from './office-math-properties';
|
|
14
|
+
/**
|
|
15
|
+
* Implementation helper. @private
|
|
16
|
+
*
|
|
17
|
+
* @param {MathFunctionType} type The function type.
|
|
18
|
+
* @param {string} pr The property element (`m:*Pr`), if present.
|
|
19
|
+
* @param {string[]} args The argument element names, in order.
|
|
20
|
+
* @param {Fill} [apply] Optional property applier.
|
|
21
|
+
* @returns {Shape} The result.
|
|
22
|
+
*/
|
|
23
|
+
function shape(type, pr, args, apply) {
|
|
24
|
+
return { type: type, pr: pr, args: args, apply: apply };
|
|
25
|
+
}
|
|
26
|
+
var SHAPES = {
|
|
27
|
+
acc: shape(MathFunctionType.Accent, 'accPr', ['e'], P.applyAccent),
|
|
28
|
+
bar: shape(MathFunctionType.Bar, 'barPr', ['e'], P.applyBar),
|
|
29
|
+
borderBox: shape(MathFunctionType.BorderBox, 'borderBoxPr', ['e'], P.applyBorderBox),
|
|
30
|
+
box: shape(MathFunctionType.Box, 'boxPr', ['e'], P.applyBox),
|
|
31
|
+
f: shape(MathFunctionType.Fraction, 'fPr', ['num', 'den'], P.applyFraction),
|
|
32
|
+
func: shape(MathFunctionType.Function, 'funcPr', ['fName', 'e']),
|
|
33
|
+
groupChr: shape(MathFunctionType.GroupCharacter, 'groupChrPr', ['e'], P.applyGroupCharacter),
|
|
34
|
+
limLow: shape(MathFunctionType.Limit, 'limLowPr', ['e', 'lim']),
|
|
35
|
+
limUpp: shape(MathFunctionType.Limit, 'limUppPr', ['e', 'lim']),
|
|
36
|
+
nary: shape(MathFunctionType.NArray, 'naryPr', ['sub', 'sup', 'e'], P.applyNArray),
|
|
37
|
+
phant: shape(MathFunctionType.Phantom, 'phantPr', ['e'], P.applyPhantom),
|
|
38
|
+
rad: shape(MathFunctionType.Radical, 'radPr', ['deg', 'e'], P.applyRadical),
|
|
39
|
+
sPre: shape(MathFunctionType.LeftSubSuperscript, 'sPrePr', ['sub', 'sup', 'e']),
|
|
40
|
+
sSub: shape(MathFunctionType.SubSuperscript, 'sSubPr', ['e', 'sub']),
|
|
41
|
+
sSubSup: shape(MathFunctionType.RightSubSuperscript, 'sSubSupPr', ['e', 'sub', 'sup'], P.applyRightScript),
|
|
42
|
+
sSup: shape(MathFunctionType.SubSuperscript, 'sSupPr', ['e', 'sup'])
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Implementation helper. @private
|
|
46
|
+
*
|
|
47
|
+
* @param {Context} ctx The parse context.
|
|
48
|
+
* @param {OpenXmlElement} xml The source element.
|
|
49
|
+
* @param {string} message The diagnostic message.
|
|
50
|
+
* @returns {void}
|
|
51
|
+
*/
|
|
52
|
+
function diagnose(ctx, xml, message) {
|
|
53
|
+
if (ctx.options !== undefined && ctx.options.onDiagnostic !== undefined) {
|
|
54
|
+
var diagnostic = { path: xml.localName, message: message, localName: xml.localName };
|
|
55
|
+
ctx.options.onDiagnostic(diagnostic);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Implementation helper. @private
|
|
60
|
+
*
|
|
61
|
+
* @param {OpenXmlElement} xml The source element.
|
|
62
|
+
* @param {OfficeMath} target The target to populate.
|
|
63
|
+
* @returns {void}
|
|
64
|
+
*/
|
|
65
|
+
function preserve(xml, target) {
|
|
66
|
+
target.functions.insert(target.functions.count, new OfficeMathUnknownElement(xml.localName, xml));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Implementation helper. @private
|
|
70
|
+
*
|
|
71
|
+
* @param {OpenXmlElement} ctrl The `m:ctrlPr` element.
|
|
72
|
+
* @param {OfficeMathFunctionBase} fn The function being populated.
|
|
73
|
+
* @param {Context} ctx The parse context.
|
|
74
|
+
* @returns {OfficeRunFormat} The result.
|
|
75
|
+
*/
|
|
76
|
+
function ctrlFormat(ctrl, fn, ctx) {
|
|
77
|
+
return ctx.adapter !== undefined ? ctx.adapter.parseControlProperties(ctrl, fn) : new BasicRunFormat(ctrl);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Implementation helper. @private
|
|
81
|
+
*
|
|
82
|
+
* @param {OfficeMath} target The target to populate.
|
|
83
|
+
* @param {OpenXmlElement | undefined} el The source element.
|
|
84
|
+
* @param {Context} ctx The parse context.
|
|
85
|
+
* @returns {void}
|
|
86
|
+
*/
|
|
87
|
+
function fillArgument(target, el, ctx) {
|
|
88
|
+
if (el === undefined) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
var ctrl = P.findMathChild(el, 'ctrlPr');
|
|
92
|
+
if (ctrl !== undefined) {
|
|
93
|
+
target.preservedControlProperties = ctrl;
|
|
94
|
+
}
|
|
95
|
+
var size = P.readArgumentSize(P.findMathChild(el, 'argPr'));
|
|
96
|
+
if (size !== undefined) {
|
|
97
|
+
target.argumentSize = Number(size);
|
|
98
|
+
}
|
|
99
|
+
fillElements(target, el, ctx);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Implementation helper. @private
|
|
103
|
+
*
|
|
104
|
+
* @param {OfficeMath} target The target to populate.
|
|
105
|
+
* @param {OpenXmlElement} parent The parent element.
|
|
106
|
+
* @param {Context} ctx The parse context.
|
|
107
|
+
* @returns {void}
|
|
108
|
+
*/
|
|
109
|
+
function fillElements(target, parent, ctx) {
|
|
110
|
+
childElements(parent).forEach(function (child) {
|
|
111
|
+
var isMath = child.namespaceUri === MATH_NAMESPACE;
|
|
112
|
+
if (isMath && (child.localName === 'argPr' || child.localName === 'ctrlPr')) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
parseFunction(child, target, ctx);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Implementation helper. @private
|
|
120
|
+
*
|
|
121
|
+
* @param {OpenXmlElement} el The source element.
|
|
122
|
+
* @param {OfficeMath} target The target to populate.
|
|
123
|
+
* @param {Context} ctx The parse context.
|
|
124
|
+
* @returns {void}
|
|
125
|
+
*/
|
|
126
|
+
function parseFunction(el, target, ctx) {
|
|
127
|
+
if (el.namespaceUri !== MATH_NAMESPACE) {
|
|
128
|
+
preserve(el, target);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (el.localName === 'r') {
|
|
132
|
+
parseRun(el, target, ctx);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (el.localName === 'd' || el.localName === 'eqArr') {
|
|
136
|
+
parseList(el, target, ctx);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (el.localName === 'm') {
|
|
140
|
+
parseMatrix(el, target, ctx);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
var spec = SHAPES.hasOwnProperty(el.localName) ? SHAPES[el.localName] : undefined;
|
|
144
|
+
var args = spec === undefined ? [] : spec.args.map(function (n) { return P.findMathChild(el, n); });
|
|
145
|
+
if (spec === undefined || args.some(function (a) { return a === undefined; })) {
|
|
146
|
+
if (spec !== undefined) {
|
|
147
|
+
diagnose(ctx, el, 'm:' + el.localName + ' is missing a required child');
|
|
148
|
+
}
|
|
149
|
+
preserve(el, target);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
var fn = target.functions.add(spec.type);
|
|
153
|
+
var pr = P.findMathChild(el, spec.pr);
|
|
154
|
+
applyCommon(fn, pr, ctx);
|
|
155
|
+
if (spec.apply !== undefined) {
|
|
156
|
+
spec.apply(fn, pr);
|
|
157
|
+
}
|
|
158
|
+
bind(el.localName, fn, args, ctx);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Implementation helper. @private
|
|
162
|
+
*
|
|
163
|
+
* @param {OfficeMathFunctionBase} fn The function being populated.
|
|
164
|
+
* @param {OpenXmlElement | undefined} pr The property element (`m:*Pr`), if present.
|
|
165
|
+
* @param {Context} ctx The parse context.
|
|
166
|
+
* @returns {void}
|
|
167
|
+
*/
|
|
168
|
+
function applyCommon(fn, pr, ctx) {
|
|
169
|
+
var ctrl = P.findMathChild(pr, 'ctrlPr');
|
|
170
|
+
if (ctrl !== undefined) {
|
|
171
|
+
fn.controlProperties = ctrlFormat(ctrl, fn, ctx);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Implementation helper. @private
|
|
176
|
+
*
|
|
177
|
+
* @param {string} name The local name of the child element.
|
|
178
|
+
* @param {OfficeMathFunctionBase} fn The function being populated.
|
|
179
|
+
* @param {OpenXmlElement[]} a First object.
|
|
180
|
+
* @param {Context} ctx The parse context.
|
|
181
|
+
* @returns {void}
|
|
182
|
+
*/
|
|
183
|
+
function bind(name, fn, a, ctx) {
|
|
184
|
+
var into = function (m, i) { return fillArgument(m, a[i], ctx); };
|
|
185
|
+
switch (fn.type) {
|
|
186
|
+
case MathFunctionType.Fraction:
|
|
187
|
+
into(fn.numerator, 0);
|
|
188
|
+
into(fn.denominator, 1);
|
|
189
|
+
break;
|
|
190
|
+
case MathFunctionType.Function:
|
|
191
|
+
into(fn.functionName, 0);
|
|
192
|
+
into(fn.equation, 1);
|
|
193
|
+
break;
|
|
194
|
+
case MathFunctionType.Limit:
|
|
195
|
+
fn.limitType = name === 'limUpp' ? MathLimitType.UpperLimit : MathLimitType.LowerLimit;
|
|
196
|
+
into(fn.equation, 0);
|
|
197
|
+
into(fn.limit, 1);
|
|
198
|
+
break;
|
|
199
|
+
case MathFunctionType.NArray:
|
|
200
|
+
into(fn.subscript, 0);
|
|
201
|
+
into(fn.superscript, 1);
|
|
202
|
+
into(fn.equation, 2);
|
|
203
|
+
break;
|
|
204
|
+
case MathFunctionType.Radical:
|
|
205
|
+
into(fn.degree, 0);
|
|
206
|
+
into(fn.equation, 1);
|
|
207
|
+
break;
|
|
208
|
+
case MathFunctionType.LeftSubSuperscript:
|
|
209
|
+
into(fn.subscript, 0);
|
|
210
|
+
into(fn.superscript, 1);
|
|
211
|
+
into(fn.equation, 2);
|
|
212
|
+
break;
|
|
213
|
+
case MathFunctionType.SubSuperscript:
|
|
214
|
+
fn.scriptType = name === 'sSub' ? MathScriptType.Subscript : MathScriptType.Superscript;
|
|
215
|
+
into(fn.equation, 0);
|
|
216
|
+
into(fn.script, 1);
|
|
217
|
+
break;
|
|
218
|
+
case MathFunctionType.RightSubSuperscript:
|
|
219
|
+
into(fn.equation, 0);
|
|
220
|
+
into(fn.subscript, 1);
|
|
221
|
+
into(fn.superscript, 2);
|
|
222
|
+
break;
|
|
223
|
+
default:
|
|
224
|
+
into(fn.equation, 0);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Implementation helper. @private
|
|
229
|
+
*
|
|
230
|
+
* @param {OpenXmlElement} el The source element.
|
|
231
|
+
* @param {OfficeMath} target The target to populate.
|
|
232
|
+
* @param {Context} ctx The parse context.
|
|
233
|
+
* @returns {void}
|
|
234
|
+
*/
|
|
235
|
+
function parseList(el, target, ctx) {
|
|
236
|
+
var items = P.findMathChildren(el, 'e');
|
|
237
|
+
if (items.length < 1) {
|
|
238
|
+
diagnose(ctx, el, 'm:' + el.localName + ' is missing a required m:e');
|
|
239
|
+
preserve(el, target);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
var isDelimiter = el.localName === 'd';
|
|
243
|
+
var fn = target.functions.add(isDelimiter ? MathFunctionType.Delimiter : MathFunctionType.EquationArray);
|
|
244
|
+
var pr = P.findMathChild(el, isDelimiter ? 'dPr' : 'eqArrPr');
|
|
245
|
+
applyCommon(fn, pr, ctx);
|
|
246
|
+
if (isDelimiter) {
|
|
247
|
+
P.applyDelimiter(fn, pr);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
P.applyEquationArray(fn, pr);
|
|
251
|
+
}
|
|
252
|
+
var equations = fn.equations;
|
|
253
|
+
items.forEach(function (item) { return fillArgument(equations.add(), item, ctx); });
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Implementation helper. @private
|
|
257
|
+
*
|
|
258
|
+
* @param {OpenXmlElement} el The source element.
|
|
259
|
+
* @param {OfficeMath} target The target to populate.
|
|
260
|
+
* @param {Context} ctx The parse context.
|
|
261
|
+
* @returns {void}
|
|
262
|
+
*/
|
|
263
|
+
function parseMatrix(el, target, ctx) {
|
|
264
|
+
var rows = P.findMathChildren(el, 'mr');
|
|
265
|
+
if (rows.length < 1) {
|
|
266
|
+
diagnose(ctx, el, 'm:m is missing a required m:mr');
|
|
267
|
+
preserve(el, target);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
var matrix = target.functions.add(MathFunctionType.Matrix);
|
|
271
|
+
var pr = P.findMathChild(el, 'mPr');
|
|
272
|
+
applyCommon(matrix, pr, ctx);
|
|
273
|
+
P.applyMatrix(matrix, pr);
|
|
274
|
+
var widest = rows.reduce(function (max, r) { return Math.max(max, P.findMathChildren(r, 'e').length); }, 0);
|
|
275
|
+
P.applyMatrixColumns(matrix, pr, widest);
|
|
276
|
+
rows.forEach(function (row) {
|
|
277
|
+
var created = matrix.rows.add();
|
|
278
|
+
P.findMathChildren(row, 'e').forEach(function (cell, i) { return fillArgument(created.arguments.getItem(i), cell, ctx); });
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Implementation helper. @private
|
|
283
|
+
*
|
|
284
|
+
* @param {OpenXmlElement} el The source element.
|
|
285
|
+
* @param {OfficeMath} target The target to populate.
|
|
286
|
+
* @param {Context} ctx The parse context.
|
|
287
|
+
* @returns {void}
|
|
288
|
+
*/
|
|
289
|
+
function parseRun(el, target, ctx) {
|
|
290
|
+
var run = target.functions.add(MathFunctionType.RunElement);
|
|
291
|
+
P.applyRunFormat(run.mathFormat, P.findMathChild(el, 'rPr'));
|
|
292
|
+
if (ctx.adapter !== undefined) {
|
|
293
|
+
ctx.adapter.parseMathRun(el, run);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
var item = new BasicRun();
|
|
297
|
+
childElements(el).forEach(function (child) {
|
|
298
|
+
if (child.namespaceUri === MATH_NAMESPACE && child.localName === 'rPr') {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (child.namespaceUri === WML_TRANSITIONAL_NAMESPACE && child.localName === 'rPr') {
|
|
302
|
+
item.runProperties = child;
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (child.namespaceUri === MATH_NAMESPACE && child.localName === 't') {
|
|
306
|
+
var space = attrValueNs(child, XML_NAMESPACE, 'space');
|
|
307
|
+
item.parts.push(space === undefined ? { kind: 'text', value: textContent(child) }
|
|
308
|
+
: { kind: 'text', value: textContent(child), space: space });
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
item.parts.push({ kind: 'xml', element: child });
|
|
312
|
+
});
|
|
313
|
+
run.item = item;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Implementation helper. @private
|
|
317
|
+
*
|
|
318
|
+
* @param {OfficeMathParagraph} paragraph The paragraph being populated.
|
|
319
|
+
* @param {OpenXmlElement} oMath The `m:oMath` element.
|
|
320
|
+
* @param {Context} ctx The parse context.
|
|
321
|
+
* @returns {void}
|
|
322
|
+
*/
|
|
323
|
+
function fillRoot(paragraph, oMath, ctx) {
|
|
324
|
+
fillElements(paragraph.maths.add(), oMath, ctx);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Parses an `m:oMathPara` (or a bare `m:oMath`) into an {@link OfficeMathParagraph}.
|
|
328
|
+
*
|
|
329
|
+
* Tolerant: never throws. A bare `m:oMath` is wrapped in a paragraph that has no explicit justification.
|
|
330
|
+
* A malformed `m:oMathPara` (foreign children, text, or no `m:oMath`) is preserved verbatim as a single
|
|
331
|
+
* `OfficeMathUnknownElement` and reported through `onDiagnostic`.
|
|
332
|
+
*
|
|
333
|
+
* @param {OpenXmlElement} root The `m:oMathPara` or `m:oMath` element.
|
|
334
|
+
* @param {MathDocumentAdapter} adapter Optional host adapter supplying native runs and formats.
|
|
335
|
+
* @param {ParseMathOptions} options Optional parser options.
|
|
336
|
+
* @returns {OfficeMathParagraph} The populated model.
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
export function parseOfficeMathParagraph(root, adapter, options) {
|
|
340
|
+
var paragraph = new OfficeMathParagraph(adapter);
|
|
341
|
+
var ctx = { adapter: adapter, options: options };
|
|
342
|
+
paragraph.suspendMutations(function () {
|
|
343
|
+
if (!isWellFormedRoot(root)) {
|
|
344
|
+
diagnose(ctx, root, 'm:' + root.localName + ' is not a well-formed m:oMath or m:oMathPara; preserved verbatim');
|
|
345
|
+
preserve(root, paragraph.maths.add());
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (root.localName === 'oMath') {
|
|
349
|
+
fillRoot(paragraph, root, ctx);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
var jc = attrValueOf(P.findMathChild(P.findMathChild(root, 'oMathParaPr'), 'jc'));
|
|
353
|
+
if (jc !== undefined && Object.prototype.hasOwnProperty.call(JUSTIFICATION, jc)) {
|
|
354
|
+
paragraph.justification = JUSTIFICATION[jc];
|
|
355
|
+
}
|
|
356
|
+
P.findMathChildren(root, 'oMath').forEach(function (m) { return fillRoot(paragraph, m, ctx); });
|
|
357
|
+
});
|
|
358
|
+
return paragraph;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* A root is well formed when it is `m:oMath`, or an `m:oMathPara` whose children are an optional
|
|
362
|
+
* `m:oMathParaPr` followed by at least one `m:oMath` and nothing else.
|
|
363
|
+
*
|
|
364
|
+
* @param {OpenXmlElement} root The candidate root element.
|
|
365
|
+
* @returns {boolean} True when the root can be modelled without losing content.
|
|
366
|
+
*/
|
|
367
|
+
function isWellFormedRoot(root) {
|
|
368
|
+
if (root.namespaceUri !== MATH_NAMESPACE) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
if (root.localName === 'oMath') {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
if (root.localName !== 'oMathPara') {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
var children = childElements(root).slice();
|
|
378
|
+
var nonMath = children.filter(function (c) { return c.namespaceUri !== MATH_NAMESPACE; });
|
|
379
|
+
var others = children.filter(function (c) { return c.namespaceUri === MATH_NAMESPACE
|
|
380
|
+
&& c.localName !== 'oMath' && c.localName !== 'oMathParaPr'; });
|
|
381
|
+
var hasText = root.children.some(function (c) { return c.kind === 'text' && (c.value || '').trim() !== ''; });
|
|
382
|
+
return nonMath.length === 0 && others.length === 0 && !hasText && P.findMathChildren(root, 'oMath').length > 0;
|
|
383
|
+
}
|
|
384
|
+
var JUSTIFICATION = {
|
|
385
|
+
left: MathJustification.Left, right: MathJustification.Right,
|
|
386
|
+
center: MathJustification.Center, centerGroup: MathJustification.CenterGroup
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* Implementation helper. @private
|
|
390
|
+
*
|
|
391
|
+
* @param {OpenXmlElement | undefined} el The source element.
|
|
392
|
+
* @returns {string | undefined} The result.
|
|
393
|
+
*/
|
|
394
|
+
function attrValueOf(el) {
|
|
395
|
+
return el === undefined ? undefined : attrValue(el, 'val');
|
|
396
|
+
}
|