Rect.js 650 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict
  9. */
  10. 'use strict';
  11. export type Rect = $ReadOnly<{|
  12. bottom?: ?number,
  13. left?: ?number,
  14. right?: ?number,
  15. top?: ?number,
  16. |}>;
  17. export type RectOrSize = Rect | number;
  18. export function createSquare(size: number): Rect {
  19. return {bottom: size, left: size, right: size, top: size};
  20. }
  21. export function normalizeRect(rectOrSize: ?RectOrSize): ?Rect {
  22. return typeof rectOrSize === 'number' ? createSquare(rectOrSize) : rectOrSize;
  23. }