flexily 0.5.2 → 0.6.0
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/dist/chunk-CBBoxR_p.mjs +26 -0
- package/dist/constants-BNURa6H7.mjs +65 -0
- package/dist/constants-BNURa6H7.mjs.map +1 -0
- package/dist/constants-D7ythAJC.d.mts +64 -0
- package/dist/constants-D7ythAJC.d.mts.map +1 -0
- package/{src/classic/node.ts → dist/index-classic.d.mts} +118 -619
- package/dist/index-classic.d.mts.map +1 -0
- package/dist/index-classic.mjs +1909 -0
- package/dist/index-classic.mjs.map +1 -0
- package/dist/index.d.mts +195 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3279 -0
- package/dist/index.mjs.map +1 -0
- package/dist/node-zero-75maLs2s.d.mts +762 -0
- package/dist/node-zero-75maLs2s.d.mts.map +1 -0
- package/dist/src-BWyhokNZ.mjs +692 -0
- package/dist/src-BWyhokNZ.mjs.map +1 -0
- package/dist/src-DdSLylRA.mjs +816 -0
- package/dist/src-DdSLylRA.mjs.map +1 -0
- package/dist/testing.d.mts +55 -0
- package/dist/testing.d.mts.map +1 -0
- package/dist/testing.mjs +154 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types--IozHd4V.mjs +283 -0
- package/dist/types--IozHd4V.mjs.map +1 -0
- package/dist/types-DG1H4DVR.d.mts +157 -0
- package/dist/types-DG1H4DVR.d.mts.map +1 -0
- package/package.json +33 -24
- package/src/CLAUDE.md +0 -527
- package/src/classic/layout.ts +0 -1843
- package/src/constants.ts +0 -82
- package/src/create-flexily.ts +0 -153
- package/src/index-classic.ts +0 -110
- package/src/index.ts +0 -133
- package/src/layout-flex-lines.ts +0 -413
- package/src/layout-helpers.ts +0 -160
- package/src/layout-measure.ts +0 -259
- package/src/layout-stats.ts +0 -41
- package/src/layout-traversal.ts +0 -70
- package/src/layout-zero.ts +0 -2219
- package/src/logger.ts +0 -68
- package/src/monospace-measurer.ts +0 -68
- package/src/node-zero.ts +0 -1508
- package/src/pretext-measurer.ts +0 -86
- package/src/test-measurer.ts +0 -219
- package/src/testing.ts +0 -215
- package/src/text-layout.ts +0 -75
- package/src/trace.ts +0 -252
- package/src/types.ts +0 -236
- package/src/utils.ts +0 -243
package/src/utils.ts
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flexily Utility Functions
|
|
3
|
-
*
|
|
4
|
-
* Helper functions for edge value manipulation and value resolution.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as C from "./constants.js"
|
|
8
|
-
import type { Value } from "./types.js"
|
|
9
|
-
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// Shared Traversal Stack
|
|
12
|
-
// ============================================================================
|
|
13
|
-
// Pre-allocated stack array for iterative tree traversal. Shared across all
|
|
14
|
-
// layout functions to avoid multiple allocations. Using a single stack is safe
|
|
15
|
-
// because layout operations are synchronous (no concurrent traversals).
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Shared traversal stack for iterative tree operations.
|
|
19
|
-
* Avoids recursion (prevents stack overflow on deep trees) and avoids
|
|
20
|
-
* allocation during layout passes.
|
|
21
|
-
*/
|
|
22
|
-
export const traversalStack: unknown[] = []
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Set a value on an edge array (supports all edge types including logical START/END).
|
|
26
|
-
*/
|
|
27
|
-
export function setEdgeValue(
|
|
28
|
-
arr: [Value, Value, Value, Value, Value, Value],
|
|
29
|
-
edge: number,
|
|
30
|
-
value: number,
|
|
31
|
-
unit: number,
|
|
32
|
-
): void {
|
|
33
|
-
const v = { value, unit }
|
|
34
|
-
switch (edge) {
|
|
35
|
-
case C.EDGE_LEFT:
|
|
36
|
-
arr[0] = v
|
|
37
|
-
break
|
|
38
|
-
case C.EDGE_TOP:
|
|
39
|
-
arr[1] = v
|
|
40
|
-
break
|
|
41
|
-
case C.EDGE_RIGHT:
|
|
42
|
-
arr[2] = v
|
|
43
|
-
break
|
|
44
|
-
case C.EDGE_BOTTOM:
|
|
45
|
-
arr[3] = v
|
|
46
|
-
break
|
|
47
|
-
case C.EDGE_HORIZONTAL:
|
|
48
|
-
arr[0] = v
|
|
49
|
-
arr[2] = v
|
|
50
|
-
break
|
|
51
|
-
case C.EDGE_VERTICAL:
|
|
52
|
-
arr[1] = v
|
|
53
|
-
arr[3] = v
|
|
54
|
-
break
|
|
55
|
-
case C.EDGE_ALL:
|
|
56
|
-
arr[0] = v
|
|
57
|
-
arr[1] = v
|
|
58
|
-
arr[2] = v
|
|
59
|
-
arr[3] = v
|
|
60
|
-
break
|
|
61
|
-
case C.EDGE_START:
|
|
62
|
-
// Store in logical START slot (resolved to physical at layout time)
|
|
63
|
-
arr[4] = v
|
|
64
|
-
break
|
|
65
|
-
case C.EDGE_END:
|
|
66
|
-
// Store in logical END slot (resolved to physical at layout time)
|
|
67
|
-
arr[5] = v
|
|
68
|
-
break
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Set a border value on an edge array.
|
|
74
|
-
*/
|
|
75
|
-
export function setEdgeBorder(
|
|
76
|
-
arr: [number, number, number, number, number, number],
|
|
77
|
-
edge: number,
|
|
78
|
-
value: number,
|
|
79
|
-
): void {
|
|
80
|
-
switch (edge) {
|
|
81
|
-
case C.EDGE_LEFT:
|
|
82
|
-
arr[0] = value
|
|
83
|
-
break
|
|
84
|
-
case C.EDGE_TOP:
|
|
85
|
-
arr[1] = value
|
|
86
|
-
break
|
|
87
|
-
case C.EDGE_RIGHT:
|
|
88
|
-
arr[2] = value
|
|
89
|
-
break
|
|
90
|
-
case C.EDGE_BOTTOM:
|
|
91
|
-
arr[3] = value
|
|
92
|
-
break
|
|
93
|
-
case C.EDGE_HORIZONTAL:
|
|
94
|
-
arr[0] = value
|
|
95
|
-
arr[2] = value
|
|
96
|
-
break
|
|
97
|
-
case C.EDGE_VERTICAL:
|
|
98
|
-
arr[1] = value
|
|
99
|
-
arr[3] = value
|
|
100
|
-
break
|
|
101
|
-
case C.EDGE_ALL:
|
|
102
|
-
arr[0] = value
|
|
103
|
-
arr[1] = value
|
|
104
|
-
arr[2] = value
|
|
105
|
-
arr[3] = value
|
|
106
|
-
break
|
|
107
|
-
case C.EDGE_START:
|
|
108
|
-
// Store in logical START slot (resolved to physical at layout time)
|
|
109
|
-
arr[4] = value
|
|
110
|
-
break
|
|
111
|
-
case C.EDGE_END:
|
|
112
|
-
// Store in logical END slot (resolved to physical at layout time)
|
|
113
|
-
arr[5] = value
|
|
114
|
-
break
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Get a value from an edge array.
|
|
120
|
-
*/
|
|
121
|
-
export function getEdgeValue(arr: [Value, Value, Value, Value, Value, Value], edge: number): Value {
|
|
122
|
-
switch (edge) {
|
|
123
|
-
case C.EDGE_LEFT:
|
|
124
|
-
return arr[0]
|
|
125
|
-
case C.EDGE_TOP:
|
|
126
|
-
return arr[1]
|
|
127
|
-
case C.EDGE_RIGHT:
|
|
128
|
-
return arr[2]
|
|
129
|
-
case C.EDGE_BOTTOM:
|
|
130
|
-
return arr[3]
|
|
131
|
-
case C.EDGE_START:
|
|
132
|
-
return arr[4]
|
|
133
|
-
case C.EDGE_END:
|
|
134
|
-
return arr[5]
|
|
135
|
-
default:
|
|
136
|
-
return arr[0] // Default to left
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Get a border value from an edge array.
|
|
142
|
-
*/
|
|
143
|
-
export function getEdgeBorderValue(arr: [number, number, number, number, number, number], edge: number): number {
|
|
144
|
-
switch (edge) {
|
|
145
|
-
case C.EDGE_LEFT:
|
|
146
|
-
return arr[0]
|
|
147
|
-
case C.EDGE_TOP:
|
|
148
|
-
return arr[1]
|
|
149
|
-
case C.EDGE_RIGHT:
|
|
150
|
-
return arr[2]
|
|
151
|
-
case C.EDGE_BOTTOM:
|
|
152
|
-
return arr[3]
|
|
153
|
-
case C.EDGE_START:
|
|
154
|
-
return arr[4]
|
|
155
|
-
case C.EDGE_END:
|
|
156
|
-
return arr[5]
|
|
157
|
-
default:
|
|
158
|
-
return arr[0] // Default to left
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Resolve a value (point or percent) to an absolute number.
|
|
164
|
-
*/
|
|
165
|
-
export function resolveValue(value: Value, availableSize: number): number {
|
|
166
|
-
switch (value.unit) {
|
|
167
|
-
case C.UNIT_POINT:
|
|
168
|
-
return value.value
|
|
169
|
-
case C.UNIT_PERCENT:
|
|
170
|
-
// Percentage against NaN (auto-sized parent) resolves to 0
|
|
171
|
-
if (Number.isNaN(availableSize)) {
|
|
172
|
-
return 0
|
|
173
|
-
}
|
|
174
|
-
return availableSize * (value.value / 100)
|
|
175
|
-
default:
|
|
176
|
-
return 0
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Apply min/max constraints to a size.
|
|
182
|
-
*
|
|
183
|
-
* CSS behavior:
|
|
184
|
-
* - min: Floor constraint. Does NOT affect children's layout — the container expands
|
|
185
|
-
* after shrink-wrap. When size is NaN (auto-sized), min is NOT applied here;
|
|
186
|
-
* the post-shrink-wrap applyMinMax call (Phase 9) handles it.
|
|
187
|
-
* - max: Ceiling constraint. DOES affect children's layout — content wraps/clips
|
|
188
|
-
* within the max. When size is NaN (auto-sized), max constrains the container
|
|
189
|
-
* so children are laid out within the max bound.
|
|
190
|
-
*
|
|
191
|
-
* Percent constraints that can't resolve (available is NaN) are skipped entirely,
|
|
192
|
-
* since resolveValue returns 0 for percent-against-NaN, which would incorrectly
|
|
193
|
-
* clamp sizes to 0.
|
|
194
|
-
*/
|
|
195
|
-
export function applyMinMax(size: number, min: Value, max: Value, available: number): number {
|
|
196
|
-
let result = size
|
|
197
|
-
|
|
198
|
-
// Apply max first, then min. CSS spec: when min > max, min wins.
|
|
199
|
-
// By applying max before min, Math.max(result, minValue) ensures min dominates.
|
|
200
|
-
|
|
201
|
-
if (max.unit !== C.UNIT_UNDEFINED) {
|
|
202
|
-
// Skip percent max when available is NaN — can't resolve meaningfully
|
|
203
|
-
if (max.unit === C.UNIT_PERCENT && Number.isNaN(available)) {
|
|
204
|
-
// Skip: percent against NaN resolves to 0, which would be wrong
|
|
205
|
-
} else {
|
|
206
|
-
const maxValue = resolveValue(max, available)
|
|
207
|
-
if (!Number.isNaN(maxValue)) {
|
|
208
|
-
// Apply max as ceiling even when size is NaN (auto-sized).
|
|
209
|
-
// This constrains children's layout to the max bound.
|
|
210
|
-
// Phase 9 shrink-wrap may reduce it further; the post-shrink-wrap
|
|
211
|
-
// applyMinMax call ensures max is still respected.
|
|
212
|
-
if (Number.isNaN(result)) {
|
|
213
|
-
// For auto-sized nodes, only apply finite max constraints.
|
|
214
|
-
// Infinity means "no real constraint" (e.g., silvery sets
|
|
215
|
-
// maxWidth=Infinity as default) and should not replace NaN.
|
|
216
|
-
if (maxValue !== Infinity) {
|
|
217
|
-
result = maxValue
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
result = Math.min(result, maxValue)
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (min.unit !== C.UNIT_UNDEFINED) {
|
|
227
|
-
// Skip percent min when available is NaN — can't resolve meaningfully
|
|
228
|
-
if (min.unit === C.UNIT_PERCENT && Number.isNaN(available)) {
|
|
229
|
-
// Skip: percent against NaN resolves to 0, which would be wrong
|
|
230
|
-
} else {
|
|
231
|
-
const minValue = resolveValue(min, available)
|
|
232
|
-
if (!Number.isNaN(minValue)) {
|
|
233
|
-
// Only apply min to definite sizes. When size is NaN (auto-sized),
|
|
234
|
-
// skip — the post-shrink-wrap applyMinMax call will floor it.
|
|
235
|
-
if (!Number.isNaN(result)) {
|
|
236
|
-
result = Math.max(result, minValue)
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return result
|
|
243
|
-
}
|