UNPKG

@telekom/scale-components

Version:

Scale is the digital design system for Telekom products and experiences.

1,261 lines (1,167 loc) 41.5 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-a0ea3d79.js'); const index$1 = require('./index-53f5a5fc.js'); const statusNote = require('./status-note-dceee5a3.js'); function toInteger(dirtyNumber) { if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) { return NaN; } var number = Number(dirtyNumber); if (isNaN(number)) { return number; } return number < 0 ? Math.ceil(number) : Math.floor(number); } function requiredArgs(required, args) { if (args.length < required) { throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present'); } } /** * @name toDate * @category Common Helpers * @summary Convert the given argument to an instance of Date. * * @description * Convert the given argument to an instance of Date. * * If the argument is an instance of Date, the function returns its clone. * * If the argument is a number, it is treated as a timestamp. * * If the argument is none of the above, the function returns Invalid Date. * * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`. * * @param {Date|Number} argument - the value to convert * @returns {Date} the parsed date in the local time zone * @throws {TypeError} 1 argument required * * @example * // Clone the date: * const result = toDate(new Date(2014, 1, 11, 11, 30, 30)) * //=> Tue Feb 11 2014 11:30:30 * * @example * // Convert the timestamp to date: * const result = toDate(1392098430000) * //=> Tue Feb 11 2014 11:30:30 */ function toDate(argument) { requiredArgs(1, arguments); var argStr = Object.prototype.toString.call(argument); // Clone the date if (argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]') { // Prevent the date to lose the milliseconds when passed to new Date() in IE10 return new Date(argument.getTime()); } else if (typeof argument === 'number' || argStr === '[object Number]') { return new Date(argument); } else { if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') { // eslint-disable-next-line no-console console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console console.warn(new Error().stack); } return new Date(NaN); } } /** * @name addMilliseconds * @category Millisecond Helpers * @summary Add the specified number of milliseconds to the given date. * * @description * Add the specified number of milliseconds to the given date. * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * * @param {Date|Number} date - the date to be changed * @param {Number} amount - the amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. * @returns {Date} the new date with the milliseconds added * @throws {TypeError} 2 arguments required * * @example * // Add 750 milliseconds to 10 July 2014 12:45:30.000: * var result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750) * //=> Thu Jul 10 2014 12:45:30.750 */ function addMilliseconds(dirtyDate, dirtyAmount) { requiredArgs(2, arguments); var timestamp = toDate(dirtyDate).getTime(); var amount = toInteger(dirtyAmount); return new Date(timestamp + amount); } var MILLISECONDS_IN_MINUTE = 60000; function getDateMillisecondsPart(date) { return date.getTime() % MILLISECONDS_IN_MINUTE; } /** * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds. * They usually appear for dates that denote time before the timezones were introduced * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891 * and GMT+01:00:00 after that date) * * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above, * which would lead to incorrect calculations. * * This function returns the timezone offset in milliseconds that takes seconds in account. */ function getTimezoneOffsetInMilliseconds(dirtyDate) { var date = new Date(dirtyDate.getTime()); var baseTimezoneOffset = Math.ceil(date.getTimezoneOffset()); date.setSeconds(0, 0); var hasNegativeUTCOffset = baseTimezoneOffset > 0; var millisecondsPartOfTimezoneOffset = hasNegativeUTCOffset ? (MILLISECONDS_IN_MINUTE + getDateMillisecondsPart(date)) % MILLISECONDS_IN_MINUTE : getDateMillisecondsPart(date); return baseTimezoneOffset * MILLISECONDS_IN_MINUTE + millisecondsPartOfTimezoneOffset; } /** * @name addSeconds * @category Second Helpers * @summary Add the specified number of seconds to the given date. * * @description * Add the specified number of seconds to the given date. * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * * @param {Date|Number} date - the date to be changed * @param {Number} amount - the amount of seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. * @returns {Date} the new date with the seconds added * @throws {TypeError} 2 arguments required * * @example * // Add 30 seconds to 10 July 2014 12:45:00: * var result = addSeconds(new Date(2014, 6, 10, 12, 45, 0), 30) * //=> Thu Jul 10 2014 12:45:30 */ function addSeconds(dirtyDate, dirtyAmount) { requiredArgs(2, arguments); var amount = toInteger(dirtyAmount); return addMilliseconds(dirtyDate, amount * 1000); } /** * @name compareAsc * @category Common Helpers * @summary Compare the two dates and return -1, 0 or 1. * * @description * Compare the two dates and return 1 if the first date is after the second, * -1 if the first date is before the second or 0 if dates are equal. * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * * @param {Date|Number} dateLeft - the first date to compare * @param {Date|Number} dateRight - the second date to compare * @returns {Number} the result of the comparison * @throws {TypeError} 2 arguments required * * @example * // Compare 11 February 1987 and 10 July 1989: * var result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10)) * //=> -1 * * @example * // Sort the array of dates: * var result = [ * new Date(1995, 6, 2), * new Date(1987, 1, 11), * new Date(1989, 6, 10) * ].sort(compareAsc) * //=> [ * // Wed Feb 11 1987 00:00:00, * // Mon Jul 10 1989 00:00:00, * // Sun Jul 02 1995 00:00:00 * // ] */ function compareAsc(dirtyDateLeft, dirtyDateRight) { requiredArgs(2, arguments); var dateLeft = toDate(dirtyDateLeft); var dateRight = toDate(dirtyDateRight); var diff = dateLeft.getTime() - dateRight.getTime(); if (diff < 0) { return -1; } else if (diff > 0) { return 1; // Return 0 if diff is 0; return NaN if diff is NaN } else { return diff; } } /** * @name differenceInCalendarMonths * @category Month Helpers * @summary Get the number of calendar months between the given dates. * * @description * Get the number of calendar months between the given dates. * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * * @param {Date|Number} dateLeft - the later date * @param {Date|Number} dateRight - the earlier date * @returns {Number} the number of calendar months * @throws {TypeError} 2 arguments required * * @example * // How many calendar months are between 31 January 2014 and 1 September 2014? * var result = differenceInCalendarMonths( * new Date(2014, 8, 1), * new Date(2014, 0, 31) * ) * //=> 8 */ function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) { requiredArgs(2, arguments); var dateLeft = toDate(dirtyDateLeft); var dateRight = toDate(dirtyDateRight); var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); var monthDiff = dateLeft.getMonth() - dateRight.getMonth(); return yearDiff * 12 + monthDiff; } /** * @name differenceInMilliseconds * @category Millisecond Helpers * @summary Get the number of milliseconds between the given dates. * * @description * Get the number of milliseconds between the given dates. * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * * @param {Date|Number} dateLeft - the later date * @param {Date|Number} dateRight - the earlier date * @returns {Number} the number of milliseconds * @throws {TypeError} 2 arguments required * * @example * // How many milliseconds are between * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? * var result = differenceInMilliseconds( * new Date(2014, 6, 2, 12, 30, 21, 700), * new Date(2014, 6, 2, 12, 30, 20, 600) * ) * //=> 1100 */ function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) { requiredArgs(2, arguments); var dateLeft = toDate(dirtyDateLeft); var dateRight = toDate(dirtyDateRight); return dateLeft.getTime() - dateRight.getTime(); } /** * @name differenceInMonths * @category Month Helpers * @summary Get the number of full months between the given dates. * * @description * Get the number of full months between the given dates. * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * * @param {Date|Number} dateLeft - the later date * @param {Date|Number} dateRight - the earlier date * @returns {Number} the number of full months * @throws {TypeError} 2 arguments required * * @example * // How many full months are between 31 January 2014 and 1 September 2014? * var result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) * //=> 7 */ function differenceInMonths(dirtyDateLeft, dirtyDateRight) { requiredArgs(2, arguments); var dateLeft = toDate(dirtyDateLeft); var dateRight = toDate(dirtyDateRight); var sign = compareAsc(dateLeft, dateRight); var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full // If so, result must be decreased by 1 in absolute value var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero return result === 0 ? 0 : result; } /** * @name differenceInSeconds * @category Second Helpers * @summary Get the number of seconds between the given dates. * * @description * Get the number of seconds between the given dates. * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * * @param {Date|Number} dateLeft - the later date * @param {Date|Number} dateRight - the earlier date * @returns {Number} the number of seconds * @throws {TypeError} 2 arguments required * * @example * // How many seconds are between * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? * var result = differenceInSeconds( * new Date(2014, 6, 2, 12, 30, 20, 0), * new Date(2014, 6, 2, 12, 30, 7, 999) * ) * //=> 12 */ function differenceInSeconds(dirtyDateLeft, dirtyDateRight) { requiredArgs(2, arguments); var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000; return diff > 0 ? Math.floor(diff) : Math.ceil(diff); } var formatDistanceLocale = { lessThanXSeconds: { one: 'less than a second', other: 'less than {{count}} seconds' }, xSeconds: { one: '1 second', other: '{{count}} seconds' }, halfAMinute: 'half a minute', lessThanXMinutes: { one: 'less than a minute', other: 'less than {{count}} minutes' }, xMinutes: { one: '1 minute', other: '{{count}} minutes' }, aboutXHours: { one: 'about 1 hour', other: 'about {{count}} hours' }, xHours: { one: '1 hour', other: '{{count}} hours' }, xDays: { one: '1 day', other: '{{count}} days' }, aboutXWeeks: { one: 'about 1 week', other: 'about {{count}} weeks' }, xWeeks: { one: '1 week', other: '{{count}} weeks' }, aboutXMonths: { one: 'about 1 month', other: 'about {{count}} months' }, xMonths: { one: '1 month', other: '{{count}} months' }, aboutXYears: { one: 'about 1 year', other: 'about {{count}} years' }, xYears: { one: '1 year', other: '{{count}} years' }, overXYears: { one: 'over 1 year', other: 'over {{count}} years' }, almostXYears: { one: 'almost 1 year', other: 'almost {{count}} years' } }; function formatDistance$1(token, count, options) { options = options || {}; var result; if (typeof formatDistanceLocale[token] === 'string') { result = formatDistanceLocale[token]; } else if (count === 1) { result = formatDistanceLocale[token].one; } else { result = formatDistanceLocale[token].other.replace('{{count}}', count); } if (options.addSuffix) { if (options.comparison > 0) { return 'in ' + result; } else { return result + ' ago'; } } return result; } function buildFormatLongFn(args) { return function (dirtyOptions) { var options = dirtyOptions || {}; var width = options.width ? String(options.width) : args.defaultWidth; var format = args.formats[width] || args.formats[args.defaultWidth]; return format; }; } var dateFormats = { full: 'EEEE, MMMM do, y', long: 'MMMM do, y', medium: 'MMM d, y', short: 'MM/dd/yyyy' }; var timeFormats = { full: 'h:mm:ss a zzzz', long: 'h:mm:ss a z', medium: 'h:mm:ss a', short: 'h:mm a' }; var dateTimeFormats = { full: "{{date}} 'at' {{time}}", long: "{{date}} 'at' {{time}}", medium: '{{date}}, {{time}}', short: '{{date}}, {{time}}' }; var formatLong = { date: buildFormatLongFn({ formats: dateFormats, defaultWidth: 'full' }), time: buildFormatLongFn({ formats: timeFormats, defaultWidth: 'full' }), dateTime: buildFormatLongFn({ formats: dateTimeFormats, defaultWidth: 'full' }) }; var formatRelativeLocale = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", today: "'today at' p", tomorrow: "'tomorrow at' p", nextWeek: "eeee 'at' p", other: 'P' }; function formatRelative(token, _date, _baseDate, _options) { return formatRelativeLocale[token]; } function buildLocalizeFn(args) { return function (dirtyIndex, dirtyOptions) { var options = dirtyOptions || {}; var context = options.context ? String(options.context) : 'standalone'; var valuesArray; if (context === 'formatting' && args.formattingValues) { var defaultWidth = args.defaultFormattingWidth || args.defaultWidth; var width = options.width ? String(options.width) : defaultWidth; valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; } else { var _defaultWidth = args.defaultWidth; var _width = options.width ? String(options.width) : args.defaultWidth; valuesArray = args.values[_width] || args.values[_defaultWidth]; } var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; return valuesArray[index]; }; } var eraValues = { narrow: ['B', 'A'], abbreviated: ['BC', 'AD'], wide: ['Before Christ', 'Anno Domini'] }; var quarterValues = { narrow: ['1', '2', '3', '4'], abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'], wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter'] // Note: in English, the names of days of the week and months are capitalized. // If you are making a new locale based on this one, check if the same is true for the language you're working on. // Generally, formatted dates should look like they are in the middle of a sentence, // e.g. in Spanish language the weekdays and months should be in the lowercase. }; var monthValues = { narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'], abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] }; var dayValues = { narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'], short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] }; var dayPeriodValues = { narrow: { am: 'a', pm: 'p', midnight: 'mi', noon: 'n', morning: 'morning', afternoon: 'afternoon', evening: 'evening', night: 'night' }, abbreviated: { am: 'AM', pm: 'PM', midnight: 'midnight', noon: 'noon', morning: 'morning', afternoon: 'afternoon', evening: 'evening', night: 'night' }, wide: { am: 'a.m.', pm: 'p.m.', midnight: 'midnight', noon: 'noon', morning: 'morning', afternoon: 'afternoon', evening: 'evening', night: 'night' } }; var formattingDayPeriodValues = { narrow: { am: 'a', pm: 'p', midnight: 'mi', noon: 'n', morning: 'in the morning', afternoon: 'in the afternoon', evening: 'in the evening', night: 'at night' }, abbreviated: { am: 'AM', pm: 'PM', midnight: 'midnight', noon: 'noon', morning: 'in the morning', afternoon: 'in the afternoon', evening: 'in the evening', night: 'at night' }, wide: { am: 'a.m.', pm: 'p.m.', midnight: 'midnight', noon: 'noon', morning: 'in the morning', afternoon: 'in the afternoon', evening: 'in the evening', night: 'at night' } }; function ordinalNumber(dirtyNumber, _dirtyOptions) { var number = Number(dirtyNumber); // If ordinal numbers depend on context, for example, // if they are different for different grammatical genders, // use `options.unit`: // // var options = dirtyOptions || {} // var unit = String(options.unit) // // where `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear', // 'day', 'hour', 'minute', 'second' var rem100 = number % 100; if (rem100 > 20 || rem100 < 10) { switch (rem100 % 10) { case 1: return number + 'st'; case 2: return number + 'nd'; case 3: return number + 'rd'; } } return number + 'th'; } var localize = { ordinalNumber: ordinalNumber, era: buildLocalizeFn({ values: eraValues, defaultWidth: 'wide' }), quarter: buildLocalizeFn({ values: quarterValues, defaultWidth: 'wide', argumentCallback: function (quarter) { return Number(quarter) - 1; } }), month: buildLocalizeFn({ values: monthValues, defaultWidth: 'wide' }), day: buildLocalizeFn({ values: dayValues, defaultWidth: 'wide' }), dayPeriod: buildLocalizeFn({ values: dayPeriodValues, defaultWidth: 'wide', formattingValues: formattingDayPeriodValues, defaultFormattingWidth: 'wide' }) }; function buildMatchPatternFn(args) { return function (dirtyString, dirtyOptions) { var string = String(dirtyString); var options = dirtyOptions || {}; var matchResult = string.match(args.matchPattern); if (!matchResult) { return null; } var matchedString = matchResult[0]; var parseResult = string.match(args.parsePattern); if (!parseResult) { return null; } var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; value = options.valueCallback ? options.valueCallback(value) : value; return { value: value, rest: string.slice(matchedString.length) }; }; } function buildMatchFn(args) { return function (dirtyString, dirtyOptions) { var string = String(dirtyString); var options = dirtyOptions || {}; var width = options.width; var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; var matchResult = string.match(matchPattern); if (!matchResult) { return null; } var matchedString = matchResult[0]; var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; var value; if (Object.prototype.toString.call(parsePatterns) === '[object Array]') { value = findIndex(parsePatterns, function (pattern) { return pattern.test(matchedString); }); } else { value = findKey(parsePatterns, function (pattern) { return pattern.test(matchedString); }); } value = args.valueCallback ? args.valueCallback(value) : value; value = options.valueCallback ? options.valueCallback(value) : value; return { value: value, rest: string.slice(matchedString.length) }; }; } function findKey(object, predicate) { for (var key in object) { if (object.hasOwnProperty(key) && predicate(object[key])) { return key; } } } function findIndex(array, predicate) { for (var key = 0; key < array.length; key++) { if (predicate(array[key])) { return key; } } } var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; var parseOrdinalNumberPattern = /\d+/i; var matchEraPatterns = { narrow: /^(b|a)/i, abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, wide: /^(before christ|before common era|anno domini|common era)/i }; var parseEraPatterns = { any: [/^b/i, /^(a|c)/i] }; var matchQuarterPatterns = { narrow: /^[1234]/i, abbreviated: /^q[1234]/i, wide: /^[1234](th|st|nd|rd)? quarter/i }; var parseQuarterPatterns = { any: [/1/i, /2/i, /3/i, /4/i] }; var matchMonthPatterns = { narrow: /^[jfmasond]/i, abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i, wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i }; var parseMonthPatterns = { narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i], any: [/^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i] }; var matchDayPatterns = { narrow: /^[smtwf]/i, short: /^(su|mo|tu|we|th|fr|sa)/i, abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i, wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i }; var parseDayPatterns = { narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i], any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i] }; var matchDayPeriodPatterns = { narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i, any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i }; var parseDayPeriodPatterns = { any: { am: /^a/i, pm: /^p/i, midnight: /^mi/i, noon: /^no/i, morning: /morning/i, afternoon: /afternoon/i, evening: /evening/i, night: /night/i } }; var match = { ordinalNumber: buildMatchPatternFn({ matchPattern: matchOrdinalNumberPattern, parsePattern: parseOrdinalNumberPattern, valueCallback: function (value) { return parseInt(value, 10); } }), era: buildMatchFn({ matchPatterns: matchEraPatterns, defaultMatchWidth: 'wide', parsePatterns: parseEraPatterns, defaultParseWidth: 'any' }), quarter: buildMatchFn({ matchPatterns: matchQuarterPatterns, defaultMatchWidth: 'wide', parsePatterns: parseQuarterPatterns, defaultParseWidth: 'any', valueCallback: function (index) { return index + 1; } }), month: buildMatchFn({ matchPatterns: matchMonthPatterns, defaultMatchWidth: 'wide', parsePatterns: parseMonthPatterns, defaultParseWidth: 'any' }), day: buildMatchFn({ matchPatterns: matchDayPatterns, defaultMatchWidth: 'wide', parsePatterns: parseDayPatterns, defaultParseWidth: 'any' }), dayPeriod: buildMatchFn({ matchPatterns: matchDayPeriodPatterns, defaultMatchWidth: 'any', parsePatterns: parseDayPeriodPatterns, defaultParseWidth: 'any' }) }; /** * @type {Locale} * @category Locales * @summary English locale (United States). * @language English * @iso-639-2 eng * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp} * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss} */ var locale = { code: 'en-US', formatDistance: formatDistance$1, formatLong: formatLong, formatRelative: formatRelative, localize: localize, match: match, options: { weekStartsOn: 0 /* Sunday */ , firstWeekContainsDate: 1 } }; function assign(target, dirtyObject) { if (target == null) { throw new TypeError('assign requires that input parameter not be null or undefined'); } dirtyObject = dirtyObject || {}; for (var property in dirtyObject) { if (dirtyObject.hasOwnProperty(property)) { target[property] = dirtyObject[property]; } } return target; } function cloneObject(dirtyObject) { return assign({}, dirtyObject); } var MINUTES_IN_DAY = 1440; var MINUTES_IN_ALMOST_TWO_DAYS = 2520; var MINUTES_IN_MONTH = 43200; var MINUTES_IN_TWO_MONTHS = 86400; /** * @name formatDistance * @category Common Helpers * @summary Return the distance between the given dates in words. * * @description * Return the distance between the given dates in words. * * | Distance between dates | Result | * |-------------------------------------------------------------------|---------------------| * | 0 ... 30 secs | less than a minute | * | 30 secs ... 1 min 30 secs | 1 minute | * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes | * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour | * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours | * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day | * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days | * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month | * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months | * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months | * | 1 yr ... 1 yr 3 months | about 1 year | * | 1 yr 3 months ... 1 yr 9 month s | over 1 year | * | 1 yr 9 months ... 2 yrs | almost 2 years | * | N yrs ... N yrs 3 months | about N years | * | N yrs 3 months ... N yrs 9 months | over N years | * | N yrs 9 months ... N+1 yrs | almost N+1 years | * * With `options.includeSeconds == true`: * | Distance between dates | Result | * |------------------------|----------------------| * | 0 secs ... 5 secs | less than 5 seconds | * | 5 secs ... 10 secs | less than 10 seconds | * | 10 secs ... 20 secs | less than 20 seconds | * | 20 secs ... 40 secs | half a minute | * | 40 secs ... 60 secs | less than a minute | * | 60 secs ... 90 secs | 1 minute | * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * * - The function was renamed from `distanceInWords ` to `formatDistance` * to make its name consistent with `format` and `formatRelative`. * * - The order of arguments is swapped to make the function * consistent with `differenceIn...` functions. * * ```javascript * // Before v2.0.0 * * distanceInWords( * new Date(1986, 3, 4, 10, 32, 0), * new Date(1986, 3, 4, 11, 32, 0), * { addSuffix: true } * ) //=> 'in about 1 hour' * * // v2.0.0 onward * * formatDistance( * new Date(1986, 3, 4, 11, 32, 0), * new Date(1986, 3, 4, 10, 32, 0), * { addSuffix: true } * ) //=> 'in about 1 hour' * ``` * * @param {Date|Number} date - the date * @param {Date|Number} baseDate - the date to compare with * @param {Object} [options] - an object with options. * @param {Boolean} [options.includeSeconds=false] - distances less than a minute are more detailed * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} * @returns {String} the distance in words * @throws {TypeError} 2 arguments required * @throws {RangeError} `date` must not be Invalid Date * @throws {RangeError} `baseDate` must not be Invalid Date * @throws {RangeError} `options.locale` must contain `formatDistance` property * * @example * // What is the distance between 2 July 2014 and 1 January 2015? * var result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1)) * //=> '6 months' * * @example * // What is the distance between 1 January 2015 00:00:15 * // and 1 January 2015 00:00:00, including seconds? * var result = formatDistance( * new Date(2015, 0, 1, 0, 0, 15), * new Date(2015, 0, 1, 0, 0, 0), * { includeSeconds: true } * ) * //=> 'less than 20 seconds' * * @example * // What is the distance from 1 January 2016 * // to 1 January 2015, with a suffix? * var result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), { * addSuffix: true * }) * //=> 'about 1 year ago' * * @example * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto? * import { eoLocale } from 'date-fns/locale/eo' * var result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), { * locale: eoLocale * }) * //=> 'pli ol 1 jaro' */ function formatDistance(dirtyDate, dirtyBaseDate, dirtyOptions) { requiredArgs(2, arguments); var options = dirtyOptions || {}; var locale$1 = options.locale || locale; if (!locale$1.formatDistance) { throw new RangeError('locale must contain formatDistance property'); } var comparison = compareAsc(dirtyDate, dirtyBaseDate); if (isNaN(comparison)) { throw new RangeError('Invalid time value'); } var localizeOptions = cloneObject(options); localizeOptions.addSuffix = Boolean(options.addSuffix); localizeOptions.comparison = comparison; var dateLeft; var dateRight; if (comparison > 0) { dateLeft = toDate(dirtyBaseDate); dateRight = toDate(dirtyDate); } else { dateLeft = toDate(dirtyDate); dateRight = toDate(dirtyBaseDate); } var seconds = differenceInSeconds(dateRight, dateLeft); var offsetInSeconds = (getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft)) / 1000; var minutes = Math.round((seconds - offsetInSeconds) / 60); var months; // 0 up to 2 mins if (minutes < 2) { if (options.includeSeconds) { if (seconds < 5) { return locale$1.formatDistance('lessThanXSeconds', 5, localizeOptions); } else if (seconds < 10) { return locale$1.formatDistance('lessThanXSeconds', 10, localizeOptions); } else if (seconds < 20) { return locale$1.formatDistance('lessThanXSeconds', 20, localizeOptions); } else if (seconds < 40) { return locale$1.formatDistance('halfAMinute', null, localizeOptions); } else if (seconds < 60) { return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); } else { return locale$1.formatDistance('xMinutes', 1, localizeOptions); } } else { if (minutes === 0) { return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); } else { return locale$1.formatDistance('xMinutes', minutes, localizeOptions); } } // 2 mins up to 0.75 hrs } else if (minutes < 45) { return locale$1.formatDistance('xMinutes', minutes, localizeOptions); // 0.75 hrs up to 1.5 hrs } else if (minutes < 90) { return locale$1.formatDistance('aboutXHours', 1, localizeOptions); // 1.5 hrs up to 24 hrs } else if (minutes < MINUTES_IN_DAY) { var hours = Math.round(minutes / 60); return locale$1.formatDistance('aboutXHours', hours, localizeOptions); // 1 day up to 1.75 days } else if (minutes < MINUTES_IN_ALMOST_TWO_DAYS) { return locale$1.formatDistance('xDays', 1, localizeOptions); // 1.75 days up to 30 days } else if (minutes < MINUTES_IN_MONTH) { var days = Math.round(minutes / MINUTES_IN_DAY); return locale$1.formatDistance('xDays', days, localizeOptions); // 1 month up to 2 months } else if (minutes < MINUTES_IN_TWO_MONTHS) { months = Math.round(minutes / MINUTES_IN_MONTH); return locale$1.formatDistance('aboutXMonths', months, localizeOptions); } months = differenceInMonths(dateRight, dateLeft); // 2 months up to 12 months if (months < 12) { var nearestMonth = Math.round(minutes / MINUTES_IN_MONTH); return locale$1.formatDistance('xMonths', nearestMonth, localizeOptions); // 1 year up to max Date } else { var monthsSinceStartOfYear = months % 12; var years = Math.floor(months / 12); // N years up to 1 years 3 months if (monthsSinceStartOfYear < 3) { return locale$1.formatDistance('aboutXYears', years, localizeOptions); // N years 3 months up to N years 9 months } else if (monthsSinceStartOfYear < 9) { return locale$1.formatDistance('overXYears', years, localizeOptions); // N years 9 months up to N year 12 months } else { return locale$1.formatDistance('almostXYears', years + 1, localizeOptions); } } } /** * @name subSeconds * @category Second Helpers * @summary Subtract the specified number of seconds from the given date. * * @description * Subtract the specified number of seconds from the given date. * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * * @param {Date|Number} date - the date to be changed * @param {Number} amount - the amount of seconds to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. * @returns {Date} the new date with the seconds subtracted * @throws {TypeError} 2 arguments required * * @example * // Subtract 30 seconds from 10 July 2014 12:45:00: * var result = subSeconds(new Date(2014, 6, 10, 12, 45, 0), 30) * //=> Thu Jul 10 2014 12:44:30 */ function subSeconds(dirtyDate, dirtyAmount) { requiredArgs(2, arguments); var amount = toInteger(dirtyAmount); return addSeconds(dirtyDate, -amount); } const toastCss = ":host{--width:400px;--radius:var(--telekom-radius-small);--background:var(--scl-color-background-standard);--box-shadow:var(--telekom-shadow-app-bar-top-raised);--spacing:var(--telekom-spacing-composition-space-06);--border-header:1px solid var(--scl-color-grey-20);--font-size-header:var(--telekom-text-style-heading-4);--font-size-header-small:var(--telekom-typography-font-size-small);--height-progress:var(--telekom-spacing-composition-space-02)}.toast{width:var(--width);display:flex;opacity:0;z-index:1;position:fixed;background:var(--background);box-shadow:var(--box-shadow);box-sizing:border-box;border-radius:var(--radius);flex-direction:column;justify-content:space-between}.toast__body{padding:var(--spacing)}.toast__header{margin:0;display:flex;padding:var(--spacing);border-bottom:var(--border-header);justify-content:space-between;font:var(--font-size-header)}.toast__header a{cursor:pointer}.toast__header small{margin-top:5px;margin-left:120px;font-size:var(--font-size-header-small)}.toast__progress{left:0;bottom:0;height:var(--height-progress);display:block;overflow:hidden;position:absolute;background:red}"; const Toast = class { constructor(hostRef) { index.registerInstance(this, hostRef); /** (optional) Toast size */ this.size = ''; /** (optional) Toast variant */ this.variant = ''; /** (optional) Toast autohide time */ this.autoHide = false; /** (optional) Animated toast */ this.animated = true; /** (optional) Toast position at the top */ this.positionTop = 12; /** (optional) Toast position right */ this.positionRight = 12; /** (optional) Toast fade duration */ this.fadeDuration = 500; /** (optional) Toast state progress */ this.progress = 0; /** (optional) Toast state height with offset */ this.toastHeightWithOffset = 0; this.hideToast = false; this.timerId = null; this.close = () => { clearInterval(this.timerId); this.hideToast = true; setTimeout(() => { this.timerId = null; this.opened = false; this.progress = 0; }, this.fadeDuration); }; this.getTime = () => { const formattedTime = this.time && formatDistance(subSeconds(this.time, 3), new Date(), { addSuffix: true }); return formattedTime; }; this.setToastTimeout = () => { if (this.opened && this.autoHide !== false && !this.timerId) { this.timerId = setInterval(() => { this.progress += 1 / (this.getAutoHide() / 1000); if (this.progress >= 100) { this.close(); } }, 10); } }; this.transitions = (offset) => ` @keyframes fadeIn { from { opacity: 0; top: -${offset}px; } to { opacity: 1; top: ${this.positionTop}px; } } @keyframes fadeOut { from { opacity: 1; top: ${this.positionTop}px; } to { opacity: 0; top: -${offset}px; } } `; this.animationStyle = (offset) => { return ` .toast--show { right: ${this.positionRight}px; animation: fadeIn ${this.fadeDuration / 1000}s ease-in-out; top: ${this.positionTop}px; opacity: 1; }, .toast--show { right: ${this.positionRight}px; animation: fadeOut ${this.fadeDuration / 1000}s ease-in-out; top: -${offset}px; opacity: 0; } `; }; } connectedCallback() { statusNote.statusNote({ source: this.element, type: 'warn' }); } disconnectedCallback() { if (this.timerId) { clearTimeout(this.timerId); this.timerId = null; this.opened = false; this.progress = 0; } } /** Toast method: open() */ async open() { this.opened = true; this.hideToast = false; } render() { this.setToastTimeout(); return (index.h(index.Host, null, this.styles && index.h("style", null, this.styles), index.h("style", null, this.transitions(this.toastHeightWithOffset)), index.h("style", null, this.animationStyle(this.toastHeightWithOffset)), index.h("div", { class: this.getCssClassMap(), part: this.getBasePartMap() }, index.h("div", { part: "header", class: "toast__header" }, index.h("slot", { name: "header" }), index.h("small", null, this.getTime()), index.h("a", { onClick: this.close }, index.h("span", { "aria-hidden": "true" }, "\u00D7"))), this.autoHide && (index.h("div", { part: "progress", class: "toast__progress", style: { width: `${this.progress}%` } }, "\u00A0")), index.h("div", { part: "body", class: "toast__body" }, index.h("slot", null))))); } getToastHeightWithOffset() { const toastHeight = this.element.shadowRoot.querySelector('.toast').scrollHeight; this.toastHeightWithOffset = toastHeight + this.positionTop; } getAutoHide() { if (typeof this.autoHide === 'number' || typeof this.autoHide === 'string') { return Number(this.autoHide); } else { return 0; } } getBasePartMap() { return this.getCssOrBasePartMap('basePart'); } getCssClassMap() { return this.getCssOrBasePartMap('css'); } getCssOrBasePartMap(mode) { const component = 'toast'; const prefix = mode === 'basePart' ? '' : `${component}`; return index$1.classnames(mode === 'basePart' ? 'base' : component, this.size && `${prefix}--size-${this.size}`, this.variant && `${prefix}--variant-${this.variant}`, !!this.opened && `${prefix}--opened`, !!!this.hideToast && `${prefix}--show`, !!this.hideToast && `${prefix}--hide`); } get element() { return index.getElement(this); } }; Toast.style = toastCss; exports.scale_toast = Toast;