Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.ts 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { CONNECTION_TYPE } from './constants';
  2. /**
  3. * The avatar size to container size ration.
  4. */
  5. const ratio = 1 / 3;
  6. /**
  7. * The max avatar size.
  8. */
  9. const maxSize = 190;
  10. /**
  11. * The window limit height over which the avatar should have the default dimension.
  12. */
  13. const upperHeightLimit = 760;
  14. /**
  15. * The window limit height under which the avatar should not be resized anymore.
  16. */
  17. const lowerHeightLimit = 460;
  18. /**
  19. * The default top margin of the avatar.
  20. */
  21. const defaultMarginTop = '10%';
  22. /**
  23. * The top margin of the avatar when its dimension is small.
  24. */
  25. const smallMarginTop = '5%';
  26. /**
  27. * Calculates avatar dimensions based on window height and position.
  28. *
  29. * @param {number} height - The window height.
  30. * @returns {{
  31. * marginTop: string,
  32. * size: number
  33. * }}
  34. */
  35. export function calculateAvatarDimensions(height: number) {
  36. if (height > upperHeightLimit) {
  37. return {
  38. size: maxSize,
  39. marginTop: defaultMarginTop
  40. };
  41. }
  42. if (height > lowerHeightLimit) {
  43. const diff = height - lowerHeightLimit;
  44. const percent = diff * ratio;
  45. const size = Math.floor(maxSize * percent / 100);
  46. let marginTop = defaultMarginTop;
  47. if (height < 600) {
  48. marginTop = smallMarginTop;
  49. }
  50. return {
  51. size,
  52. marginTop
  53. };
  54. }
  55. return {
  56. size: 0,
  57. marginTop: '0'
  58. };
  59. }
  60. /**
  61. * Selector for determining the connection type & details.
  62. *
  63. * @returns {{
  64. * connectionType: string,
  65. * connectionDetails: string[]
  66. * }}
  67. */
  68. export function getConnectionData() {
  69. return {
  70. connectionType: CONNECTION_TYPE.NONE,
  71. connectionDetails: []
  72. };
  73. }