@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Snaily
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LayoutNode } from "./node";
|
|
2
|
+
export interface AbsoluteLayout {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
containingBlock: LayoutNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function computeAbsoluteLayout(node: LayoutNode): AbsoluteLayout;
|
|
10
|
+
//# sourceMappingURL=absolute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"absolute.d.ts","sourceRoot":"","sources":["../../../src/core/engine/absolute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAIxC,MAAM,WAAW,cAAc;IAC9B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,UAAU,CAAA;CAC3B;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAuDtE"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local findContainingBlockForAbsolute = TS.import(script, script.Parent, "node").findContainingBlockForAbsolute
|
|
4
|
+
local resolvePixels = TS.import(script, script.Parent.Parent, "parse").resolvePixels
|
|
5
|
+
local function computeAbsoluteLayout(node)
|
|
6
|
+
local cb = findContainingBlockForAbsolute(node)
|
|
7
|
+
local cbW = cb.computedWidth
|
|
8
|
+
local cbH = cb.computedHeight
|
|
9
|
+
local style = node.style
|
|
10
|
+
local hasLeft = style.left ~= nil
|
|
11
|
+
local hasRight = style.right ~= nil
|
|
12
|
+
local hasTop = style.top ~= nil
|
|
13
|
+
local hasBottom = style.bottom ~= nil
|
|
14
|
+
local hasWidth = style.width ~= nil
|
|
15
|
+
local hasHeight = style.height ~= nil
|
|
16
|
+
local leftPx = if hasLeft then resolvePixels(style.left, cbW) else nil
|
|
17
|
+
local rightPx = if hasRight then resolvePixels(style.right, cbW) else nil
|
|
18
|
+
local topPx = if hasTop then resolvePixels(style.top, cbH) else nil
|
|
19
|
+
local bottomPx = if hasBottom then resolvePixels(style.bottom, cbH) else nil
|
|
20
|
+
local widthPx = if hasWidth then resolvePixels(style.width, cbW) else nil
|
|
21
|
+
local heightPx = if hasHeight then resolvePixels(style.height, cbH) else nil
|
|
22
|
+
local x
|
|
23
|
+
local width
|
|
24
|
+
if leftPx ~= nil and rightPx ~= nil and widthPx == nil then
|
|
25
|
+
x = leftPx
|
|
26
|
+
width = cbW - leftPx - rightPx
|
|
27
|
+
elseif leftPx ~= nil then
|
|
28
|
+
x = leftPx
|
|
29
|
+
local _condition = widthPx
|
|
30
|
+
if _condition == nil then
|
|
31
|
+
_condition = 0
|
|
32
|
+
end
|
|
33
|
+
width = _condition
|
|
34
|
+
elseif rightPx ~= nil then
|
|
35
|
+
local _condition = widthPx
|
|
36
|
+
if _condition == nil then
|
|
37
|
+
_condition = 0
|
|
38
|
+
end
|
|
39
|
+
width = _condition
|
|
40
|
+
x = cbW - rightPx - width
|
|
41
|
+
else
|
|
42
|
+
x = 0
|
|
43
|
+
local _condition = widthPx
|
|
44
|
+
if _condition == nil then
|
|
45
|
+
_condition = 0
|
|
46
|
+
end
|
|
47
|
+
width = _condition
|
|
48
|
+
end
|
|
49
|
+
local y
|
|
50
|
+
local height
|
|
51
|
+
if topPx ~= nil and bottomPx ~= nil and heightPx == nil then
|
|
52
|
+
y = topPx
|
|
53
|
+
height = cbH - topPx - bottomPx
|
|
54
|
+
elseif topPx ~= nil then
|
|
55
|
+
y = topPx
|
|
56
|
+
local _condition = heightPx
|
|
57
|
+
if _condition == nil then
|
|
58
|
+
_condition = 0
|
|
59
|
+
end
|
|
60
|
+
height = _condition
|
|
61
|
+
elseif bottomPx ~= nil then
|
|
62
|
+
local _condition = heightPx
|
|
63
|
+
if _condition == nil then
|
|
64
|
+
_condition = 0
|
|
65
|
+
end
|
|
66
|
+
height = _condition
|
|
67
|
+
y = cbH - bottomPx - height
|
|
68
|
+
else
|
|
69
|
+
y = 0
|
|
70
|
+
local _condition = heightPx
|
|
71
|
+
if _condition == nil then
|
|
72
|
+
_condition = 0
|
|
73
|
+
end
|
|
74
|
+
height = _condition
|
|
75
|
+
end
|
|
76
|
+
return {
|
|
77
|
+
x = x,
|
|
78
|
+
y = y,
|
|
79
|
+
width = width,
|
|
80
|
+
height = height,
|
|
81
|
+
containingBlock = cb,
|
|
82
|
+
}
|
|
83
|
+
end
|
|
84
|
+
return {
|
|
85
|
+
computeAbsoluteLayout = computeAbsoluteLayout,
|
|
86
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LayoutNode } from "./node";
|
|
2
|
+
export interface FlexLayout {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Algoritmo Flexbox completo.
|
|
10
|
+
* Opera en píxeles absolutos — resolvePixels ya resolvió UDimValues antes de llegar aquí.
|
|
11
|
+
* Devuelve layouts en el mismo orden que node.children.
|
|
12
|
+
*/
|
|
13
|
+
export declare function computeFlexLayout(node: LayoutNode, containerWidth: number, containerHeight: number): FlexLayout[];
|
|
14
|
+
//# sourceMappingURL=flex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flex.d.ts","sourceRoot":"","sources":["../../../src/core/engine/flex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAIxC,MAAM,WAAW,UAAU;IAC1B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACd;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,UAAU,EAChB,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GACrB,UAAU,EAAE,CA6Ld"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local resolvePixels = TS.import(script, script.Parent.Parent, "parse").resolvePixels
|
|
4
|
+
--[[
|
|
5
|
+
*
|
|
6
|
+
* Algoritmo Flexbox completo.
|
|
7
|
+
* Opera en píxeles absolutos — resolvePixels ya resolvió UDimValues antes de llegar aquí.
|
|
8
|
+
* Devuelve layouts en el mismo orden que node.children.
|
|
9
|
+
|
|
10
|
+
]]
|
|
11
|
+
local function computeFlexLayout(node, containerWidth, containerHeight)
|
|
12
|
+
local style = node.style
|
|
13
|
+
local direction = style.flexDirection or "row"
|
|
14
|
+
local isRow = direction == "row" or direction == "row-reverse"
|
|
15
|
+
local isReverse = direction == "row-reverse" or direction == "column-reverse"
|
|
16
|
+
local wrap = style.flexWrap or "nowrap"
|
|
17
|
+
local justifyContent = style.justifyContent or "flex-start"
|
|
18
|
+
local alignItems = style.alignItems or "stretch"
|
|
19
|
+
local mainSize = if isRow then containerWidth else containerHeight
|
|
20
|
+
local crossSize = if isRow then containerHeight else containerWidth
|
|
21
|
+
local _condition = style.columnGap
|
|
22
|
+
if _condition == nil then
|
|
23
|
+
_condition = style.gap
|
|
24
|
+
if _condition == nil then
|
|
25
|
+
_condition = 0
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
local colGapPx = resolvePixels(_condition, containerWidth)
|
|
29
|
+
local _condition_1 = style.rowGap
|
|
30
|
+
if _condition_1 == nil then
|
|
31
|
+
_condition_1 = style.gap
|
|
32
|
+
if _condition_1 == nil then
|
|
33
|
+
_condition_1 = 0
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
local rowGapPx = resolvePixels(_condition_1, containerHeight)
|
|
37
|
+
local mainGap = if isRow then colGapPx else rowGapPx
|
|
38
|
+
local crossGap = if isRow then rowGapPx else colGapPx
|
|
39
|
+
-- Solo hijos en flujo
|
|
40
|
+
local inFlow = {}
|
|
41
|
+
for _, child in node.children do
|
|
42
|
+
if child.style.position ~= "absolute" then
|
|
43
|
+
table.insert(inFlow, child)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
if #inFlow == 0 then
|
|
47
|
+
local _exp = node.children
|
|
48
|
+
-- ▼ ReadonlyArray.map ▼
|
|
49
|
+
local _newValue = table.create(#_exp)
|
|
50
|
+
local _callback = function()
|
|
51
|
+
return {
|
|
52
|
+
x = 0,
|
|
53
|
+
y = 0,
|
|
54
|
+
width = 0,
|
|
55
|
+
height = 0,
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
for _k, _v in _exp do
|
|
59
|
+
_newValue[_k] = _callback(_v, _k - 1, _exp)
|
|
60
|
+
end
|
|
61
|
+
-- ▲ ReadonlyArray.map ▲
|
|
62
|
+
return _newValue
|
|
63
|
+
end
|
|
64
|
+
-- ── Paso 1: métricas base por hijo ────────────────────────────────────────
|
|
65
|
+
local items = {}
|
|
66
|
+
for _, child in inFlow do
|
|
67
|
+
local cs = child.style
|
|
68
|
+
local flexBasis = if cs.flexBasis ~= nil and cs.flexBasis ~= "auto" then (cs.flexBasis) else nil
|
|
69
|
+
local _condition_2 = flexBasis
|
|
70
|
+
if _condition_2 == nil then
|
|
71
|
+
local _result
|
|
72
|
+
if isRow then
|
|
73
|
+
local _condition_3 = cs.width
|
|
74
|
+
if _condition_3 == nil then
|
|
75
|
+
_condition_3 = 0
|
|
76
|
+
end
|
|
77
|
+
_result = resolvePixels(_condition_3, containerWidth)
|
|
78
|
+
else
|
|
79
|
+
local _condition_3 = cs.height
|
|
80
|
+
if _condition_3 == nil then
|
|
81
|
+
_condition_3 = 0
|
|
82
|
+
end
|
|
83
|
+
_result = resolvePixels(_condition_3, containerHeight)
|
|
84
|
+
end
|
|
85
|
+
_condition_2 = _result
|
|
86
|
+
end
|
|
87
|
+
local mainBase = _condition_2
|
|
88
|
+
local _result
|
|
89
|
+
if isRow then
|
|
90
|
+
local _condition_3 = cs.height
|
|
91
|
+
if _condition_3 == nil then
|
|
92
|
+
_condition_3 = 0
|
|
93
|
+
end
|
|
94
|
+
_result = resolvePixels(_condition_3, containerHeight)
|
|
95
|
+
else
|
|
96
|
+
local _condition_3 = cs.width
|
|
97
|
+
if _condition_3 == nil then
|
|
98
|
+
_condition_3 = 0
|
|
99
|
+
end
|
|
100
|
+
_result = resolvePixels(_condition_3, containerWidth)
|
|
101
|
+
end
|
|
102
|
+
local crossBase = _result
|
|
103
|
+
local _condition_3 = cs.flexGrow
|
|
104
|
+
if _condition_3 == nil then
|
|
105
|
+
_condition_3 = (if cs.flex ~= nil then cs.flex else 0)
|
|
106
|
+
end
|
|
107
|
+
local flexGrow = _condition_3
|
|
108
|
+
local _condition_4 = cs.flexShrink
|
|
109
|
+
if _condition_4 == nil then
|
|
110
|
+
_condition_4 = 1
|
|
111
|
+
end
|
|
112
|
+
local flexShrink = _condition_4
|
|
113
|
+
local _arg0 = {
|
|
114
|
+
node = child,
|
|
115
|
+
mainBase = mainBase,
|
|
116
|
+
crossBase = crossBase,
|
|
117
|
+
flexGrow = flexGrow,
|
|
118
|
+
flexShrink = flexShrink,
|
|
119
|
+
}
|
|
120
|
+
table.insert(items, _arg0)
|
|
121
|
+
end
|
|
122
|
+
-- ── Paso 2: agrupar en líneas ─────────────────────────────────────────────
|
|
123
|
+
local lines = {}
|
|
124
|
+
if wrap == "nowrap" then
|
|
125
|
+
table.insert(lines, items)
|
|
126
|
+
else
|
|
127
|
+
local currentLine = {}
|
|
128
|
+
local currentMainSize = 0
|
|
129
|
+
for _, item in items do
|
|
130
|
+
local gapContrib = if #currentLine > 0 then mainGap else 0
|
|
131
|
+
if #currentLine > 0 and currentMainSize + gapContrib + item.mainBase > mainSize then
|
|
132
|
+
local _currentLine = currentLine
|
|
133
|
+
table.insert(lines, _currentLine)
|
|
134
|
+
currentLine = { item }
|
|
135
|
+
currentMainSize = item.mainBase
|
|
136
|
+
else
|
|
137
|
+
table.insert(currentLine, item)
|
|
138
|
+
currentMainSize += gapContrib + item.mainBase
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
if #currentLine > 0 then
|
|
142
|
+
local _currentLine = currentLine
|
|
143
|
+
table.insert(lines, _currentLine)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
-- ── Paso 3: flex-grow / flex-shrink + align stretch ───────────────────────
|
|
147
|
+
for _, line in lines do
|
|
148
|
+
local totalGaps = mainGap * math.max(0, #line - 1)
|
|
149
|
+
local baseSum = 0
|
|
150
|
+
for _1, item in line do
|
|
151
|
+
baseSum += item.mainBase
|
|
152
|
+
end
|
|
153
|
+
local freeSpace = mainSize - totalGaps - baseSum
|
|
154
|
+
if freeSpace > 0 then
|
|
155
|
+
local totalGrow = 0
|
|
156
|
+
for _1, item in line do
|
|
157
|
+
totalGrow += item.flexGrow
|
|
158
|
+
end
|
|
159
|
+
if totalGrow > 0 then
|
|
160
|
+
for _1, item in line do
|
|
161
|
+
if item.flexGrow > 0 then
|
|
162
|
+
item.mainBase += (freeSpace * item.flexGrow) / totalGrow
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
elseif freeSpace < 0 then
|
|
167
|
+
local totalShrink = 0
|
|
168
|
+
for _1, item in line do
|
|
169
|
+
totalShrink += item.flexShrink * item.mainBase
|
|
170
|
+
end
|
|
171
|
+
if totalShrink > 0 then
|
|
172
|
+
for _1, item in line do
|
|
173
|
+
if item.flexShrink > 0 then
|
|
174
|
+
local ratio = (item.flexShrink * item.mainBase) / totalShrink
|
|
175
|
+
item.mainBase = math.max(0, item.mainBase + freeSpace * ratio)
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
-- stretch: usar crossSize del contenedor como fallback
|
|
181
|
+
local lineCrossSize = crossSize
|
|
182
|
+
for _1, item in line do
|
|
183
|
+
if item.crossBase > 0 then
|
|
184
|
+
lineCrossSize = math.max(lineCrossSize, item.crossBase)
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
for _1, item in line do
|
|
188
|
+
if alignItems == "stretch" and item.crossBase == 0 then
|
|
189
|
+
item.crossBase = lineCrossSize
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
-- ── Paso 4: calcular posiciones ───────────────────────────────────────────
|
|
194
|
+
-- Usamos tabla indexada en lugar de Map para evitar overhead de hashing
|
|
195
|
+
local resultIndex = {}
|
|
196
|
+
local crossOffset = 0
|
|
197
|
+
for _, line in lines do
|
|
198
|
+
local lineCrossSize = 0
|
|
199
|
+
for _1, item in line do
|
|
200
|
+
if item.crossBase > lineCrossSize then
|
|
201
|
+
lineCrossSize = item.crossBase
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
local totalMain = 0
|
|
205
|
+
for _1, item in line do
|
|
206
|
+
totalMain += item.mainBase
|
|
207
|
+
end
|
|
208
|
+
totalMain += mainGap * math.max(0, #line - 1)
|
|
209
|
+
local freeMain = mainSize - totalMain
|
|
210
|
+
local mainOffset = 0
|
|
211
|
+
local extraGap = 0
|
|
212
|
+
if justifyContent == "flex-end" then
|
|
213
|
+
mainOffset = freeMain
|
|
214
|
+
elseif justifyContent == "center" then
|
|
215
|
+
mainOffset = freeMain / 2
|
|
216
|
+
elseif justifyContent == "space-between" then
|
|
217
|
+
extraGap = if #line > 1 then freeMain / (#line - 1) else 0
|
|
218
|
+
elseif justifyContent == "space-around" then
|
|
219
|
+
extraGap = freeMain / #line
|
|
220
|
+
mainOffset = extraGap / 2
|
|
221
|
+
elseif justifyContent == "space-evenly" then
|
|
222
|
+
extraGap = freeMain / (#line + 1)
|
|
223
|
+
mainOffset = extraGap
|
|
224
|
+
end
|
|
225
|
+
-- Orden normal o reverso sin crear array nuevo
|
|
226
|
+
local lineSize = #line
|
|
227
|
+
do
|
|
228
|
+
local i = 0
|
|
229
|
+
local _shouldIncrement = false
|
|
230
|
+
while true do
|
|
231
|
+
if _shouldIncrement then
|
|
232
|
+
i += 1
|
|
233
|
+
else
|
|
234
|
+
_shouldIncrement = true
|
|
235
|
+
end
|
|
236
|
+
if not (i < lineSize) then
|
|
237
|
+
break
|
|
238
|
+
end
|
|
239
|
+
local item = if isReverse then line[lineSize - 1 - i + 1] else line[i + 1]
|
|
240
|
+
local crossPos = crossOffset
|
|
241
|
+
if alignItems == "center" then
|
|
242
|
+
crossPos += (lineCrossSize - item.crossBase) / 2
|
|
243
|
+
elseif alignItems == "flex-end" then
|
|
244
|
+
crossPos += lineCrossSize - item.crossBase
|
|
245
|
+
end
|
|
246
|
+
local _node = item.node
|
|
247
|
+
local _arg1 = {
|
|
248
|
+
x = if isRow then mainOffset else crossPos,
|
|
249
|
+
y = if isRow then crossPos else mainOffset,
|
|
250
|
+
width = if isRow then item.mainBase else item.crossBase,
|
|
251
|
+
height = if isRow then item.crossBase else item.mainBase,
|
|
252
|
+
}
|
|
253
|
+
resultIndex[_node] = _arg1
|
|
254
|
+
mainOffset += item.mainBase + mainGap + extraGap
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
crossOffset += lineCrossSize + crossGap
|
|
258
|
+
end
|
|
259
|
+
-- Devolver en orden de node.children (absolute incluidos con zeros)
|
|
260
|
+
local _exp = node.children
|
|
261
|
+
-- ▼ ReadonlyArray.map ▼
|
|
262
|
+
local _newValue = table.create(#_exp)
|
|
263
|
+
local _callback = function(child)
|
|
264
|
+
local _child = child
|
|
265
|
+
local _condition_2 = resultIndex[_child]
|
|
266
|
+
if _condition_2 == nil then
|
|
267
|
+
_condition_2 = {
|
|
268
|
+
x = 0,
|
|
269
|
+
y = 0,
|
|
270
|
+
width = 0,
|
|
271
|
+
height = 0,
|
|
272
|
+
}
|
|
273
|
+
end
|
|
274
|
+
return _condition_2
|
|
275
|
+
end
|
|
276
|
+
for _k, _v in _exp do
|
|
277
|
+
_newValue[_k] = _callback(_v, _k - 1, _exp)
|
|
278
|
+
end
|
|
279
|
+
-- ▲ ReadonlyArray.map ▲
|
|
280
|
+
return _newValue
|
|
281
|
+
end
|
|
282
|
+
return {
|
|
283
|
+
computeFlexLayout = computeFlexLayout,
|
|
284
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LayoutNode } from "./node";
|
|
2
|
+
export interface GridLayout {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function computeGridLayout(node: LayoutNode, containerWidth: number, containerHeight: number): GridLayout[];
|
|
9
|
+
//# sourceMappingURL=grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../src/core/engine/grid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAIxC,MAAM,WAAW,UAAU;IAC1B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACd;AAED,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,UAAU,EAChB,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GACrB,UAAU,EAAE,CAwJd"}
|