@angular/material 21.0.0-next.9 → 21.0.0-rc.0

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 (202) hide show
  1. package/core/tokens/_classes.scss +1 -1
  2. package/core/tokens/m2/_md-sys-color.scss +17 -17
  3. package/fesm2022/_animation-chunk.mjs +10 -16
  4. package/fesm2022/_animation-chunk.mjs.map +1 -1
  5. package/fesm2022/_date-formats-chunk.mjs +68 -164
  6. package/fesm2022/_date-formats-chunk.mjs.map +1 -1
  7. package/fesm2022/_date-range-input-harness-chunk.mjs +284 -463
  8. package/fesm2022/_date-range-input-harness-chunk.mjs.map +1 -1
  9. package/fesm2022/_error-options-chunk.mjs +56 -19
  10. package/fesm2022/_error-options-chunk.mjs.map +1 -1
  11. package/fesm2022/_error-state-chunk.mjs +24 -31
  12. package/fesm2022/_error-state-chunk.mjs.map +1 -1
  13. package/fesm2022/_form-field-chunk.mjs +1224 -1017
  14. package/fesm2022/_form-field-chunk.mjs.map +1 -1
  15. package/fesm2022/_icon-button-chunk.mjs +243 -187
  16. package/fesm2022/_icon-button-chunk.mjs.map +1 -1
  17. package/fesm2022/_icon-registry-chunk.mjs +350 -575
  18. package/fesm2022/_icon-registry-chunk.mjs.map +1 -1
  19. package/fesm2022/_input-harness-chunk.mjs +56 -107
  20. package/fesm2022/_input-harness-chunk.mjs.map +1 -1
  21. package/fesm2022/_input-value-accessor-chunk.mjs +0 -6
  22. package/fesm2022/_input-value-accessor-chunk.mjs.map +1 -1
  23. package/fesm2022/_internal-form-field-chunk.mjs +59 -19
  24. package/fesm2022/_internal-form-field-chunk.mjs.map +1 -1
  25. package/fesm2022/_line-chunk.mjs +83 -43
  26. package/fesm2022/_line-chunk.mjs.map +1 -1
  27. package/fesm2022/_option-chunk.mjs +348 -311
  28. package/fesm2022/_option-chunk.mjs.map +1 -1
  29. package/fesm2022/_option-harness-chunk.mjs +23 -39
  30. package/fesm2022/_option-harness-chunk.mjs.map +1 -1
  31. package/fesm2022/_option-module-chunk.mjs +36 -10
  32. package/fesm2022/_option-module-chunk.mjs.map +1 -1
  33. package/fesm2022/_pseudo-checkbox-chunk.mjs +79 -44
  34. package/fesm2022/_pseudo-checkbox-chunk.mjs.map +1 -1
  35. package/fesm2022/_pseudo-checkbox-module-chunk.mjs +36 -10
  36. package/fesm2022/_pseudo-checkbox-module-chunk.mjs.map +1 -1
  37. package/fesm2022/_public-api-chunk.mjs +71 -134
  38. package/fesm2022/_public-api-chunk.mjs.map +1 -1
  39. package/fesm2022/_ripple-chunk.mjs +504 -600
  40. package/fesm2022/_ripple-chunk.mjs.map +1 -1
  41. package/fesm2022/_ripple-loader-chunk.mjs +120 -138
  42. package/fesm2022/_ripple-loader-chunk.mjs.map +1 -1
  43. package/fesm2022/_ripple-module-chunk.mjs +36 -10
  44. package/fesm2022/_ripple-module-chunk.mjs.map +1 -1
  45. package/fesm2022/_structural-styles-chunk.mjs +37 -10
  46. package/fesm2022/_structural-styles-chunk.mjs.map +1 -1
  47. package/fesm2022/_tooltip-chunk.mjs +810 -888
  48. package/fesm2022/_tooltip-chunk.mjs.map +1 -1
  49. package/fesm2022/autocomplete-testing.mjs +62 -86
  50. package/fesm2022/autocomplete-testing.mjs.map +1 -1
  51. package/fesm2022/autocomplete.mjs +965 -1126
  52. package/fesm2022/autocomplete.mjs.map +1 -1
  53. package/fesm2022/badge-testing.mjs +38 -54
  54. package/fesm2022/badge-testing.mjs.map +1 -1
  55. package/fesm2022/badge.mjs +321 -272
  56. package/fesm2022/badge.mjs.map +1 -1
  57. package/fesm2022/bottom-sheet-testing.mjs +10 -24
  58. package/fesm2022/bottom-sheet-testing.mjs.map +1 -1
  59. package/fesm2022/bottom-sheet.mjs +349 -344
  60. package/fesm2022/bottom-sheet.mjs.map +1 -1
  61. package/fesm2022/button-testing.mjs +60 -94
  62. package/fesm2022/button-testing.mjs.map +1 -1
  63. package/fesm2022/button-toggle-testing.mjs +76 -125
  64. package/fesm2022/button-toggle-testing.mjs.map +1 -1
  65. package/fesm2022/button-toggle.mjs +752 -662
  66. package/fesm2022/button-toggle.mjs.map +1 -1
  67. package/fesm2022/button.mjs +263 -158
  68. package/fesm2022/button.mjs.map +1 -1
  69. package/fesm2022/card-testing.mjs +19 -33
  70. package/fesm2022/card-testing.mjs.map +1 -1
  71. package/fesm2022/card.mjs +576 -272
  72. package/fesm2022/card.mjs.map +1 -1
  73. package/fesm2022/checkbox-testing.mjs +71 -123
  74. package/fesm2022/checkbox-testing.mjs.map +1 -1
  75. package/fesm2022/checkbox.mjs +515 -477
  76. package/fesm2022/checkbox.mjs.map +1 -1
  77. package/fesm2022/chips-testing.mjs +201 -344
  78. package/fesm2022/chips-testing.mjs.map +1 -1
  79. package/fesm2022/chips.mjs +2552 -2289
  80. package/fesm2022/chips.mjs.map +1 -1
  81. package/fesm2022/core-testing.mjs +14 -28
  82. package/fesm2022/core-testing.mjs.map +1 -1
  83. package/fesm2022/core.mjs +357 -328
  84. package/fesm2022/core.mjs.map +1 -1
  85. package/fesm2022/datepicker-testing.mjs +15 -25
  86. package/fesm2022/datepicker-testing.mjs.map +1 -1
  87. package/fesm2022/datepicker.mjs +4826 -4563
  88. package/fesm2022/datepicker.mjs.map +1 -1
  89. package/fesm2022/dialog-testing.mjs +93 -129
  90. package/fesm2022/dialog-testing.mjs.map +1 -1
  91. package/fesm2022/dialog.mjs +810 -829
  92. package/fesm2022/dialog.mjs.map +1 -1
  93. package/fesm2022/divider-testing.mjs +10 -11
  94. package/fesm2022/divider-testing.mjs.map +1 -1
  95. package/fesm2022/divider.mjs +119 -43
  96. package/fesm2022/divider.mjs.map +1 -1
  97. package/fesm2022/expansion-testing.mjs +74 -130
  98. package/fesm2022/expansion-testing.mjs.map +1 -1
  99. package/fesm2022/expansion.mjs +703 -515
  100. package/fesm2022/expansion.mjs.map +1 -1
  101. package/fesm2022/form-field-testing-control.mjs +16 -33
  102. package/fesm2022/form-field-testing-control.mjs.map +1 -1
  103. package/fesm2022/form-field-testing.mjs +118 -179
  104. package/fesm2022/form-field-testing.mjs.map +1 -1
  105. package/fesm2022/form-field.mjs +36 -10
  106. package/fesm2022/form-field.mjs.map +1 -1
  107. package/fesm2022/grid-list-testing.mjs +65 -113
  108. package/fesm2022/grid-list-testing.mjs.map +1 -1
  109. package/fesm2022/grid-list.mjs +559 -494
  110. package/fesm2022/grid-list.mjs.map +1 -1
  111. package/fesm2022/icon-testing.mjs +148 -127
  112. package/fesm2022/icon-testing.mjs.map +1 -1
  113. package/fesm2022/icon.mjs +325 -351
  114. package/fesm2022/icon.mjs.map +1 -1
  115. package/fesm2022/input-testing.mjs +59 -99
  116. package/fesm2022/input-testing.mjs.map +1 -1
  117. package/fesm2022/input.mjs +457 -520
  118. package/fesm2022/input.mjs.map +1 -1
  119. package/fesm2022/list-testing.mjs +251 -434
  120. package/fesm2022/list-testing.mjs.map +1 -1
  121. package/fesm2022/list.mjs +1522 -1204
  122. package/fesm2022/list.mjs.map +1 -1
  123. package/fesm2022/material.mjs +0 -5
  124. package/fesm2022/material.mjs.map +1 -1
  125. package/fesm2022/menu-testing.mjs +159 -228
  126. package/fesm2022/menu-testing.mjs.map +1 -1
  127. package/fesm2022/menu.mjs +1338 -1343
  128. package/fesm2022/menu.mjs.map +1 -1
  129. package/fesm2022/paginator-testing.mjs +55 -79
  130. package/fesm2022/paginator-testing.mjs.map +1 -1
  131. package/fesm2022/paginator.mjs +381 -309
  132. package/fesm2022/paginator.mjs.map +1 -1
  133. package/fesm2022/progress-bar-testing.mjs +12 -21
  134. package/fesm2022/progress-bar-testing.mjs.map +1 -1
  135. package/fesm2022/progress-bar.mjs +224 -169
  136. package/fesm2022/progress-bar.mjs.map +1 -1
  137. package/fesm2022/progress-spinner-testing.mjs +13 -23
  138. package/fesm2022/progress-spinner-testing.mjs.map +1 -1
  139. package/fesm2022/progress-spinner.mjs +235 -160
  140. package/fesm2022/progress-spinner.mjs.map +1 -1
  141. package/fesm2022/radio-testing.mjs +133 -208
  142. package/fesm2022/radio-testing.mjs.map +1 -1
  143. package/fesm2022/radio.mjs +712 -679
  144. package/fesm2022/radio.mjs.map +1 -1
  145. package/fesm2022/select-testing.mjs +83 -117
  146. package/fesm2022/select-testing.mjs.map +1 -1
  147. package/fesm2022/select.mjs +1116 -1246
  148. package/fesm2022/select.mjs.map +1 -1
  149. package/fesm2022/sidenav-testing.mjs +54 -120
  150. package/fesm2022/sidenav-testing.mjs.map +1 -1
  151. package/fesm2022/sidenav.mjs +1078 -995
  152. package/fesm2022/sidenav.mjs.map +1 -1
  153. package/fesm2022/slide-toggle-testing.mjs +57 -92
  154. package/fesm2022/slide-toggle-testing.mjs.map +1 -1
  155. package/fesm2022/slide-toggle.mjs +369 -279
  156. package/fesm2022/slide-toggle.mjs.map +1 -1
  157. package/fesm2022/slider-testing.mjs +90 -138
  158. package/fesm2022/slider-testing.mjs.map +1 -1
  159. package/fesm2022/slider.mjs +1651 -1716
  160. package/fesm2022/slider.mjs.map +1 -1
  161. package/fesm2022/snack-bar-testing.mjs +40 -87
  162. package/fesm2022/snack-bar-testing.mjs.map +1 -1
  163. package/fesm2022/snack-bar.mjs +763 -714
  164. package/fesm2022/snack-bar.mjs.map +1 -1
  165. package/fesm2022/sort-testing.mjs +45 -66
  166. package/fesm2022/sort-testing.mjs.map +1 -1
  167. package/fesm2022/sort.mjs +419 -344
  168. package/fesm2022/sort.mjs.map +1 -1
  169. package/fesm2022/stepper-testing.mjs +78 -154
  170. package/fesm2022/stepper-testing.mjs.map +1 -1
  171. package/fesm2022/stepper.mjs +790 -498
  172. package/fesm2022/stepper.mjs.map +1 -1
  173. package/fesm2022/table-testing.mjs +120 -213
  174. package/fesm2022/table-testing.mjs.map +1 -1
  175. package/fesm2022/table.mjs +1026 -684
  176. package/fesm2022/table.mjs.map +1 -1
  177. package/fesm2022/tabs-testing.mjs +125 -197
  178. package/fesm2022/tabs-testing.mjs.map +1 -1
  179. package/fesm2022/tabs.mjs +2351 -2028
  180. package/fesm2022/tabs.mjs.map +1 -1
  181. package/fesm2022/timepicker-testing.mjs +113 -172
  182. package/fesm2022/timepicker-testing.mjs.map +1 -1
  183. package/fesm2022/timepicker.mjs +1019 -826
  184. package/fesm2022/timepicker.mjs.map +1 -1
  185. package/fesm2022/toolbar-testing.mjs +16 -27
  186. package/fesm2022/toolbar-testing.mjs.map +1 -1
  187. package/fesm2022/toolbar.mjs +163 -78
  188. package/fesm2022/toolbar.mjs.map +1 -1
  189. package/fesm2022/tooltip-testing.mjs +41 -52
  190. package/fesm2022/tooltip-testing.mjs.map +1 -1
  191. package/fesm2022/tooltip.mjs +36 -10
  192. package/fesm2022/tooltip.mjs.map +1 -1
  193. package/fesm2022/tree-testing.mjs +86 -162
  194. package/fesm2022/tree-testing.mjs.map +1 -1
  195. package/fesm2022/tree.mjs +638 -466
  196. package/fesm2022/tree.mjs.map +1 -1
  197. package/package.json +2 -2
  198. package/schematics/ng-add/index.js +1 -1
  199. package/types/expansion.d.ts +4 -2
  200. package/types/menu-testing.d.ts +2 -0
  201. package/types/select.d.ts +1 -1
  202. package/types/timepicker.d.ts +1 -0
package/fesm2022/core.mjs CHANGED
@@ -24,355 +24,384 @@ import '@angular/cdk/private';
24
24
  import '@angular/cdk/platform';
25
25
  import '@angular/cdk/coercion';
26
26
 
27
- /** Current version of Angular Material. */
28
- const VERSION = new Version('21.0.0-next.9');
27
+ const VERSION = new Version('21.0.0-rc.0');
29
28
 
30
- /**
31
- * Matches strings that have the form of a valid RFC 3339 string
32
- * (https://tools.ietf.org/html/rfc3339). Note that the string may not actually be a valid date
33
- * because the regex will match strings with an out of bounds month, date, etc.
34
- */
35
29
  const ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))?)?$/;
36
- /**
37
- * Matches a time string. Supported formats:
38
- * - {{hours}}:{{minutes}}
39
- * - {{hours}}:{{minutes}}:{{seconds}}
40
- * - {{hours}}:{{minutes}} AM/PM
41
- * - {{hours}}:{{minutes}}:{{seconds}} AM/PM
42
- * - {{hours}}.{{minutes}}
43
- * - {{hours}}.{{minutes}}.{{seconds}}
44
- * - {{hours}}.{{minutes}} AM/PM
45
- * - {{hours}}.{{minutes}}.{{seconds}} AM/PM
46
- */
47
30
  const TIME_REGEX = /^(\d?\d)[:.](\d?\d)(?:[:.](\d?\d))?\s*(AM|PM)?$/i;
48
- /** Creates an array and fills it with values. */
49
31
  function range(length, valueFunction) {
50
- const valuesArray = Array(length);
51
- for (let i = 0; i < length; i++) {
52
- valuesArray[i] = valueFunction(i);
53
- }
54
- return valuesArray;
32
+ const valuesArray = Array(length);
33
+ for (let i = 0; i < length; i++) {
34
+ valuesArray[i] = valueFunction(i);
35
+ }
36
+ return valuesArray;
55
37
  }
56
- /** Adapts the native JS Date for use with cdk-based components that work with dates. */
57
38
  class NativeDateAdapter extends DateAdapter {
58
- /** The injected locale. */
59
- _matDateLocale = inject(MAT_DATE_LOCALE, { optional: true });
60
- constructor() {
61
- super();
62
- const matDateLocale = inject(MAT_DATE_LOCALE, { optional: true });
63
- if (matDateLocale !== undefined) {
64
- this._matDateLocale = matDateLocale;
65
- }
66
- super.setLocale(this._matDateLocale);
67
- }
68
- getYear(date) {
69
- return date.getFullYear();
70
- }
71
- getMonth(date) {
72
- return date.getMonth();
73
- }
74
- getDate(date) {
75
- return date.getDate();
76
- }
77
- getDayOfWeek(date) {
78
- return date.getDay();
79
- }
80
- getMonthNames(style) {
81
- const dtf = new Intl.DateTimeFormat(this.locale, { month: style, timeZone: 'utc' });
82
- return range(12, i => this._format(dtf, new Date(2017, i, 1)));
83
- }
84
- getDateNames() {
85
- const dtf = new Intl.DateTimeFormat(this.locale, { day: 'numeric', timeZone: 'utc' });
86
- return range(31, i => this._format(dtf, new Date(2017, 0, i + 1)));
87
- }
88
- getDayOfWeekNames(style) {
89
- const dtf = new Intl.DateTimeFormat(this.locale, { weekday: style, timeZone: 'utc' });
90
- return range(7, i => this._format(dtf, new Date(2017, 0, i + 1)));
91
- }
92
- getYearName(date) {
93
- const dtf = new Intl.DateTimeFormat(this.locale, { year: 'numeric', timeZone: 'utc' });
94
- return this._format(dtf, date);
95
- }
96
- getFirstDayOfWeek() {
97
- // At the time of writing `Intl.Locale` isn't available
98
- // in the internal types so we need to cast to `any`.
99
- if (typeof Intl !== 'undefined' && Intl.Locale) {
100
- const locale = new Intl.Locale(this.locale);
101
- // Some browsers implement a `getWeekInfo` method while others have a `weekInfo` getter.
102
- // Note that this isn't supported in all browsers so we need to null check it.
103
- const firstDay = (locale.getWeekInfo?.() || locale.weekInfo)?.firstDay ?? 0;
104
- // `weekInfo.firstDay` is a number between 1 and 7 where, starting from Monday,
105
- // whereas our representation is 0 to 6 where 0 is Sunday so we need to normalize it.
106
- return firstDay === 7 ? 0 : firstDay;
107
- }
108
- // Default to Sunday if the browser doesn't provide the week information.
109
- return 0;
110
- }
111
- getNumDaysInMonth(date) {
112
- return this.getDate(this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0));
113
- }
114
- clone(date) {
115
- return new Date(date.getTime());
116
- }
117
- createDate(year, month, date) {
118
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
119
- // Check for invalid month and date (except upper bound on date which we have to check after
120
- // creating the Date).
121
- if (month < 0 || month > 11) {
122
- throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
123
- }
124
- if (date < 1) {
125
- throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
126
- }
127
- }
128
- let result = this._createDateWithOverflow(year, month, date);
129
- // Check that the date wasn't above the upper bound for the month, causing the month to overflow
130
- if (result.getMonth() != month && (typeof ngDevMode === 'undefined' || ngDevMode)) {
131
- throw Error(`Invalid date "${date}" for month with index "${month}".`);
132
- }
133
- return result;
134
- }
135
- today() {
136
- return new Date();
137
- }
138
- parse(value, parseFormat) {
139
- // We have no way using the native JS Date to set the parse format or locale, so we ignore these
140
- // parameters.
141
- if (typeof value == 'number') {
142
- return new Date(value);
143
- }
144
- return value ? new Date(Date.parse(value)) : null;
145
- }
146
- format(date, displayFormat) {
147
- if (!this.isValid(date)) {
148
- throw Error('NativeDateAdapter: Cannot format invalid date.');
149
- }
150
- const dtf = new Intl.DateTimeFormat(this.locale, { ...displayFormat, timeZone: 'utc' });
151
- return this._format(dtf, date);
152
- }
153
- addCalendarYears(date, years) {
154
- return this.addCalendarMonths(date, years * 12);
155
- }
156
- addCalendarMonths(date, months) {
157
- let newDate = this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + months, this.getDate(date));
158
- // It's possible to wind up in the wrong month if the original month has more days than the new
159
- // month. In this case we want to go to the last day of the desired month.
160
- // Note: the additional + 12 % 12 ensures we end up with a positive number, since JS % doesn't
161
- // guarantee this.
162
- if (this.getMonth(newDate) != (((this.getMonth(date) + months) % 12) + 12) % 12) {
163
- newDate = this._createDateWithOverflow(this.getYear(newDate), this.getMonth(newDate), 0);
164
- }
165
- return newDate;
166
- }
167
- addCalendarDays(date, days) {
168
- return this._createDateWithOverflow(this.getYear(date), this.getMonth(date), this.getDate(date) + days);
169
- }
170
- toIso8601(date) {
171
- return [
172
- date.getUTCFullYear(),
173
- this._2digit(date.getUTCMonth() + 1),
174
- this._2digit(date.getUTCDate()),
175
- ].join('-');
176
- }
177
- /**
178
- * Returns the given value if given a valid Date or null. Deserializes valid ISO 8601 strings
179
- * (https://www.ietf.org/rfc/rfc3339.txt) into valid Dates and empty string into null. Returns an
180
- * invalid date for all other values.
181
- */
182
- deserialize(value) {
183
- if (typeof value === 'string') {
184
- if (!value) {
185
- return null;
186
- }
187
- // The `Date` constructor accepts formats other than ISO 8601, so we need to make sure the
188
- // string is the right format first.
189
- if (ISO_8601_REGEX.test(value)) {
190
- let date = new Date(value);
191
- if (this.isValid(date)) {
192
- return date;
193
- }
194
- }
195
- }
196
- return super.deserialize(value);
197
- }
198
- isDateInstance(obj) {
199
- return obj instanceof Date;
200
- }
201
- isValid(date) {
202
- return !isNaN(date.getTime());
203
- }
204
- invalid() {
205
- return new Date(NaN);
206
- }
207
- setTime(target, hours, minutes, seconds) {
208
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
209
- if (!inRange(hours, 0, 23)) {
210
- throw Error(`Invalid hours "${hours}". Hours value must be between 0 and 23.`);
211
- }
212
- if (!inRange(minutes, 0, 59)) {
213
- throw Error(`Invalid minutes "${minutes}". Minutes value must be between 0 and 59.`);
214
- }
215
- if (!inRange(seconds, 0, 59)) {
216
- throw Error(`Invalid seconds "${seconds}". Seconds value must be between 0 and 59.`);
217
- }
218
- }
219
- const clone = this.clone(target);
220
- clone.setHours(hours, minutes, seconds, 0);
221
- return clone;
222
- }
223
- getHours(date) {
224
- return date.getHours();
225
- }
226
- getMinutes(date) {
227
- return date.getMinutes();
228
- }
229
- getSeconds(date) {
230
- return date.getSeconds();
231
- }
232
- parseTime(userValue, parseFormat) {
233
- if (typeof userValue !== 'string') {
234
- return userValue instanceof Date ? new Date(userValue.getTime()) : null;
235
- }
236
- const value = userValue.trim();
237
- if (value.length === 0) {
238
- return null;
239
- }
240
- // Attempt to parse the value directly.
241
- let result = this._parseTimeString(value);
242
- // Some locales add extra characters around the time, but are otherwise parseable
243
- // (e.g. `00:05 ч.` in bg-BG). Try replacing all non-number and non-colon characters.
244
- if (result === null) {
245
- const withoutExtras = value.replace(/[^0-9:(AM|PM)]/gi, '').trim();
246
- if (withoutExtras.length > 0) {
247
- result = this._parseTimeString(withoutExtras);
248
- }
249
- }
250
- return result || this.invalid();
251
- }
252
- addSeconds(date, amount) {
253
- return new Date(date.getTime() + amount * 1000);
254
- }
255
- /** Creates a date but allows the month and date to overflow. */
256
- _createDateWithOverflow(year, month, date) {
257
- // Passing the year to the constructor causes year numbers <100 to be converted to 19xx.
258
- // To work around this we use `setFullYear` and `setHours` instead.
259
- const d = new Date();
260
- d.setFullYear(year, month, date);
261
- d.setHours(0, 0, 0, 0);
262
- return d;
263
- }
264
- /**
265
- * Pads a number to make it two digits.
266
- * @param n The number to pad.
267
- * @returns The padded number.
268
- */
269
- _2digit(n) {
270
- return ('00' + n).slice(-2);
271
- }
272
- /**
273
- * When converting Date object to string, javascript built-in functions may return wrong
274
- * results because it applies its internal DST rules. The DST rules around the world change
275
- * very frequently, and the current valid rule is not always valid in previous years though.
276
- * We work around this problem building a new Date object which has its internal UTC
277
- * representation with the local date and time.
278
- * @param dtf Intl.DateTimeFormat object, containing the desired string format. It must have
279
- * timeZone set to 'utc' to work fine.
280
- * @param date Date from which we want to get the string representation according to dtf
281
- * @returns A Date object with its UTC representation based on the passed in date info
282
- */
283
- _format(dtf, date) {
284
- // Passing the year to the constructor causes year numbers <100 to be converted to 19xx.
285
- // To work around this we use `setUTCFullYear` and `setUTCHours` instead.
286
- const d = new Date();
287
- d.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());
288
- d.setUTCHours(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
289
- return dtf.format(d);
290
- }
291
- /**
292
- * Attempts to parse a time string into a date object. Returns null if it cannot be parsed.
293
- * @param value Time string to parse.
294
- */
295
- _parseTimeString(value) {
296
- // Note: we can technically rely on the browser for the time parsing by generating
297
- // an ISO string and appending the string to the end of it. We don't do it, because
298
- // browsers aren't consistent in what they support. Some examples:
299
- // - Safari doesn't support AM/PM.
300
- // - Firefox produces a valid date object if the time string has overflows (e.g. 12:75) while
301
- // other browsers produce an invalid date.
302
- // - Safari doesn't allow padded numbers.
303
- const parsed = value.toUpperCase().match(TIME_REGEX);
304
- if (parsed) {
305
- let hours = parseInt(parsed[1]);
306
- const minutes = parseInt(parsed[2]);
307
- let seconds = parsed[3] == null ? undefined : parseInt(parsed[3]);
308
- const amPm = parsed[4];
309
- if (hours === 12) {
310
- hours = amPm === 'AM' ? 0 : hours;
311
- }
312
- else if (amPm === 'PM') {
313
- hours += 12;
314
- }
315
- if (inRange(hours, 0, 23) &&
316
- inRange(minutes, 0, 59) &&
317
- (seconds == null || inRange(seconds, 0, 59))) {
318
- return this.setTime(this.today(), hours, minutes, seconds || 0);
319
- }
320
- }
39
+ _matDateLocale = inject(MAT_DATE_LOCALE, {
40
+ optional: true
41
+ });
42
+ constructor() {
43
+ super();
44
+ const matDateLocale = inject(MAT_DATE_LOCALE, {
45
+ optional: true
46
+ });
47
+ if (matDateLocale !== undefined) {
48
+ this._matDateLocale = matDateLocale;
49
+ }
50
+ super.setLocale(this._matDateLocale);
51
+ }
52
+ getYear(date) {
53
+ return date.getFullYear();
54
+ }
55
+ getMonth(date) {
56
+ return date.getMonth();
57
+ }
58
+ getDate(date) {
59
+ return date.getDate();
60
+ }
61
+ getDayOfWeek(date) {
62
+ return date.getDay();
63
+ }
64
+ getMonthNames(style) {
65
+ const dtf = new Intl.DateTimeFormat(this.locale, {
66
+ month: style,
67
+ timeZone: 'utc'
68
+ });
69
+ return range(12, i => this._format(dtf, new Date(2017, i, 1)));
70
+ }
71
+ getDateNames() {
72
+ const dtf = new Intl.DateTimeFormat(this.locale, {
73
+ day: 'numeric',
74
+ timeZone: 'utc'
75
+ });
76
+ return range(31, i => this._format(dtf, new Date(2017, 0, i + 1)));
77
+ }
78
+ getDayOfWeekNames(style) {
79
+ const dtf = new Intl.DateTimeFormat(this.locale, {
80
+ weekday: style,
81
+ timeZone: 'utc'
82
+ });
83
+ return range(7, i => this._format(dtf, new Date(2017, 0, i + 1)));
84
+ }
85
+ getYearName(date) {
86
+ const dtf = new Intl.DateTimeFormat(this.locale, {
87
+ year: 'numeric',
88
+ timeZone: 'utc'
89
+ });
90
+ return this._format(dtf, date);
91
+ }
92
+ getFirstDayOfWeek() {
93
+ if (typeof Intl !== 'undefined' && Intl.Locale) {
94
+ const locale = new Intl.Locale(this.locale);
95
+ const firstDay = (locale.getWeekInfo?.() || locale.weekInfo)?.firstDay ?? 0;
96
+ return firstDay === 7 ? 0 : firstDay;
97
+ }
98
+ return 0;
99
+ }
100
+ getNumDaysInMonth(date) {
101
+ return this.getDate(this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0));
102
+ }
103
+ clone(date) {
104
+ return new Date(date.getTime());
105
+ }
106
+ createDate(year, month, date) {
107
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
108
+ if (month < 0 || month > 11) {
109
+ throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
110
+ }
111
+ if (date < 1) {
112
+ throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
113
+ }
114
+ }
115
+ let result = this._createDateWithOverflow(year, month, date);
116
+ if (result.getMonth() != month && (typeof ngDevMode === 'undefined' || ngDevMode)) {
117
+ throw Error(`Invalid date "${date}" for month with index "${month}".`);
118
+ }
119
+ return result;
120
+ }
121
+ today() {
122
+ return new Date();
123
+ }
124
+ parse(value, parseFormat) {
125
+ if (typeof value == 'number') {
126
+ return new Date(value);
127
+ }
128
+ return value ? new Date(Date.parse(value)) : null;
129
+ }
130
+ format(date, displayFormat) {
131
+ if (!this.isValid(date)) {
132
+ throw Error('NativeDateAdapter: Cannot format invalid date.');
133
+ }
134
+ const dtf = new Intl.DateTimeFormat(this.locale, {
135
+ ...displayFormat,
136
+ timeZone: 'utc'
137
+ });
138
+ return this._format(dtf, date);
139
+ }
140
+ addCalendarYears(date, years) {
141
+ return this.addCalendarMonths(date, years * 12);
142
+ }
143
+ addCalendarMonths(date, months) {
144
+ let newDate = this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + months, this.getDate(date));
145
+ if (this.getMonth(newDate) != ((this.getMonth(date) + months) % 12 + 12) % 12) {
146
+ newDate = this._createDateWithOverflow(this.getYear(newDate), this.getMonth(newDate), 0);
147
+ }
148
+ return newDate;
149
+ }
150
+ addCalendarDays(date, days) {
151
+ return this._createDateWithOverflow(this.getYear(date), this.getMonth(date), this.getDate(date) + days);
152
+ }
153
+ toIso8601(date) {
154
+ return [date.getUTCFullYear(), this._2digit(date.getUTCMonth() + 1), this._2digit(date.getUTCDate())].join('-');
155
+ }
156
+ deserialize(value) {
157
+ if (typeof value === 'string') {
158
+ if (!value) {
321
159
  return null;
322
- }
323
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: NativeDateAdapter, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
324
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: NativeDateAdapter });
160
+ }
161
+ if (ISO_8601_REGEX.test(value)) {
162
+ let date = new Date(value);
163
+ if (this.isValid(date)) {
164
+ return date;
165
+ }
166
+ }
167
+ }
168
+ return super.deserialize(value);
169
+ }
170
+ isDateInstance(obj) {
171
+ return obj instanceof Date;
172
+ }
173
+ isValid(date) {
174
+ return !isNaN(date.getTime());
175
+ }
176
+ invalid() {
177
+ return new Date(NaN);
178
+ }
179
+ setTime(target, hours, minutes, seconds) {
180
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
181
+ if (!inRange(hours, 0, 23)) {
182
+ throw Error(`Invalid hours "${hours}". Hours value must be between 0 and 23.`);
183
+ }
184
+ if (!inRange(minutes, 0, 59)) {
185
+ throw Error(`Invalid minutes "${minutes}". Minutes value must be between 0 and 59.`);
186
+ }
187
+ if (!inRange(seconds, 0, 59)) {
188
+ throw Error(`Invalid seconds "${seconds}". Seconds value must be between 0 and 59.`);
189
+ }
190
+ }
191
+ const clone = this.clone(target);
192
+ clone.setHours(hours, minutes, seconds, 0);
193
+ return clone;
194
+ }
195
+ getHours(date) {
196
+ return date.getHours();
197
+ }
198
+ getMinutes(date) {
199
+ return date.getMinutes();
200
+ }
201
+ getSeconds(date) {
202
+ return date.getSeconds();
203
+ }
204
+ parseTime(userValue, parseFormat) {
205
+ if (typeof userValue !== 'string') {
206
+ return userValue instanceof Date ? new Date(userValue.getTime()) : null;
207
+ }
208
+ const value = userValue.trim();
209
+ if (value.length === 0) {
210
+ return null;
211
+ }
212
+ let result = this._parseTimeString(value);
213
+ if (result === null) {
214
+ const withoutExtras = value.replace(/[^0-9:(AM|PM)]/gi, '').trim();
215
+ if (withoutExtras.length > 0) {
216
+ result = this._parseTimeString(withoutExtras);
217
+ }
218
+ }
219
+ return result || this.invalid();
220
+ }
221
+ addSeconds(date, amount) {
222
+ return new Date(date.getTime() + amount * 1000);
223
+ }
224
+ _createDateWithOverflow(year, month, date) {
225
+ const d = new Date();
226
+ d.setFullYear(year, month, date);
227
+ d.setHours(0, 0, 0, 0);
228
+ return d;
229
+ }
230
+ _2digit(n) {
231
+ return ('00' + n).slice(-2);
232
+ }
233
+ _format(dtf, date) {
234
+ const d = new Date();
235
+ d.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());
236
+ d.setUTCHours(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
237
+ return dtf.format(d);
238
+ }
239
+ _parseTimeString(value) {
240
+ const parsed = value.toUpperCase().match(TIME_REGEX);
241
+ if (parsed) {
242
+ let hours = parseInt(parsed[1]);
243
+ const minutes = parseInt(parsed[2]);
244
+ let seconds = parsed[3] == null ? undefined : parseInt(parsed[3]);
245
+ const amPm = parsed[4];
246
+ if (hours === 12) {
247
+ hours = amPm === 'AM' ? 0 : hours;
248
+ } else if (amPm === 'PM') {
249
+ hours += 12;
250
+ }
251
+ if (inRange(hours, 0, 23) && inRange(minutes, 0, 59) && (seconds == null || inRange(seconds, 0, 59))) {
252
+ return this.setTime(this.today(), hours, minutes, seconds || 0);
253
+ }
254
+ }
255
+ return null;
256
+ }
257
+ static ɵfac = i0.ɵɵngDeclareFactory({
258
+ minVersion: "12.0.0",
259
+ version: "20.2.0-next.2",
260
+ ngImport: i0,
261
+ type: NativeDateAdapter,
262
+ deps: [],
263
+ target: i0.ɵɵFactoryTarget.Injectable
264
+ });
265
+ static ɵprov = i0.ɵɵngDeclareInjectable({
266
+ minVersion: "12.0.0",
267
+ version: "20.2.0-next.2",
268
+ ngImport: i0,
269
+ type: NativeDateAdapter
270
+ });
325
271
  }
326
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: NativeDateAdapter, decorators: [{
327
- type: Injectable
328
- }], ctorParameters: () => [] });
329
- /** Checks whether a number is within a certain range. */
272
+ i0.ɵɵngDeclareClassMetadata({
273
+ minVersion: "12.0.0",
274
+ version: "20.2.0-next.2",
275
+ ngImport: i0,
276
+ type: NativeDateAdapter,
277
+ decorators: [{
278
+ type: Injectable
279
+ }],
280
+ ctorParameters: () => []
281
+ });
330
282
  function inRange(value, min, max) {
331
- return !isNaN(value) && value >= min && value <= max;
283
+ return !isNaN(value) && value >= min && value <= max;
332
284
  }
333
285
 
334
286
  const MAT_NATIVE_DATE_FORMATS = {
335
- parse: {
336
- dateInput: null,
337
- timeInput: null,
287
+ parse: {
288
+ dateInput: null,
289
+ timeInput: null
290
+ },
291
+ display: {
292
+ dateInput: {
293
+ year: 'numeric',
294
+ month: 'numeric',
295
+ day: 'numeric'
296
+ },
297
+ timeInput: {
298
+ hour: 'numeric',
299
+ minute: 'numeric'
338
300
  },
339
- display: {
340
- dateInput: { year: 'numeric', month: 'numeric', day: 'numeric' },
341
- timeInput: { hour: 'numeric', minute: 'numeric' },
342
- monthYearLabel: { year: 'numeric', month: 'short' },
343
- dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
344
- monthYearA11yLabel: { year: 'numeric', month: 'long' },
345
- timeOptionLabel: { hour: 'numeric', minute: 'numeric' },
301
+ monthYearLabel: {
302
+ year: 'numeric',
303
+ month: 'short'
346
304
  },
305
+ dateA11yLabel: {
306
+ year: 'numeric',
307
+ month: 'long',
308
+ day: 'numeric'
309
+ },
310
+ monthYearA11yLabel: {
311
+ year: 'numeric',
312
+ month: 'long'
313
+ },
314
+ timeOptionLabel: {
315
+ hour: 'numeric',
316
+ minute: 'numeric'
317
+ }
318
+ }
347
319
  };
348
320
 
349
321
  class NativeDateModule {
350
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: NativeDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
351
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.2.0-next.2", ngImport: i0, type: NativeDateModule });
352
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: NativeDateModule, providers: [{ provide: DateAdapter, useClass: NativeDateAdapter }] });
322
+ static ɵfac = i0.ɵɵngDeclareFactory({
323
+ minVersion: "12.0.0",
324
+ version: "20.2.0-next.2",
325
+ ngImport: i0,
326
+ type: NativeDateModule,
327
+ deps: [],
328
+ target: i0.ɵɵFactoryTarget.NgModule
329
+ });
330
+ static ɵmod = i0.ɵɵngDeclareNgModule({
331
+ minVersion: "14.0.0",
332
+ version: "20.2.0-next.2",
333
+ ngImport: i0,
334
+ type: NativeDateModule
335
+ });
336
+ static ɵinj = i0.ɵɵngDeclareInjector({
337
+ minVersion: "12.0.0",
338
+ version: "20.2.0-next.2",
339
+ ngImport: i0,
340
+ type: NativeDateModule,
341
+ providers: [{
342
+ provide: DateAdapter,
343
+ useClass: NativeDateAdapter
344
+ }]
345
+ });
353
346
  }
354
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: NativeDateModule, decorators: [{
355
- type: NgModule,
356
- args: [{
357
- providers: [{ provide: DateAdapter, useClass: NativeDateAdapter }],
358
- }]
359
- }] });
347
+ i0.ɵɵngDeclareClassMetadata({
348
+ minVersion: "12.0.0",
349
+ version: "20.2.0-next.2",
350
+ ngImport: i0,
351
+ type: NativeDateModule,
352
+ decorators: [{
353
+ type: NgModule,
354
+ args: [{
355
+ providers: [{
356
+ provide: DateAdapter,
357
+ useClass: NativeDateAdapter
358
+ }]
359
+ }]
360
+ }]
361
+ });
360
362
  class MatNativeDateModule {
361
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: MatNativeDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
362
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.2.0-next.2", ngImport: i0, type: MatNativeDateModule });
363
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: MatNativeDateModule, providers: [provideNativeDateAdapter()] });
363
+ static ɵfac = i0.ɵɵngDeclareFactory({
364
+ minVersion: "12.0.0",
365
+ version: "20.2.0-next.2",
366
+ ngImport: i0,
367
+ type: MatNativeDateModule,
368
+ deps: [],
369
+ target: i0.ɵɵFactoryTarget.NgModule
370
+ });
371
+ static ɵmod = i0.ɵɵngDeclareNgModule({
372
+ minVersion: "14.0.0",
373
+ version: "20.2.0-next.2",
374
+ ngImport: i0,
375
+ type: MatNativeDateModule
376
+ });
377
+ static ɵinj = i0.ɵɵngDeclareInjector({
378
+ minVersion: "12.0.0",
379
+ version: "20.2.0-next.2",
380
+ ngImport: i0,
381
+ type: MatNativeDateModule,
382
+ providers: [provideNativeDateAdapter()]
383
+ });
364
384
  }
365
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: MatNativeDateModule, decorators: [{
366
- type: NgModule,
367
- args: [{
368
- providers: [provideNativeDateAdapter()],
369
- }]
370
- }] });
385
+ i0.ɵɵngDeclareClassMetadata({
386
+ minVersion: "12.0.0",
387
+ version: "20.2.0-next.2",
388
+ ngImport: i0,
389
+ type: MatNativeDateModule,
390
+ decorators: [{
391
+ type: NgModule,
392
+ args: [{
393
+ providers: [provideNativeDateAdapter()]
394
+ }]
395
+ }]
396
+ });
371
397
  function provideNativeDateAdapter(formats = MAT_NATIVE_DATE_FORMATS) {
372
- return [
373
- { provide: DateAdapter, useClass: NativeDateAdapter },
374
- { provide: MAT_DATE_FORMATS, useValue: formats },
375
- ];
398
+ return [{
399
+ provide: DateAdapter,
400
+ useClass: NativeDateAdapter
401
+ }, {
402
+ provide: MAT_DATE_FORMATS,
403
+ useValue: formats
404
+ }];
376
405
  }
377
406
 
378
407
  export { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MAT_NATIVE_DATE_FORMATS, MatNativeDateModule, NativeDateAdapter, NativeDateModule, VERSION, provideNativeDateAdapter };