@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
@@ -0,0 +1,4639 @@
1
+ import * as i1$1 from '@angular/common';
2
+ import { DOCUMENT, CommonModule } from '@angular/common';
3
+ import * as i0 from '@angular/core';
4
+ import { Injectable, Inject, Injector, NgModule } from '@angular/core';
5
+ import * as i1$2 from '@angular/router';
6
+ import { Router, RouterModule } from '@angular/router';
7
+ import * as i1 from '@ngx-translate/core';
8
+ import { TranslateService } from '@ngx-translate/core';
9
+ import { BlockUI, BlockUIModule } from 'ng-block-ui';
10
+ import { ToastrService, ToastrModule } from 'ngx-toastr';
11
+ import { HttpModule } from '@angular/http';
12
+ import { __awaiter, __decorate, __rest } from 'tslib';
13
+ import * as i1$3 from '@angular/common/http';
14
+ import { HttpHeaders, HttpClient, HttpParams } from '@angular/common/http';
15
+ import { UserManager, WebStorageStateStore } from 'oidc-client';
16
+ import { Subject, Observable, throwError, BehaviorSubject } from 'rxjs';
17
+ import { takeUntil, tap, map } from 'rxjs/operators';
18
+ import { plainToClass } from 'class-transformer';
19
+ import JSZip from 'jszip';
20
+ import { fragment, create } from 'xmlbuilder2';
21
+ import VNode from 'virtual-dom/vnode/vnode';
22
+ import VText from 'virtual-dom/vnode/vtext';
23
+ import HTMLToVDOM from 'html-to-vdom';
24
+ import { cloneDeep } from 'lodash';
25
+ import { nanoid } from 'nanoid';
26
+ import isVNode from 'virtual-dom/vnode/is-vnode';
27
+ import isVText from 'virtual-dom/vnode/is-vtext';
28
+ import escape from 'escape-html';
29
+ import sizeOf from 'image-size';
30
+ import imageToBase64 from 'image-to-base64';
31
+ import mimeTypes from 'mime-types';
32
+ import colorNames from 'color-name';
33
+
34
+ // This file can be replaced during build by using the `fileReplacements` array.
35
+ // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
36
+ // The list of file replacements can be found in `angular.json`.
37
+ const environment = Object.assign({}, window.Environment);
38
+ /*
39
+ * In development mode, to ignore zone related error stack frames such as
40
+ * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can
41
+ * import the following file, but please comment it out in production mode
42
+ * because it will have performance impact when throw error
43
+ */
44
+ // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
45
+
46
+ class EnvironmentService {
47
+ getEnvironmentObject() {
48
+ return environment;
49
+ }
50
+ getBaseUrl() {
51
+ let Url = environment["BBSF_BaseURL"];
52
+ return Url;
53
+ }
54
+ getApiUrl() {
55
+ let Url = environment["BBSF_ApiUrl"];
56
+ return Url;
57
+ }
58
+ getProductionMode() {
59
+ let Mode = environment["BBSF_IsProduction"];
60
+ return Mode;
61
+ }
62
+ getDefaultLanguage() {
63
+ let Mode = environment["BBSF_DefaultLanguage"];
64
+ return Mode;
65
+ }
66
+ getIdentityServerUrl() {
67
+ let Url = environment["BBSF_IdentityServerUrl"];
68
+ return Url;
69
+ }
70
+ getIsIdentityServerExternal() {
71
+ let Mode = environment["BBSF_IsExternalIdentityServer"];
72
+ return Mode;
73
+ }
74
+ getIsIdentityServerClientId() {
75
+ let Mode = environment["BBSF_IdentityServer_Client_Id"];
76
+ return Mode;
77
+ }
78
+ getIsIdentityServerClientSecret() {
79
+ let Mode = environment["BBSF_IdentityServer_Client_Secret"];
80
+ return Mode;
81
+ }
82
+ }
83
+ EnvironmentService.AreaList = [];
84
+ EnvironmentService.ɵprov = i0.ɵɵdefineInjectable({ factory: function EnvironmentService_Factory() { return new EnvironmentService(); }, token: EnvironmentService, providedIn: "root" });
85
+ EnvironmentService.decorators = [
86
+ { type: Injectable, args: [{
87
+ providedIn: 'root'
88
+ },] }
89
+ ];
90
+
91
+ class BBSFTranslateService extends TranslateService {
92
+ }
93
+ BBSFTranslateService.ɵprov = i0.ɵɵdefineInjectable({ factory: function BBSFTranslateService_Factory() { return new BBSFTranslateService(i0.ɵɵinject(i1.TranslateStore), i0.ɵɵinject(i1.TranslateLoader), i0.ɵɵinject(i1.TranslateCompiler), i0.ɵɵinject(i1.TranslateParser), i0.ɵɵinject(i1.MissingTranslationHandler), i0.ɵɵinject(i1.USE_DEFAULT_LANG), i0.ɵɵinject(i1.USE_STORE), i0.ɵɵinject(i1.USE_EXTEND), i0.ɵɵinject(i1.DEFAULT_LANGUAGE)); }, token: BBSFTranslateService, providedIn: "root" });
94
+ BBSFTranslateService.decorators = [
95
+ { type: Injectable, args: [{
96
+ providedIn: 'root'
97
+ },] }
98
+ ];
99
+
100
+ class RequestOptionsModel {
101
+ constructor() {
102
+ this.disableSuccessNotification = false;
103
+ this.disableBlockUI = false;
104
+ this.disableErrorHandler = false;
105
+ this.responseType = "";
106
+ this.formGroup = null;
107
+ this.castResponsetoClass = true;
108
+ }
109
+ }
110
+
111
+ class RequestHandlerService {
112
+ constructor(http, authService, environmentService, utilityService, bbsfTranslateService, router) {
113
+ //using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
114
+ this.http = http;
115
+ this.authService = authService;
116
+ this.environmentService = environmentService;
117
+ this.utilityService = utilityService;
118
+ this.bbsfTranslateService = bbsfTranslateService;
119
+ this.router = router;
120
+ this.requestOptions = new RequestOptionsModel();
121
+ this.currentLanguage = "";
122
+ this.onDestroy$ = new Subject();
123
+ this.bbsfTranslateService.onLangChange.subscribe((event) => {
124
+ if (this.currentLanguage != event.lang) {
125
+ this.currentLanguage = event.lang;
126
+ }
127
+ });
128
+ }
129
+ getLuckyNumber() {
130
+ return Observable.create((subject) => {
131
+ setInterval(() => {
132
+ const number = Math.floor(Math.random() * 10);
133
+ console.log(number);
134
+ subject.next(number);
135
+ }, 1000);
136
+ }).pipe(takeUntil(this.onDestroy$));
137
+ }
138
+ get(Url, params, responseType, requestOptions) {
139
+ if (requestOptions)
140
+ this.requestOptions = requestOptions;
141
+ let headers = this.getHeaders();
142
+ if (!this.requestOptions.disableBlockUI)
143
+ this.utilityService.startBlockUI();
144
+ let object;
145
+ return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
146
+ if (!this.requestOptions.disableBlockUI)
147
+ this.utilityService.stopBlockUI();
148
+ }, error => {
149
+ if (!this.requestOptions.disableErrorHandler)
150
+ this.handleError(error);
151
+ }), map((data) => {
152
+ if (this.requestOptions.castResponsetoClass)
153
+ return plainToClass(responseType, data, { excludeExtraneousValues: true });
154
+ else
155
+ return data;
156
+ }));
157
+ }
158
+ post(Url, model, responseType, params, requestOptions) {
159
+ if (requestOptions)
160
+ this.requestOptions = requestOptions;
161
+ let headers = this.getHeaders();
162
+ if (!this.requestOptions.disableBlockUI)
163
+ this.utilityService.startBlockUI();
164
+ return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
165
+ if (!this.requestOptions.disableBlockUI)
166
+ this.utilityService.stopBlockUI();
167
+ }, error => {
168
+ if (!this.requestOptions.disableErrorHandler)
169
+ this.handleError(error);
170
+ }), map((data) => {
171
+ if (this.requestOptions.castResponsetoClass)
172
+ return plainToClass(responseType, data, { excludeExtraneousValues: true });
173
+ else
174
+ return data;
175
+ }));
176
+ }
177
+ delete(Url, deletedId, requestOptions, responseType, params) {
178
+ if (requestOptions)
179
+ this.requestOptions = requestOptions;
180
+ let headers = this.getHeaders();
181
+ if (!this.requestOptions.disableBlockUI)
182
+ this.utilityService.startBlockUI();
183
+ return this.http.delete(this.environmentService.getApiUrl() + Url + `/${deletedId}`, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
184
+ if (!this.requestOptions.disableBlockUI)
185
+ this.utilityService.stopBlockUI();
186
+ }, error => {
187
+ if (!this.requestOptions.disableErrorHandler)
188
+ this.handleError(error);
189
+ }), map((data) => {
190
+ if (this.requestOptions.castResponsetoClass)
191
+ return plainToClass(responseType, data, { excludeExtraneousValues: true });
192
+ else
193
+ return data;
194
+ }));
195
+ }
196
+ put(Url, model, params, responseType, requestOptions) {
197
+ if (requestOptions)
198
+ this.requestOptions = requestOptions;
199
+ let headers = this.getHeaders();
200
+ if (!this.requestOptions.disableBlockUI)
201
+ this.utilityService.startBlockUI();
202
+ return this.http.put(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
203
+ if (!this.requestOptions.disableBlockUI)
204
+ this.utilityService.stopBlockUI();
205
+ }, error => {
206
+ if (!this.requestOptions.disableErrorHandler)
207
+ this.handleError(error);
208
+ }), map((data) => {
209
+ if (this.requestOptions.castResponsetoClass)
210
+ return plainToClass(responseType, data, { excludeExtraneousValues: true });
211
+ else
212
+ return data;
213
+ }));
214
+ }
215
+ patch(Url, model, responseType, params, requestOptions) {
216
+ if (requestOptions)
217
+ this.requestOptions = requestOptions;
218
+ let headers = new HttpHeaders({
219
+ 'Content-Type': 'application/json',
220
+ 'Authorization': this.authService.authorizationHeaderValue(),
221
+ });
222
+ this.currentLanguage = localStorage.getItem('language');
223
+ headers = headers.set('Accept-Language', this.currentLanguage.toString());
224
+ headers = headers.set('ignore-cookies', 'true');
225
+ if (!this.requestOptions.disableBlockUI)
226
+ this.utilityService.startBlockUI();
227
+ return this.http.patch(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
228
+ if (!this.requestOptions.disableBlockUI)
229
+ this.utilityService.stopBlockUI();
230
+ }, error => {
231
+ if (!this.requestOptions.disableErrorHandler)
232
+ this.handleError(error);
233
+ }), map((data) => {
234
+ if (this.requestOptions.castResponsetoClass)
235
+ return plainToClass(responseType, data, { excludeExtraneousValues: true });
236
+ else
237
+ return data;
238
+ }));
239
+ }
240
+ download(Url, params, requestOptions) {
241
+ if (requestOptions)
242
+ this.requestOptions = requestOptions;
243
+ let headers = this.getHeaders();
244
+ if (!this.requestOptions.disableBlockUI)
245
+ this.utilityService.startBlockUI();
246
+ return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
247
+ if (!this.requestOptions.disableBlockUI)
248
+ this.utilityService.stopBlockUI();
249
+ }, error => {
250
+ if (!this.requestOptions.disableErrorHandler)
251
+ this.handleError(error);
252
+ }));
253
+ }
254
+ destroyHandler() {
255
+ this.onDestroy$.next();
256
+ }
257
+ ngOnDestroy() {
258
+ console.log("clearInterval");
259
+ this.destroyHandler();
260
+ }
261
+ handleError(err) {
262
+ var isEnglish = this.utilityService.getCurrentLanguage() == "en";
263
+ if (err.error instanceof ErrorEvent) {
264
+ this.utilityService.notifyErrorMessage();
265
+ }
266
+ else {
267
+ if (err.status == 400)
268
+ throwError(err); //error 400 is thrown to be catch by the Form component to handle Fluent validation errors
269
+ else if (err.status == 401)
270
+ this.router.navigate(["/Admin/account/login"]);
271
+ else if (err.status == 403)
272
+ this.utilityService.notifyErrorMessage(isEnglish ? "Sorry, You're not authorized to access this action" : "عذرا ليس لديك الصلاحيه لهذا الطلب");
273
+ else if (err.status == 510)
274
+ this.utilityService.notifyErrorMessage(isEnglish ? "Can not delete this item as it is related to others" : "لا يمكن حذف هذا العنصر لأنه مرتبط بعناصر أخرى");
275
+ else if (err.status == 515)
276
+ this.utilityService.notifyErrorMessage((err.error ? err.error.Message : err.message));
277
+ else {
278
+ console.log(`error message is: ${err.error ? err.error.Message : err.message}`);
279
+ this.utilityService.notifyErrorMessage(this.utilityService.getResourceValue("ErrorMassage"));
280
+ }
281
+ }
282
+ this.utilityService.stopBlockUI();
283
+ }
284
+ getHeaders() {
285
+ return new HttpHeaders({
286
+ 'Content-Type': 'application/json',
287
+ 'Authorization': this.authService.authorizationHeaderValue(),
288
+ 'Client-Local-Time-Zone': Intl.DateTimeFormat().resolvedOptions().timeZone,
289
+ 'Accept-Language': localStorage.getItem('language'),
290
+ 'ignore-cookies': 'true'
291
+ });
292
+ }
293
+ }
294
+ RequestHandlerService.decorators = [
295
+ { type: Injectable }
296
+ ];
297
+ RequestHandlerService.ctorParameters = () => [
298
+ { type: HttpClient },
299
+ { type: AuthService },
300
+ { type: EnvironmentService },
301
+ { type: UtilityService },
302
+ { type: BBSFTranslateService },
303
+ { type: Router }
304
+ ];
305
+
306
+ class StylesBundleService {
307
+ constructor(document, translateService) {
308
+ this.document = document;
309
+ this.translateService = translateService;
310
+ }
311
+ loadThemes(lang, bundleEnglishName, bundleArabicName) {
312
+ if (lang == "ar") {
313
+ this.loadStyleBundle(bundleArabicName.toString());
314
+ document.querySelector('html').setAttribute("b-lang", "ar"); //use b-lang instead of lang to fix firefox number inputs in Arabic locale
315
+ document.querySelector('html').setAttribute("dir", "rtl");
316
+ }
317
+ else {
318
+ this.loadStyleBundle(bundleEnglishName.toString());
319
+ document.querySelector('html').setAttribute("b-lang", "en");
320
+ document.querySelector('html').setAttribute("dir", "ltr");
321
+ }
322
+ }
323
+ loadThemesColor(theme, bundleDarkName, bundleLightName) {
324
+ if (theme == "Light")
325
+ this.loadStyleBundle(bundleLightName.toString());
326
+ else
327
+ this.loadStyleBundle(bundleDarkName.toString());
328
+ }
329
+ loadStyleBundle(styleName) {
330
+ const head = this.document.getElementsByTagName('head')[0];
331
+ let themeLink = this.document.getElementById('client-theme');
332
+ if (themeLink && themeLink.href.includes(styleName)) {
333
+ return;
334
+ }
335
+ else if (themeLink && !themeLink.href.includes(styleName)) {
336
+ themeLink.remove();
337
+ }
338
+ const style = this.document.createElement('link');
339
+ style.id = 'client-theme';
340
+ style.rel = 'stylesheet';
341
+ style.href = `${styleName}`;
342
+ head.appendChild(style);
343
+ }
344
+ }
345
+ StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$1.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
346
+ StylesBundleService.decorators = [
347
+ { type: Injectable, args: [{
348
+ providedIn: 'root'
349
+ },] }
350
+ ];
351
+ StylesBundleService.ctorParameters = () => [
352
+ { type: Document, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
353
+ { type: BBSFTranslateService }
354
+ ];
355
+
356
+ class MasterLayoutService {
357
+ constructor(router, http, authService, stylesBundleService, translate, environmentService) {
358
+ this.router = router;
359
+ this.http = http;
360
+ this.authService = authService;
361
+ this.stylesBundleService = stylesBundleService;
362
+ this.translate = translate;
363
+ this.environmentService = environmentService;
364
+ this.ApiUrl = '/api/Home/';
365
+ }
366
+ switchLang(lang, bundleEnglishName, bundleArabicName) {
367
+ this.changeLanguage(lang).subscribe((result) => {
368
+ this.updateUserInfo().subscribe((Value) => {
369
+ let UserInfoObject = Value;
370
+ this.authService.getUser();
371
+ this.authService.user.profile = Object.assign(this.authService.user.profile, UserInfoObject);
372
+ this.authService.storUser(this.authService.user);
373
+ this.stylesBundleService.loadThemes(lang, bundleEnglishName, bundleArabicName);
374
+ localStorage.setItem('language', lang);
375
+ this.translate.use(lang);
376
+ });
377
+ });
378
+ }
379
+ reloadComponent() {
380
+ let currentUrl = this.router.url;
381
+ this.router.routeReuseStrategy.shouldReuseRoute = () => false;
382
+ this.router.onSameUrlNavigation = 'reload';
383
+ this.router.navigate([currentUrl]);
384
+ }
385
+ changeLanguage(key) {
386
+ let params = new HttpParams();
387
+ params = params.append('UserId', this.authService.user.profile.id);
388
+ params = params.append('LanguageKey', key);
389
+ return this.http.post(this.ApiUrl + 'UpdateLanguage', null, null, params);
390
+ }
391
+ getUserClaims() {
392
+ return this.http.get(this.ApiUrl + 'GetUserClaims', null, null);
393
+ }
394
+ logError(error) {
395
+ let params = new HttpParams();
396
+ params = params.append('error', error);
397
+ return this.http.post(this.ApiUrl + 'LogError', null, null, params);
398
+ }
399
+ updateUserInfo() {
400
+ let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() == 'true';
401
+ if (isExternal)
402
+ return this.getUserClaims();
403
+ return this.http.get('/connect/userinfo');
404
+ }
405
+ switchRole(permissionSetID) {
406
+ this.updateRole(permissionSetID).subscribe((result) => {
407
+ this.updateUserInfo().subscribe((Value) => {
408
+ let UserInfoObject = Value;
409
+ this.authService.getUser();
410
+ this.authService.user.profile = Object.assign(this.authService.user.profile, UserInfoObject);
411
+ this.authService.storUser(this.authService.user);
412
+ });
413
+ });
414
+ }
415
+ updateRole(permissionSetID) {
416
+ let params = new HttpParams();
417
+ params = params.append('UserId', this.authService.user.profile.id);
418
+ params = params.append('RoleID', permissionSetID);
419
+ return this.http.post(this.ApiUrl + 'SwitchRole', null, null, params);
420
+ }
421
+ }
422
+ MasterLayoutService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MasterLayoutService_Factory() { return new MasterLayoutService(i0.ɵɵinject(i1$2.Router), i0.ɵɵinject(RequestHandlerService), i0.ɵɵinject(AuthService), i0.ɵɵinject(StylesBundleService), i0.ɵɵinject(i1.TranslateService), i0.ɵɵinject(EnvironmentService)); }, token: MasterLayoutService, providedIn: "root" });
423
+ MasterLayoutService.decorators = [
424
+ { type: Injectable, args: [{
425
+ providedIn: 'root',
426
+ },] }
427
+ ];
428
+ MasterLayoutService.ctorParameters = () => [
429
+ { type: Router },
430
+ { type: RequestHandlerService },
431
+ { type: AuthService },
432
+ { type: StylesBundleService },
433
+ { type: TranslateService },
434
+ { type: EnvironmentService }
435
+ ];
436
+
437
+ class AuthService {
438
+ constructor(injector, http, environmentService, translateService, router) {
439
+ this.injector = injector;
440
+ this.http = http;
441
+ this.environmentService = environmentService;
442
+ this.translateService = translateService;
443
+ this.router = router;
444
+ // Observable navItem source
445
+ this._authNavStatusSource = new BehaviorSubject(false);
446
+ // Observable navItem stream
447
+ this.authNavStatus$ = this._authNavStatusSource.asObservable();
448
+ // Observable navItem source
449
+ this._userSource = new Subject();
450
+ this.UserStatus$ = this._userSource.asObservable();
451
+ this.manager = this.getUserManager();
452
+ this.redirectUrl = '';
453
+ this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
454
+ this.manager.storeUser(user);
455
+ AuthService.user = user;
456
+ this.user = user;
457
+ this._authNavStatusSource.next(yield this.isAuthenticated());
458
+ }));
459
+ this.manager.events.addAccessTokenExpired((_) => {
460
+ this._authNavStatusSource.next(false);
461
+ });
462
+ }
463
+ getUserManager() {
464
+ let user = null;
465
+ let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() ==
466
+ 'true';
467
+ if (isExternal) {
468
+ user = new UserManager({
469
+ authority: this.environmentService.getIdentityServerUrl(),
470
+ client_id: this.environmentService.getIsIdentityServerClientId(),
471
+ client_secret: this.environmentService.getIsIdentityServerClientSecret(),
472
+ redirect_uri: this.environmentService.getBaseUrl() +
473
+ '/Admin/authentication/auth-callback',
474
+ post_logout_redirect_uri: this.environmentService.getBaseUrl(),
475
+ response_type: 'code',
476
+ scope: 'openid profile email',
477
+ filterProtocolClaims: true,
478
+ loadUserInfo: true,
479
+ automaticSilentRenew: true,
480
+ silent_redirect_uri: this.environmentService.getBaseUrl() + '/assets/silent-callback.html',
481
+ userStore: new WebStorageStateStore({ store: window.localStorage }),
482
+ });
483
+ }
484
+ else {
485
+ user = new UserManager({
486
+ authority: this.environmentService.getIdentityServerUrl(),
487
+ client_id: 'angular_spa',
488
+ redirect_uri: this.environmentService.getBaseUrl() +
489
+ '/Admin/authentication/auth-callback',
490
+ post_logout_redirect_uri: this.environmentService.getBaseUrl(),
491
+ response_type: 'id_token token',
492
+ scope: 'openid profile email IdentityServerApi',
493
+ filterProtocolClaims: true,
494
+ loadUserInfo: true,
495
+ automaticSilentRenew: true,
496
+ silent_redirect_uri: this.environmentService.getBaseUrl() + '/assets/silent-callback.html',
497
+ userStore: new WebStorageStateStore({ store: window.localStorage }),
498
+ });
499
+ }
500
+ return user;
501
+ }
502
+ login() {
503
+ return this.manager.signinRedirect();
504
+ }
505
+ getUser() {
506
+ this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
507
+ AuthService.user = user;
508
+ this.user = user;
509
+ this._authNavStatusSource.next(yield this.isAuthenticated());
510
+ }));
511
+ }
512
+ storUser(User) {
513
+ this.manager.storeUser(User);
514
+ }
515
+ revokeAccessToken() {
516
+ this.manager.revokeAccessToken();
517
+ }
518
+ signinSilent() {
519
+ let x = this.manager.signinSilentCallback();
520
+ x.then((s) => {
521
+ //console.log(s)
522
+ });
523
+ }
524
+ completeAuthentication() {
525
+ return __awaiter(this, void 0, void 0, function* () {
526
+ this.user = yield this.manager.signinRedirectCallback();
527
+ AuthService.user = this.user;
528
+ this._userSource.next(AuthService.user);
529
+ this._authNavStatusSource.next(yield this.isAuthenticated());
530
+ let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() ==
531
+ 'true';
532
+ if (isExternal) {
533
+ const masterLayoutService = this.injector.get(MasterLayoutService);
534
+ let userClaims = yield masterLayoutService.getUserClaims().toPromise()
535
+ .then((e) => {
536
+ AuthService.UserClaims = e;
537
+ }, (error) => {
538
+ console.log(error);
539
+ });
540
+ AuthService.user.profile = Object.assign(AuthService.user.profile, AuthService.UserClaims);
541
+ }
542
+ this.storUser(AuthService.user);
543
+ if (!localStorage.getItem('language') ||
544
+ localStorage.getItem('language') == this.user.profile.locale)
545
+ localStorage.setItem('language', this.user.profile.locale);
546
+ if (this.translateService.currentLang != localStorage.getItem('language')) {
547
+ this.translateService.resetLang(this.translateService.currentLang);
548
+ yield this.translateService
549
+ .reloadLang(localStorage.getItem('language'))
550
+ .subscribe((res) => {
551
+ console.log(res);
552
+ });
553
+ }
554
+ this._userSource.next(AuthService.user);
555
+ this._authNavStatusSource.next(yield this.isAuthenticated());
556
+ this.user = AuthService.user;
557
+ });
558
+ }
559
+ refreshToken(token) {
560
+ return __awaiter(this, void 0, void 0, function* () {
561
+ const httpOptions = {
562
+ headers: new HttpHeaders({
563
+ 'Content-Type': 'application/json',
564
+ Authorization: token,
565
+ }),
566
+ };
567
+ this.manager.revokeAccessToken();
568
+ return yield this.http
569
+ .post(`${this.environmentService.getIdentityServerUrl()}/users/refresh-token`, httpOptions, { withCredentials: true })
570
+ .subscribe((user) => {
571
+ this._userSource.next(user);
572
+ AuthService.user = user;
573
+ this.user = user;
574
+ });
575
+ });
576
+ }
577
+ getCurrentUser() {
578
+ return this.manager.getUser();
579
+ }
580
+ isAuthenticated() {
581
+ return __awaiter(this, void 0, void 0, function* () {
582
+ let user = yield this.manager.getUser().then((user) => {
583
+ return user;
584
+ });
585
+ return this.user != null && !this.user.expired;
586
+ });
587
+ }
588
+ isUserInRole(allowedPermission) {
589
+ let selectedPermissionSetID = Number.parseInt(this.user.profile['selectedpermissionsetid']);
590
+ return allowedPermission.includes(selectedPermissionSetID);
591
+ }
592
+ authorizationHeaderValue() {
593
+ return AuthService.user
594
+ ? `${AuthService.user.token_type} ${AuthService.user.access_token}`
595
+ : '';
596
+ }
597
+ name() {
598
+ return AuthService.user != null ? AuthService.user.profile.given_name : '';
599
+ }
600
+ setUrl(url) {
601
+ localStorage.setItem('redirectUrl', url);
602
+ }
603
+ getUrl() {
604
+ return localStorage.getItem('redirectUrl');
605
+ }
606
+ signinSilentCallback() {
607
+ return __awaiter(this, void 0, void 0, function* () {
608
+ let user = yield this.manager.signinSilentCallback();
609
+ //await this.manager.storeUser(user);
610
+ AuthService.user = user;
611
+ console.log('Token from signinSilentCallback :' + AuthService.user);
612
+ this.user = user;
613
+ });
614
+ }
615
+ signout() {
616
+ return __awaiter(this, void 0, void 0, function* () {
617
+ if (yield !this.isAuthenticated())
618
+ this.router.navigate(['/Admin/account/login']), localStorage.clear();
619
+ let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() ==
620
+ 'true';
621
+ if (isExternal) {
622
+ yield this.clearUserSessionClaims()
623
+ .toPromise()
624
+ .then((res) => {
625
+ let result = res;
626
+ });
627
+ }
628
+ yield this.manager.signoutRedirect();
629
+ });
630
+ }
631
+ clearUserSessionClaims() {
632
+ const httpOptions = {
633
+ headers: new HttpHeaders({
634
+ 'Content-Type': 'application/json',
635
+ }),
636
+ };
637
+ let ApiUrl = '/api/Home/';
638
+ return this.http.get(this.environmentService.getBaseUrl() + ApiUrl + 'ClearCurrentUserSession', httpOptions);
639
+ }
640
+ }
641
+ AuthService.user = null;
642
+ AuthService.UserClaims = null;
643
+ AuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(i1$3.HttpClient), i0.ɵɵinject(EnvironmentService), i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(i1$2.Router)); }, token: AuthService, providedIn: "root" });
644
+ AuthService.decorators = [
645
+ { type: Injectable, args: [{
646
+ providedIn: 'root',
647
+ },] }
648
+ ];
649
+ AuthService.ctorParameters = () => [
650
+ { type: Injector },
651
+ { type: HttpClient },
652
+ { type: EnvironmentService },
653
+ { type: BBSFTranslateService },
654
+ { type: Router }
655
+ ];
656
+
657
+ class UtilityService {
658
+ constructor(translator, authService, environmentService) {
659
+ this.translator = translator;
660
+ this.authService = authService;
661
+ this.environmentService = environmentService;
662
+ this.isCreatedBefore = false;
663
+ }
664
+ getResourceValue(Key) {
665
+ let ResourceValue = this.translator.instant(Key);
666
+ return ResourceValue;
667
+ }
668
+ getCurrentLanguage() {
669
+ let currentLanguage = this.environmentService.getDefaultLanguage();
670
+ let lang = localStorage.getItem('language');
671
+ if (lang)
672
+ currentLanguage = lang;
673
+ else
674
+ localStorage.setItem('language', currentLanguage);
675
+ return currentLanguage;
676
+ }
677
+ isCurrentLanguageEnglish() {
678
+ return this.getCurrentLanguage() == "en";
679
+ }
680
+ isCurrentLanguageArabic() {
681
+ return this.getCurrentLanguage() == "ar";
682
+ }
683
+ notifySuccessMessage(Message, title, time, showHeader = true) {
684
+ let MessageTemplate = this.getResourceValue("SuccessMessage");
685
+ let titleTemplate;
686
+ if (Message) {
687
+ MessageTemplate = Message;
688
+ }
689
+ if (title) {
690
+ titleTemplate = title;
691
+ }
692
+ let toaster = AppInjector.get(ToastrService);
693
+ showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
694
+ }
695
+ notifyErrorMessage(Message, title, time, showHeader = true) {
696
+ let MessageTemplate = this.getResourceValue("ErrorMessage");
697
+ let titleTemplate = this.getResourceValue("Error");
698
+ if (Message) {
699
+ MessageTemplate = Message;
700
+ }
701
+ if (title) {
702
+ titleTemplate = title;
703
+ }
704
+ const toaster = AppInjector.get(ToastrService);
705
+ showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
706
+ }
707
+ notifyWarningMessage(Message, title, time, showHeader = true) {
708
+ let MessageTemplate = this.getResourceValue("WarningMessage");
709
+ let titleTemplate = this.getResourceValue("Warning");
710
+ if (Message) {
711
+ MessageTemplate = Message;
712
+ }
713
+ if (title) {
714
+ titleTemplate = title;
715
+ }
716
+ const toaster = AppInjector.get(ToastrService);
717
+ showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
718
+ }
719
+ startBlockUI() {
720
+ this.blockUI.start();
721
+ }
722
+ stopBlockUI() {
723
+ this.blockUI.stop();
724
+ }
725
+ }
726
+ UtilityService.ɵprov = i0.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(AuthService), i0.ɵɵinject(EnvironmentService)); }, token: UtilityService, providedIn: "root" });
727
+ UtilityService.decorators = [
728
+ { type: Injectable, args: [{
729
+ providedIn: 'root'
730
+ },] }
731
+ ];
732
+ UtilityService.ctorParameters = () => [
733
+ { type: BBSFTranslateService },
734
+ { type: AuthService },
735
+ { type: EnvironmentService }
736
+ ];
737
+ __decorate([
738
+ BlockUI()
739
+ ], UtilityService.prototype, "blockUI", void 0);
740
+
741
+ class ControlValidationService {
742
+ constructor(utilityService) {
743
+ this.utilityService = utilityService;
744
+ this.requestOptions = new RequestOptionsModel();
745
+ this.isCreatedBefor = false;
746
+ }
747
+ showGlobalError(errorMessage, formId, deleteOld) {
748
+ let globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
749
+ if (globalErorrElement.length > 0) {
750
+ this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
751
+ }
752
+ if (this.isCreatedBefor == true) {
753
+ this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
754
+ }
755
+ // tslint:disable-next-line: prefer-const
756
+ if (!formId)
757
+ formId = "currentForm";
758
+ var object = document.getElementById(formId);
759
+ const tagName = 'div';
760
+ // tslint:disable-next-line: prefer-const
761
+ var elementToAppend = document.createElement(tagName); // Your tag name here
762
+ let message = "";
763
+ if (!errorMessage || (typeof errorMessage == "string")) {
764
+ if (localStorage.getItem('language') == "ar")
765
+ message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
766
+ else
767
+ message = errorMessage ? errorMessage : "You have some validation errors. Please check below";
768
+ elementToAppend.innerHTML = "<ul class='list-unstyled m-0 py-3 d-flex align-items-center fs-6'><li><i class='fa fa-times-circle text-danger me-3 fs-2'></i>" + message + "</li></ul>";
769
+ elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
770
+ elementToAppend.id += 'errorId';
771
+ // tslint:disable-next-line: prefer-for-of
772
+ const elementToAppen = elementToAppend.cloneNode(true);
773
+ // let targetElement = object.getElementsByClassName("b-control")[0];
774
+ object.insertBefore(elementToAppen, object.firstChild);
775
+ }
776
+ else {
777
+ let ul = document.createElement("ul");
778
+ elementToAppend.appendChild(ul);
779
+ for (const iterator of errorMessage) {
780
+ let li = document.createElement("li");
781
+ li.innerHTML = iterator;
782
+ ul.appendChild(li);
783
+ }
784
+ elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
785
+ elementToAppend.id += 'errorId';
786
+ // tslint:disable-next-line: prefer-for-of
787
+ const elementToAppen = elementToAppend.cloneNode(true);
788
+ // let targetElement = object.getElementsByClassName("b-control")[0];
789
+ object.insertBefore(elementToAppen, object.firstChild);
790
+ }
791
+ this.isCreatedBefor = true;
792
+ }
793
+ RemoveGlobalError() {
794
+ const removedList = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
795
+ // tslint:disable-next-line: prefer-for-of
796
+ for (let index = 0; index < removedList.length; index++) {
797
+ const element = removedList[index];
798
+ element.remove();
799
+ }
800
+ this.isCreatedBefor = false;
801
+ }
802
+ showInputErro(errors) {
803
+ // show error on top of form
804
+ this.showGlobalError();
805
+ // remove old error from server
806
+ this.removeElementsByClass('errortemplet');
807
+ // Looping in error Object
808
+ for (const key in errors) {
809
+ if (errors.hasOwnProperty(key)) {
810
+ for (const iterator of errors[key]) {
811
+ const input = document.querySelectorAll('[ng-reflect-name=' + key + ']')[0];
812
+ if (input.attributes['ng-reflect-name'].value === key) {
813
+ this.removeElementsByClass('erroclass-' + key);
814
+ const tagName = 'p';
815
+ const elementToAppend = document.createElement(tagName); // Your tag name here
816
+ elementToAppend.innerHTML = iterator;
817
+ elementToAppend.style.color = 'red';
818
+ elementToAppend.className += 'errortemplet erroclass-' + key;
819
+ const elementToappen = elementToAppend.cloneNode(true);
820
+ input.parentNode.insertBefore(elementToappen, input.lastChild);
821
+ break;
822
+ }
823
+ }
824
+ }
825
+ }
826
+ }
827
+ removeElementsByClass(className) {
828
+ const elements = document.getElementsByClassName(className);
829
+ while (elements.length > 0) {
830
+ elements[0].parentNode.removeChild(elements[0]);
831
+ }
832
+ }
833
+ renderServerErrors(form, err, requestOptions, formId) {
834
+ if (err.error == null) {
835
+ return;
836
+ }
837
+ let errorsArray = [];
838
+ this.requestOptions = requestOptions;
839
+ if (err.error.validation_errors) {
840
+ err.error.validation_errors.forEach((element) => {
841
+ let fieldName = element.field;
842
+ let controlName = element.controlName;
843
+ let message = element.message;
844
+ if (form == null) {
845
+ this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${message}`);
846
+ }
847
+ else if (controlName && !this.hasControlName(form, controlName)) {
848
+ errorsArray.push(`${fieldName}: ${message}`);
849
+ }
850
+ else {
851
+ this.setFieldError(form, controlName, fieldName, message);
852
+ this.showGlobalError(null, formId);
853
+ }
854
+ });
855
+ if (errorsArray.length > 0)
856
+ this.showGlobalError(errorsArray, formId);
857
+ }
858
+ }
859
+ hasControlName(form, controlName) {
860
+ let control = form.get(controlName);
861
+ return control != null;
862
+ }
863
+ setFieldError(form, controlName, fieldName, message) {
864
+ let control = null;
865
+ if (controlName)
866
+ control = this.getControlFormNameByFieldName(form, controlName);
867
+ else
868
+ control = this.getControlFormNameByFieldName(form, fieldName.split('.')[0]);
869
+ let errors = { "errorMassage": message };
870
+ let fieldNameArray = fieldName.split('.');
871
+ if (fieldNameArray.length >= 1) {
872
+ switch (fieldNameArray[fieldNameArray.length - 1].toLocaleLowerCase()) {
873
+ case "english":
874
+ let englishControl = control.get("English");
875
+ englishControl.setErrors(errors);
876
+ break;
877
+ case "arabic":
878
+ let arabicControl = control.get("Arabic");
879
+ arabicControl.setErrors(errors);
880
+ break;
881
+ default:
882
+ control.setErrors(errors);
883
+ }
884
+ }
885
+ else {
886
+ this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${message}`);
887
+ }
888
+ }
889
+ getControlFormNameByFieldName(form, fieldName) {
890
+ const formControls = form.controls;
891
+ let controlName = Object.keys(formControls).find(c => c.toLocaleLowerCase() === fieldName.toLocaleLowerCase());
892
+ let control = form.get(controlName);
893
+ return control;
894
+ }
895
+ }
896
+ ControlValidationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ControlValidationService_Factory() { return new ControlValidationService(i0.ɵɵinject(UtilityService)); }, token: ControlValidationService, providedIn: "root" });
897
+ ControlValidationService.decorators = [
898
+ { type: Injectable, args: [{
899
+ providedIn: 'root'
900
+ },] }
901
+ ];
902
+ ControlValidationService.ctorParameters = () => [
903
+ { type: UtilityService }
904
+ ];
905
+ __decorate([
906
+ BlockUI()
907
+ ], ControlValidationService.prototype, "blockUI", void 0);
908
+
909
+ class ConfigurationService {
910
+ constructor(httpClient) {
911
+ this.httpClient = httpClient;
912
+ this.httpClient.get("./assets/config/configurations.json").subscribe(data => {
913
+ ConfigurationService.JsonData = data;
914
+ });
915
+ }
916
+ getConfigurationValue(key) {
917
+ return ConfigurationService.JsonData[key];
918
+ }
919
+ }
920
+ ConfigurationService.JsonData = [];
921
+ ConfigurationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ConfigurationService_Factory() { return new ConfigurationService(i0.ɵɵinject(i1$3.HttpClient)); }, token: ConfigurationService, providedIn: "root" });
922
+ ConfigurationService.decorators = [
923
+ { type: Injectable, args: [{
924
+ providedIn: 'root'
925
+ },] }
926
+ ];
927
+ ConfigurationService.ctorParameters = () => [
928
+ { type: HttpClient }
929
+ ];
930
+
931
+ let AppInjector;
932
+ class BBSFUtilitiesModule {
933
+ constructor(injector) {
934
+ this.injector = injector;
935
+ AppInjector = this.injector;
936
+ }
937
+ }
938
+ BBSFUtilitiesModule.decorators = [
939
+ { type: NgModule, args: [{
940
+ declarations: [],
941
+ imports: [
942
+ CommonModule,
943
+ BlockUIModule.forRoot(),
944
+ HttpModule,
945
+ RouterModule,
946
+ ToastrModule.forRoot(),
947
+ ],
948
+ exports: [],
949
+ providers: [
950
+ UtilityService,
951
+ EnvironmentService,
952
+ AuthService,
953
+ RequestHandlerService,
954
+ StylesBundleService,
955
+ TranslateService,
956
+ BBSFTranslateService,
957
+ ControlValidationService,
958
+ MasterLayoutService,
959
+ ConfigurationService
960
+ ]
961
+ },] }
962
+ ];
963
+ BBSFUtilitiesModule.ctorParameters = () => [
964
+ { type: Injector }
965
+ ];
966
+
967
+ class TranslationResolverService {
968
+ constructor(translateService) {
969
+ this.translateService = translateService;
970
+ }
971
+ resolve() {
972
+ return this.translateService.getTranslation(this.translateService.currentLang);
973
+ }
974
+ }
975
+ TranslationResolverService.ɵprov = i0.ɵɵdefineInjectable({ factory: function TranslationResolverService_Factory() { return new TranslationResolverService(i0.ɵɵinject(BBSFTranslateService)); }, token: TranslationResolverService, providedIn: "root" });
976
+ TranslationResolverService.decorators = [
977
+ { type: Injectable, args: [{ providedIn: 'root' },] }
978
+ ];
979
+ TranslationResolverService.ctorParameters = () => [
980
+ { type: BBSFTranslateService }
981
+ ];
982
+
983
+ class AppearanceConfigurationService {
984
+ constructor(configService) {
985
+ this.configService = configService;
986
+ }
987
+ getLayoutTheme() {
988
+ return this.configService.getConfigurationValue('AnonymousLayout_Theme');
989
+ }
990
+ getFooterText() {
991
+ return this.configService.getConfigurationValue('AnonymousLayout_FooterText');
992
+ }
993
+ getPageTitle() {
994
+ return this.configService.getConfigurationValue('AnonymousLayout_PageTitle');
995
+ }
996
+ getFavIcon() {
997
+ return this.configService.getConfigurationValue('AnonymousLayout_FavIcon');
998
+ }
999
+ getCustomStyles() {
1000
+ return this.configService.getConfigurationValue('AnonymousLayout_CustomStyles');
1001
+ }
1002
+ getLogo() {
1003
+ return this.configService.getConfigurationValue('AnonymousLayout_Logo');
1004
+ }
1005
+ }
1006
+ AppearanceConfigurationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AppearanceConfigurationService_Factory() { return new AppearanceConfigurationService(i0.ɵɵinject(ConfigurationService)); }, token: AppearanceConfigurationService, providedIn: "root" });
1007
+ AppearanceConfigurationService.decorators = [
1008
+ { type: Injectable, args: [{
1009
+ providedIn: 'root'
1010
+ },] }
1011
+ ];
1012
+ AppearanceConfigurationService.ctorParameters = () => [
1013
+ { type: ConfigurationService }
1014
+ ];
1015
+
1016
+ const contentTypesXML = `
1017
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1018
+
1019
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
1020
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
1021
+ <Default Extension="jpeg" ContentType="image/jpeg"/>
1022
+ <Default Extension="png" ContentType="image/png"/>
1023
+ <Default Extension="xml" ContentType="application/xml"/>
1024
+ <Override PartName="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
1025
+ <Override PartName="/word/_rels/document.xml.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
1026
+ <Override PartName="/word/_rels/footer1.xml.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
1027
+ <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
1028
+ <Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
1029
+ <Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>
1030
+ <Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
1031
+ <Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"/>
1032
+ <Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
1033
+ <Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"/>
1034
+ <Override PartName="/word/webSettings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"/>
1035
+ <Override PartName="/word/afchunk.mht" ContentType="message/rfc822"/>
1036
+ <Override PartName="/word/afchunkheader.mht" ContentType="message/rfc822"/>
1037
+ <Override PartName="/word/afchunkfooter.mht" ContentType="message/rfc822"/>
1038
+ </Types>
1039
+ `;
1040
+
1041
+ const namespaces = {
1042
+ a: 'http://schemas.openxmlformats.org/drawingml/2006/main',
1043
+ b: 'http://schemas.openxmlformats.org/officeDocument/2006/bibliography',
1044
+ cdr: 'http://schemas.openxmlformats.org/drawingml/2006/chartDrawing',
1045
+ dc: 'http://purl.org/dc/elements/1.1/',
1046
+ dcmitype: 'http://purl.org/dc/dcmitype/',
1047
+ dcterms: 'http://purl.org/dc/terms/',
1048
+ o: 'urn:schemas-microsoft-com:office:office',
1049
+ pic: 'http://schemas.openxmlformats.org/drawingml/2006/picture',
1050
+ r: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
1051
+ v: 'urn:schemas-microsoft-com:vml',
1052
+ ve: 'http://schemas.openxmlformats.org/markup-compatibility/2006',
1053
+ vt: 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes',
1054
+ w: 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
1055
+ w10: 'urn:schemas-microsoft-com:office:word',
1056
+ wp: 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing',
1057
+ wne: 'http://schemas.microsoft.com/office/word/2006/wordml',
1058
+ xsd: 'http://www.w3.org/2001/XMLSchema',
1059
+ xsi: 'http://www.w3.org/2001/XMLSchema-instance',
1060
+ numbering: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
1061
+ hyperlinks: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
1062
+ images: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
1063
+ styles: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
1064
+ headers: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header',
1065
+ footers: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer',
1066
+ themes: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
1067
+ coreProperties: 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
1068
+ officeDocumentRelation: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
1069
+ corePropertiesRelation: 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
1070
+ settingsRelation: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
1071
+ webSettingsRelation: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
1072
+ sl: 'http://schemas.openxmlformats.org/schemaLibrary/2006/main',
1073
+ contentTypes: 'http://schemas.openxmlformats.org/package/2006/content-types',
1074
+ relationship: 'http://schemas.openxmlformats.org/package/2006/relationships',
1075
+ };
1076
+
1077
+ const applicationName = 'html-to-docx';
1078
+ const defaultOrientation = 'portrait';
1079
+ const landscapeWidth = 15840;
1080
+ const landscapeHeight = 12240;
1081
+ const landscapeMargins = {
1082
+ top: 1800,
1083
+ right: 1440,
1084
+ bottom: 1800,
1085
+ left: 1440,
1086
+ header: 720,
1087
+ footer: 720,
1088
+ gutter: 0,
1089
+ };
1090
+ const portraitMargins = {
1091
+ top: 1440,
1092
+ right: 1800,
1093
+ bottom: 1440,
1094
+ left: 1800,
1095
+ header: 720,
1096
+ footer: 720,
1097
+ gutter: 0,
1098
+ };
1099
+ const defaultFont = 'Times New Roman';
1100
+ const defaultFontSize = 22;
1101
+ const defaultDocumentOptions = {
1102
+ orientation: defaultOrientation,
1103
+ margins: cloneDeep(portraitMargins),
1104
+ title: '',
1105
+ subject: '',
1106
+ creator: applicationName,
1107
+ keywords: [applicationName],
1108
+ description: '',
1109
+ lastModifiedBy: applicationName,
1110
+ revision: 1,
1111
+ createdAt: new Date(),
1112
+ modifiedAt: new Date(),
1113
+ headerType: 'default',
1114
+ header: false,
1115
+ footerType: 'default',
1116
+ footer: false,
1117
+ font: defaultFont,
1118
+ fontSize: defaultFontSize,
1119
+ complexScriptFontSize: defaultFontSize,
1120
+ table: {
1121
+ row: {
1122
+ cantSplit: false,
1123
+ },
1124
+ },
1125
+ pageSize: {
1126
+ width: landscapeHeight,
1127
+ height: landscapeWidth,
1128
+ },
1129
+ pageNumber: false,
1130
+ skipFirstHeaderFooter: false,
1131
+ lineNumber: false,
1132
+ lineNumberOptions: {
1133
+ countBy: 1,
1134
+ start: 0,
1135
+ restart: 'continuous',
1136
+ },
1137
+ numbering: {
1138
+ defaultOrderedListStyleType: 'decimal',
1139
+ },
1140
+ };
1141
+ const defaultHTMLString = '<p></p>';
1142
+ const relsFolderName = '_rels';
1143
+ const headerFileName = 'header1';
1144
+ const footerFileName = 'footer1';
1145
+ const themeFileName = 'theme1';
1146
+ const documentFileName = 'document';
1147
+ const headerType = 'header';
1148
+ const footerType = 'footer';
1149
+ const themeType = 'theme';
1150
+ const hyperlinkType = 'hyperlink';
1151
+ const imageType = 'image';
1152
+ const internalRelationship = 'Internal';
1153
+ const wordFolder = 'word';
1154
+ const themeFolder = 'theme';
1155
+ const paragraphBordersObject = {
1156
+ top: {
1157
+ size: 0,
1158
+ spacing: 3,
1159
+ color: 'FFFFFF',
1160
+ },
1161
+ left: {
1162
+ size: 0,
1163
+ spacing: 3,
1164
+ color: 'FFFFFF',
1165
+ },
1166
+ bottom: {
1167
+ size: 0,
1168
+ spacing: 3,
1169
+ color: 'FFFFFF',
1170
+ },
1171
+ right: {
1172
+ size: 0,
1173
+ spacing: 3,
1174
+ color: 'FFFFFF',
1175
+ },
1176
+ };
1177
+ const colorlessColors = ['transparent', 'auto'];
1178
+ const verticalAlignValues = ['top', 'middle', 'bottom'];
1179
+
1180
+ const generateCoreXML = (title = '', subject = '', creator = applicationName, keywords = [applicationName], description = '', lastModifiedBy = applicationName, revision = 1, createdAt = new Date(), modifiedAt = new Date()) => `
1181
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1182
+
1183
+ <cp:coreProperties
1184
+ xmlns:cp="${namespaces.coreProperties}"
1185
+ xmlns:dc="${namespaces.dc}"
1186
+ xmlns:dcterms="${namespaces.dcterms}"
1187
+ xmlns:dcmitype="${namespaces.dcmitype}"
1188
+ xmlns:xsi="${namespaces.xsi}"
1189
+ >
1190
+ <dc:title>${title}</dc:title>
1191
+ <dc:subject>${subject}</dc:subject>
1192
+ <dc:creator>${creator}</dc:creator>
1193
+ ${keywords && Array.isArray(keywords)
1194
+ ? `<cp:keywords>${keywords.join(', ')}</cp:keywords>`
1195
+ : ''}
1196
+ <dc:description>${description}</dc:description>
1197
+ <cp:lastModifiedBy>${lastModifiedBy}</cp:lastModifiedBy>
1198
+ <cp:revision>${revision}</cp:revision>
1199
+ <dcterms:created xsi:type="dcterms:W3CDTF">${createdAt instanceof Date ? createdAt.toISOString() : new Date().toISOString()}</dcterms:created>
1200
+ <dcterms:modified xsi:type="dcterms:W3CDTF">${modifiedAt instanceof Date ? modifiedAt.toISOString() : new Date().toISOString()}</dcterms:modified>
1201
+ </cp:coreProperties>
1202
+ `;
1203
+ const ɵ0$8 = generateCoreXML;
1204
+
1205
+ const documentRelsXML = `
1206
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1207
+
1208
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
1209
+ <Relationship Id="rId1" Type="${namespaces.numbering}" Target="numbering.xml"/>
1210
+ <Relationship Id="rId2" Type="${namespaces.styles}" Target="styles.xml"/>
1211
+ <Relationship Id="rId3" Type="${namespaces.settingsRelation}" Target="settings.xml"/>
1212
+ <Relationship Id="rId4" Type="${namespaces.webSettingsRelation}" Target="webSettings.xml"/>
1213
+ <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunk.mht" Id="htmlChunk" />
1214
+ <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunkheader.mht" Id="htmlChunkHeader" />
1215
+ <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunkfooter.mht" Id="htmlChunkFooter" />
1216
+ </Relationships>
1217
+ `;
1218
+
1219
+ const relsXML = `
1220
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1221
+
1222
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
1223
+ <Relationship Id="rId1" Type="${namespaces.officeDocumentRelation}" Target="word/document.xml"/>
1224
+ <Relationship Id="rId2" Type="${namespaces.corePropertiesRelation}" Target="docProps/core.xml"/>
1225
+ </Relationships>
1226
+ `;
1227
+
1228
+ const generateNumberingXMLTemplate = () => `
1229
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1230
+
1231
+ <w:numbering
1232
+ xmlns:w="${namespaces.w}"
1233
+ xmlns:ve="${namespaces.ve}"
1234
+ xmlns:o="${namespaces.o}"
1235
+ xmlns:r="${namespaces.r}"
1236
+ xmlns:v="${namespaces.v}"
1237
+ xmlns:wp="${namespaces.wp}"
1238
+ xmlns:w10="${namespaces.w10}"
1239
+ xmlns:wne="${namespaces.wne}">
1240
+ </w:numbering>
1241
+ `;
1242
+ const ɵ0$7 = generateNumberingXMLTemplate;
1243
+
1244
+ const generateStylesXML = (font = defaultFont, fontSize = defaultFontSize, complexScriptFontSize = defaultFontSize) => `
1245
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1246
+
1247
+ <w:styles xmlns:w="${namespaces.w}" xmlns:r="${namespaces.r}">
1248
+ <w:docDefaults>
1249
+ <w:rPrDefault>
1250
+ <w:rPr>
1251
+ <w:rFonts w:ascii="${font}" w:eastAsiaTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi" w:cstheme="minorBidi" />
1252
+ <w:sz w:val="${fontSize}" />
1253
+ <w:szCs w:val="${complexScriptFontSize}" />
1254
+ <w:lang w:val="en-US" w:eastAsia="en-US" w:bidi="ar-SA" />
1255
+ </w:rPr>
1256
+ </w:rPrDefault>
1257
+ <w:pPrDefault>
1258
+ <w:pPr>
1259
+ <w:spacing w:after="120" w:line="240" w:lineRule="atLeast" />
1260
+ </w:pPr>
1261
+ </w:pPrDefault>
1262
+ </w:docDefaults>
1263
+ <w:style w:type="character" w:styleId="Hyperlink">
1264
+ <w:name w:val="Hyperlink" />
1265
+ <w:rPr>
1266
+ <w:color w:val="0000FF" />
1267
+ <w:u w:val="single" />
1268
+ </w:rPr>
1269
+ </w:style>
1270
+ <w:style w:type="paragraph" w:styleId="Heading1">
1271
+ <w:name w:val="heading 1" />
1272
+ <w:basedOn w:val="Normal" />
1273
+ <w:next w:val="Normal" />
1274
+ <w:uiPriority w:val="9" />
1275
+ <w:qFormat />
1276
+ <w:pPr>
1277
+ <w:keepNext />
1278
+ <w:keepLines />
1279
+ <w:spacing w:before="480" />
1280
+ <w:outlineLvl w:val="0" />
1281
+ </w:pPr>
1282
+ <w:rPr>
1283
+ <w:b />
1284
+ <w:sz w:val="48" />
1285
+ <w:szCs w:val="48" />
1286
+ </w:rPr>
1287
+ </w:style>
1288
+ <w:style w:type="paragraph" w:styleId="Heading2">
1289
+ <w:name w:val="heading 2" />
1290
+ <w:basedOn w:val="Normal" />
1291
+ <w:next w:val="Normal" />
1292
+ <w:uiPriority w:val="9" />
1293
+ <w:unhideWhenUsed />
1294
+ <w:qFormat />
1295
+ <w:pPr>
1296
+ <w:keepNext />
1297
+ <w:keepLines />
1298
+ <w:spacing w:before="360" w:after="80" />
1299
+ <w:outlineLvl w:val="1" />
1300
+ </w:pPr>
1301
+ <w:rPr>
1302
+ <w:b />
1303
+ <w:sz w:val="36" />
1304
+ <w:szCs w:val="36" />
1305
+ </w:rPr>
1306
+ </w:style>
1307
+ <w:style w:type="paragraph" w:styleId="Heading3">
1308
+ <w:name w:val="heading 3" />
1309
+ <w:basedOn w:val="Normal" />
1310
+ <w:next w:val="Normal" />
1311
+ <w:uiPriority w:val="9" />
1312
+ <w:semiHidden />
1313
+ <w:unhideWhenUsed />
1314
+ <w:qFormat />
1315
+ <w:pPr>
1316
+ <w:keepNext />
1317
+ <w:keepLines />
1318
+ <w:spacing w:before="280" w:after="80" />
1319
+ <w:outlineLvl w:val="2" />
1320
+ </w:pPr>
1321
+ <w:rPr>
1322
+ <w:b />
1323
+ <w:sz w:val="28" />
1324
+ <w:szCs w:val="28" />
1325
+ </w:rPr>
1326
+ </w:style>
1327
+ <w:style w:type="paragraph" w:styleId="Heading4">
1328
+ <w:name w:val="heading 4" />
1329
+ <w:basedOn w:val="Normal" />
1330
+ <w:next w:val="Normal" />
1331
+ <w:uiPriority w:val="9" />
1332
+ <w:semiHidden />
1333
+ <w:unhideWhenUsed />
1334
+ <w:qFormat />
1335
+ <w:pPr>
1336
+ <w:keepNext />
1337
+ <w:keepLines />
1338
+ <w:spacing w:before="240" w:after="40" />
1339
+ <w:outlineLvl w:val="3" />
1340
+ </w:pPr>
1341
+ <w:rPr>
1342
+ <w:b />
1343
+ <w:sz w:val="24" />
1344
+ <w:szCs w:val="24" />
1345
+ </w:rPr>
1346
+ </w:style>
1347
+ <w:style w:type="paragraph" w:styleId="Heading5">
1348
+ <w:name w:val="heading 5" />
1349
+ <w:basedOn w:val="Normal" />
1350
+ <w:next w:val="Normal" />
1351
+ <w:uiPriority w:val="9" />
1352
+ <w:semiHidden />
1353
+ <w:unhideWhenUsed />
1354
+ <w:qFormat />
1355
+ <w:pPr>
1356
+ <w:keepNext />
1357
+ <w:keepLines />
1358
+ <w:spacing w:before="220" w:after="40" />
1359
+ <w:outlineLvl w:val="4" />
1360
+ </w:pPr>
1361
+ <w:rPr>
1362
+ <w:b />
1363
+ </w:rPr>
1364
+ </w:style>
1365
+ <w:style w:type="paragraph" w:styleId="Heading6">
1366
+ <w:name w:val="heading 6" />
1367
+ <w:basedOn w:val="Normal" />
1368
+ <w:next w:val="Normal" />
1369
+ <w:uiPriority w:val="9" />
1370
+ <w:semiHidden />
1371
+ <w:unhideWhenUsed />
1372
+ <w:qFormat />
1373
+ <w:pPr>
1374
+ <w:keepNext />
1375
+ <w:keepLines />
1376
+ <w:spacing w:before="200" w:after="40" />
1377
+ <w:outlineLvl w:val="5" />
1378
+ </w:pPr>
1379
+ <w:rPr>
1380
+ <w:b />
1381
+ <w:sz w:val="20" />
1382
+ <w:szCs w:val="20" />
1383
+ </w:rPr>
1384
+ </w:style>
1385
+ </w:styles>
1386
+ `;
1387
+ const ɵ0$6 = generateStylesXML;
1388
+
1389
+ const fontTableXML = `
1390
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1391
+
1392
+ <w:fonts
1393
+ xmlns:r="${namespaces.r}"
1394
+ xmlns:w="${namespaces.w}"
1395
+ >
1396
+ <w:font w:name="Symbol">
1397
+ <w:panose1 w:val="05050102010706020507"/>
1398
+ <w:charset w:val="02"/>
1399
+ <w:family w:val="decorative"/>
1400
+ <w:pitch w:val="variable"/>
1401
+ <w:sig w:usb0="00000000" w:usb1="10000000" w:usb2="00000000" w:usb3="00000000" w:csb0="80000000" w:csb1="00000000"/>
1402
+ </w:font>
1403
+ <w:font w:name="Calibri">
1404
+ <w:panose1 w:val="020F0502020204030204"/>
1405
+ <w:charset w:val="00"/>
1406
+ <w:family w:val="swiss"/>
1407
+ <w:pitch w:val="variable"/>
1408
+ <w:sig w:usb0="E4002EFF" w:usb1="C000247B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
1409
+ </w:font>
1410
+ <w:font w:name="Times New Roman">
1411
+ <w:panose1 w:val="02020603050405020304"/>
1412
+ <w:charset w:val="00"/>
1413
+ <w:family w:val="roman"/>
1414
+ <w:pitch w:val="variable"/>
1415
+ <w:sig w:usb0="E0002EFF" w:usb1="C000785B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
1416
+ </w:font>
1417
+ <w:font w:name="Calibri Light">
1418
+ <w:panose1 w:val="020F0302020204030204"/>
1419
+ <w:charset w:val="00"/>
1420
+ <w:family w:val="swiss"/>
1421
+ <w:pitch w:val="variable"/>
1422
+ <w:sig w:usb0="E4002EFF" w:usb1="C000247B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
1423
+ </w:font>
1424
+ </w:fonts>
1425
+ `;
1426
+
1427
+ const generateThemeXML = (font = defaultFont) => `
1428
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1429
+
1430
+ <a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme">
1431
+ <a:themeElements>
1432
+ <a:clrScheme name="Office">
1433
+ <a:dk1>
1434
+ <a:sysClr val="windowText" lastClr="000000"/>
1435
+ </a:dk1>
1436
+ <a:lt1>
1437
+ <a:sysClr val="window" lastClr="FFFFFF"/>
1438
+ </a:lt1>
1439
+ <a:dk2>
1440
+ <a:srgbClr val="44546A"/>
1441
+ </a:dk2>
1442
+ <a:lt2>
1443
+ <a:srgbClr val="E7E6E6"/>
1444
+ </a:lt2>
1445
+ <a:accent1>
1446
+ <a:srgbClr val="4472C4"/>
1447
+ </a:accent1>
1448
+ <a:accent2>
1449
+ <a:srgbClr val="ED7D31"/>
1450
+ </a:accent2>
1451
+ <a:accent3>
1452
+ <a:srgbClr val="A5A5A5"/>
1453
+ </a:accent3>
1454
+ <a:accent4>
1455
+ <a:srgbClr val="FFC000"/>
1456
+ </a:accent4>
1457
+ <a:accent5>
1458
+ <a:srgbClr val="5B9BD5"/>
1459
+ </a:accent5>
1460
+ <a:accent6>
1461
+ <a:srgbClr val="70AD47"/>
1462
+ </a:accent6>
1463
+ <a:hlink>
1464
+ <a:srgbClr val="0563C1"/>
1465
+ </a:hlink>
1466
+ <a:folHlink>
1467
+ <a:srgbClr val="954F72"/>
1468
+ </a:folHlink>
1469
+ </a:clrScheme>
1470
+ <a:fontScheme name="Office">
1471
+ <a:majorFont>
1472
+ <a:latin typeface="${font}"/>
1473
+ <a:ea typeface="${font}"/>
1474
+ <a:cs typeface=""/>
1475
+ </a:majorFont>
1476
+ <a:minorFont>
1477
+ <a:latin typeface="${font}"/>
1478
+ <a:ea typeface="${font}"/>
1479
+ <a:cs typeface=""/>
1480
+ </a:minorFont>
1481
+ </a:fontScheme>
1482
+ <a:fmtScheme name="Office">
1483
+ <a:fillStyleLst>
1484
+ <a:solidFill>
1485
+ <a:schemeClr val="phClr"/>
1486
+ </a:solidFill>
1487
+ <a:gradFill rotWithShape="1">
1488
+ <a:gsLst>
1489
+ <a:gs pos="0">
1490
+ <a:schemeClr val="phClr">
1491
+ <a:lumMod val="110000"/>
1492
+ <a:satMod val="105000"/>
1493
+ <a:tint val="67000"/>
1494
+ </a:schemeClr>
1495
+ </a:gs>
1496
+ <a:gs pos="50000">
1497
+ <a:schemeClr val="phClr">
1498
+ <a:lumMod val="105000"/>
1499
+ <a:satMod val="103000"/>
1500
+ <a:tint val="73000"/>
1501
+ </a:schemeClr>
1502
+ </a:gs>
1503
+ <a:gs pos="100000">
1504
+ <a:schemeClr val="phClr">
1505
+ <a:lumMod val="105000"/>
1506
+ <a:satMod val="109000"/>
1507
+ <a:tint val="81000"/>
1508
+ </a:schemeClr>
1509
+ </a:gs>
1510
+ </a:gsLst>
1511
+ <a:lin ang="5400000" scaled="0"/>
1512
+ </a:gradFill>
1513
+ <a:gradFill rotWithShape="1">
1514
+ <a:gsLst>
1515
+ <a:gs pos="0">
1516
+ <a:schemeClr val="phClr">
1517
+ <a:satMod val="103000"/>
1518
+ <a:lumMod val="102000"/>
1519
+ <a:tint val="94000"/>
1520
+ </a:schemeClr>
1521
+ </a:gs>
1522
+ <a:gs pos="50000">
1523
+ <a:schemeClr val="phClr">
1524
+ <a:satMod val="110000"/>
1525
+ <a:lumMod val="100000"/>
1526
+ <a:shade val="100000"/>
1527
+ </a:schemeClr>
1528
+ </a:gs>
1529
+ <a:gs pos="100000">
1530
+ <a:schemeClr val="phClr">
1531
+ <a:lumMod val="99000"/>
1532
+ <a:satMod val="120000"/>
1533
+ <a:shade val="78000"/>
1534
+ </a:schemeClr>
1535
+ </a:gs>
1536
+ </a:gsLst>
1537
+ <a:lin ang="5400000" scaled="0"/>
1538
+ </a:gradFill>
1539
+ </a:fillStyleLst>
1540
+ <a:lnStyleLst>
1541
+ <a:ln w="6350" cap="flat" cmpd="sng" algn="ctr">
1542
+ <a:solidFill>
1543
+ <a:schemeClr val="phClr"/>
1544
+ </a:solidFill>
1545
+ <a:prstDash val="solid"/>
1546
+ <a:miter lim="800000"/>
1547
+ </a:ln>
1548
+ <a:ln w="12700" cap="flat" cmpd="sng" algn="ctr">
1549
+ <a:solidFill>
1550
+ <a:schemeClr val="phClr"/>
1551
+ </a:solidFill>
1552
+ <a:prstDash val="solid"/>
1553
+ <a:miter lim="800000"/>
1554
+ </a:ln>
1555
+ <a:ln w="19050" cap="flat" cmpd="sng" algn="ctr">
1556
+ <a:solidFill>
1557
+ <a:schemeClr val="phClr"/>
1558
+ </a:solidFill>
1559
+ <a:prstDash val="solid"/>
1560
+ <a:miter lim="800000"/>
1561
+ </a:ln>
1562
+ </a:lnStyleLst>
1563
+ <a:effectStyleLst>
1564
+ <a:effectStyle>
1565
+ <a:effectLst/>
1566
+ </a:effectStyle>
1567
+ <a:effectStyle>
1568
+ <a:effectLst/>
1569
+ </a:effectStyle>
1570
+ <a:effectStyle>
1571
+ <a:effectLst>
1572
+ <a:outerShdw blurRad="57150" dist="19050" dir="5400000" algn="ctr" rotWithShape="0">
1573
+ <a:srgbClr val="000000">
1574
+ <a:alpha val="63000"/>
1575
+ </a:srgbClr>
1576
+ </a:outerShdw>
1577
+ </a:effectLst>
1578
+ </a:effectStyle>
1579
+ </a:effectStyleLst>
1580
+ <a:bgFillStyleLst>
1581
+ <a:solidFill>
1582
+ <a:schemeClr val="phClr"/>
1583
+ </a:solidFill>
1584
+ <a:solidFill>
1585
+ <a:schemeClr val="phClr">
1586
+ <a:tint val="95000"/>
1587
+ <a:satMod val="170000"/>
1588
+ </a:schemeClr>
1589
+ </a:solidFill>
1590
+ <a:gradFill rotWithShape="1">
1591
+ <a:gsLst>
1592
+ <a:gs pos="0">
1593
+ <a:schemeClr val="phClr">
1594
+ <a:tint val="93000"/>
1595
+ <a:satMod val="150000"/>
1596
+ <a:shade val="98000"/>
1597
+ <a:lumMod val="102000"/>
1598
+ </a:schemeClr>
1599
+ </a:gs>
1600
+ <a:gs pos="50000">
1601
+ <a:schemeClr val="phClr">
1602
+ <a:tint val="98000"/>
1603
+ <a:satMod val="130000"/>
1604
+ <a:shade val="90000"/>
1605
+ <a:lumMod val="103000"/>
1606
+ </a:schemeClr>
1607
+ </a:gs>
1608
+ <a:gs pos="100000">
1609
+ <a:schemeClr val="phClr">
1610
+ <a:shade val="63000"/>
1611
+ <a:satMod val="120000"/>
1612
+ </a:schemeClr>
1613
+ </a:gs>
1614
+ </a:gsLst>
1615
+ <a:lin ang="5400000" scaled="0"/>
1616
+ </a:gradFill>
1617
+ </a:bgFillStyleLst>
1618
+ </a:fmtScheme>
1619
+ </a:themeElements>
1620
+ </a:theme>
1621
+ `;
1622
+ const ɵ0$5 = generateThemeXML;
1623
+
1624
+ const settingsXML = `
1625
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1626
+
1627
+ <w:settings xmlns:w="${namespaces.w}" xmlns:o="${namespaces.o}" xmlns:r="${namespaces.r}" xmlns:v="${namespaces.v}" xmlns:w10="${namespaces.w10}" xmlns:sl="${namespaces.sl}">
1628
+ <w:zoom w:percent="100"/>
1629
+ <w:defaultTabStop w:val="720"/>
1630
+ <w:decimalSymbol w:val="."/>
1631
+ <w:listSeparator w:val=","/>
1632
+ </w:settings>
1633
+ `;
1634
+
1635
+ const webSettingsXML = `
1636
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1637
+
1638
+ <w:webSettings xmlns:w="${namespaces.w}" xmlns:r="${namespaces.r}">
1639
+ </w:webSettings>
1640
+ `;
1641
+
1642
+ const genericRelsXML = `
1643
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1644
+
1645
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
1646
+ <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunk.mht" Id="htmlChunk" />
1647
+ <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunkheader.mht" Id="htmlChunkHeader" />
1648
+ <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunkfooter.mht" Id="htmlChunkFooter" />
1649
+ </Relationships>
1650
+ `;
1651
+
1652
+ const generateDocumentTemplate = (width, height, orientation, margins) => `
1653
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1654
+ <w:document
1655
+ xmlns:a="${namespaces.a}"
1656
+ xmlns:cdr="${namespaces.cdr}"
1657
+ xmlns:o="${namespaces.o}"
1658
+ xmlns:pic="${namespaces.pic}"
1659
+ xmlns:r="${namespaces.r}"
1660
+ xmlns:v="${namespaces.v}"
1661
+ xmlns:ve="${namespaces.ve}"
1662
+ xmlns:vt="${namespaces.vt}"
1663
+ xmlns:w="${namespaces.w}"
1664
+ xmlns:w10="${namespaces.w10}"
1665
+ xmlns:wp="${namespaces.wp}"
1666
+ xmlns:wne="${namespaces.wne}"
1667
+ >
1668
+ <w:body>
1669
+
1670
+ <w:altChunk r:id="htmlChunk" />
1671
+ <w:sectPr>
1672
+ <w:pgSz w:w="${width}" w:h="${height}" w:orient="${orientation}" />
1673
+ <w:pgMar w:top="${margins.top}"
1674
+ w:right="${margins.right}"
1675
+ w:bottom="${margins.bottom}"
1676
+ w:left="${margins.left}"
1677
+ w:header="${margins.header}"
1678
+ w:footer="${margins.footer}"
1679
+ w:gutter="${margins.gutter}"/>
1680
+ </w:sectPr>
1681
+ </w:body>
1682
+ </w:document>
1683
+ `;
1684
+ const ɵ0$4 = generateDocumentTemplate;
1685
+ const generateDocumentTemplateHeader = `
1686
+ <w:hdr
1687
+ xmlns:a="${namespaces.a}"
1688
+ xmlns:cdr="${namespaces.cdr}"
1689
+ xmlns:o="${namespaces.o}"
1690
+ xmlns:pic="${namespaces.pic}"
1691
+ xmlns:r="${namespaces.r}"
1692
+ xmlns:v="${namespaces.v}"
1693
+ xmlns:ve="${namespaces.ve}"
1694
+ xmlns:vt="${namespaces.vt}"
1695
+ xmlns:w="${namespaces.w}"
1696
+ xmlns:w10="${namespaces.w10}"
1697
+ xmlns:wp="${namespaces.wp}"
1698
+ xmlns:wne="${namespaces.wne}"
1699
+ >
1700
+ <w:altChunk r:id="htmlChunkHeader" />
1701
+ </w:hdr>
1702
+ `;
1703
+ const generateDocumentTemplateFooter = `
1704
+ <w:ftr
1705
+ xmlns:a="${namespaces.a}"
1706
+ xmlns:cdr="${namespaces.cdr}"
1707
+ xmlns:o="${namespaces.o}"
1708
+ xmlns:pic="${namespaces.pic}"
1709
+ xmlns:r="${namespaces.r}"
1710
+ xmlns:v="${namespaces.v}"
1711
+ xmlns:ve="${namespaces.ve}"
1712
+ xmlns:vt="${namespaces.vt}"
1713
+ xmlns:w="${namespaces.w}"
1714
+ xmlns:w10="${namespaces.w10}"
1715
+ xmlns:wp="${namespaces.wp}"
1716
+ >
1717
+ <w:altChunk r:id="htmlChunkFooter" />
1718
+ <w:p w:rsidR="0014021C" w:rsidRDefault="0014021C" w:rsidP="0014021C">
1719
+ <w:pPr>
1720
+ <w:pStyle w:val="Footer"/>
1721
+ <w:jc w:val="center"/>
1722
+ </w:pPr>
1723
+ <w:fldSimple xmlns:ns2="http://schemas.openxmlformats.org/wordprocessingml/2006/main" ns2:instr="PAGE">
1724
+ <w:r/>
1725
+ </w:fldSimple>
1726
+ </w:p>
1727
+ </w:ftr>
1728
+ `;
1729
+ const generateDocumentTemplateFooterWithoutPaging = `
1730
+ <w:ftr
1731
+ xmlns:a="${namespaces.a}"
1732
+ xmlns:cdr="${namespaces.cdr}"
1733
+ xmlns:o="${namespaces.o}"
1734
+ xmlns:pic="${namespaces.pic}"
1735
+ xmlns:r="${namespaces.r}"
1736
+ xmlns:v="${namespaces.v}"
1737
+ xmlns:ve="${namespaces.ve}"
1738
+ xmlns:vt="${namespaces.vt}"
1739
+ xmlns:w="${namespaces.w}"
1740
+ xmlns:w10="${namespaces.w10}"
1741
+ xmlns:wp="${namespaces.wp}"
1742
+ >
1743
+ <w:altChunk r:id="htmlChunkFooter" />
1744
+ </w:ftr>
1745
+ `;
1746
+ { /* <w:altChunk r:id="htmlChunkFooter" /> */ }
1747
+ {
1748
+ /* <w:altChunk r:id="htmlChunkFooter" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" /> */
1749
+ }
1750
+ {
1751
+ /* <w:ftr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
1752
+ <fldSimple xmlns:ns2="http://schemas.openxmlformats.org/wordprocessingml/2006/main" ns2:instr="PAGE">
1753
+ </fldSimple>
1754
+ <w:altChunk r:id="htmlChunkFooter" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />
1755
+ </w:ftr> */
1756
+ }
1757
+
1758
+ /* eslint-disable no-param-reassign */
1759
+ const rgbRegex = /rgb\((\d+),\s*([\d.]+),\s*([\d.]+)\)/i;
1760
+ const hslRegex = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/i;
1761
+ const hexRegex = /#([0-9A-F]{6})/i;
1762
+ const hex3Regex = /#([0-9A-F])([0-9A-F])([0-9A-F])/i;
1763
+ // eslint-disable-next-line import/prefer-default-export
1764
+ const rgbToHex = (red, green, blue) => {
1765
+ const hexColorCode = [red, green, blue]
1766
+ .map((x) => {
1767
+ // eslint-disable-next-line radix, no-param-reassign
1768
+ x = parseInt(x).toString(16);
1769
+ return x.length === 1 ? `0${x}` : x;
1770
+ })
1771
+ .join('');
1772
+ return hexColorCode;
1773
+ };
1774
+ const hslToHex = (hue, saturation, luminosity) => {
1775
+ hue /= 360;
1776
+ saturation /= 100;
1777
+ luminosity /= 100;
1778
+ // eslint-disable-next-line one-var
1779
+ let red, green, blue;
1780
+ if (saturation === 0) {
1781
+ // eslint-disable-next-line no-multi-assign
1782
+ red = green = blue = luminosity; // achromatic
1783
+ }
1784
+ else {
1785
+ const hue2rgb = (p, q, t) => {
1786
+ if (t < 0)
1787
+ t += 1;
1788
+ if (t > 1)
1789
+ t -= 1;
1790
+ if (t < 1 / 6)
1791
+ return p + (q - p) * 6 * t;
1792
+ if (t < 1 / 2)
1793
+ return q;
1794
+ if (t < 2 / 3)
1795
+ return p + (q - p) * (2 / 3 - t) * 6;
1796
+ return p;
1797
+ };
1798
+ const q = luminosity < 0.5
1799
+ ? luminosity * (1 + saturation)
1800
+ : luminosity + saturation - luminosity * saturation;
1801
+ const p = 2 * luminosity - q;
1802
+ red = hue2rgb(p, q, hue + 1 / 3);
1803
+ green = hue2rgb(p, q, hue);
1804
+ blue = hue2rgb(p, q, hue - 1 / 3);
1805
+ }
1806
+ return [red, green, blue]
1807
+ .map((x) => {
1808
+ const hex = Math.round(x * 255).toString(16);
1809
+ return hex.length === 1 ? `0${hex}` : hex;
1810
+ })
1811
+ .join('');
1812
+ };
1813
+ const hex3ToHex = (red, green, blue) => {
1814
+ const hexColorCode = [red, green, blue].map((x) => `${x}${x}`).join('');
1815
+ return hexColorCode;
1816
+ };
1817
+
1818
+ const pixelRegex = /([\d.]+)px/i;
1819
+ const percentageRegex = /([\d.]+)%/i;
1820
+ const pointRegex = /([\d.]+)pt/i;
1821
+ const cmRegex = /([\d.]+)cm/i;
1822
+ const inchRegex = /([\d.]+)in/i;
1823
+ const pixelToEMU = (pixelValue) => Math.round(pixelValue * 9525);
1824
+ const EMUToPixel = (EMUValue) => Math.round(EMUValue / 9525);
1825
+ const TWIPToEMU = (TWIPValue) => Math.round(TWIPValue * 635);
1826
+ const EMUToTWIP = (EMUValue) => Math.round(EMUValue / 635);
1827
+ const pointToTWIP = (pointValue) => Math.round(pointValue * 20);
1828
+ const TWIPToPoint = (TWIPValue) => Math.round(TWIPValue / 20);
1829
+ const pointToHIP = (pointValue) => Math.round(pointValue * 2);
1830
+ const HIPToPoint = (HIPValue) => Math.round(HIPValue / 2);
1831
+ const HIPToTWIP = (HIPValue) => Math.round(HIPValue * 10);
1832
+ const TWIPToHIP = (TWIPValue) => Math.round(TWIPValue / 10);
1833
+ const pixelToTWIP = (pixelValue) => EMUToTWIP(pixelToEMU(pixelValue));
1834
+ const TWIPToPixel = (TWIPValue) => EMUToPixel(TWIPToEMU(TWIPValue));
1835
+ const pixelToHIP = (pixelValue) => TWIPToHIP(EMUToTWIP(pixelToEMU(pixelValue)));
1836
+ const HIPToPixel = (HIPValue) => EMUToPixel(TWIPToEMU(HIPToTWIP(HIPValue)));
1837
+ const inchToPoint = (inchValue) => Math.round(inchValue * 72);
1838
+ const inchToTWIP = (inchValue) => pointToTWIP(inchToPoint(inchValue));
1839
+ const cmToInch = (cmValue) => cmValue * 0.3937008;
1840
+ const cmToTWIP = (cmValue) => inchToTWIP(cmToInch(cmValue));
1841
+ const pixelToPoint = (pixelValue) => HIPToPoint(pixelToHIP(pixelValue));
1842
+ const pointToPixel = (pointValue) => HIPToPixel(pointToHIP(pointValue));
1843
+ const EIPToPoint = (EIPValue) => Math.round(EIPValue / 8);
1844
+ const pointToEIP = (PointValue) => Math.round(PointValue * 8);
1845
+ const pixelToEIP = (pixelValue) => pointToEIP(pixelToPoint(pixelValue));
1846
+ const EIPToPixel = (EIPValue) => pointToPixel(EIPToPoint(EIPValue));
1847
+
1848
+ // eslint-disable-next-line import/prefer-default-export
1849
+ const vNodeHasChildren = (vNode) => vNode && vNode.children && Array.isArray(vNode.children) && vNode.children.length;
1850
+
1851
+ const isValidUrl = (urlString) => {
1852
+ const urlRegex = /http(s)?:\/\/(\w+:?\w*@)?(\S+)(:\d+)?((?<=\.)\w+)+(\/([\w#!:.?+=&%@!\-/])*)?/gi;
1853
+ return Boolean(urlRegex.test(urlString));
1854
+ };
1855
+ const ɵ0$3 = isValidUrl;
1856
+
1857
+ // eslint-disable-next-line consistent-return
1858
+ const fixupColorCode = (colorCodeString) => {
1859
+ if (Object.prototype.hasOwnProperty.call(colorNames, colorCodeString.toLowerCase())) {
1860
+ const [red, green, blue] = colorNames[colorCodeString.toLowerCase()];
1861
+ return rgbToHex(red, green, blue);
1862
+ }
1863
+ else if (rgbRegex.test(colorCodeString)) {
1864
+ const matchedParts = colorCodeString.match(rgbRegex);
1865
+ const red = matchedParts[1];
1866
+ const green = matchedParts[2];
1867
+ const blue = matchedParts[3];
1868
+ return rgbToHex(red, green, blue);
1869
+ }
1870
+ else if (hslRegex.test(colorCodeString)) {
1871
+ const matchedParts = colorCodeString.match(hslRegex);
1872
+ const hue = matchedParts[1];
1873
+ const saturation = matchedParts[2];
1874
+ const luminosity = matchedParts[3];
1875
+ return hslToHex(hue, saturation, luminosity);
1876
+ }
1877
+ else if (hexRegex.test(colorCodeString)) {
1878
+ const matchedParts = colorCodeString.match(hexRegex);
1879
+ return matchedParts[1];
1880
+ }
1881
+ else if (hex3Regex.test(colorCodeString)) {
1882
+ const matchedParts = colorCodeString.match(hex3Regex);
1883
+ const red = matchedParts[1];
1884
+ const green = matchedParts[2];
1885
+ const blue = matchedParts[3];
1886
+ return hex3ToHex(red, green, blue);
1887
+ }
1888
+ else {
1889
+ return '000000';
1890
+ }
1891
+ };
1892
+ const ɵ0$2 = fixupColorCode;
1893
+ const buildRunFontFragment = (fontName = defaultFont) => fragment({ namespaceAlias: { w: namespaces.w } })
1894
+ .ele('@w', 'rFonts')
1895
+ .att('@w', 'ascii', fontName)
1896
+ .att('@w', 'hAnsi', fontName)
1897
+ .up();
1898
+ const ɵ1$1 = buildRunFontFragment;
1899
+ const buildRunStyleFragment = (type = 'Hyperlink') => fragment({ namespaceAlias: { w: namespaces.w } })
1900
+ .ele('@w', 'rStyle')
1901
+ .att('@w', 'val', type)
1902
+ .up();
1903
+ const ɵ2$1 = buildRunStyleFragment;
1904
+ const buildTableRowHeight = (tableRowHeight) => fragment({ namespaceAlias: { w: namespaces.w } })
1905
+ .ele('@w', 'trHeight')
1906
+ .att('@w', 'val', tableRowHeight)
1907
+ .att('@w', 'hRule', 'atLeast')
1908
+ .up();
1909
+ const ɵ3$1 = buildTableRowHeight;
1910
+ const buildVerticalAlignment = (verticalAlignment) => {
1911
+ if (verticalAlignment.toLowerCase() === 'middle') {
1912
+ verticalAlignment = 'center';
1913
+ }
1914
+ return fragment({ namespaceAlias: { w: namespaces.w } })
1915
+ .ele('@w', 'vAlign')
1916
+ .att('@w', 'val', verticalAlignment)
1917
+ .up();
1918
+ };
1919
+ const ɵ4 = buildVerticalAlignment;
1920
+ const buildVerticalMerge = (verticalMerge = 'continue') => fragment({ namespaceAlias: { w: namespaces.w } })
1921
+ .ele('@w', 'vMerge')
1922
+ .att('@w', 'val', verticalMerge)
1923
+ .up();
1924
+ const ɵ5 = buildVerticalMerge;
1925
+ const buildColor = (colorCode) => fragment({ namespaceAlias: { w: namespaces.w } })
1926
+ .ele('@w', 'color')
1927
+ .att('@w', 'val', colorCode)
1928
+ .up();
1929
+ const ɵ6 = buildColor;
1930
+ const buildFontSize = (fontSize) => fragment({ namespaceAlias: { w: namespaces.w } })
1931
+ .ele('@w', 'sz')
1932
+ .att('@w', 'val', fontSize)
1933
+ .up();
1934
+ const ɵ7 = buildFontSize;
1935
+ const buildShading = (colorCode) => fragment({ namespaceAlias: { w: namespaces.w } })
1936
+ .ele('@w', 'shd')
1937
+ .att('@w', 'val', 'clear')
1938
+ .att('@w', 'fill', colorCode)
1939
+ .up();
1940
+ const ɵ8 = buildShading;
1941
+ const buildHighlight = (color = 'yellow') => fragment({ namespaceAlias: { w: namespaces.w } })
1942
+ .ele('@w', 'highlight')
1943
+ .att('@w', 'val', color)
1944
+ .up();
1945
+ const ɵ9 = buildHighlight;
1946
+ const buildVertAlign = (type = 'baseline') => fragment({ namespaceAlias: { w: namespaces.w } })
1947
+ .ele('@w', 'vertAlign')
1948
+ .att('@w', 'val', type)
1949
+ .up();
1950
+ const ɵ10 = buildVertAlign;
1951
+ const buildStrike = () => fragment({ namespaceAlias: { w: namespaces.w } })
1952
+ .ele('@w', 'strike')
1953
+ .att('@w', 'val', true)
1954
+ .up();
1955
+ const ɵ11 = buildStrike;
1956
+ const buildBold = () => fragment({ namespaceAlias: { w: namespaces.w } })
1957
+ .ele('@w', 'b')
1958
+ .up();
1959
+ const ɵ12 = buildBold;
1960
+ const buildItalics = () => fragment({ namespaceAlias: { w: namespaces.w } })
1961
+ .ele('@w', 'i')
1962
+ .up();
1963
+ const ɵ13 = buildItalics;
1964
+ const buildUnderline = (type = 'single') => fragment({ namespaceAlias: { w: namespaces.w } })
1965
+ .ele('@w', 'u')
1966
+ .att('@w', 'val', type)
1967
+ .up();
1968
+ const ɵ14 = buildUnderline;
1969
+ const buildLineBreak = (type = 'textWrapping') => fragment({ namespaceAlias: { w: namespaces.w } })
1970
+ .ele('@w', 'br')
1971
+ .att('@w', 'type', type)
1972
+ .up();
1973
+ const ɵ15 = buildLineBreak;
1974
+ const buildBorder = (borderSide = 'top', borderSize = 0, borderSpacing = 0, borderColor = fixupColorCode('black'), borderStroke = 'single') => fragment({ namespaceAlias: { w: namespaces.w } })
1975
+ .ele('@w', borderSide)
1976
+ .att('@w', 'val', borderStroke)
1977
+ .att('@w', 'sz', borderSize)
1978
+ .att('@w', 'space', borderSpacing)
1979
+ .att('@w', 'color', borderColor)
1980
+ .up();
1981
+ const ɵ16 = buildBorder;
1982
+ const buildTextElement = (text) => fragment({ namespaceAlias: { w: namespaces.w } })
1983
+ .ele('@w', 't')
1984
+ .att('@xml', 'space', 'preserve')
1985
+ .txt(text)
1986
+ .up();
1987
+ const ɵ17 = buildTextElement;
1988
+ // eslint-disable-next-line consistent-return
1989
+ const fixupLineHeight = (lineHeight, fontSize) => {
1990
+ // FIXME: If line height is anything other than a number
1991
+ // eslint-disable-next-line no-restricted-globals
1992
+ if (!isNaN(lineHeight)) {
1993
+ if (fontSize) {
1994
+ const actualLineHeight = +lineHeight * fontSize;
1995
+ return HIPToTWIP(actualLineHeight);
1996
+ }
1997
+ else {
1998
+ // 240 TWIP or 12 point is default line height
1999
+ return +lineHeight * 240;
2000
+ }
2001
+ }
2002
+ else {
2003
+ // 240 TWIP or 12 point is default line height
2004
+ return 240;
2005
+ }
2006
+ };
2007
+ const ɵ18 = fixupLineHeight;
2008
+ // eslint-disable-next-line consistent-return
2009
+ const fixupFontSize$1 = (fontSizeString) => {
2010
+ if (pointRegex.test(fontSizeString)) {
2011
+ const matchedParts = fontSizeString.match(pointRegex);
2012
+ // convert point to half point
2013
+ return pointToHIP(matchedParts[1]);
2014
+ }
2015
+ else if (pixelRegex.test(fontSizeString)) {
2016
+ const matchedParts = fontSizeString.match(pixelRegex);
2017
+ // convert pixels to half point
2018
+ return pixelToHIP(matchedParts[1]);
2019
+ }
2020
+ };
2021
+ const ɵ19 = fixupFontSize$1;
2022
+ // eslint-disable-next-line consistent-return
2023
+ const fixupRowHeight = (rowHeightString) => {
2024
+ if (pointRegex.test(rowHeightString)) {
2025
+ const matchedParts = rowHeightString.match(pointRegex);
2026
+ // convert point to half point
2027
+ return pointToTWIP(matchedParts[1]);
2028
+ }
2029
+ else if (pixelRegex.test(rowHeightString)) {
2030
+ const matchedParts = rowHeightString.match(pixelRegex);
2031
+ // convert pixels to half point
2032
+ return pixelToTWIP(matchedParts[1]);
2033
+ }
2034
+ else if (cmRegex.test(rowHeightString)) {
2035
+ const matchedParts = rowHeightString.match(cmRegex);
2036
+ return cmToTWIP(matchedParts[1]);
2037
+ }
2038
+ else if (inchRegex.test(rowHeightString)) {
2039
+ const matchedParts = rowHeightString.match(inchRegex);
2040
+ return inchToTWIP(matchedParts[1]);
2041
+ }
2042
+ };
2043
+ const ɵ20 = fixupRowHeight;
2044
+ // eslint-disable-next-line consistent-return
2045
+ const fixupColumnWidth = (columnWidthString) => {
2046
+ if (pointRegex.test(columnWidthString)) {
2047
+ const matchedParts = columnWidthString.match(pointRegex);
2048
+ return pointToTWIP(matchedParts[1]);
2049
+ }
2050
+ else if (pixelRegex.test(columnWidthString)) {
2051
+ const matchedParts = columnWidthString.match(pixelRegex);
2052
+ return pixelToTWIP(matchedParts[1]);
2053
+ }
2054
+ else if (cmRegex.test(columnWidthString)) {
2055
+ const matchedParts = columnWidthString.match(cmRegex);
2056
+ return cmToTWIP(matchedParts[1]);
2057
+ }
2058
+ else if (inchRegex.test(columnWidthString)) {
2059
+ const matchedParts = columnWidthString.match(inchRegex);
2060
+ return inchToTWIP(matchedParts[1]);
2061
+ }
2062
+ };
2063
+ const ɵ21 = fixupColumnWidth;
2064
+ // eslint-disable-next-line consistent-return
2065
+ const fixupMargin = (marginString) => {
2066
+ if (pointRegex.test(marginString)) {
2067
+ const matchedParts = marginString.match(pointRegex);
2068
+ // convert point to half point
2069
+ return pointToTWIP(matchedParts[1]);
2070
+ }
2071
+ else if (pixelRegex.test(marginString)) {
2072
+ const matchedParts = marginString.match(pixelRegex);
2073
+ // convert pixels to half point
2074
+ return pixelToTWIP(matchedParts[1]);
2075
+ }
2076
+ };
2077
+ const ɵ22 = fixupMargin;
2078
+ const modifiedStyleAttributesBuilder = (vNode, attributes, options) => {
2079
+ const modifiedAttributes = Object.assign({}, attributes);
2080
+ // styles
2081
+ if (isVNode(vNode) && vNode.properties && vNode.properties.style) {
2082
+ if (vNode.properties.style.color && !colorlessColors.includes(vNode.properties.style.color)) {
2083
+ modifiedAttributes.color = fixupColorCode(vNode.properties.style.color);
2084
+ }
2085
+ if (vNode.properties.style['background-color'] &&
2086
+ !colorlessColors.includes(vNode.properties.style['background-color'])) {
2087
+ modifiedAttributes.backgroundColor = fixupColorCode(vNode.properties.style['background-color']);
2088
+ }
2089
+ if (vNode.properties.style['vertical-align'] &&
2090
+ verticalAlignValues.includes(vNode.properties.style['vertical-align'])) {
2091
+ modifiedAttributes.verticalAlign = vNode.properties.style['vertical-align'];
2092
+ }
2093
+ if (vNode.properties.style['text-align'] &&
2094
+ ['left', 'right', 'center', 'justify'].includes(vNode.properties.style['text-align'])) {
2095
+ modifiedAttributes.textAlign = vNode.properties.style['text-align'];
2096
+ }
2097
+ // FIXME: remove bold check when other font weights are handled.
2098
+ if (vNode.properties.style['font-weight'] && vNode.properties.style['font-weight'] === 'bold') {
2099
+ modifiedAttributes.strong = vNode.properties.style['font-weight'];
2100
+ }
2101
+ if (vNode.properties.style['font-size']) {
2102
+ modifiedAttributes.fontSize = fixupFontSize$1(vNode.properties.style['font-size']);
2103
+ }
2104
+ if (vNode.properties.style['line-height']) {
2105
+ modifiedAttributes.lineHeight = fixupLineHeight(vNode.properties.style['line-height'], vNode.properties.style['font-size']
2106
+ ? fixupFontSize$1(vNode.properties.style['font-size'])
2107
+ : null);
2108
+ }
2109
+ if (vNode.properties.style['margin-left'] || vNode.properties.style['margin-right']) {
2110
+ const leftMargin = fixupMargin(vNode.properties.style['margin-left']);
2111
+ const rightMargin = fixupMargin(vNode.properties.style['margin-right']);
2112
+ const indentation = {};
2113
+ if (leftMargin) {
2114
+ indentation.left = leftMargin;
2115
+ }
2116
+ if (rightMargin) {
2117
+ indentation.right = rightMargin;
2118
+ }
2119
+ if (leftMargin || rightMargin) {
2120
+ modifiedAttributes.indentation = indentation;
2121
+ }
2122
+ }
2123
+ if (vNode.properties.style.display) {
2124
+ modifiedAttributes.display = vNode.properties.style.display;
2125
+ }
2126
+ if (vNode.properties.style.width) {
2127
+ modifiedAttributes.width = vNode.properties.style.width;
2128
+ }
2129
+ }
2130
+ // paragraph only
2131
+ if (options && options.isParagraph) {
2132
+ if (isVNode(vNode) && vNode.tagName === 'blockquote') {
2133
+ modifiedAttributes.indentation = { left: 284 };
2134
+ modifiedAttributes.textAlign = 'justify';
2135
+ }
2136
+ else if (isVNode(vNode) && vNode.tagName === 'code') {
2137
+ modifiedAttributes.highlightColor = 'lightGray';
2138
+ }
2139
+ else if (isVNode(vNode) && vNode.tagName === 'pre') {
2140
+ modifiedAttributes.font = 'Courier';
2141
+ }
2142
+ }
2143
+ return modifiedAttributes;
2144
+ };
2145
+ const ɵ23 = modifiedStyleAttributesBuilder;
2146
+ // html tag to formatting function
2147
+ // options are passed to the formatting function if needed
2148
+ const buildFormatting = (htmlTag, options) => {
2149
+ switch (htmlTag) {
2150
+ case 'strong':
2151
+ case 'b':
2152
+ return buildBold();
2153
+ case 'em':
2154
+ case 'i':
2155
+ return buildItalics();
2156
+ case 'ins':
2157
+ case 'u':
2158
+ return buildUnderline();
2159
+ case 'strike':
2160
+ case 'del':
2161
+ case 's':
2162
+ return buildStrike();
2163
+ case 'sub':
2164
+ return buildVertAlign('subscript');
2165
+ case 'sup':
2166
+ return buildVertAlign('superscript');
2167
+ case 'mark':
2168
+ return buildHighlight();
2169
+ case 'code':
2170
+ return buildHighlight('lightGray');
2171
+ case 'highlightColor':
2172
+ return buildHighlight(options && options.color ? options.color : 'lightGray');
2173
+ case 'font':
2174
+ case 'pre':
2175
+ return buildRunFontFragment('Courier');
2176
+ case 'color':
2177
+ return buildColor(options && options.color ? options.color : 'black');
2178
+ case 'backgroundColor':
2179
+ return buildShading(options && options.color ? options.color : 'black');
2180
+ case 'fontSize':
2181
+ // does this need a unit of measure?
2182
+ return buildFontSize(options && options.fontSize ? options.fontSize : 10);
2183
+ case 'hyperlink':
2184
+ return buildRunStyleFragment('Hyperlink');
2185
+ }
2186
+ return null;
2187
+ };
2188
+ const ɵ24 = buildFormatting;
2189
+ const buildRunProperties = (attributes) => {
2190
+ const runPropertiesFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'rPr');
2191
+ if (attributes && attributes.constructor === Object) {
2192
+ Object.keys(attributes).forEach((key) => {
2193
+ const options = {};
2194
+ if (key === 'color' || key === 'backgroundColor' || key === 'highlightColor') {
2195
+ options.color = attributes[key];
2196
+ }
2197
+ if (key === 'fontSize') {
2198
+ options.fontSize = attributes[key];
2199
+ }
2200
+ const formattingFragment = buildFormatting(key, options);
2201
+ if (formattingFragment) {
2202
+ runPropertiesFragment.import(formattingFragment);
2203
+ }
2204
+ });
2205
+ }
2206
+ runPropertiesFragment.up();
2207
+ return runPropertiesFragment;
2208
+ };
2209
+ const ɵ25 = buildRunProperties;
2210
+ const buildRun = (vNode, attributes, docxDocumentInstance) => __awaiter(void 0, void 0, void 0, function* () {
2211
+ const runFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'r');
2212
+ const runPropertiesFragment = buildRunProperties(cloneDeep(attributes));
2213
+ // case where we have recursive spans representing font changes
2214
+ if (isVNode(vNode) && vNode.tagName === 'span') {
2215
+ // eslint-disable-next-line no-use-before-define
2216
+ return buildRunOrRuns(vNode, attributes, docxDocumentInstance);
2217
+ }
2218
+ if (isVNode(vNode) &&
2219
+ [
2220
+ 'strong',
2221
+ 'b',
2222
+ 'em',
2223
+ 'i',
2224
+ 'u',
2225
+ 'ins',
2226
+ 'strike',
2227
+ 'del',
2228
+ 's',
2229
+ 'sub',
2230
+ 'sup',
2231
+ 'mark',
2232
+ 'blockquote',
2233
+ 'code',
2234
+ 'pre',
2235
+ ].includes(vNode.tagName)) {
2236
+ const runFragmentsArray = [];
2237
+ let vNodes = [vNode];
2238
+ // create temp run fragments to split the paragraph into different runs
2239
+ let tempAttributes = cloneDeep(attributes);
2240
+ let tempRunFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'r');
2241
+ while (vNodes.length) {
2242
+ const tempVNode = vNodes.shift();
2243
+ if (isVText(tempVNode)) {
2244
+ const textFragment = buildTextElement(tempVNode.text);
2245
+ const tempRunPropertiesFragment = buildRunProperties(Object.assign(Object.assign({}, attributes), tempAttributes));
2246
+ tempRunFragment.import(tempRunPropertiesFragment);
2247
+ tempRunFragment.import(textFragment);
2248
+ runFragmentsArray.push(tempRunFragment);
2249
+ // re initialize temp run fragments with new fragment
2250
+ tempAttributes = cloneDeep(attributes);
2251
+ tempRunFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'r');
2252
+ }
2253
+ else if (isVNode(tempVNode)) {
2254
+ if ([
2255
+ 'strong',
2256
+ 'b',
2257
+ 'em',
2258
+ 'i',
2259
+ 'u',
2260
+ 'ins',
2261
+ 'strike',
2262
+ 'del',
2263
+ 's',
2264
+ 'sub',
2265
+ 'sup',
2266
+ 'mark',
2267
+ 'code',
2268
+ 'pre',
2269
+ ].includes(tempVNode.tagName)) {
2270
+ tempAttributes = {};
2271
+ switch (tempVNode.tagName) {
2272
+ case 'strong':
2273
+ case 'b':
2274
+ tempAttributes.strong = true;
2275
+ break;
2276
+ case 'i':
2277
+ tempAttributes.i = true;
2278
+ break;
2279
+ case 'u':
2280
+ tempAttributes.u = true;
2281
+ break;
2282
+ case 'sub':
2283
+ tempAttributes.sub = true;
2284
+ break;
2285
+ case 'sup':
2286
+ tempAttributes.sup = true;
2287
+ break;
2288
+ }
2289
+ const formattingFragment = buildFormatting(tempVNode);
2290
+ if (formattingFragment) {
2291
+ runPropertiesFragment.import(formattingFragment);
2292
+ }
2293
+ // go a layer deeper if there is a span somewhere in the children
2294
+ }
2295
+ else if (tempVNode.tagName === 'span') {
2296
+ // eslint-disable-next-line no-use-before-define
2297
+ const spanFragment = yield buildRunOrRuns(tempVNode, Object.assign(Object.assign({}, attributes), tempAttributes), docxDocumentInstance);
2298
+ // if spanFragment is an array, we need to add each fragment to the runFragmentsArray. If the fragment is an array, perform a depth first search on the array to add each fragment to the runFragmentsArray
2299
+ if (Array.isArray(spanFragment)) {
2300
+ spanFragment.flat(Infinity);
2301
+ runFragmentsArray.push(...spanFragment);
2302
+ }
2303
+ else {
2304
+ runFragmentsArray.push(spanFragment);
2305
+ }
2306
+ // do not slice and concat children since this is already accounted for in the buildRunOrRuns function
2307
+ // eslint-disable-next-line no-continue
2308
+ continue;
2309
+ }
2310
+ }
2311
+ if (tempVNode.children && tempVNode.children.length) {
2312
+ if (tempVNode.children.length > 1) {
2313
+ attributes = Object.assign(Object.assign({}, attributes), tempAttributes);
2314
+ }
2315
+ vNodes = tempVNode.children.slice().concat(vNodes);
2316
+ }
2317
+ }
2318
+ if (runFragmentsArray.length) {
2319
+ return runFragmentsArray;
2320
+ }
2321
+ }
2322
+ runFragment.import(runPropertiesFragment);
2323
+ if (isVText(vNode)) {
2324
+ const textFragment = buildTextElement(vNode.text);
2325
+ runFragment.import(textFragment);
2326
+ }
2327
+ else if (attributes && attributes.type === 'picture') {
2328
+ let response = null;
2329
+ const base64Uri = decodeURIComponent(vNode.properties.src);
2330
+ if (base64Uri) {
2331
+ response = docxDocumentInstance.createMediaFile(base64Uri);
2332
+ }
2333
+ if (response) {
2334
+ docxDocumentInstance.zip
2335
+ .folder('word')
2336
+ .folder('media')
2337
+ .file(response.fileNameWithExtension, Buffer.from(response.fileContent, 'base64'), {
2338
+ createFolders: false,
2339
+ });
2340
+ const documentRelsId = docxDocumentInstance.createDocumentRelationships(docxDocumentInstance.relationshipFilename, imageType, `media/${response.fileNameWithExtension}`, internalRelationship);
2341
+ attributes.inlineOrAnchored = true;
2342
+ attributes.relationshipId = documentRelsId;
2343
+ attributes.id = response.id;
2344
+ attributes.fileContent = response.fileContent;
2345
+ attributes.fileNameWithExtension = response.fileNameWithExtension;
2346
+ }
2347
+ const { type, inlineOrAnchored } = attributes, otherAttributes = __rest(attributes, ["type", "inlineOrAnchored"]);
2348
+ // eslint-disable-next-line no-use-before-define
2349
+ const imageFragment = buildDrawing(inlineOrAnchored, type, otherAttributes);
2350
+ runFragment.import(imageFragment);
2351
+ }
2352
+ else if (isVNode(vNode) && vNode.tagName === 'br') {
2353
+ const lineBreakFragment = buildLineBreak();
2354
+ runFragment.import(lineBreakFragment);
2355
+ }
2356
+ runFragment.up();
2357
+ return runFragment;
2358
+ });
2359
+ const ɵ26 = buildRun;
2360
+ const buildRunOrRuns = (vNode, attributes, docxDocumentInstance) => __awaiter(void 0, void 0, void 0, function* () {
2361
+ if (isVNode(vNode) && vNode.tagName === 'span') {
2362
+ let runFragments = [];
2363
+ for (let index = 0; index < vNode.children.length; index++) {
2364
+ const childVNode = vNode.children[index];
2365
+ const modifiedAttributes = modifiedStyleAttributesBuilder(vNode, attributes);
2366
+ const tempRunFragments = yield buildRun(childVNode, modifiedAttributes, docxDocumentInstance);
2367
+ runFragments = runFragments.concat(Array.isArray(tempRunFragments) ? tempRunFragments : [tempRunFragments]);
2368
+ }
2369
+ return runFragments;
2370
+ }
2371
+ else {
2372
+ const tempRunFragments = yield buildRun(vNode, attributes, docxDocumentInstance);
2373
+ return tempRunFragments;
2374
+ }
2375
+ });
2376
+ const ɵ27 = buildRunOrRuns;
2377
+ const buildRunOrHyperLink = (vNode, attributes, docxDocumentInstance) => __awaiter(void 0, void 0, void 0, function* () {
2378
+ if (isVNode(vNode) && vNode.tagName === 'a') {
2379
+ const relationshipId = docxDocumentInstance.createDocumentRelationships(docxDocumentInstance.relationshipFilename, hyperlinkType, vNode.properties && vNode.properties.href ? vNode.properties.href : '');
2380
+ const hyperlinkFragment = fragment({ namespaceAlias: { w: namespaces.w, r: namespaces.r } })
2381
+ .ele('@w', 'hyperlink')
2382
+ .att('@r', 'id', `rId${relationshipId}`);
2383
+ const modifiedAttributes = Object.assign({}, attributes);
2384
+ modifiedAttributes.hyperlink = true;
2385
+ const runFragments = yield buildRunOrRuns(vNode.children[0], modifiedAttributes, docxDocumentInstance);
2386
+ if (Array.isArray(runFragments)) {
2387
+ for (let index = 0; index < runFragments.length; index++) {
2388
+ const runFragment = runFragments[index];
2389
+ hyperlinkFragment.import(runFragment);
2390
+ }
2391
+ }
2392
+ else {
2393
+ hyperlinkFragment.import(runFragments);
2394
+ }
2395
+ hyperlinkFragment.up();
2396
+ return hyperlinkFragment;
2397
+ }
2398
+ const runFragments = yield buildRunOrRuns(vNode, attributes, docxDocumentInstance);
2399
+ return runFragments;
2400
+ });
2401
+ const ɵ28 = buildRunOrHyperLink;
2402
+ const buildNumberingProperties = (levelId, numberingId) => fragment({ namespaceAlias: { w: namespaces.w } })
2403
+ .ele('@w', 'numPr')
2404
+ .ele('@w', 'ilvl')
2405
+ .att('@w', 'val', String(levelId))
2406
+ .up()
2407
+ .ele('@w', 'numId')
2408
+ .att('@w', 'val', String(numberingId))
2409
+ .up()
2410
+ .up();
2411
+ const ɵ29 = buildNumberingProperties;
2412
+ const buildNumberingInstances = () => fragment({ namespaceAlias: { w: namespaces.w } })
2413
+ .ele('@w', 'num')
2414
+ .ele('@w', 'abstractNumId')
2415
+ .up()
2416
+ .up();
2417
+ const ɵ30 = buildNumberingInstances;
2418
+ const buildSpacing = (lineSpacing, beforeSpacing, afterSpacing) => {
2419
+ const spacingFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'spacing');
2420
+ if (lineSpacing) {
2421
+ spacingFragment.att('@w', 'line', lineSpacing);
2422
+ }
2423
+ if (beforeSpacing) {
2424
+ spacingFragment.att('@w', 'before', beforeSpacing);
2425
+ }
2426
+ if (afterSpacing) {
2427
+ spacingFragment.att('@w', 'after', afterSpacing);
2428
+ }
2429
+ spacingFragment.att('@w', 'lineRule', 'auto').up();
2430
+ return spacingFragment;
2431
+ };
2432
+ const ɵ31 = buildSpacing;
2433
+ const buildIndentation = ({ left, right }) => {
2434
+ const indentationFragment = fragment({
2435
+ namespaceAlias: { w: namespaces.w },
2436
+ }).ele('@w', 'ind');
2437
+ if (left) {
2438
+ indentationFragment.att('@w', 'left', left);
2439
+ }
2440
+ if (right) {
2441
+ indentationFragment.att('@w', 'right', right);
2442
+ }
2443
+ indentationFragment.up();
2444
+ return indentationFragment;
2445
+ };
2446
+ const ɵ32 = buildIndentation;
2447
+ const buildPStyle = (style = 'Normal') => fragment({ namespaceAlias: { w: namespaces.w } })
2448
+ .ele('@w', 'pStyle')
2449
+ .att('@w', 'val', style)
2450
+ .up();
2451
+ const ɵ33 = buildPStyle;
2452
+ const buildHorizontalAlignment = (horizontalAlignment) => {
2453
+ if (horizontalAlignment === 'justify') {
2454
+ horizontalAlignment = 'both';
2455
+ }
2456
+ return fragment({ namespaceAlias: { w: namespaces.w } })
2457
+ .ele('@w', 'jc')
2458
+ .att('@w', 'val', horizontalAlignment)
2459
+ .up();
2460
+ };
2461
+ const ɵ34 = buildHorizontalAlignment;
2462
+ const buildParagraphBorder = () => {
2463
+ const paragraphBorderFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'pBdr');
2464
+ const bordersObject = cloneDeep(paragraphBordersObject);
2465
+ Object.keys(bordersObject).forEach((borderName) => {
2466
+ if (bordersObject[borderName]) {
2467
+ const { size, spacing, color } = bordersObject[borderName];
2468
+ const borderFragment = buildBorder(borderName, size, spacing, color);
2469
+ paragraphBorderFragment.import(borderFragment);
2470
+ }
2471
+ });
2472
+ paragraphBorderFragment.up();
2473
+ return paragraphBorderFragment;
2474
+ };
2475
+ const ɵ35 = buildParagraphBorder;
2476
+ const buildParagraphProperties = (attributes) => {
2477
+ const paragraphPropertiesFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'pPr');
2478
+ if (attributes && attributes.constructor === Object) {
2479
+ Object.keys(attributes).forEach((key) => {
2480
+ switch (key) {
2481
+ case 'numbering':
2482
+ const { levelId, numberingId } = attributes[key];
2483
+ const numberingPropertiesFragment = buildNumberingProperties(levelId, numberingId);
2484
+ paragraphPropertiesFragment.import(numberingPropertiesFragment);
2485
+ // eslint-disable-next-line no-param-reassign
2486
+ delete attributes.numbering;
2487
+ break;
2488
+ case 'textAlign':
2489
+ const horizontalAlignmentFragment = buildHorizontalAlignment(attributes[key]);
2490
+ paragraphPropertiesFragment.import(horizontalAlignmentFragment);
2491
+ // eslint-disable-next-line no-param-reassign
2492
+ delete attributes.textAlign;
2493
+ break;
2494
+ case 'backgroundColor':
2495
+ // Add shading to Paragraph Properties only if display is block
2496
+ // Essentially if background color needs to be across the row
2497
+ if (attributes.display === 'block') {
2498
+ const shadingFragment = buildShading(attributes[key]);
2499
+ paragraphPropertiesFragment.import(shadingFragment);
2500
+ // FIXME: Inner padding in case of shaded paragraphs.
2501
+ const paragraphBorderFragment = buildParagraphBorder();
2502
+ paragraphPropertiesFragment.import(paragraphBorderFragment);
2503
+ // eslint-disable-next-line no-param-reassign
2504
+ delete attributes.backgroundColor;
2505
+ }
2506
+ break;
2507
+ case 'paragraphStyle':
2508
+ const pStyleFragment = buildPStyle(attributes.paragraphStyle);
2509
+ paragraphPropertiesFragment.import(pStyleFragment);
2510
+ delete attributes.paragraphStyle;
2511
+ break;
2512
+ case 'indentation':
2513
+ const indentationFragment = buildIndentation(attributes[key]);
2514
+ paragraphPropertiesFragment.import(indentationFragment);
2515
+ // eslint-disable-next-line no-param-reassign
2516
+ delete attributes.indentation;
2517
+ break;
2518
+ }
2519
+ });
2520
+ const spacingFragment = buildSpacing(attributes.lineHeight, attributes.beforeSpacing, attributes.afterSpacing);
2521
+ // eslint-disable-next-line no-param-reassign
2522
+ delete attributes.lineHeight;
2523
+ // eslint-disable-next-line no-param-reassign
2524
+ delete attributes.beforeSpacing;
2525
+ // eslint-disable-next-line no-param-reassign
2526
+ delete attributes.afterSpacing;
2527
+ paragraphPropertiesFragment.import(spacingFragment);
2528
+ }
2529
+ paragraphPropertiesFragment.up();
2530
+ return paragraphPropertiesFragment;
2531
+ };
2532
+ const ɵ36 = buildParagraphProperties;
2533
+ const computeImageDimensions = (vNode, attributes) => {
2534
+ const { maximumWidth, originalWidth, originalHeight } = attributes;
2535
+ const aspectRatio = originalWidth / originalHeight;
2536
+ const maximumWidthInEMU = TWIPToEMU(maximumWidth);
2537
+ let originalWidthInEMU = pixelToEMU(originalWidth);
2538
+ let originalHeightInEMU = pixelToEMU(originalHeight);
2539
+ if (originalWidthInEMU > maximumWidthInEMU) {
2540
+ originalWidthInEMU = maximumWidthInEMU;
2541
+ originalHeightInEMU = Math.round(originalWidthInEMU / aspectRatio);
2542
+ }
2543
+ let modifiedHeight;
2544
+ let modifiedWidth;
2545
+ if (vNode.properties && vNode.properties.style) {
2546
+ if (vNode.properties.style.width) {
2547
+ if (vNode.properties.style.width !== 'auto') {
2548
+ if (pixelRegex.test(vNode.properties.style.width)) {
2549
+ modifiedWidth = pixelToEMU(vNode.properties.style.width.match(pixelRegex)[1]);
2550
+ }
2551
+ else if (percentageRegex.test(vNode.properties.style.width)) {
2552
+ const percentageValue = vNode.properties.style.width.match(percentageRegex)[1];
2553
+ modifiedWidth = Math.round((percentageValue / 100) * originalWidthInEMU);
2554
+ }
2555
+ }
2556
+ else {
2557
+ // eslint-disable-next-line no-lonely-if
2558
+ if (vNode.properties.style.height && vNode.properties.style.height === 'auto') {
2559
+ modifiedWidth = originalWidthInEMU;
2560
+ modifiedHeight = originalHeightInEMU;
2561
+ }
2562
+ }
2563
+ }
2564
+ if (vNode.properties.style.height) {
2565
+ if (vNode.properties.style.height !== 'auto') {
2566
+ if (pixelRegex.test(vNode.properties.style.height)) {
2567
+ modifiedHeight = pixelToEMU(vNode.properties.style.height.match(pixelRegex)[1]);
2568
+ }
2569
+ else if (percentageRegex.test(vNode.properties.style.height)) {
2570
+ const percentageValue = vNode.properties.style.width.match(percentageRegex)[1];
2571
+ modifiedHeight = Math.round((percentageValue / 100) * originalHeightInEMU);
2572
+ if (!modifiedWidth) {
2573
+ modifiedWidth = Math.round(modifiedHeight * aspectRatio);
2574
+ }
2575
+ }
2576
+ }
2577
+ else {
2578
+ // eslint-disable-next-line no-lonely-if
2579
+ if (modifiedWidth) {
2580
+ if (!modifiedHeight) {
2581
+ modifiedHeight = Math.round(modifiedWidth / aspectRatio);
2582
+ }
2583
+ }
2584
+ else {
2585
+ modifiedHeight = originalHeightInEMU;
2586
+ modifiedWidth = originalWidthInEMU;
2587
+ }
2588
+ }
2589
+ }
2590
+ if (modifiedWidth && !modifiedHeight) {
2591
+ modifiedHeight = Math.round(modifiedWidth / aspectRatio);
2592
+ }
2593
+ else if (modifiedHeight && !modifiedWidth) {
2594
+ modifiedWidth = Math.round(modifiedHeight * aspectRatio);
2595
+ }
2596
+ }
2597
+ else {
2598
+ modifiedWidth = originalWidthInEMU;
2599
+ modifiedHeight = originalHeightInEMU;
2600
+ }
2601
+ // eslint-disable-next-line no-param-reassign
2602
+ attributes.width = modifiedWidth;
2603
+ // eslint-disable-next-line no-param-reassign
2604
+ attributes.height = modifiedHeight;
2605
+ };
2606
+ const ɵ37 = computeImageDimensions;
2607
+ const buildParagraph = (vNode, attributes, docxDocumentInstance) => __awaiter(void 0, void 0, void 0, function* () {
2608
+ const paragraphFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'p');
2609
+ const modifiedAttributes = modifiedStyleAttributesBuilder(vNode, attributes, {
2610
+ isParagraph: true,
2611
+ });
2612
+ const paragraphPropertiesFragment = buildParagraphProperties(modifiedAttributes);
2613
+ paragraphFragment.import(paragraphPropertiesFragment);
2614
+ if (isVNode(vNode) && vNodeHasChildren(vNode)) {
2615
+ if ([
2616
+ 'span',
2617
+ 'strong',
2618
+ 'b',
2619
+ 'em',
2620
+ 'i',
2621
+ 'u',
2622
+ 'ins',
2623
+ 'strike',
2624
+ 'del',
2625
+ 's',
2626
+ 'sub',
2627
+ 'sup',
2628
+ 'mark',
2629
+ 'a',
2630
+ 'code',
2631
+ 'pre',
2632
+ ].includes(vNode.tagName)) {
2633
+ const runOrHyperlinkFragments = yield buildRunOrHyperLink(vNode, modifiedAttributes, docxDocumentInstance);
2634
+ if (Array.isArray(runOrHyperlinkFragments)) {
2635
+ for (let iteratorIndex = 0; iteratorIndex < runOrHyperlinkFragments.length; iteratorIndex++) {
2636
+ const runOrHyperlinkFragment = runOrHyperlinkFragments[iteratorIndex];
2637
+ paragraphFragment.import(runOrHyperlinkFragment);
2638
+ }
2639
+ }
2640
+ else {
2641
+ paragraphFragment.import(runOrHyperlinkFragments);
2642
+ }
2643
+ }
2644
+ else if (vNode.tagName === 'blockquote') {
2645
+ const runFragmentOrFragments = yield buildRun(vNode, attributes);
2646
+ if (Array.isArray(runFragmentOrFragments)) {
2647
+ for (let index = 0; index < runFragmentOrFragments.length; index++) {
2648
+ paragraphFragment.import(runFragmentOrFragments[index]);
2649
+ }
2650
+ }
2651
+ else {
2652
+ paragraphFragment.import(runFragmentOrFragments);
2653
+ }
2654
+ }
2655
+ else {
2656
+ for (let index = 0; index < vNode.children.length; index++) {
2657
+ const childVNode = vNode.children[index];
2658
+ if (childVNode.tagName === 'img') {
2659
+ let base64String;
2660
+ const imageSource = childVNode.properties.src;
2661
+ if (isValidUrl(imageSource)) {
2662
+ base64String = yield imageToBase64(imageSource).catch((error) => {
2663
+ // eslint-disable-next-line no-console
2664
+ console.warning(`skipping image download and conversion due to ${error}`);
2665
+ });
2666
+ if (base64String && mimeTypes.lookup(imageSource)) {
2667
+ childVNode.properties.src = `data:${mimeTypes.lookup(imageSource)};base64, ${base64String}`;
2668
+ }
2669
+ else {
2670
+ break;
2671
+ }
2672
+ }
2673
+ else {
2674
+ // eslint-disable-next-line no-useless-escape, prefer-destructuring
2675
+ base64String = imageSource.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/)[2];
2676
+ }
2677
+ const imageBuffer = Buffer.from(decodeURIComponent(base64String), 'base64');
2678
+ const imageProperties = sizeOf(imageBuffer);
2679
+ modifiedAttributes.maximumWidth =
2680
+ modifiedAttributes.maximumWidth || docxDocumentInstance.availableDocumentSpace;
2681
+ modifiedAttributes.originalWidth = imageProperties.width;
2682
+ modifiedAttributes.originalHeight = imageProperties.height;
2683
+ computeImageDimensions(childVNode, modifiedAttributes);
2684
+ }
2685
+ const runOrHyperlinkFragments = yield buildRunOrHyperLink(childVNode, isVNode(childVNode) && childVNode.tagName === 'img'
2686
+ ? Object.assign(Object.assign({}, modifiedAttributes), { type: 'picture' }) : modifiedAttributes, docxDocumentInstance);
2687
+ if (Array.isArray(runOrHyperlinkFragments)) {
2688
+ for (let iteratorIndex = 0; iteratorIndex < runOrHyperlinkFragments.length; iteratorIndex++) {
2689
+ const runOrHyperlinkFragment = runOrHyperlinkFragments[iteratorIndex];
2690
+ paragraphFragment.import(runOrHyperlinkFragment);
2691
+ }
2692
+ }
2693
+ else {
2694
+ paragraphFragment.import(runOrHyperlinkFragments);
2695
+ }
2696
+ }
2697
+ }
2698
+ }
2699
+ else {
2700
+ // In case paragraphs has to be rendered where vText is present. Eg. table-cell
2701
+ // Or in case the vNode is something like img
2702
+ if (isVNode(vNode) && vNode.tagName === 'img') {
2703
+ const imageSource = vNode.properties.src;
2704
+ let base64String = imageSource;
2705
+ if (isValidUrl(imageSource)) {
2706
+ base64String = yield imageToBase64(imageSource).catch((error) => {
2707
+ // eslint-disable-next-line no-console
2708
+ console.warning(`skipping image download and conversion due to ${error}`);
2709
+ });
2710
+ if (base64String && mimeTypes.lookup(imageSource)) {
2711
+ vNode.properties.src = `data:${mimeTypes.lookup(imageSource)};base64, ${base64String}`;
2712
+ }
2713
+ else {
2714
+ paragraphFragment.up();
2715
+ return paragraphFragment;
2716
+ }
2717
+ }
2718
+ else {
2719
+ // eslint-disable-next-line no-useless-escape, prefer-destructuring
2720
+ base64String = base64String.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/)[2];
2721
+ }
2722
+ const imageBuffer = Buffer.from(decodeURIComponent(base64String), 'base64');
2723
+ const imageProperties = sizeOf(imageBuffer);
2724
+ modifiedAttributes.maximumWidth =
2725
+ modifiedAttributes.maximumWidth || docxDocumentInstance.availableDocumentSpace;
2726
+ modifiedAttributes.originalWidth = imageProperties.width;
2727
+ modifiedAttributes.originalHeight = imageProperties.height;
2728
+ computeImageDimensions(vNode, modifiedAttributes);
2729
+ }
2730
+ const runFragments = yield buildRunOrRuns(vNode, modifiedAttributes, docxDocumentInstance);
2731
+ if (Array.isArray(runFragments)) {
2732
+ for (let index = 0; index < runFragments.length; index++) {
2733
+ const runFragment = runFragments[index];
2734
+ paragraphFragment.import(runFragment);
2735
+ }
2736
+ }
2737
+ else {
2738
+ paragraphFragment.import(runFragments);
2739
+ }
2740
+ }
2741
+ paragraphFragment.up();
2742
+ return paragraphFragment;
2743
+ });
2744
+ const ɵ38 = buildParagraph;
2745
+ const buildGridSpanFragment = (spanValue) => fragment({ namespaceAlias: { w: namespaces.w } })
2746
+ .ele('@w', 'gridSpan')
2747
+ .att('@w', 'val', spanValue)
2748
+ .up();
2749
+ const ɵ39 = buildGridSpanFragment;
2750
+ const buildTableCellSpacing = (cellSpacing = 0) => fragment({ namespaceAlias: { w: namespaces.w } })
2751
+ .ele('@w', 'tblCellSpacing')
2752
+ .att('@w', 'w', cellSpacing)
2753
+ .att('@w', 'type', 'dxa')
2754
+ .up();
2755
+ const ɵ40 = buildTableCellSpacing;
2756
+ const buildTableCellBorders = (tableCellBorder) => {
2757
+ const tableCellBordersFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tcBorders');
2758
+ const { color, stroke } = tableCellBorder, borders = __rest(tableCellBorder, ["color", "stroke"]);
2759
+ Object.keys(borders).forEach((border) => {
2760
+ if (tableCellBorder[border]) {
2761
+ const borderFragment = buildBorder(border, tableCellBorder[border], 0, color, stroke);
2762
+ tableCellBordersFragment.import(borderFragment);
2763
+ }
2764
+ });
2765
+ tableCellBordersFragment.up();
2766
+ return tableCellBordersFragment;
2767
+ };
2768
+ const ɵ41 = buildTableCellBorders;
2769
+ const buildTableCellWidth = (tableCellWidth) => fragment({ namespaceAlias: { w: namespaces.w } })
2770
+ .ele('@w', 'tcW')
2771
+ .att('@w', 'w', fixupColumnWidth(tableCellWidth))
2772
+ .att('@w', 'type', 'dxa')
2773
+ .up();
2774
+ const ɵ42 = buildTableCellWidth;
2775
+ const buildTableCellProperties = (attributes) => {
2776
+ const tableCellPropertiesFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tcPr');
2777
+ if (attributes && attributes.constructor === Object) {
2778
+ Object.keys(attributes).forEach((key) => {
2779
+ switch (key) {
2780
+ case 'backgroundColor':
2781
+ const shadingFragment = buildShading(attributes[key]);
2782
+ tableCellPropertiesFragment.import(shadingFragment);
2783
+ // eslint-disable-next-line no-param-reassign
2784
+ delete attributes.backgroundColor;
2785
+ break;
2786
+ case 'verticalAlign':
2787
+ const verticalAlignmentFragment = buildVerticalAlignment(attributes[key]);
2788
+ tableCellPropertiesFragment.import(verticalAlignmentFragment);
2789
+ // eslint-disable-next-line no-param-reassign
2790
+ delete attributes.verticalAlign;
2791
+ break;
2792
+ case 'colSpan':
2793
+ const gridSpanFragment = buildGridSpanFragment(attributes[key]);
2794
+ tableCellPropertiesFragment.import(gridSpanFragment);
2795
+ // eslint-disable-next-line no-param-reassign
2796
+ delete attributes.colSpan;
2797
+ break;
2798
+ case 'tableCellBorder':
2799
+ const tableCellBorderFragment = buildTableCellBorders(attributes[key]);
2800
+ tableCellPropertiesFragment.import(tableCellBorderFragment);
2801
+ // eslint-disable-next-line no-param-reassign
2802
+ delete attributes.tableCellBorder;
2803
+ break;
2804
+ case 'rowSpan':
2805
+ const verticalMergeFragment = buildVerticalMerge(attributes[key]);
2806
+ tableCellPropertiesFragment.import(verticalMergeFragment);
2807
+ delete attributes.rowSpan;
2808
+ break;
2809
+ case 'width':
2810
+ const widthFragment = buildTableCellWidth(attributes[key]);
2811
+ tableCellPropertiesFragment.import(widthFragment);
2812
+ delete attributes.width;
2813
+ break;
2814
+ }
2815
+ });
2816
+ }
2817
+ tableCellPropertiesFragment.up();
2818
+ return tableCellPropertiesFragment;
2819
+ };
2820
+ const ɵ43 = buildTableCellProperties;
2821
+ const fixupTableCellBorder = (vNode, attributes) => {
2822
+ if (Object.prototype.hasOwnProperty.call(vNode.properties.style, 'border')) {
2823
+ if (vNode.properties.style.border === 'none' || vNode.properties.style.border === 0) {
2824
+ attributes.tableCellBorder = {};
2825
+ }
2826
+ else {
2827
+ // eslint-disable-next-line no-use-before-define
2828
+ const [borderSize, borderStroke, borderColor] = cssBorderParser(vNode.properties.style.border);
2829
+ attributes.tableCellBorder = {
2830
+ top: borderSize,
2831
+ left: borderSize,
2832
+ bottom: borderSize,
2833
+ right: borderSize,
2834
+ color: borderColor,
2835
+ stroke: borderStroke,
2836
+ };
2837
+ }
2838
+ }
2839
+ if (vNode.properties.style['border-top'] && vNode.properties.style['border-top'] === '0') {
2840
+ attributes.tableCellBorder = Object.assign(Object.assign({}, attributes.tableCellBorder), { top: 0 });
2841
+ }
2842
+ else if (vNode.properties.style['border-top'] && vNode.properties.style['border-top'] !== '0') {
2843
+ // eslint-disable-next-line no-use-before-define
2844
+ const [borderSize, borderStroke, borderColor] = cssBorderParser(vNode.properties.style['border-top']);
2845
+ attributes.tableCellBorder = Object.assign(Object.assign({}, attributes.tableCellBorder), { top: borderSize, color: borderColor, stroke: borderStroke });
2846
+ }
2847
+ if (vNode.properties.style['border-left'] && vNode.properties.style['border-left'] === '0') {
2848
+ attributes.tableCellBorder = Object.assign(Object.assign({}, attributes.tableCellBorder), { left: 0 });
2849
+ }
2850
+ else if (vNode.properties.style['border-left'] &&
2851
+ vNode.properties.style['border-left'] !== '0') {
2852
+ // eslint-disable-next-line no-use-before-define
2853
+ const [borderSize, borderStroke, borderColor] = cssBorderParser(vNode.properties.style['border-left']);
2854
+ attributes.tableCellBorder = Object.assign(Object.assign({}, attributes.tableCellBorder), { left: borderSize, color: borderColor, stroke: borderStroke });
2855
+ }
2856
+ if (vNode.properties.style['border-bottom'] && vNode.properties.style['border-bottom'] === '0') {
2857
+ attributes.tableCellBorder = Object.assign(Object.assign({}, attributes.tableCellBorder), { bottom: 0 });
2858
+ }
2859
+ else if (vNode.properties.style['border-bottom'] &&
2860
+ vNode.properties.style['border-bottom'] !== '0') {
2861
+ // eslint-disable-next-line no-use-before-define
2862
+ const [borderSize, borderStroke, borderColor] = cssBorderParser(vNode.properties.style['border-bottom']);
2863
+ attributes.tableCellBorder = Object.assign(Object.assign({}, attributes.tableCellBorder), { bottom: borderSize, color: borderColor, stroke: borderStroke });
2864
+ }
2865
+ if (vNode.properties.style['border-right'] && vNode.properties.style['border-right'] === '0') {
2866
+ attributes.tableCellBorder = Object.assign(Object.assign({}, attributes.tableCellBorder), { right: 0 });
2867
+ }
2868
+ else if (vNode.properties.style['border-right'] &&
2869
+ vNode.properties.style['border-right'] !== '0') {
2870
+ // eslint-disable-next-line no-use-before-define
2871
+ const [borderSize, borderStroke, borderColor] = cssBorderParser(vNode.properties.style['border-right']);
2872
+ attributes.tableCellBorder = Object.assign(Object.assign({}, attributes.tableCellBorder), { right: borderSize, color: borderColor, stroke: borderStroke });
2873
+ }
2874
+ };
2875
+ const ɵ44 = fixupTableCellBorder;
2876
+ const buildTableCell = (vNode, attributes, rowSpanMap, columnIndex, docxDocumentInstance) => __awaiter(void 0, void 0, void 0, function* () {
2877
+ const tableCellFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tc');
2878
+ let modifiedAttributes = Object.assign({}, attributes);
2879
+ if (isVNode(vNode) && vNode.properties) {
2880
+ if (vNode.properties.rowSpan) {
2881
+ rowSpanMap.set(columnIndex.index, { rowSpan: vNode.properties.rowSpan - 1, colSpan: 0 });
2882
+ modifiedAttributes.rowSpan = 'restart';
2883
+ }
2884
+ else {
2885
+ const previousSpanObject = rowSpanMap.get(columnIndex.index);
2886
+ rowSpanMap.set(columnIndex.index,
2887
+ // eslint-disable-next-line prefer-object-spread
2888
+ Object.assign({}, previousSpanObject, {
2889
+ rowSpan: 0,
2890
+ colSpan: (previousSpanObject && previousSpanObject.colSpan) || 0,
2891
+ }));
2892
+ }
2893
+ if (vNode.properties.colSpan ||
2894
+ (vNode.properties.style && vNode.properties.style['column-span'])) {
2895
+ modifiedAttributes.colSpan =
2896
+ vNode.properties.colSpan ||
2897
+ (vNode.properties.style && vNode.properties.style['column-span']);
2898
+ const previousSpanObject = rowSpanMap.get(columnIndex.index);
2899
+ rowSpanMap.set(columnIndex.index,
2900
+ // eslint-disable-next-line prefer-object-spread
2901
+ Object.assign({}, previousSpanObject, {
2902
+ colSpan: parseInt(modifiedAttributes.colSpan) || 0,
2903
+ }));
2904
+ columnIndex.index += parseInt(modifiedAttributes.colSpan) - 1;
2905
+ }
2906
+ if (vNode.properties.style) {
2907
+ modifiedAttributes = Object.assign(Object.assign({}, modifiedAttributes), modifiedStyleAttributesBuilder(vNode, attributes));
2908
+ fixupTableCellBorder(vNode, modifiedAttributes);
2909
+ }
2910
+ }
2911
+ const tableCellPropertiesFragment = buildTableCellProperties(modifiedAttributes);
2912
+ tableCellFragment.import(tableCellPropertiesFragment);
2913
+ if (vNodeHasChildren(vNode)) {
2914
+ for (let index = 0; index < vNode.children.length; index++) {
2915
+ const childVNode = vNode.children[index];
2916
+ if (isVNode(childVNode) && childVNode.tagName === 'img') {
2917
+ const imageFragment = yield buildImage(docxDocumentInstance, childVNode, modifiedAttributes.maximumWidth);
2918
+ if (imageFragment) {
2919
+ tableCellFragment.import(imageFragment);
2920
+ }
2921
+ }
2922
+ else if (isVNode(childVNode) && childVNode.tagName === 'figure') {
2923
+ if (vNodeHasChildren(childVNode)) {
2924
+ // eslint-disable-next-line no-plusplus
2925
+ for (let iteratorIndex = 0; iteratorIndex < childVNode.children.length; iteratorIndex++) {
2926
+ const grandChildVNode = childVNode.children[iteratorIndex];
2927
+ if (grandChildVNode.tagName === 'img') {
2928
+ const imageFragment = yield buildImage(docxDocumentInstance, grandChildVNode, modifiedAttributes.maximumWidth);
2929
+ if (imageFragment) {
2930
+ tableCellFragment.import(imageFragment);
2931
+ }
2932
+ }
2933
+ }
2934
+ }
2935
+ }
2936
+ else if (isVNode(childVNode) && ['ul', 'ol'].includes(childVNode.tagName)) {
2937
+ // render list in table
2938
+ if (vNodeHasChildren(childVNode)) {
2939
+ yield buildList(childVNode, docxDocumentInstance, tableCellFragment);
2940
+ }
2941
+ }
2942
+ else {
2943
+ const paragraphFragment = yield buildParagraph(childVNode, modifiedAttributes, docxDocumentInstance);
2944
+ tableCellFragment.import(paragraphFragment);
2945
+ }
2946
+ }
2947
+ }
2948
+ else {
2949
+ // TODO: Figure out why building with buildParagraph() isn't working
2950
+ const paragraphFragment = fragment({ namespaceAlias: { w: namespaces.w } })
2951
+ .ele('@w', 'p')
2952
+ .up();
2953
+ tableCellFragment.import(paragraphFragment);
2954
+ }
2955
+ tableCellFragment.up();
2956
+ return tableCellFragment;
2957
+ });
2958
+ const ɵ45 = buildTableCell;
2959
+ const buildRowSpanCell = (rowSpanMap, columnIndex, attributes) => {
2960
+ const rowSpanCellFragments = [];
2961
+ let spanObject = rowSpanMap.get(columnIndex.index);
2962
+ while (spanObject && spanObject.rowSpan) {
2963
+ const rowSpanCellFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tc');
2964
+ const tableCellPropertiesFragment = buildTableCellProperties(Object.assign(Object.assign({}, attributes), { rowSpan: 'continue', colSpan: spanObject.colSpan ? spanObject.colSpan : 0 }));
2965
+ rowSpanCellFragment.import(tableCellPropertiesFragment);
2966
+ const paragraphFragment = fragment({ namespaceAlias: { w: namespaces.w } })
2967
+ .ele('@w', 'p')
2968
+ .up();
2969
+ rowSpanCellFragment.import(paragraphFragment);
2970
+ rowSpanCellFragment.up();
2971
+ rowSpanCellFragments.push(rowSpanCellFragment);
2972
+ if (spanObject.rowSpan - 1 === 0) {
2973
+ rowSpanMap.delete(columnIndex.index);
2974
+ }
2975
+ else {
2976
+ rowSpanMap.set(columnIndex.index, {
2977
+ rowSpan: spanObject.rowSpan - 1,
2978
+ colSpan: spanObject.colSpan || 0,
2979
+ });
2980
+ }
2981
+ columnIndex.index += spanObject.colSpan || 1;
2982
+ spanObject = rowSpanMap.get(columnIndex.index);
2983
+ }
2984
+ return rowSpanCellFragments;
2985
+ };
2986
+ const ɵ46 = buildRowSpanCell;
2987
+ const buildTableRowProperties = (attributes) => {
2988
+ const tableRowPropertiesFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'trPr');
2989
+ if (attributes && attributes.constructor === Object) {
2990
+ Object.keys(attributes).forEach((key) => {
2991
+ switch (key) {
2992
+ case 'tableRowHeight':
2993
+ const tableRowHeightFragment = buildTableRowHeight(attributes[key]);
2994
+ tableRowPropertiesFragment.import(tableRowHeightFragment);
2995
+ // eslint-disable-next-line no-param-reassign
2996
+ delete attributes.tableRowHeight;
2997
+ break;
2998
+ case 'rowCantSplit':
2999
+ if (attributes.rowCantSplit) {
3000
+ const cantSplitFragment = fragment({ namespaceAlias: { w: namespaces.w } })
3001
+ .ele('@w', 'cantSplit')
3002
+ .up();
3003
+ tableRowPropertiesFragment.import(cantSplitFragment);
3004
+ // eslint-disable-next-line no-param-reassign
3005
+ delete attributes.rowCantSplit;
3006
+ }
3007
+ break;
3008
+ }
3009
+ });
3010
+ }
3011
+ tableRowPropertiesFragment.up();
3012
+ return tableRowPropertiesFragment;
3013
+ };
3014
+ const ɵ47 = buildTableRowProperties;
3015
+ const buildTableRow = (vNode, attributes, rowSpanMap, docxDocumentInstance) => __awaiter(void 0, void 0, void 0, function* () {
3016
+ const tableRowFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tr');
3017
+ const modifiedAttributes = Object.assign({}, attributes);
3018
+ if (isVNode(vNode) && vNode.properties) {
3019
+ // FIXME: find a better way to get row height from cell style
3020
+ if ((vNode.properties.style && vNode.properties.style.height) ||
3021
+ (vNode.children[0] &&
3022
+ isVNode(vNode.children[0]) &&
3023
+ vNode.children[0].properties.style &&
3024
+ vNode.children[0].properties.style.height)) {
3025
+ modifiedAttributes.tableRowHeight = fixupRowHeight((vNode.properties.style && vNode.properties.style.height) ||
3026
+ (vNode.children[0] &&
3027
+ isVNode(vNode.children[0]) &&
3028
+ vNode.children[0].properties.style &&
3029
+ vNode.children[0].properties.style.height
3030
+ ? vNode.children[0].properties.style.height
3031
+ : undefined));
3032
+ }
3033
+ if (vNode.properties.style) {
3034
+ fixupTableCellBorder(vNode, modifiedAttributes);
3035
+ }
3036
+ }
3037
+ const tableRowPropertiesFragment = buildTableRowProperties(modifiedAttributes);
3038
+ tableRowFragment.import(tableRowPropertiesFragment);
3039
+ const columnIndex = { index: 0 };
3040
+ if (vNodeHasChildren(vNode)) {
3041
+ const tableColumns = vNode.children.filter((childVNode) => ['td', 'th'].includes(childVNode.tagName));
3042
+ const maximumColumnWidth = docxDocumentInstance.availableDocumentSpace / tableColumns.length;
3043
+ // eslint-disable-next-line no-restricted-syntax
3044
+ for (const column of tableColumns) {
3045
+ const rowSpanCellFragments = buildRowSpanCell(rowSpanMap, columnIndex, modifiedAttributes);
3046
+ if (Array.isArray(rowSpanCellFragments)) {
3047
+ for (let iteratorIndex = 0; iteratorIndex < rowSpanCellFragments.length; iteratorIndex++) {
3048
+ const rowSpanCellFragment = rowSpanCellFragments[iteratorIndex];
3049
+ tableRowFragment.import(rowSpanCellFragment);
3050
+ }
3051
+ }
3052
+ const tableCellFragment = yield buildTableCell(column, Object.assign(Object.assign({}, modifiedAttributes), { maximumWidth: maximumColumnWidth }), rowSpanMap, columnIndex, docxDocumentInstance);
3053
+ columnIndex.index++;
3054
+ tableRowFragment.import(tableCellFragment);
3055
+ }
3056
+ }
3057
+ if (columnIndex.index < rowSpanMap.size) {
3058
+ const rowSpanCellFragments = buildRowSpanCell(rowSpanMap, columnIndex, modifiedAttributes);
3059
+ if (Array.isArray(rowSpanCellFragments)) {
3060
+ for (let iteratorIndex = 0; iteratorIndex < rowSpanCellFragments.length; iteratorIndex++) {
3061
+ const rowSpanCellFragment = rowSpanCellFragments[iteratorIndex];
3062
+ tableRowFragment.import(rowSpanCellFragment);
3063
+ }
3064
+ }
3065
+ }
3066
+ tableRowFragment.up();
3067
+ return tableRowFragment;
3068
+ });
3069
+ const ɵ48 = buildTableRow;
3070
+ const buildTableGridCol = (gridWidth) => fragment({ namespaceAlias: { w: namespaces.w } })
3071
+ .ele('@w', 'gridCol')
3072
+ .att('@w', 'w', String(gridWidth));
3073
+ const ɵ49 = buildTableGridCol;
3074
+ const buildTableGrid = (vNode, attributes) => {
3075
+ const tableGridFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tblGrid');
3076
+ if (vNodeHasChildren(vNode)) {
3077
+ const gridColumns = vNode.children.filter((childVNode) => childVNode.tagName === 'col');
3078
+ const gridWidth = attributes.maximumWidth / gridColumns.length;
3079
+ for (let index = 0; index < gridColumns.length; index++) {
3080
+ const tableGridColFragment = buildTableGridCol(gridWidth);
3081
+ tableGridFragment.import(tableGridColFragment);
3082
+ }
3083
+ }
3084
+ tableGridFragment.up();
3085
+ return tableGridFragment;
3086
+ };
3087
+ const ɵ50 = buildTableGrid;
3088
+ const buildTableGridFromTableRow = (vNode, attributes) => {
3089
+ const tableGridFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tblGrid');
3090
+ if (vNodeHasChildren(vNode)) {
3091
+ const numberOfGridColumns = vNode.children.reduce((accumulator, childVNode) => {
3092
+ const colSpan = childVNode.properties.colSpan ||
3093
+ (childVNode.properties.style && childVNode.properties.style['column-span']);
3094
+ return accumulator + (colSpan ? parseInt(colSpan) : 1);
3095
+ }, 0);
3096
+ const gridWidth = attributes.maximumWidth / numberOfGridColumns;
3097
+ for (let index = 0; index < numberOfGridColumns; index++) {
3098
+ const tableGridColFragment = buildTableGridCol(gridWidth);
3099
+ tableGridFragment.import(tableGridColFragment);
3100
+ }
3101
+ }
3102
+ tableGridFragment.up();
3103
+ return tableGridFragment;
3104
+ };
3105
+ const ɵ51 = buildTableGridFromTableRow;
3106
+ const buildTableBorders = (tableBorder) => {
3107
+ const tableBordersFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tblBorders');
3108
+ const { color, stroke } = tableBorder, borders = __rest(tableBorder, ["color", "stroke"]);
3109
+ Object.keys(borders).forEach((border) => {
3110
+ if (borders[border]) {
3111
+ const borderFragment = buildBorder(border, borders[border], 0, color, stroke);
3112
+ tableBordersFragment.import(borderFragment);
3113
+ }
3114
+ });
3115
+ tableBordersFragment.up();
3116
+ return tableBordersFragment;
3117
+ };
3118
+ const ɵ52 = buildTableBorders;
3119
+ const buildTableWidth = (tableWidth) => fragment({ namespaceAlias: { w: namespaces.w } })
3120
+ .ele('@w', 'tblW')
3121
+ .att('@w', 'type', 'dxa')
3122
+ .att('@w', 'w', String(tableWidth))
3123
+ .up();
3124
+ const ɵ53 = buildTableWidth;
3125
+ const buildCellMargin = (side, margin) => fragment({ namespaceAlias: { w: namespaces.w } })
3126
+ .ele('@w', side)
3127
+ .att('@w', 'type', 'dxa')
3128
+ .att('@w', 'w', String(margin))
3129
+ .up();
3130
+ const ɵ54 = buildCellMargin;
3131
+ const buildTableCellMargins = (margin) => {
3132
+ const tableCellMarFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tblCellMar');
3133
+ ['top', 'bottom'].forEach((side) => {
3134
+ const marginFragment = buildCellMargin(side, margin / 2);
3135
+ tableCellMarFragment.import(marginFragment);
3136
+ });
3137
+ ['left', 'right'].forEach((side) => {
3138
+ const marginFragment = buildCellMargin(side, margin);
3139
+ tableCellMarFragment.import(marginFragment);
3140
+ });
3141
+ return tableCellMarFragment;
3142
+ };
3143
+ const ɵ55 = buildTableCellMargins;
3144
+ const buildTableProperties = (attributes) => {
3145
+ const tablePropertiesFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tblPr');
3146
+ if (attributes && attributes.constructor === Object) {
3147
+ Object.keys(attributes).forEach((key) => {
3148
+ switch (key) {
3149
+ case 'tableBorder':
3150
+ const tableBordersFragment = buildTableBorders(attributes[key]);
3151
+ tablePropertiesFragment.import(tableBordersFragment);
3152
+ // eslint-disable-next-line no-param-reassign
3153
+ delete attributes.tableBorder;
3154
+ break;
3155
+ case 'tableCellSpacing':
3156
+ const tableCellSpacingFragment = buildTableCellSpacing(attributes[key]);
3157
+ tablePropertiesFragment.import(tableCellSpacingFragment);
3158
+ // eslint-disable-next-line no-param-reassign
3159
+ delete attributes.tableCellSpacing;
3160
+ break;
3161
+ case 'width':
3162
+ if (attributes[key]) {
3163
+ const tableWidthFragment = buildTableWidth(attributes[key]);
3164
+ tablePropertiesFragment.import(tableWidthFragment);
3165
+ }
3166
+ // eslint-disable-next-line no-param-reassign
3167
+ delete attributes.width;
3168
+ break;
3169
+ }
3170
+ });
3171
+ }
3172
+ const tableCellMarginFragment = buildTableCellMargins(160);
3173
+ tablePropertiesFragment.import(tableCellMarginFragment);
3174
+ // by default, all tables are center aligned.
3175
+ const alignmentFragment = buildHorizontalAlignment('center');
3176
+ tablePropertiesFragment.import(alignmentFragment);
3177
+ tablePropertiesFragment.up();
3178
+ return tablePropertiesFragment;
3179
+ };
3180
+ const ɵ56 = buildTableProperties;
3181
+ const cssBorderParser = (borderString) => {
3182
+ let [size, stroke, color] = borderString.split(' ');
3183
+ if (pointRegex.test(size)) {
3184
+ const matchedParts = size.match(pointRegex);
3185
+ // convert point to eighth of a point
3186
+ size = pointToEIP(matchedParts[1]);
3187
+ }
3188
+ else if (pixelRegex.test(size)) {
3189
+ const matchedParts = size.match(pixelRegex);
3190
+ // convert pixels to eighth of a point
3191
+ size = pixelToEIP(matchedParts[1]);
3192
+ }
3193
+ stroke = stroke && ['dashed', 'dotted', 'double'].includes(stroke) ? stroke : 'single';
3194
+ color = color && fixupColorCode(color).toUpperCase();
3195
+ return [size, stroke, color];
3196
+ };
3197
+ const ɵ57 = cssBorderParser;
3198
+ const buildTable = (vNode, attributes, docxDocumentInstance) => __awaiter(void 0, void 0, void 0, function* () {
3199
+ const tableFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'tbl');
3200
+ const modifiedAttributes = Object.assign({}, attributes);
3201
+ if (isVNode(vNode) && vNode.properties) {
3202
+ const tableAttributes = vNode.properties.attributes || {};
3203
+ const tableStyles = vNode.properties.style || {};
3204
+ const tableBorders = {};
3205
+ const tableCellBorders = {};
3206
+ let [borderSize, borderStrike, borderColor] = [2, 'single', '000000'];
3207
+ // eslint-disable-next-line no-restricted-globals
3208
+ if (!isNaN(tableAttributes.border)) {
3209
+ borderSize = parseInt(tableAttributes.border, 10);
3210
+ }
3211
+ // css style overrides table border properties
3212
+ if (tableStyles.border) {
3213
+ const [cssSize, cssStroke, cssColor] = cssBorderParser(tableStyles.border);
3214
+ borderSize = cssSize || borderSize;
3215
+ borderColor = cssColor || borderColor;
3216
+ borderStrike = cssStroke || borderStrike;
3217
+ }
3218
+ tableBorders.top = borderSize;
3219
+ tableBorders.bottom = borderSize;
3220
+ tableBorders.left = borderSize;
3221
+ tableBorders.right = borderSize;
3222
+ tableBorders.stroke = borderStrike;
3223
+ tableBorders.color = borderColor;
3224
+ if (tableStyles['border-collapse'] === 'collapse') {
3225
+ tableBorders.insideV = borderSize;
3226
+ tableBorders.insideH = borderSize;
3227
+ }
3228
+ else {
3229
+ tableBorders.insideV = 0;
3230
+ tableBorders.insideH = 0;
3231
+ tableCellBorders.top = 1;
3232
+ tableCellBorders.bottom = 1;
3233
+ tableCellBorders.left = 1;
3234
+ tableCellBorders.right = 1;
3235
+ }
3236
+ modifiedAttributes.tableBorder = tableBorders;
3237
+ modifiedAttributes.tableCellSpacing = 0;
3238
+ if (Object.keys(tableCellBorders).length) {
3239
+ modifiedAttributes.tableCellBorder = tableCellBorders;
3240
+ }
3241
+ let minimumWidth;
3242
+ let maximumWidth;
3243
+ let width;
3244
+ // Calculate minimum width of table
3245
+ if (pixelRegex.test(tableStyles['min-width'])) {
3246
+ minimumWidth = pixelToTWIP(tableStyles['min-width'].match(pixelRegex)[1]);
3247
+ }
3248
+ else if (percentageRegex.test(tableStyles['min-width'])) {
3249
+ const percentageValue = tableStyles['min-width'].match(percentageRegex)[1];
3250
+ minimumWidth = Math.round((percentageValue / 100) * attributes.maximumWidth);
3251
+ }
3252
+ // Calculate maximum width of table
3253
+ if (pixelRegex.test(tableStyles['max-width'])) {
3254
+ pixelRegex.lastIndex = 0;
3255
+ maximumWidth = pixelToTWIP(tableStyles['max-width'].match(pixelRegex)[1]);
3256
+ }
3257
+ else if (percentageRegex.test(tableStyles['max-width'])) {
3258
+ percentageRegex.lastIndex = 0;
3259
+ const percentageValue = tableStyles['max-width'].match(percentageRegex)[1];
3260
+ maximumWidth = Math.round((percentageValue / 100) * attributes.maximumWidth);
3261
+ }
3262
+ // Calculate specified width of table
3263
+ if (pixelRegex.test(tableStyles.width)) {
3264
+ pixelRegex.lastIndex = 0;
3265
+ width = pixelToTWIP(tableStyles.width.match(pixelRegex)[1]);
3266
+ }
3267
+ else if (percentageRegex.test(tableStyles.width)) {
3268
+ percentageRegex.lastIndex = 0;
3269
+ const percentageValue = tableStyles.width.match(percentageRegex)[1];
3270
+ width = Math.round((percentageValue / 100) * attributes.maximumWidth);
3271
+ }
3272
+ // If width isn't supplied, we should have min-width as the width.
3273
+ if (width) {
3274
+ modifiedAttributes.width = width;
3275
+ if (maximumWidth) {
3276
+ modifiedAttributes.width = Math.min(modifiedAttributes.width, maximumWidth);
3277
+ }
3278
+ if (minimumWidth) {
3279
+ modifiedAttributes.width = Math.max(modifiedAttributes.width, minimumWidth);
3280
+ }
3281
+ }
3282
+ else if (minimumWidth) {
3283
+ modifiedAttributes.width = minimumWidth;
3284
+ }
3285
+ if (modifiedAttributes.width) {
3286
+ modifiedAttributes.width = Math.min(modifiedAttributes.width, attributes.maximumWidth);
3287
+ }
3288
+ }
3289
+ const tablePropertiesFragment = buildTableProperties(modifiedAttributes);
3290
+ tableFragment.import(tablePropertiesFragment);
3291
+ const rowSpanMap = new Map();
3292
+ if (vNodeHasChildren(vNode)) {
3293
+ for (let index = 0; index < vNode.children.length; index++) {
3294
+ const childVNode = vNode.children[index];
3295
+ if (childVNode.tagName === 'colgroup') {
3296
+ const tableGridFragment = buildTableGrid(childVNode, modifiedAttributes);
3297
+ tableFragment.import(tableGridFragment);
3298
+ }
3299
+ else if (childVNode.tagName === 'thead') {
3300
+ for (let iteratorIndex = 0; iteratorIndex < childVNode.children.length; iteratorIndex++) {
3301
+ const grandChildVNode = childVNode.children[iteratorIndex];
3302
+ if (grandChildVNode.tagName === 'tr') {
3303
+ if (iteratorIndex === 0) {
3304
+ const tableGridFragment = buildTableGridFromTableRow(grandChildVNode, modifiedAttributes);
3305
+ tableFragment.import(tableGridFragment);
3306
+ }
3307
+ const tableRowFragment = yield buildTableRow(grandChildVNode, modifiedAttributes, rowSpanMap, docxDocumentInstance);
3308
+ tableFragment.import(tableRowFragment);
3309
+ }
3310
+ }
3311
+ }
3312
+ else if (childVNode.tagName === 'tbody') {
3313
+ for (let iteratorIndex = 0; iteratorIndex < childVNode.children.length; iteratorIndex++) {
3314
+ const grandChildVNode = childVNode.children[iteratorIndex];
3315
+ if (grandChildVNode.tagName === 'tr') {
3316
+ if (iteratorIndex === 0) {
3317
+ const tableGridFragment = buildTableGridFromTableRow(grandChildVNode, modifiedAttributes);
3318
+ tableFragment.import(tableGridFragment);
3319
+ }
3320
+ const tableRowFragment = yield buildTableRow(grandChildVNode, modifiedAttributes, rowSpanMap, docxDocumentInstance);
3321
+ tableFragment.import(tableRowFragment);
3322
+ }
3323
+ }
3324
+ }
3325
+ else if (childVNode.tagName === 'tr') {
3326
+ if (index === 0) {
3327
+ const tableGridFragment = buildTableGridFromTableRow(childVNode, modifiedAttributes);
3328
+ tableFragment.import(tableGridFragment);
3329
+ }
3330
+ const tableRowFragment = yield buildTableRow(childVNode, modifiedAttributes, rowSpanMap, docxDocumentInstance);
3331
+ tableFragment.import(tableRowFragment);
3332
+ }
3333
+ }
3334
+ }
3335
+ tableFragment.up();
3336
+ return tableFragment;
3337
+ });
3338
+ const ɵ58 = buildTable;
3339
+ const buildPresetGeometry = () => fragment({ namespaceAlias: { a: namespaces.a } })
3340
+ .ele('@a', 'prstGeom')
3341
+ .att('prst', 'rect')
3342
+ .up();
3343
+ const ɵ59 = buildPresetGeometry;
3344
+ const buildExtents = ({ width, height }) => fragment({ namespaceAlias: { a: namespaces.a } })
3345
+ .ele('@a', 'ext')
3346
+ .att('cx', width)
3347
+ .att('cy', height)
3348
+ .up();
3349
+ const ɵ60 = buildExtents;
3350
+ const buildOffset = () => fragment({ namespaceAlias: { a: namespaces.a } })
3351
+ .ele('@a', 'off')
3352
+ .att('x', '0')
3353
+ .att('y', '0')
3354
+ .up();
3355
+ const ɵ61 = buildOffset;
3356
+ const buildGraphicFrameTransform = (attributes) => {
3357
+ const graphicFrameTransformFragment = fragment({ namespaceAlias: { a: namespaces.a } }).ele('@a', 'xfrm');
3358
+ const offsetFragment = buildOffset();
3359
+ graphicFrameTransformFragment.import(offsetFragment);
3360
+ const extentsFragment = buildExtents(attributes);
3361
+ graphicFrameTransformFragment.import(extentsFragment);
3362
+ graphicFrameTransformFragment.up();
3363
+ return graphicFrameTransformFragment;
3364
+ };
3365
+ const ɵ62 = buildGraphicFrameTransform;
3366
+ const buildShapeProperties = (attributes) => {
3367
+ const shapeProperties = fragment({ namespaceAlias: { pic: namespaces.pic } }).ele('@pic', 'spPr');
3368
+ const graphicFrameTransformFragment = buildGraphicFrameTransform(attributes);
3369
+ shapeProperties.import(graphicFrameTransformFragment);
3370
+ const presetGeometryFragment = buildPresetGeometry();
3371
+ shapeProperties.import(presetGeometryFragment);
3372
+ shapeProperties.up();
3373
+ return shapeProperties;
3374
+ };
3375
+ const ɵ63 = buildShapeProperties;
3376
+ const buildFillRect = () => fragment({ namespaceAlias: { a: namespaces.a } })
3377
+ .ele('@a', 'fillRect')
3378
+ .up();
3379
+ const ɵ64 = buildFillRect;
3380
+ const buildStretch = () => {
3381
+ const stretchFragment = fragment({ namespaceAlias: { a: namespaces.a } }).ele('@a', 'stretch');
3382
+ const fillRectFragment = buildFillRect();
3383
+ stretchFragment.import(fillRectFragment);
3384
+ stretchFragment.up();
3385
+ return stretchFragment;
3386
+ };
3387
+ const ɵ65 = buildStretch;
3388
+ const buildSrcRectFragment = () => fragment({ namespaceAlias: { a: namespaces.a } })
3389
+ .ele('@a', 'srcRect')
3390
+ .att('b', '0')
3391
+ .att('l', '0')
3392
+ .att('r', '0')
3393
+ .att('t', '0')
3394
+ .up();
3395
+ const ɵ66 = buildSrcRectFragment;
3396
+ const buildBinaryLargeImageOrPicture = (relationshipId) => fragment({
3397
+ namespaceAlias: { a: namespaces.a, r: namespaces.r },
3398
+ })
3399
+ .ele('@a', 'blip')
3400
+ .att('@r', 'embed', `rId${relationshipId}`)
3401
+ // FIXME: possible values 'email', 'none', 'print', 'hqprint', 'screen'
3402
+ .att('cstate', 'print')
3403
+ .up();
3404
+ const ɵ67 = buildBinaryLargeImageOrPicture;
3405
+ const buildBinaryLargeImageOrPictureFill = (relationshipId) => {
3406
+ const binaryLargeImageOrPictureFillFragment = fragment({
3407
+ namespaceAlias: { pic: namespaces.pic },
3408
+ }).ele('@pic', 'blipFill');
3409
+ const binaryLargeImageOrPictureFragment = buildBinaryLargeImageOrPicture(relationshipId);
3410
+ binaryLargeImageOrPictureFillFragment.import(binaryLargeImageOrPictureFragment);
3411
+ const srcRectFragment = buildSrcRectFragment();
3412
+ binaryLargeImageOrPictureFillFragment.import(srcRectFragment);
3413
+ const stretchFragment = buildStretch();
3414
+ binaryLargeImageOrPictureFillFragment.import(stretchFragment);
3415
+ binaryLargeImageOrPictureFillFragment.up();
3416
+ return binaryLargeImageOrPictureFillFragment;
3417
+ };
3418
+ const ɵ68 = buildBinaryLargeImageOrPictureFill;
3419
+ const buildNonVisualPictureDrawingProperties = () => fragment({ namespaceAlias: { pic: namespaces.pic } })
3420
+ .ele('@pic', 'cNvPicPr')
3421
+ .up();
3422
+ const ɵ69 = buildNonVisualPictureDrawingProperties;
3423
+ const buildNonVisualDrawingProperties = (pictureId, pictureNameWithExtension, pictureDescription = '') => fragment({ namespaceAlias: { pic: namespaces.pic } })
3424
+ .ele('@pic', 'cNvPr')
3425
+ .att('id', pictureId)
3426
+ .att('name', pictureNameWithExtension)
3427
+ .att('descr', pictureDescription)
3428
+ .up();
3429
+ const ɵ70 = buildNonVisualDrawingProperties;
3430
+ const buildNonVisualPictureProperties = (pictureId, pictureNameWithExtension, pictureDescription) => {
3431
+ const nonVisualPicturePropertiesFragment = fragment({
3432
+ namespaceAlias: { pic: namespaces.pic },
3433
+ }).ele('@pic', 'nvPicPr');
3434
+ // TODO: Handle picture attributes
3435
+ const nonVisualDrawingPropertiesFragment = buildNonVisualDrawingProperties(pictureId, pictureNameWithExtension, pictureDescription);
3436
+ nonVisualPicturePropertiesFragment.import(nonVisualDrawingPropertiesFragment);
3437
+ const nonVisualPictureDrawingPropertiesFragment = buildNonVisualPictureDrawingProperties();
3438
+ nonVisualPicturePropertiesFragment.import(nonVisualPictureDrawingPropertiesFragment);
3439
+ nonVisualPicturePropertiesFragment.up();
3440
+ return nonVisualPicturePropertiesFragment;
3441
+ };
3442
+ const ɵ71 = buildNonVisualPictureProperties;
3443
+ const buildPicture = ({ id, fileNameWithExtension, description, relationshipId, width, height, }) => {
3444
+ const pictureFragment = fragment({ namespaceAlias: { pic: namespaces.pic } }).ele('@pic', 'pic');
3445
+ const nonVisualPicturePropertiesFragment = buildNonVisualPictureProperties(id, fileNameWithExtension, description);
3446
+ pictureFragment.import(nonVisualPicturePropertiesFragment);
3447
+ const binaryLargeImageOrPictureFill = buildBinaryLargeImageOrPictureFill(relationshipId);
3448
+ pictureFragment.import(binaryLargeImageOrPictureFill);
3449
+ const shapeProperties = buildShapeProperties({ width, height });
3450
+ pictureFragment.import(shapeProperties);
3451
+ pictureFragment.up();
3452
+ return pictureFragment;
3453
+ };
3454
+ const ɵ72 = buildPicture;
3455
+ const buildGraphicData = (graphicType, attributes) => {
3456
+ const graphicDataFragment = fragment({ namespaceAlias: { a: namespaces.a } })
3457
+ .ele('@a', 'graphicData')
3458
+ .att('uri', 'http://schemas.openxmlformats.org/drawingml/2006/picture');
3459
+ if (graphicType === 'picture') {
3460
+ const pictureFragment = buildPicture(attributes);
3461
+ graphicDataFragment.import(pictureFragment);
3462
+ }
3463
+ graphicDataFragment.up();
3464
+ return graphicDataFragment;
3465
+ };
3466
+ const ɵ73 = buildGraphicData;
3467
+ const buildGraphic = (graphicType, attributes) => {
3468
+ const graphicFragment = fragment({ namespaceAlias: { a: namespaces.a } }).ele('@a', 'graphic');
3469
+ // TODO: Handle drawing type
3470
+ const graphicDataFragment = buildGraphicData(graphicType, attributes);
3471
+ graphicFragment.import(graphicDataFragment);
3472
+ graphicFragment.up();
3473
+ return graphicFragment;
3474
+ };
3475
+ const ɵ74 = buildGraphic;
3476
+ const buildDrawingObjectNonVisualProperties = (pictureId, pictureName) => fragment({ namespaceAlias: { wp: namespaces.wp } })
3477
+ .ele('@wp', 'docPr')
3478
+ .att('id', pictureId)
3479
+ .att('name', pictureName)
3480
+ .up();
3481
+ const ɵ75 = buildDrawingObjectNonVisualProperties;
3482
+ const buildWrapSquare = () => fragment({ namespaceAlias: { wp: namespaces.wp } })
3483
+ .ele('@wp', 'wrapSquare')
3484
+ .att('wrapText', 'bothSides')
3485
+ .att('distB', '228600')
3486
+ .att('distT', '228600')
3487
+ .att('distL', '228600')
3488
+ .att('distR', '228600')
3489
+ .up();
3490
+ const ɵ76 = buildWrapSquare;
3491
+ // eslint-disable-next-line no-unused-vars
3492
+ const buildWrapNone = () => fragment({ namespaceAlias: { wp: namespaces.wp } })
3493
+ .ele('@wp', 'wrapNone')
3494
+ .up();
3495
+ const ɵ77 = buildWrapNone;
3496
+ const buildEffectExtentFragment = () => fragment({ namespaceAlias: { wp: namespaces.wp } })
3497
+ .ele('@wp', 'effectExtent')
3498
+ .att('b', '0')
3499
+ .att('l', '0')
3500
+ .att('r', '0')
3501
+ .att('t', '0')
3502
+ .up();
3503
+ const ɵ78 = buildEffectExtentFragment;
3504
+ const buildExtent = ({ width, height }) => fragment({ namespaceAlias: { wp: namespaces.wp } })
3505
+ .ele('@wp', 'extent')
3506
+ .att('cx', width)
3507
+ .att('cy', height)
3508
+ .up();
3509
+ const ɵ79 = buildExtent;
3510
+ const buildPositionV = () => fragment({ namespaceAlias: { wp: namespaces.wp } })
3511
+ .ele('@wp', 'positionV')
3512
+ .att('relativeFrom', 'paragraph')
3513
+ .ele('@wp', 'posOffset')
3514
+ .txt('19050')
3515
+ .up()
3516
+ .up();
3517
+ const ɵ80 = buildPositionV;
3518
+ const buildPositionH = () => fragment({ namespaceAlias: { wp: namespaces.wp } })
3519
+ .ele('@wp', 'positionH')
3520
+ .att('relativeFrom', 'column')
3521
+ .ele('@wp', 'posOffset')
3522
+ .txt('19050')
3523
+ .up()
3524
+ .up();
3525
+ const ɵ81 = buildPositionH;
3526
+ const buildSimplePos = () => fragment({ namespaceAlias: { wp: namespaces.wp } })
3527
+ .ele('@wp', 'simplePos')
3528
+ .att('x', '0')
3529
+ .att('y', '0')
3530
+ .up();
3531
+ const ɵ82 = buildSimplePos;
3532
+ const buildAnchoredDrawing = (graphicType, attributes) => {
3533
+ const anchoredDrawingFragment = fragment({ namespaceAlias: { wp: namespaces.wp } })
3534
+ .ele('@wp', 'anchor')
3535
+ .att('distB', '0')
3536
+ .att('distL', '0')
3537
+ .att('distR', '0')
3538
+ .att('distT', '0')
3539
+ .att('relativeHeight', '0')
3540
+ .att('behindDoc', 'false')
3541
+ .att('locked', 'true')
3542
+ .att('layoutInCell', 'true')
3543
+ .att('allowOverlap', 'false')
3544
+ .att('simplePos', 'false');
3545
+ // Even though simplePos isnt supported by Word 2007 simplePos is required.
3546
+ const simplePosFragment = buildSimplePos();
3547
+ anchoredDrawingFragment.import(simplePosFragment);
3548
+ const positionHFragment = buildPositionH();
3549
+ anchoredDrawingFragment.import(positionHFragment);
3550
+ const positionVFragment = buildPositionV();
3551
+ anchoredDrawingFragment.import(positionVFragment);
3552
+ const extentFragment = buildExtent({ width: attributes.width, height: attributes.height });
3553
+ anchoredDrawingFragment.import(extentFragment);
3554
+ const effectExtentFragment = buildEffectExtentFragment();
3555
+ anchoredDrawingFragment.import(effectExtentFragment);
3556
+ const wrapSquareFragment = buildWrapSquare();
3557
+ anchoredDrawingFragment.import(wrapSquareFragment);
3558
+ const drawingObjectNonVisualPropertiesFragment = buildDrawingObjectNonVisualProperties(attributes.id, attributes.fileNameWithExtension);
3559
+ anchoredDrawingFragment.import(drawingObjectNonVisualPropertiesFragment);
3560
+ const graphicFragment = buildGraphic(graphicType, attributes);
3561
+ anchoredDrawingFragment.import(graphicFragment);
3562
+ anchoredDrawingFragment.up();
3563
+ return anchoredDrawingFragment;
3564
+ };
3565
+ const ɵ83 = buildAnchoredDrawing;
3566
+ const buildInlineDrawing = (graphicType, attributes) => {
3567
+ const inlineDrawingFragment = fragment({ namespaceAlias: { wp: namespaces.wp } })
3568
+ .ele('@wp', 'inline')
3569
+ .att('distB', '0')
3570
+ .att('distL', '0')
3571
+ .att('distR', '0')
3572
+ .att('distT', '0');
3573
+ const extentFragment = buildExtent({ width: attributes.width, height: attributes.height });
3574
+ inlineDrawingFragment.import(extentFragment);
3575
+ const effectExtentFragment = buildEffectExtentFragment();
3576
+ inlineDrawingFragment.import(effectExtentFragment);
3577
+ const drawingObjectNonVisualPropertiesFragment = buildDrawingObjectNonVisualProperties(attributes.id, attributes.fileNameWithExtension);
3578
+ inlineDrawingFragment.import(drawingObjectNonVisualPropertiesFragment);
3579
+ const graphicFragment = buildGraphic(graphicType, attributes);
3580
+ inlineDrawingFragment.import(graphicFragment);
3581
+ inlineDrawingFragment.up();
3582
+ return inlineDrawingFragment;
3583
+ };
3584
+ const ɵ84 = buildInlineDrawing;
3585
+ const buildDrawing = (inlineOrAnchored = false, graphicType, attributes) => {
3586
+ const drawingFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'drawing');
3587
+ const inlineOrAnchoredDrawingFragment = inlineOrAnchored
3588
+ ? buildInlineDrawing(graphicType, attributes)
3589
+ : buildAnchoredDrawing(graphicType, attributes);
3590
+ drawingFragment.import(inlineOrAnchoredDrawingFragment);
3591
+ drawingFragment.up();
3592
+ return drawingFragment;
3593
+ };
3594
+ const ɵ85 = buildDrawing;
3595
+
3596
+ const convertHTML$1 = HTMLToVDOM({
3597
+ VNode,
3598
+ VText,
3599
+ });
3600
+ // eslint-disable-next-line consistent-return, no-shadow
3601
+ const buildImage = (docxDocumentInstance, vNode, maximumWidth = null) => __awaiter(void 0, void 0, void 0, function* () {
3602
+ let response = null;
3603
+ let base64Uri = null;
3604
+ try {
3605
+ const imageSource = vNode.properties.src;
3606
+ if (isValidUrl(imageSource)) {
3607
+ const base64String = yield imageToBase64(imageSource).catch((error) => {
3608
+ // eslint-disable-next-line no-console
3609
+ console.warning(`skipping image download and conversion due to ${error}`);
3610
+ });
3611
+ if (base64String) {
3612
+ base64Uri = `data:${mimeTypes.lookup(imageSource)};base64, ${base64String}`;
3613
+ }
3614
+ }
3615
+ else {
3616
+ base64Uri = decodeURIComponent(vNode.properties.src);
3617
+ }
3618
+ if (base64Uri) {
3619
+ response = docxDocumentInstance.createMediaFile(base64Uri);
3620
+ }
3621
+ }
3622
+ catch (error) {
3623
+ // NOOP
3624
+ }
3625
+ if (response) {
3626
+ docxDocumentInstance.zip
3627
+ .folder('word')
3628
+ .folder('media')
3629
+ .file(response.fileNameWithExtension, Buffer.from(response.fileContent, 'base64'), {
3630
+ createFolders: false,
3631
+ });
3632
+ const documentRelsId = docxDocumentInstance.createDocumentRelationships(docxDocumentInstance.relationshipFilename, imageType, `media/${response.fileNameWithExtension}`, internalRelationship);
3633
+ const imageBuffer = Buffer.from(response.fileContent, 'base64');
3634
+ const imageProperties = sizeOf(imageBuffer);
3635
+ const imageFragment = yield buildParagraph(vNode, Object.assign(Object.assign({ type: 'picture', inlineOrAnchored: true, relationshipId: documentRelsId }, response), { maximumWidth: maximumWidth || docxDocumentInstance.availableDocumentSpace, originalWidth: imageProperties.width, originalHeight: imageProperties.height }), docxDocumentInstance);
3636
+ return imageFragment;
3637
+ }
3638
+ });
3639
+ const buildList = (vNode, docxDocumentInstance, xmlFragment) => __awaiter(void 0, void 0, void 0, function* () {
3640
+ const listElements = [];
3641
+ let vNodeObjects = [
3642
+ {
3643
+ node: vNode,
3644
+ level: 0,
3645
+ type: vNode.tagName,
3646
+ numberingId: docxDocumentInstance.createNumbering(vNode.tagName, vNode.properties),
3647
+ },
3648
+ ];
3649
+ while (vNodeObjects.length) {
3650
+ const tempVNodeObject = vNodeObjects.shift();
3651
+ if (isVText(tempVNodeObject.node) ||
3652
+ (isVNode(tempVNodeObject.node) && !['ul', 'ol', 'li'].includes(tempVNodeObject.node.tagName))) {
3653
+ const paragraphFragment = yield buildParagraph(tempVNodeObject.node, {
3654
+ numbering: { levelId: tempVNodeObject.level, numberingId: tempVNodeObject.numberingId },
3655
+ }, docxDocumentInstance);
3656
+ xmlFragment.import(paragraphFragment);
3657
+ }
3658
+ if (tempVNodeObject.node.children &&
3659
+ tempVNodeObject.node.children.length &&
3660
+ ['ul', 'ol', 'li'].includes(tempVNodeObject.node.tagName)) {
3661
+ const tempVNodeObjects = tempVNodeObject.node.children.reduce((accumulator, childVNode) => {
3662
+ if (['ul', 'ol'].includes(childVNode.tagName)) {
3663
+ accumulator.push({
3664
+ node: childVNode,
3665
+ level: tempVNodeObject.level + 1,
3666
+ type: childVNode.tagName,
3667
+ numberingId: docxDocumentInstance.createNumbering(childVNode.tagName, childVNode.properties),
3668
+ });
3669
+ }
3670
+ else {
3671
+ // eslint-disable-next-line no-lonely-if
3672
+ if (accumulator.length > 0 &&
3673
+ isVNode(accumulator[accumulator.length - 1].node) &&
3674
+ accumulator[accumulator.length - 1].node.tagName.toLowerCase() === 'p') {
3675
+ accumulator[accumulator.length - 1].node.children.push(childVNode);
3676
+ }
3677
+ else {
3678
+ const paragraphVNode = new VNode('p', null,
3679
+ // eslint-disable-next-line no-nested-ternary
3680
+ isVText(childVNode)
3681
+ ? [childVNode]
3682
+ : // eslint-disable-next-line no-nested-ternary
3683
+ isVNode(childVNode)
3684
+ ? childVNode.tagName.toLowerCase() === 'li'
3685
+ ? [...childVNode.children]
3686
+ : [childVNode]
3687
+ : []);
3688
+ accumulator.push({
3689
+ // eslint-disable-next-line prettier/prettier, no-nested-ternary
3690
+ node: isVNode(childVNode)
3691
+ ? // eslint-disable-next-line prettier/prettier, no-nested-ternary
3692
+ childVNode.tagName.toLowerCase() === 'li'
3693
+ ? childVNode
3694
+ : childVNode.tagName.toLowerCase() !== 'p'
3695
+ ? paragraphVNode
3696
+ : childVNode
3697
+ : // eslint-disable-next-line prettier/prettier
3698
+ paragraphVNode,
3699
+ level: tempVNodeObject.level,
3700
+ type: tempVNodeObject.type,
3701
+ numberingId: tempVNodeObject.numberingId,
3702
+ });
3703
+ }
3704
+ }
3705
+ return accumulator;
3706
+ }, []);
3707
+ vNodeObjects = tempVNodeObjects.concat(vNodeObjects);
3708
+ }
3709
+ }
3710
+ return listElements;
3711
+ });
3712
+ function findXMLEquivalent(docxDocumentInstance, vNode, xmlFragment) {
3713
+ return __awaiter(this, void 0, void 0, function* () {
3714
+ if (vNode.tagName === 'div' &&
3715
+ (vNode.properties.attributes.class === 'page-break' ||
3716
+ (vNode.properties.style && vNode.properties.style['page-break-after']))) {
3717
+ const paragraphFragment = fragment({ namespaceAlias: { w: namespaces.w } })
3718
+ .ele('@w', 'p')
3719
+ .ele('@w', 'r')
3720
+ .ele('@w', 'br')
3721
+ .att('@w', 'type', 'page')
3722
+ .up()
3723
+ .up()
3724
+ .up();
3725
+ xmlFragment.import(paragraphFragment);
3726
+ return;
3727
+ }
3728
+ switch (vNode.tagName) {
3729
+ case 'h1':
3730
+ case 'h2':
3731
+ case 'h3':
3732
+ case 'h4':
3733
+ case 'h5':
3734
+ case 'h6':
3735
+ const headingFragment = yield buildParagraph(vNode, {
3736
+ paragraphStyle: `Heading${vNode.tagName[1]}`,
3737
+ }, docxDocumentInstance);
3738
+ xmlFragment.import(headingFragment);
3739
+ return;
3740
+ case 'span':
3741
+ case 'strong':
3742
+ case 'b':
3743
+ case 'em':
3744
+ case 'i':
3745
+ case 'u':
3746
+ case 'ins':
3747
+ case 'strike':
3748
+ case 'del':
3749
+ case 's':
3750
+ case 'sub':
3751
+ case 'sup':
3752
+ case 'mark':
3753
+ case 'p':
3754
+ case 'a':
3755
+ case 'blockquote':
3756
+ case 'code':
3757
+ case 'pre':
3758
+ const paragraphFragment = yield buildParagraph(vNode, {}, docxDocumentInstance);
3759
+ xmlFragment.import(paragraphFragment);
3760
+ return;
3761
+ case 'figure':
3762
+ if (vNodeHasChildren(vNode)) {
3763
+ // eslint-disable-next-line no-plusplus
3764
+ for (let index = 0; index < vNode.children.length; index++) {
3765
+ const childVNode = vNode.children[index];
3766
+ if (childVNode.tagName === 'table') {
3767
+ const tableFragment = yield buildTable(childVNode, {
3768
+ maximumWidth: docxDocumentInstance.availableDocumentSpace,
3769
+ rowCantSplit: docxDocumentInstance.tableRowCantSplit,
3770
+ }, docxDocumentInstance);
3771
+ xmlFragment.import(tableFragment);
3772
+ // Adding empty paragraph for space after table
3773
+ const emptyParagraphFragment = yield buildParagraph(null, {});
3774
+ xmlFragment.import(emptyParagraphFragment);
3775
+ }
3776
+ else if (childVNode.tagName === 'img') {
3777
+ const imageFragment = yield buildImage(docxDocumentInstance, childVNode);
3778
+ if (imageFragment) {
3779
+ xmlFragment.import(imageFragment);
3780
+ }
3781
+ }
3782
+ }
3783
+ }
3784
+ return;
3785
+ case 'table':
3786
+ const tableFragment = yield buildTable(vNode, {
3787
+ maximumWidth: docxDocumentInstance.availableDocumentSpace,
3788
+ rowCantSplit: docxDocumentInstance.tableRowCantSplit,
3789
+ }, docxDocumentInstance);
3790
+ xmlFragment.import(tableFragment);
3791
+ // Adding empty paragraph for space after table
3792
+ const emptyParagraphFragment = yield buildParagraph(null, {});
3793
+ xmlFragment.import(emptyParagraphFragment);
3794
+ return;
3795
+ case 'ol':
3796
+ case 'ul':
3797
+ yield buildList(vNode, docxDocumentInstance, xmlFragment);
3798
+ return;
3799
+ case 'img':
3800
+ const imageFragment = yield buildImage(docxDocumentInstance, vNode);
3801
+ if (imageFragment) {
3802
+ xmlFragment.import(imageFragment);
3803
+ }
3804
+ return;
3805
+ case 'br':
3806
+ const linebreakFragment = yield buildParagraph(null, {});
3807
+ xmlFragment.import(linebreakFragment);
3808
+ return;
3809
+ }
3810
+ if (vNodeHasChildren(vNode)) {
3811
+ // eslint-disable-next-line no-plusplus
3812
+ for (let index = 0; index < vNode.children.length; index++) {
3813
+ const childVNode = vNode.children[index];
3814
+ // eslint-disable-next-line no-use-before-define
3815
+ yield convertVTreeToXML(docxDocumentInstance, childVNode, xmlFragment);
3816
+ }
3817
+ }
3818
+ });
3819
+ }
3820
+ // eslint-disable-next-line consistent-return
3821
+ function convertVTreeToXML(docxDocumentInstance, vTree, xmlFragment) {
3822
+ return __awaiter(this, void 0, void 0, function* () {
3823
+ if (!vTree) {
3824
+ // eslint-disable-next-line no-useless-return
3825
+ return '';
3826
+ }
3827
+ if (Array.isArray(vTree) && vTree.length) {
3828
+ // eslint-disable-next-line no-plusplus
3829
+ for (let index = 0; index < vTree.length; index++) {
3830
+ const vNode = vTree[index];
3831
+ yield convertVTreeToXML(docxDocumentInstance, vNode, xmlFragment);
3832
+ }
3833
+ }
3834
+ else if (isVNode(vTree)) {
3835
+ yield findXMLEquivalent(docxDocumentInstance, vTree, xmlFragment);
3836
+ }
3837
+ else if (isVText(vTree)) {
3838
+ buildTextElement(xmlFragment, escape(String(vTree.text)));
3839
+ }
3840
+ return xmlFragment;
3841
+ });
3842
+ }
3843
+ function renderDocumentFile(docxDocumentInstance) {
3844
+ return __awaiter(this, void 0, void 0, function* () {
3845
+ const vTree = convertHTML$1(docxDocumentInstance.htmlString);
3846
+ const xmlFragment = fragment({ namespaceAlias: { w: namespaces.w } });
3847
+ const populatedXmlFragment = yield convertVTreeToXML(docxDocumentInstance, vTree, xmlFragment);
3848
+ return populatedXmlFragment;
3849
+ });
3850
+ }
3851
+
3852
+ /* eslint-disable import/prefer-default-export */
3853
+
3854
+ class ListStyleBuilder {
3855
+ // defaults is an object passed in from constants.js / numbering with the following properties:
3856
+ // defaultOrderedListStyleType: 'decimal' (unless otherwise specified)
3857
+ constructor(defaults) {
3858
+ this.defaults = defaults || { defaultOrderedListStyleType: 'decimal' };
3859
+ }
3860
+ // eslint-disable-next-line class-methods-use-this
3861
+ getListStyleType(listType) {
3862
+ switch (listType) {
3863
+ case 'upper-roman':
3864
+ return 'upperRoman';
3865
+ case 'lower-roman':
3866
+ return 'lowerRoman';
3867
+ case 'upper-alpha':
3868
+ case 'upper-alpha-bracket-end':
3869
+ return 'upperLetter';
3870
+ case 'lower-alpha':
3871
+ case 'lower-alpha-bracket-end':
3872
+ return 'lowerLetter';
3873
+ case 'decimal':
3874
+ case 'decimal-bracket':
3875
+ return 'decimal';
3876
+ default:
3877
+ return this.defaults.defaultOrderedListStyleType;
3878
+ }
3879
+ }
3880
+ getListPrefixSuffix(style, lvl) {
3881
+ let listType = this.defaults.defaultOrderedListStyleType;
3882
+ if (style && style['list-style-type']) {
3883
+ listType = style['list-style-type'];
3884
+ }
3885
+ switch (listType) {
3886
+ case 'upper-roman':
3887
+ case 'lower-roman':
3888
+ case 'upper-alpha':
3889
+ case 'lower-alpha':
3890
+ return `%${lvl + 1}.`;
3891
+ case 'upper-alpha-bracket-end':
3892
+ case 'lower-alpha-bracket-end':
3893
+ case 'decimal-bracket-end':
3894
+ return `%${lvl + 1})`;
3895
+ case 'decimal-bracket':
3896
+ return `(%${lvl + 1})`;
3897
+ case 'decimal':
3898
+ default:
3899
+ return `%${lvl + 1}.`;
3900
+ }
3901
+ }
3902
+ }
3903
+
3904
+ function generateContentTypesFragments(contentTypesXML, type, objects) {
3905
+ if (objects && Array.isArray(objects)) {
3906
+ objects.forEach((object) => {
3907
+ const contentTypesFragment = fragment({ defaultNamespace: { ele: namespaces.contentTypes } })
3908
+ .ele('Override')
3909
+ .att('PartName', `/word/${type}${object[`${type}Id`]}.xml`)
3910
+ .att('ContentType', `application/vnd.openxmlformats-officedocument.wordprocessingml.${type}+xml`)
3911
+ .up();
3912
+ contentTypesXML.root().import(contentTypesFragment);
3913
+ });
3914
+ }
3915
+ }
3916
+ function generateSectionReferenceXML(documentXML, documentSectionType, objects, isEnabled) {
3917
+ if (isEnabled && objects && Array.isArray(objects) && objects.length) {
3918
+ const xmlFragment = fragment();
3919
+ objects.forEach(({ relationshipId, type }) => {
3920
+ const objectFragment = fragment({ namespaceAlias: { w: namespaces.w, r: namespaces.r } })
3921
+ .ele('@w', `${documentSectionType}Reference`)
3922
+ .att('@r', 'id', `rId${relationshipId}`)
3923
+ .att('@w', 'type', type)
3924
+ .up();
3925
+ xmlFragment.import(objectFragment);
3926
+ });
3927
+ documentXML.root().first().first().import(xmlFragment);
3928
+ }
3929
+ }
3930
+ function generateXMLString(xmlString) {
3931
+ const xmlDocumentString = create({ encoding: 'UTF-8', standalone: true }, xmlString);
3932
+ return xmlDocumentString.toString({ prettyPrint: true });
3933
+ }
3934
+ function generateSectionXML(vTree, type = 'header') {
3935
+ return __awaiter(this, void 0, void 0, function* () {
3936
+ debugger;
3937
+ const sectionXML = create({
3938
+ encoding: 'UTF-8',
3939
+ standalone: true,
3940
+ namespaceAlias: {
3941
+ a: namespaces.a,
3942
+ cdr: namespaces.cdr,
3943
+ o: namespaces.o,
3944
+ pic: namespaces.pic,
3945
+ r: namespaces.r,
3946
+ v: namespaces.v,
3947
+ ve: namespaces.ve,
3948
+ vt: namespaces.vt,
3949
+ w: namespaces.w,
3950
+ w10: namespaces.w10,
3951
+ wp: namespaces.wp,
3952
+ wne: namespaces.wne
3953
+ },
3954
+ }).ele('@w', type === 'header' ? 'hdr' : 'ftr');
3955
+ const XMLFragment = fragment();
3956
+ yield convertVTreeToXML(this, vTree, XMLFragment);
3957
+ if (type === 'footer' && XMLFragment.first().node.tagName === 'p' && this.pageNumber) {
3958
+ XMLFragment.first().import(fragment({ namespaceAlias: { w: namespaces.w } })
3959
+ .ele('@w', 'fldSimple')
3960
+ .att('@w', 'instr', 'PAGE')
3961
+ .ele('@w', 'r')
3962
+ .up()
3963
+ .up());
3964
+ }
3965
+ sectionXML.root().import(XMLFragment);
3966
+ const referenceName = type === 'header' ? 'Header' : 'Footer';
3967
+ this[`last${referenceName}Id`] += 1;
3968
+ return { [`${type}Id`]: this[`last${referenceName}Id`], [`${type}XML`]: sectionXML };
3969
+ });
3970
+ }
3971
+ class DocxDocument {
3972
+ constructor(properties) {
3973
+ this.zip = properties.zip;
3974
+ this.htmlString = properties.htmlString;
3975
+ this.orientation = properties.orientation;
3976
+ this.pageSize = properties.pageSize || defaultDocumentOptions.pageSize;
3977
+ const isPortraitOrientation = this.orientation === defaultOrientation;
3978
+ const height = this.pageSize.height ? this.pageSize.height : landscapeHeight;
3979
+ const width = this.pageSize.width ? this.pageSize.width : landscapeWidth;
3980
+ this.width = isPortraitOrientation ? width : height;
3981
+ this.height = isPortraitOrientation ? height : width;
3982
+ const marginsObject = properties.margins;
3983
+ this.margins =
3984
+ // eslint-disable-next-line no-nested-ternary
3985
+ marginsObject && Object.keys(marginsObject).length
3986
+ ? marginsObject
3987
+ : isPortraitOrientation
3988
+ ? portraitMargins
3989
+ : landscapeMargins;
3990
+ this.availableDocumentSpace = this.width - this.margins.left - this.margins.right;
3991
+ this.title = properties.title || '';
3992
+ this.subject = properties.subject || '';
3993
+ this.creator = properties.creator || applicationName;
3994
+ this.keywords = properties.keywords || [applicationName];
3995
+ this.description = properties.description || '';
3996
+ this.lastModifiedBy = properties.lastModifiedBy || applicationName;
3997
+ this.revision = properties.revision || 1;
3998
+ this.createdAt = properties.createdAt || new Date();
3999
+ this.modifiedAt = properties.modifiedAt || new Date();
4000
+ this.headerType = properties.headerType || 'default';
4001
+ this.header = properties.header || false;
4002
+ this.footerType = properties.footerType || 'default';
4003
+ this.footer = properties.footer || false;
4004
+ this.font = properties.font || defaultFont;
4005
+ this.fontSize = properties.fontSize || defaultFontSize;
4006
+ this.complexScriptFontSize = properties.complexScriptFontSize || defaultFontSize;
4007
+ this.tableRowCantSplit =
4008
+ (properties.table && properties.table.row && properties.table.row.cantSplit) || false;
4009
+ this.pageNumber = properties.pageNumber || false;
4010
+ this.skipFirstHeaderFooter = properties.skipFirstHeaderFooter || false;
4011
+ this.lineNumber = properties.lineNumber ? properties.lineNumberOptions : null;
4012
+ this.lastNumberingId = 0;
4013
+ this.lastMediaId = 0;
4014
+ this.lastHeaderId = 0;
4015
+ this.lastFooterId = 0;
4016
+ this.stylesObjects = [];
4017
+ this.numberingObjects = [];
4018
+ this.relationshipFilename = documentFileName;
4019
+ this.relationships = [{ fileName: documentFileName, lastRelsId: 4, rels: [] }];
4020
+ this.mediaFiles = [];
4021
+ this.headerObjects = [];
4022
+ this.footerObjects = [];
4023
+ this.documentXML = null;
4024
+ this.generateContentTypesXML = this.generateContentTypesXML.bind(this);
4025
+ this.generateDocumentXML = this.generateDocumentXML.bind(this);
4026
+ this.generateCoreXML = this.generateCoreXML.bind(this);
4027
+ this.generateSettingsXML = this.generateSettingsXML.bind(this);
4028
+ this.generateWebSettingsXML = this.generateWebSettingsXML.bind(this);
4029
+ this.generateStylesXML = this.generateStylesXML.bind(this);
4030
+ this.generateFontTableXML = this.generateFontTableXML.bind(this);
4031
+ this.generateThemeXML = this.generateThemeXML.bind(this);
4032
+ this.generateNumberingXML = this.generateNumberingXML.bind(this);
4033
+ this.generateRelsXML = this.generateRelsXML.bind(this);
4034
+ this.createMediaFile = this.createMediaFile.bind(this);
4035
+ this.createDocumentRelationships = this.createDocumentRelationships.bind(this);
4036
+ this.generateHeaderXML = this.generateHeaderXML.bind(this);
4037
+ this.generateFooterXML = this.generateFooterXML.bind(this);
4038
+ this.generateSectionXML = generateSectionXML.bind(this);
4039
+ this.ListStyleBuilder = new ListStyleBuilder(properties.numbering);
4040
+ }
4041
+ generateContentTypesXML() {
4042
+ const contentTypesXML$1 = create({ encoding: 'UTF-8', standalone: true }, contentTypesXML);
4043
+ generateContentTypesFragments(contentTypesXML$1, 'header', this.headerObjects);
4044
+ generateContentTypesFragments(contentTypesXML$1, 'footer', this.footerObjects);
4045
+ return contentTypesXML$1.toString({ prettyPrint: true });
4046
+ }
4047
+ generateDocumentXML() {
4048
+ const documentXML = create({ encoding: 'UTF-8', standalone: true }, generateDocumentTemplate(this.width, this.height, this.orientation, this.margins));
4049
+ // documentXML.root().first().import(this.documentXML);
4050
+ generateSectionReferenceXML(documentXML, 'header', this.headerObjects, this.header);
4051
+ generateSectionReferenceXML(documentXML, 'footer', this.footerObjects, this.footer);
4052
+ if ((this.header || this.footer) && this.skipFirstHeaderFooter) {
4053
+ documentXML
4054
+ .root()
4055
+ .first()
4056
+ .first()
4057
+ .import(fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'titlePg'));
4058
+ }
4059
+ if (this.lineNumber) {
4060
+ const { countBy, start, restart } = this.lineNumber;
4061
+ documentXML
4062
+ .root()
4063
+ .first()
4064
+ .first()
4065
+ .import(fragment({ namespaceAlias: { w: namespaces.w } })
4066
+ .ele('@w', 'lnNumType')
4067
+ .att('@w', 'countBy', countBy)
4068
+ .att('@w', 'start', start)
4069
+ .att('@w', 'restart', restart));
4070
+ }
4071
+ return documentXML.toString({ prettyPrint: true });
4072
+ }
4073
+ generateCoreXML() {
4074
+ return generateXMLString(generateCoreXML(this.title, this.subject, this.creator, this.keywords, this.description, this.lastModifiedBy, this.revision, this.createdAt, this.modifiedAt));
4075
+ }
4076
+ // eslint-disable-next-line class-methods-use-this
4077
+ generateSettingsXML() {
4078
+ return generateXMLString(settingsXML);
4079
+ }
4080
+ // eslint-disable-next-line class-methods-use-this
4081
+ generateWebSettingsXML() {
4082
+ return generateXMLString(webSettingsXML);
4083
+ }
4084
+ generateStylesXML() {
4085
+ return generateXMLString(generateStylesXML(this.font, this.fontSize, this.complexScriptFontSize));
4086
+ }
4087
+ // eslint-disable-next-line class-methods-use-this
4088
+ generateFontTableXML() {
4089
+ return generateXMLString(fontTableXML);
4090
+ }
4091
+ generateThemeXML() {
4092
+ return generateXMLString(generateThemeXML(this.font));
4093
+ }
4094
+ generateNumberingXML() {
4095
+ const numberingXML = create({ encoding: 'UTF-8', standalone: true }, generateNumberingXMLTemplate());
4096
+ const abstractNumberingFragments = fragment();
4097
+ const numberingFragments = fragment();
4098
+ this.numberingObjects.forEach(({ numberingId, type, properties }) => {
4099
+ const abstractNumberingFragment = fragment({ namespaceAlias: { w: namespaces.w } })
4100
+ .ele('@w', 'abstractNum')
4101
+ .att('@w', 'abstractNumId', String(numberingId));
4102
+ [...Array(8).keys()].forEach((level) => {
4103
+ const levelFragment = fragment({ namespaceAlias: { w: namespaces.w } })
4104
+ .ele('@w', 'lvl')
4105
+ .att('@w', 'ilvl', level)
4106
+ .ele('@w', 'start')
4107
+ .att('@w', 'val', type === 'ol'
4108
+ ? (properties.attributes && properties.attributes['data-start']) || 1
4109
+ : '1')
4110
+ .up()
4111
+ .ele('@w', 'numFmt')
4112
+ .att('@w', 'val', type === 'ol'
4113
+ ? this.ListStyleBuilder.getListStyleType(properties.style && properties.style['list-style-type'])
4114
+ : 'bullet')
4115
+ .up()
4116
+ .ele('@w', 'lvlText')
4117
+ .att('@w', 'val', type === 'ol' ? this.ListStyleBuilder.getListPrefixSuffix(properties.style, level) : '')
4118
+ .up()
4119
+ .ele('@w', 'lvlJc')
4120
+ .att('@w', 'val', 'left')
4121
+ .up()
4122
+ .ele('@w', 'pPr')
4123
+ .ele('@w', 'tabs')
4124
+ .ele('@w', 'tab')
4125
+ .att('@w', 'val', 'num')
4126
+ .att('@w', 'pos', (level + 1) * 720)
4127
+ .up()
4128
+ .up()
4129
+ .ele('@w', 'ind')
4130
+ .att('@w', 'left', (level + 1) * 720)
4131
+ .att('@w', 'hanging', 360)
4132
+ .up()
4133
+ .up()
4134
+ .up();
4135
+ if (type === 'ul') {
4136
+ levelFragment.last().import(fragment({ namespaceAlias: { w: namespaces.w } })
4137
+ .ele('@w', 'rPr')
4138
+ .ele('@w', 'rFonts')
4139
+ .att('@w', 'ascii', 'Symbol')
4140
+ .att('@w', 'hAnsi', 'Symbol')
4141
+ .att('@w', 'hint', 'default')
4142
+ .up()
4143
+ .up());
4144
+ }
4145
+ abstractNumberingFragment.import(levelFragment);
4146
+ });
4147
+ abstractNumberingFragment.up();
4148
+ abstractNumberingFragments.import(abstractNumberingFragment);
4149
+ numberingFragments.import(fragment({ namespaceAlias: { w: namespaces.w } })
4150
+ .ele('@w', 'num')
4151
+ .att('@w', 'numId', String(numberingId))
4152
+ .ele('@w', 'abstractNumId')
4153
+ .att('@w', 'val', String(numberingId))
4154
+ .up()
4155
+ .up());
4156
+ });
4157
+ numberingXML.root().import(abstractNumberingFragments);
4158
+ numberingXML.root().import(numberingFragments);
4159
+ return numberingXML.toString({ prettyPrint: true });
4160
+ }
4161
+ // eslint-disable-next-line class-methods-use-this
4162
+ appendRelationships(xmlFragment, relationships) {
4163
+ relationships.forEach(({ relationshipId, type, target, targetMode }) => {
4164
+ xmlFragment.import(fragment({ defaultNamespace: { ele: namespaces.relationship } })
4165
+ .ele('Relationship')
4166
+ .att('Id', `rId${relationshipId}`)
4167
+ .att('Type', type)
4168
+ .att('Target', target)
4169
+ .att('TargetMode', targetMode)
4170
+ .up());
4171
+ });
4172
+ }
4173
+ generateRelsXML() {
4174
+ const relationshipXMLStrings = this.relationships.map(({ fileName, rels }) => {
4175
+ const xmlFragment = create({ encoding: 'UTF-8', standalone: true }, fileName === documentFileName ? documentRelsXML : genericRelsXML);
4176
+ this.appendRelationships(xmlFragment.root(), rels);
4177
+ return { fileName, xmlString: xmlFragment.toString({ prettyPrint: true }) };
4178
+ });
4179
+ return relationshipXMLStrings;
4180
+ }
4181
+ createNumbering(type, properties) {
4182
+ this.lastNumberingId += 1;
4183
+ this.numberingObjects.push({ numberingId: this.lastNumberingId, type, properties });
4184
+ return this.lastNumberingId;
4185
+ }
4186
+ createMediaFile(base64String) {
4187
+ // eslint-disable-next-line no-useless-escape
4188
+ const matches = base64String.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
4189
+ if (matches.length !== 3) {
4190
+ throw new Error('Invalid base64 string');
4191
+ }
4192
+ const base64FileContent = matches[2];
4193
+ // matches array contains file type in base64 format - image/jpeg and base64 stringified data
4194
+ const fileExtension = matches[1].match(/\/(.*?)$/)[1] === 'octet-stream' ? 'png' : matches[1].match(/\/(.*?)$/)[1];
4195
+ const fileNameWithExtension = `image-${nanoid()}.${fileExtension}`;
4196
+ this.lastMediaId += 1;
4197
+ return { id: this.lastMediaId, fileContent: base64FileContent, fileNameWithExtension };
4198
+ }
4199
+ createDocumentRelationships(fileName = 'document', type, target, targetMode = 'External') {
4200
+ debugger;
4201
+ let relationshipObject = this.relationships.find((relationship) => relationship.fileName === fileName);
4202
+ let lastRelsId = 1;
4203
+ if (relationshipObject) {
4204
+ lastRelsId = relationshipObject.lastRelsId + 1;
4205
+ relationshipObject.lastRelsId = lastRelsId;
4206
+ }
4207
+ else {
4208
+ relationshipObject = { fileName, lastRelsId, rels: [] };
4209
+ this.relationships.push(relationshipObject);
4210
+ }
4211
+ let relationshipType;
4212
+ switch (type) {
4213
+ case hyperlinkType:
4214
+ relationshipType = namespaces.hyperlinks;
4215
+ break;
4216
+ case imageType:
4217
+ relationshipType = namespaces.images;
4218
+ break;
4219
+ case headerType:
4220
+ relationshipType = namespaces.headers;
4221
+ break;
4222
+ case footerType:
4223
+ relationshipType = namespaces.footers;
4224
+ break;
4225
+ case themeType:
4226
+ relationshipType = namespaces.themes;
4227
+ break;
4228
+ }
4229
+ relationshipObject.rels.push({
4230
+ relationshipId: lastRelsId,
4231
+ type: relationshipType,
4232
+ target,
4233
+ targetMode,
4234
+ });
4235
+ console.log(fileName);
4236
+ console.log(relationshipObject.rels);
4237
+ return lastRelsId;
4238
+ }
4239
+ generateHeaderXML(vTree) {
4240
+ return this.generateSectionXML(vTree, 'header');
4241
+ }
4242
+ generateFooterXML(vTree) {
4243
+ return this.generateSectionXML(vTree, 'footer');
4244
+ }
4245
+ }
4246
+
4247
+ const defaultMargins = {
4248
+ top: 1440,
4249
+ right: 1440,
4250
+ bottom: 1440,
4251
+ left: 1440,
4252
+ header: 720,
4253
+ footer: 720,
4254
+ gutter: 0,
4255
+ };
4256
+ const documentTemplate = (width, height, orient, margins) => {
4257
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
4258
+ <w:document
4259
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
4260
+ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
4261
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
4262
+ xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
4263
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
4264
+ xmlns:ns6="http://schemas.openxmlformats.org/schemaLibrary/2006/main"
4265
+ xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
4266
+ xmlns:ns8="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"
4267
+ xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"
4268
+ xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
4269
+ xmlns:ns11="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
4270
+ xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram"
4271
+ xmlns:ns13="urn:schemas-microsoft-com:office:excel"
4272
+ xmlns:o="urn:schemas-microsoft-com:office:office"
4273
+ xmlns:v="urn:schemas-microsoft-com:vml"
4274
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
4275
+ xmlns:ns17="urn:schemas-microsoft-com:office:powerpoint"
4276
+ xmlns:odx="http://opendope.org/xpaths"
4277
+ xmlns:odc="http://opendope.org/conditions"
4278
+ xmlns:odq="http://opendope.org/questions"
4279
+ xmlns:odi="http://opendope.org/components"
4280
+ xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy"
4281
+ xmlns:ns24="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"
4282
+ xmlns:ns25="http://schemas.openxmlformats.org/drawingml/2006/compatibility"
4283
+ xmlns:ns26="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas">
4284
+ <w:body>
4285
+ <w:altChunk r:id="htmlChunk" />
4286
+ <w:sectPr>
4287
+ <w:pgSz w:w="${width}" w:h="${height}" w:orient="${orient}" />
4288
+ <w:pgMar w:top="${margins.top}"
4289
+ w:right="${margins.right}"
4290
+ w:bottom="${margins.bottom}"
4291
+ w:left="${margins.left}"
4292
+ w:header="${margins.header}"
4293
+ w:footer="${margins.footer}"
4294
+ w:gutter="${margins.gutter}"/>
4295
+ </w:sectPr>
4296
+ </w:body>
4297
+ </w:document>
4298
+ `;
4299
+ };
4300
+
4301
+ const mhtDocumentTemplate = (htmlSource, contentParts) => {
4302
+ debugger;
4303
+ return `MIME-Version: 1.0
4304
+ Content-Type: multipart/related;
4305
+ type="text/html";
4306
+ boundary="----=mhtDocumentPart"
4307
+
4308
+
4309
+ ------=mhtDocumentPart
4310
+ Content-Type: text/html;
4311
+ charset="utf-8"
4312
+ Content-Transfer-Encoding: quoted-printable
4313
+ Content-Location: file:///C:/fake/document.html
4314
+
4315
+ ${htmlSource}
4316
+
4317
+ ${contentParts}
4318
+
4319
+ ------=mhtDocumentPart--
4320
+ `;
4321
+ };
4322
+
4323
+ const mhtPartTemplate = (contentType, contentEncoding, contentLocation, encodedContent) => {
4324
+ return `------=mhtDocumentPart
4325
+ Content-Type: ${contentType}
4326
+ Content-Transfer-Encoding: ${contentEncoding}
4327
+ Content-Location: ${contentLocation}
4328
+
4329
+ ${encodedContent}
4330
+ `;
4331
+ };
4332
+
4333
+ function getMHTdocument(htmlSource) {
4334
+ debugger;
4335
+ const ref = _prepareImageParts(htmlSource);
4336
+ const imageContentPartsString = ref.imageContentParts.join('\n');
4337
+ htmlSource = ref.htmlSource.replace(/\=/g, '=3D');
4338
+ return mhtDocumentTemplate(htmlSource, imageContentPartsString);
4339
+ }
4340
+ function _prepareImageParts(htmlSource) {
4341
+ debugger;
4342
+ const imageContentParts = [];
4343
+ const inlinedSrcPattern = /"data:(\w+\/\w+);(\w+),(\S+)"/g;
4344
+ const inlinedReplacer = (match, contentType, contentEncoding, encodedContent) => {
4345
+ const index = imageContentParts.length;
4346
+ const extension = contentType.split('/')[1];
4347
+ const contentLocation = `file:///C:/fake/image${index}.${extension}`;
4348
+ imageContentParts.push(mhtPartTemplate(contentType, contentEncoding, contentLocation, encodedContent));
4349
+ return `\"${contentLocation}\"`;
4350
+ };
4351
+ if (!/<img/g.test(htmlSource)) {
4352
+ return { htmlSource, imageContentParts };
4353
+ }
4354
+ htmlSource = htmlSource.replace(inlinedSrcPattern, inlinedReplacer);
4355
+ return { htmlSource, imageContentParts };
4356
+ }
4357
+
4358
+ const convertHTML = HTMLToVDOM({
4359
+ VNode,
4360
+ VText,
4361
+ });
4362
+ const mergeOptions = (options, patch) => (Object.assign(Object.assign({}, options), patch));
4363
+ const ɵ0$1 = mergeOptions;
4364
+ const fixupFontSize = (fontSize) => {
4365
+ let normalizedFontSize;
4366
+ if (pointRegex.test(fontSize)) {
4367
+ const matchedParts = fontSize.match(pointRegex);
4368
+ normalizedFontSize = pointToHIP(matchedParts[1]);
4369
+ }
4370
+ else if (fontSize) {
4371
+ // assuming it is already in HIP
4372
+ normalizedFontSize = fontSize;
4373
+ }
4374
+ else {
4375
+ normalizedFontSize = null;
4376
+ }
4377
+ return normalizedFontSize;
4378
+ };
4379
+ const ɵ1 = fixupFontSize;
4380
+ const normalizeUnits = (dimensioningObject, defaultDimensionsProperty) => {
4381
+ let normalizedUnitResult = {};
4382
+ if (typeof dimensioningObject === 'object' && dimensioningObject !== null) {
4383
+ Object.keys(dimensioningObject).forEach((key) => {
4384
+ if (pixelRegex.test(dimensioningObject[key])) {
4385
+ const matchedParts = dimensioningObject[key].match(pixelRegex);
4386
+ normalizedUnitResult[key] = pixelToTWIP(matchedParts[1]);
4387
+ }
4388
+ else if (cmRegex.test(dimensioningObject[key])) {
4389
+ const matchedParts = dimensioningObject[key].match(cmRegex);
4390
+ normalizedUnitResult[key] = cmToTWIP(matchedParts[1]);
4391
+ }
4392
+ else if (inchRegex.test(dimensioningObject[key])) {
4393
+ const matchedParts = dimensioningObject[key].match(inchRegex);
4394
+ normalizedUnitResult[key] = inchToTWIP(matchedParts[1]);
4395
+ }
4396
+ else if (dimensioningObject[key]) {
4397
+ normalizedUnitResult[key] = dimensioningObject[key];
4398
+ }
4399
+ else {
4400
+ // incase value is something like 0
4401
+ normalizedUnitResult[key] = defaultDimensionsProperty[key];
4402
+ }
4403
+ });
4404
+ }
4405
+ else {
4406
+ // eslint-disable-next-line no-param-reassign
4407
+ normalizedUnitResult = null;
4408
+ }
4409
+ return normalizedUnitResult;
4410
+ };
4411
+ const ɵ2 = normalizeUnits;
4412
+ const normalizeDocumentOptions = (documentOptions) => {
4413
+ const normalizedDocumentOptions = Object.assign({}, documentOptions);
4414
+ Object.keys(documentOptions).forEach((key) => {
4415
+ // eslint-disable-next-line default-case
4416
+ switch (key) {
4417
+ case 'pageSize':
4418
+ case 'margins':
4419
+ normalizedDocumentOptions[key] = normalizeUnits(documentOptions[key], defaultDocumentOptions[key]);
4420
+ break;
4421
+ case 'fontSize':
4422
+ case 'complexScriptFontSize':
4423
+ normalizedDocumentOptions[key] = fixupFontSize(documentOptions[key]);
4424
+ break;
4425
+ }
4426
+ });
4427
+ return normalizedDocumentOptions;
4428
+ };
4429
+ const ɵ3 = normalizeDocumentOptions;
4430
+ // Ref: https://en.wikipedia.org/wiki/Office_Open_XML_file_formats
4431
+ // http://officeopenxml.com/anatomyofOOXML.php
4432
+ function addFilesToContainer(zip, htmlString, suppliedDocumentOptions, headerHTMLString, footerHTMLString) {
4433
+ return __awaiter(this, void 0, void 0, function* () {
4434
+ debugger;
4435
+ const normalizedDocumentOptions = normalizeDocumentOptions(suppliedDocumentOptions);
4436
+ const documentOptions = mergeOptions(defaultDocumentOptions, normalizedDocumentOptions);
4437
+ if (documentOptions.header && !headerHTMLString) {
4438
+ // eslint-disable-next-line no-param-reassign
4439
+ headerHTMLString = defaultHTMLString;
4440
+ }
4441
+ if (documentOptions.footer && !footerHTMLString) {
4442
+ // eslint-disable-next-line no-param-reassign
4443
+ footerHTMLString = defaultHTMLString;
4444
+ }
4445
+ const docxDocument = new DocxDocument(Object.assign({ zip, htmlString }, documentOptions));
4446
+ // Conversion to Word XML happens here
4447
+ docxDocument.documentXML = yield renderDocumentFile(docxDocument);
4448
+ debugger;
4449
+ zip
4450
+ .folder(relsFolderName)
4451
+ .file('.rels', create({ encoding: 'UTF-8', standalone: true }, relsXML).toString({ prettyPrint: true }), { createFolders: false });
4452
+ zip.folder('docProps').file('core.xml', docxDocument.generateCoreXML(), {
4453
+ createFolders: false,
4454
+ });
4455
+ if (docxDocument.header && headerHTMLString) {
4456
+ const vTree = convertHTML(headerHTMLString);
4457
+ docxDocument.relationshipFilename = headerFileName;
4458
+ const { headerId, headerXML } = yield docxDocument.generateHeaderXML(vTree);
4459
+ docxDocument.relationshipFilename = documentFileName;
4460
+ const fileNameWithExt = `${headerType}${headerId}.xml`;
4461
+ const relationshipId = docxDocument.createDocumentRelationships(docxDocument.relationshipFilename, headerType, fileNameWithExt, internalRelationship);
4462
+ zip.folder(wordFolder).file(fileNameWithExt, generateDocumentTemplateHeader.toString({ prettyPrint: true }), {
4463
+ createFolders: false,
4464
+ });
4465
+ docxDocument.headerObjects.push({ headerId, relationshipId, type: docxDocument.headerType });
4466
+ }
4467
+ if (docxDocument.footer && footerHTMLString) {
4468
+ const vTree = convertHTML(footerHTMLString);
4469
+ docxDocument.relationshipFilename = footerFileName;
4470
+ const { footerId, footerXML } = yield docxDocument.generateFooterXML(vTree);
4471
+ docxDocument.relationshipFilename = documentFileName;
4472
+ const fileNameWithExt = `${footerType}${footerId}.xml`;
4473
+ const relationshipId = docxDocument.createDocumentRelationships(docxDocument.relationshipFilename, footerType, fileNameWithExt, internalRelationship);
4474
+ console.log(footerXML.toString({ prettyPrint: true }));
4475
+ if (suppliedDocumentOptions.pageNumber)
4476
+ zip.folder(wordFolder).file(fileNameWithExt, generateDocumentTemplateFooter.toString({ prettyPrint: true }), {
4477
+ createFolders: false,
4478
+ });
4479
+ else
4480
+ zip.folder(wordFolder).file(fileNameWithExt, generateDocumentTemplateFooterWithoutPaging.toString({ prettyPrint: true }), {
4481
+ createFolders: false,
4482
+ });
4483
+ docxDocument.footerObjects.push({ footerId, relationshipId, type: docxDocument.footerType });
4484
+ }
4485
+ const themeFileNameWithExt = `${themeFileName}.xml`;
4486
+ docxDocument.createDocumentRelationships(docxDocument.relationshipFilename, themeType, `${themeFolder}/${themeFileNameWithExt}`, internalRelationship);
4487
+ zip
4488
+ .folder(wordFolder)
4489
+ .folder(themeFolder)
4490
+ .file(themeFileNameWithExt, docxDocument.generateThemeXML(), {
4491
+ createFolders: false,
4492
+ });
4493
+ zip
4494
+ .folder(wordFolder)
4495
+ .file('document.xml', docxDocument.generateDocumentXML(), { createFolders: false })
4496
+ .file('afchunk.mht', getMHTdocument(htmlString), {
4497
+ createFolders: false,
4498
+ })
4499
+ .file('afchunkheader.mht', getMHTdocument(headerHTMLString), {
4500
+ createFolders: false,
4501
+ })
4502
+ .file('afchunkfooter.mht', getMHTdocument(footerHTMLString), {
4503
+ createFolders: false,
4504
+ })
4505
+ .file('fontTable.xml', docxDocument.generateFontTableXML(), { createFolders: false })
4506
+ .file('styles.xml', docxDocument.generateStylesXML(), { createFolders: false })
4507
+ .file('numbering.xml', docxDocument.generateNumberingXML(), { createFolders: false })
4508
+ .file('settings.xml', docxDocument.generateSettingsXML(), { createFolders: false })
4509
+ .file('webSettings.xml', docxDocument.generateWebSettingsXML(), { createFolders: false });
4510
+ const relationshipXMLs = docxDocument.generateRelsXML();
4511
+ if (relationshipXMLs && Array.isArray(relationshipXMLs)) {
4512
+ relationshipXMLs.forEach(({ fileName, xmlString }) => {
4513
+ console.log(xmlString);
4514
+ zip.folder(wordFolder).folder(relsFolderName).file(`${fileName}.xml.rels`, xmlString, {
4515
+ createFolders: false,
4516
+ });
4517
+ });
4518
+ }
4519
+ if (relationshipXMLs && Array.isArray(relationshipXMLs)) {
4520
+ relationshipXMLs.forEach(({ fileName, xmlString }) => {
4521
+ zip.folder(wordFolder).folder(relsFolderName).file(`header1.xml.rels`, xmlString, {
4522
+ createFolders: false,
4523
+ });
4524
+ });
4525
+ }
4526
+ if (relationshipXMLs && Array.isArray(relationshipXMLs)) {
4527
+ relationshipXMLs.forEach(({ fileName, xmlString }) => {
4528
+ zip.folder(wordFolder).folder(relsFolderName).file(`footer1.xml.rels`, xmlString, {
4529
+ createFolders: false,
4530
+ });
4531
+ });
4532
+ }
4533
+ zip.file('[Content_Types].xml', docxDocument.generateContentTypesXML(), { createFolders: false });
4534
+ return zip;
4535
+ });
4536
+ }
4537
+
4538
+ const minifyHTMLString = (htmlString) => {
4539
+ try {
4540
+ if (typeof htmlString === 'string' || htmlString instanceof String) {
4541
+ const minifiedHTMLString = htmlString
4542
+ .replace(/\n/g, ' ')
4543
+ .replace(/\r/g, ' ')
4544
+ .replace(/\r\n/g, ' ')
4545
+ .replace(/[\t]+\</g, '<')
4546
+ .replace(/\>[\t ]+\</g, '><')
4547
+ .replace(/\>[\t ]+$/g, '>');
4548
+ return minifiedHTMLString;
4549
+ }
4550
+ throw new Error('invalid html string');
4551
+ }
4552
+ catch (error) {
4553
+ return null;
4554
+ }
4555
+ };
4556
+ const ɵ0 = minifyHTMLString;
4557
+ function generateContainer(htmlString, headerHTMLString, documentOptions = {}, footerHTMLString) {
4558
+ return __awaiter(this, void 0, void 0, function* () {
4559
+ const zip = new JSZip();
4560
+ let contentHTML = htmlString;
4561
+ let headerHTML = headerHTMLString;
4562
+ let footerHTML = footerHTMLString;
4563
+ if (htmlString) {
4564
+ contentHTML = minifyHTMLString(contentHTML);
4565
+ }
4566
+ if (headerHTMLString) {
4567
+ headerHTML = minifyHTMLString(headerHTML);
4568
+ }
4569
+ if (footerHTMLString) {
4570
+ footerHTML = minifyHTMLString(footerHTML);
4571
+ }
4572
+ yield addFilesToContainer(zip, contentHTML, documentOptions, headerHTML, footerHTML);
4573
+ const buffer = yield zip.generateAsync({ type: 'arraybuffer' });
4574
+ if (Object.prototype.hasOwnProperty.call(global, 'Buffer')) {
4575
+ return Buffer.from(new Uint8Array(buffer));
4576
+ }
4577
+ if (Object.prototype.hasOwnProperty.call(global, 'Blob')) {
4578
+ // eslint-disable-next-line no-undef
4579
+ return new Blob([buffer], {
4580
+ type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
4581
+ });
4582
+ }
4583
+ throw new Error('Add blob support using a polyfill eg https://github.com/bjornstar/blob-polyfill');
4584
+ });
4585
+ }
4586
+
4587
+ class WordDocumentService {
4588
+ generateWordByteFile(model) {
4589
+ return __awaiter(this, void 0, void 0, function* () {
4590
+ let documentOptions = {};
4591
+ if (model.options.isLandscape)
4592
+ documentOptions.orientation = 'landscape';
4593
+ documentOptions.pageSize = {
4594
+ width: model.options.pageWidth * 15,
4595
+ height: model.options.pageHeight * 15,
4596
+ };
4597
+ documentOptions.margins = {
4598
+ top: model.options.top * 15,
4599
+ right: model.options.right * 15,
4600
+ bottom: model.options.bottom * 15,
4601
+ left: model.options.left * 15,
4602
+ header: model.options.top * 15 * 2,
4603
+ footer: model.options.bottom * 15 * 2,
4604
+ gutter: 0,
4605
+ };
4606
+ documentOptions.footer = true;
4607
+ documentOptions.header = true;
4608
+ documentOptions.pageNumber = model.options.showPaging;
4609
+ documentOptions.table = { row: { cantSplit: true } };
4610
+ var fileBuffer = yield generateContainer(model.body, model.header, documentOptions, model.footer);
4611
+ return fileBuffer;
4612
+ });
4613
+ }
4614
+ }
4615
+ WordDocumentService.ɵprov = i0.ɵɵdefineInjectable({ factory: function WordDocumentService_Factory() { return new WordDocumentService(); }, token: WordDocumentService, providedIn: "root" });
4616
+ WordDocumentService.decorators = [
4617
+ { type: Injectable, args: [{
4618
+ providedIn: 'root',
4619
+ },] }
4620
+ ];
4621
+
4622
+ class WordDocumentModel {
4623
+ constructor() {
4624
+ this.options = new DocumentOptionsModel();
4625
+ }
4626
+ }
4627
+ class DocumentOptionsModel {
4628
+ }
4629
+
4630
+ /*
4631
+ * Public API Surface of @bnsights/bbsf-utilities
4632
+ */
4633
+
4634
+ /**
4635
+ * Generated bundle index. Do not edit.
4636
+ */
4637
+
4638
+ export { AppInjector, AppearanceConfigurationService, AuthService, BBSFTranslateService, BBSFUtilitiesModule, ConfigurationService, ControlValidationService, DocumentOptionsModel, EnvironmentService, MasterLayoutService, RequestHandlerService, RequestOptionsModel, StylesBundleService, TranslationResolverService, UtilityService, WordDocumentModel, WordDocumentService, environment };
4639
+ //# sourceMappingURL=bnsights-bbsf-utilities.js.map