square.mjs 603 B

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