@bnsights/bbsf-utilities 1.0.34 → 1.0.36
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 +8 -0
- package/karma.conf.js +44 -0
- package/ng-package.json +10 -0
- package/package.json +20 -28
- package/src/lib/bbsf-utilities.module.ts +52 -0
- package/src/lib/shared/authentication/auth.service.ts +242 -0
- package/src/lib/shared/config/environment.ts +16 -0
- package/src/lib/shared/config/word/constants.js +133 -0
- package/src/lib/shared/config/word/docx-document.js +482 -0
- package/src/lib/shared/config/word/helpers/index.js +3 -0
- package/src/lib/shared/config/word/helpers/render-document-file.js +334 -0
- package/src/lib/shared/config/word/helpers/xml-builder.js +2165 -0
- package/src/lib/shared/config/word/html-to-docx.js +259 -0
- package/src/lib/shared/config/word/index.js +63 -0
- package/src/lib/shared/config/word/namespaces.js +40 -0
- package/src/lib/shared/config/word/schemas/content-types.js +26 -0
- package/src/lib/shared/config/word/schemas/core.js +44 -0
- package/src/lib/shared/config/word/schemas/document-rels.js +17 -0
- package/src/lib/shared/config/word/schemas/document.template.js +119 -0
- package/src/lib/shared/config/word/schemas/font-table.js +41 -0
- package/src/lib/shared/config/word/schemas/generic-rels.js +11 -0
- package/src/lib/shared/config/word/schemas/index.js +12 -0
- package/src/lib/shared/config/word/schemas/numbering.js +18 -0
- package/src/lib/shared/config/word/schemas/rels.js +12 -0
- package/src/lib/shared/config/word/schemas/settings.js +14 -0
- package/src/lib/shared/config/word/schemas/styles.js +152 -0
- package/src/lib/shared/config/word/schemas/theme.js +199 -0
- package/src/lib/shared/config/word/schemas/web-settings.js +10 -0
- package/src/lib/shared/config/word/utils/color-conversion.js +60 -0
- package/src/lib/shared/config/word/utils/list.js +55 -0
- package/src/lib/shared/config/word/utils/unit-conversion.js +53 -0
- package/src/lib/shared/config/word/utils/url.js +8 -0
- package/src/lib/shared/config/word/utils/vnode.js +3 -0
- package/src/lib/shared/config/word/word-work/assets/contentTypesXml.ts +1 -0
- package/src/lib/shared/config/word/word-work/assets/documentXmlRels.ts +1 -0
- package/src/lib/shared/config/word/word-work/assets/index.ts +3 -0
- package/src/lib/shared/config/word/word-work/assets/relsXml.ts +1 -0
- package/src/lib/shared/config/word/word-work/index.ts +8 -0
- package/src/lib/shared/config/word/word-work/internal.ts +69 -0
- package/src/lib/shared/config/word/word-work/templates/documentTemplate.ts +58 -0
- package/src/lib/shared/config/word/word-work/templates/index.ts +3 -0
- package/src/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.ts +21 -0
- package/src/lib/shared/config/word/word-work/templates/mhtPartTemplate.ts +14 -0
- package/src/lib/shared/config/word/word-work/utils.ts +27 -0
- package/src/lib/shared/models/AreaModel.ts +5 -0
- package/{lib/shared/models/ErrorModel.d.ts → src/lib/shared/models/ErrorModel.ts} +5 -2
- package/src/lib/shared/models/RequestOptionsModel.ts +13 -0
- package/src/lib/shared/models/WordDocumentModel.ts +19 -0
- package/src/lib/shared/services/AppearanceConfiguration.service.ts +30 -0
- package/src/lib/shared/services/configuration.service.ts +18 -0
- package/src/lib/shared/services/controlvalidation.service.ts +194 -0
- package/src/lib/shared/services/environment.service.ts +56 -0
- package/src/lib/shared/services/masterlayout.service.ts +89 -0
- package/src/lib/shared/services/requesthandler.service.ts +241 -0
- package/src/lib/shared/services/stylesbundle.service.ts +52 -0
- package/src/lib/shared/services/translate.service.ts +8 -0
- package/src/lib/shared/services/translationresolver.service.ts +16 -0
- package/src/lib/shared/services/utility.service.ts +94 -0
- package/src/lib/shared/services/word-document.service.ts +36 -0
- package/src/public-api.ts +27 -0
- package/src/test.ts +26 -0
- package/tsconfig.lib.json +39 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +17 -0
- package/tslint.json +17 -0
- package/bnsights-bbsf-utilities-1.0.34.tgz +0 -0
- package/bnsights-bbsf-utilities.d.ts +0 -4
- package/bnsights-bbsf-utilities.metadata.json +0 -1
- package/bundles/bnsights-bbsf-utilities.umd.js +0 -4865
- package/bundles/bnsights-bbsf-utilities.umd.js.map +0 -1
- package/esm2015/bnsights-bbsf-utilities.js +0 -5
- package/esm2015/lib/bbsf-utilities.module.js +0 -52
- package/esm2015/lib/shared/authentication/auth.service.js +0 -236
- package/esm2015/lib/shared/config/environment.js +0 -12
- package/esm2015/lib/shared/config/word/constants.js +0 -105
- package/esm2015/lib/shared/config/word/docx-document.js +0 -351
- package/esm2015/lib/shared/config/word/helpers/index.js +0 -4
- package/esm2015/lib/shared/config/word/helpers/render-document-file.js +0 -278
- package/esm2015/lib/shared/config/word/helpers/xml-builder.js +0 -1765
- package/esm2015/lib/shared/config/word/html-to-docx.js +0 -195
- package/esm2015/lib/shared/config/word/index.js +0 -55
- package/esm2015/lib/shared/config/word/namespaces.js +0 -37
- package/esm2015/lib/shared/config/word/schemas/content-types.js +0 -26
- package/esm2015/lib/shared/config/word/schemas/core.js +0 -29
- package/esm2015/lib/shared/config/word/schemas/document-rels.js +0 -16
- package/esm2015/lib/shared/config/word/schemas/document.template.js +0 -109
- package/esm2015/lib/shared/config/word/schemas/font-table.js +0 -40
- package/esm2015/lib/shared/config/word/schemas/generic-rels.js +0 -11
- package/esm2015/lib/shared/config/word/schemas/index.js +0 -13
- package/esm2015/lib/shared/config/word/schemas/numbering.js +0 -19
- package/esm2015/lib/shared/config/word/schemas/rels.js +0 -11
- package/esm2015/lib/shared/config/word/schemas/settings.js +0 -13
- package/esm2015/lib/shared/config/word/schemas/styles.js +0 -149
- package/esm2015/lib/shared/config/word/schemas/theme.js +0 -200
- package/esm2015/lib/shared/config/word/schemas/web-settings.js +0 -9
- package/esm2015/lib/shared/config/word/utils/color-conversion.js +0 -60
- package/esm2015/lib/shared/config/word/utils/list.js +0 -51
- package/esm2015/lib/shared/config/word/utils/unit-conversion.js +0 -30
- package/esm2015/lib/shared/config/word/utils/url.js +0 -9
- package/esm2015/lib/shared/config/word/utils/vnode.js +0 -3
- package/esm2015/lib/shared/config/word/word-work/templates/documentTemplate.js +0 -54
- package/esm2015/lib/shared/config/word/word-work/templates/index.js +0 -4
- package/esm2015/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.js +0 -22
- package/esm2015/lib/shared/config/word/word-work/templates/mhtPartTemplate.js +0 -10
- package/esm2015/lib/shared/config/word/word-work/utils.js +0 -26
- package/esm2015/lib/shared/models/AreaModel.js +0 -3
- package/esm2015/lib/shared/models/ErrorModel.js +0 -3
- package/esm2015/lib/shared/models/RequestOptionsModel.js +0 -11
- package/esm2015/lib/shared/models/WordDocumentModel.js +0 -8
- package/esm2015/lib/shared/services/AppearanceConfiguration.service.js +0 -37
- package/esm2015/lib/shared/services/configuration.service.js +0 -26
- package/esm2015/lib/shared/services/controlvalidation.service.js +0 -168
- package/esm2015/lib/shared/services/environment.service.js +0 -48
- package/esm2015/lib/shared/services/masterlayout.service.js +0 -96
- package/esm2015/lib/shared/services/requesthandler.service.js +0 -206
- package/esm2015/lib/shared/services/stylesbundle.service.js +0 -56
- package/esm2015/lib/shared/services/translate.service.js +0 -13
- package/esm2015/lib/shared/services/translationresolver.service.js +0 -20
- package/esm2015/lib/shared/services/utility.service.js +0 -96
- package/esm2015/lib/shared/services/word-document.service.js +0 -39
- package/esm2015/public-api.js +0 -20
- package/fesm2015/bnsights-bbsf-utilities.js +0 -4634
- package/fesm2015/bnsights-bbsf-utilities.js.map +0 -1
- package/lib/bbsf-utilities.module.d.ts +0 -6
- package/lib/shared/authentication/auth.service.d.ts +0 -41
- package/lib/shared/config/environment.d.ts +0 -1
- package/lib/shared/config/word/constants.d.ts +0 -124
- package/lib/shared/config/word/docx-document.d.ts +0 -73
- package/lib/shared/config/word/helpers/index.d.ts +0 -1
- package/lib/shared/config/word/helpers/render-document-file.d.ts +0 -4
- package/lib/shared/config/word/helpers/xml-builder.d.ts +0 -14
- package/lib/shared/config/word/html-to-docx.d.ts +0 -1
- package/lib/shared/config/word/index.d.ts +0 -1
- package/lib/shared/config/word/namespaces.d.ts +0 -36
- package/lib/shared/config/word/schemas/content-types.d.ts +0 -1
- package/lib/shared/config/word/schemas/core.d.ts +0 -1
- package/lib/shared/config/word/schemas/document-rels.d.ts +0 -1
- package/lib/shared/config/word/schemas/document.template.d.ts +0 -4
- package/lib/shared/config/word/schemas/font-table.d.ts +0 -1
- package/lib/shared/config/word/schemas/generic-rels.d.ts +0 -1
- package/lib/shared/config/word/schemas/index.d.ts +0 -12
- package/lib/shared/config/word/schemas/numbering.d.ts +0 -1
- package/lib/shared/config/word/schemas/rels.d.ts +0 -1
- package/lib/shared/config/word/schemas/settings.d.ts +0 -1
- package/lib/shared/config/word/schemas/styles.d.ts +0 -1
- package/lib/shared/config/word/schemas/theme.d.ts +0 -1
- package/lib/shared/config/word/schemas/web-settings.d.ts +0 -1
- package/lib/shared/config/word/utils/color-conversion.d.ts +0 -7
- package/lib/shared/config/word/utils/list.d.ts +0 -6
- package/lib/shared/config/word/utils/unit-conversion.d.ts +0 -29
- package/lib/shared/config/word/utils/url.d.ts +0 -1
- package/lib/shared/config/word/utils/vnode.d.ts +0 -1
- package/lib/shared/config/word/word-work/templates/documentTemplate.d.ts +0 -12
- package/lib/shared/config/word/word-work/templates/index.d.ts +0 -3
- package/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.d.ts +0 -1
- package/lib/shared/config/word/word-work/templates/mhtPartTemplate.d.ts +0 -1
- package/lib/shared/config/word/word-work/utils.d.ts +0 -1
- package/lib/shared/models/AreaModel.d.ts +0 -4
- package/lib/shared/models/RequestOptionsModel.d.ts +0 -11
- package/lib/shared/models/WordDocumentModel.d.ts +0 -16
- package/lib/shared/services/AppearanceConfiguration.service.d.ts +0 -11
- package/lib/shared/services/configuration.service.d.ts +0 -7
- package/lib/shared/services/controlvalidation.service.d.ts +0 -19
- package/lib/shared/services/environment.service.d.ts +0 -13
- package/lib/shared/services/masterlayout.service.d.ts +0 -24
- package/lib/shared/services/requesthandler.service.d.ts +0 -32
- package/lib/shared/services/stylesbundle.service.d.ts +0 -9
- package/lib/shared/services/translate.service.d.ts +0 -3
- package/lib/shared/services/translationresolver.service.d.ts +0 -8
- package/lib/shared/services/utility.service.d.ts +0 -21
- package/lib/shared/services/word-document.service.d.ts +0 -5
- package/public-api.d.ts +0 -16
|
@@ -0,0 +1,334 @@
|
|
|
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};
|