core.mjs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. export { _ as _MatInternalFormField } from './internal-form-field-grv62mCZ.mjs';
  2. import * as i0 from '@angular/core';
  3. import { Version, inject, Injectable, NgModule } from '@angular/core';
  4. export { a as MATERIAL_SANITY_CHECKS, M as MatCommonModule } from './common-module-WayjW0Pb.mjs';
  5. export { _ as _ErrorStateTracker } from './error-state-Dtb1IHM-.mjs';
  6. import { D as DateAdapter, M as MAT_DATE_LOCALE, a as MAT_DATE_FORMATS } from './date-formats-K6TQue-Y.mjs';
  7. export { b as MAT_DATE_LOCALE_FACTORY } from './date-formats-K6TQue-Y.mjs';
  8. export { E as ErrorStateMatcher, S as ShowOnDirtyErrorStateMatcher } from './error-options-Dm2JJUbF.mjs';
  9. export { _ as _StructuralStylesLoader } from './structural-styles-BQUT6wsL.mjs';
  10. export { M as MatLine, a as MatLineModule, s as setLines } from './line-Bm3zUbBF.mjs';
  11. export { d as MAT_OPTGROUP, c as MAT_OPTION_PARENT_COMPONENT, a as MatOptgroup, M as MatOption, e as MatOptionSelectionChange, _ as _countGroupLabelsBeforeOption, b as _getOptionScrollPosition } from './option-ChV6uQgD.mjs';
  12. export { M as MatOptionModule } from './index-DOxJc1m4.mjs';
  13. export { M as MatRippleLoader } from './ripple-loader-Ce3DAhPW.mjs';
  14. export { a as MAT_RIPPLE_GLOBAL_OPTIONS, M as MatRipple, c as RippleRef, R as RippleRenderer, b as RippleState, d as defaultRippleAnimationConfig } from './ripple-BT3tzh6F.mjs';
  15. export { M as MatRippleModule } from './index-SYVYjXwK.mjs';
  16. export { M as MatPseudoCheckbox } from './pseudo-checkbox-CJ7seqQH.mjs';
  17. export { M as MatPseudoCheckboxModule } from './pseudo-checkbox-module-CAX2sutq.mjs';
  18. import '@angular/cdk/a11y';
  19. import '@angular/cdk/bidi';
  20. import 'rxjs';
  21. import 'rxjs/operators';
  22. import '@angular/cdk/keycodes';
  23. import '@angular/cdk/private';
  24. import '@angular/common';
  25. import '@angular/cdk/platform';
  26. import '@angular/cdk/coercion';
  27. /** Current version of Angular Material. */
  28. const VERSION = new Version('19.2.17');
  29. /**
  30. * @deprecated No longer used, will be removed.
  31. * @breaking-change 21.0.0
  32. * @docs-private
  33. */
  34. class AnimationCurves {
  35. static STANDARD_CURVE = 'cubic-bezier(0.4,0.0,0.2,1)';
  36. static DECELERATION_CURVE = 'cubic-bezier(0.0,0.0,0.2,1)';
  37. static ACCELERATION_CURVE = 'cubic-bezier(0.4,0.0,1,1)';
  38. static SHARP_CURVE = 'cubic-bezier(0.4,0.0,0.6,1)';
  39. }
  40. /**
  41. * @deprecated No longer used, will be removed.
  42. * @breaking-change 21.0.0
  43. * @docs-private
  44. */
  45. class AnimationDurations {
  46. static COMPLEX = '375ms';
  47. static ENTERING = '225ms';
  48. static EXITING = '195ms';
  49. }
  50. /**
  51. * Matches strings that have the form of a valid RFC 3339 string
  52. * (https://tools.ietf.org/html/rfc3339). Note that the string may not actually be a valid date
  53. * because the regex will match strings with an out of bounds month, date, etc.
  54. */
  55. const ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))?)?$/;
  56. /**
  57. * Matches a time string. Supported formats:
  58. * - {{hours}}:{{minutes}}
  59. * - {{hours}}:{{minutes}}:{{seconds}}
  60. * - {{hours}}:{{minutes}} AM/PM
  61. * - {{hours}}:{{minutes}}:{{seconds}} AM/PM
  62. * - {{hours}}.{{minutes}}
  63. * - {{hours}}.{{minutes}}.{{seconds}}
  64. * - {{hours}}.{{minutes}} AM/PM
  65. * - {{hours}}.{{minutes}}.{{seconds}} AM/PM
  66. */
  67. const TIME_REGEX = /^(\d?\d)[:.](\d?\d)(?:[:.](\d?\d))?\s*(AM|PM)?$/i;
  68. /** Creates an array and fills it with values. */
  69. function range(length, valueFunction) {
  70. const valuesArray = Array(length);
  71. for (let i = 0; i < length; i++) {
  72. valuesArray[i] = valueFunction(i);
  73. }
  74. return valuesArray;
  75. }
  76. /** Adapts the native JS Date for use with cdk-based components that work with dates. */
  77. class NativeDateAdapter extends DateAdapter {
  78. /**
  79. * @deprecated No longer being used. To be removed.
  80. * @breaking-change 14.0.0
  81. */
  82. useUtcForDisplay = false;
  83. /** The injected locale. */
  84. _matDateLocale = inject(MAT_DATE_LOCALE, { optional: true });
  85. constructor() {
  86. super();
  87. const matDateLocale = inject(MAT_DATE_LOCALE, { optional: true });
  88. if (matDateLocale !== undefined) {
  89. this._matDateLocale = matDateLocale;
  90. }
  91. super.setLocale(this._matDateLocale);
  92. }
  93. getYear(date) {
  94. return date.getFullYear();
  95. }
  96. getMonth(date) {
  97. return date.getMonth();
  98. }
  99. getDate(date) {
  100. return date.getDate();
  101. }
  102. getDayOfWeek(date) {
  103. return date.getDay();
  104. }
  105. getMonthNames(style) {
  106. const dtf = new Intl.DateTimeFormat(this.locale, { month: style, timeZone: 'utc' });
  107. return range(12, i => this._format(dtf, new Date(2017, i, 1)));
  108. }
  109. getDateNames() {
  110. const dtf = new Intl.DateTimeFormat(this.locale, { day: 'numeric', timeZone: 'utc' });
  111. return range(31, i => this._format(dtf, new Date(2017, 0, i + 1)));
  112. }
  113. getDayOfWeekNames(style) {
  114. const dtf = new Intl.DateTimeFormat(this.locale, { weekday: style, timeZone: 'utc' });
  115. return range(7, i => this._format(dtf, new Date(2017, 0, i + 1)));
  116. }
  117. getYearName(date) {
  118. const dtf = new Intl.DateTimeFormat(this.locale, { year: 'numeric', timeZone: 'utc' });
  119. return this._format(dtf, date);
  120. }
  121. getFirstDayOfWeek() {
  122. // At the time of writing `Intl.Locale` isn't available
  123. // in the internal types so we need to cast to `any`.
  124. if (typeof Intl !== 'undefined' && Intl.Locale) {
  125. const locale = new Intl.Locale(this.locale);
  126. // Some browsers implement a `getWeekInfo` method while others have a `weekInfo` getter.
  127. // Note that this isn't supported in all browsers so we need to null check it.
  128. const firstDay = (locale.getWeekInfo?.() || locale.weekInfo)?.firstDay ?? 0;
  129. // `weekInfo.firstDay` is a number between 1 and 7 where, starting from Monday,
  130. // whereas our representation is 0 to 6 where 0 is Sunday so we need to normalize it.
  131. return firstDay === 7 ? 0 : firstDay;
  132. }
  133. // Default to Sunday if the browser doesn't provide the week information.
  134. return 0;
  135. }
  136. getNumDaysInMonth(date) {
  137. return this.getDate(this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0));
  138. }
  139. clone(date) {
  140. return new Date(date.getTime());
  141. }
  142. createDate(year, month, date) {
  143. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  144. // Check for invalid month and date (except upper bound on date which we have to check after
  145. // creating the Date).
  146. if (month < 0 || month > 11) {
  147. throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
  148. }
  149. if (date < 1) {
  150. throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
  151. }
  152. }
  153. let result = this._createDateWithOverflow(year, month, date);
  154. // Check that the date wasn't above the upper bound for the month, causing the month to overflow
  155. if (result.getMonth() != month && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  156. throw Error(`Invalid date "${date}" for month with index "${month}".`);
  157. }
  158. return result;
  159. }
  160. today() {
  161. return new Date();
  162. }
  163. parse(value, parseFormat) {
  164. // We have no way using the native JS Date to set the parse format or locale, so we ignore these
  165. // parameters.
  166. if (typeof value == 'number') {
  167. return new Date(value);
  168. }
  169. return value ? new Date(Date.parse(value)) : null;
  170. }
  171. format(date, displayFormat) {
  172. if (!this.isValid(date)) {
  173. throw Error('NativeDateAdapter: Cannot format invalid date.');
  174. }
  175. const dtf = new Intl.DateTimeFormat(this.locale, { ...displayFormat, timeZone: 'utc' });
  176. return this._format(dtf, date);
  177. }
  178. addCalendarYears(date, years) {
  179. return this.addCalendarMonths(date, years * 12);
  180. }
  181. addCalendarMonths(date, months) {
  182. let newDate = this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + months, this.getDate(date));
  183. // It's possible to wind up in the wrong month if the original month has more days than the new
  184. // month. In this case we want to go to the last day of the desired month.
  185. // Note: the additional + 12 % 12 ensures we end up with a positive number, since JS % doesn't
  186. // guarantee this.
  187. if (this.getMonth(newDate) != (((this.getMonth(date) + months) % 12) + 12) % 12) {
  188. newDate = this._createDateWithOverflow(this.getYear(newDate), this.getMonth(newDate), 0);
  189. }
  190. return newDate;
  191. }
  192. addCalendarDays(date, days) {
  193. return this._createDateWithOverflow(this.getYear(date), this.getMonth(date), this.getDate(date) + days);
  194. }
  195. toIso8601(date) {
  196. return [
  197. date.getUTCFullYear(),
  198. this._2digit(date.getUTCMonth() + 1),
  199. this._2digit(date.getUTCDate()),
  200. ].join('-');
  201. }
  202. /**
  203. * Returns the given value if given a valid Date or null. Deserializes valid ISO 8601 strings
  204. * (https://www.ietf.org/rfc/rfc3339.txt) into valid Dates and empty string into null. Returns an
  205. * invalid date for all other values.
  206. */
  207. deserialize(value) {
  208. if (typeof value === 'string') {
  209. if (!value) {
  210. return null;
  211. }
  212. // The `Date` constructor accepts formats other than ISO 8601, so we need to make sure the
  213. // string is the right format first.
  214. if (ISO_8601_REGEX.test(value)) {
  215. let date = new Date(value);
  216. if (this.isValid(date)) {
  217. return date;
  218. }
  219. }
  220. }
  221. return super.deserialize(value);
  222. }
  223. isDateInstance(obj) {
  224. return obj instanceof Date;
  225. }
  226. isValid(date) {
  227. return !isNaN(date.getTime());
  228. }
  229. invalid() {
  230. return new Date(NaN);
  231. }
  232. setTime(target, hours, minutes, seconds) {
  233. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  234. if (!inRange(hours, 0, 23)) {
  235. throw Error(`Invalid hours "${hours}". Hours value must be between 0 and 23.`);
  236. }
  237. if (!inRange(minutes, 0, 59)) {
  238. throw Error(`Invalid minutes "${minutes}". Minutes value must be between 0 and 59.`);
  239. }
  240. if (!inRange(seconds, 0, 59)) {
  241. throw Error(`Invalid seconds "${seconds}". Seconds value must be between 0 and 59.`);
  242. }
  243. }
  244. const clone = this.clone(target);
  245. clone.setHours(hours, minutes, seconds, 0);
  246. return clone;
  247. }
  248. getHours(date) {
  249. return date.getHours();
  250. }
  251. getMinutes(date) {
  252. return date.getMinutes();
  253. }
  254. getSeconds(date) {
  255. return date.getSeconds();
  256. }
  257. parseTime(userValue, parseFormat) {
  258. if (typeof userValue !== 'string') {
  259. return userValue instanceof Date ? new Date(userValue.getTime()) : null;
  260. }
  261. const value = userValue.trim();
  262. if (value.length === 0) {
  263. return null;
  264. }
  265. // Attempt to parse the value directly.
  266. let result = this._parseTimeString(value);
  267. // Some locales add extra characters around the time, but are otherwise parseable
  268. // (e.g. `00:05 ч.` in bg-BG). Try replacing all non-number and non-colon characters.
  269. if (result === null) {
  270. const withoutExtras = value.replace(/[^0-9:(AM|PM)]/gi, '').trim();
  271. if (withoutExtras.length > 0) {
  272. result = this._parseTimeString(withoutExtras);
  273. }
  274. }
  275. return result || this.invalid();
  276. }
  277. addSeconds(date, amount) {
  278. return new Date(date.getTime() + amount * 1000);
  279. }
  280. /** Creates a date but allows the month and date to overflow. */
  281. _createDateWithOverflow(year, month, date) {
  282. // Passing the year to the constructor causes year numbers <100 to be converted to 19xx.
  283. // To work around this we use `setFullYear` and `setHours` instead.
  284. const d = new Date();
  285. d.setFullYear(year, month, date);
  286. d.setHours(0, 0, 0, 0);
  287. return d;
  288. }
  289. /**
  290. * Pads a number to make it two digits.
  291. * @param n The number to pad.
  292. * @returns The padded number.
  293. */
  294. _2digit(n) {
  295. return ('00' + n).slice(-2);
  296. }
  297. /**
  298. * When converting Date object to string, javascript built-in functions may return wrong
  299. * results because it applies its internal DST rules. The DST rules around the world change
  300. * very frequently, and the current valid rule is not always valid in previous years though.
  301. * We work around this problem building a new Date object which has its internal UTC
  302. * representation with the local date and time.
  303. * @param dtf Intl.DateTimeFormat object, containing the desired string format. It must have
  304. * timeZone set to 'utc' to work fine.
  305. * @param date Date from which we want to get the string representation according to dtf
  306. * @returns A Date object with its UTC representation based on the passed in date info
  307. */
  308. _format(dtf, date) {
  309. // Passing the year to the constructor causes year numbers <100 to be converted to 19xx.
  310. // To work around this we use `setUTCFullYear` and `setUTCHours` instead.
  311. const d = new Date();
  312. d.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  313. d.setUTCHours(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
  314. return dtf.format(d);
  315. }
  316. /**
  317. * Attempts to parse a time string into a date object. Returns null if it cannot be parsed.
  318. * @param value Time string to parse.
  319. */
  320. _parseTimeString(value) {
  321. // Note: we can technically rely on the browser for the time parsing by generating
  322. // an ISO string and appending the string to the end of it. We don't do it, because
  323. // browsers aren't consistent in what they support. Some examples:
  324. // - Safari doesn't support AM/PM.
  325. // - Firefox produces a valid date object if the time string has overflows (e.g. 12:75) while
  326. // other browsers produce an invalid date.
  327. // - Safari doesn't allow padded numbers.
  328. const parsed = value.toUpperCase().match(TIME_REGEX);
  329. if (parsed) {
  330. let hours = parseInt(parsed[1]);
  331. const minutes = parseInt(parsed[2]);
  332. let seconds = parsed[3] == null ? undefined : parseInt(parsed[3]);
  333. const amPm = parsed[4];
  334. if (hours === 12) {
  335. hours = amPm === 'AM' ? 0 : hours;
  336. }
  337. else if (amPm === 'PM') {
  338. hours += 12;
  339. }
  340. if (inRange(hours, 0, 23) &&
  341. inRange(minutes, 0, 59) &&
  342. (seconds == null || inRange(seconds, 0, 59))) {
  343. return this.setTime(this.today(), hours, minutes, seconds || 0);
  344. }
  345. }
  346. return null;
  347. }
  348. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NativeDateAdapter, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  349. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NativeDateAdapter });
  350. }
  351. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NativeDateAdapter, decorators: [{
  352. type: Injectable
  353. }], ctorParameters: () => [] });
  354. /** Checks whether a number is within a certain range. */
  355. function inRange(value, min, max) {
  356. return !isNaN(value) && value >= min && value <= max;
  357. }
  358. const MAT_NATIVE_DATE_FORMATS = {
  359. parse: {
  360. dateInput: null,
  361. timeInput: null,
  362. },
  363. display: {
  364. dateInput: { year: 'numeric', month: 'numeric', day: 'numeric' },
  365. timeInput: { hour: 'numeric', minute: 'numeric' },
  366. monthYearLabel: { year: 'numeric', month: 'short' },
  367. dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
  368. monthYearA11yLabel: { year: 'numeric', month: 'long' },
  369. timeOptionLabel: { hour: 'numeric', minute: 'numeric' },
  370. },
  371. };
  372. class NativeDateModule {
  373. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NativeDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  374. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.6", ngImport: i0, type: NativeDateModule });
  375. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NativeDateModule, providers: [{ provide: DateAdapter, useClass: NativeDateAdapter }] });
  376. }
  377. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NativeDateModule, decorators: [{
  378. type: NgModule,
  379. args: [{
  380. providers: [{ provide: DateAdapter, useClass: NativeDateAdapter }],
  381. }]
  382. }] });
  383. class MatNativeDateModule {
  384. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatNativeDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  385. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.6", ngImport: i0, type: MatNativeDateModule });
  386. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatNativeDateModule, providers: [provideNativeDateAdapter()] });
  387. }
  388. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatNativeDateModule, decorators: [{
  389. type: NgModule,
  390. args: [{
  391. providers: [provideNativeDateAdapter()],
  392. }]
  393. }] });
  394. function provideNativeDateAdapter(formats = MAT_NATIVE_DATE_FORMATS) {
  395. return [
  396. { provide: DateAdapter, useClass: NativeDateAdapter },
  397. { provide: MAT_DATE_FORMATS, useValue: formats },
  398. ];
  399. }
  400. export { AnimationCurves, AnimationDurations, DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MAT_NATIVE_DATE_FORMATS, MatNativeDateModule, NativeDateAdapter, NativeDateModule, VERSION, provideNativeDateAdapter };
  401. //# sourceMappingURL=core.mjs.map