cmat 0.0.110 → 0.0.112

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 (256) hide show
  1. package/fesm2022/cmat-components-adapter.mjs +531 -536
  2. package/fesm2022/cmat-components-adapter.mjs.map +1 -1
  3. package/fesm2022/cmat-components-breadcrumb.mjs +521 -356
  4. package/fesm2022/cmat-components-breadcrumb.mjs.map +1 -1
  5. package/fesm2022/cmat-components-card.mjs +150 -42
  6. package/fesm2022/cmat-components-card.mjs.map +1 -1
  7. package/fesm2022/cmat-components-carousel.mjs +1120 -629
  8. package/fesm2022/cmat-components-carousel.mjs.map +1 -1
  9. package/fesm2022/cmat-components-cascade.mjs +861 -441
  10. package/fesm2022/cmat-components-cascade.mjs.map +1 -1
  11. package/fesm2022/cmat-components-chip-input.mjs +580 -335
  12. package/fesm2022/cmat-components-chip-input.mjs.map +1 -1
  13. package/fesm2022/cmat-components-code-editor.mjs +197 -105
  14. package/fesm2022/cmat-components-code-editor.mjs.map +1 -1
  15. package/fesm2022/cmat-components-color-picker.mjs +1762 -825
  16. package/fesm2022/cmat-components-color-picker.mjs.map +1 -1
  17. package/fesm2022/cmat-components-custom-formly.mjs +5196 -2531
  18. package/fesm2022/cmat-components-custom-formly.mjs.map +1 -1
  19. package/fesm2022/cmat-components-data-picker.mjs +1901 -1073
  20. package/fesm2022/cmat-components-data-picker.mjs.map +1 -1
  21. package/fesm2022/cmat-components-date-range.mjs +701 -456
  22. package/fesm2022/cmat-components-date-range.mjs.map +1 -1
  23. package/fesm2022/cmat-components-date-time-display.mjs +137 -30
  24. package/fesm2022/cmat-components-date-time-display.mjs.map +1 -1
  25. package/fesm2022/cmat-components-drawer.mjs +410 -258
  26. package/fesm2022/cmat-components-drawer.mjs.map +1 -1
  27. package/fesm2022/cmat-components-empty-state.mjs +201 -41
  28. package/fesm2022/cmat-components-empty-state.mjs.map +1 -1
  29. package/fesm2022/cmat-components-file-preview.mjs +198 -35
  30. package/fesm2022/cmat-components-file-preview.mjs.map +1 -1
  31. package/fesm2022/cmat-components-filter-toolbar.mjs +320 -72
  32. package/fesm2022/cmat-components-filter-toolbar.mjs.map +1 -1
  33. package/fesm2022/cmat-components-form-actions.mjs +102 -26
  34. package/fesm2022/cmat-components-form-actions.mjs.map +1 -1
  35. package/fesm2022/cmat-components-fullscreen.mjs +167 -47
  36. package/fesm2022/cmat-components-fullscreen.mjs.map +1 -1
  37. package/fesm2022/cmat-components-highlight.mjs +203 -112
  38. package/fesm2022/cmat-components-highlight.mjs.map +1 -1
  39. package/fesm2022/cmat-components-image-viewer.mjs +489 -215
  40. package/fesm2022/cmat-components-image-viewer.mjs.map +1 -1
  41. package/fesm2022/cmat-components-inline-loading.mjs +117 -27
  42. package/fesm2022/cmat-components-inline-loading.mjs.map +1 -1
  43. package/fesm2022/cmat-components-json-editor.mjs +276 -230
  44. package/fesm2022/cmat-components-json-editor.mjs.map +1 -1
  45. package/fesm2022/cmat-components-knob-input.mjs +615 -420
  46. package/fesm2022/cmat-components-knob-input.mjs.map +1 -1
  47. package/fesm2022/cmat-components-loading-overlay.mjs +53 -25
  48. package/fesm2022/cmat-components-loading-overlay.mjs.map +1 -1
  49. package/fesm2022/cmat-components-masonry.mjs +120 -40
  50. package/fesm2022/cmat-components-masonry.mjs.map +1 -1
  51. package/fesm2022/cmat-components-material-color-picker.mjs +332 -155
  52. package/fesm2022/cmat-components-material-color-picker.mjs.map +1 -1
  53. package/fesm2022/cmat-components-material-datetimepicker.mjs +4283 -2504
  54. package/fesm2022/cmat-components-material-datetimepicker.mjs.map +1 -1
  55. package/fesm2022/cmat-components-navigation.mjs +3080 -1404
  56. package/fesm2022/cmat-components-navigation.mjs.map +1 -1
  57. package/fesm2022/cmat-components-opt-input.mjs +540 -466
  58. package/fesm2022/cmat-components-opt-input.mjs.map +1 -1
  59. package/fesm2022/cmat-components-org-chart.mjs +528 -125
  60. package/fesm2022/cmat-components-org-chart.mjs.map +1 -1
  61. package/fesm2022/cmat-components-page-header.mjs +141 -32
  62. package/fesm2022/cmat-components-page-header.mjs.map +1 -1
  63. package/fesm2022/cmat-components-pagination.mjs +866 -534
  64. package/fesm2022/cmat-components-pagination.mjs.map +1 -1
  65. package/fesm2022/cmat-components-password-strength.mjs +873 -434
  66. package/fesm2022/cmat-components-password-strength.mjs.map +1 -1
  67. package/fesm2022/cmat-components-popover.mjs +1012 -731
  68. package/fesm2022/cmat-components-popover.mjs.map +1 -1
  69. package/fesm2022/cmat-components-progress-bar.mjs +98 -35
  70. package/fesm2022/cmat-components-progress-bar.mjs.map +1 -1
  71. package/fesm2022/cmat-components-qrcode.mjs +463 -287
  72. package/fesm2022/cmat-components-qrcode.mjs.map +1 -1
  73. package/fesm2022/cmat-components-rating.mjs +377 -203
  74. package/fesm2022/cmat-components-rating.mjs.map +1 -1
  75. package/fesm2022/cmat-components-rich-text-editor.mjs +153 -39
  76. package/fesm2022/cmat-components-rich-text-editor.mjs.map +1 -1
  77. package/fesm2022/cmat-components-select-search.mjs +926 -496
  78. package/fesm2022/cmat-components-select-search.mjs.map +1 -1
  79. package/fesm2022/cmat-components-select-table.mjs +1280 -842
  80. package/fesm2022/cmat-components-select-table.mjs.map +1 -1
  81. package/fesm2022/cmat-components-select-tree.mjs +998 -690
  82. package/fesm2022/cmat-components-select-tree.mjs.map +1 -1
  83. package/fesm2022/cmat-components-skeleton.mjs +143 -57
  84. package/fesm2022/cmat-components-skeleton.mjs.map +1 -1
  85. package/fesm2022/cmat-components-speed-dial.mjs +457 -303
  86. package/fesm2022/cmat-components-speed-dial.mjs.map +1 -1
  87. package/fesm2022/cmat-components-status-tag.mjs +136 -44
  88. package/fesm2022/cmat-components-status-tag.mjs.map +1 -1
  89. package/fesm2022/cmat-components-table-toolbar.mjs +120 -28
  90. package/fesm2022/cmat-components-table-toolbar.mjs.map +1 -1
  91. package/fesm2022/cmat-components-timeline.mjs +464 -168
  92. package/fesm2022/cmat-components-timeline.mjs.map +1 -1
  93. package/fesm2022/cmat-components-toast.mjs +346 -262
  94. package/fesm2022/cmat-components-toast.mjs.map +1 -1
  95. package/fesm2022/cmat-components-transfer-picker.mjs +1427 -593
  96. package/fesm2022/cmat-components-transfer-picker.mjs.map +1 -1
  97. package/fesm2022/cmat-components-treetable.mjs +372 -112
  98. package/fesm2022/cmat-components-treetable.mjs.map +1 -1
  99. package/fesm2022/cmat-components-upload.mjs +904 -410
  100. package/fesm2022/cmat-components-upload.mjs.map +1 -1
  101. package/fesm2022/cmat-components-x6-angular-shape.mjs +153 -170
  102. package/fesm2022/cmat-components-x6-angular-shape.mjs.map +1 -1
  103. package/fesm2022/cmat-directives-animate-on-scroll.mjs +220 -138
  104. package/fesm2022/cmat-directives-animate-on-scroll.mjs.map +1 -1
  105. package/fesm2022/cmat-directives-arrow-cursor.mjs +246 -193
  106. package/fesm2022/cmat-directives-arrow-cursor.mjs.map +1 -1
  107. package/fesm2022/cmat-directives-autofocus.mjs +43 -25
  108. package/fesm2022/cmat-directives-autofocus.mjs.map +1 -1
  109. package/fesm2022/cmat-directives-data-exporter.mjs +537 -338
  110. package/fesm2022/cmat-directives-data-exporter.mjs.map +1 -1
  111. package/fesm2022/cmat-directives-debounce.mjs +162 -76
  112. package/fesm2022/cmat-directives-debounce.mjs.map +1 -1
  113. package/fesm2022/cmat-directives-digit-only.mjs +457 -356
  114. package/fesm2022/cmat-directives-digit-only.mjs.map +1 -1
  115. package/fesm2022/cmat-directives-equal-validator.mjs +70 -53
  116. package/fesm2022/cmat-directives-equal-validator.mjs.map +1 -1
  117. package/fesm2022/cmat-directives-seamless-auto-scroll.mjs +180 -132
  118. package/fesm2022/cmat-directives-seamless-auto-scroll.mjs.map +1 -1
  119. package/fesm2022/cmat-lib-mock-api.mjs +207 -195
  120. package/fesm2022/cmat-lib-mock-api.mjs.map +1 -1
  121. package/fesm2022/cmat-pipes-bytes.mjs +50 -30
  122. package/fesm2022/cmat-pipes-bytes.mjs.map +1 -1
  123. package/fesm2022/cmat-pipes-date-format.mjs +41 -25
  124. package/fesm2022/cmat-pipes-date-format.mjs.map +1 -1
  125. package/fesm2022/cmat-pipes-find-by-key.mjs +44 -26
  126. package/fesm2022/cmat-pipes-find-by-key.mjs.map +1 -1
  127. package/fesm2022/cmat-pipes-group-by.mjs +50 -38
  128. package/fesm2022/cmat-pipes-group-by.mjs.map +1 -1
  129. package/fesm2022/cmat-pipes-keys.mjs +44 -31
  130. package/fesm2022/cmat-pipes-keys.mjs.map +1 -1
  131. package/fesm2022/cmat-pipes-secure.mjs +60 -49
  132. package/fesm2022/cmat-pipes-secure.mjs.map +1 -1
  133. package/fesm2022/cmat-pipes-uppercase.mjs +39 -22
  134. package/fesm2022/cmat-pipes-uppercase.mjs.map +1 -1
  135. package/fesm2022/cmat-reports.mjs +2751 -0
  136. package/fesm2022/cmat-reports.mjs.map +1 -0
  137. package/fesm2022/cmat-services-alert.mjs +249 -277
  138. package/fesm2022/cmat-services-alert.mjs.map +1 -1
  139. package/fesm2022/cmat-services-config.mjs +110 -81
  140. package/fesm2022/cmat-services-config.mjs.map +1 -1
  141. package/fesm2022/cmat-services-confirmation.mjs +184 -73
  142. package/fesm2022/cmat-services-confirmation.mjs.map +1 -1
  143. package/fesm2022/cmat-services-data.mjs +136 -125
  144. package/fesm2022/cmat-services-data.mjs.map +1 -1
  145. package/fesm2022/cmat-services-export-as.mjs +165 -183
  146. package/fesm2022/cmat-services-export-as.mjs.map +1 -1
  147. package/fesm2022/cmat-services-loading.mjs +116 -95
  148. package/fesm2022/cmat-services-loading.mjs.map +1 -1
  149. package/fesm2022/cmat-services-local-storage.mjs +75 -66
  150. package/fesm2022/cmat-services-local-storage.mjs.map +1 -1
  151. package/fesm2022/cmat-services-media-watcher.mjs +69 -64
  152. package/fesm2022/cmat-services-media-watcher.mjs.map +1 -1
  153. package/fesm2022/cmat-services-platform.mjs +48 -45
  154. package/fesm2022/cmat-services-platform.mjs.map +1 -1
  155. package/fesm2022/cmat-services-print.mjs +985 -669
  156. package/fesm2022/cmat-services-print.mjs.map +1 -1
  157. package/fesm2022/cmat-services-splash-screen.mjs +53 -38
  158. package/fesm2022/cmat-services-splash-screen.mjs.map +1 -1
  159. package/fesm2022/cmat-services-title.mjs +57 -47
  160. package/fesm2022/cmat-services-title.mjs.map +1 -1
  161. package/fesm2022/cmat-services-translation.mjs +79 -68
  162. package/fesm2022/cmat-services-translation.mjs.map +1 -1
  163. package/fesm2022/cmat-services-utils.mjs +424 -517
  164. package/fesm2022/cmat-services-utils.mjs.map +1 -1
  165. package/fesm2022/cmat-validators.mjs +23 -33
  166. package/fesm2022/cmat-validators.mjs.map +1 -1
  167. package/fesm2022/cmat-version.mjs +12 -16
  168. package/fesm2022/cmat-version.mjs.map +1 -1
  169. package/fesm2022/cmat.mjs +39806 -22071
  170. package/fesm2022/cmat.mjs.map +1 -1
  171. package/package.json +5 -1
  172. package/types/cmat-components-adapter.d.ts +145 -156
  173. package/types/cmat-components-breadcrumb.d.ts +108 -86
  174. package/types/cmat-components-card.d.ts +34 -18
  175. package/types/cmat-components-carousel.d.ts +251 -134
  176. package/types/cmat-components-cascade.d.ts +158 -117
  177. package/types/cmat-components-chip-input.d.ts +105 -71
  178. package/types/cmat-components-code-editor.d.ts +59 -34
  179. package/types/cmat-components-color-picker.d.ts +378 -236
  180. package/types/cmat-components-custom-formly.d.ts +776 -814
  181. package/types/cmat-components-data-picker.d.ts +502 -360
  182. package/types/cmat-components-date-range.d.ts +106 -77
  183. package/types/cmat-components-date-time-display.d.ts +36 -13
  184. package/types/cmat-components-drawer.d.ts +91 -61
  185. package/types/cmat-components-empty-state.d.ts +47 -17
  186. package/types/cmat-components-file-preview.d.ts +42 -14
  187. package/types/cmat-components-filter-toolbar.d.ts +57 -25
  188. package/types/cmat-components-form-actions.d.ts +18 -10
  189. package/types/cmat-components-fullscreen.d.ts +21 -13
  190. package/types/cmat-components-highlight.d.ts +33 -26
  191. package/types/cmat-components-image-viewer.d.ts +119 -58
  192. package/types/cmat-components-inline-loading.d.ts +24 -11
  193. package/types/cmat-components-json-editor.d.ts +39 -28
  194. package/types/cmat-components-knob-input.d.ts +172 -101
  195. package/types/cmat-components-loading-overlay.d.ts +8 -11
  196. package/types/cmat-components-masonry.d.ts +27 -14
  197. package/types/cmat-components-material-color-picker.d.ts +56 -42
  198. package/types/cmat-components-material-datetimepicker.d.ts +817 -454
  199. package/types/cmat-components-navigation.d.ts +295 -221
  200. package/types/cmat-components-opt-input.d.ts +111 -90
  201. package/types/cmat-components-org-chart.d.ts +53 -35
  202. package/types/cmat-components-page-header.d.ts +37 -14
  203. package/types/cmat-components-pagination.d.ts +144 -107
  204. package/types/cmat-components-password-strength.d.ts +197 -86
  205. package/types/cmat-components-popover.d.ts +264 -166
  206. package/types/cmat-components-progress-bar.d.ts +17 -14
  207. package/types/cmat-components-qrcode.d.ts +111 -42
  208. package/types/cmat-components-rating.d.ts +105 -59
  209. package/types/cmat-components-rich-text-editor.d.ts +39 -16
  210. package/types/cmat-components-select-search.d.ts +195 -99
  211. package/types/cmat-components-select-table.d.ts +241 -142
  212. package/types/cmat-components-select-tree.d.ts +185 -118
  213. package/types/cmat-components-skeleton.d.ts +55 -32
  214. package/types/cmat-components-speed-dial.d.ts +86 -61
  215. package/types/cmat-components-status-tag.d.ts +42 -24
  216. package/types/cmat-components-table-toolbar.d.ts +30 -12
  217. package/types/cmat-components-timeline.d.ts +83 -51
  218. package/types/cmat-components-toast.d.ts +84 -85
  219. package/types/cmat-components-transfer-picker.d.ts +228 -181
  220. package/types/cmat-components-treetable.d.ts +63 -39
  221. package/types/cmat-components-upload.d.ts +205 -106
  222. package/types/cmat-components-x6-angular-shape.d.ts +29 -37
  223. package/types/cmat-directives-animate-on-scroll.d.ts +48 -30
  224. package/types/cmat-directives-arrow-cursor.d.ts +55 -35
  225. package/types/cmat-directives-autofocus.d.ts +8 -11
  226. package/types/cmat-directives-data-exporter.d.ts +71 -40
  227. package/types/cmat-directives-debounce.d.ts +31 -28
  228. package/types/cmat-directives-digit-only.d.ts +90 -53
  229. package/types/cmat-directives-equal-validator.d.ts +11 -14
  230. package/types/cmat-directives-seamless-auto-scroll.d.ts +42 -29
  231. package/types/cmat-lib-mock-api.d.ts +46 -55
  232. package/types/cmat-pipes-bytes.d.ts +7 -10
  233. package/types/cmat-pipes-date-format.d.ts +7 -10
  234. package/types/cmat-pipes-find-by-key.d.ts +8 -12
  235. package/types/cmat-pipes-group-by.d.ts +11 -15
  236. package/types/cmat-pipes-keys.d.ts +10 -13
  237. package/types/cmat-pipes-secure.d.ts +14 -17
  238. package/types/cmat-pipes-uppercase.d.ts +7 -10
  239. package/types/cmat-reports.d.ts +1131 -0
  240. package/types/cmat-services-alert.d.ts +80 -87
  241. package/types/cmat-services-config.d.ts +37 -43
  242. package/types/cmat-services-confirmation.d.ts +31 -37
  243. package/types/cmat-services-data.d.ts +18 -21
  244. package/types/cmat-services-export-as.d.ts +28 -33
  245. package/types/cmat-services-loading.d.ts +27 -31
  246. package/types/cmat-services-local-storage.d.ts +17 -21
  247. package/types/cmat-services-media-watcher.d.ts +14 -18
  248. package/types/cmat-services-platform.d.ts +8 -11
  249. package/types/cmat-services-print.d.ts +97 -92
  250. package/types/cmat-services-splash-screen.d.ts +11 -14
  251. package/types/cmat-services-title.d.ts +9 -12
  252. package/types/cmat-services-translation.d.ts +19 -22
  253. package/types/cmat-services-utils.d.ts +76 -80
  254. package/types/cmat-validators.d.ts +5 -8
  255. package/types/cmat-version.d.ts +8 -10
  256. package/types/cmat.d.ts +7551 -5194
@@ -1,184 +1,166 @@
1
- import * as i0 from '@angular/core';
2
- import { Injectable } from '@angular/core';
3
- import * as FileSaver from 'file-saver-es';
4
- import { Observable } from 'rxjs';
5
- import * as XLSX from 'xlsx';
6
-
7
- class CmatExportAsService {
8
- get(config) {
9
- switch (config.type.toUpperCase()) {
10
- case 'CSV':
11
- return this._getCSV(config);
12
- case 'TXT':
13
- return this._getTXT(config);
14
- case 'XLS':
15
- return this._getXLS(config);
16
- case 'XLSX':
17
- return this._getXLSX(config);
18
- case 'JSON':
19
- return this._getJSON(config);
20
- case 'XML':
21
- return this._getXML(config);
22
- default:
23
- return new Observable((observer) => { observer.error('导出格式不支持。'); });
24
- }
25
- }
26
- save(config, fileName) {
27
- config.download = true;
28
- config.fileName = fileName + '.' + config.type;
29
- return this.get(config);
30
- }
31
- contentToBlob(content) {
32
- return new Observable((observer) => {
33
- const arr = content.split(','), mime = (/:(.*?);/.exec(arr[0]))?.[1], bstr = atob(arr[1]);
34
- let n = bstr.length;
35
- const u8arr = new Uint8Array(n);
36
- while (n--) {
37
- u8arr[n] = bstr.charCodeAt(n);
38
- }
39
- observer.next(new Blob([u8arr], { type: mime }));
40
- observer.complete();
41
- });
42
- }
43
- removeFileTypeFromBase64(fileContent) {
44
- const re = /^data:[^]*;base64,/g;
45
- const newContent = re[Symbol.replace](fileContent, '');
46
- return newContent;
47
- }
48
- addFileTypeToBase64(fileContent, fileMime) {
49
- return `data:${fileMime};base64,${fileContent}`;
50
- }
51
- downloadFromDataURL(fileName, dataURL) {
52
- this.contentToBlob(dataURL).subscribe((blob) => {
53
- this.downloadFromBlob(blob, fileName);
54
- });
55
- }
56
- downloadFromBlob(blob, fileName) {
57
- FileSaver.saveAs(blob, fileName);
58
- }
59
- _getCSV(config) {
60
- return new Observable((observer) => {
61
- const element = document.getElementById(config.elementIdOrContent);
62
- const csv = [];
63
- const rows = element?.querySelectorAll('table tr');
64
- rows?.forEach((rowElement) => {
65
- const row = [];
66
- const cols = rowElement.querySelectorAll('td, th');
67
- Array.from(cols).forEach((col) => {
68
- row.push('"' + (col.textContent ?? col.innerText) + '"');
69
- });
70
- csv.push(row.join(','));
71
- });
72
- const csvContent = 'data:text/csv;base64,' + this._btoa(csv.join('\n'));
73
- if (config.download) {
74
- this.downloadFromDataURL(config.fileName, csvContent);
75
- observer.next(null);
76
- }
77
- else {
78
- observer.next(csvContent);
79
- }
80
- observer.complete();
81
- });
82
- }
83
- _getTXT(config) {
84
- const nameFrags = config.fileName?.split('.');
85
- config.fileName = `${nameFrags?.[0]}.txt`;
86
- return this._getCSV(config);
87
- }
88
- _getXLS(config) {
89
- return new Observable((observer) => {
90
- const element = document.getElementById(config.elementIdOrContent);
91
- const ws3 = XLSX.utils.table_to_sheet(element, config.options);
92
- const wb = XLSX.utils.book_new();
93
- XLSX.utils.book_append_sheet(wb, ws3, config.fileName);
94
- const out = XLSX.write(wb, { type: 'base64' });
95
- const xlsContent = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,' + out;
96
- if (config.download) {
97
- this.downloadFromDataURL(config.fileName, xlsContent);
98
- observer.next(null);
99
- }
100
- else {
101
- observer.next(xlsContent);
102
- }
103
- observer.complete();
104
- });
105
- }
106
- _getXLSX(config) {
107
- return this._getXLS(config);
108
- }
109
- _getJSON(config) {
110
- return new Observable((observer) => {
111
- const data = [];
112
- const headers = [];
113
- const table = document.getElementById(config.elementIdOrContent);
114
- for (let index = 0; index < table.rows[0].cells.length; index++) {
115
- headers[index] = (table.rows[0].cells[index].textContent ?? '').toLowerCase().replace(/ /gi, '');
116
- }
117
- for (let i = 1; i < table.rows.length; i++) {
118
- const tableRow = table.rows[i];
119
- const rowData = {};
120
- for (let j = 0; j < tableRow.cells.length; j++) {
121
- rowData[headers[j]] = tableRow.cells[j].textContent ?? '';
122
- }
123
- data.push(rowData);
124
- }
125
- const jsonString = JSON.stringify(data);
126
- const jsonBase64 = this._btoa(jsonString);
127
- const dataStr = 'data:text/json;base64,' + jsonBase64;
128
- if (config.download) {
129
- this.downloadFromDataURL(config.fileName, dataStr);
130
- observer.next(null);
131
- }
132
- else {
133
- observer.next(data);
134
- }
135
- observer.complete();
136
- });
137
- }
138
- _getXML(config) {
139
- return new Observable((observer) => {
140
- let xml = '<?xml version="1.0" encoding="UTF-8"?><Root><Classes>';
141
- const tritem = document.getElementById(config.elementIdOrContent)?.getElementsByTagName('tr');
142
- if (tritem) {
143
- Array.from(tritem).forEach((celldata) => {
144
- if (celldata.cells.length > 0) {
145
- xml += '<Class name="' + celldata.cells[0].textContent + '">\n';
146
- for (let m = 1; m < celldata.cells.length; ++m) {
147
- xml += '\t<data>' + celldata.cells[m].textContent + '</data>\n';
148
- }
149
- xml += '</Class>\n';
150
- }
151
- });
152
- }
153
- xml += '</Classes></Root>';
154
- const base64 = 'data:text/xml;base64,' + this._btoa(xml);
155
- if (config.download) {
156
- this.downloadFromDataURL(config.fileName, base64);
157
- observer.next(null);
158
- }
159
- else {
160
- observer.next(base64);
161
- }
162
- observer.complete();
163
- });
164
- }
165
- _btoa(content) {
166
- // eslint-disable-next-line @typescript-eslint/no-deprecated
167
- return btoa(unescape(encodeURIComponent(content)));
168
- }
169
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatExportAsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
170
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatExportAsService, providedIn: 'root' }); }
171
- }
172
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatExportAsService, decorators: [{
173
- type: Injectable,
174
- args: [{
175
- providedIn: 'root'
176
- }]
177
- }] });
178
-
179
- /**
180
- * Generated bundle index. Do not edit.
181
- */
182
-
1
+ import * as i0 from "@angular/core";
2
+ import { Injectable } from "@angular/core";
3
+ import * as FileSaver from "file-saver-es";
4
+ import { Observable } from "rxjs";
5
+ import * as XLSX from "xlsx";
6
+ var CmatExportAsService = class CmatExportAsService {
7
+ get(config) {
8
+ switch (config.type.toUpperCase()) {
9
+ case "CSV": return this._getCSV(config);
10
+ case "TXT": return this._getTXT(config);
11
+ case "XLS": return this._getXLS(config);
12
+ case "XLSX": return this._getXLSX(config);
13
+ case "JSON": return this._getJSON(config);
14
+ case "XML": return this._getXML(config);
15
+ default: return new Observable((observer) => {
16
+ observer.error("导出格式不支持。");
17
+ });
18
+ }
19
+ }
20
+ save(config, fileName) {
21
+ config.download = true;
22
+ config.fileName = fileName + "." + config.type;
23
+ return this.get(config);
24
+ }
25
+ contentToBlob(content) {
26
+ return new Observable((observer) => {
27
+ const arr = content.split(","), mime = /:(.*?);/.exec(arr[0])?.[1], bstr = atob(arr[1]);
28
+ let n = bstr.length;
29
+ const u8arr = new Uint8Array(n);
30
+ while (n--) u8arr[n] = bstr.charCodeAt(n);
31
+ observer.next(new Blob([u8arr], { type: mime }));
32
+ observer.complete();
33
+ });
34
+ }
35
+ removeFileTypeFromBase64(fileContent) {
36
+ return /^data:[^]*;base64,/g[Symbol.replace](fileContent, "");
37
+ }
38
+ addFileTypeToBase64(fileContent, fileMime) {
39
+ return `data:${fileMime};base64,${fileContent}`;
40
+ }
41
+ downloadFromDataURL(fileName, dataURL) {
42
+ this.contentToBlob(dataURL).subscribe((blob) => {
43
+ this.downloadFromBlob(blob, fileName);
44
+ });
45
+ }
46
+ downloadFromBlob(blob, fileName) {
47
+ FileSaver.saveAs(blob, fileName);
48
+ }
49
+ _getCSV(config) {
50
+ return new Observable((observer) => {
51
+ const element = document.getElementById(config.elementIdOrContent);
52
+ const csv = [];
53
+ (element?.querySelectorAll("table tr"))?.forEach((rowElement) => {
54
+ const row = [];
55
+ const cols = rowElement.querySelectorAll("td, th");
56
+ Array.from(cols).forEach((col) => {
57
+ row.push("\"" + (col.textContent ?? col.innerText) + "\"");
58
+ });
59
+ csv.push(row.join(","));
60
+ });
61
+ const csvContent = "data:text/csv;base64," + this._btoa(csv.join("\n"));
62
+ if (config.download) {
63
+ this.downloadFromDataURL(config.fileName, csvContent);
64
+ observer.next(null);
65
+ } else observer.next(csvContent);
66
+ observer.complete();
67
+ });
68
+ }
69
+ _getTXT(config) {
70
+ config.fileName = `${(config.fileName?.split("."))?.[0]}.txt`;
71
+ return this._getCSV(config);
72
+ }
73
+ _getXLS(config) {
74
+ return new Observable((observer) => {
75
+ const element = document.getElementById(config.elementIdOrContent);
76
+ const ws3 = XLSX.utils.table_to_sheet(element, config.options);
77
+ const wb = XLSX.utils.book_new();
78
+ XLSX.utils.book_append_sheet(wb, ws3, config.fileName);
79
+ const xlsContent = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," + XLSX.write(wb, { type: "base64" });
80
+ if (config.download) {
81
+ this.downloadFromDataURL(config.fileName, xlsContent);
82
+ observer.next(null);
83
+ } else observer.next(xlsContent);
84
+ observer.complete();
85
+ });
86
+ }
87
+ _getXLSX(config) {
88
+ return this._getXLS(config);
89
+ }
90
+ _getJSON(config) {
91
+ return new Observable((observer) => {
92
+ const data = [];
93
+ const headers = [];
94
+ const table = document.getElementById(config.elementIdOrContent);
95
+ for (let index = 0; index < table.rows[0].cells.length; index++) headers[index] = (table.rows[0].cells[index].textContent ?? "").toLowerCase().replace(/ /gi, "");
96
+ for (let i = 1; i < table.rows.length; i++) {
97
+ const tableRow = table.rows[i];
98
+ const rowData = {};
99
+ for (let j = 0; j < tableRow.cells.length; j++) rowData[headers[j]] = tableRow.cells[j].textContent ?? "";
100
+ data.push(rowData);
101
+ }
102
+ const jsonString = JSON.stringify(data);
103
+ const dataStr = "data:text/json;base64," + this._btoa(jsonString);
104
+ if (config.download) {
105
+ this.downloadFromDataURL(config.fileName, dataStr);
106
+ observer.next(null);
107
+ } else observer.next(data);
108
+ observer.complete();
109
+ });
110
+ }
111
+ _getXML(config) {
112
+ return new Observable((observer) => {
113
+ let xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Root><Classes>";
114
+ const tritem = document.getElementById(config.elementIdOrContent)?.getElementsByTagName("tr");
115
+ if (tritem) Array.from(tritem).forEach((celldata) => {
116
+ if (celldata.cells.length > 0) {
117
+ xml += "<Class name=\"" + celldata.cells[0].textContent + "\">\n";
118
+ for (let m = 1; m < celldata.cells.length; ++m) xml += " <data>" + celldata.cells[m].textContent + "</data>\n";
119
+ xml += "</Class>\n";
120
+ }
121
+ });
122
+ xml += "</Classes></Root>";
123
+ const base64 = "data:text/xml;base64," + this._btoa(xml);
124
+ if (config.download) {
125
+ this.downloadFromDataURL(config.fileName, base64);
126
+ observer.next(null);
127
+ } else observer.next(base64);
128
+ observer.complete();
129
+ });
130
+ }
131
+ _btoa(content) {
132
+ return btoa(unescape(encodeURIComponent(content)));
133
+ }
134
+ static {
135
+ this.ɵfac = i0.ɵɵngDeclareFactory({
136
+ minVersion: "12.0.0",
137
+ version: "22.2.3",
138
+ ngImport: i0,
139
+ type: CmatExportAsService,
140
+ deps: [],
141
+ target: i0.ɵɵFactoryTarget.Injectable
142
+ });
143
+ }
144
+ static {
145
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
146
+ minVersion: "12.0.0",
147
+ version: "22.2.3",
148
+ ngImport: i0,
149
+ type: CmatExportAsService,
150
+ providedIn: "root"
151
+ });
152
+ }
153
+ };
154
+ i0.ɵɵngDeclareClassMetadata({
155
+ minVersion: "12.0.0",
156
+ version: "22.2.3",
157
+ ngImport: i0,
158
+ type: CmatExportAsService,
159
+ decorators: [{
160
+ type: Injectable,
161
+ args: [{ providedIn: "root" }]
162
+ }]
163
+ });
183
164
  export { CmatExportAsService };
184
- //# sourceMappingURL=cmat-services-export-as.mjs.map
165
+
166
+ //# sourceMappingURL=cmat-services-export-as.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cmat-services-export-as.mjs","sources":["../../../projects/cmat/services/export-as/export-as.service.ts","../../../projects/cmat/services/export-as/cmat-services-export-as.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\r\nimport * as FileSaver from 'file-saver-es';\r\nimport { Observable } from 'rxjs';\r\nimport * as XLSX from 'xlsx';\r\nimport { ExportAsConfig } from './export-as-config.model';\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class CmatExportAsService {\r\n \r\n get(config: ExportAsConfig): Observable<string | unknown[] | null> {\r\n switch (config.type.toUpperCase()) {\r\n case 'CSV':\r\n return this._getCSV(config);\r\n case 'TXT':\r\n return this._getTXT(config);\r\n case 'XLS':\r\n return this._getXLS(config);\r\n case 'XLSX':\r\n return this._getXLSX(config);\r\n case 'JSON':\r\n return this._getJSON(config);\r\n case 'XML':\r\n return this._getXML(config);\r\n default:\r\n return new Observable((observer): void => { observer.error('导出格式不支持。'); });\r\n }\r\n }\r\n\r\n \r\n save(config: ExportAsConfig, fileName: string): Observable<string | unknown[] | null> {\r\n config.download = true;\r\n config.fileName = fileName + '.' + config.type;\r\n return this.get(config);\r\n }\r\n\r\n \r\n contentToBlob(content: string): Observable<Blob> {\r\n return new Observable((observer): void => {\r\n const arr = content.split(','), mime = (/:(.*?);/.exec(arr[0]))?.[1],\r\n bstr = atob(arr[1]);\r\n let n = bstr.length;\r\n const u8arr = new Uint8Array(n);\r\n while (n--) {\r\n u8arr[n] = bstr.charCodeAt(n);\r\n }\r\n observer.next(new Blob([u8arr], { type: mime }));\r\n observer.complete();\r\n });\r\n }\r\n\r\n \r\n removeFileTypeFromBase64(fileContent: string): string {\r\n const re = /^data:[^]*;base64,/g;\r\n const newContent: string = re[Symbol.replace](fileContent, '');\r\n return newContent;\r\n }\r\n\r\n \r\n addFileTypeToBase64(fileContent: string, fileMime: string): string {\r\n return `data:${fileMime};base64,${fileContent}`;\r\n }\r\n\r\n downloadFromDataURL(fileName: string, dataURL: string): void {\r\n this.contentToBlob(dataURL).subscribe((blob): void => {\r\n this.downloadFromBlob(blob, fileName);\r\n });\r\n }\r\n\r\n downloadFromBlob(blob: Blob, fileName: string): void {\r\n FileSaver.saveAs(blob, fileName);\r\n }\r\n\r\n private _getCSV(config: ExportAsConfig): Observable<string | null> {\r\n return new Observable((observer): void => {\r\n const element: HTMLElement | null = document.getElementById(config.elementIdOrContent);\r\n const csv: string[] = [];\r\n const rows = element?.querySelectorAll('table tr');\r\n rows?.forEach((rowElement: Element): void => {\r\n const row: string[] = [];\r\n const cols = (rowElement as HTMLTableRowElement).querySelectorAll('td, th');\r\n\r\n Array.from(cols).forEach((col: Element): void => {\r\n row.push('\"' + ((col as HTMLTableCellElement).textContent ?? (col as HTMLTableCellElement).innerText) + '\"');\r\n });\r\n csv.push(row.join(','));\r\n });\r\n\r\n const csvContent = 'data:text/csv;base64,' + this._btoa(csv.join('\\n'));\r\n if (config.download) {\r\n this.downloadFromDataURL(config.fileName, csvContent);\r\n observer.next(null);\r\n } else {\r\n observer.next(csvContent);\r\n }\r\n observer.complete();\r\n });\r\n }\r\n\r\n private _getTXT(config: ExportAsConfig): Observable<string | null> {\r\n const nameFrags = config.fileName?.split('.');\r\n config.fileName = `${nameFrags?.[0]}.txt`;\r\n return this._getCSV(config);\r\n }\r\n\r\n private _getXLS(config: ExportAsConfig): Observable<string | null> {\r\n return new Observable((observer): void => {\r\n const element = document.getElementById(config.elementIdOrContent) as HTMLTableElement | null;\r\n const ws3 = XLSX.utils.table_to_sheet(element, config.options);\r\n const wb = XLSX.utils.book_new();\r\n XLSX.utils.book_append_sheet(wb, ws3, config.fileName);\r\n const out: string = XLSX.write(wb, { type: 'base64' }) as string;\r\n const xlsContent = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,' + out;\r\n if (config.download) {\r\n this.downloadFromDataURL(config.fileName, xlsContent);\r\n observer.next(null);\r\n } else {\r\n observer.next(xlsContent);\r\n }\r\n observer.complete();\r\n });\r\n }\r\n\r\n private _getXLSX(config: ExportAsConfig): Observable<string | null> {\r\n return this._getXLS(config);\r\n }\r\n\r\n\r\n private _getJSON(config: ExportAsConfig): Observable<Record<string, string>[] | null> {\r\n return new Observable((observer): void => {\r\n const data: Record<string, string>[] = [];\r\n const headers: string[] = [];\r\n const table = document.getElementById(config.elementIdOrContent) as HTMLTableElement;\r\n for (let index = 0; index < table.rows[0].cells.length; index++) {\r\n headers[index] = (table.rows[0].cells[index].textContent ?? '').toLowerCase().replace(/ /gi, '');\r\n }\r\n for (let i = 1; i < table.rows.length; i++) {\r\n const tableRow = table.rows[i];\r\n const rowData: Record<string, string> = {};\r\n for (let j = 0; j < tableRow.cells.length; j++) {\r\n rowData[headers[j]] = tableRow.cells[j].textContent ?? '';\r\n }\r\n data.push(rowData);\r\n }\r\n const jsonString = JSON.stringify(data);\r\n const jsonBase64 = this._btoa(jsonString);\r\n const dataStr = 'data:text/json;base64,' + jsonBase64;\r\n if (config.download) {\r\n this.downloadFromDataURL(config.fileName, dataStr);\r\n observer.next(null);\r\n } else {\r\n observer.next(data);\r\n }\r\n observer.complete();\r\n });\r\n }\r\n\r\n private _getXML(config: ExportAsConfig): Observable<string | null> {\r\n return new Observable((observer): void => {\r\n let xml = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><Root><Classes>';\r\n const tritem = document.getElementById(config.elementIdOrContent)?.getElementsByTagName('tr');\r\n\r\n if (tritem) {\r\n Array.from(tritem).forEach((celldata): void => {\r\n if (celldata.cells.length > 0) {\r\n xml += '<Class name=\"' + celldata.cells[0].textContent + '\">\\n';\r\n for (let m = 1; m < celldata.cells.length; ++m) {\r\n xml += '\\t<data>' + celldata.cells[m].textContent + '</data>\\n';\r\n }\r\n xml += '</Class>\\n';\r\n }\r\n });\r\n\r\n }\r\n\r\n xml += '</Classes></Root>';\r\n const base64 = 'data:text/xml;base64,' + this._btoa(xml);\r\n if (config.download) {\r\n this.downloadFromDataURL(config.fileName, base64);\r\n observer.next(null);\r\n } else {\r\n observer.next(base64);\r\n }\r\n observer.complete();\r\n });\r\n }\r\n\r\n private _btoa(content: string): string {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n return btoa(unescape(encodeURIComponent(content)));\r\n }\r\n\r\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MASa,mBAAmB,CAAA;AAE5B,IAAA,GAAG,CAAC,MAAsB,EAAA;AACtB,QAAA,QAAQ,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE;AAC7B,YAAA,KAAK,KAAK;AACN,gBAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;AAC/B,YAAA,KAAK,KAAK;AACN,gBAAA,OAAO,IA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,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAnB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,cAFhB,MAAM,EAAA,CAAA,CAAA;;2FAET,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAH/B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,UAAU,EAAE;AACf,iBAAA;;;ACRD;;AAEG;;"}
1
+ {"version":3,"file":"cmat-services-export-as.mjs","names":[],"sources":["../../../projects/cmat/services/export-as/export-as.service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\r\nimport * as FileSaver from 'file-saver-es';\r\nimport { Observable } from 'rxjs';\r\nimport * as XLSX from 'xlsx';\r\nimport { ExportAsConfig } from './export-as-config.model';\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class CmatExportAsService {\r\n \r\n get(config: ExportAsConfig): Observable<string | unknown[] | null> {\r\n switch (config.type.toUpperCase()) {\r\n case 'CSV':\r\n return this._getCSV(config);\r\n case 'TXT':\r\n return this._getTXT(config);\r\n case 'XLS':\r\n return this._getXLS(config);\r\n case 'XLSX':\r\n return this._getXLSX(config);\r\n case 'JSON':\r\n return this._getJSON(config);\r\n case 'XML':\r\n return this._getXML(config);\r\n default:\r\n return new Observable((observer): void => { observer.error('导出格式不支持。'); });\r\n }\r\n }\r\n\r\n \r\n save(config: ExportAsConfig, fileName: string): Observable<string | unknown[] | null> {\r\n config.download = true;\r\n config.fileName = fileName + '.' + config.type;\r\n return this.get(config);\r\n }\r\n\r\n \r\n contentToBlob(content: string): Observable<Blob> {\r\n return new Observable((observer): void => {\r\n const arr = content.split(','), mime = (/:(.*?);/.exec(arr[0]))?.[1],\r\n bstr = atob(arr[1]);\r\n let n = bstr.length;\r\n const u8arr = new Uint8Array(n);\r\n while (n--) {\r\n u8arr[n] = bstr.charCodeAt(n);\r\n }\r\n observer.next(new Blob([u8arr], { type: mime }));\r\n observer.complete();\r\n });\r\n }\r\n\r\n \r\n removeFileTypeFromBase64(fileContent: string): string {\r\n const re = /^data:[^]*;base64,/g;\r\n const newContent: string = re[Symbol.replace](fileContent, '');\r\n return newContent;\r\n }\r\n\r\n \r\n addFileTypeToBase64(fileContent: string, fileMime: string): string {\r\n return `data:${fileMime};base64,${fileContent}`;\r\n }\r\n\r\n downloadFromDataURL(fileName: string, dataURL: string): void {\r\n this.contentToBlob(dataURL).subscribe((blob): void => {\r\n this.downloadFromBlob(blob, fileName);\r\n });\r\n }\r\n\r\n downloadFromBlob(blob: Blob, fileName: string): void {\r\n FileSaver.saveAs(blob, fileName);\r\n }\r\n\r\n private _getCSV(config: ExportAsConfig): Observable<string | null> {\r\n return new Observable((observer): void => {\r\n const element: HTMLElement | null = document.getElementById(config.elementIdOrContent);\r\n const csv: string[] = [];\r\n const rows = element?.querySelectorAll('table tr');\r\n rows?.forEach((rowElement: Element): void => {\r\n const row: string[] = [];\r\n const cols = (rowElement as HTMLTableRowElement).querySelectorAll('td, th');\r\n\r\n Array.from(cols).forEach((col: Element): void => {\r\n row.push('\"' + ((col as HTMLTableCellElement).textContent ?? (col as HTMLTableCellElement).innerText) + '\"');\r\n });\r\n csv.push(row.join(','));\r\n });\r\n\r\n const csvContent = 'data:text/csv;base64,' + this._btoa(csv.join('\\n'));\r\n if (config.download) {\r\n this.downloadFromDataURL(config.fileName, csvContent);\r\n observer.next(null);\r\n } else {\r\n observer.next(csvContent);\r\n }\r\n observer.complete();\r\n });\r\n }\r\n\r\n private _getTXT(config: ExportAsConfig): Observable<string | null> {\r\n const nameFrags = config.fileName?.split('.');\r\n config.fileName = `${nameFrags?.[0]}.txt`;\r\n return this._getCSV(config);\r\n }\r\n\r\n private _getXLS(config: ExportAsConfig): Observable<string | null> {\r\n return new Observable((observer): void => {\r\n const element = document.getElementById(config.elementIdOrContent) as HTMLTableElement | null;\r\n const ws3 = XLSX.utils.table_to_sheet(element, config.options);\r\n const wb = XLSX.utils.book_new();\r\n XLSX.utils.book_append_sheet(wb, ws3, config.fileName);\r\n const out: string = XLSX.write(wb, { type: 'base64' }) as string;\r\n const xlsContent = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,' + out;\r\n if (config.download) {\r\n this.downloadFromDataURL(config.fileName, xlsContent);\r\n observer.next(null);\r\n } else {\r\n observer.next(xlsContent);\r\n }\r\n observer.complete();\r\n });\r\n }\r\n\r\n private _getXLSX(config: ExportAsConfig): Observable<string | null> {\r\n return this._getXLS(config);\r\n }\r\n\r\n\r\n private _getJSON(config: ExportAsConfig): Observable<Record<string, string>[] | null> {\r\n return new Observable((observer): void => {\r\n const data: Record<string, string>[] = [];\r\n const headers: string[] = [];\r\n const table = document.getElementById(config.elementIdOrContent) as HTMLTableElement;\r\n for (let index = 0; index < table.rows[0].cells.length; index++) {\r\n headers[index] = (table.rows[0].cells[index].textContent ?? '').toLowerCase().replace(/ /gi, '');\r\n }\r\n for (let i = 1; i < table.rows.length; i++) {\r\n const tableRow = table.rows[i];\r\n const rowData: Record<string, string> = {};\r\n for (let j = 0; j < tableRow.cells.length; j++) {\r\n rowData[headers[j]] = tableRow.cells[j].textContent ?? '';\r\n }\r\n data.push(rowData);\r\n }\r\n const jsonString = JSON.stringify(data);\r\n const jsonBase64 = this._btoa(jsonString);\r\n const dataStr = 'data:text/json;base64,' + jsonBase64;\r\n if (config.download) {\r\n this.downloadFromDataURL(config.fileName, dataStr);\r\n observer.next(null);\r\n } else {\r\n observer.next(data);\r\n }\r\n observer.complete();\r\n });\r\n }\r\n\r\n private _getXML(config: ExportAsConfig): Observable<string | null> {\r\n return new Observable((observer): void => {\r\n let xml = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><Root><Classes>';\r\n const tritem = document.getElementById(config.elementIdOrContent)?.getElementsByTagName('tr');\r\n\r\n if (tritem) {\r\n Array.from(tritem).forEach((celldata): void => {\r\n if (celldata.cells.length > 0) {\r\n xml += '<Class name=\"' + celldata.cells[0].textContent + '\">\\n';\r\n for (let m = 1; m < celldata.cells.length; ++m) {\r\n xml += '\\t<data>' + celldata.cells[m].textContent + '</data>\\n';\r\n }\r\n xml += '</Class>\\n';\r\n }\r\n });\r\n\r\n }\r\n\r\n xml += '</Classes></Root>';\r\n const base64 = 'data:text/xml;base64,' + this._btoa(xml);\r\n if (config.download) {\r\n this.downloadFromDataURL(config.fileName, base64);\r\n observer.next(null);\r\n } else {\r\n observer.next(base64);\r\n }\r\n observer.complete();\r\n });\r\n }\r\n\r\n private _btoa(content: string): string {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n return btoa(unescape(encodeURIComponent(content)));\r\n }\r\n\r\n}"],"mappings":";;;;;AASA,IAAa,sBAAb,MAAa,oBAAmB;CAE5B,IAAI,QAAsB;EACtB,QAAQ,OAAO,KAAK,YAAW,GAA/B;GACI,KAAK,OACD,OAAO,KAAK,QAAQ,MAAM;GAC9B,KAAK,OACD,OAAO,KAAK,QAAQ,MAAM;GAC9B,KAAK,OACD,OAAO,KAAK,QAAQ,MAAM;GAC9B,KAAK,QACD,OAAO,KAAK,SAAS,MAAM;GAC/B,KAAK,QACD,OAAO,KAAK,SAAS,MAAM;GAC/B,KAAK,OACD,OAAO,KAAK,QAAQ,MAAM;GAC9B,SACI,OAAO,IAAI,YAAY,aAAkB;IAAG,SAAS,MAAM,UAAU;GAAG,CAAC;EACjF;CACJ;CAGA,KAAK,QAAwB,UAAgB;EACzC,OAAO,WAAW;EAClB,OAAO,WAAW,WAAW,MAAM,OAAO;EAC1C,OAAO,KAAK,IAAI,MAAM;CAC1B;CAGA,cAAc,SAAe;EACzB,OAAO,IAAI,YAAY,aAAkB;GACrC,MAAM,MAAM,QAAQ,MAAM,GAAG,GAAG,OAAQ,UAAU,KAAK,IAAI,EAAE,CAAC,GAAI,IAC9D,OAA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GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAmB,YAAA,CAAA;EAH/B,MAAA;EAAW,MAAA,CAAA,EACR,YAAY,OACf,CAAA"}
@@ -1,96 +1,117 @@
1
- import * as i0 from '@angular/core';
2
- import { signal, Injectable, inject } from '@angular/core';
3
- import { finalize } from 'rxjs';
4
-
5
- class CmatLoadingService {
6
- constructor() {
7
- this._auto = signal(true, /* @ts-ignore */
8
- ...(ngDevMode ? [{ debugName: "_auto" }] : /* istanbul ignore next */ []));
9
- this._mode = signal('indeterminate', /* @ts-ignore */
10
- ...(ngDevMode ? [{ debugName: "_mode" }] : /* istanbul ignore next */ []));
11
- this._progress = signal(0, /* @ts-ignore */
12
- ...(ngDevMode ? [{ debugName: "_progress" }] : /* istanbul ignore next */ []));
13
- this._show = signal(false, /* @ts-ignore */
14
- ...(ngDevMode ? [{ debugName: "_show" }] : /* istanbul ignore next */ []));
15
- // eslint-disable-next-line @typescript-eslint/member-ordering
16
- this.auto = this._auto.asReadonly();
17
- // eslint-disable-next-line @typescript-eslint/member-ordering
18
- this.mode = this._mode.asReadonly();
19
- // eslint-disable-next-line @typescript-eslint/member-ordering
20
- this.progress = this._progress.asReadonly();
21
- // eslint-disable-next-line @typescript-eslint/member-ordering
22
- this.isShowing = this._show.asReadonly();
23
- this._urlSet = new Set();
24
- }
25
- show() {
26
- this._show.set(true);
27
- }
28
- hide() {
29
- this._show.set(false);
30
- }
31
- setAutoMode(value) {
32
- this._auto.set(value);
33
- }
34
- setMode(value) {
35
- this._mode.set(value);
36
- }
37
- setProgress(value) {
38
- if (value < 0 || value > 100) {
39
- console.error('Progress value must be between 0 and 100!');
40
- return;
41
- }
42
- this._progress.set(value);
43
- }
44
- setLoadingStatus(status, url) {
45
- if (!url) {
46
- console.error('The request URL must be provided!');
47
- return;
48
- }
49
- if (status) {
50
- this._urlSet.add(url);
51
- this._show.set(true);
52
- return;
53
- }
54
- if (this._urlSet.has(url)) {
55
- this._urlSet.delete(url);
56
- }
57
- if (this._urlSet.size === 0) {
58
- this._show.set(false);
59
- }
60
- }
61
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatLoadingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
62
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatLoadingService, providedIn: 'root' }); }
63
- }
64
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatLoadingService, decorators: [{
65
- type: Injectable,
66
- args: [{
67
- providedIn: 'root'
68
- }]
69
- }] });
70
-
71
- class CmatLoadingInterceptor {
72
- constructor() {
73
- this._cmatLoadingService = inject(CmatLoadingService);
74
- }
75
- intercept(req, next) {
76
- if (!this._cmatLoadingService.auto() || req.url.includes('file/download/')) {
77
- return next.handle(req);
78
- }
79
- this._cmatLoadingService.setLoadingStatus(true, req.url);
80
- return next.handle(req).pipe(finalize(() => {
81
- this._cmatLoadingService.setLoadingStatus(false, req.url);
82
- }));
83
- }
84
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatLoadingInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
85
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatLoadingInterceptor }); }
86
- }
87
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatLoadingInterceptor, decorators: [{
88
- type: Injectable
89
- }] });
90
-
91
- /**
92
- * Generated bundle index. Do not edit.
93
- */
94
-
1
+ import * as i0 from "@angular/core";
2
+ import { Injectable, inject, signal } from "@angular/core";
3
+ import { finalize } from "rxjs";
4
+ var CmatLoadingService = class CmatLoadingService {
5
+ constructor() {
6
+ this._auto = signal(true, ...ngDevMode ? [{ debugName: "_auto" }] : /* istanbul ignore next */ []);
7
+ this._mode = signal("indeterminate", ...ngDevMode ? [{ debugName: "_mode" }] : /* istanbul ignore next */ []);
8
+ this._progress = signal(0, ...ngDevMode ? [{ debugName: "_progress" }] : /* istanbul ignore next */ []);
9
+ this._show = signal(false, ...ngDevMode ? [{ debugName: "_show" }] : /* istanbul ignore next */ []);
10
+ this.auto = this._auto.asReadonly();
11
+ this.mode = this._mode.asReadonly();
12
+ this.progress = this._progress.asReadonly();
13
+ this.isShowing = this._show.asReadonly();
14
+ this._urlSet = /* @__PURE__ */ new Set();
15
+ }
16
+ show() {
17
+ this._show.set(true);
18
+ }
19
+ hide() {
20
+ this._show.set(false);
21
+ }
22
+ setAutoMode(value) {
23
+ this._auto.set(value);
24
+ }
25
+ setMode(value) {
26
+ this._mode.set(value);
27
+ }
28
+ setProgress(value) {
29
+ if (value < 0 || value > 100) {
30
+ console.error("Progress value must be between 0 and 100!");
31
+ return;
32
+ }
33
+ this._progress.set(value);
34
+ }
35
+ setLoadingStatus(status, url) {
36
+ if (!url) {
37
+ console.error("The request URL must be provided!");
38
+ return;
39
+ }
40
+ if (status) {
41
+ this._urlSet.add(url);
42
+ this._show.set(true);
43
+ return;
44
+ }
45
+ if (this._urlSet.has(url)) this._urlSet.delete(url);
46
+ if (this._urlSet.size === 0) this._show.set(false);
47
+ }
48
+ static {
49
+ this.ɵfac = i0.ɵɵngDeclareFactory({
50
+ minVersion: "12.0.0",
51
+ version: "22.2.3",
52
+ ngImport: i0,
53
+ type: CmatLoadingService,
54
+ deps: [],
55
+ target: i0.ɵɵFactoryTarget.Injectable
56
+ });
57
+ }
58
+ static {
59
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
60
+ minVersion: "12.0.0",
61
+ version: "22.2.3",
62
+ ngImport: i0,
63
+ type: CmatLoadingService,
64
+ providedIn: "root"
65
+ });
66
+ }
67
+ };
68
+ i0.ɵɵngDeclareClassMetadata({
69
+ minVersion: "12.0.0",
70
+ version: "22.2.3",
71
+ ngImport: i0,
72
+ type: CmatLoadingService,
73
+ decorators: [{
74
+ type: Injectable,
75
+ args: [{ providedIn: "root" }]
76
+ }]
77
+ });
78
+ var CmatLoadingInterceptor = class CmatLoadingInterceptor {
79
+ constructor() {
80
+ this._cmatLoadingService = inject(CmatLoadingService);
81
+ }
82
+ intercept(req, next) {
83
+ if (!this._cmatLoadingService.auto() || req.url.includes("file/download/")) return next.handle(req);
84
+ this._cmatLoadingService.setLoadingStatus(true, req.url);
85
+ return next.handle(req).pipe(finalize(() => {
86
+ this._cmatLoadingService.setLoadingStatus(false, req.url);
87
+ }));
88
+ }
89
+ static {
90
+ this.ɵfac = i0.ɵɵngDeclareFactory({
91
+ minVersion: "12.0.0",
92
+ version: "22.2.3",
93
+ ngImport: i0,
94
+ type: CmatLoadingInterceptor,
95
+ deps: [],
96
+ target: i0.ɵɵFactoryTarget.Injectable
97
+ });
98
+ }
99
+ static {
100
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
101
+ minVersion: "12.0.0",
102
+ version: "22.2.3",
103
+ ngImport: i0,
104
+ type: CmatLoadingInterceptor
105
+ });
106
+ }
107
+ };
108
+ i0.ɵɵngDeclareClassMetadata({
109
+ minVersion: "12.0.0",
110
+ version: "22.2.3",
111
+ ngImport: i0,
112
+ type: CmatLoadingInterceptor,
113
+ decorators: [{ type: Injectable }]
114
+ });
95
115
  export { CmatLoadingInterceptor, CmatLoadingService };
96
- //# sourceMappingURL=cmat-services-loading.mjs.map
116
+
117
+ //# sourceMappingURL=cmat-services-loading.mjs.map