Using OKLCH and sRGB. This also works for Display P3, however you'll have to pass the correct coefficients to the cusp & intersection utilities, and instead of using linear sRGB, you would convert to linear Display P3.
If you wish to support both sRGB and Display P3 gamut mapping, it is possible with a single function and a matrix parameter, as they both use the same coordinate range (0..1) and gamma transfer function.
import { OKLCH_to_linear_sRGB } from './convert.js';
import { rgb_in_gamut, linear_to_gamma } from './util.js';
import { find_cusp, find_gamut_intersection } from './oklab-cusp.js';