local s=Vector2.new(math.huge,math.huge)function TextLabel.getSize(m)if not(m.props.Width or m.props.Height or m.props.Size=="\087\082\065\080\095\067\079\078\084\069\078\084")then return m.props.Size end local h,f if typeof(m.props.Width)=="\085\068\105\109"then h=m.props.Width elseif typeof(m.props.Height)=="\085\068\105\109"then f=m.props.Height end local S=m.props.TextSize if m.props.TextScaled and m.AbsoluteSize then S=m.AbsoluteSize.Y end local I=TextService:GetTextSize(m.props.Text,S,m.props.Font,s)if not h and(m.props.Width=="\087\082\065\080\095\067\079\078\084\069\078\084"or m.props.Size=="\087\082\065\080\095\067\079\078\084\069\078\084")then h=UDim.new(0,I.X)end if not f and(m.props.Height=="\087\082\065\080\095\067\079\078\084\069\078\084"or m.props.Size=="\087\082\065\080\095\067\079\078\084\069\078\084")then f=UDim.new(0,I.Y)end return UDim2.new(h or m.props.Size and m.props.Size.X or UDim.new(),f or m.props.Size and m.props.Size.Y or UDim.new())end function TextLabel.updateSize(s)if not s.Mounted then return end local m=s:getSize()local h=s.props.TextScaled and(s.AbsoluteSize and s.AbsoluteSize.Y)or s.props.TextSize if s.state.Size~=m or s.state.TextSize~=h then s:setState({Size=m,TextSize=h})end end function TextLabel.init(s)s.Updating=true s.state={Size=UDim2.new(),TextSize=0}end function TextLabel.willUpdate(h,s,m)h.Updating=true end function TextLabel.render(s)local m=Support.Merge({},s.props,{Size=s.state.Size;TextSize=s.state.TextSize,TextScaled=false;[Roact.Ref]=function(m)s.AbsoluteSize=m and m.AbsoluteSize or s.AbsoluteSize end;[Roact.Change.AbsoluteSize]=function(m)s.AbsoluteSize=m.AbsoluteSize if not s.Updating then s:updateSize()end end})if type(m.TextColor)=="\115\116\114\105\110\103"then local s,h,f=(m.TextColor:lower()):match("\035\063\040\046\046\041\040\046\046\041\040\046\046\041")m.TextColor3=Color3.fromRGB(tonumber(s,16),tonumber(h,16),tonumber(f,16))end local h=Support.Merge({},s.props[Roact.Children])m.Width=nil m.Height=nil m.Bold=nil m.TextColor=nil m.AspectRatio=nil m[Roact.Children]=nil if s.props.AspectRatio then local m=new("\085\073\065\115\112\101\099\116\082\097\116\105\111\067\111\110\115\116\114\097\105\110\116",{AspectRatio=s.props.AspectRatio})h.AspectRatio=m end if s.props.Bold then local s=Support.CloneTable(m)s.Size=UDim2.new(1,0,1,0)s.Position=nil s.TextScaled=true s.AnchorPoint=nil h.Bold=new(TextLabel,s)end return new("\084\101\120\116\076\097\098\101\108",m,h)end function TextLabel.didMount(s)s.Updating=nil s.Mounted=true s:updateSize()end function TextLabel.willUnmount(s)s.Mounted=nil end function TextLabel.didUpdate(h,s,m)h.Updating=nil h:updateSize()end return TextLabel

local INFINITE_BOUNDS = Vector2.new(math.huge, math.huge)

function TextLabel:getSize()

    -- Return size directly if fixed
    if not (self.props.Width or self.props.Height or self.props.Size == 'WRAP_CONTENT') then
        return self.props.Size
    end

    -- Get fixed sizes for individual axes
    local Width, Height
    if typeof(self.props.Width) == 'UDim' then
        Width = self.props.Width
    elseif typeof(self.props.Height) == 'UDim' then
        Height = self.props.Height
    end

    -- Get text size from height if autoscaled
    local TextSize = self.props.TextSize
    if self.props.TextScaled and self.AbsoluteSize then
        TextSize = self.AbsoluteSize.Y
    end

    -- Calculate content bounds
    local Bounds = TextService:GetTextSize(
        self.props.Text,
        TextSize,
        self.props.Font,
        INFINITE_BOUNDS
    )

    -- Set width and height based on content if requested
    if not Width and (self.props.Width == 'WRAP_CONTENT' or self.props.Size == 'WRAP_CONTENT') then
        Width = UDim.new(0, Bounds.X)
    end
    if not Height and (self.props.Height == 'WRAP_CONTENT' or self.props.Size == 'WRAP_CONTENT') then
        Height = UDim.new(0, Bounds.Y)
    end

    -- Return the calculated size
    return UDim2.new(
        Width or (self.props.Size and self.props.Size.X) or UDim.new(),
        Height or (self.props.Size and self.props.Size.Y) or UDim.new()
    )

end

function TextLabel:updateSize()
    if not self.Mounted then
        return
    end

    -- Calculate new size
    local Size = self:getSize()
    local TextSize = self.props.TextScaled and
        (self.AbsoluteSize and self.AbsoluteSize.Y) or
        self.props.TextSize

    -- Check if state is outdated
    if self.state.Size ~= Size or
        self.state.TextSize ~= TextSize then

        -- Update state
        self:setState {
            Size = Size,
            TextSize = TextSize
        }
    end
end

function TextLabel:init()
    self.Updating = true
    self.state = {
        Size = UDim2.new(),
        TextSize = 0
    }
end

function TextLabel:willUpdate(nextProps, nextState)
    self.Updating = true
end

function TextLabel:render()
    local props = Support.Merge({}, self.props, {

        -- Override size
        Size = self.state.Size,
        TextSize = self.state.TextSize,
        TextScaled = false,

        -- Get initial size
        [Roact.Ref] = function (rbx)
            self.AbsoluteSize = rbx and
                rbx.AbsoluteSize or
                self.AbsoluteSize
        end,

        -- Track size changes
        [Roact.Change.AbsoluteSize] = function (rbx)
            self.AbsoluteSize = rbx.AbsoluteSize
            if not self.Updating then
                self:updateSize()
            end
        end

    })

    -- Parse hex colors
    if type(props.TextColor) == 'string' then
        local R, G, B = props.TextColor:lower():match('#?(..)(..)(..)')
        props.TextColor3 = Color3.fromRGB(tonumber(R, 16), tonumber(G, 16), tonumber(B, 16))
    end

    -- Separate children from props
    local children = Support.Merge({}, self.props[Roact.Children])

    -- Clear invalid props
    props.Width = nil
    props.Height = nil
    props.Bold = nil
    props.TextColor = nil
    props.AspectRatio = nil
    props[Roact.Children] = nil

    -- Include aspect ratio constraint if specified
    if self.props.AspectRatio then
        local Constraint = new('UIAspectRatioConstraint', {
            AspectRatio = self.props.AspectRatio
        })

        -- Insert constraint into children
        children.AspectRatio = Constraint
    end

    -- Add a bold layer if specified
    if self.props.Bold then
        local BoldProps = Support.CloneTable(props)
        BoldProps.Size = UDim2.new(1, 0, 1, 0)
        BoldProps.Position = nil
        BoldProps.TextScaled = true
        BoldProps.AnchorPoint = nil
        children.Bold = new(TextLabel, BoldProps)
    end

    -- Display component in wrapper
    return new('TextLabel', props, children)

end

function TextLabel:didMount()
    self.Updating = nil
    self.Mounted = true
    self:updateSize()
end

function TextLabel:willUnmount()
    self.Mounted = nil
end

function TextLabel:didUpdate(previousProps, previousState)
    self.Updating = nil
    self:updateSize()
end

return TextLabel
