Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d54fdc1
add hydrate
gaymeowing Sep 19, 2026
a50320e
oops i forgot to export hydrate, and fix the export for PropertiesFor
gaymeowing Sep 19, 2026
d7f90b9
format (i hate stylua mandating that requires need to be ascending in…
gaymeowing Sep 19, 2026
97c78a7
fix optional value source type errs (#65)
nnullcolumn Sep 23, 2026
5b7f457
update instances list
gaymeowing Sep 24, 2026
347d71d
Merge branch 'main' into hydrate
gaymeowing Sep 24, 2026
f05a71c
add hydrate to docs
gaymeowing Sep 27, 2026
4a0f4d5
* update bind to have better types
gaymeowing Sep 27, 2026
6a9d0dc
formatting
gaymeowing Sep 27, 2026
5b5c01e
appease stylua having the worst require formatting style
gaymeowing Sep 27, 2026
b195e9d
initial commit
gaymeowing Sep 27, 2026
341945c
copy over stuff from old stylesheet branch
gaymeowing Sep 27, 2026
154fc00
sync
gaymeowing Sep 27, 2026
403c632
Finalize style sheet wrapper
gaymeowing Sep 27, 2026
a8b76fd
add fluid.style_sheet to API Overview
gaymeowing Sep 27, 2026
cdc1d1a
* style_sheet bug fixes
gaymeowing Sep 27, 2026
8502349
fix typo & remove unnecessary code
gaymeowing Sep 28, 2026
8d26c15
add todo about read_only_properties
gaymeowing Sep 28, 2026
d04d210
fix props type kindof (i cannot be bothered to make a giant union of …
gaymeowing Sep 28, 2026
69a2592
add PseudoInstances to instance_types
gaymeowing Sep 29, 2026
f0e5309
* add _conditions to queries defined in _queries for rules, allowing …
gaymeowing Sep 30, 2026
b999b7e
change PseudoSelector non string type error message
gaymeowing Sep 30, 2026
cf3920c
add comment to underive about why it doesn't do any type function stuff
gaymeowing Sep 30, 2026
6ccc4ef
typo fix
gaymeowing Sep 30, 2026
1b6803f
remove useless comments
gaymeowing Sep 30, 2026
5b313cc
seperate query instance creation into its own function & improve erro…
gaymeowing Oct 1, 2026
72ca4ea
add comment about _priority in pseudo-instances
gaymeowing Oct 1, 2026
73e9fbe
fix StyleSheet:query()
gaymeowing Oct 1, 2026
858fc43
format
gaymeowing Oct 1, 2026
1359896
add UIGradient as an allowed pseudo-instance child to UIShadow
gaymeowing Oct 15, 2026
7e79a09
add UIBlur to the PseudoInstances list
gaymeowing Oct 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"prettier.useTabs": true,

"luau-lsp.completion.imports.stringRequires.enabled": true,

"luau-lsp.types.definitionFiles": ["types/globals.d.luau"],


"luau-lsp.sourcemap.autogenerate": false,
"luau-lsp.sourcemap.enabled": false,
"luau-lsp.sourcemap.includeNonScripts": true,
Expand Down
1 change: 1 addition & 0 deletions docs/guides/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fluid = "ffrostfall/fluid@<release>"
# API overview

- fluid.create("Frame")({ property = value })
- fluid.style_sheet()
- fluid.source()
- fluid.async()
- fluid.derive()
Expand Down
6 changes: 5 additions & 1 deletion src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local effect = require("@self/reactive/effect")
local for_keys = require("@self/instances/for_keys")
local for_values = require("@self/instances/for_values")
local graph = require("@self/reactive/graph")
local instance_types = require("@self/instances/types")
local interval = require("@self/utils/interval")
local lerp = require("@self/anim/lerp")
local mount = require("@self/instances/mount")
Expand All @@ -20,16 +21,18 @@ local show = require("@self/utils/show")
local show_delay = require("@self/utils/show_delay")
local source = require("@self/reactive/source")
local spring = require("@self/anim/spring/spring_file")
local style_sheet = require("@self/instances/style_sheet")
local switch = require("@self/utils/switch")
local switch_delay = require("@self/utils/switch_delay")
local tags = require("@self/utils/tags")
local types = require("@self/reactive/types")
local untrack = require("@self/reactive/untrack")

export type StyleSheet<Tokens = {}, Tags = {}, Queries = {}> = style_sheet.Sheet<Tokens, Tags, Queries>
export type UsedAs<T> = types.UsedAs<T>
export type Source<T> = types.Source<T>
export type Action = action.Identity
export type PropertiesFor<T> = create.PropertiesFor<T>
export type PropertiesFor<I> = instance_types.PropertiesFor<I>

local scheduler_thread: thread? = nil

Expand Down Expand Up @@ -59,6 +62,7 @@ end

local fluid = {}

fluid.style_sheet = style_sheet
fluid.create = create
fluid.mount = mount
fluid.tags = tags
Expand Down
25 changes: 13 additions & 12 deletions src/instances/bind.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local action = require("./action")
local graph = require("../reactive/graph")
local types = require("../reactive/types")
local instance_types = require("./types")
local reactive_types = require("../reactive/types")

local function set_property(inst: Instance, property: string, value: any)
(inst :: any)[property] = value
Expand All @@ -10,7 +11,7 @@ local function get_property(inst: Instance, property: string): any
return (inst :: any)[property]
end

local function bind_property<T>(inst: Instance, property: string, value: types.Readable<T>)
local function bind_property<T>(inst: Instance, property: string, value: reactive_types.Readable<T>)
local property_node = graph.create_reactive_node(graph.assert_stable_parent(), function()
set_property(inst, property, value())
return nil
Expand Down Expand Up @@ -101,17 +102,17 @@ local function bind_reactive_child(inst: Instance, func: () -> Result)
graph.evaluate_node(property_node)
end

local function bind(inst: Instance, props: { [unknown & number]: unknown })
for key: any, value: any in props do
local function bind<I>(instance: I & Instance, props: instance_types.PropertiesFor<I>): I
for key, value in props :: any do
local key_type, value_type = type(key), typeof(value)

if key_type == "string" then
local property_value = get_property(inst, key)
local property_value = get_property(instance, key)
if typeof(property_value) ~= "RBXScriptSignal" then
if value_type == "function" then
bind_property(inst, key, value)
bind_property(instance, key, value)
else
set_property(inst, key, value)
set_property(instance, key, value)
end
elseif value_type == "function" then
local connection = property_value:Connect(value)
Expand All @@ -122,19 +123,19 @@ local function bind(inst: Instance, props: { [unknown & number]: unknown })
end
else
if value_type == "Instance" then
value.Parent = inst
value.Parent = instance
elseif value_type == "table" then
if value.__ACTION_SYMBOL == action.symbol then
value.callback(inst)
value.callback(instance)
else
bind(inst, value)
bind(instance, value)
end
elseif value_type == "function" then
bind_reactive_child(inst, value)
bind_reactive_child(instance, value)
end
end
end
return inst
return instance
end

return bind
216 changes: 4 additions & 212 deletions src/instances/create.luau
Original file line number Diff line number Diff line change
@@ -1,214 +1,5 @@
local action = require("./action")
local bind = require("./bind")

type Instances = {
PyramidHandleAdornment: PyramidHandleAdornment,
AudioChannelSplitter: AudioChannelSplitter,
AudioPitchShifter: AudioPitchShifter,
AudioDeviceOutput: AudioDeviceOutput,
AudioChannelMixer: AudioChannelMixer,
AudioTextToSpeech: AudioTextToSpeech,
AudioDeviceInput: AudioDeviceInput,
AudioDistortion: AudioDistortion,
AudioCompressor: AudioCompressor,
AudioEqualizer: AudioEqualizer,
AudioAnalyzer: AudioAnalyzer,
AudioListener: AudioListener,
AudioRecorder: AudioRecorder,
AudioLimiter: AudioLimiter,
AudioFlanger: AudioFlanger,
AudioEmitter: AudioEmitter,
AudioPlayer: AudioPlayer,
AudioReverb: AudioReverb,
AudioFilter: AudioFilter,
ArcHandles: ArcHandles,
AudioFader: AudioFader,
AudioEcho: AudioEcho,
AdGui: AdGui,
BoxHandleAdornment: BoxHandleAdornment,
BillboardGui: BillboardGui,
BlurEffect: BlurEffect,
CylinderHandleAdornment: CylinderHandleAdornment,
ConeHandleAdornment: ConeHandleAdornment,
CanvasGroup: CanvasGroup,
Camera: Camera,
DialogChoice: DialogChoice,
DragDetector: DragDetector,
Dialog: Dialog,
Folder: Folder,
Frame: Frame,
Highlight: Highlight,
Handles: Handles,
ImageHandLeAdornment: ImageHandleAdornment,
InputActionLabel: InputActionLabel,
ImageButton: ImageButton,
ImageLabel: ImageLabel,
LineHandleAdornment: LineHandleAdornment,
ProximityPrompt: ProximityPrompt,
Path3D: Path3D,
Path2D: Path2D,
Part: Part,
SphereHandLeAdornment: SphereHandleAdornment,
SelectionSphere: SelectionSphere,
ScrollingFrame: ScrollingFrame,
SelectionBox: SelectionBox,
StyleDerive: StyleDerive,
StyleQuery: StyleQuery,
SurfaceGui: SurfaceGui,
StyleSheet: StyleSheet,
SoundGroup: SoundGroup,
StyleLink: StyleLink,
ScreenGui: ScreenGui,
StyleBase: StyleBase,
StyleRule: StyleRule,
Sound: Sound,
TextButton: TextButton,
TextLabel: TextLabel,
TextBox: TextBox,
UIAspectRatioConstraint: UIAspectRatioConstraint,
UITextSizeConstraint: UITextSizeConstraint,
UISizeConstraint: UISizeConstraint,
UIDragDetector: UIDragDetector,
UITableLayout: UITableLayout,
UIPageLayout: UIPageLayout,
UIGridLayout: UIGridLayout,
UIListLayout: UIListLayout,
UIGradient: UIGradient,
UIFlexItem: UIFlexItem,
UIPadding: UIPadding,
UIStroke: UIStroke,
UICorner: UICorner,
UIShadow: UIShadow,
UIScale: UIScale,
ViewportCamera: ViewportCamera,
ViewportFrame: ViewportFrame,
VideoDisplay: VideoDisplay,
VideoFrame: VideoFrame,
WireframeHandleAdornment: WireframeHandleAdornment,
WorldModel: WorldModel,
Wire: Wire,
}

type UnknownConnectCallback = (...any) -> ()

type Signal = RBXScriptSignal

type function get_connect(v: type): type?
local connect = v:readproperty(types.singleton("Connect"))

if connect and connect:is("function") then
local head = connect:parameters().head

if not head then
return nil
end
local callback = head[2]

if callback and callback:is("function") then
return callback
end
end

return nil
end

type function is_signal(v: type): type?
if v == Signal and v.tag == "extern" then
return UnknownConnectCallback
-- luau lsp types RBXScriptSignals as tables
elseif v.tag == "table" then
local connect = get_connect(v)

if connect then
return connect
end

-- i cba to test if this is needed or not
local metatable = v:metatable()

if metatable then
connect = get_connect(metatable)

if connect then
return connect
end
end
end

return nil
end

type instance = Instance

type Action = action.Identity

type function GetInstance(class_name: type, instances: type): type
if not class_name:is("singleton") then
return instance
end

return instances:readproperty(class_name) or instance
end

export type function PropertiesFor(class_name: type): type
local object = GetInstance(class_name, Instances)
local head_table = {}
local args_table = { head = head_table }
local properties = types.newtable()
local current = object
local empty_table = {}

local read_only_properties = table.freeze({
types.singleton("RobloxLocked"),
types.singleton("ClassName"),
types.singleton("UniqueId"),
})

while current do
for property, value in current:properties() do
if table.find(read_only_properties, property) then
continue
end

local value_read = value.read
local callback = is_signal(value_read)

if callback then
properties:setproperty(property, types.optional(callback))
elseif value_read.tag == "function" or value_read.tag == "intersection" then
continue
elseif value.write then
head_table[1] = value_read

properties:setproperty(
property,
types.optional(
types.unionof(types.newfunction(empty_table :: any, args_table :: any), value.write)
)
)
end
end

current = current:readparent()
end

-- Functions returning a child can return an array of children, or alike functions, nested to any level
local function_returns_child = types.newfunction()
local child_only_union = types.unionof(function_returns_child, instance)

-- TODO: Use a read only indexer when released to properly accept children which are subtypes of `Instance`
-- TODO: Nesting throws a type error, seemingly a solver bug caused whenever the keys are a union instead of direct type
-- Happens even with a union between `Instance` and `any`, but disappears when it's just `Instance`
local nested_table_or_function_or_child = types.newtable()
local nested_child_union = types.unionof(child_only_union, nested_table_or_function_or_child)
nested_table_or_function_or_child:setindexer(types.number, nested_child_union)
function_returns_child:setreturns({ nested_child_union })

local full_union = types.unionof(child_only_union, Action, properties)
properties:setindexer(types.number, types.optional(full_union))

return properties
end
local types = require("./types")

local function try_create_instance(class_name: string): Instance
local success, call_result = pcall(Instance.new, class_name)
Expand All @@ -217,9 +8,10 @@ local function try_create_instance(class_name: string): Instance
return call_result
end

--stylua: ignore
local function create<ClassName>(
class_name: ClassName | keyof<Instances> | ""
): (props: PropertiesFor<ClassName>) -> GetInstance<ClassName, Instances>
class_name: ClassName | keyof<types.Instances> | ""
): (props: types.PropertiesFor<ClassName>) -> types.GetInstance<ClassName, types.Instances>
return function(properties)
return bind(try_create_instance(class_name), properties) :: any
end
Expand Down
Loading
Loading