@mxenabled/connect-widget 0.18.2 → 0.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -12728,124 +12728,29 @@ function requireDist () {
12728
12728
 
12729
12729
  var distExports = requireDist();
12730
12730
 
12731
- /**
12732
- * @module constants
12733
- * @summary Useful constants
12734
- * @description
12735
- * Collection of useful date constants.
12736
- *
12737
- * The constants could be imported from `date-fns/constants`:
12738
- *
12739
- * ```ts
12740
- * import { maxTime, minTime } from "./constants/date-fns/constants";
12741
- *
12742
- * function isAllowedTime(time) {
12743
- * return time <= maxTime && time >= minTime;
12744
- * }
12745
- * ```
12746
- */
12747
-
12731
+ const millisecondsInDay = 864e5;
12732
+ const constructFromSymbol = Symbol.for("constructDateFrom");
12748
12733
 
12749
- /**
12750
- * @constant
12751
- * @name millisecondsInDay
12752
- * @summary Milliseconds in 1 day.
12753
- */
12754
- const millisecondsInDay = 86400000;
12755
-
12756
- /**
12757
- * @name toDate
12758
- * @category Common Helpers
12759
- * @summary Convert the given argument to an instance of Date.
12760
- *
12761
- * @description
12762
- * Convert the given argument to an instance of Date.
12763
- *
12764
- * If the argument is an instance of Date, the function returns its clone.
12765
- *
12766
- * If the argument is a number, it is treated as a timestamp.
12767
- *
12768
- * If the argument is none of the above, the function returns Invalid Date.
12769
- *
12770
- * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
12771
- *
12772
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
12773
- *
12774
- * @param argument - The value to convert
12775
- *
12776
- * @returns The parsed date in the local time zone
12777
- *
12778
- * @example
12779
- * // Clone the date:
12780
- * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
12781
- * //=> Tue Feb 11 2014 11:30:30
12782
- *
12783
- * @example
12784
- * // Convert the timestamp to date:
12785
- * const result = toDate(1392098430000)
12786
- * //=> Tue Feb 11 2014 11:30:30
12787
- */
12788
- function toDate(argument) {
12789
- const argStr = Object.prototype.toString.call(argument);
12734
+ function constructFrom(date, value) {
12735
+ if (typeof date === "function") return date(value);
12736
+ if (date && typeof date === "object" && constructFromSymbol in date)
12737
+ return date[constructFromSymbol](value);
12738
+ if (date instanceof Date) return new date.constructor(value);
12739
+ return new Date(value);
12740
+ }
12790
12741
 
12791
- // Clone the date
12792
- if (
12793
- argument instanceof Date ||
12794
- (typeof argument === "object" && argStr === "[object Date]")
12795
- ) {
12796
- // Prevent the date to lose the milliseconds when passed to new Date() in IE10
12797
- return new argument.constructor(+argument);
12798
- } else if (
12799
- typeof argument === "number" ||
12800
- argStr === "[object Number]" ||
12801
- typeof argument === "string" ||
12802
- argStr === "[object String]"
12803
- ) {
12804
- // TODO: Can we get rid of as?
12805
- return new Date(argument);
12806
- } else {
12807
- // TODO: Can we get rid of as?
12808
- return new Date(NaN);
12809
- }
12742
+ function normalizeDates(context, ...dates) {
12743
+ const normalize = constructFrom.bind(
12744
+ null,
12745
+ dates.find((date) => typeof date === "object")
12746
+ );
12747
+ return dates.map(normalize);
12810
12748
  }
12811
12749
 
12812
- /**
12813
- * @name startOfDay
12814
- * @category Day Helpers
12815
- * @summary Return the start of a day for the given date.
12816
- *
12817
- * @description
12818
- * Return the start of a day for the given date.
12819
- * The result will be in the local timezone.
12820
- *
12821
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
12822
- *
12823
- * @param date - The original date
12824
- *
12825
- * @returns The start of a day
12826
- *
12827
- * @example
12828
- * // The start of a day for 2 September 2014 11:55:00:
12829
- * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
12830
- * //=> Tue Sep 02 2014 00:00:00
12831
- */
12832
- function startOfDay(date) {
12833
- const _date = toDate(date);
12834
- _date.setHours(0, 0, 0, 0);
12835
- return _date;
12750
+ function toDate(argument, context) {
12751
+ return constructFrom(argument, argument);
12836
12752
  }
12837
12753
 
12838
- /**
12839
- * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
12840
- * They usually appear for dates that denote time before the timezones were introduced
12841
- * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
12842
- * and GMT+01:00:00 after that date)
12843
- *
12844
- * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
12845
- * which would lead to incorrect calculations.
12846
- *
12847
- * This function returns the timezone offset in milliseconds that takes seconds in account.
12848
- */
12849
12754
  function getTimezoneOffsetInMilliseconds(date) {
12850
12755
  const _date = toDate(date);
12851
12756
  const utcDate = new Date(
@@ -12856,176 +12761,58 @@ function getTimezoneOffsetInMilliseconds(date) {
12856
12761
  _date.getHours(),
12857
12762
  _date.getMinutes(),
12858
12763
  _date.getSeconds(),
12859
- _date.getMilliseconds(),
12860
- ),
12764
+ _date.getMilliseconds()
12765
+ )
12861
12766
  );
12862
12767
  utcDate.setUTCFullYear(_date.getFullYear());
12863
12768
  return +date - +utcDate;
12864
12769
  }
12865
12770
 
12866
- /**
12867
- * @name differenceInCalendarDays
12868
- * @category Day Helpers
12869
- * @summary Get the number of calendar days between the given dates.
12870
- *
12871
- * @description
12872
- * Get the number of calendar days between the given dates. This means that the times are removed
12873
- * from the dates and then the difference in days is calculated.
12874
- *
12875
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
12876
- *
12877
- * @param dateLeft - The later date
12878
- * @param dateRight - The earlier date
12879
- *
12880
- * @returns The number of calendar days
12881
- *
12882
- * @example
12883
- * // How many calendar days are between
12884
- * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
12885
- * const result = differenceInCalendarDays(
12886
- * new Date(2012, 6, 2, 0, 0),
12887
- * new Date(2011, 6, 2, 23, 0)
12888
- * )
12889
- * //=> 366
12890
- * // How many calendar days are between
12891
- * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
12892
- * const result = differenceInCalendarDays(
12893
- * new Date(2011, 6, 3, 0, 1),
12894
- * new Date(2011, 6, 2, 23, 59)
12895
- * )
12896
- * //=> 1
12897
- */
12898
- function differenceInCalendarDays(dateLeft, dateRight) {
12899
- const startOfDayLeft = startOfDay(dateLeft);
12900
- const startOfDayRight = startOfDay(dateRight);
12901
-
12902
- const timestampLeft =
12903
- +startOfDayLeft - getTimezoneOffsetInMilliseconds(startOfDayLeft);
12904
- const timestampRight =
12905
- +startOfDayRight - getTimezoneOffsetInMilliseconds(startOfDayRight);
12906
-
12907
- // Round the number of days to the nearest integer because the number of
12908
- // milliseconds in a day is not constant (e.g. it's different in the week of
12909
- // the daylight saving time clock shift).
12910
- return Math.round((timestampLeft - timestampRight) / millisecondsInDay);
12771
+ function startOfDay(date, options) {
12772
+ const _date = toDate(date);
12773
+ _date.setHours(0, 0, 0, 0);
12774
+ return _date;
12911
12775
  }
12912
12776
 
12913
- /**
12914
- * @name differenceInDays
12915
- * @category Day Helpers
12916
- * @summary Get the number of full days between the given dates.
12917
- *
12918
- * @description
12919
- * Get the number of full day periods between two dates. Fractional days are
12920
- * truncated towards zero.
12921
- *
12922
- * One "full day" is the distance between a local time in one day to the same
12923
- * local time on the next or previous day. A full day can sometimes be less than
12924
- * or more than 24 hours if a daylight savings change happens between two dates.
12925
- *
12926
- * To ignore DST and only measure exact 24-hour periods, use this instead:
12927
- * `Math.trunc(differenceInHours(dateLeft, dateRight)/24)|0`.
12928
- *
12929
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
12930
- *
12931
- * @param dateLeft - The later date
12932
- * @param dateRight - The earlier date
12933
- *
12934
- * @returns The number of full days according to the local timezone
12935
- *
12936
- * @example
12937
- * // How many full days are between
12938
- * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
12939
- * const result = differenceInDays(
12940
- * new Date(2012, 6, 2, 0, 0),
12941
- * new Date(2011, 6, 2, 23, 0)
12942
- * )
12943
- * //=> 365
12944
- *
12945
- * @example
12946
- * // How many full days are between
12947
- * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
12948
- * const result = differenceInDays(
12949
- * new Date(2011, 6, 3, 0, 1),
12950
- * new Date(2011, 6, 2, 23, 59)
12951
- * )
12952
- * //=> 0
12953
- *
12954
- * @example
12955
- * // How many full days are between
12956
- * // 1 March 2020 0:00 and 1 June 2020 0:00 ?
12957
- * // Note: because local time is used, the
12958
- * // result will always be 92 days, even in
12959
- * // time zones where DST starts and the
12960
- * // period has only 92*24-1 hours.
12961
- * const result = differenceInDays(
12962
- * new Date(2020, 5, 1),
12963
- * new Date(2020, 2, 1)
12964
- * )
12965
- * //=> 92
12966
- */
12967
- function differenceInDays(dateLeft, dateRight) {
12968
- const _dateLeft = toDate(dateLeft);
12969
- const _dateRight = toDate(dateRight);
12970
-
12971
- const sign = compareLocalAsc(_dateLeft, _dateRight);
12972
- const difference = Math.abs(differenceInCalendarDays(_dateLeft, _dateRight));
12973
-
12974
- _dateLeft.setDate(_dateLeft.getDate() - sign * difference);
12975
-
12976
- // Math.abs(diff in full days - diff in calendar days) === 1 if last calendar day is not full
12977
- // If so, result must be decreased by 1 in absolute value
12777
+ function differenceInCalendarDays(laterDate, earlierDate, options) {
12778
+ const [laterDate_, earlierDate_] = normalizeDates(
12779
+ options?.in,
12780
+ laterDate,
12781
+ earlierDate
12782
+ );
12783
+ const laterStartOfDay = startOfDay(laterDate_);
12784
+ const earlierStartOfDay = startOfDay(earlierDate_);
12785
+ const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
12786
+ const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
12787
+ return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
12788
+ }
12789
+
12790
+ function differenceInDays(laterDate, earlierDate, options) {
12791
+ const [laterDate_, earlierDate_] = normalizeDates(
12792
+ options?.in,
12793
+ laterDate,
12794
+ earlierDate
12795
+ );
12796
+ const sign = compareLocalAsc(laterDate_, earlierDate_);
12797
+ const difference = Math.abs(
12798
+ differenceInCalendarDays(laterDate_, earlierDate_)
12799
+ );
12800
+ laterDate_.setDate(laterDate_.getDate() - sign * difference);
12978
12801
  const isLastDayNotFull = Number(
12979
- compareLocalAsc(_dateLeft, _dateRight) === -sign,
12802
+ compareLocalAsc(laterDate_, earlierDate_) === -sign
12980
12803
  );
12981
12804
  const result = sign * (difference - isLastDayNotFull);
12982
- // Prevent negative zero
12983
12805
  return result === 0 ? 0 : result;
12984
12806
  }
12985
-
12986
- // Like `compareAsc` but uses local time not UTC, which is needed
12987
- // for accurate equality comparisons of UTC timestamps that end up
12988
- // having the same representation in local time, e.g. one hour before
12989
- // DST ends vs. the instant that DST ends.
12990
- function compareLocalAsc(dateLeft, dateRight) {
12991
- const diff =
12992
- dateLeft.getFullYear() - dateRight.getFullYear() ||
12993
- dateLeft.getMonth() - dateRight.getMonth() ||
12994
- dateLeft.getDate() - dateRight.getDate() ||
12995
- dateLeft.getHours() - dateRight.getHours() ||
12996
- dateLeft.getMinutes() - dateRight.getMinutes() ||
12997
- dateLeft.getSeconds() - dateRight.getSeconds() ||
12998
- dateLeft.getMilliseconds() - dateRight.getMilliseconds();
12999
-
13000
- if (diff < 0) {
13001
- return -1;
13002
- } else if (diff > 0) {
13003
- return 1;
13004
- // Return 0 if diff is 0; return NaN if diff is NaN
13005
- } else {
13006
- return diff;
13007
- }
12807
+ function compareLocalAsc(laterDate, earlierDate) {
12808
+ const diff = laterDate.getFullYear() - earlierDate.getFullYear() || laterDate.getMonth() - earlierDate.getMonth() || laterDate.getDate() - earlierDate.getDate() || laterDate.getHours() - earlierDate.getHours() || laterDate.getMinutes() - earlierDate.getMinutes() || laterDate.getSeconds() - earlierDate.getSeconds() || laterDate.getMilliseconds() - earlierDate.getMilliseconds();
12809
+ if (diff < 0) return -1;
12810
+ if (diff > 0) return 1;
12811
+ return diff;
13008
12812
  }
13009
12813
 
13010
- /**
13011
- * @name fromUnixTime
13012
- * @category Timestamp Helpers
13013
- * @summary Create a date from a Unix timestamp.
13014
- *
13015
- * @description
13016
- * Create a date from a Unix timestamp (in seconds). Decimal values will be discarded.
13017
- *
13018
- * @param unixTime - The given Unix timestamp (in seconds)
13019
- *
13020
- * @returns The date
13021
- *
13022
- * @example
13023
- * // Create the date 29 February 2012 11:45:05:
13024
- * const result = fromUnixTime(1330515905)
13025
- * //=> Wed Feb 29 2012 11:45:05
13026
- */
13027
- function fromUnixTime(unixTime) {
13028
- return toDate(unixTime * 1000);
12814
+ function fromUnixTime(unixTime, options) {
12815
+ return toDate(unixTime * 1e3);
13029
12816
  }
13030
12817
 
13031
12818
  const Style$1 = {
@@ -80957,27 +80744,8 @@ const ConnectedTokenProvider = ({ children }) => {
80957
80744
  );
80958
80745
  };
80959
80746
 
80960
- /**
80961
- * @name getUnixTime
80962
- * @category Timestamp Helpers
80963
- * @summary Get the seconds timestamp of the given date.
80964
- *
80965
- * @description
80966
- * Get the seconds timestamp of the given date.
80967
- *
80968
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
80969
- *
80970
- * @param date - The given date
80971
- *
80972
- * @returns The timestamp
80973
- *
80974
- * @example
80975
- * // Get the timestamp of 29 February 2012 11:45:05 CET:
80976
- * const result = getUnixTime(new Date(2012, 1, 29, 11, 45, 5))
80977
- * //=> 1330512305
80978
- */
80979
80747
  function getUnixTime(date) {
80980
- return Math.trunc(+toDate(date) / 1000);
80748
+ return Math.trunc(+toDate(date) / 1e3);
80981
80749
  }
80982
80750
 
80983
80751
  const APP_MIN_WIDTH = 320;