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