local M=require(script.Parent.Parent.Creator)local B=require(script.Parent.CreateAcrylic)local f,e=unpack(require(script.Parent.Utils))local D=Instance.new("\070\111\108\100\101\114",(game:GetService("\087\111\114\107\115\112\097\099\101")).CurrentCamera)local function A(M)local A={}M=M or.001 local n={topLeft=Vector2.new();topRight=Vector2.new();bottomRight=Vector2.new()}local H=B()H.Parent=D local function b(M,B)n.topLeft=B n.topRight=B+Vector2.new(M.X,0)n.bottomRight=B+M end local function d()local B=(game:GetService("\087\111\114\107\115\112\097\099\101")).CurrentCamera if B then B=B.CFrame end local e=B if not e then e=CFrame.new()end local D=e local A=n.topLeft local b=n.topRight local d=n.bottomRight local z=f(A,M)local p=f(b,M)local s=f(d,M)local C=(p-z).Magnitude local R=(p-s).Magnitude H.CFrame=CFrame.fromMatrix((z+s)/2,D.XVector,D.YVector,D.ZVector)H.Mesh.Scale=Vector3.new(C,R,0)end local function z(M)local B=e()local f=M.AbsoluteSize-Vector2.new(B,B)local D=M.AbsolutePosition+Vector2.new(B/2,B/2)b(f,D)task.spawn(d)end local function p()local M=(game:GetService("\087\111\114\107\115\112\097\099\101")).CurrentCamera if not M then return end table.insert(A,(M:GetPropertyChangedSignal("\067\070\114\097\109\101")):Connect(d))table.insert(A,(M:GetPropertyChangedSignal("\086\105\101\119\112\111\114\116\083\105\122\101")):Connect(d))table.insert(A,(M:GetPropertyChangedSignal("\070\105\101\108\100\079\102\086\105\101\119")):Connect(d))task.spawn(d)end H.Destroying:Connect(function()for M,B in A do pcall(function()B:Disconnect()end)end end)p()return z,H end return function(B)local f={}local e,D=A(B)local n=M.New("\070\114\097\109\101",{BackgroundTransparency=1,Size=UDim2.fromScale(1,1)})M.AddSignal(n:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110"),function()e(n)end)M.AddSignal(n:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101"),function()e(n)end)f.AddParent=function(B)M.AddSignal(B:GetPropertyChangedSignal("\086\105\115\105\098\108\101"),function()f.SetVisibility(B.Visible)end)end f.SetVisibility=function(M)D.Transparency=M and.98 or 1 end f.Frame=n f.Model=D return f end
local Creator = require(script.Parent.Parent.Creator)
local createAcrylic = require(script.Parent.CreateAcrylic)
local viewportPointToWorld, getOffset = unpack(require(script.Parent.Utils))

local BlurFolder = Instance.new("Folder", game:GetService("Workspace").CurrentCamera)

local function createAcrylicBlur(distance)
	local cleanups = {}

	distance = distance or 0.001
	local positions = {
		topLeft = Vector2.new(),
		topRight = Vector2.new(),
		bottomRight = Vector2.new(),
	}
	local model = createAcrylic()
	model.Parent = BlurFolder

	local function updatePositions(size, position)
		positions.topLeft = position
		positions.topRight = position + Vector2.new(size.X, 0)
		positions.bottomRight = position + size
	end

	local function render()
		local res = game:GetService("Workspace").CurrentCamera
		if res then
			res = res.CFrame
		end
		local cond = res
		if not cond then
			cond = CFrame.new()
		end

		local camera = cond
		local topLeft = positions.topLeft
		local topRight = positions.topRight
		local bottomRight = positions.bottomRight

		local topLeft3D = viewportPointToWorld(topLeft, distance)
		local topRight3D = viewportPointToWorld(topRight, distance)
		local bottomRight3D = viewportPointToWorld(bottomRight, distance)

		local width = (topRight3D - topLeft3D).Magnitude
		local height = (topRight3D - bottomRight3D).Magnitude

		model.CFrame =
			CFrame.fromMatrix((topLeft3D + bottomRight3D) / 2, camera.XVector, camera.YVector, camera.ZVector)
		model.Mesh.Scale = Vector3.new(width, height, 0)
	end

	local function onChange(rbx)
		local offset = getOffset()
		local size = rbx.AbsoluteSize - Vector2.new(offset, offset)
		local position = rbx.AbsolutePosition + Vector2.new(offset / 2, offset / 2)

		updatePositions(size, position)
		task.spawn(render)
	end

	local function renderOnChange()
		local camera = game:GetService("Workspace").CurrentCamera
		if not camera then
			return
		end

		table.insert(cleanups, camera:GetPropertyChangedSignal("CFrame"):Connect(render))
		table.insert(cleanups, camera:GetPropertyChangedSignal("ViewportSize"):Connect(render))
		table.insert(cleanups, camera:GetPropertyChangedSignal("FieldOfView"):Connect(render))
		task.spawn(render)
	end

	model.Destroying:Connect(function()
		for _, item in cleanups do
			pcall(function()
				item:Disconnect()
			end)
		end
	end)

	renderOnChange()

	return onChange, model
end

return function(distance)
	local Blur = {}
	local onChange, model = createAcrylicBlur(distance)

	local comp = Creator.New("Frame", {
		BackgroundTransparency = 1,
		Size = UDim2.fromScale(1, 1),
	})

	Creator.AddSignal(comp:GetPropertyChangedSignal("AbsolutePosition"), function()
		onChange(comp)
	end)

	Creator.AddSignal(comp:GetPropertyChangedSignal("AbsoluteSize"), function()
		onChange(comp)
	end)

	Blur.AddParent = function(Parent)
		Creator.AddSignal(Parent:GetPropertyChangedSignal("Visible"), function()
			Blur.SetVisibility(Parent.Visible)
		end)
	end

	Blur.SetVisibility = function(Value)
		model.Transparency = Value and 0.98 or 1
	end

	Blur.Frame = comp
	Blur.Model = model

	return Blur
end
