Background Information
Inspired by this answer on Arqade SE
Minecraft has rails which allow you to move minecarts around on them for transporting players, entities, and items. There are many types of rails, but today we're only interested in regular rails, which are also the only type that can curve.
When you place down a normal rail that has two adjacent rails, it will connect them. If they are not on opposite sides of the rail, the rail will curve to a 90 degree angle. However, if there are more than two adjacent rails, it can't connect all of them. In that case, it will always favor going south-east (this is called the south-east or Z-X rule) (for this challenge, north is up, east is right, south is down, west is left). If there is a T-junction, the rail will always connect to the "vertical" branch of the T, and then it will prioritize south over north if the main branch is east-west, and east over west if the main branch is north-south. If there is a four-way junction, the rail will connect south and east.
I/O
For this challenge, you will need eight distinct characters: empty space, vertical rail, horizontal rail, up-left curved rail, up-right curved rail, down-left curved rail, down-right curved rail, and placeholder. You may select any characters; I choose to use box-drawing characters in my examples. You may count these eight characters as one byte in your code (this is just to allow people to use box-drawing characters instead of just like " |-WXYZ#"
or something not as nice-looking).
You will be given input in a convenient format for a layout of existing rails. This will be a grid, so you may take it as a matrix of characters, a list of strings, newline-separated strings, etc. Anything reasonable. To simplify a bit, your input will only contain straight rails, placeholders, and blanks.
Your output should be a grid of the same size, but in each placeholder you are to place a rail according to the rules given. To make this challenge a bit simpler, every placeholder will always have at least two adjacent rails that are already facing the appropriate direction, so you should not change any cells except the placeholders. Note that it is possible for the rails to be on opposite sides of the placeholder, in which case you may need to place down a straight rail.
Detailed Example
This contains every possible configuration:
.═.═.═.
║ ═ ║ ║
.║ ║ ║
║ ║ ║
.═══.═.
║ ║ ║
.═══.═.
The output for this would be:
╔═══╔═╗
║ ═ ║ ║
║║ ║ ║
║ ║ ║
╔═══╔═╗
║ ║ ║
╚═══╚═╝
Note that it's valid to have rails facing the wrong direction next to placeholders. You are guaranteed that at least two adjacent rails are facing the right way though. Technically, in Minecraft, this might cause the side rails to turn to face the new rail and then curve, but in this specific challenge, we'll just assume that existing straight rails will not turn, and you just need to connect up exactly two of the adjacent, correctly-oriented rails in accordance to the S-E rule.
.══.══. ╔═════╗
║ ║ ║ ║
.══.══. . ╔══╔══╗ ║
║ ║ ║ ║ -> ║ ║ ║ ║
.══.══. . ╚══╔══╝ ║
║ ║ ║ ║
.══.══. ╚═════╝
You're running out of space on your minecart to write your code, so your code must be as short as possible! This is code-golf, so the shortest answer in bytes wins (remember that you may count your eight I/O characters as one byte).