Yes, Pearl Harbor was a direct attack in the US, but why did it happen? The US wanted to stay out of WW2 and comunicated the wrong message to the Japanese. That's why it happened!
That's a little too simplistic. Here's a more detailed explanation:
Japan had been modernising its economy throughout the 20th century and wanted to build an empire of its own. However, Japan lacked the natural resources to make it a reality, with all but 6% of its oil supply being imported. After capturing Manchuria, Japan became bogged down in a full-scale war with China in 1937 and had to look elsewhere for the resources it needed to fight. Meanwhile, the USA was slowly awakening from its isolationism.
When Japan occupied French Indochina in 1941, America retaliated by freezing all Japanese assets in the states, preventing Japan from purchasing oil. Having lost 94% of its oil supply and unwilling to submit to U.S demands, Japan planned to take the oil needed by force. However, striking south into British Malaya and the Dutch East Indies would almost certainly provoke an armed U.S response. To blunt that response, Japan decided to attack the U.S Pacific Fleet at Pearl Harbor, hoping that the U.S would negotiate peace.
The attack at Pearl Harbor was a huge gamble, but one which did not pay off. Though Japan took its objectives in the Pacific and Southeast Asia, the U.S did not respond as expected. Instead of reverting to isolationism, the U.S geared up for total war and Japan's fate was sealed.https://www.iwm.org.uk/history/why-did-japan-attack-pearl-harborIt's not comparable to our policies towards Ukraine. The US began trying to help Ukraine pivot away from Russia's economic and political influence during Obama's second term. We began arming and training Ukraine in 2017 after Trump took office. Putin viewed US/NATO meddling in Ukraine as escalatory. Our actions didn't deter him.
With all that said, I still view Putin as a rational actor. Ukraine isn't a NATO member state so he can screw with them but he's not going to screw with NATO.
As far as China goes, if we're not willing to intervene directly in Ukraine because Russia is a nuclear power, why would China take seriously Biden's vow to intervene to help Taiwan? China is a nuclear power and dominates global trade. A war between the US and China wouldn't be painless for Americans and the worst-case scenario is that it could lead to nuclear war...