code: function constrain(value, max, size) {
            if (value < 0) {
              return 0;
            }
  
            if (value + size > max) {
              value = max - size;
              return value < 0 ? 0 : value;
            }
  
            return value;
          }
docs: TODO: Move this to some global class