square.cjs 660 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. function makeIconSquare(icon) {
  3. if (icon.width !== icon.height) {
  4. const max = Math.max(icon.width, icon.height);
  5. return {
  6. ...icon,
  7. width: max,
  8. height: max,
  9. left: icon.left - (max - icon.width) / 2,
  10. top: icon.top - (max - icon.height) / 2
  11. };
  12. }
  13. return icon;
  14. }
  15. function makeViewBoxSquare(viewBox) {
  16. const [left, top, width, height] = viewBox;
  17. if (width !== height) {
  18. const max = Math.max(width, height);
  19. return [left - (max - width) / 2, top - (max - height) / 2, max, max];
  20. }
  21. return viewBox;
  22. }
  23. exports.makeIconSquare = makeIconSquare;
  24. exports.makeViewBoxSquare = makeViewBoxSquare;