Store each `pointerdown`'s coordinates in a `Map` keyed by `pointerId`, tracking how many pointers are currently active. When the second pointer lands, remember the distance between the two points at that moment (`startDist`) and the current scale (`startScale`) as your baseline.
On every subsequent `pointermove`, re-measure the distance between the two points, take its ratio to `startDist`, and update scale with `newScale = startScale * (currentDist / startDist)` — spreading fingers increases distance and zooms in, pinching decreases it and zooms out.
Desktop has no multitouch, so it's common to open a secondary path — trackpad or mouse wheel (`deltaY` from the `wheel` event) driving the same scale value. Always clamp the scale with a min/max so it can't grow unbounded or flip negative.
When to use
Use it for photo viewers, maps, and galleries where people need to inspect detail. Once zoomed in, pair it with panning (drag to move) for it to feel complete.