@snailycfx/stylesheet 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +3 -0
- package/LICENSE +21 -0
- package/out/core/engine/absolute.d.ts +10 -0
- package/out/core/engine/absolute.d.ts.map +1 -0
- package/out/core/engine/absolute.luau +86 -0
- package/out/core/engine/flex.d.ts +14 -0
- package/out/core/engine/flex.d.ts.map +1 -0
- package/out/core/engine/flex.luau +284 -0
- package/out/core/engine/grid.d.ts +9 -0
- package/out/core/engine/grid.d.ts.map +1 -0
- package/out/core/engine/grid.luau +306 -0
- package/out/core/engine/index.d.ts +14 -0
- package/out/core/engine/index.d.ts.map +1 -0
- package/out/core/engine/init.luau +179 -0
- package/out/core/engine/node.d.ts +25 -0
- package/out/core/engine/node.d.ts.map +1 -0
- package/out/core/engine/node.luau +84 -0
- package/out/core/index.d.ts +16 -0
- package/out/core/index.d.ts.map +1 -0
- package/out/core/init.luau +21 -0
- package/out/core/parse/color.d.ts +3 -0
- package/out/core/parse/color.d.ts.map +1 -0
- package/out/core/parse/color.luau +22 -0
- package/out/core/parse/grid.d.ts +18 -0
- package/out/core/parse/grid.d.ts.map +1 -0
- package/out/core/parse/grid.luau +158 -0
- package/out/core/parse/index.d.ts +5 -0
- package/out/core/parse/index.d.ts.map +1 -0
- package/out/core/parse/init.luau +13 -0
- package/out/core/parse/udim.d.ts +5 -0
- package/out/core/parse/udim.d.ts.map +1 -0
- package/out/core/parse/udim.luau +53 -0
- package/out/core/types/RbxStyle.d.ts +17 -0
- package/out/core/types/RbxStyle.d.ts.map +1 -0
- package/out/core/types/RbxStyle.luau +2 -0
- package/out/core/types/index.d.ts +11 -0
- package/out/core/types/index.d.ts.map +1 -0
- package/out/core/types/init.luau +2 -0
- package/out/core/types/primitives.d.ts +7 -0
- package/out/core/types/primitives.d.ts.map +1 -0
- package/out/core/types/primitives.luau +2 -0
- package/out/core/types/style/background.d.ts +10 -0
- package/out/core/types/style/background.d.ts.map +1 -0
- package/out/core/types/style/background.luau +2 -0
- package/out/core/types/style/border.d.ts +8 -0
- package/out/core/types/style/border.d.ts.map +1 -0
- package/out/core/types/style/border.luau +2 -0
- package/out/core/types/style/index.d.ts +9 -0
- package/out/core/types/style/index.d.ts.map +1 -0
- package/out/core/types/style/init.luau +2 -0
- package/out/core/types/style/layout.d.ts +23 -0
- package/out/core/types/style/layout.d.ts.map +1 -0
- package/out/core/types/style/layout.luau +2 -0
- package/out/core/types/style/misc.d.ts +7 -0
- package/out/core/types/style/misc.d.ts.map +1 -0
- package/out/core/types/style/misc.luau +2 -0
- package/out/core/types/style/position.d.ts +11 -0
- package/out/core/types/style/position.d.ts.map +1 -0
- package/out/core/types/style/position.luau +2 -0
- package/out/core/types/style/size.d.ts +11 -0
- package/out/core/types/style/size.d.ts.map +1 -0
- package/out/core/types/style/size.luau +2 -0
- package/out/core/types/style/spacing.d.ts +21 -0
- package/out/core/types/style/spacing.d.ts.map +1 -0
- package/out/core/types/style/spacing.luau +2 -0
- package/out/core/types/style/text.d.ts +14 -0
- package/out/core/types/style/text.d.ts.map +1 -0
- package/out/core/types/style/text.luau +2 -0
- package/out/core/writer/index.d.ts +8 -0
- package/out/core/writer/index.d.ts.map +1 -0
- package/out/core/writer/init.luau +505 -0
- package/out/elements/index.d.ts +44 -0
- package/out/elements/index.d.ts.map +1 -0
- package/out/elements/init.luau +316 -0
- package/out/index.d.ts +11 -0
- package/out/index.d.ts.map +1 -0
- package/out/init.luau +19 -0
- package/out/stylesheet/index.d.ts +25 -0
- package/out/stylesheet/index.d.ts.map +1 -0
- package/out/stylesheet/init.luau +71 -0
- package/package.json +37 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local _react = TS.import(script, TS.getModule(script, "@rbxts", "react"))
|
|
4
|
+
local React = _react
|
|
5
|
+
local useEffect = _react.useEffect
|
|
6
|
+
local useRef = _react.useRef
|
|
7
|
+
local useContext = _react.useContext
|
|
8
|
+
local _core = TS.import(script, script.Parent, "core")
|
|
9
|
+
local createNode = _core.createNode
|
|
10
|
+
local updateNodeStyle = _core.updateNodeStyle
|
|
11
|
+
local removeNode = _core.removeNode
|
|
12
|
+
local runLayout = _core.runLayout
|
|
13
|
+
local writeVisual = _core.writeVisual
|
|
14
|
+
local getRoot = _core.getRoot
|
|
15
|
+
local StyleSheet = TS.import(script, script.Parent, "stylesheet").StyleSheet
|
|
16
|
+
-- ── Context ───────────────────────────────────────────────────────────────────
|
|
17
|
+
local NodeContext = React.createContext(nil)
|
|
18
|
+
-- ── Tipos ─────────────────────────────────────────────────────────────────────
|
|
19
|
+
-- ── Hook central ──────────────────────────────────────────────────────────────
|
|
20
|
+
local function useLayoutNode(ref, style, className, disabled)
|
|
21
|
+
local parentNode = useContext(NodeContext)
|
|
22
|
+
local nodeRef = useRef()
|
|
23
|
+
local prevStyleRef = useRef()
|
|
24
|
+
-- Fusión de estilos — solo recalcular si alguno de los dos cambió
|
|
25
|
+
local base = StyleSheet:compose(className, style)
|
|
26
|
+
local activeStyle = if disabled and base[":disabled"] then StyleSheet:withPseudo(base, ":disabled") else base
|
|
27
|
+
useEffect(function()
|
|
28
|
+
local instance = ref.current
|
|
29
|
+
if not instance then
|
|
30
|
+
return nil
|
|
31
|
+
end
|
|
32
|
+
-- Primer montaje
|
|
33
|
+
local node = createNode(instance, activeStyle, parentNode)
|
|
34
|
+
nodeRef.current = node
|
|
35
|
+
prevStyleRef.current = activeStyle
|
|
36
|
+
-- Escribir visual inicial (sin prev — primera vez)
|
|
37
|
+
writeVisual(instance, activeStyle)
|
|
38
|
+
-- Layout
|
|
39
|
+
runLayout(getRoot(node))
|
|
40
|
+
-- Escuchar resize del contenedor
|
|
41
|
+
local sizeConn = instance:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
|
|
42
|
+
return runLayout(getRoot(node))
|
|
43
|
+
end)
|
|
44
|
+
-- Pseudo-estado :hover
|
|
45
|
+
local connections = { sizeConn }
|
|
46
|
+
if base[":hover"] then
|
|
47
|
+
local hoverStyle = StyleSheet:withPseudo(base, ":hover")
|
|
48
|
+
local _arg0 = instance.MouseEnter:Connect(function()
|
|
49
|
+
if disabled then
|
|
50
|
+
return nil
|
|
51
|
+
end
|
|
52
|
+
writeVisual(instance, hoverStyle, activeStyle)
|
|
53
|
+
end)
|
|
54
|
+
local _arg1 = instance.MouseLeave:Connect(function()
|
|
55
|
+
writeVisual(instance, activeStyle, hoverStyle)
|
|
56
|
+
end)
|
|
57
|
+
-- ▼ Array.push ▼
|
|
58
|
+
table.insert(connections, _arg0)
|
|
59
|
+
table.insert(connections, _arg1)
|
|
60
|
+
-- ▲ Array.push ▲
|
|
61
|
+
end
|
|
62
|
+
-- Pseudo-estado :active
|
|
63
|
+
if base[":active"] then
|
|
64
|
+
local activeStateStyle = StyleSheet:withPseudo(base, ":active")
|
|
65
|
+
local btn = instance
|
|
66
|
+
local _arg0 = btn.MouseButton1Down:Connect(function()
|
|
67
|
+
if disabled then
|
|
68
|
+
return nil
|
|
69
|
+
end
|
|
70
|
+
writeVisual(instance, activeStateStyle, activeStyle)
|
|
71
|
+
end)
|
|
72
|
+
local _arg1 = btn.MouseButton1Up:Connect(function()
|
|
73
|
+
writeVisual(instance, activeStyle, activeStateStyle)
|
|
74
|
+
end)
|
|
75
|
+
-- ▼ Array.push ▼
|
|
76
|
+
table.insert(connections, _arg0)
|
|
77
|
+
table.insert(connections, _arg1)
|
|
78
|
+
-- ▲ Array.push ▲
|
|
79
|
+
end
|
|
80
|
+
return function()
|
|
81
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
82
|
+
local _callback = function(c)
|
|
83
|
+
return c:Disconnect()
|
|
84
|
+
end
|
|
85
|
+
for _k, _v in connections do
|
|
86
|
+
_callback(_v, _k - 1, connections)
|
|
87
|
+
end
|
|
88
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
89
|
+
removeNode(node)
|
|
90
|
+
if parentNode then
|
|
91
|
+
runLayout(getRoot(parentNode))
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end, {})
|
|
95
|
+
-- Actualizar estilo cuando cambia
|
|
96
|
+
useEffect(function()
|
|
97
|
+
local node = nodeRef.current
|
|
98
|
+
if not node then
|
|
99
|
+
return nil
|
|
100
|
+
end
|
|
101
|
+
local prev = prevStyleRef.current
|
|
102
|
+
if prev == activeStyle then
|
|
103
|
+
return nil
|
|
104
|
+
end
|
|
105
|
+
updateNodeStyle(node, activeStyle)
|
|
106
|
+
writeVisual(node.instance, activeStyle, prev)
|
|
107
|
+
prevStyleRef.current = activeStyle
|
|
108
|
+
runLayout(getRoot(node))
|
|
109
|
+
end, { activeStyle })
|
|
110
|
+
return nodeRef.current
|
|
111
|
+
end
|
|
112
|
+
-- ── Elementos ─────────────────────────────────────────────────────────────────
|
|
113
|
+
local function div(props)
|
|
114
|
+
local ref = useRef()
|
|
115
|
+
local node = useLayoutNode(ref, props.style, props.className)
|
|
116
|
+
return React.createElement(NodeContext.Provider, {
|
|
117
|
+
value = node,
|
|
118
|
+
}, React.createElement("frame", {
|
|
119
|
+
ref = ref,
|
|
120
|
+
BackgroundTransparency = 1,
|
|
121
|
+
BorderSizePixel = 0,
|
|
122
|
+
LayoutOrder = props.layoutOrder,
|
|
123
|
+
}, props.children))
|
|
124
|
+
end
|
|
125
|
+
local function span(props)
|
|
126
|
+
local ref = useRef()
|
|
127
|
+
local node = useLayoutNode(ref, props.style, props.className)
|
|
128
|
+
local _attributes = {
|
|
129
|
+
ref = ref,
|
|
130
|
+
}
|
|
131
|
+
local _condition = props.text
|
|
132
|
+
if _condition == nil then
|
|
133
|
+
_condition = ""
|
|
134
|
+
end
|
|
135
|
+
_attributes.Text = _condition
|
|
136
|
+
local _condition_1 = props.richText
|
|
137
|
+
if _condition_1 == nil then
|
|
138
|
+
_condition_1 = false
|
|
139
|
+
end
|
|
140
|
+
_attributes.RichText = _condition_1
|
|
141
|
+
_attributes.BackgroundTransparency = 1
|
|
142
|
+
_attributes.BorderSizePixel = 0
|
|
143
|
+
_attributes.LayoutOrder = props.layoutOrder
|
|
144
|
+
_attributes.TextWrapped = true
|
|
145
|
+
return React.createElement(NodeContext.Provider, {
|
|
146
|
+
value = node,
|
|
147
|
+
}, React.createElement("textlabel", _attributes, props.children))
|
|
148
|
+
end
|
|
149
|
+
local function button(props)
|
|
150
|
+
local ref = useRef()
|
|
151
|
+
local node = useLayoutNode(ref, props.style, props.className, props.disabled)
|
|
152
|
+
local _attributes = {
|
|
153
|
+
ref = ref,
|
|
154
|
+
}
|
|
155
|
+
local _condition = props.text
|
|
156
|
+
if _condition == nil then
|
|
157
|
+
_condition = ""
|
|
158
|
+
end
|
|
159
|
+
_attributes.Text = _condition
|
|
160
|
+
_attributes.Active = not props.disabled
|
|
161
|
+
_attributes.AutoButtonColor = false
|
|
162
|
+
_attributes.BackgroundTransparency = 1
|
|
163
|
+
_attributes.BorderSizePixel = 0
|
|
164
|
+
_attributes.LayoutOrder = props.layoutOrder
|
|
165
|
+
_attributes.Event = {
|
|
166
|
+
MouseButton1Click = function()
|
|
167
|
+
if not props.disabled then
|
|
168
|
+
local _result = props.onClick
|
|
169
|
+
if _result ~= nil then
|
|
170
|
+
_result()
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end,
|
|
174
|
+
MouseEnter = function()
|
|
175
|
+
local _result = props.onMouseEnter
|
|
176
|
+
if _result ~= nil then
|
|
177
|
+
_result = _result()
|
|
178
|
+
end
|
|
179
|
+
return _result
|
|
180
|
+
end,
|
|
181
|
+
MouseLeave = function()
|
|
182
|
+
local _result = props.onMouseLeave
|
|
183
|
+
if _result ~= nil then
|
|
184
|
+
_result = _result()
|
|
185
|
+
end
|
|
186
|
+
return _result
|
|
187
|
+
end,
|
|
188
|
+
}
|
|
189
|
+
return React.createElement(NodeContext.Provider, {
|
|
190
|
+
value = node,
|
|
191
|
+
}, React.createElement("textbutton", _attributes, props.children))
|
|
192
|
+
end
|
|
193
|
+
local function img(props)
|
|
194
|
+
local ref = useRef()
|
|
195
|
+
local node = useLayoutNode(ref, props.style, props.className)
|
|
196
|
+
local scaleTypeMap = {
|
|
197
|
+
fit = Enum.ScaleType.Fit,
|
|
198
|
+
crop = Enum.ScaleType.Crop,
|
|
199
|
+
stretch = Enum.ScaleType.Stretch,
|
|
200
|
+
tile = Enum.ScaleType.Tile,
|
|
201
|
+
}
|
|
202
|
+
return React.createElement(NodeContext.Provider, {
|
|
203
|
+
value = node,
|
|
204
|
+
}, React.createElement("imagelabel", {
|
|
205
|
+
ref = ref,
|
|
206
|
+
Image = props.src,
|
|
207
|
+
ScaleType = scaleTypeMap[props.scaleType or "fit"],
|
|
208
|
+
BackgroundTransparency = 1,
|
|
209
|
+
BorderSizePixel = 0,
|
|
210
|
+
LayoutOrder = props.layoutOrder,
|
|
211
|
+
}, props.children))
|
|
212
|
+
end
|
|
213
|
+
local function input(props)
|
|
214
|
+
local ref = useRef()
|
|
215
|
+
local node = useLayoutNode(ref, props.style, props.className)
|
|
216
|
+
local _attributes = {
|
|
217
|
+
ref = ref,
|
|
218
|
+
}
|
|
219
|
+
local _condition = props.value
|
|
220
|
+
if _condition == nil then
|
|
221
|
+
_condition = ""
|
|
222
|
+
end
|
|
223
|
+
_attributes.Text = _condition
|
|
224
|
+
local _condition_1 = props.placeholder
|
|
225
|
+
if _condition_1 == nil then
|
|
226
|
+
_condition_1 = ""
|
|
227
|
+
end
|
|
228
|
+
_attributes.PlaceholderText = _condition_1
|
|
229
|
+
local _condition_2 = props.clearOnFocus
|
|
230
|
+
if _condition_2 == nil then
|
|
231
|
+
_condition_2 = false
|
|
232
|
+
end
|
|
233
|
+
_attributes.ClearTextOnFocus = _condition_2
|
|
234
|
+
_attributes.BackgroundTransparency = 1
|
|
235
|
+
_attributes.BorderSizePixel = 0
|
|
236
|
+
_attributes.LayoutOrder = props.layoutOrder
|
|
237
|
+
_attributes.Event = {
|
|
238
|
+
FocusLost = function(box)
|
|
239
|
+
local _result = props.onChanged
|
|
240
|
+
if _result ~= nil then
|
|
241
|
+
_result = _result(box.Text)
|
|
242
|
+
end
|
|
243
|
+
return _result
|
|
244
|
+
end,
|
|
245
|
+
}
|
|
246
|
+
return React.createElement(NodeContext.Provider, {
|
|
247
|
+
value = node,
|
|
248
|
+
}, React.createElement("textbox", _attributes, props.children))
|
|
249
|
+
end
|
|
250
|
+
local function ul(props)
|
|
251
|
+
local ref = useRef()
|
|
252
|
+
local node = useLayoutNode(ref, props.style, props.className)
|
|
253
|
+
local _attributes = {
|
|
254
|
+
ref = ref,
|
|
255
|
+
BackgroundTransparency = 1,
|
|
256
|
+
BorderSizePixel = 0,
|
|
257
|
+
}
|
|
258
|
+
local _condition = props.scrollBarThickness
|
|
259
|
+
if _condition == nil then
|
|
260
|
+
_condition = 4
|
|
261
|
+
end
|
|
262
|
+
_attributes.ScrollBarThickness = _condition
|
|
263
|
+
_attributes.ScrollingDirection = if props.scrollDirection == "horizontal" then Enum.ScrollingDirection.X else Enum.ScrollingDirection.Y
|
|
264
|
+
_attributes.CanvasSize = UDim2.fromScale(0, 0)
|
|
265
|
+
_attributes.AutomaticCanvasSize = if props.scrollDirection == "horizontal" then Enum.AutomaticSize.X else Enum.AutomaticSize.Y
|
|
266
|
+
_attributes.LayoutOrder = props.layoutOrder
|
|
267
|
+
return React.createElement(NodeContext.Provider, {
|
|
268
|
+
value = node,
|
|
269
|
+
}, React.createElement("scrollingframe", _attributes, props.children))
|
|
270
|
+
end
|
|
271
|
+
local function canvas(props)
|
|
272
|
+
local ref = useRef()
|
|
273
|
+
local node = useLayoutNode(ref, props.style, props.className)
|
|
274
|
+
return React.createElement(NodeContext.Provider, {
|
|
275
|
+
value = node,
|
|
276
|
+
}, React.createElement("viewportframe", {
|
|
277
|
+
ref = ref,
|
|
278
|
+
BackgroundTransparency = 1,
|
|
279
|
+
BorderSizePixel = 0,
|
|
280
|
+
LayoutOrder = props.layoutOrder,
|
|
281
|
+
}, props.children))
|
|
282
|
+
end
|
|
283
|
+
local function video(props)
|
|
284
|
+
local ref = useRef()
|
|
285
|
+
local node = useLayoutNode(ref, props.style, props.className)
|
|
286
|
+
local _attributes = {
|
|
287
|
+
ref = ref,
|
|
288
|
+
Video = props.src,
|
|
289
|
+
}
|
|
290
|
+
local _condition = props.looped
|
|
291
|
+
if _condition == nil then
|
|
292
|
+
_condition = false
|
|
293
|
+
end
|
|
294
|
+
_attributes.Looped = _condition
|
|
295
|
+
local _condition_1 = props.playing
|
|
296
|
+
if _condition_1 == nil then
|
|
297
|
+
_condition_1 = false
|
|
298
|
+
end
|
|
299
|
+
_attributes.Playing = _condition_1
|
|
300
|
+
_attributes.BackgroundTransparency = 1
|
|
301
|
+
_attributes.BorderSizePixel = 0
|
|
302
|
+
_attributes.LayoutOrder = props.layoutOrder
|
|
303
|
+
return React.createElement(NodeContext.Provider, {
|
|
304
|
+
value = node,
|
|
305
|
+
}, React.createElement("videoframe", _attributes, props.children))
|
|
306
|
+
end
|
|
307
|
+
return {
|
|
308
|
+
div = div,
|
|
309
|
+
span = span,
|
|
310
|
+
button = button,
|
|
311
|
+
img = img,
|
|
312
|
+
input = input,
|
|
313
|
+
ul = ul,
|
|
314
|
+
canvas = canvas,
|
|
315
|
+
video = video,
|
|
316
|
+
}
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { StyleSheet } from "./stylesheet";
|
|
2
|
+
export * as elements from "./elements";
|
|
3
|
+
export type { RbxStyle, RbxStyleBase } from "./core";
|
|
4
|
+
export type { UDimValue, ColorValue, GradientStop } from "./core";
|
|
5
|
+
export type { SpacingStyle, SizeStyle, BackgroundStyle } from "./core";
|
|
6
|
+
export type { BorderStyle, TextStyle } from "./core";
|
|
7
|
+
export type { LayoutStyle, Display, FlexDirection, JustifyContent, AlignItems, AlignContent, FlexWrap } from "./core";
|
|
8
|
+
export type { PositionStyle, PositionType, MiscStyle } from "./core";
|
|
9
|
+
export { writeVisual, runLayout, runLayoutImmediate, markLayoutDirty, getRoot, createNode, updateNodeStyle, removeNode, parseColor, parseUDim, parseUDim2 } from "./core";
|
|
10
|
+
export type { LayoutNode } from "./core";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAS,cAAc,CAAA;AAC5C,OAAO,KAAK,QAAQ,MAAU,YAAY,CAAA;AAE1C,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAA+B,QAAQ,CAAA;AAC7E,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAkB,QAAQ,CAAA;AAC7E,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAa,QAAQ,CAAA;AAC7E,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAA+B,QAAQ,CAAA;AAC7E,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACrH,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,MAAe,QAAQ,CAAA;AAG7E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,kBAAkB,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACzK,YAAY,EAAE,UAAU,EAAE,MAA4C,QAAQ,CAAA"}
|
package/out/init.luau
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local exports = {}
|
|
4
|
+
exports.StyleSheet = TS.import(script, script, "stylesheet").StyleSheet
|
|
5
|
+
exports.elements = TS.import(script, script, "elements")
|
|
6
|
+
-- API avanzada para extensión del paquete
|
|
7
|
+
local _core = TS.import(script, script, "core")
|
|
8
|
+
exports.writeVisual = _core.writeVisual
|
|
9
|
+
exports.runLayout = _core.runLayout
|
|
10
|
+
exports.runLayoutImmediate = _core.runLayoutImmediate
|
|
11
|
+
exports.markLayoutDirty = _core.markLayoutDirty
|
|
12
|
+
exports.getRoot = _core.getRoot
|
|
13
|
+
exports.createNode = _core.createNode
|
|
14
|
+
exports.updateNodeStyle = _core.updateNodeStyle
|
|
15
|
+
exports.removeNode = _core.removeNode
|
|
16
|
+
exports.parseColor = _core.parseColor
|
|
17
|
+
exports.parseUDim = _core.parseUDim
|
|
18
|
+
exports.parseUDim2 = _core.parseUDim2
|
|
19
|
+
return exports
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RbxStyle } from "../core";
|
|
2
|
+
type StyleMap = Record<string, RbxStyle>;
|
|
3
|
+
type PseudoKey = ":hover" | ":active" | ":disabled" | ":focus";
|
|
4
|
+
type VariantConfig<V extends Record<string, Record<string, RbxStyle>>> = {
|
|
5
|
+
base: RbxStyle;
|
|
6
|
+
variants: V;
|
|
7
|
+
defaultVariants?: {
|
|
8
|
+
[K in keyof V]?: keyof V[K];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
type VariantProps<V extends Record<string, Record<string, RbxStyle>>> = {
|
|
12
|
+
[K in keyof V]?: keyof V[K];
|
|
13
|
+
};
|
|
14
|
+
export declare const StyleSheet: {
|
|
15
|
+
create<T extends StyleMap>(styles: T): T;
|
|
16
|
+
/**
|
|
17
|
+
* Fusiona estilos. Itera con next() en vez de pairs() para mejor rendimiento.
|
|
18
|
+
*/
|
|
19
|
+
compose(...styles: Array<RbxStyle | undefined | false>): RbxStyle;
|
|
20
|
+
createVariants<V extends Record<string, Record<string, RbxStyle>>>(config: VariantConfig<V>): (props?: VariantProps<V>) => RbxStyle;
|
|
21
|
+
createTheme<T extends Record<string, Record<string, unknown>>>(tokens: T): T;
|
|
22
|
+
withPseudo(base: RbxStyle, pseudo: PseudoKey): RbxStyle;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stylesheet/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAgB,MAAM,SAAS,CAAA;AAErD,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AACxC,KAAK,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;AAE9D,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,IAAI;IACxE,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,CAAC,CAAA;IACX,eAAe,CAAC,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;KAAE,CAAA;CACjD,CAAA;AAED,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,IAAI;KACtE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CAC3B,CAAA;AAED,eAAO,MAAM,UAAU;WACf,CAAC,SAAS,QAAQ,UAAU,CAAC,GAAG,CAAC;IAIxC;;OAEG;uBACgB,KAAK,CAAC,QAAQ,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,QAAQ;mBAoBlD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,UACxD,aAAa,CAAC,CAAC,CAAC,GACtB,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,QAAQ;gBAoB5B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;qBAI3D,QAAQ,UAAU,SAAS,GAAG,QAAQ;CAKvD,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local StyleSheet
|
|
3
|
+
StyleSheet = {
|
|
4
|
+
create = function(self, styles)
|
|
5
|
+
return styles
|
|
6
|
+
end,
|
|
7
|
+
compose = function(self, ...)
|
|
8
|
+
local styles = { ... }
|
|
9
|
+
-- Caso rápido: un solo estilo no undefined
|
|
10
|
+
local nonNull
|
|
11
|
+
local count = 0
|
|
12
|
+
for _, s in styles do
|
|
13
|
+
if s then
|
|
14
|
+
nonNull = s
|
|
15
|
+
count += 1
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
if count == 0 then
|
|
19
|
+
return {}
|
|
20
|
+
end
|
|
21
|
+
if count == 1 then
|
|
22
|
+
return nonNull
|
|
23
|
+
end
|
|
24
|
+
local result = {}
|
|
25
|
+
for _, style in styles do
|
|
26
|
+
if not style then
|
|
27
|
+
continue
|
|
28
|
+
end
|
|
29
|
+
for key, value in pairs(style) do
|
|
30
|
+
result[key] = value
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
return result
|
|
34
|
+
end,
|
|
35
|
+
createVariants = function(self, config)
|
|
36
|
+
-- Pre-computar las combinaciones más comunes no es viable sin conocer los props,
|
|
37
|
+
-- pero podemos evitar allocations innecesarias en el path feliz
|
|
38
|
+
return function(props)
|
|
39
|
+
local resolved = (props or {})
|
|
40
|
+
local defaults = (config.defaultVariants or {})
|
|
41
|
+
local parts = { config.base }
|
|
42
|
+
for key, variantMap in pairs(config.variants) do
|
|
43
|
+
local _condition = resolved[key]
|
|
44
|
+
if _condition == nil then
|
|
45
|
+
_condition = defaults[key]
|
|
46
|
+
end
|
|
47
|
+
local chosen = _condition
|
|
48
|
+
if chosen ~= nil then
|
|
49
|
+
local s = variantMap[chosen]
|
|
50
|
+
if s then
|
|
51
|
+
table.insert(parts, s)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
return StyleSheet:compose(unpack(parts))
|
|
56
|
+
end
|
|
57
|
+
end,
|
|
58
|
+
createTheme = function(self, tokens)
|
|
59
|
+
return tokens
|
|
60
|
+
end,
|
|
61
|
+
withPseudo = function(self, base, pseudo)
|
|
62
|
+
local pseudoStyle = base[pseudo]
|
|
63
|
+
if not pseudoStyle then
|
|
64
|
+
return base
|
|
65
|
+
end
|
|
66
|
+
return StyleSheet:compose(base, pseudoStyle)
|
|
67
|
+
end,
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
StyleSheet = StyleSheet,
|
|
71
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@snailycfx/stylesheet",
|
|
3
|
+
"version": "1.0.10",
|
|
4
|
+
"description": "CSS-inspired StyleSheet system for roblox-ts and @rbxts/react",
|
|
5
|
+
"main": "out/init.lua",
|
|
6
|
+
"types": "out/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "rbxtsc",
|
|
9
|
+
"watch": "rbxtsc -w",
|
|
10
|
+
"prepublishOnly": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"roblox",
|
|
14
|
+
"roblox-ts",
|
|
15
|
+
"rbxts",
|
|
16
|
+
"stylesheet",
|
|
17
|
+
"css",
|
|
18
|
+
"ui"
|
|
19
|
+
],
|
|
20
|
+
"author": "Snaily",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@rbxts/react": "^17.3.7-ts.1",
|
|
24
|
+
"@rbxts/types": "^1.0.920",
|
|
25
|
+
"roblox-ts": "^3.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@rbxts/react": "^17.3.7-ts.1",
|
|
29
|
+
"@rbxts/compiler-types": "3.0.0-types.0",
|
|
30
|
+
"@rbxts/types": "^1.0.911",
|
|
31
|
+
"roblox-ts": "^3.0.0",
|
|
32
|
+
"typescript": "^5.0.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|