A chain of serendipity. If the Japanese found us first and destroyed our carriers it would the reverse. Japan would have Midway and a clear path to our west coast. We would have had to settle and that is what they wanted.
I don't think the Japanese every had it in mind to attack the US West Coast or invade America. They just wanted to do their imperial thing in what they considered their sphere of influence. They did it brutally, but they were following similar imperial conquests and actions from Europe. This wasn't long after the European colonies were all over Asia. Laos (France), Cambodia (France), Philippines (Spain and then USA), Hong Kong (England), etc. In southeast Asia only Thailand resisted ever being "colonized" by the Europeans. Japan was following suit and wanted to create their own empire. Nationalism grew there as it had previously elsewhere and they became brutal and did horrible things to those who resisted their rule; especially but not exclusively the Chinese. America got themselves involved (not long after pulling out of their own occupation of Philippines; an occupation they took again after the war) and set out to cut off resources from Japan. It wasn't a humanitarian action by the US. It was their own power play. Japan took a gamble and struck out at the USA to break free that resource flow, and attacked pearl harbour (which is nowhere near the continental US) and within what Japan considered its sphere of influence.
Had America stayed out Asia, Japan would not have attacked America. It was never a threat to the USA itself. It was a threat to other Asian countries and "US interests". The war ended when the USA bombed large centres of the civilian population of Japan, turning human beings into ash, not once, but twice.