// Copyright (c) 2018-2022 Omar Al-Ithawi and The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// Go translation and modification of MathJax 3.2.2 ColorMethods.ts.

package color

import (
	
	
	
	

	
	
)

var (
	parseFloatPrefix = regexp.MustCompile(`^[+-]?(?:Infinity|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)`)
	trailingUnit     = regexp.MustCompile(`[a-z]*$`)
)

// PaddingProperties ports ColorMethods.ts's padding() helper. Attribute order
// matches the source PropertyList so a core parser can apply it directly to an
// mpadded node.
func ( string) []spec.Attribute {
	 := "+" + 
	 := paddingUnit()
	 := 2 * parseFloat()
	return []spec.Attribute{
		{Name: "width", Value: "+" + jscompat.NumberString() + },
		{Name: "height", Value: },
		{Name: "depth", Value: },
		{Name: "lspace", Value: },
	}
}

func paddingUnit( string) string {
	// JavaScript's dot does not match line terminators, so the source
	// /^.*?([a-z]*)$/ replacement leaves such a value entirely unchanged.
	if strings.ContainsAny(, "\n\r\u2028\u2029") {
		return 
	}
	return trailingUnit.FindString()
}

func parseFloat( string) float64 {
	 := parseFloatPrefix.FindString()
	if  == "" {
		return math.NaN()
	}
	if  == "+Infinity" ||  == "Infinity" {
		return math.Inf(1)
	}
	if  == "-Infinity" {
		return math.Inf(-1)
	}
	,  := strconv.ParseFloat(, 64)
	if  != nil && !math.IsInf(, 0) {
		return math.NaN()
	}
	return 
}