One way to understand this passage is as the evolution of the concept of sequence in 20th century showtunes.
The music is by Alan Menken and he both pioneered and exemplifies this particular style of composition. If you wanted to read books that explain this music better, you could look for jazz, pop, and 20th century theory books. That said, this musical theatre style itself is not widely analyzed music theory texts, at least as far as I’ve found.
Notice how the third measure is very similar to the first measure with most elements transposed down a half step, but also with some harmonic modifications to create a certain feeling.
The key is D major and the first chord of the first measure is the tonic chord (D major) in root position. The melody starts on the third degree of the chord (F#). I think it is helpful to interpret the second chord of the first measure as an E minor 7th chord, with the 7th in the bass.
In the third measure, the melodic contour is repeated with the first note a whole step down and the rest of the melody only a half step down. As I mentioned, I think it’s helpful to see this as a melodic sequence, which is a common tool used for centuries to extend and develop a melody in a way that is the same but different. (“Same but different” is a great way to create music that is catchy and popular.)
The harmony for the third measure also imitates the contour of the harmony of the first measure, but it is not a whole step down. It’s a whole step up. There are two reasons I can think of for that. First, following the second measure Menken might have wanted to use a jazz-related harmonic trope of going down a tritone (augmented fourth) instead of a fifth. Tritone relationships are a whole thing in jazz. The second reason is a sequence can lose a lot of impact if the harmony is repeated the same way the melody is repeated.
And there’s a possible third reason. The D# of the melody can be heard as (perhaps weakly) tonicizing the E minor chord. This is another jazz related concept of “the key of the moment”. Without the fourth measure this is just a guess, but temporarily making the tonal center E minor could be a setup for a larger ii - V - I structure, which is arguably the quintessence of jazz (especially showtune jazz, if I can coin that sub genre). It’s common in jazz progressions to have a measure or two of chords based in a minor ii tonality, followed by a few measures in V7 tonality, followed by a I chord, or perhaps a deceptive cadence or turnaround, etc.
To summarize, it’s not going to be very helpful to try to analyze 20th and 21st century musical theatre and movie musical music in the context of 17th - 19th century European art music (AKA “classical” music). Musical theatre (and I’m lumping in movie musicals) as a genre is very fuzzy and borrows from many other genres, but it shares the closest kinship with jazz (in my humble opinion). You’ll get a lot more mileage out of studying jazz theory to help understand a lot of popular and commercial music of the 20th century through today.