@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.
Files changed (172) hide show
  1. package/README.md +8 -0
  2. package/karma.conf.js +44 -0
  3. package/ng-package.json +10 -0
  4. package/package.json +20 -28
  5. package/src/lib/bbsf-utilities.module.ts +52 -0
  6. package/src/lib/shared/authentication/auth.service.ts +242 -0
  7. package/src/lib/shared/config/environment.ts +16 -0
  8. package/src/lib/shared/config/word/constants.js +133 -0
  9. package/src/lib/shared/config/word/docx-document.js +482 -0
  10. package/src/lib/shared/config/word/helpers/index.js +3 -0
  11. package/src/lib/shared/config/word/helpers/render-document-file.js +334 -0
  12. package/src/lib/shared/config/word/helpers/xml-builder.js +2165 -0
  13. package/src/lib/shared/config/word/html-to-docx.js +259 -0
  14. package/src/lib/shared/config/word/index.js +63 -0
  15. package/src/lib/shared/config/word/namespaces.js +40 -0
  16. package/src/lib/shared/config/word/schemas/content-types.js +26 -0
  17. package/src/lib/shared/config/word/schemas/core.js +44 -0
  18. package/src/lib/shared/config/word/schemas/document-rels.js +17 -0
  19. package/src/lib/shared/config/word/schemas/document.template.js +119 -0
  20. package/src/lib/shared/config/word/schemas/font-table.js +41 -0
  21. package/src/lib/shared/config/word/schemas/generic-rels.js +11 -0
  22. package/src/lib/shared/config/word/schemas/index.js +12 -0
  23. package/src/lib/shared/config/word/schemas/numbering.js +18 -0
  24. package/src/lib/shared/config/word/schemas/rels.js +12 -0
  25. package/src/lib/shared/config/word/schemas/settings.js +14 -0
  26. package/src/lib/shared/config/word/schemas/styles.js +152 -0
  27. package/src/lib/shared/config/word/schemas/theme.js +199 -0
  28. package/src/lib/shared/config/word/schemas/web-settings.js +10 -0
  29. package/src/lib/shared/config/word/utils/color-conversion.js +60 -0
  30. package/src/lib/shared/config/word/utils/list.js +55 -0
  31. package/src/lib/shared/config/word/utils/unit-conversion.js +53 -0
  32. package/src/lib/shared/config/word/utils/url.js +8 -0
  33. package/src/lib/shared/config/word/utils/vnode.js +3 -0
  34. package/src/lib/shared/config/word/word-work/assets/contentTypesXml.ts +1 -0
  35. package/src/lib/shared/config/word/word-work/assets/documentXmlRels.ts +1 -0
  36. package/src/lib/shared/config/word/word-work/assets/index.ts +3 -0
  37. package/src/lib/shared/config/word/word-work/assets/relsXml.ts +1 -0
  38. package/src/lib/shared/config/word/word-work/index.ts +8 -0
  39. package/src/lib/shared/config/word/word-work/internal.ts +69 -0
  40. package/src/lib/shared/config/word/word-work/templates/documentTemplate.ts +58 -0
  41. package/src/lib/shared/config/word/word-work/templates/index.ts +3 -0
  42. package/src/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.ts +21 -0
  43. package/src/lib/shared/config/word/word-work/templates/mhtPartTemplate.ts +14 -0
  44. package/src/lib/shared/config/word/word-work/utils.ts +27 -0
  45. package/src/lib/shared/models/AreaModel.ts +5 -0
  46. package/{lib/shared/models/ErrorModel.d.ts → src/lib/shared/models/ErrorModel.ts} +5 -2
  47. package/src/lib/shared/models/RequestOptionsModel.ts +13 -0
  48. package/src/lib/shared/models/WordDocumentModel.ts +19 -0
  49. package/src/lib/shared/services/AppearanceConfiguration.service.ts +30 -0
  50. package/src/lib/shared/services/configuration.service.ts +18 -0
  51. package/src/lib/shared/services/controlvalidation.service.ts +194 -0
  52. package/src/lib/shared/services/environment.service.ts +56 -0
  53. package/src/lib/shared/services/masterlayout.service.ts +89 -0
  54. package/src/lib/shared/services/requesthandler.service.ts +241 -0
  55. package/src/lib/shared/services/stylesbundle.service.ts +52 -0
  56. package/src/lib/shared/services/translate.service.ts +8 -0
  57. package/src/lib/shared/services/translationresolver.service.ts +16 -0
  58. package/src/lib/shared/services/utility.service.ts +94 -0
  59. package/src/lib/shared/services/word-document.service.ts +36 -0
  60. package/src/public-api.ts +27 -0
  61. package/src/test.ts +26 -0
  62. package/tsconfig.lib.json +39 -0
  63. package/tsconfig.lib.prod.json +11 -0
  64. package/tsconfig.spec.json +17 -0
  65. package/tslint.json +17 -0
  66. package/bnsights-bbsf-utilities-1.0.34.tgz +0 -0
  67. package/bnsights-bbsf-utilities.d.ts +0 -4
  68. package/bnsights-bbsf-utilities.metadata.json +0 -1
  69. package/bundles/bnsights-bbsf-utilities.umd.js +0 -4865
  70. package/bundles/bnsights-bbsf-utilities.umd.js.map +0 -1
  71. package/esm2015/bnsights-bbsf-utilities.js +0 -5
  72. package/esm2015/lib/bbsf-utilities.module.js +0 -52
  73. package/esm2015/lib/shared/authentication/auth.service.js +0 -236
  74. package/esm2015/lib/shared/config/environment.js +0 -12
  75. package/esm2015/lib/shared/config/word/constants.js +0 -105
  76. package/esm2015/lib/shared/config/word/docx-document.js +0 -351
  77. package/esm2015/lib/shared/config/word/helpers/index.js +0 -4
  78. package/esm2015/lib/shared/config/word/helpers/render-document-file.js +0 -278
  79. package/esm2015/lib/shared/config/word/helpers/xml-builder.js +0 -1765
  80. package/esm2015/lib/shared/config/word/html-to-docx.js +0 -195
  81. package/esm2015/lib/shared/config/word/index.js +0 -55
  82. package/esm2015/lib/shared/config/word/namespaces.js +0 -37
  83. package/esm2015/lib/shared/config/word/schemas/content-types.js +0 -26
  84. package/esm2015/lib/shared/config/word/schemas/core.js +0 -29
  85. package/esm2015/lib/shared/config/word/schemas/document-rels.js +0 -16
  86. package/esm2015/lib/shared/config/word/schemas/document.template.js +0 -109
  87. package/esm2015/lib/shared/config/word/schemas/font-table.js +0 -40
  88. package/esm2015/lib/shared/config/word/schemas/generic-rels.js +0 -11
  89. package/esm2015/lib/shared/config/word/schemas/index.js +0 -13
  90. package/esm2015/lib/shared/config/word/schemas/numbering.js +0 -19
  91. package/esm2015/lib/shared/config/word/schemas/rels.js +0 -11
  92. package/esm2015/lib/shared/config/word/schemas/settings.js +0 -13
  93. package/esm2015/lib/shared/config/word/schemas/styles.js +0 -149
  94. package/esm2015/lib/shared/config/word/schemas/theme.js +0 -200
  95. package/esm2015/lib/shared/config/word/schemas/web-settings.js +0 -9
  96. package/esm2015/lib/shared/config/word/utils/color-conversion.js +0 -60
  97. package/esm2015/lib/shared/config/word/utils/list.js +0 -51
  98. package/esm2015/lib/shared/config/word/utils/unit-conversion.js +0 -30
  99. package/esm2015/lib/shared/config/word/utils/url.js +0 -9
  100. package/esm2015/lib/shared/config/word/utils/vnode.js +0 -3
  101. package/esm2015/lib/shared/config/word/word-work/templates/documentTemplate.js +0 -54
  102. package/esm2015/lib/shared/config/word/word-work/templates/index.js +0 -4
  103. package/esm2015/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.js +0 -22
  104. package/esm2015/lib/shared/config/word/word-work/templates/mhtPartTemplate.js +0 -10
  105. package/esm2015/lib/shared/config/word/word-work/utils.js +0 -26
  106. package/esm2015/lib/shared/models/AreaModel.js +0 -3
  107. package/esm2015/lib/shared/models/ErrorModel.js +0 -3
  108. package/esm2015/lib/shared/models/RequestOptionsModel.js +0 -11
  109. package/esm2015/lib/shared/models/WordDocumentModel.js +0 -8
  110. package/esm2015/lib/shared/services/AppearanceConfiguration.service.js +0 -37
  111. package/esm2015/lib/shared/services/configuration.service.js +0 -26
  112. package/esm2015/lib/shared/services/controlvalidation.service.js +0 -168
  113. package/esm2015/lib/shared/services/environment.service.js +0 -48
  114. package/esm2015/lib/shared/services/masterlayout.service.js +0 -96
  115. package/esm2015/lib/shared/services/requesthandler.service.js +0 -206
  116. package/esm2015/lib/shared/services/stylesbundle.service.js +0 -56
  117. package/esm2015/lib/shared/services/translate.service.js +0 -13
  118. package/esm2015/lib/shared/services/translationresolver.service.js +0 -20
  119. package/esm2015/lib/shared/services/utility.service.js +0 -96
  120. package/esm2015/lib/shared/services/word-document.service.js +0 -39
  121. package/esm2015/public-api.js +0 -20
  122. package/fesm2015/bnsights-bbsf-utilities.js +0 -4634
  123. package/fesm2015/bnsights-bbsf-utilities.js.map +0 -1
  124. package/lib/bbsf-utilities.module.d.ts +0 -6
  125. package/lib/shared/authentication/auth.service.d.ts +0 -41
  126. package/lib/shared/config/environment.d.ts +0 -1
  127. package/lib/shared/config/word/constants.d.ts +0 -124
  128. package/lib/shared/config/word/docx-document.d.ts +0 -73
  129. package/lib/shared/config/word/helpers/index.d.ts +0 -1
  130. package/lib/shared/config/word/helpers/render-document-file.d.ts +0 -4
  131. package/lib/shared/config/word/helpers/xml-builder.d.ts +0 -14
  132. package/lib/shared/config/word/html-to-docx.d.ts +0 -1
  133. package/lib/shared/config/word/index.d.ts +0 -1
  134. package/lib/shared/config/word/namespaces.d.ts +0 -36
  135. package/lib/shared/config/word/schemas/content-types.d.ts +0 -1
  136. package/lib/shared/config/word/schemas/core.d.ts +0 -1
  137. package/lib/shared/config/word/schemas/document-rels.d.ts +0 -1
  138. package/lib/shared/config/word/schemas/document.template.d.ts +0 -4
  139. package/lib/shared/config/word/schemas/font-table.d.ts +0 -1
  140. package/lib/shared/config/word/schemas/generic-rels.d.ts +0 -1
  141. package/lib/shared/config/word/schemas/index.d.ts +0 -12
  142. package/lib/shared/config/word/schemas/numbering.d.ts +0 -1
  143. package/lib/shared/config/word/schemas/rels.d.ts +0 -1
  144. package/lib/shared/config/word/schemas/settings.d.ts +0 -1
  145. package/lib/shared/config/word/schemas/styles.d.ts +0 -1
  146. package/lib/shared/config/word/schemas/theme.d.ts +0 -1
  147. package/lib/shared/config/word/schemas/web-settings.d.ts +0 -1
  148. package/lib/shared/config/word/utils/color-conversion.d.ts +0 -7
  149. package/lib/shared/config/word/utils/list.d.ts +0 -6
  150. package/lib/shared/config/word/utils/unit-conversion.d.ts +0 -29
  151. package/lib/shared/config/word/utils/url.d.ts +0 -1
  152. package/lib/shared/config/word/utils/vnode.d.ts +0 -1
  153. package/lib/shared/config/word/word-work/templates/documentTemplate.d.ts +0 -12
  154. package/lib/shared/config/word/word-work/templates/index.d.ts +0 -3
  155. package/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.d.ts +0 -1
  156. package/lib/shared/config/word/word-work/templates/mhtPartTemplate.d.ts +0 -1
  157. package/lib/shared/config/word/word-work/utils.d.ts +0 -1
  158. package/lib/shared/models/AreaModel.d.ts +0 -4
  159. package/lib/shared/models/RequestOptionsModel.d.ts +0 -11
  160. package/lib/shared/models/WordDocumentModel.d.ts +0 -16
  161. package/lib/shared/services/AppearanceConfiguration.service.d.ts +0 -11
  162. package/lib/shared/services/configuration.service.d.ts +0 -7
  163. package/lib/shared/services/controlvalidation.service.d.ts +0 -19
  164. package/lib/shared/services/environment.service.d.ts +0 -13
  165. package/lib/shared/services/masterlayout.service.d.ts +0 -24
  166. package/lib/shared/services/requesthandler.service.d.ts +0 -32
  167. package/lib/shared/services/stylesbundle.service.d.ts +0 -9
  168. package/lib/shared/services/translate.service.d.ts +0 -3
  169. package/lib/shared/services/translationresolver.service.d.ts +0 -8
  170. package/lib/shared/services/utility.service.d.ts +0 -21
  171. package/lib/shared/services/word-document.service.d.ts +0 -5
  172. package/public-api.d.ts +0 -16
@@ -0,0 +1,482 @@
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
+
@@ -0,0 +1,3 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ export { renderDocumentFile } from './render-document-file';
3
+ export { convertVTreeToXML } from './render-document-file';