// Copyright 2017-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// This file is a Go translation and modification of MathJax 3.2.2.

package svg

import (
	

	
	
	
)

// CommonMfrac constructs the slash after its authored children are wrapped.
// Keep its node separate from the input MathML, and size it once, just as the
// original constructor does rather than recreating it during bbox queries.
func ( *wrapper) () {
	if len(.children) < 2 || !boolAttributeDefault(.node, "bevelled", false) {
		return
	}
	, , , ,  := .bevelData(.fractionDisplay())
	 := math.Max(.Scale*(.H+.D),
		.Scale*(.H+.D)) + 2*

	 := syntheticMMLFactory.Create("mo", mml.NewText("/"))
	.Flags.Token, .Flags.Embellished = true, true
	.Attributes.Set("stretchy", true)
	// AbstractMmlNode.inheritAttributesFrom copies only these effective values,
	// not authored IDs, fonts, colors, or other fraction attributes.
	.Attributes.SetInherited("displaystyle", attribute(.node, "displaystyle", .displayStyle))
	.Attributes.SetInherited("scriptlevel", attribute(.node, "scriptlevel", .scriptLevel))
	if .node.Attributes.IsSet("mathsize") {
		.Attributes.SetInherited("mathsize", attribute(.node, "mathsize", "normal"))
	}
	if ,  := .node.Property("texprimestyle");  && truthy() {
		.SetProperty("texprimestyle", true)
	}
	.bevel = .renderer.wrap(, , .scriptLevel, .displayStyle)
	.Attributes.Set("symmetric", true)
	.bevel.canStretch(font.DirectionVertical)
	.bevel.getStretchedVariant([]float64{}, true)
}

func ( *wrapper) () float64 {
	if ,  := .node.Property("withDelims");  && truthy() {
		return 0
	}
	return .renderer.params.NullDelimiterSpace
}

func ( *wrapper) () bool { return .displayStyle && .scriptLevel == 0 }

func ( *wrapper) () float64 {
	return layout.Length2Em(attribute(.node, "linethickness", "medium"), .06, .bbox.Scale, .renderer.pxPerEm)
}

func ( *wrapper) ( *layout.BBox) {
	.Empty()
	if len(.children) < 2 {
		.Clean()
		return
	}
	 := .fractionDisplay()
	 := .fractionThickness()
	if boolAttributeDefault(.node, "bevelled", false) {
		.computeBevelledBBox(, )
	} else if  == 0 {
		, , , ,  := .fractionUVQ()
		.Combine(, 0, )
		.Combine(, 0, -)
		.W += 2 * .fractionPad()
	} else {
		 := .children[0].outerBBox()
		 := .children[1].outerBBox()
		 := .renderer.params.Axis
		, ,  := .fractionTUV(, )
		.Combine(, 0, ++math.Max(.D*.RScale, ))
		.Combine(, 0, --math.Max(.H*.RScale, ))
		.W += 2*.fractionPad() + .2
	}
	.Clean()
}

func ( *wrapper) ( bool,  float64) (, ,  float64) {
	 := .renderer.params
	if  {
		 = 3.5 * 
		 = .Num1 - .Axis - 
		 = .Denom1 + .Axis - 
	} else {
		 = 1.5 * 
		 = .Num2 - .Axis - 
		 = .Denom2 + .Axis - 
	}
	return
}

func ( *wrapper) ( bool) (, ,  float64, ,  *layout.BBox) {
	 = .children[0].outerBBox()
	 = .children[1].outerBBox()
	 := .renderer.params
	if  {
		,  = .Num1, .Denom1
	} else {
		,  = .Num3, .Denom2
	}
	 := 3 * .Rule
	if  {
		 = 7 * .Rule
	}
	 = ( - .D*.Scale) - (.H*.Scale - )
	if  <  {
		 += ( - ) / 2
		 += ( - ) / 2
		 = 
	}
	return
}

func ( *wrapper) ( *layout.BBox,  bool) {
	, , , ,  := .bevelData()
	.Combine(, 0, )
	.Combine(.bevel.outerBBox(), .W-/2, 0)
	.Combine(, .W-/2, )
}

func ( *wrapper) ( bool) (, ,  float64, ,  *layout.BBox) {
	 = .children[0].outerBBox()
	 = .children[1].outerBBox()
	 = .15
	if  {
		 = .4
	}
	 := .renderer.params.Axis
	 = .Scale*(.D-.H)/2 +  + 
	 = .Scale*(.D-.H)/2 +  - 
	return
}

func ( *wrapper) ( *Element) {
	 := .standardSVG()
	if len(.children) < 2 {
		return
	}
	if boolAttributeDefault(.node, "bevelled", false) {
		.bevelledToSVG(, .fractionDisplay())
		return
	}
	 := .fractionThickness()
	if  == 0 {
		.atopToSVG(, .fractionDisplay())
	} else {
		.ruledFractionToSVG(, .fractionDisplay(), )
	}
}

func ( *wrapper) ( *Element,  bool,  float64) {
	,  := .children[0], .children[1]
	,  := .outerBBox(), .outerBBox()
	 := math.Max((.L+.W+.R)*.RScale, (.L+.W+.R)*.RScale)
	 := .fractionPad()
	 := alignX(, , stringAttribute(.node, "numalign", "center")) + .1 + 
	 := alignX(, , stringAttribute(.node, "denomalign", "center")) + .1 + 
	, ,  := .fractionTUV(, )
	 := .renderer.params.Axis
	.toSVG()
	.place(, ++math.Max(.D*.RScale, ))
	.toSVG()
	.place(, --math.Max(.H*.RScale, ))
	.Append(NewElement("rect").
		SetAttr("width", fixed(+2*.1)).
		SetAttr("height", fixed()).
		SetAttr("x", fixed()).
		SetAttr("y", fixed(-/2)))
}

func ( *wrapper) ( *Element,  bool) {
	,  := .children[0], .children[1]
	,  := .outerBBox(), .outerBBox()
	 := math.Max((.L+.W+.R)*.RScale, (.L+.W+.R)*.RScale)
	 := .fractionPad()
	 := alignX(, , stringAttribute(.node, "numalign", "center")) + 
	 := alignX(, , stringAttribute(.node, "denomalign", "center")) + 
	, , , ,  := .fractionUVQ()
	.toSVG()
	.place(, )
	.toSVG()
	.place(, -)
}

func ( *wrapper) ( *Element,  bool) {
	,  := .children[0], .children[1]
	, , , ,  := .bevelData()
	 := (.L + .W + .R) * .RScale
	.toSVG()
	.bevel.toSVG()
	.toSVG()
	.place(.L*.RScale, )
	.bevel.place(-/2, 0)
	.place(+.bevel.outerBBox().W+.L*.RScale-, )
}

func alignX( float64,  *layout.BBox,  string) float64 {
	switch  {
	case "right":
		return  - (.W+.R)*.RScale
	case "left":
		return .L * .RScale
	default:
		return ( - .W*.RScale) / 2
	}
}