local s=require(script.Parent:WaitForChild("\077\097\105\100"))local Q=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local a=game:GetService("\082\117\110\083\101\114\118\105\099\101")local i=.0225 local q=Vector3.new(1,-1,1)local U={[Enum.UserInputType.MouseButton1]=true,[Enum.UserInputType.Touch]=true}local z={[Enum.UserInputType.MouseMovement]=true;[Enum.UserInputType.Touch]=true}local u={}u.__index=u u.ClassName="\068\114\097\103\103\101\114"function u.new(Q)local a=setmetatable({},u)a._Maid=s.new()a._DragBind=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")a._StartBind=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")a._StopBind=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")a.Element=Q a.IsDragging=false a.DragChanged=a._DragBind.Event a.DragStart=a._StartBind.Event a.DragStop=a._StopBind.Event init(a)return a end function init(s)local a=s.Element local i=s._Maid local q=s._DragBind local u=Vector3.new()i:Mark(s._DragBind)i:Mark(s._StartBind)i:Mark(s._StopBind)i:Mark(a.InputBegan:Connect(function(Q)if U[Q.UserInputType]then u=Q.Position s.IsDragging=true s._StartBind:Fire()end end))i:Mark(Q.InputEnded:Connect(function(Q)if U[Q.UserInputType]then s.IsDragging=false s._StopBind:Fire()end end))i:Mark(Q.InputChanged:Connect(function(Q,i)if s.IsDragging then if z[Q.UserInputType]then local s=Q.Position-u u=Q.Position q:Fire(a,Q,s)end end end))end function u.Destroy(s)s._Maid:Sweep()s.DragChanged=nil s.DragStart=nil s.DragStop=nil s.Element=nil end return u
local Maid = require(script.Parent:WaitForChild("Maid"))

-- CONSTANTS

local UIS = game:GetService("UserInputService")
local RUNSERVICE = game:GetService("RunService")

local DEADZONE2 = 0.15^2
local FLIP_THUMB = Vector3.new(1, -1, 1)

local VALID_PRESS = {
	[Enum.UserInputType.MouseButton1] = true;
	[Enum.UserInputType.Touch] = true;
}

local VALID_MOVEMENT = {
	[Enum.UserInputType.MouseMovement] = true;
	[Enum.UserInputType.Touch] = true;
}

-- Class

local DraggerClass = {}
DraggerClass.__index = DraggerClass
DraggerClass.ClassName = "Dragger"

-- Public Constructors

function DraggerClass.new(element)
	local self = setmetatable({}, DraggerClass)
	
	self._Maid = Maid.new()
	self._DragBind = Instance.new("BindableEvent")
	self._StartBind = Instance.new("BindableEvent")
	self._StopBind = Instance.new("BindableEvent")
	
	self.Element = element
	self.IsDragging = false
	self.DragChanged = self._DragBind.Event
	self.DragStart = self._StartBind.Event
	self.DragStop = self._StopBind.Event
	
	init(self)
	
	return self
end

-- Private Methods

function init(self)
	local element = self.Element
	local maid = self._Maid
	local dragBind = self._DragBind
	local lastMousePosition = Vector3.new()
	
	maid:Mark(self._DragBind)
	maid:Mark(self._StartBind)
	maid:Mark(self._StopBind)
	
	maid:Mark(element.InputBegan:Connect(function(input)
		if (VALID_PRESS[input.UserInputType]) then
			lastMousePosition = input.Position
			self.IsDragging = true
			self._StartBind:Fire()
		end
	end))
	
	maid:Mark(UIS.InputEnded:Connect(function(input)
		if (VALID_PRESS[input.UserInputType]) then
			self.IsDragging = false
			self._StopBind:Fire()
		end
	end))
	
	maid:Mark(UIS.InputChanged:Connect(function(input, process)
		if (self.IsDragging) then
			if (VALID_MOVEMENT[input.UserInputType]) then
				local delta = input.Position - lastMousePosition
				lastMousePosition = input.Position
				dragBind:Fire(element, input, delta)
			end
		end
	end))
end

-- Public Methods

function DraggerClass:Destroy()
	self._Maid:Sweep()
	self.DragChanged = nil
	self.DragStart = nil
	self.DragStop = nil
	self.Element = nil
end

--

return DraggerClass