cmat 0.0.111 → 0.0.113
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.
- package/fesm2022/cmat-components-adapter.mjs +531 -536
- package/fesm2022/cmat-components-adapter.mjs.map +1 -1
- package/fesm2022/cmat-components-breadcrumb.mjs +521 -356
- package/fesm2022/cmat-components-breadcrumb.mjs.map +1 -1
- package/fesm2022/cmat-components-card.mjs +150 -42
- package/fesm2022/cmat-components-card.mjs.map +1 -1
- package/fesm2022/cmat-components-carousel.mjs +1120 -629
- package/fesm2022/cmat-components-carousel.mjs.map +1 -1
- package/fesm2022/cmat-components-cascade.mjs +861 -441
- package/fesm2022/cmat-components-cascade.mjs.map +1 -1
- package/fesm2022/cmat-components-chip-input.mjs +580 -335
- package/fesm2022/cmat-components-chip-input.mjs.map +1 -1
- package/fesm2022/cmat-components-code-editor.mjs +197 -105
- package/fesm2022/cmat-components-code-editor.mjs.map +1 -1
- package/fesm2022/cmat-components-color-picker.mjs +1762 -825
- package/fesm2022/cmat-components-color-picker.mjs.map +1 -1
- package/fesm2022/cmat-components-custom-formly.mjs +5196 -2531
- package/fesm2022/cmat-components-custom-formly.mjs.map +1 -1
- package/fesm2022/cmat-components-data-picker.mjs +1901 -1073
- package/fesm2022/cmat-components-data-picker.mjs.map +1 -1
- package/fesm2022/cmat-components-date-range.mjs +701 -456
- package/fesm2022/cmat-components-date-range.mjs.map +1 -1
- package/fesm2022/cmat-components-date-time-display.mjs +137 -30
- package/fesm2022/cmat-components-date-time-display.mjs.map +1 -1
- package/fesm2022/cmat-components-drawer.mjs +410 -258
- package/fesm2022/cmat-components-drawer.mjs.map +1 -1
- package/fesm2022/cmat-components-empty-state.mjs +201 -41
- package/fesm2022/cmat-components-empty-state.mjs.map +1 -1
- package/fesm2022/cmat-components-file-preview.mjs +198 -35
- package/fesm2022/cmat-components-file-preview.mjs.map +1 -1
- package/fesm2022/cmat-components-filter-toolbar.mjs +320 -72
- package/fesm2022/cmat-components-filter-toolbar.mjs.map +1 -1
- package/fesm2022/cmat-components-form-actions.mjs +102 -26
- package/fesm2022/cmat-components-form-actions.mjs.map +1 -1
- package/fesm2022/cmat-components-fullscreen.mjs +167 -47
- package/fesm2022/cmat-components-fullscreen.mjs.map +1 -1
- package/fesm2022/cmat-components-highlight.mjs +203 -112
- package/fesm2022/cmat-components-highlight.mjs.map +1 -1
- package/fesm2022/cmat-components-image-viewer.mjs +489 -215
- package/fesm2022/cmat-components-image-viewer.mjs.map +1 -1
- package/fesm2022/cmat-components-inline-loading.mjs +117 -27
- package/fesm2022/cmat-components-inline-loading.mjs.map +1 -1
- package/fesm2022/cmat-components-json-editor.mjs +276 -230
- package/fesm2022/cmat-components-json-editor.mjs.map +1 -1
- package/fesm2022/cmat-components-knob-input.mjs +615 -420
- package/fesm2022/cmat-components-knob-input.mjs.map +1 -1
- package/fesm2022/cmat-components-loading-overlay.mjs +53 -25
- package/fesm2022/cmat-components-loading-overlay.mjs.map +1 -1
- package/fesm2022/cmat-components-masonry.mjs +120 -40
- package/fesm2022/cmat-components-masonry.mjs.map +1 -1
- package/fesm2022/cmat-components-material-color-picker.mjs +332 -155
- package/fesm2022/cmat-components-material-color-picker.mjs.map +1 -1
- package/fesm2022/cmat-components-material-datetimepicker.mjs +4283 -2504
- package/fesm2022/cmat-components-material-datetimepicker.mjs.map +1 -1
- package/fesm2022/cmat-components-navigation.mjs +3080 -1404
- package/fesm2022/cmat-components-navigation.mjs.map +1 -1
- package/fesm2022/cmat-components-opt-input.mjs +540 -466
- package/fesm2022/cmat-components-opt-input.mjs.map +1 -1
- package/fesm2022/cmat-components-org-chart.mjs +528 -125
- package/fesm2022/cmat-components-org-chart.mjs.map +1 -1
- package/fesm2022/cmat-components-page-header.mjs +141 -32
- package/fesm2022/cmat-components-page-header.mjs.map +1 -1
- package/fesm2022/cmat-components-pagination.mjs +866 -534
- package/fesm2022/cmat-components-pagination.mjs.map +1 -1
- package/fesm2022/cmat-components-password-strength.mjs +873 -434
- package/fesm2022/cmat-components-password-strength.mjs.map +1 -1
- package/fesm2022/cmat-components-popover.mjs +1012 -731
- package/fesm2022/cmat-components-popover.mjs.map +1 -1
- package/fesm2022/cmat-components-progress-bar.mjs +98 -35
- package/fesm2022/cmat-components-progress-bar.mjs.map +1 -1
- package/fesm2022/cmat-components-qrcode.mjs +463 -287
- package/fesm2022/cmat-components-qrcode.mjs.map +1 -1
- package/fesm2022/cmat-components-rating.mjs +377 -203
- package/fesm2022/cmat-components-rating.mjs.map +1 -1
- package/fesm2022/cmat-components-rich-text-editor.mjs +153 -39
- package/fesm2022/cmat-components-rich-text-editor.mjs.map +1 -1
- package/fesm2022/cmat-components-select-search.mjs +926 -496
- package/fesm2022/cmat-components-select-search.mjs.map +1 -1
- package/fesm2022/cmat-components-select-table.mjs +1280 -842
- package/fesm2022/cmat-components-select-table.mjs.map +1 -1
- package/fesm2022/cmat-components-select-tree.mjs +998 -690
- package/fesm2022/cmat-components-select-tree.mjs.map +1 -1
- package/fesm2022/cmat-components-skeleton.mjs +143 -57
- package/fesm2022/cmat-components-skeleton.mjs.map +1 -1
- package/fesm2022/cmat-components-speed-dial.mjs +457 -303
- package/fesm2022/cmat-components-speed-dial.mjs.map +1 -1
- package/fesm2022/cmat-components-status-tag.mjs +136 -44
- package/fesm2022/cmat-components-status-tag.mjs.map +1 -1
- package/fesm2022/cmat-components-table-toolbar.mjs +120 -28
- package/fesm2022/cmat-components-table-toolbar.mjs.map +1 -1
- package/fesm2022/cmat-components-timeline.mjs +464 -168
- package/fesm2022/cmat-components-timeline.mjs.map +1 -1
- package/fesm2022/cmat-components-toast.mjs +346 -262
- package/fesm2022/cmat-components-toast.mjs.map +1 -1
- package/fesm2022/cmat-components-transfer-picker.mjs +1427 -593
- package/fesm2022/cmat-components-transfer-picker.mjs.map +1 -1
- package/fesm2022/cmat-components-treetable.mjs +372 -112
- package/fesm2022/cmat-components-treetable.mjs.map +1 -1
- package/fesm2022/cmat-components-upload.mjs +904 -410
- package/fesm2022/cmat-components-upload.mjs.map +1 -1
- package/fesm2022/cmat-components-x6-angular-shape.mjs +153 -170
- package/fesm2022/cmat-components-x6-angular-shape.mjs.map +1 -1
- package/fesm2022/cmat-directives-animate-on-scroll.mjs +220 -138
- package/fesm2022/cmat-directives-animate-on-scroll.mjs.map +1 -1
- package/fesm2022/cmat-directives-arrow-cursor.mjs +246 -193
- package/fesm2022/cmat-directives-arrow-cursor.mjs.map +1 -1
- package/fesm2022/cmat-directives-autofocus.mjs +43 -25
- package/fesm2022/cmat-directives-autofocus.mjs.map +1 -1
- package/fesm2022/cmat-directives-data-exporter.mjs +537 -338
- package/fesm2022/cmat-directives-data-exporter.mjs.map +1 -1
- package/fesm2022/cmat-directives-debounce.mjs +162 -76
- package/fesm2022/cmat-directives-debounce.mjs.map +1 -1
- package/fesm2022/cmat-directives-digit-only.mjs +457 -356
- package/fesm2022/cmat-directives-digit-only.mjs.map +1 -1
- package/fesm2022/cmat-directives-equal-validator.mjs +70 -53
- package/fesm2022/cmat-directives-equal-validator.mjs.map +1 -1
- package/fesm2022/cmat-directives-seamless-auto-scroll.mjs +180 -132
- package/fesm2022/cmat-directives-seamless-auto-scroll.mjs.map +1 -1
- package/fesm2022/cmat-lib-mock-api.mjs +207 -195
- package/fesm2022/cmat-lib-mock-api.mjs.map +1 -1
- package/fesm2022/cmat-pipes-bytes.mjs +50 -30
- package/fesm2022/cmat-pipes-bytes.mjs.map +1 -1
- package/fesm2022/cmat-pipes-date-format.mjs +41 -25
- package/fesm2022/cmat-pipes-date-format.mjs.map +1 -1
- package/fesm2022/cmat-pipes-find-by-key.mjs +44 -26
- package/fesm2022/cmat-pipes-find-by-key.mjs.map +1 -1
- package/fesm2022/cmat-pipes-group-by.mjs +50 -38
- package/fesm2022/cmat-pipes-group-by.mjs.map +1 -1
- package/fesm2022/cmat-pipes-keys.mjs +44 -31
- package/fesm2022/cmat-pipes-keys.mjs.map +1 -1
- package/fesm2022/cmat-pipes-secure.mjs +60 -49
- package/fesm2022/cmat-pipes-secure.mjs.map +1 -1
- package/fesm2022/cmat-pipes-uppercase.mjs +39 -22
- package/fesm2022/cmat-pipes-uppercase.mjs.map +1 -1
- package/fesm2022/cmat-reports.mjs +2761 -0
- package/fesm2022/cmat-reports.mjs.map +1 -0
- package/fesm2022/cmat-services-alert.mjs +249 -277
- package/fesm2022/cmat-services-alert.mjs.map +1 -1
- package/fesm2022/cmat-services-config.mjs +110 -81
- package/fesm2022/cmat-services-config.mjs.map +1 -1
- package/fesm2022/cmat-services-confirmation.mjs +184 -73
- package/fesm2022/cmat-services-confirmation.mjs.map +1 -1
- package/fesm2022/cmat-services-data.mjs +136 -125
- package/fesm2022/cmat-services-data.mjs.map +1 -1
- package/fesm2022/cmat-services-export-as.mjs +165 -183
- package/fesm2022/cmat-services-export-as.mjs.map +1 -1
- package/fesm2022/cmat-services-loading.mjs +116 -95
- package/fesm2022/cmat-services-loading.mjs.map +1 -1
- package/fesm2022/cmat-services-local-storage.mjs +75 -66
- package/fesm2022/cmat-services-local-storage.mjs.map +1 -1
- package/fesm2022/cmat-services-media-watcher.mjs +69 -64
- package/fesm2022/cmat-services-media-watcher.mjs.map +1 -1
- package/fesm2022/cmat-services-platform.mjs +48 -45
- package/fesm2022/cmat-services-platform.mjs.map +1 -1
- package/fesm2022/cmat-services-print.mjs +984 -1109
- package/fesm2022/cmat-services-print.mjs.map +1 -1
- package/fesm2022/cmat-services-splash-screen.mjs +53 -38
- package/fesm2022/cmat-services-splash-screen.mjs.map +1 -1
- package/fesm2022/cmat-services-title.mjs +57 -47
- package/fesm2022/cmat-services-title.mjs.map +1 -1
- package/fesm2022/cmat-services-translation.mjs +79 -68
- package/fesm2022/cmat-services-translation.mjs.map +1 -1
- package/fesm2022/cmat-services-utils.mjs +424 -517
- package/fesm2022/cmat-services-utils.mjs.map +1 -1
- package/fesm2022/cmat-validators.mjs +23 -33
- package/fesm2022/cmat-validators.mjs.map +1 -1
- package/fesm2022/cmat-version.mjs +12 -16
- package/fesm2022/cmat-version.mjs.map +1 -1
- package/fesm2022/cmat.mjs +39805 -22511
- package/fesm2022/cmat.mjs.map +1 -1
- package/package.json +5 -1
- package/types/cmat-components-adapter.d.ts +145 -156
- package/types/cmat-components-breadcrumb.d.ts +108 -86
- package/types/cmat-components-card.d.ts +34 -18
- package/types/cmat-components-carousel.d.ts +251 -134
- package/types/cmat-components-cascade.d.ts +158 -117
- package/types/cmat-components-chip-input.d.ts +105 -71
- package/types/cmat-components-code-editor.d.ts +59 -34
- package/types/cmat-components-color-picker.d.ts +378 -236
- package/types/cmat-components-custom-formly.d.ts +776 -814
- package/types/cmat-components-data-picker.d.ts +502 -360
- package/types/cmat-components-date-range.d.ts +106 -77
- package/types/cmat-components-date-time-display.d.ts +36 -13
- package/types/cmat-components-drawer.d.ts +91 -61
- package/types/cmat-components-empty-state.d.ts +47 -17
- package/types/cmat-components-file-preview.d.ts +42 -14
- package/types/cmat-components-filter-toolbar.d.ts +57 -25
- package/types/cmat-components-form-actions.d.ts +18 -10
- package/types/cmat-components-fullscreen.d.ts +21 -13
- package/types/cmat-components-highlight.d.ts +33 -26
- package/types/cmat-components-image-viewer.d.ts +119 -58
- package/types/cmat-components-inline-loading.d.ts +24 -11
- package/types/cmat-components-json-editor.d.ts +39 -28
- package/types/cmat-components-knob-input.d.ts +172 -101
- package/types/cmat-components-loading-overlay.d.ts +8 -11
- package/types/cmat-components-masonry.d.ts +27 -14
- package/types/cmat-components-material-color-picker.d.ts +56 -42
- package/types/cmat-components-material-datetimepicker.d.ts +817 -454
- package/types/cmat-components-navigation.d.ts +295 -221
- package/types/cmat-components-opt-input.d.ts +111 -90
- package/types/cmat-components-org-chart.d.ts +53 -35
- package/types/cmat-components-page-header.d.ts +37 -14
- package/types/cmat-components-pagination.d.ts +144 -107
- package/types/cmat-components-password-strength.d.ts +197 -86
- package/types/cmat-components-popover.d.ts +264 -166
- package/types/cmat-components-progress-bar.d.ts +17 -14
- package/types/cmat-components-qrcode.d.ts +111 -42
- package/types/cmat-components-rating.d.ts +105 -59
- package/types/cmat-components-rich-text-editor.d.ts +39 -16
- package/types/cmat-components-select-search.d.ts +195 -99
- package/types/cmat-components-select-table.d.ts +241 -142
- package/types/cmat-components-select-tree.d.ts +185 -118
- package/types/cmat-components-skeleton.d.ts +55 -32
- package/types/cmat-components-speed-dial.d.ts +86 -61
- package/types/cmat-components-status-tag.d.ts +42 -24
- package/types/cmat-components-table-toolbar.d.ts +30 -12
- package/types/cmat-components-timeline.d.ts +83 -51
- package/types/cmat-components-toast.d.ts +84 -85
- package/types/cmat-components-transfer-picker.d.ts +228 -181
- package/types/cmat-components-treetable.d.ts +63 -39
- package/types/cmat-components-upload.d.ts +205 -106
- package/types/cmat-components-x6-angular-shape.d.ts +29 -37
- package/types/cmat-directives-animate-on-scroll.d.ts +48 -30
- package/types/cmat-directives-arrow-cursor.d.ts +55 -35
- package/types/cmat-directives-autofocus.d.ts +8 -11
- package/types/cmat-directives-data-exporter.d.ts +71 -40
- package/types/cmat-directives-debounce.d.ts +31 -28
- package/types/cmat-directives-digit-only.d.ts +90 -53
- package/types/cmat-directives-equal-validator.d.ts +11 -14
- package/types/cmat-directives-seamless-auto-scroll.d.ts +42 -29
- package/types/cmat-lib-mock-api.d.ts +46 -55
- package/types/cmat-pipes-bytes.d.ts +7 -10
- package/types/cmat-pipes-date-format.d.ts +7 -10
- package/types/cmat-pipes-find-by-key.d.ts +8 -12
- package/types/cmat-pipes-group-by.d.ts +11 -15
- package/types/cmat-pipes-keys.d.ts +10 -13
- package/types/cmat-pipes-secure.d.ts +14 -17
- package/types/cmat-pipes-uppercase.d.ts +7 -10
- package/types/cmat-reports.d.ts +1138 -0
- package/types/cmat-services-alert.d.ts +80 -87
- package/types/cmat-services-config.d.ts +37 -43
- package/types/cmat-services-confirmation.d.ts +31 -37
- package/types/cmat-services-data.d.ts +18 -21
- package/types/cmat-services-export-as.d.ts +28 -33
- package/types/cmat-services-loading.d.ts +27 -31
- package/types/cmat-services-local-storage.d.ts +17 -21
- package/types/cmat-services-media-watcher.d.ts +14 -18
- package/types/cmat-services-platform.d.ts +8 -11
- package/types/cmat-services-print.d.ts +97 -102
- package/types/cmat-services-splash-screen.d.ts +11 -14
- package/types/cmat-services-title.d.ts +9 -12
- package/types/cmat-services-translation.d.ts +19 -22
- package/types/cmat-services-utils.d.ts +76 -80
- package/types/cmat-validators.d.ts +5 -8
- package/types/cmat-version.d.ts +8 -10
- package/types/cmat.d.ts +7551 -5204
|
@@ -1,184 +1,166 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import { Injectable } from
|
|
3
|
-
import * as FileSaver from
|
|
4
|
-
import { Observable } from
|
|
5
|
-
import * as XLSX from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
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,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;AAC/B,YAAA,KAAK,KAAK;AACN,gBAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;AAC/B,YAAA,KAAK,MAAM;AACP,gBAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AAChC,YAAA,KAAK,MAAM;AACP,gBAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AAChC,YAAA,KAAK,KAAK;AACN,gBAAA,OAAO,IAAI,CAAC,OAAO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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,OAAO,KAAK,IAAI,EAAE;GACtB,IAAI,IAAI,KAAK;GACb,MAAM,QAAQ,IAAI,WAAW,CAAC;GAC9B,OAAO,KACH,MAAM,KAAK,KAAK,WAAW,CAAC;GAEhC,SAAS,KAAK,IAAI,KAAK,CAAC,KAAK,GAAG,EAAE,MAAM,KAAI,CAAE,CAAC;GAC/C,SAAS,SAAQ;EACrB,CAAC;CACL;CAGA,yBAAyB,aAAmB;EAGxC,OAD2B,sBAAG,OAAO,QAAQ,CAAC,aAAa,EACpD;CACX;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|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=cmat-services-loading.mjs.map
|