@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,259 +0,0 @@
1
- import { create } from 'xmlbuilder2';
2
- import VNode from 'virtual-dom/vnode/vnode';
3
- import VText from 'virtual-dom/vnode/vtext';
4
- // eslint-disable-next-line import/no-named-default
5
- import { default as HTMLToVDOM } from 'html-to-vdom';
6
-
7
- import { relsXML } from './schemas';
8
- import {DocxDocument} from './docx-document';
9
- import { renderDocumentFile } from './helpers';
10
- import {getMHTdocument} from "./word-work/utils"
11
- import {
12
- pixelRegex,
13
- pixelToTWIP,
14
- cmRegex,
15
- cmToTWIP,
16
- inchRegex,
17
- inchToTWIP,
18
- pointRegex,
19
- pointToHIP,
20
- } from './utils/unit-conversion';
21
- import {
22
- defaultDocumentOptions,
23
- defaultHTMLString,
24
- relsFolderName,
25
- headerFileName,
26
- footerFileName,
27
- themeFileName,
28
- documentFileName,
29
- headerType,
30
- footerType,
31
- internalRelationship,
32
- wordFolder,
33
- themeFolder,
34
- themeType,
35
- } from './constants';
36
- import {generateDocumentTemplateHeader,generateDocumentTemplateFooter,generateDocumentTemplateFooterWithoutPaging }from './schemas/document.template';
37
- const convertHTML = HTMLToVDOM({
38
- VNode,
39
- VText,
40
- });
41
-
42
- const mergeOptions = (options, patch) => ({ ...options, ...patch });
43
-
44
- const fixupFontSize = (fontSize) => {
45
- let normalizedFontSize;
46
- if (pointRegex.test(fontSize)) {
47
- const matchedParts = fontSize.match(pointRegex);
48
-
49
- normalizedFontSize = pointToHIP(matchedParts[1]);
50
- } else if (fontSize) {
51
- // assuming it is already in HIP
52
- normalizedFontSize = fontSize;
53
- } else {
54
- normalizedFontSize = null;
55
- }
56
-
57
- return normalizedFontSize;
58
- };
59
-
60
- const normalizeUnits = (dimensioningObject, defaultDimensionsProperty) => {
61
- let normalizedUnitResult = {};
62
- if (typeof dimensioningObject === 'object' && dimensioningObject !== null) {
63
- Object.keys(dimensioningObject).forEach((key) => {
64
- if (pixelRegex.test(dimensioningObject[key])) {
65
- const matchedParts = dimensioningObject[key].match(pixelRegex);
66
- normalizedUnitResult[key] = pixelToTWIP(matchedParts[1]);
67
- } else if (cmRegex.test(dimensioningObject[key])) {
68
- const matchedParts = dimensioningObject[key].match(cmRegex);
69
- normalizedUnitResult[key] = cmToTWIP(matchedParts[1]);
70
- } else if (inchRegex.test(dimensioningObject[key])) {
71
- const matchedParts = dimensioningObject[key].match(inchRegex);
72
- normalizedUnitResult[key] = inchToTWIP(matchedParts[1]);
73
- } else if (dimensioningObject[key]) {
74
- normalizedUnitResult[key] = dimensioningObject[key];
75
- } else {
76
- // incase value is something like 0
77
- normalizedUnitResult[key] = defaultDimensionsProperty[key];
78
- }
79
- });
80
- } else {
81
- // eslint-disable-next-line no-param-reassign
82
- normalizedUnitResult = null;
83
- }
84
-
85
- return normalizedUnitResult;
86
- };
87
-
88
- const normalizeDocumentOptions = (documentOptions) => {
89
- const normalizedDocumentOptions = { ...documentOptions };
90
- Object.keys(documentOptions).forEach((key) => {
91
- // eslint-disable-next-line default-case
92
- switch (key) {
93
- case 'pageSize':
94
- case 'margins':
95
- normalizedDocumentOptions[key] = normalizeUnits(
96
- documentOptions[key],
97
- defaultDocumentOptions[key]
98
- );
99
- break;
100
- case 'fontSize':
101
- case 'complexScriptFontSize':
102
- normalizedDocumentOptions[key] = fixupFontSize(documentOptions[key]);
103
- break;
104
- }
105
- });
106
-
107
- return normalizedDocumentOptions;
108
- };
109
-
110
- // Ref: https://en.wikipedia.org/wiki/Office_Open_XML_file_formats
111
- // http://officeopenxml.com/anatomyofOOXML.php
112
- async function addFilesToContainer(
113
- zip,
114
- htmlString,
115
- suppliedDocumentOptions,
116
- headerHTMLString,
117
- footerHTMLString
118
- ) {
119
- debugger;
120
- const normalizedDocumentOptions = normalizeDocumentOptions(suppliedDocumentOptions);
121
- const documentOptions = mergeOptions(defaultDocumentOptions, normalizedDocumentOptions);
122
-
123
- if (documentOptions.header && !headerHTMLString) {
124
- // eslint-disable-next-line no-param-reassign
125
- headerHTMLString = defaultHTMLString;
126
- }
127
- if (documentOptions.footer && !footerHTMLString) {
128
- // eslint-disable-next-line no-param-reassign
129
- footerHTMLString = defaultHTMLString;
130
- }
131
-
132
- const docxDocument = new DocxDocument({ zip, htmlString, ...documentOptions });
133
- // Conversion to Word XML happens here
134
- docxDocument.documentXML = await renderDocumentFile(docxDocument);
135
- debugger;
136
- zip
137
- .folder(relsFolderName)
138
- .file(
139
- '.rels',
140
- create({ encoding: 'UTF-8', standalone: true }, relsXML).toString({ prettyPrint: true }),
141
- { createFolders: false }
142
- );
143
-
144
- zip.folder('docProps').file('core.xml', docxDocument.generateCoreXML(), {
145
- createFolders: false,
146
- });
147
-
148
- if (docxDocument.header && headerHTMLString) {
149
- const vTree = convertHTML(headerHTMLString);
150
-
151
- docxDocument.relationshipFilename = headerFileName;
152
- const { headerId, headerXML } = await docxDocument.generateHeaderXML(vTree);
153
- docxDocument.relationshipFilename = documentFileName;
154
- const fileNameWithExt = `${headerType}${headerId}.xml`;
155
-
156
- const relationshipId = docxDocument.createDocumentRelationships(
157
- docxDocument.relationshipFilename,
158
- headerType,
159
- fileNameWithExt,
160
- internalRelationship
161
- );
162
-
163
- zip.folder(wordFolder).file(fileNameWithExt, generateDocumentTemplateHeader.toString({ prettyPrint: true }), {
164
- createFolders: false,
165
- });
166
-
167
- docxDocument.headerObjects.push({ headerId, relationshipId, type: docxDocument.headerType });
168
- }
169
- if (docxDocument.footer && footerHTMLString) {
170
- const vTree = convertHTML(footerHTMLString);
171
-
172
- docxDocument.relationshipFilename = footerFileName;
173
- const { footerId, footerXML } = await docxDocument.generateFooterXML(vTree);
174
- docxDocument.relationshipFilename = documentFileName;
175
- const fileNameWithExt = `${footerType}${footerId}.xml`;
176
-
177
- const relationshipId = docxDocument.createDocumentRelationships(
178
- docxDocument.relationshipFilename,
179
- footerType,
180
- fileNameWithExt,
181
- internalRelationship
182
- );
183
- console.log(footerXML.toString({ prettyPrint: true }))
184
-
185
- if(suppliedDocumentOptions.pageNumber)
186
- zip.folder(wordFolder).file(fileNameWithExt, generateDocumentTemplateFooter.toString({ prettyPrint: true }), {
187
- createFolders: false,
188
- });
189
- else
190
- zip.folder(wordFolder).file(fileNameWithExt, generateDocumentTemplateFooterWithoutPaging.toString({ prettyPrint: true }), {
191
- createFolders: false,
192
- });
193
-
194
- docxDocument.footerObjects.push({ footerId, relationshipId, type: docxDocument.footerType });
195
- }
196
- const themeFileNameWithExt = `${themeFileName}.xml`;
197
- docxDocument.createDocumentRelationships(
198
- docxDocument.relationshipFilename,
199
- themeType,
200
- `${themeFolder}/${themeFileNameWithExt}`,
201
- internalRelationship
202
- );
203
- zip
204
- .folder(wordFolder)
205
- .folder(themeFolder)
206
- .file(themeFileNameWithExt, docxDocument.generateThemeXML(), {
207
- createFolders: false,
208
- });
209
-
210
- zip
211
- .folder(wordFolder)
212
- .file('document.xml', docxDocument.generateDocumentXML(), { createFolders: false })
213
- .file('afchunk.mht', getMHTdocument(htmlString), {
214
- createFolders: false,
215
- })
216
- .file('afchunkheader.mht', getMHTdocument(headerHTMLString), {
217
- createFolders: false,
218
- })
219
- .file('afchunkfooter.mht', getMHTdocument(footerHTMLString), {
220
- createFolders: false,
221
- })
222
- .file('fontTable.xml', docxDocument.generateFontTableXML(), { createFolders: false })
223
- .file('styles.xml', docxDocument.generateStylesXML(), { createFolders: false })
224
- .file('numbering.xml', docxDocument.generateNumberingXML(), { createFolders: false })
225
- .file('settings.xml', docxDocument.generateSettingsXML(), { createFolders: false })
226
- .file('webSettings.xml', docxDocument.generateWebSettingsXML(), { createFolders: false });
227
-
228
- const relationshipXMLs = docxDocument.generateRelsXML();
229
- if (relationshipXMLs && Array.isArray(relationshipXMLs)) {
230
- relationshipXMLs.forEach(({ fileName, xmlString }) => {
231
- console.log(xmlString)
232
- zip.folder(wordFolder).folder(relsFolderName).file(`${fileName}.xml.rels`, xmlString, {
233
- createFolders: false,
234
- });
235
- });
236
- }
237
-
238
- if (relationshipXMLs && Array.isArray(relationshipXMLs)) {
239
- relationshipXMLs.forEach(({ fileName, xmlString }) => {
240
- zip.folder(wordFolder).folder(relsFolderName).file(`header1.xml.rels`, xmlString, {
241
- createFolders: false,
242
- });
243
- });
244
- }
245
- if (relationshipXMLs && Array.isArray(relationshipXMLs)) {
246
- relationshipXMLs.forEach(({ fileName, xmlString }) => {
247
- zip.folder(wordFolder).folder(relsFolderName).file(`footer1.xml.rels`, xmlString, {
248
- createFolders: false,
249
- });
250
- });
251
- }
252
-
253
-
254
- zip.file('[Content_Types].xml', docxDocument.generateContentTypesXML(), { createFolders: false });
255
-
256
- return zip;
257
- }
258
-
259
- export { addFilesToContainer};
@@ -1,63 +0,0 @@
1
- /* eslint-disable no-useless-escape */
2
- import JSZip from 'jszip';
3
- import {addFilesToContainer} from './html-to-docx';
4
-
5
- const minifyHTMLString = (htmlString) => {
6
- try {
7
- if (typeof htmlString === 'string' || htmlString instanceof String) {
8
- const minifiedHTMLString = htmlString
9
- .replace(/\n/g, ' ')
10
- .replace(/\r/g, ' ')
11
- .replace(/\r\n/g, ' ')
12
- .replace(/[\t]+\</g, '<')
13
- .replace(/\>[\t ]+\</g, '><')
14
- .replace(/\>[\t ]+$/g, '>');
15
-
16
- return minifiedHTMLString;
17
- }
18
-
19
- throw new Error('invalid html string');
20
- } catch (error) {
21
- return null;
22
- }
23
- };
24
-
25
- async function generateContainer(
26
- htmlString,
27
- headerHTMLString,
28
- documentOptions = {},
29
- footerHTMLString
30
- ) {
31
- const zip = new JSZip();
32
-
33
- let contentHTML = htmlString;
34
- let headerHTML = headerHTMLString;
35
- let footerHTML = footerHTMLString;
36
- if (htmlString) {
37
- contentHTML = minifyHTMLString(contentHTML);
38
- }
39
- if (headerHTMLString) {
40
- headerHTML = minifyHTMLString(headerHTML);
41
- }
42
- if (footerHTMLString) {
43
- footerHTML = minifyHTMLString(footerHTML);
44
- }
45
-
46
- await addFilesToContainer(zip, contentHTML, documentOptions, headerHTML, footerHTML);
47
-
48
- const buffer = await zip.generateAsync({ type: 'arraybuffer' });
49
- if (Object.prototype.hasOwnProperty.call(global, 'Buffer')) {
50
- return Buffer.from(new Uint8Array(buffer));
51
- }
52
- if (Object.prototype.hasOwnProperty.call(global, 'Blob')) {
53
- // eslint-disable-next-line no-undef
54
- return new Blob([buffer], {
55
- type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
56
- });
57
- }
58
- throw new Error(
59
- 'Add blob support using a polyfill eg https://github.com/bjornstar/blob-polyfill'
60
- );
61
- }
62
-
63
- export {generateContainer};
@@ -1,40 +0,0 @@
1
- const namespaces = {
2
- a: 'http://schemas.openxmlformats.org/drawingml/2006/main',
3
- b: 'http://schemas.openxmlformats.org/officeDocument/2006/bibliography',
4
- cdr: 'http://schemas.openxmlformats.org/drawingml/2006/chartDrawing',
5
- dc: 'http://purl.org/dc/elements/1.1/',
6
- dcmitype: 'http://purl.org/dc/dcmitype/',
7
- dcterms: 'http://purl.org/dc/terms/',
8
- o: 'urn:schemas-microsoft-com:office:office',
9
- pic: 'http://schemas.openxmlformats.org/drawingml/2006/picture',
10
- r: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
11
- v: 'urn:schemas-microsoft-com:vml',
12
- ve: 'http://schemas.openxmlformats.org/markup-compatibility/2006',
13
- vt: 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes',
14
- w: 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
15
- w10: 'urn:schemas-microsoft-com:office:word',
16
- wp: 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing',
17
- wne: 'http://schemas.microsoft.com/office/word/2006/wordml',
18
- xsd: 'http://www.w3.org/2001/XMLSchema',
19
- xsi: 'http://www.w3.org/2001/XMLSchema-instance',
20
- numbering: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
21
- hyperlinks: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
22
- images: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
23
- styles: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
24
- headers: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header',
25
- footers: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer',
26
- themes: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
27
- coreProperties: 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
28
- officeDocumentRelation:
29
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
30
- corePropertiesRelation:
31
- 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
32
- settingsRelation: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
33
- webSettingsRelation:
34
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
35
- sl: 'http://schemas.openxmlformats.org/schemaLibrary/2006/main',
36
- contentTypes: 'http://schemas.openxmlformats.org/package/2006/content-types',
37
- relationship: 'http://schemas.openxmlformats.org/package/2006/relationships',
38
- };
39
-
40
- export default namespaces;
@@ -1,26 +0,0 @@
1
- const contentTypesXML = `
2
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3
-
4
- <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
5
- <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
6
- <Default Extension="jpeg" ContentType="image/jpeg"/>
7
- <Default Extension="png" ContentType="image/png"/>
8
- <Default Extension="xml" ContentType="application/xml"/>
9
- <Override PartName="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
10
- <Override PartName="/word/_rels/document.xml.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
11
- <Override PartName="/word/_rels/footer1.xml.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
12
- <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
13
- <Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
14
- <Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>
15
- <Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
16
- <Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"/>
17
- <Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
18
- <Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"/>
19
- <Override PartName="/word/webSettings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"/>
20
- <Override PartName="/word/afchunk.mht" ContentType="message/rfc822"/>
21
- <Override PartName="/word/afchunkheader.mht" ContentType="message/rfc822"/>
22
- <Override PartName="/word/afchunkfooter.mht" ContentType="message/rfc822"/>
23
- </Types>
24
- `;
25
-
26
- export { contentTypesXML};
@@ -1,44 +0,0 @@
1
- import namespaces from '../namespaces';
2
- import { applicationName } from '../constants';
3
-
4
- const generateCoreXML = (
5
- title = '',
6
- subject = '',
7
- creator = applicationName,
8
- keywords = [applicationName],
9
- description = '',
10
- lastModifiedBy = applicationName,
11
- revision = 1,
12
- createdAt = new Date(),
13
- modifiedAt = new Date()
14
- ) => `
15
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
16
-
17
- <cp:coreProperties
18
- xmlns:cp="${namespaces.coreProperties}"
19
- xmlns:dc="${namespaces.dc}"
20
- xmlns:dcterms="${namespaces.dcterms}"
21
- xmlns:dcmitype="${namespaces.dcmitype}"
22
- xmlns:xsi="${namespaces.xsi}"
23
- >
24
- <dc:title>${title}</dc:title>
25
- <dc:subject>${subject}</dc:subject>
26
- <dc:creator>${creator}</dc:creator>
27
- ${
28
- keywords && Array.isArray(keywords)
29
- ? `<cp:keywords>${keywords.join(', ')}</cp:keywords>`
30
- : ''
31
- }
32
- <dc:description>${description}</dc:description>
33
- <cp:lastModifiedBy>${lastModifiedBy}</cp:lastModifiedBy>
34
- <cp:revision>${revision}</cp:revision>
35
- <dcterms:created xsi:type="dcterms:W3CDTF">${
36
- createdAt instanceof Date ? createdAt.toISOString() : new Date().toISOString()
37
- }</dcterms:created>
38
- <dcterms:modified xsi:type="dcterms:W3CDTF">${
39
- modifiedAt instanceof Date ? modifiedAt.toISOString() : new Date().toISOString()
40
- }</dcterms:modified>
41
- </cp:coreProperties>
42
- `;
43
-
44
- export { generateCoreXML};
@@ -1,17 +0,0 @@
1
- import namespaces from '../namespaces';
2
-
3
- const documentRelsXML = `
4
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
5
-
6
- <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
7
- <Relationship Id="rId1" Type="${namespaces.numbering}" Target="numbering.xml"/>
8
- <Relationship Id="rId2" Type="${namespaces.styles}" Target="styles.xml"/>
9
- <Relationship Id="rId3" Type="${namespaces.settingsRelation}" Target="settings.xml"/>
10
- <Relationship Id="rId4" Type="${namespaces.webSettingsRelation}" Target="webSettings.xml"/>
11
- <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunk.mht" Id="htmlChunk" />
12
- <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunkheader.mht" Id="htmlChunkHeader" />
13
- <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunkfooter.mht" Id="htmlChunkFooter" />
14
- </Relationships>
15
- `;
16
-
17
- export {documentRelsXML};
@@ -1,119 +0,0 @@
1
- import namespaces from "../namespaces";
2
-
3
- const generateDocumentTemplate = (width, height, orientation, margins) => `
4
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
5
- <w:document
6
- xmlns:a="${namespaces.a}"
7
- xmlns:cdr="${namespaces.cdr}"
8
- xmlns:o="${namespaces.o}"
9
- xmlns:pic="${namespaces.pic}"
10
- xmlns:r="${namespaces.r}"
11
- xmlns:v="${namespaces.v}"
12
- xmlns:ve="${namespaces.ve}"
13
- xmlns:vt="${namespaces.vt}"
14
- xmlns:w="${namespaces.w}"
15
- xmlns:w10="${namespaces.w10}"
16
- xmlns:wp="${namespaces.wp}"
17
- xmlns:wne="${namespaces.wne}"
18
- >
19
- <w:body>
20
-
21
- <w:altChunk r:id="htmlChunk" />
22
- <w:sectPr>
23
- <w:pgSz w:w="${width}" w:h="${height}" w:orient="${orientation}" />
24
- <w:pgMar w:top="${margins.top}"
25
- w:right="${margins.right}"
26
- w:bottom="${margins.bottom}"
27
- w:left="${margins.left}"
28
- w:header="${margins.header}"
29
- w:footer="${margins.footer}"
30
- w:gutter="${margins.gutter}"/>
31
- </w:sectPr>
32
- </w:body>
33
- </w:document>
34
- `;
35
-
36
- const generateDocumentTemplateHeader = `
37
- <w:hdr
38
- xmlns:a="${namespaces.a}"
39
- xmlns:cdr="${namespaces.cdr}"
40
- xmlns:o="${namespaces.o}"
41
- xmlns:pic="${namespaces.pic}"
42
- xmlns:r="${namespaces.r}"
43
- xmlns:v="${namespaces.v}"
44
- xmlns:ve="${namespaces.ve}"
45
- xmlns:vt="${namespaces.vt}"
46
- xmlns:w="${namespaces.w}"
47
- xmlns:w10="${namespaces.w10}"
48
- xmlns:wp="${namespaces.wp}"
49
- xmlns:wne="${namespaces.wne}"
50
- >
51
- <w:altChunk r:id="htmlChunkHeader" />
52
- </w:hdr>
53
- `;
54
-
55
- const generateDocumentTemplateFooter = `
56
- <w:ftr
57
- xmlns:a="${namespaces.a}"
58
- xmlns:cdr="${namespaces.cdr}"
59
- xmlns:o="${namespaces.o}"
60
- xmlns:pic="${namespaces.pic}"
61
- xmlns:r="${namespaces.r}"
62
- xmlns:v="${namespaces.v}"
63
- xmlns:ve="${namespaces.ve}"
64
- xmlns:vt="${namespaces.vt}"
65
- xmlns:w="${namespaces.w}"
66
- xmlns:w10="${namespaces.w10}"
67
- xmlns:wp="${namespaces.wp}"
68
- >
69
- <w:altChunk r:id="htmlChunkFooter" />
70
- <w:p w:rsidR="0014021C" w:rsidRDefault="0014021C" w:rsidP="0014021C">
71
- <w:pPr>
72
- <w:pStyle w:val="Footer"/>
73
- <w:jc w:val="center"/>
74
- </w:pPr>
75
- <w:fldSimple xmlns:ns2="http://schemas.openxmlformats.org/wordprocessingml/2006/main" ns2:instr="PAGE">
76
- <w:r/>
77
- </w:fldSimple>
78
- </w:p>
79
- </w:ftr>
80
- `;
81
-
82
- const generateDocumentTemplateFooterWithoutPaging = `
83
- <w:ftr
84
- xmlns:a="${namespaces.a}"
85
- xmlns:cdr="${namespaces.cdr}"
86
- xmlns:o="${namespaces.o}"
87
- xmlns:pic="${namespaces.pic}"
88
- xmlns:r="${namespaces.r}"
89
- xmlns:v="${namespaces.v}"
90
- xmlns:ve="${namespaces.ve}"
91
- xmlns:vt="${namespaces.vt}"
92
- xmlns:w="${namespaces.w}"
93
- xmlns:w10="${namespaces.w10}"
94
- xmlns:wp="${namespaces.wp}"
95
- >
96
- <w:altChunk r:id="htmlChunkFooter" />
97
- </w:ftr>
98
- `;
99
-
100
- export {
101
- generateDocumentTemplate,
102
- generateDocumentTemplateHeader,
103
- generateDocumentTemplateFooter,
104
- generateDocumentTemplateFooterWithoutPaging
105
- };
106
-
107
- {/* <w:altChunk r:id="htmlChunkFooter" /> */}
108
-
109
- {
110
- /* <w:altChunk r:id="htmlChunkFooter" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" /> */
111
- }
112
-
113
- {
114
- /* <w:ftr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
115
- <fldSimple xmlns:ns2="http://schemas.openxmlformats.org/wordprocessingml/2006/main" ns2:instr="PAGE">
116
- </fldSimple>
117
- <w:altChunk r:id="htmlChunkFooter" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />
118
- </w:ftr> */
119
- }
@@ -1,41 +0,0 @@
1
- import namespaces from '../namespaces';
2
-
3
- const fontTableXML = `
4
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
5
-
6
- <w:fonts
7
- xmlns:r="${namespaces.r}"
8
- xmlns:w="${namespaces.w}"
9
- >
10
- <w:font w:name="Symbol">
11
- <w:panose1 w:val="05050102010706020507"/>
12
- <w:charset w:val="02"/>
13
- <w:family w:val="decorative"/>
14
- <w:pitch w:val="variable"/>
15
- <w:sig w:usb0="00000000" w:usb1="10000000" w:usb2="00000000" w:usb3="00000000" w:csb0="80000000" w:csb1="00000000"/>
16
- </w:font>
17
- <w:font w:name="Calibri">
18
- <w:panose1 w:val="020F0502020204030204"/>
19
- <w:charset w:val="00"/>
20
- <w:family w:val="swiss"/>
21
- <w:pitch w:val="variable"/>
22
- <w:sig w:usb0="E4002EFF" w:usb1="C000247B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
23
- </w:font>
24
- <w:font w:name="Times New Roman">
25
- <w:panose1 w:val="02020603050405020304"/>
26
- <w:charset w:val="00"/>
27
- <w:family w:val="roman"/>
28
- <w:pitch w:val="variable"/>
29
- <w:sig w:usb0="E0002EFF" w:usb1="C000785B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
30
- </w:font>
31
- <w:font w:name="Calibri Light">
32
- <w:panose1 w:val="020F0302020204030204"/>
33
- <w:charset w:val="00"/>
34
- <w:family w:val="swiss"/>
35
- <w:pitch w:val="variable"/>
36
- <w:sig w:usb0="E4002EFF" w:usb1="C000247B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
37
- </w:font>
38
- </w:fonts>
39
- `;
40
-
41
- export {fontTableXML};
@@ -1,11 +0,0 @@
1
- const genericRelsXML = `
2
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3
-
4
- <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
5
- <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunk.mht" Id="htmlChunk" />
6
- <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunkheader.mht" Id="htmlChunkHeader" />
7
- <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunkfooter.mht" Id="htmlChunkFooter" />
8
- </Relationships>
9
- `;
10
-
11
- export {genericRelsXML};
@@ -1,12 +0,0 @@
1
- export { contentTypesXML } from './content-types';
2
- export { generateCoreXML } from './core';
3
- export { documentRelsXML } from './document-rels';
4
- export { relsXML } from './rels';
5
- export { generateNumberingXMLTemplate } from './numbering';
6
- export { generateStylesXML } from './styles';
7
- export { fontTableXML } from './font-table';
8
- export { generateThemeXML } from './theme';
9
- export { settingsXML } from './settings';
10
- export { webSettingsXML } from './web-settings';
11
- export { genericRelsXML } from './generic-rels';
12
- export { generateDocumentTemplate } from './document.template';
@@ -1,18 +0,0 @@
1
- import namespaces from '../namespaces';
2
-
3
- const generateNumberingXMLTemplate = () => `
4
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
5
-
6
- <w:numbering
7
- xmlns:w="${namespaces.w}"
8
- xmlns:ve="${namespaces.ve}"
9
- xmlns:o="${namespaces.o}"
10
- xmlns:r="${namespaces.r}"
11
- xmlns:v="${namespaces.v}"
12
- xmlns:wp="${namespaces.wp}"
13
- xmlns:w10="${namespaces.w10}"
14
- xmlns:wne="${namespaces.wne}">
15
- </w:numbering>
16
- `;
17
-
18
- export {generateNumberingXMLTemplate};