@bnsights/bbsf-utilities 1.0.36 → 1.0.38
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/README.md +4 -0
- package/bnsights-bbsf-utilities-1.0.38.tgz +0 -0
- package/bnsights-bbsf-utilities.d.ts +4 -0
- package/bnsights-bbsf-utilities.metadata.json +1 -0
- package/bundles/bnsights-bbsf-utilities.umd.js +4782 -0
- package/bundles/bnsights-bbsf-utilities.umd.js.map +1 -0
- package/esm2015/bnsights-bbsf-utilities.js +5 -0
- package/esm2015/lib/bbsf-utilities.module.js +54 -0
- package/esm2015/lib/shared/authentication/auth.service.js +204 -0
- package/esm2015/lib/shared/config/environment.js +12 -0
- package/esm2015/lib/shared/config/word/constants.js +105 -0
- package/esm2015/lib/shared/config/word/docx-document.js +351 -0
- package/esm2015/lib/shared/config/word/helpers/index.js +4 -0
- package/esm2015/lib/shared/config/word/helpers/render-document-file.js +278 -0
- package/esm2015/lib/shared/config/word/helpers/xml-builder.js +1765 -0
- package/esm2015/lib/shared/config/word/html-to-docx.js +195 -0
- package/esm2015/lib/shared/config/word/index.js +55 -0
- package/esm2015/lib/shared/config/word/namespaces.js +37 -0
- package/esm2015/lib/shared/config/word/schemas/content-types.js +26 -0
- package/esm2015/lib/shared/config/word/schemas/core.js +29 -0
- package/esm2015/lib/shared/config/word/schemas/document-rels.js +16 -0
- package/esm2015/lib/shared/config/word/schemas/document.template.js +109 -0
- package/esm2015/lib/shared/config/word/schemas/font-table.js +40 -0
- package/esm2015/lib/shared/config/word/schemas/generic-rels.js +11 -0
- package/esm2015/lib/shared/config/word/schemas/index.js +13 -0
- package/esm2015/lib/shared/config/word/schemas/numbering.js +19 -0
- package/esm2015/lib/shared/config/word/schemas/rels.js +11 -0
- package/esm2015/lib/shared/config/word/schemas/settings.js +13 -0
- package/esm2015/lib/shared/config/word/schemas/styles.js +149 -0
- package/esm2015/lib/shared/config/word/schemas/theme.js +200 -0
- package/esm2015/lib/shared/config/word/schemas/web-settings.js +9 -0
- package/esm2015/lib/shared/config/word/utils/color-conversion.js +60 -0
- package/esm2015/lib/shared/config/word/utils/list.js +51 -0
- package/esm2015/lib/shared/config/word/utils/unit-conversion.js +30 -0
- package/esm2015/lib/shared/config/word/utils/url.js +9 -0
- package/esm2015/lib/shared/config/word/utils/vnode.js +3 -0
- package/esm2015/lib/shared/config/word/word-work/templates/documentTemplate.js +54 -0
- package/esm2015/lib/shared/config/word/word-work/templates/index.js +4 -0
- package/esm2015/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.js +22 -0
- package/esm2015/lib/shared/config/word/word-work/templates/mhtPartTemplate.js +10 -0
- package/esm2015/lib/shared/config/word/word-work/utils.js +26 -0
- package/esm2015/lib/shared/models/AreaModel.js +3 -0
- package/esm2015/lib/shared/models/ErrorModel.js +3 -0
- package/esm2015/lib/shared/models/RequestOptionsModel.js +11 -0
- package/esm2015/lib/shared/models/UserModel.js +3 -0
- package/esm2015/lib/shared/models/WordDocumentModel.js +8 -0
- package/esm2015/lib/shared/services/AppearanceConfiguration.service.js +37 -0
- package/esm2015/lib/shared/services/configuration.service.js +26 -0
- package/esm2015/lib/shared/services/controlvalidation.service.js +175 -0
- package/esm2015/lib/shared/services/environment.service.js +48 -0
- package/esm2015/lib/shared/services/masterlayout.service.js +89 -0
- package/esm2015/lib/shared/services/requesthandler.service.js +206 -0
- package/esm2015/lib/shared/services/stylesbundle.service.js +56 -0
- package/esm2015/lib/shared/services/translate.service.js +13 -0
- package/esm2015/lib/shared/services/translationresolver.service.js +20 -0
- package/esm2015/lib/shared/services/utility.service.js +96 -0
- package/esm2015/lib/shared/services/word-document.service.js +39 -0
- package/esm2015/public-api.js +20 -0
- package/fesm2015/bnsights-bbsf-utilities.js +4606 -0
- package/fesm2015/bnsights-bbsf-utilities.js.map +1 -0
- package/lib/bbsf-utilities.module.d.ts +6 -0
- package/lib/shared/authentication/auth.service.d.ts +47 -0
- package/lib/shared/config/environment.d.ts +1 -0
- package/lib/shared/config/word/constants.d.ts +124 -0
- package/lib/shared/config/word/docx-document.d.ts +73 -0
- package/lib/shared/config/word/helpers/index.d.ts +1 -0
- package/lib/shared/config/word/helpers/render-document-file.d.ts +4 -0
- package/lib/shared/config/word/helpers/xml-builder.d.ts +14 -0
- package/lib/shared/config/word/html-to-docx.d.ts +1 -0
- package/lib/shared/config/word/index.d.ts +1 -0
- package/lib/shared/config/word/namespaces.d.ts +36 -0
- package/lib/shared/config/word/schemas/content-types.d.ts +1 -0
- package/lib/shared/config/word/schemas/core.d.ts +1 -0
- package/lib/shared/config/word/schemas/document-rels.d.ts +1 -0
- package/lib/shared/config/word/schemas/document.template.d.ts +4 -0
- package/lib/shared/config/word/schemas/font-table.d.ts +1 -0
- package/lib/shared/config/word/schemas/generic-rels.d.ts +1 -0
- package/lib/shared/config/word/schemas/index.d.ts +12 -0
- package/lib/shared/config/word/schemas/numbering.d.ts +1 -0
- package/lib/shared/config/word/schemas/rels.d.ts +1 -0
- package/lib/shared/config/word/schemas/settings.d.ts +1 -0
- package/lib/shared/config/word/schemas/styles.d.ts +1 -0
- package/lib/shared/config/word/schemas/theme.d.ts +1 -0
- package/lib/shared/config/word/schemas/web-settings.d.ts +1 -0
- package/lib/shared/config/word/utils/color-conversion.d.ts +7 -0
- package/lib/shared/config/word/utils/list.d.ts +6 -0
- package/lib/shared/config/word/utils/unit-conversion.d.ts +29 -0
- package/lib/shared/config/word/utils/url.d.ts +1 -0
- package/lib/shared/config/word/utils/vnode.d.ts +1 -0
- package/lib/shared/config/word/word-work/templates/documentTemplate.d.ts +12 -0
- package/lib/shared/config/word/word-work/templates/index.d.ts +3 -0
- package/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.d.ts +1 -0
- package/lib/shared/config/word/word-work/templates/mhtPartTemplate.d.ts +1 -0
- package/lib/shared/config/word/word-work/utils.d.ts +1 -0
- package/lib/shared/models/AreaModel.d.ts +4 -0
- package/{src/lib/shared/models/ErrorModel.ts → lib/shared/models/ErrorModel.d.ts} +2 -5
- package/lib/shared/models/RequestOptionsModel.d.ts +11 -0
- package/lib/shared/models/UserModel.d.ts +6 -0
- package/lib/shared/models/WordDocumentModel.d.ts +16 -0
- package/lib/shared/services/AppearanceConfiguration.service.d.ts +11 -0
- package/lib/shared/services/configuration.service.d.ts +7 -0
- package/lib/shared/services/controlvalidation.service.d.ts +20 -0
- package/lib/shared/services/environment.service.d.ts +13 -0
- package/lib/shared/services/masterlayout.service.d.ts +24 -0
- package/lib/shared/services/requesthandler.service.d.ts +32 -0
- package/lib/shared/services/stylesbundle.service.d.ts +9 -0
- package/lib/shared/services/translate.service.d.ts +3 -0
- package/lib/shared/services/translationresolver.service.d.ts +8 -0
- package/lib/shared/services/utility.service.d.ts +21 -0
- package/lib/shared/services/word-document.service.d.ts +5 -0
- package/package.json +30 -20
- package/public-api.d.ts +16 -0
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -10
- package/src/lib/bbsf-utilities.module.ts +0 -52
- package/src/lib/shared/authentication/auth.service.ts +0 -242
- package/src/lib/shared/config/environment.ts +0 -16
- package/src/lib/shared/config/word/constants.js +0 -133
- package/src/lib/shared/config/word/docx-document.js +0 -482
- package/src/lib/shared/config/word/helpers/index.js +0 -3
- package/src/lib/shared/config/word/helpers/render-document-file.js +0 -334
- package/src/lib/shared/config/word/helpers/xml-builder.js +0 -2165
- package/src/lib/shared/config/word/html-to-docx.js +0 -259
- package/src/lib/shared/config/word/index.js +0 -63
- package/src/lib/shared/config/word/namespaces.js +0 -40
- package/src/lib/shared/config/word/schemas/content-types.js +0 -26
- package/src/lib/shared/config/word/schemas/core.js +0 -44
- package/src/lib/shared/config/word/schemas/document-rels.js +0 -17
- package/src/lib/shared/config/word/schemas/document.template.js +0 -119
- package/src/lib/shared/config/word/schemas/font-table.js +0 -41
- package/src/lib/shared/config/word/schemas/generic-rels.js +0 -11
- package/src/lib/shared/config/word/schemas/index.js +0 -12
- package/src/lib/shared/config/word/schemas/numbering.js +0 -18
- package/src/lib/shared/config/word/schemas/rels.js +0 -12
- package/src/lib/shared/config/word/schemas/settings.js +0 -14
- package/src/lib/shared/config/word/schemas/styles.js +0 -152
- package/src/lib/shared/config/word/schemas/theme.js +0 -199
- package/src/lib/shared/config/word/schemas/web-settings.js +0 -10
- package/src/lib/shared/config/word/utils/color-conversion.js +0 -60
- package/src/lib/shared/config/word/utils/list.js +0 -55
- package/src/lib/shared/config/word/utils/unit-conversion.js +0 -53
- package/src/lib/shared/config/word/utils/url.js +0 -8
- package/src/lib/shared/config/word/utils/vnode.js +0 -3
- package/src/lib/shared/config/word/word-work/assets/contentTypesXml.ts +0 -1
- package/src/lib/shared/config/word/word-work/assets/documentXmlRels.ts +0 -1
- package/src/lib/shared/config/word/word-work/assets/index.ts +0 -3
- package/src/lib/shared/config/word/word-work/assets/relsXml.ts +0 -1
- package/src/lib/shared/config/word/word-work/index.ts +0 -8
- package/src/lib/shared/config/word/word-work/internal.ts +0 -69
- package/src/lib/shared/config/word/word-work/templates/documentTemplate.ts +0 -58
- package/src/lib/shared/config/word/word-work/templates/index.ts +0 -3
- package/src/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.ts +0 -21
- package/src/lib/shared/config/word/word-work/templates/mhtPartTemplate.ts +0 -14
- package/src/lib/shared/config/word/word-work/utils.ts +0 -27
- package/src/lib/shared/models/AreaModel.ts +0 -5
- package/src/lib/shared/models/RequestOptionsModel.ts +0 -13
- package/src/lib/shared/models/WordDocumentModel.ts +0 -19
- package/src/lib/shared/services/AppearanceConfiguration.service.ts +0 -30
- package/src/lib/shared/services/configuration.service.ts +0 -18
- package/src/lib/shared/services/controlvalidation.service.ts +0 -194
- package/src/lib/shared/services/environment.service.ts +0 -56
- package/src/lib/shared/services/masterlayout.service.ts +0 -89
- package/src/lib/shared/services/requesthandler.service.ts +0 -241
- package/src/lib/shared/services/stylesbundle.service.ts +0 -52
- package/src/lib/shared/services/translate.service.ts +0 -8
- package/src/lib/shared/services/translationresolver.service.ts +0 -16
- package/src/lib/shared/services/utility.service.ts +0 -94
- package/src/lib/shared/services/word-document.service.ts +0 -36
- package/src/public-api.ts +0 -27
- package/src/test.ts +0 -26
- package/tsconfig.lib.json +0 -39
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -17
- package/tslint.json +0 -17
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-await-in-loop */
|
|
2
|
-
/* eslint-disable no-case-declarations */
|
|
3
|
-
import { fragment } from 'xmlbuilder2';
|
|
4
|
-
import VNode from 'virtual-dom/vnode/vnode';
|
|
5
|
-
import VText from 'virtual-dom/vnode/vtext';
|
|
6
|
-
import isVNode from 'virtual-dom/vnode/is-vnode';
|
|
7
|
-
import isVText from 'virtual-dom/vnode/is-vtext';
|
|
8
|
-
// eslint-disable-next-line import/no-named-default
|
|
9
|
-
import { default as HTMLToVDOM } from 'html-to-vdom';
|
|
10
|
-
import escape from 'escape-html';
|
|
11
|
-
import sizeOf from 'image-size';
|
|
12
|
-
import imageToBase64 from 'image-to-base64';
|
|
13
|
-
import mimeTypes from 'mime-types';
|
|
14
|
-
|
|
15
|
-
// FIXME: remove the cyclic dependency
|
|
16
|
-
// eslint-disable-next-line import/no-cycle
|
|
17
|
-
import * as xmlBuilder from './xml-builder';
|
|
18
|
-
import namespaces from '../namespaces';
|
|
19
|
-
import { imageType, internalRelationship } from '../constants';
|
|
20
|
-
import { vNodeHasChildren } from '../utils/vnode';
|
|
21
|
-
import { isValidUrl } from '../utils/url';
|
|
22
|
-
|
|
23
|
-
const convertHTML = HTMLToVDOM({
|
|
24
|
-
VNode,
|
|
25
|
-
VText,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line consistent-return, no-shadow
|
|
29
|
-
export const buildImage = async (docxDocumentInstance, vNode, maximumWidth = null) => {
|
|
30
|
-
let response = null;
|
|
31
|
-
let base64Uri = null;
|
|
32
|
-
try {
|
|
33
|
-
const imageSource = vNode.properties.src;
|
|
34
|
-
if (isValidUrl(imageSource)) {
|
|
35
|
-
const base64String = await imageToBase64(imageSource).catch((error) => {
|
|
36
|
-
// eslint-disable-next-line no-console
|
|
37
|
-
console.warning(`skipping image download and conversion due to ${error}`);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (base64String) {
|
|
41
|
-
base64Uri = `data:${mimeTypes.lookup(imageSource)};base64, ${base64String}`;
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
base64Uri = decodeURIComponent(vNode.properties.src);
|
|
45
|
-
}
|
|
46
|
-
if (base64Uri) {
|
|
47
|
-
response = docxDocumentInstance.createMediaFile(base64Uri);
|
|
48
|
-
}
|
|
49
|
-
} catch (error) {
|
|
50
|
-
// NOOP
|
|
51
|
-
}
|
|
52
|
-
if (response) {
|
|
53
|
-
docxDocumentInstance.zip
|
|
54
|
-
.folder('word')
|
|
55
|
-
.folder('media')
|
|
56
|
-
.file(response.fileNameWithExtension, Buffer.from(response.fileContent, 'base64'), {
|
|
57
|
-
createFolders: false,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const documentRelsId = docxDocumentInstance.createDocumentRelationships(
|
|
61
|
-
docxDocumentInstance.relationshipFilename,
|
|
62
|
-
imageType,
|
|
63
|
-
`media/${response.fileNameWithExtension}`,
|
|
64
|
-
internalRelationship
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const imageBuffer = Buffer.from(response.fileContent, 'base64');
|
|
68
|
-
const imageProperties = sizeOf(imageBuffer);
|
|
69
|
-
|
|
70
|
-
const imageFragment = await xmlBuilder.buildParagraph(
|
|
71
|
-
vNode,
|
|
72
|
-
{
|
|
73
|
-
type: 'picture',
|
|
74
|
-
inlineOrAnchored: true,
|
|
75
|
-
relationshipId: documentRelsId,
|
|
76
|
-
...response,
|
|
77
|
-
maximumWidth: maximumWidth || docxDocumentInstance.availableDocumentSpace,
|
|
78
|
-
originalWidth: imageProperties.width,
|
|
79
|
-
originalHeight: imageProperties.height,
|
|
80
|
-
},
|
|
81
|
-
docxDocumentInstance
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
return imageFragment;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const buildList = async (vNode, docxDocumentInstance, xmlFragment) => {
|
|
89
|
-
const listElements = [];
|
|
90
|
-
|
|
91
|
-
let vNodeObjects = [
|
|
92
|
-
{
|
|
93
|
-
node: vNode,
|
|
94
|
-
level: 0,
|
|
95
|
-
type: vNode.tagName,
|
|
96
|
-
numberingId: docxDocumentInstance.createNumbering(vNode.tagName, vNode.properties),
|
|
97
|
-
},
|
|
98
|
-
];
|
|
99
|
-
while (vNodeObjects.length) {
|
|
100
|
-
const tempVNodeObject = vNodeObjects.shift();
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
isVText(tempVNodeObject.node) ||
|
|
104
|
-
(isVNode(tempVNodeObject.node) && !['ul', 'ol', 'li'].includes(tempVNodeObject.node.tagName))
|
|
105
|
-
) {
|
|
106
|
-
const paragraphFragment = await xmlBuilder.buildParagraph(
|
|
107
|
-
tempVNodeObject.node,
|
|
108
|
-
{
|
|
109
|
-
numbering: { levelId: tempVNodeObject.level, numberingId: tempVNodeObject.numberingId },
|
|
110
|
-
},
|
|
111
|
-
docxDocumentInstance
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
xmlFragment.import(paragraphFragment);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
tempVNodeObject.node.children &&
|
|
119
|
-
tempVNodeObject.node.children.length &&
|
|
120
|
-
['ul', 'ol', 'li'].includes(tempVNodeObject.node.tagName)
|
|
121
|
-
) {
|
|
122
|
-
const tempVNodeObjects = tempVNodeObject.node.children.reduce((accumulator, childVNode) => {
|
|
123
|
-
if (['ul', 'ol'].includes(childVNode.tagName)) {
|
|
124
|
-
accumulator.push({
|
|
125
|
-
node: childVNode,
|
|
126
|
-
level: tempVNodeObject.level + 1,
|
|
127
|
-
type: childVNode.tagName,
|
|
128
|
-
numberingId: docxDocumentInstance.createNumbering(
|
|
129
|
-
childVNode.tagName,
|
|
130
|
-
childVNode.properties
|
|
131
|
-
),
|
|
132
|
-
});
|
|
133
|
-
} else {
|
|
134
|
-
// eslint-disable-next-line no-lonely-if
|
|
135
|
-
if (
|
|
136
|
-
accumulator.length > 0 &&
|
|
137
|
-
isVNode(accumulator[accumulator.length - 1].node) &&
|
|
138
|
-
accumulator[accumulator.length - 1].node.tagName.toLowerCase() === 'p'
|
|
139
|
-
) {
|
|
140
|
-
accumulator[accumulator.length - 1].node.children.push(childVNode);
|
|
141
|
-
} else {
|
|
142
|
-
const paragraphVNode = new VNode(
|
|
143
|
-
'p',
|
|
144
|
-
null,
|
|
145
|
-
// eslint-disable-next-line no-nested-ternary
|
|
146
|
-
isVText(childVNode)
|
|
147
|
-
? [childVNode]
|
|
148
|
-
: // eslint-disable-next-line no-nested-ternary
|
|
149
|
-
isVNode(childVNode)
|
|
150
|
-
? childVNode.tagName.toLowerCase() === 'li'
|
|
151
|
-
? [...childVNode.children]
|
|
152
|
-
: [childVNode]
|
|
153
|
-
: []
|
|
154
|
-
);
|
|
155
|
-
accumulator.push({
|
|
156
|
-
// eslint-disable-next-line prettier/prettier, no-nested-ternary
|
|
157
|
-
node: isVNode(childVNode)
|
|
158
|
-
? // eslint-disable-next-line prettier/prettier, no-nested-ternary
|
|
159
|
-
childVNode.tagName.toLowerCase() === 'li'
|
|
160
|
-
? childVNode
|
|
161
|
-
: childVNode.tagName.toLowerCase() !== 'p'
|
|
162
|
-
? paragraphVNode
|
|
163
|
-
: childVNode
|
|
164
|
-
: // eslint-disable-next-line prettier/prettier
|
|
165
|
-
paragraphVNode,
|
|
166
|
-
level: tempVNodeObject.level,
|
|
167
|
-
type: tempVNodeObject.type,
|
|
168
|
-
numberingId: tempVNodeObject.numberingId,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return accumulator;
|
|
174
|
-
}, []);
|
|
175
|
-
vNodeObjects = tempVNodeObjects.concat(vNodeObjects);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return listElements;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
async function findXMLEquivalent(docxDocumentInstance, vNode, xmlFragment) {
|
|
183
|
-
if (
|
|
184
|
-
vNode.tagName === 'div' &&
|
|
185
|
-
(vNode.properties.attributes.class === 'page-break' ||
|
|
186
|
-
(vNode.properties.style && vNode.properties.style['page-break-after']))
|
|
187
|
-
) {
|
|
188
|
-
const paragraphFragment = fragment({ namespaceAlias: { w: namespaces.w } })
|
|
189
|
-
.ele('@w', 'p')
|
|
190
|
-
.ele('@w', 'r')
|
|
191
|
-
.ele('@w', 'br')
|
|
192
|
-
.att('@w', 'type', 'page')
|
|
193
|
-
.up()
|
|
194
|
-
.up()
|
|
195
|
-
.up();
|
|
196
|
-
|
|
197
|
-
xmlFragment.import(paragraphFragment);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
switch (vNode.tagName) {
|
|
202
|
-
case 'h1':
|
|
203
|
-
case 'h2':
|
|
204
|
-
case 'h3':
|
|
205
|
-
case 'h4':
|
|
206
|
-
case 'h5':
|
|
207
|
-
case 'h6':
|
|
208
|
-
const headingFragment = await xmlBuilder.buildParagraph(
|
|
209
|
-
vNode,
|
|
210
|
-
{
|
|
211
|
-
paragraphStyle: `Heading${vNode.tagName[1]}`,
|
|
212
|
-
},
|
|
213
|
-
docxDocumentInstance
|
|
214
|
-
);
|
|
215
|
-
xmlFragment.import(headingFragment);
|
|
216
|
-
return;
|
|
217
|
-
case 'span':
|
|
218
|
-
case 'strong':
|
|
219
|
-
case 'b':
|
|
220
|
-
case 'em':
|
|
221
|
-
case 'i':
|
|
222
|
-
case 'u':
|
|
223
|
-
case 'ins':
|
|
224
|
-
case 'strike':
|
|
225
|
-
case 'del':
|
|
226
|
-
case 's':
|
|
227
|
-
case 'sub':
|
|
228
|
-
case 'sup':
|
|
229
|
-
case 'mark':
|
|
230
|
-
case 'p':
|
|
231
|
-
case 'a':
|
|
232
|
-
case 'blockquote':
|
|
233
|
-
case 'code':
|
|
234
|
-
case 'pre':
|
|
235
|
-
const paragraphFragment = await xmlBuilder.buildParagraph(vNode, {}, docxDocumentInstance);
|
|
236
|
-
xmlFragment.import(paragraphFragment);
|
|
237
|
-
return;
|
|
238
|
-
case 'figure':
|
|
239
|
-
if (vNodeHasChildren(vNode)) {
|
|
240
|
-
// eslint-disable-next-line no-plusplus
|
|
241
|
-
for (let index = 0; index < vNode.children.length; index++) {
|
|
242
|
-
const childVNode = vNode.children[index];
|
|
243
|
-
if (childVNode.tagName === 'table') {
|
|
244
|
-
const tableFragment = await xmlBuilder.buildTable(
|
|
245
|
-
childVNode,
|
|
246
|
-
{
|
|
247
|
-
maximumWidth: docxDocumentInstance.availableDocumentSpace,
|
|
248
|
-
rowCantSplit: docxDocumentInstance.tableRowCantSplit,
|
|
249
|
-
},
|
|
250
|
-
docxDocumentInstance
|
|
251
|
-
);
|
|
252
|
-
xmlFragment.import(tableFragment);
|
|
253
|
-
// Adding empty paragraph for space after table
|
|
254
|
-
const emptyParagraphFragment = await xmlBuilder.buildParagraph(null, {});
|
|
255
|
-
xmlFragment.import(emptyParagraphFragment);
|
|
256
|
-
} else if (childVNode.tagName === 'img') {
|
|
257
|
-
const imageFragment = await buildImage(docxDocumentInstance, childVNode);
|
|
258
|
-
if (imageFragment) {
|
|
259
|
-
xmlFragment.import(imageFragment);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return;
|
|
265
|
-
case 'table':
|
|
266
|
-
const tableFragment = await xmlBuilder.buildTable(
|
|
267
|
-
vNode,
|
|
268
|
-
{
|
|
269
|
-
maximumWidth: docxDocumentInstance.availableDocumentSpace,
|
|
270
|
-
rowCantSplit: docxDocumentInstance.tableRowCantSplit,
|
|
271
|
-
},
|
|
272
|
-
docxDocumentInstance
|
|
273
|
-
);
|
|
274
|
-
xmlFragment.import(tableFragment);
|
|
275
|
-
// Adding empty paragraph for space after table
|
|
276
|
-
const emptyParagraphFragment = await xmlBuilder.buildParagraph(null, {});
|
|
277
|
-
xmlFragment.import(emptyParagraphFragment);
|
|
278
|
-
return;
|
|
279
|
-
case 'ol':
|
|
280
|
-
case 'ul':
|
|
281
|
-
await buildList(vNode, docxDocumentInstance, xmlFragment);
|
|
282
|
-
return;
|
|
283
|
-
case 'img':
|
|
284
|
-
const imageFragment = await buildImage(docxDocumentInstance, vNode);
|
|
285
|
-
if (imageFragment) {
|
|
286
|
-
xmlFragment.import(imageFragment);
|
|
287
|
-
}
|
|
288
|
-
return;
|
|
289
|
-
case 'br':
|
|
290
|
-
const linebreakFragment = await xmlBuilder.buildParagraph(null, {});
|
|
291
|
-
xmlFragment.import(linebreakFragment);
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
if (vNodeHasChildren(vNode)) {
|
|
295
|
-
// eslint-disable-next-line no-plusplus
|
|
296
|
-
for (let index = 0; index < vNode.children.length; index++) {
|
|
297
|
-
const childVNode = vNode.children[index];
|
|
298
|
-
// eslint-disable-next-line no-use-before-define
|
|
299
|
-
await convertVTreeToXML(docxDocumentInstance, childVNode, xmlFragment);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// eslint-disable-next-line consistent-return
|
|
305
|
-
export async function convertVTreeToXML(docxDocumentInstance, vTree, xmlFragment) {
|
|
306
|
-
if (!vTree) {
|
|
307
|
-
// eslint-disable-next-line no-useless-return
|
|
308
|
-
return '';
|
|
309
|
-
}
|
|
310
|
-
if (Array.isArray(vTree) && vTree.length) {
|
|
311
|
-
// eslint-disable-next-line no-plusplus
|
|
312
|
-
for (let index = 0; index < vTree.length; index++) {
|
|
313
|
-
const vNode = vTree[index];
|
|
314
|
-
await convertVTreeToXML(docxDocumentInstance, vNode, xmlFragment);
|
|
315
|
-
}
|
|
316
|
-
} else if (isVNode(vTree)) {
|
|
317
|
-
await findXMLEquivalent(docxDocumentInstance, vTree, xmlFragment);
|
|
318
|
-
} else if (isVText(vTree)) {
|
|
319
|
-
xmlBuilder.buildTextElement(xmlFragment, escape(String(vTree.text)));
|
|
320
|
-
}
|
|
321
|
-
return xmlFragment;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
async function renderDocumentFile(docxDocumentInstance) {
|
|
325
|
-
const vTree = convertHTML(docxDocumentInstance.htmlString);
|
|
326
|
-
|
|
327
|
-
const xmlFragment = fragment({ namespaceAlias: { w: namespaces.w } });
|
|
328
|
-
|
|
329
|
-
const populatedXmlFragment = await convertVTreeToXML(docxDocumentInstance, vTree, xmlFragment);
|
|
330
|
-
|
|
331
|
-
return populatedXmlFragment;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export{ renderDocumentFile};
|