@bnsights/bbsf-utilities 1.0.36 → 1.0.37
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.d.ts +4 -0
- package/bnsights-bbsf-utilities.metadata.json +1 -0
- package/bundles/bnsights-bbsf-utilities.umd.js +4870 -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 +52 -0
- package/esm2015/lib/shared/authentication/auth.service.js +234 -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/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 +96 -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 +4639 -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 +41 -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/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 +28 -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,482 +0,0 @@
|
|
|
1
|
-
import { create, fragment } from 'xmlbuilder2';
|
|
2
|
-
import { nanoid } from 'nanoid';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
generateCoreXML,
|
|
6
|
-
generateStylesXML,
|
|
7
|
-
generateNumberingXMLTemplate,
|
|
8
|
-
generateThemeXML,
|
|
9
|
-
documentRelsXML as documentRelsXMLString,
|
|
10
|
-
settingsXML as settingsXMLString,
|
|
11
|
-
webSettingsXML as webSettingsXMLString,
|
|
12
|
-
contentTypesXML as contentTypesXMLString,
|
|
13
|
-
fontTableXML as fontTableXMLString,
|
|
14
|
-
genericRelsXML as genericRelsXMLString,
|
|
15
|
-
generateDocumentTemplate,
|
|
16
|
-
} from './schemas';
|
|
17
|
-
import { convertVTreeToXML } from './helpers';
|
|
18
|
-
import namespaces from './namespaces';
|
|
19
|
-
import {
|
|
20
|
-
footerType as footerFileType,
|
|
21
|
-
headerType as headerFileType,
|
|
22
|
-
themeType as themeFileType,
|
|
23
|
-
landscapeMargins,
|
|
24
|
-
portraitMargins,
|
|
25
|
-
defaultOrientation,
|
|
26
|
-
landscapeWidth,
|
|
27
|
-
landscapeHeight,
|
|
28
|
-
applicationName,
|
|
29
|
-
defaultFont,
|
|
30
|
-
defaultFontSize,
|
|
31
|
-
hyperlinkType,
|
|
32
|
-
documentFileName,
|
|
33
|
-
imageType,
|
|
34
|
-
defaultDocumentOptions,
|
|
35
|
-
} from './constants';
|
|
36
|
-
import {ListStyleBuilder} from './utils/list';
|
|
37
|
-
|
|
38
|
-
function generateContentTypesFragments(contentTypesXML, type, objects) {
|
|
39
|
-
if (objects && Array.isArray(objects)) {
|
|
40
|
-
objects.forEach((object) => {
|
|
41
|
-
const contentTypesFragment = fragment({ defaultNamespace: { ele: namespaces.contentTypes } })
|
|
42
|
-
.ele('Override')
|
|
43
|
-
.att('PartName', `/word/${type}${object[`${type}Id`]}.xml`)
|
|
44
|
-
.att(
|
|
45
|
-
'ContentType',
|
|
46
|
-
`application/vnd.openxmlformats-officedocument.wordprocessingml.${type}+xml`
|
|
47
|
-
)
|
|
48
|
-
.up();
|
|
49
|
-
|
|
50
|
-
contentTypesXML.root().import(contentTypesFragment);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function generateSectionReferenceXML(documentXML, documentSectionType, objects, isEnabled) {
|
|
56
|
-
if (isEnabled && objects && Array.isArray(objects) && objects.length) {
|
|
57
|
-
const xmlFragment = fragment();
|
|
58
|
-
objects.forEach(({ relationshipId, type }) => {
|
|
59
|
-
const objectFragment = fragment({ namespaceAlias: { w: namespaces.w, r: namespaces.r } })
|
|
60
|
-
.ele('@w', `${documentSectionType}Reference`)
|
|
61
|
-
.att('@r', 'id', `rId${relationshipId}`)
|
|
62
|
-
.att('@w', 'type', type)
|
|
63
|
-
.up();
|
|
64
|
-
xmlFragment.import(objectFragment);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
documentXML.root().first().first().import(xmlFragment);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function generateXMLString(xmlString) {
|
|
72
|
-
const xmlDocumentString = create({ encoding: 'UTF-8', standalone: true }, xmlString);
|
|
73
|
-
return xmlDocumentString.toString({ prettyPrint: true });
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function generateSectionXML(vTree, type = 'header') {
|
|
77
|
-
debugger;
|
|
78
|
-
const sectionXML = create({
|
|
79
|
-
encoding: 'UTF-8',
|
|
80
|
-
standalone: true,
|
|
81
|
-
namespaceAlias: {
|
|
82
|
-
a:namespaces.a,
|
|
83
|
-
cdr:namespaces.cdr,
|
|
84
|
-
o:namespaces.o,
|
|
85
|
-
pic:namespaces.pic,
|
|
86
|
-
r:namespaces.r,
|
|
87
|
-
v:namespaces.v,
|
|
88
|
-
ve:namespaces.ve,
|
|
89
|
-
vt:namespaces.vt,
|
|
90
|
-
w:namespaces.w,
|
|
91
|
-
w10:namespaces.w10,
|
|
92
|
-
wp:namespaces.wp,
|
|
93
|
-
wne:namespaces.wne
|
|
94
|
-
},
|
|
95
|
-
}).ele('@w', type === 'header' ? 'hdr' : 'ftr');
|
|
96
|
-
|
|
97
|
-
const XMLFragment = fragment();
|
|
98
|
-
await convertVTreeToXML(this, vTree, XMLFragment);
|
|
99
|
-
if (type === 'footer' && XMLFragment.first().node.tagName === 'p' && this.pageNumber) {
|
|
100
|
-
XMLFragment.first().import(
|
|
101
|
-
fragment({ namespaceAlias: { w: namespaces.w } })
|
|
102
|
-
.ele('@w', 'fldSimple')
|
|
103
|
-
.att('@w', 'instr', 'PAGE')
|
|
104
|
-
.ele('@w', 'r')
|
|
105
|
-
.up()
|
|
106
|
-
.up()
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
sectionXML.root().import(XMLFragment);
|
|
110
|
-
|
|
111
|
-
const referenceName = type === 'header' ? 'Header' : 'Footer';
|
|
112
|
-
this[`last${referenceName}Id`] += 1;
|
|
113
|
-
|
|
114
|
-
return { [`${type}Id`]: this[`last${referenceName}Id`], [`${type}XML`]: sectionXML };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export class DocxDocument {
|
|
118
|
-
constructor(properties) {
|
|
119
|
-
this.zip = properties.zip;
|
|
120
|
-
this.htmlString = properties.htmlString;
|
|
121
|
-
this.orientation = properties.orientation;
|
|
122
|
-
this.pageSize = properties.pageSize || defaultDocumentOptions.pageSize;
|
|
123
|
-
|
|
124
|
-
const isPortraitOrientation = this.orientation === defaultOrientation;
|
|
125
|
-
const height = this.pageSize.height ? this.pageSize.height : landscapeHeight;
|
|
126
|
-
const width = this.pageSize.width ? this.pageSize.width : landscapeWidth;
|
|
127
|
-
|
|
128
|
-
this.width = isPortraitOrientation ? width : height;
|
|
129
|
-
this.height = isPortraitOrientation ? height : width;
|
|
130
|
-
|
|
131
|
-
const marginsObject = properties.margins;
|
|
132
|
-
this.margins =
|
|
133
|
-
// eslint-disable-next-line no-nested-ternary
|
|
134
|
-
marginsObject && Object.keys(marginsObject).length
|
|
135
|
-
? marginsObject
|
|
136
|
-
: isPortraitOrientation
|
|
137
|
-
? portraitMargins
|
|
138
|
-
: landscapeMargins;
|
|
139
|
-
|
|
140
|
-
this.availableDocumentSpace = this.width - this.margins.left - this.margins.right;
|
|
141
|
-
this.title = properties.title || '';
|
|
142
|
-
this.subject = properties.subject || '';
|
|
143
|
-
this.creator = properties.creator || applicationName;
|
|
144
|
-
this.keywords = properties.keywords || [applicationName];
|
|
145
|
-
this.description = properties.description || '';
|
|
146
|
-
this.lastModifiedBy = properties.lastModifiedBy || applicationName;
|
|
147
|
-
this.revision = properties.revision || 1;
|
|
148
|
-
this.createdAt = properties.createdAt || new Date();
|
|
149
|
-
this.modifiedAt = properties.modifiedAt || new Date();
|
|
150
|
-
this.headerType = properties.headerType || 'default';
|
|
151
|
-
this.header = properties.header || false;
|
|
152
|
-
this.footerType = properties.footerType || 'default';
|
|
153
|
-
this.footer = properties.footer || false;
|
|
154
|
-
this.font = properties.font || defaultFont;
|
|
155
|
-
this.fontSize = properties.fontSize || defaultFontSize;
|
|
156
|
-
this.complexScriptFontSize = properties.complexScriptFontSize || defaultFontSize;
|
|
157
|
-
this.tableRowCantSplit =
|
|
158
|
-
(properties.table && properties.table.row && properties.table.row.cantSplit) || false;
|
|
159
|
-
this.pageNumber = properties.pageNumber || false;
|
|
160
|
-
this.skipFirstHeaderFooter = properties.skipFirstHeaderFooter || false;
|
|
161
|
-
this.lineNumber = properties.lineNumber ? properties.lineNumberOptions : null;
|
|
162
|
-
|
|
163
|
-
this.lastNumberingId = 0;
|
|
164
|
-
this.lastMediaId = 0;
|
|
165
|
-
this.lastHeaderId = 0;
|
|
166
|
-
this.lastFooterId = 0;
|
|
167
|
-
this.stylesObjects = [];
|
|
168
|
-
this.numberingObjects = [];
|
|
169
|
-
this.relationshipFilename = documentFileName;
|
|
170
|
-
this.relationships = [{ fileName: documentFileName, lastRelsId: 4, rels: [] }];
|
|
171
|
-
this.mediaFiles = [];
|
|
172
|
-
this.headerObjects = [];
|
|
173
|
-
this.footerObjects = [];
|
|
174
|
-
this.documentXML = null;
|
|
175
|
-
|
|
176
|
-
this.generateContentTypesXML = this.generateContentTypesXML.bind(this);
|
|
177
|
-
this.generateDocumentXML = this.generateDocumentXML.bind(this);
|
|
178
|
-
this.generateCoreXML = this.generateCoreXML.bind(this);
|
|
179
|
-
this.generateSettingsXML = this.generateSettingsXML.bind(this);
|
|
180
|
-
this.generateWebSettingsXML = this.generateWebSettingsXML.bind(this);
|
|
181
|
-
this.generateStylesXML = this.generateStylesXML.bind(this);
|
|
182
|
-
this.generateFontTableXML = this.generateFontTableXML.bind(this);
|
|
183
|
-
this.generateThemeXML = this.generateThemeXML.bind(this);
|
|
184
|
-
this.generateNumberingXML = this.generateNumberingXML.bind(this);
|
|
185
|
-
this.generateRelsXML = this.generateRelsXML.bind(this);
|
|
186
|
-
this.createMediaFile = this.createMediaFile.bind(this);
|
|
187
|
-
this.createDocumentRelationships = this.createDocumentRelationships.bind(this);
|
|
188
|
-
this.generateHeaderXML = this.generateHeaderXML.bind(this);
|
|
189
|
-
this.generateFooterXML = this.generateFooterXML.bind(this);
|
|
190
|
-
this.generateSectionXML = generateSectionXML.bind(this);
|
|
191
|
-
|
|
192
|
-
this.ListStyleBuilder = new ListStyleBuilder(properties.numbering);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
generateContentTypesXML() {
|
|
196
|
-
const contentTypesXML = create({ encoding: 'UTF-8', standalone: true }, contentTypesXMLString);
|
|
197
|
-
|
|
198
|
-
generateContentTypesFragments(contentTypesXML, 'header', this.headerObjects);
|
|
199
|
-
generateContentTypesFragments(contentTypesXML, 'footer', this.footerObjects);
|
|
200
|
-
|
|
201
|
-
return contentTypesXML.toString({ prettyPrint: true });
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
generateDocumentXML() {
|
|
205
|
-
const documentXML = create(
|
|
206
|
-
{ encoding: 'UTF-8', standalone: true },
|
|
207
|
-
generateDocumentTemplate(this.width, this.height, this.orientation, this.margins)
|
|
208
|
-
);
|
|
209
|
-
// documentXML.root().first().import(this.documentXML);
|
|
210
|
-
|
|
211
|
-
generateSectionReferenceXML(documentXML, 'header', this.headerObjects, this.header);
|
|
212
|
-
generateSectionReferenceXML(documentXML, 'footer', this.footerObjects, this.footer);
|
|
213
|
-
|
|
214
|
-
if ((this.header || this.footer) && this.skipFirstHeaderFooter) {
|
|
215
|
-
documentXML
|
|
216
|
-
.root()
|
|
217
|
-
.first()
|
|
218
|
-
.first()
|
|
219
|
-
.import(fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'titlePg'));
|
|
220
|
-
}
|
|
221
|
-
if (this.lineNumber) {
|
|
222
|
-
const { countBy, start, restart } = this.lineNumber;
|
|
223
|
-
documentXML
|
|
224
|
-
.root()
|
|
225
|
-
.first()
|
|
226
|
-
.first()
|
|
227
|
-
.import(
|
|
228
|
-
fragment({ namespaceAlias: { w: namespaces.w } })
|
|
229
|
-
.ele('@w', 'lnNumType')
|
|
230
|
-
.att('@w', 'countBy', countBy)
|
|
231
|
-
.att('@w', 'start', start)
|
|
232
|
-
.att('@w', 'restart', restart)
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return documentXML.toString({ prettyPrint: true });
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
generateCoreXML() {
|
|
240
|
-
return generateXMLString(
|
|
241
|
-
generateCoreXML(
|
|
242
|
-
this.title,
|
|
243
|
-
this.subject,
|
|
244
|
-
this.creator,
|
|
245
|
-
this.keywords,
|
|
246
|
-
this.description,
|
|
247
|
-
this.lastModifiedBy,
|
|
248
|
-
this.revision,
|
|
249
|
-
this.createdAt,
|
|
250
|
-
this.modifiedAt
|
|
251
|
-
)
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// eslint-disable-next-line class-methods-use-this
|
|
256
|
-
generateSettingsXML() {
|
|
257
|
-
return generateXMLString(settingsXMLString);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// eslint-disable-next-line class-methods-use-this
|
|
261
|
-
generateWebSettingsXML() {
|
|
262
|
-
return generateXMLString(webSettingsXMLString);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
generateStylesXML() {
|
|
266
|
-
return generateXMLString(
|
|
267
|
-
generateStylesXML(this.font, this.fontSize, this.complexScriptFontSize)
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// eslint-disable-next-line class-methods-use-this
|
|
272
|
-
generateFontTableXML() {
|
|
273
|
-
return generateXMLString(fontTableXMLString);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
generateThemeXML() {
|
|
277
|
-
return generateXMLString(generateThemeXML(this.font));
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
generateNumberingXML() {
|
|
281
|
-
const numberingXML = create(
|
|
282
|
-
{ encoding: 'UTF-8', standalone: true },
|
|
283
|
-
generateNumberingXMLTemplate()
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
const abstractNumberingFragments = fragment();
|
|
287
|
-
const numberingFragments = fragment();
|
|
288
|
-
|
|
289
|
-
this.numberingObjects.forEach(({ numberingId, type, properties }) => {
|
|
290
|
-
const abstractNumberingFragment = fragment({ namespaceAlias: { w: namespaces.w } })
|
|
291
|
-
.ele('@w', 'abstractNum')
|
|
292
|
-
.att('@w', 'abstractNumId', String(numberingId));
|
|
293
|
-
|
|
294
|
-
[...Array(8).keys()].forEach((level) => {
|
|
295
|
-
const levelFragment = fragment({ namespaceAlias: { w: namespaces.w } })
|
|
296
|
-
.ele('@w', 'lvl')
|
|
297
|
-
.att('@w', 'ilvl', level)
|
|
298
|
-
.ele('@w', 'start')
|
|
299
|
-
.att(
|
|
300
|
-
'@w',
|
|
301
|
-
'val',
|
|
302
|
-
type === 'ol'
|
|
303
|
-
? (properties.attributes && properties.attributes['data-start']) || 1
|
|
304
|
-
: '1'
|
|
305
|
-
)
|
|
306
|
-
.up()
|
|
307
|
-
.ele('@w', 'numFmt')
|
|
308
|
-
.att(
|
|
309
|
-
'@w',
|
|
310
|
-
'val',
|
|
311
|
-
type === 'ol'
|
|
312
|
-
? this.ListStyleBuilder.getListStyleType(
|
|
313
|
-
properties.style && properties.style['list-style-type']
|
|
314
|
-
)
|
|
315
|
-
: 'bullet'
|
|
316
|
-
)
|
|
317
|
-
.up()
|
|
318
|
-
.ele('@w', 'lvlText')
|
|
319
|
-
.att(
|
|
320
|
-
'@w',
|
|
321
|
-
'val',
|
|
322
|
-
type === 'ol' ? this.ListStyleBuilder.getListPrefixSuffix(properties.style, level) : ''
|
|
323
|
-
)
|
|
324
|
-
.up()
|
|
325
|
-
.ele('@w', 'lvlJc')
|
|
326
|
-
.att('@w', 'val', 'left')
|
|
327
|
-
.up()
|
|
328
|
-
.ele('@w', 'pPr')
|
|
329
|
-
.ele('@w', 'tabs')
|
|
330
|
-
.ele('@w', 'tab')
|
|
331
|
-
.att('@w', 'val', 'num')
|
|
332
|
-
.att('@w', 'pos', (level + 1) * 720)
|
|
333
|
-
.up()
|
|
334
|
-
.up()
|
|
335
|
-
.ele('@w', 'ind')
|
|
336
|
-
.att('@w', 'left', (level + 1) * 720)
|
|
337
|
-
.att('@w', 'hanging', 360)
|
|
338
|
-
.up()
|
|
339
|
-
.up()
|
|
340
|
-
.up();
|
|
341
|
-
|
|
342
|
-
if (type === 'ul') {
|
|
343
|
-
levelFragment.last().import(
|
|
344
|
-
fragment({ namespaceAlias: { w: namespaces.w } })
|
|
345
|
-
.ele('@w', 'rPr')
|
|
346
|
-
.ele('@w', 'rFonts')
|
|
347
|
-
.att('@w', 'ascii', 'Symbol')
|
|
348
|
-
.att('@w', 'hAnsi', 'Symbol')
|
|
349
|
-
.att('@w', 'hint', 'default')
|
|
350
|
-
.up()
|
|
351
|
-
.up()
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
abstractNumberingFragment.import(levelFragment);
|
|
355
|
-
});
|
|
356
|
-
abstractNumberingFragment.up();
|
|
357
|
-
abstractNumberingFragments.import(abstractNumberingFragment);
|
|
358
|
-
|
|
359
|
-
numberingFragments.import(
|
|
360
|
-
fragment({ namespaceAlias: { w: namespaces.w } })
|
|
361
|
-
.ele('@w', 'num')
|
|
362
|
-
.att('@w', 'numId', String(numberingId))
|
|
363
|
-
.ele('@w', 'abstractNumId')
|
|
364
|
-
.att('@w', 'val', String(numberingId))
|
|
365
|
-
.up()
|
|
366
|
-
.up()
|
|
367
|
-
);
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
numberingXML.root().import(abstractNumberingFragments);
|
|
371
|
-
numberingXML.root().import(numberingFragments);
|
|
372
|
-
|
|
373
|
-
return numberingXML.toString({ prettyPrint: true });
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// eslint-disable-next-line class-methods-use-this
|
|
377
|
-
appendRelationships(xmlFragment, relationships) {
|
|
378
|
-
relationships.forEach(({ relationshipId, type, target, targetMode }) => {
|
|
379
|
-
xmlFragment.import(
|
|
380
|
-
fragment({ defaultNamespace: { ele: namespaces.relationship } })
|
|
381
|
-
.ele('Relationship')
|
|
382
|
-
.att('Id', `rId${relationshipId}`)
|
|
383
|
-
.att('Type', type)
|
|
384
|
-
.att('Target', target)
|
|
385
|
-
.att('TargetMode', targetMode)
|
|
386
|
-
.up()
|
|
387
|
-
);
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
generateRelsXML() {
|
|
392
|
-
const relationshipXMLStrings = this.relationships.map(({ fileName, rels }) => {
|
|
393
|
-
const xmlFragment = create(
|
|
394
|
-
{ encoding: 'UTF-8', standalone: true },
|
|
395
|
-
fileName === documentFileName ? documentRelsXMLString : genericRelsXMLString
|
|
396
|
-
);
|
|
397
|
-
this.appendRelationships(xmlFragment.root(), rels);
|
|
398
|
-
|
|
399
|
-
return { fileName, xmlString: xmlFragment.toString({ prettyPrint: true }) };
|
|
400
|
-
});
|
|
401
|
-
return relationshipXMLStrings;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
createNumbering(type, properties) {
|
|
405
|
-
this.lastNumberingId += 1;
|
|
406
|
-
this.numberingObjects.push({ numberingId: this.lastNumberingId, type, properties });
|
|
407
|
-
|
|
408
|
-
return this.lastNumberingId;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
createMediaFile(base64String) {
|
|
412
|
-
// eslint-disable-next-line no-useless-escape
|
|
413
|
-
const matches = base64String.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
|
|
414
|
-
if (matches.length !== 3) {
|
|
415
|
-
throw new Error('Invalid base64 string');
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
const base64FileContent = matches[2];
|
|
419
|
-
// matches array contains file type in base64 format - image/jpeg and base64 stringified data
|
|
420
|
-
const fileExtension =
|
|
421
|
-
matches[1].match(/\/(.*?)$/)[1] === 'octet-stream' ? 'png' : matches[1].match(/\/(.*?)$/)[1];
|
|
422
|
-
|
|
423
|
-
const fileNameWithExtension = `image-${nanoid()}.${fileExtension}`;
|
|
424
|
-
|
|
425
|
-
this.lastMediaId += 1;
|
|
426
|
-
|
|
427
|
-
return { id: this.lastMediaId, fileContent: base64FileContent, fileNameWithExtension };
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
createDocumentRelationships(fileName = 'document', type, target, targetMode = 'External') {
|
|
431
|
-
debugger;
|
|
432
|
-
let relationshipObject = this.relationships.find(
|
|
433
|
-
(relationship) => relationship.fileName === fileName
|
|
434
|
-
);
|
|
435
|
-
let lastRelsId = 1;
|
|
436
|
-
if (relationshipObject) {
|
|
437
|
-
lastRelsId = relationshipObject.lastRelsId + 1;
|
|
438
|
-
relationshipObject.lastRelsId = lastRelsId;
|
|
439
|
-
} else {
|
|
440
|
-
relationshipObject = { fileName, lastRelsId, rels: [] };
|
|
441
|
-
this.relationships.push(relationshipObject);
|
|
442
|
-
}
|
|
443
|
-
let relationshipType;
|
|
444
|
-
switch (type) {
|
|
445
|
-
case hyperlinkType:
|
|
446
|
-
relationshipType = namespaces.hyperlinks;
|
|
447
|
-
break;
|
|
448
|
-
case imageType:
|
|
449
|
-
relationshipType = namespaces.images;
|
|
450
|
-
break;
|
|
451
|
-
case headerFileType:
|
|
452
|
-
relationshipType = namespaces.headers;
|
|
453
|
-
break;
|
|
454
|
-
case footerFileType:
|
|
455
|
-
relationshipType = namespaces.footers;
|
|
456
|
-
break;
|
|
457
|
-
case themeFileType:
|
|
458
|
-
relationshipType = namespaces.themes;
|
|
459
|
-
break;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
relationshipObject.rels.push({
|
|
463
|
-
relationshipId: lastRelsId,
|
|
464
|
-
type: relationshipType,
|
|
465
|
-
target,
|
|
466
|
-
targetMode,
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
console.log(fileName)
|
|
470
|
-
console.log( relationshipObject.rels)
|
|
471
|
-
return lastRelsId;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
generateHeaderXML(vTree) {
|
|
475
|
-
return this.generateSectionXML(vTree, 'header');
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
generateFooterXML(vTree) {
|
|
479
|
-
return this.generateSectionXML(vTree, 'footer');
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|