// 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 (
	

	
	
	
)

func ( *wrapper) () int { return 0 }

func ( *wrapper) () int {
	if .node.Kind == "mroot" {
		return 1
	}
	return -1
}

func ( *wrapper) () int {
	if .node.Kind == "mroot" {
		return 2
	}
	return 1
}

func ( *wrapper) () {
	if len(.children) == 0 {
		return
	}
	 := mml.NewText("√")
	 := syntheticMMLFactory.Create("mo", )
	.Flags.Token = true
	.Flags.Embellished = true
	.TeXClass = mml.TeXClassOrd
	.Attributes.Set("stretchy", true)
	// CommonWrapper.createMo inherits the root's effective layout attributes
	// before wrapping the generated surd. In particular, its mathsize must
	// match the root so the radical is not scaled back to the default size.
	.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)
	}
	 := .renderer.wrap(, , .scriptLevel, .displayStyle)
	.children = append(.children, )
	.canStretch(font.DirectionVertical)
	 := .children[.rootBaseIndex()].outerBBox()
	 := .renderer.params.Rule
	 := 
	if .displayStyle {
		 = .renderer.params.XHeight
	}
	.surdHeight = .H + .D + 2* + /4
	.getStretchedVariant([]float64{.surdHeight - .D, .D}, true)
}

func ( *wrapper) ( *layout.BBox) (,  float64) {
	 := .renderer.params.Rule
	 = 
	if .displayStyle {
		 = .renderer.params.XHeight
	}
	if .H+.D > .surdHeight {
		 = ((.H + .D) - (.surdHeight - 2* - /2)) / 2
	} else {
		 =  + /4
	}
	return
}

func ( *wrapper) ( *layout.BBox,  float64) (, ,  float64) {
	if .node.Kind != "mroot" || .rootIndex() >= len(.children) {
		return 0, 0, 0
	}
	 := .children[.rootIndex()].outerBBox()
	 := .children[.surdIndex()]
	 := .6
	if .size < 0 {
		 = .5
	}
	// JavaScript rounds both products before the final subtraction.
	 := float64( * .W)
	 := math.Max(.W, /.RScale)
	 = math.Max(0, -.W)
	 := .H + .D
	 := .55 * 
	if .size < 0 {
		 = 1.9
	}
	 =  - ( - ) + math.Max(0, .D*.RScale)
	 = float64(*.RScale) - 
	return
}

func ( *wrapper) ( *layout.BBox) {
	,  := .rootBaseIndex(), .surdIndex()
	if  >= len(.children) ||  >= len(.children) {
		.computeChildrenBBox()
		return
	}
	 := .children[].getBBox()
	 := .children[].outerBBox()
	// CommonMsqrt constructs a new BBox from the radicand's dimensions.
	// Unlike Clone, that constructor resets scale and spacing metadata before
	// combining the base, so a local mathsize is not applied a second time.
	 := layout.NewBBox(.W, .H, .D)
	,  := .rootPQ()
	 := .renderer.params.Rule
	 := .H +  + 
	, ,  := .rootDimensions(, )
	.H =  + 
	if  := .rootIndex();  >= 0 &&  < len(.children) {
		.Combine(.children[].outerBBox(), 0, )
	}
	.Combine(, , -.H)
	.Combine(, +.W, 0)
	.Clean()
}

func ( *wrapper) ( *Element) {
	,  := .rootBaseIndex(), .surdIndex()
	if  >= len(.children) ||  >= len(.children) {
		return
	}
	 := .children[]
	 := .children[]
	 := .getBBox()
	 := .outerBBox()
	,  := .rootPQ()
	 := .renderer.params.Rule * .bbox.Scale
	 := .H +  + 
	 := .standardSVG()
	 := NewElement("g")
	.Append()
	if  := .rootIndex();  >= 0 &&  < len(.children) {
		 := .children[]
		.toSVG()
		, ,  := .rootDimensions(, )
		 := .outerBBox()
		.place(*.RScale, )
		.dx = 
	}
	.toSVG()
	.place(.dx, -.H)
	.toSVG()
	.place(.dx+.W, 0)
	.Append(NewElement("rect").
		SetAttr("width", fixed(.W)).
		SetAttr("height", fixed()).
		SetAttr("x", fixed(.dx+.W)).
		SetAttr("y", fixed(-)))
}