Gamma-ray burst precursors as the remnant of the thermal radiation initially trapped in the fireball