I did develop a solution which did this, BUT while it did work with the onboard WiFi interfaces it is a kludge, so I can not recommend it as a reliable solution.
Raspberry Pi to configure automatically as an Access Point OR WiFi client.
It is far simpler to change modes using systemd-networkd
.
This requires a total change to networking and more manual configuration, and I am not sure if there is a solution which automatically switches. You should study Ingo's many posts to see if one of these meets your needs.
If you did want to explore this, I suggest you first migrate to systemd-networkd
. https://raspberrypi.stackexchange.com/a/117843/8697 describes a relatively simple setup which works as well as dhcpcd
.