How to preserve spacing when inserting `dif x` through a variable?

Testing the following cases, seen below, I think this is the best we can do so far. With a custom adjustment to attach to “move” the thin weak space from inside of the attach to before it.

#let thinweak = h(math.thin.amount, weak: true)
#let dx = $dif x$  // dif is the same as thinweak upright(d)
#let starts-with(body, item) = {
  if body.func() == math.equation { return starts-with(body.body, item) }
  body.func() == [].func() and body.children.at(0) == item
}
#show math.attach: it => {
  if starts-with(it.base, math.dif) {
    thinweak + it
  } else {
    it
  }
}

$f dx + g dx$\
$f dx^1 + g dx^1$\
$A dx and dx$\
$B dx^1 and dx^2$\
$1 + dx$\
$2(dx + 1)$\
$display(integral dx integral dx^1 integral f dx^1 and g dx^1)$\

We could ask why the space in dif and here is weak at all - the answer is the case with (dx) where we need the space in front to collapse, which it does if it is weak(?)