local Y=require(game.ReplicatedStorage.Packages.Fusion)local p=Y.New local r=Y.Children local b=Y.OnEvent local h=Y.OnChange local D=Y.State local g=Y.Computed local P=Y.Spring local m=game:GetService("\087\111\114\107\115\112\097\099\101")local L=game:GetService("\071\117\105\083\101\114\118\105\099\101")local s=m.CurrentCamera local z,f=L:GetGuiInset()local function n(Y)local r=D()local function b()local p=Y.Size local b=s.ViewportSize-(z+f)r:set(1/math.max(p.X/b.X,p.Y/b.Y))end b();(s:GetPropertyChangedSignal("\086\105\101\119\112\111\114\116\083\105\122\101")):Connect(b)return(p("\085\073\083\099\097\108\101"))({Scale=g(function()return r:get()*Y.Scale end)})end return n


local Fusion = require(game.ReplicatedStorage.Packages.Fusion)
local New = Fusion.New
local Children = Fusion.Children
local OnEvent = Fusion.OnEvent
local OnChange = Fusion.OnChange
local State = Fusion.State
local Computed = Fusion.Computed
local Spring = Fusion.Spring


local Workspace = game:GetService("Workspace")
local GuiService = game:GetService("GuiService")

local Camera = Workspace.CurrentCamera
local TopInset, BottomInset = GuiService:GetGuiInset()



local function UIScale(props)
	--props:  Size = v3   Scale = float
	local	ScaleState = State()

	local function update()
		local currentSize = props.Size
		local viewportSize = Camera.ViewportSize - (TopInset + BottomInset)
	
		ScaleState:set(1 / math.max(
			currentSize.X / viewportSize.X,
			currentSize.Y / viewportSize.Y
		))
	end

	update()
	Camera:GetPropertyChangedSignal("ViewportSize"):Connect(update)

	return New "UIScale" {
		Scale = Computed(function()
			return ScaleState:get() * props.Scale
		end)
	}
end


return UIScale
