utils.d.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Use of this source code is governed by an MIT-style license that can be
  3. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  4. */
  5. /**
  6. * fit content details: https://github.com/NG-ZORRO/ng-zorro-antd/pull/6154#issuecomment-745025554
  7. *
  8. * calc position x,y point
  9. *
  10. * CASE (width <= clientWidth && height <= clientHeight):
  11. *
  12. * ------------- clientWidth -------------
  13. * | |
  14. * | ------ width ------ |
  15. * | | | |
  16. * | | | |
  17. * client height | |
  18. * Height | | |
  19. * | | | |
  20. * | ------------------- |
  21. * | |
  22. * | |
  23. * ---------------------------------------
  24. * fixedPosition = { x: 0, y: 0 }
  25. *
  26. *
  27. *
  28. * CASE (width > clientWidth || height > clientHeight):
  29. *
  30. * ------------- clientWidth -------------
  31. * | | |
  32. * | top |
  33. * | | |
  34. * |--left--|--------------- width -----------------
  35. * | | |
  36. * client | |
  37. * Height | |
  38. * | | |
  39. * | | |
  40. * | height |
  41. * | | |
  42. * ---------| |
  43. * | |
  44. * | |
  45. * | |
  46. * ----------------------------------------
  47. *
  48. *
  49. * - left || top > 0
  50. * left -> 0 || top -> 0
  51. *
  52. * - (left + width) < clientWidth || (top + height) < clientHeight
  53. * - left | top + width | height < clientWidth | clientHeight -> Back left | top + width | height === clientWidth | clientHeight
  54. *
  55. * DEFAULT:
  56. * - hold position
  57. *
  58. */
  59. export declare function getFitContentPosition(params: {
  60. width: number;
  61. height: number;
  62. left: number;
  63. top: number;
  64. clientWidth: number;
  65. clientHeight: number;
  66. }): {
  67. x?: number;
  68. y?: number;
  69. };
  70. export declare function getOffset(node: HTMLElement): {
  71. left: number;
  72. top: number;
  73. };
  74. export declare function getClientSize(): {
  75. width: number;
  76. height: number;
  77. };