def _rescale_factor(
    df: DataFrameLike, vals: list[int | float], domain: list[float], palette: list[str]
) -> list[float]:
    """
    Rescale factor values

    Rescale the factor values in `vals=` to the range [0, 1] using the domain provided.
    """

    domain_length = len(domain)
    palette_length = len(palette)

    if domain_length <= palette_length:
        # If the length of `domain` is less than or equal to the length of `palette`, then clip the
        # length of `palette` to the length of `domain`
        palette = palette[:domain_length]

    # For each value in `vals`, get the index of the value in `domain` but if not present then
    # use NA; then scale these index values to the range [0, 1]
    scaled_vals = _rescale_numeric(
        df=df,
        vals=[domain.index(x) if x in domain else np.nan for x in vals],
        domain=[0, domain_length],
    )

    return scaled_vals

    Rescale factor values

    Rescale the factor values in `vals=` to the range [0, 1] using the domain provided.
    
great_tables/_data_color/base.py