I have wrapped my head around this now, and implemented a solution I’m fairly happy with. This is not an invite to a discussion about how it is going to work, unless you see something obviously wrong, but if you are curious and can understand some source code, you can extract the “how” from the test cases here:
… I have written absolutely no documentation for this …