elit 3.5.6 → 3.5.7
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/Cargo.toml +1 -1
- package/README.md +1 -1
- package/desktop/build.rs +83 -0
- package/desktop/icon.rs +106 -0
- package/desktop/lib.rs +2 -0
- package/desktop/main.rs +235 -0
- package/desktop/native_main.rs +128 -0
- package/desktop/native_renderer/action_widgets.rs +184 -0
- package/desktop/native_renderer/app_models.rs +171 -0
- package/desktop/native_renderer/app_runtime.rs +140 -0
- package/desktop/native_renderer/container_rendering.rs +610 -0
- package/desktop/native_renderer/content_widgets.rs +634 -0
- package/desktop/native_renderer/css_models.rs +371 -0
- package/desktop/native_renderer/embedded_surfaces.rs +414 -0
- package/desktop/native_renderer/form_controls.rs +516 -0
- package/desktop/native_renderer/interaction_dispatch.rs +89 -0
- package/desktop/native_renderer/runtime_support.rs +135 -0
- package/desktop/native_renderer/utilities.rs +495 -0
- package/desktop/native_renderer/vector_drawing.rs +491 -0
- package/desktop/native_renderer.rs +4122 -0
- package/desktop/runtime/external.rs +422 -0
- package/desktop/runtime/mod.rs +67 -0
- package/desktop/runtime/quickjs.rs +106 -0
- package/desktop/window.rs +383 -0
- package/package.json +6 -3
- package/dist/build.d.mts +0 -20
- package/dist/chokidar.d.mts +0 -134
- package/dist/cli.d.mts +0 -81
- package/dist/config.d.mts +0 -254
- package/dist/coverage.d.mts +0 -85
- package/dist/database.d.mts +0 -52
- package/dist/desktop.d.mts +0 -68
- package/dist/dom.d.mts +0 -87
- package/dist/el.d.mts +0 -208
- package/dist/fs.d.mts +0 -255
- package/dist/hmr.d.mts +0 -38
- package/dist/http.d.mts +0 -169
- package/dist/https.d.mts +0 -108
- package/dist/index.d.mts +0 -13
- package/dist/mime-types.d.mts +0 -48
- package/dist/native.d.mts +0 -136
- package/dist/path.d.mts +0 -163
- package/dist/router.d.mts +0 -49
- package/dist/runtime.d.mts +0 -97
- package/dist/server-D0Dp4R5z.d.mts +0 -449
- package/dist/server.d.mts +0 -7
- package/dist/state.d.mts +0 -117
- package/dist/style.d.mts +0 -232
- package/dist/test-reporter.d.mts +0 -77
- package/dist/test-runtime.d.mts +0 -122
- package/dist/test.d.mts +0 -39
- package/dist/types.d.mts +0 -586
- package/dist/universal.d.mts +0 -21
- package/dist/ws.d.mts +0 -200
- package/dist/wss.d.mts +0 -108
- package/src/build.ts +0 -362
- package/src/chokidar.ts +0 -427
- package/src/cli.ts +0 -1162
- package/src/config.ts +0 -509
- package/src/coverage.ts +0 -1479
- package/src/database.ts +0 -1410
- package/src/desktop-auto-render.ts +0 -317
- package/src/desktop-cli.ts +0 -1533
- package/src/desktop.ts +0 -99
- package/src/dev-build.ts +0 -340
- package/src/dom.ts +0 -901
- package/src/el.ts +0 -183
- package/src/fs.ts +0 -609
- package/src/hmr.ts +0 -149
- package/src/http.ts +0 -856
- package/src/https.ts +0 -411
- package/src/index.ts +0 -16
- package/src/mime-types.ts +0 -222
- package/src/mobile-cli.ts +0 -2313
- package/src/native-background.ts +0 -444
- package/src/native-border.ts +0 -343
- package/src/native-canvas.ts +0 -260
- package/src/native-cli.ts +0 -414
- package/src/native-color.ts +0 -904
- package/src/native-estimation.ts +0 -194
- package/src/native-grid.ts +0 -590
- package/src/native-interaction.ts +0 -1289
- package/src/native-layout.ts +0 -568
- package/src/native-link.ts +0 -76
- package/src/native-render-support.ts +0 -361
- package/src/native-spacing.ts +0 -231
- package/src/native-state.ts +0 -318
- package/src/native-strings.ts +0 -46
- package/src/native-transform.ts +0 -120
- package/src/native-types.ts +0 -439
- package/src/native-typography.ts +0 -254
- package/src/native-units.ts +0 -441
- package/src/native-vector.ts +0 -910
- package/src/native.ts +0 -5606
- package/src/path.ts +0 -493
- package/src/pm-cli.ts +0 -2498
- package/src/preview-build.ts +0 -294
- package/src/render-context.ts +0 -138
- package/src/router.ts +0 -260
- package/src/runtime.ts +0 -97
- package/src/server.ts +0 -2294
- package/src/state.ts +0 -556
- package/src/style.ts +0 -1790
- package/src/test-globals.d.ts +0 -184
- package/src/test-reporter.ts +0 -609
- package/src/test-runtime.ts +0 -1359
- package/src/test.ts +0 -368
- package/src/types.ts +0 -381
- package/src/universal.ts +0 -81
- package/src/wapk-cli.ts +0 -3213
- package/src/workspace-package.ts +0 -102
- package/src/ws.ts +0 -648
- package/src/wss.ts +0 -241
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import { type NativeStyleResolveOptions } from './style';
|
|
2
|
-
import type {
|
|
3
|
-
NativeBackgroundImageSpec,
|
|
4
|
-
NativeBackgroundLayerSpec,
|
|
5
|
-
NativeChunkedLayout,
|
|
6
|
-
NativeChunkedRow,
|
|
7
|
-
NativeContentStackAlignment,
|
|
8
|
-
NativeGridColumnTrackSizeSpec,
|
|
9
|
-
NativeGridItemAlignment,
|
|
10
|
-
NativePropValue,
|
|
11
|
-
} from './native-types';
|
|
12
|
-
import { toComposeBrushLiteral, toComposeColorLiteral, toSwiftColorLiteral, toSwiftGradientLiteral } from './native-color';
|
|
13
|
-
import { quoteKotlinString, quoteSwiftString } from './native-strings';
|
|
14
|
-
import { formatFloat, getNativeStyleResolveOptions, toPointLiteral } from './native-units';
|
|
15
|
-
import { appendComposeModifierCall } from './native-canvas';
|
|
16
|
-
import { buildComposeArrangement, buildComposeCrossAlignment } from './native-layout';
|
|
17
|
-
|
|
18
|
-
function indent(level: number): string {
|
|
19
|
-
return ' '.repeat(level);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function resolveNativeStretchChunkedRows(
|
|
23
|
-
rows: NativeChunkedRow[],
|
|
24
|
-
contentAlignment: NativeContentStackAlignment | undefined,
|
|
25
|
-
): NativeChunkedRow[] {
|
|
26
|
-
if (contentAlignment !== 'stretch') {
|
|
27
|
-
return rows;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return rows.map((row) => row.trackWeight === undefined && row.stretchEligible && row.height === undefined
|
|
31
|
-
? { ...row, trackWeight: 1 }
|
|
32
|
-
: row);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function resolveEffectiveChunkedContentAlignment(layout: NativeChunkedLayout): NativeContentStackAlignment | undefined {
|
|
36
|
-
return layout.kind === 'grid' && layout.rows.some((row) => row.trackWeight !== undefined)
|
|
37
|
-
? undefined
|
|
38
|
-
: layout.contentAlignment;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function buildComposeChunkedRowArguments(
|
|
42
|
-
style: Record<string, NativePropValue> | undefined,
|
|
43
|
-
modifier: string,
|
|
44
|
-
columnGap?: number,
|
|
45
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
46
|
-
): string {
|
|
47
|
-
const args = [`modifier = ${modifier}`];
|
|
48
|
-
const arrangement = buildComposeArrangement(
|
|
49
|
-
'Row',
|
|
50
|
-
style,
|
|
51
|
-
styleResolveOptions,
|
|
52
|
-
columnGap !== undefined ? `${formatFloat(columnGap)}.dp` : undefined,
|
|
53
|
-
);
|
|
54
|
-
if (arrangement) {
|
|
55
|
-
args.push(`horizontalArrangement = ${arrangement}`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const alignment = buildComposeCrossAlignment('Row', style);
|
|
59
|
-
if (alignment) {
|
|
60
|
-
args.push(`verticalAlignment = ${alignment}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return args.join(', ');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function buildComposeChunkedTrackModifier(baseModifier: string, row: NativeChunkedRow): string {
|
|
67
|
-
let modifier = baseModifier;
|
|
68
|
-
|
|
69
|
-
if (row.height !== undefined) {
|
|
70
|
-
modifier = appendComposeModifierCall(modifier, `height(${formatFloat(row.height)}.dp)`);
|
|
71
|
-
} else if (row.minHeight !== undefined || row.maxHeight !== undefined) {
|
|
72
|
-
const heightInArgs: string[] = [];
|
|
73
|
-
if (row.minHeight !== undefined) {
|
|
74
|
-
heightInArgs.push(`min = ${formatFloat(row.minHeight)}.dp`);
|
|
75
|
-
}
|
|
76
|
-
if (row.maxHeight !== undefined) {
|
|
77
|
-
heightInArgs.push(`max = ${formatFloat(row.maxHeight)}.dp`);
|
|
78
|
-
}
|
|
79
|
-
modifier = appendComposeModifierCall(modifier, `heightIn(${heightInArgs.join(', ')})`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return row.trackWeight !== undefined
|
|
83
|
-
? appendComposeModifierCall(modifier, `weight(${formatFloat(row.trackWeight)}f, fill = true)`)
|
|
84
|
-
: modifier;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function hasNativeGridColumnConstraint(spec: NativeGridColumnTrackSizeSpec | undefined): boolean {
|
|
88
|
-
return Boolean(spec && (spec.width !== undefined || spec.minWidth !== undefined || spec.maxWidth !== undefined));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function buildComposeGridCellModifier(
|
|
92
|
-
weight: number | undefined,
|
|
93
|
-
shouldExpandWidth: boolean,
|
|
94
|
-
shouldExpandHeight: boolean,
|
|
95
|
-
columnSize: NativeGridColumnTrackSizeSpec | undefined,
|
|
96
|
-
): string {
|
|
97
|
-
let modifier = 'Modifier';
|
|
98
|
-
|
|
99
|
-
if (weight !== undefined) {
|
|
100
|
-
modifier = appendComposeModifierCall(modifier, `weight(${formatFloat(weight)}f)`);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (shouldExpandWidth) {
|
|
104
|
-
modifier = appendComposeModifierCall(modifier, 'fillMaxWidth()');
|
|
105
|
-
}
|
|
106
|
-
if (shouldExpandHeight) {
|
|
107
|
-
modifier = appendComposeModifierCall(modifier, 'fillMaxHeight()');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (columnSize?.width !== undefined) {
|
|
111
|
-
modifier = appendComposeModifierCall(modifier, `width(${formatFloat(columnSize.width)}.dp)`);
|
|
112
|
-
} else if (columnSize?.minWidth !== undefined || columnSize?.maxWidth !== undefined) {
|
|
113
|
-
const widthInArgs: string[] = [];
|
|
114
|
-
if (columnSize.minWidth !== undefined) {
|
|
115
|
-
widthInArgs.push(`min = ${formatFloat(columnSize.minWidth)}.dp`);
|
|
116
|
-
}
|
|
117
|
-
if (columnSize.maxWidth !== undefined) {
|
|
118
|
-
widthInArgs.push(`max = ${formatFloat(columnSize.maxWidth)}.dp`);
|
|
119
|
-
}
|
|
120
|
-
modifier = appendComposeModifierCall(modifier, `widthIn(${widthInArgs.join(', ')})`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return modifier;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function resolveComposeGridCellContentAlignment(
|
|
127
|
-
horizontal: NativeGridItemAlignment | undefined,
|
|
128
|
-
vertical: NativeGridItemAlignment | undefined,
|
|
129
|
-
): string | undefined {
|
|
130
|
-
const resolvedHorizontal = horizontal && horizontal !== 'stretch' ? horizontal : undefined;
|
|
131
|
-
const resolvedVertical = vertical && vertical !== 'stretch' ? vertical : undefined;
|
|
132
|
-
if (!resolvedHorizontal && !resolvedVertical) {
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const horizontalToken = resolvedHorizontal === 'center'
|
|
137
|
-
? 'Center'
|
|
138
|
-
: resolvedHorizontal === 'end'
|
|
139
|
-
? 'End'
|
|
140
|
-
: 'Start';
|
|
141
|
-
const verticalToken = resolvedVertical === 'center'
|
|
142
|
-
? 'Center'
|
|
143
|
-
: resolvedVertical === 'end'
|
|
144
|
-
? 'Bottom'
|
|
145
|
-
: 'Top';
|
|
146
|
-
|
|
147
|
-
return verticalToken === 'Center' && horizontalToken === 'Center'
|
|
148
|
-
? 'Alignment.Center'
|
|
149
|
-
: `Alignment.${verticalToken}${horizontalToken}`;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function buildComposeChunkedColumnArrangement(layout: NativeChunkedLayout): string | undefined {
|
|
153
|
-
const contentAlignment = resolveEffectiveChunkedContentAlignment(layout);
|
|
154
|
-
const gap = layout.rowGap !== undefined ? `${formatFloat(layout.rowGap)}.dp` : undefined;
|
|
155
|
-
|
|
156
|
-
switch (contentAlignment) {
|
|
157
|
-
case 'center':
|
|
158
|
-
return gap ? `Arrangement.spacedBy(${gap}, Alignment.CenterVertically)` : 'Arrangement.Center';
|
|
159
|
-
case 'end':
|
|
160
|
-
return gap ? `Arrangement.spacedBy(${gap}, Alignment.Bottom)` : 'Arrangement.Bottom';
|
|
161
|
-
case 'space-between':
|
|
162
|
-
return 'Arrangement.SpaceBetween';
|
|
163
|
-
case 'space-around':
|
|
164
|
-
return 'Arrangement.SpaceAround';
|
|
165
|
-
case 'space-evenly':
|
|
166
|
-
return 'Arrangement.SpaceEvenly';
|
|
167
|
-
default:
|
|
168
|
-
return gap ? `Arrangement.spacedBy(${gap})` : undefined;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function buildComposeBackgroundImageInvocation(spec: NativeBackgroundImageSpec, modifier: string): string {
|
|
173
|
-
return `ElitBackgroundImage(source = ${quoteKotlinString(spec.source)}${spec.fit !== 'cover' ? `, backgroundSize = ${quoteKotlinString(spec.fit)}` : ''}${spec.position !== 'center' ? `, backgroundPosition = ${quoteKotlinString(spec.position)}` : ''}${spec.repeat !== 'no-repeat' ? `, backgroundRepeat = ${quoteKotlinString(spec.repeat)}` : ''}, modifier = ${modifier})`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function shouldRenderNativeBackgroundLayersWithWrapper(layers: NativeBackgroundLayerSpec[]): boolean {
|
|
177
|
-
return layers.length > 1 || layers.some((layer) => layer.kind === 'image');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function buildComposeBackgroundLayerInvocation(layer: NativeBackgroundLayerSpec, modifier: string): string {
|
|
181
|
-
if (layer.kind === 'image') {
|
|
182
|
-
return buildComposeBackgroundImageInvocation(layer, modifier);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const backgroundCall = layer.kind === 'gradient'
|
|
186
|
-
? `background(brush = ${toComposeBrushLiteral(layer.gradient)})`
|
|
187
|
-
: `background(${toComposeColorLiteral(layer.color)})`;
|
|
188
|
-
return `Box(modifier = ${appendComposeModifierCall(modifier, backgroundCall)})`;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export function buildSwiftBackgroundImageInvocation(spec: NativeBackgroundImageSpec): string {
|
|
192
|
-
return `elitBackgroundImageSurface(source: ${quoteSwiftString(spec.source)}${spec.fit !== 'cover' ? `, backgroundSize: ${quoteSwiftString(spec.fit)}` : ''}${spec.position !== 'center' ? `, backgroundPosition: ${quoteSwiftString(spec.position)}` : ''}${spec.repeat !== 'no-repeat' ? `, backgroundRepeat: ${quoteSwiftString(spec.repeat)}` : ''})`;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export function buildSwiftBackgroundLayerInvocation(layer: NativeBackgroundLayerSpec): string {
|
|
196
|
-
if (layer.kind === 'image') {
|
|
197
|
-
return buildSwiftBackgroundImageInvocation(layer);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const fillLiteral = layer.kind === 'gradient'
|
|
201
|
-
? toSwiftGradientLiteral(layer.gradient)
|
|
202
|
-
: toSwiftColorLiteral(layer.color);
|
|
203
|
-
return `Rectangle().fill(${fillLiteral}).frame(maxWidth: .infinity, maxHeight: .infinity)`;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export function appendSwiftUIBackgroundLayers(
|
|
207
|
-
lines: string[],
|
|
208
|
-
layers: NativeBackgroundLayerSpec[],
|
|
209
|
-
level: number,
|
|
210
|
-
style: Record<string, NativePropValue> | undefined,
|
|
211
|
-
styleResolveOptions: NativeStyleResolveOptions,
|
|
212
|
-
): string[] {
|
|
213
|
-
const radius = toPointLiteral(style?.borderRadius, styleResolveOptions);
|
|
214
|
-
const result = [...lines];
|
|
215
|
-
result.push(`${indent(level + 1)}.background(alignment: .topLeading) {`);
|
|
216
|
-
if (layers.length > 1) {
|
|
217
|
-
result.push(`${indent(level + 2)}ZStack {`);
|
|
218
|
-
for (const layer of [...layers].reverse()) {
|
|
219
|
-
result.push(`${indent(level + 3)}${buildSwiftBackgroundLayerInvocation(layer)}`);
|
|
220
|
-
}
|
|
221
|
-
result.push(`${indent(level + 2)}}`);
|
|
222
|
-
} else if (layers[0]) {
|
|
223
|
-
result.push(`${indent(level + 2)}${buildSwiftBackgroundLayerInvocation(layers[0])}`);
|
|
224
|
-
}
|
|
225
|
-
if (radius) {
|
|
226
|
-
result.push(`${indent(level + 3)}.clipShape(RoundedRectangle(cornerRadius: ${radius}))`);
|
|
227
|
-
}
|
|
228
|
-
result.push(`${indent(level + 1)}}`);
|
|
229
|
-
return result;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export function resolveSwiftGridCellFrameAlignment(
|
|
233
|
-
horizontal: NativeGridItemAlignment | undefined,
|
|
234
|
-
vertical: NativeGridItemAlignment | undefined,
|
|
235
|
-
): string | undefined {
|
|
236
|
-
const resolvedHorizontal = horizontal && horizontal !== 'stretch' ? horizontal : undefined;
|
|
237
|
-
const resolvedVertical = vertical && vertical !== 'stretch' ? vertical : undefined;
|
|
238
|
-
if (!resolvedHorizontal && !resolvedVertical) {
|
|
239
|
-
return undefined;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const horizontalToken = resolvedHorizontal === 'center'
|
|
243
|
-
? 'center'
|
|
244
|
-
: resolvedHorizontal === 'end'
|
|
245
|
-
? 'trailing'
|
|
246
|
-
: 'leading';
|
|
247
|
-
const verticalToken = resolvedVertical === 'center'
|
|
248
|
-
? 'center'
|
|
249
|
-
: resolvedVertical === 'end'
|
|
250
|
-
? 'bottom'
|
|
251
|
-
: 'top';
|
|
252
|
-
|
|
253
|
-
if (verticalToken === 'center') {
|
|
254
|
-
if (horizontalToken === 'center') {
|
|
255
|
-
return '.center';
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return horizontalToken === 'trailing' ? '.trailing' : '.leading';
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (horizontalToken === 'center') {
|
|
262
|
-
return verticalToken === 'bottom' ? '.bottom' : '.top';
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return `.${verticalToken}${horizontalToken === 'trailing' ? 'Trailing' : 'Leading'}`;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export function resolveNativeGridCellFillWidth(defaultFillWidth: boolean, horizontalAlignment: NativeGridItemAlignment | undefined): boolean {
|
|
269
|
-
if (!horizontalAlignment) {
|
|
270
|
-
return defaultFillWidth;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return horizontalAlignment === 'stretch';
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
export function buildSwiftGridCellFrameModifier(
|
|
277
|
-
shouldExpandWidth: boolean,
|
|
278
|
-
shouldExpandHeight: boolean,
|
|
279
|
-
alignment: string | undefined,
|
|
280
|
-
columnSize?: NativeGridColumnTrackSizeSpec,
|
|
281
|
-
): string | undefined {
|
|
282
|
-
const frameArgs: string[] = [];
|
|
283
|
-
if (columnSize?.width !== undefined) {
|
|
284
|
-
frameArgs.push(`width: ${formatFloat(columnSize.width)}`);
|
|
285
|
-
} else {
|
|
286
|
-
if (columnSize?.minWidth !== undefined) {
|
|
287
|
-
frameArgs.push(`minWidth: ${formatFloat(columnSize.minWidth)}`);
|
|
288
|
-
}
|
|
289
|
-
if (columnSize?.maxWidth !== undefined) {
|
|
290
|
-
frameArgs.push(`maxWidth: ${formatFloat(columnSize.maxWidth)}`);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
if (shouldExpandWidth) {
|
|
294
|
-
frameArgs.push('maxWidth: .infinity');
|
|
295
|
-
}
|
|
296
|
-
if (shouldExpandHeight) {
|
|
297
|
-
frameArgs.push('maxHeight: .infinity');
|
|
298
|
-
}
|
|
299
|
-
if (alignment) {
|
|
300
|
-
frameArgs.push(`alignment: ${alignment}`);
|
|
301
|
-
} else if (frameArgs.length > 0) {
|
|
302
|
-
frameArgs.push(`alignment: ${shouldExpandHeight ? '.topLeading' : '.leading'}`);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
return frameArgs.length > 0 ? `.frame(${frameArgs.join(', ')})` : undefined;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export function buildSwiftChunkedRowModifiers(row: NativeChunkedRow): string[] {
|
|
309
|
-
if (row.height === undefined && row.minHeight === undefined && row.maxHeight === undefined && row.trackWeight === undefined) {
|
|
310
|
-
return [];
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const frameArgs = ['maxWidth: .infinity'];
|
|
314
|
-
if (row.height !== undefined) {
|
|
315
|
-
frameArgs.push(`height: ${formatFloat(row.height)}`);
|
|
316
|
-
} else {
|
|
317
|
-
if (row.minHeight !== undefined) {
|
|
318
|
-
frameArgs.push(`minHeight: ${formatFloat(row.minHeight)}`);
|
|
319
|
-
}
|
|
320
|
-
if (row.maxHeight !== undefined) {
|
|
321
|
-
frameArgs.push(`maxHeight: ${formatFloat(row.maxHeight)}`);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (row.trackWeight !== undefined && !frameArgs.includes('maxHeight: .infinity')) {
|
|
326
|
-
frameArgs.push('maxHeight: .infinity');
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
frameArgs.push('alignment: .topLeading');
|
|
330
|
-
|
|
331
|
-
return [
|
|
332
|
-
`.frame(${frameArgs.join(', ')})`,
|
|
333
|
-
...(row.trackWeight !== undefined ? [`.layoutPriority(${formatFloat(row.trackWeight)})`] : []),
|
|
334
|
-
];
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export function appendSwiftUIModifiers(lines: string[], modifiers: string[], level: number): string[] {
|
|
338
|
-
if (modifiers.length === 0) {
|
|
339
|
-
return lines;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
return [
|
|
343
|
-
...lines,
|
|
344
|
-
...modifiers.map((modifier) => `${indent(level + 1)}${modifier}`),
|
|
345
|
-
];
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export function appendSwiftUIOverlays(lines: string[], overlays: string[][], level: number): string[] {
|
|
349
|
-
if (overlays.length === 0) {
|
|
350
|
-
return lines;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const result = [...lines];
|
|
354
|
-
for (const overlayLines of overlays) {
|
|
355
|
-
result.push(`${indent(level + 1)}.overlay(alignment: .topLeading) {`);
|
|
356
|
-
result.push(...overlayLines);
|
|
357
|
-
result.push(`${indent(level + 1)}}`);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
return result;
|
|
361
|
-
}
|
package/src/native-spacing.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { type NativeStyleResolveOptions } from './style';
|
|
2
|
-
import type { NativeAutoMarginFlags, NativePropValue } from './native-types';
|
|
3
|
-
import { formatFloat, getNativeStyleResolveOptions, toScaledUnitNumber } from './native-units';
|
|
4
|
-
import { isFillValue } from './native-color';
|
|
5
|
-
|
|
6
|
-
function parseSpacingShorthand(
|
|
7
|
-
value: NativePropValue | undefined,
|
|
8
|
-
unitParser: (value: NativePropValue | undefined) => string | undefined,
|
|
9
|
-
): { top?: string; right?: string; bottom?: string; left?: string } | undefined {
|
|
10
|
-
if (value === undefined) return undefined;
|
|
11
|
-
|
|
12
|
-
const rawValues = typeof value === 'string'
|
|
13
|
-
? value.trim().split(/\s+/).filter(Boolean)
|
|
14
|
-
: [value];
|
|
15
|
-
|
|
16
|
-
if (rawValues.length === 0 || rawValues.length > 4) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const parsed = rawValues.map((item) => unitParser(item));
|
|
21
|
-
if (parsed.some((item) => !item)) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const [first, second = first, third = first, fourth = second] = parsed as string[];
|
|
26
|
-
|
|
27
|
-
switch (parsed.length) {
|
|
28
|
-
case 1:
|
|
29
|
-
return { top: first, right: first, bottom: first, left: first };
|
|
30
|
-
case 2:
|
|
31
|
-
return { top: first, right: second, bottom: first, left: second };
|
|
32
|
-
case 3:
|
|
33
|
-
return { top: first, right: second, bottom: third, left: second };
|
|
34
|
-
case 4:
|
|
35
|
-
return { top: first, right: second, bottom: third, left: fourth };
|
|
36
|
-
default:
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function resolveDirectionalSpacing(
|
|
42
|
-
style: Record<string, NativePropValue>,
|
|
43
|
-
prefix: 'padding' | 'margin',
|
|
44
|
-
unitParser: (value: NativePropValue | undefined) => string | undefined,
|
|
45
|
-
): { top?: string; right?: string; bottom?: string; left?: string } {
|
|
46
|
-
const shorthand = parseSpacingShorthand(style[prefix], unitParser);
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
top: shorthand?.top ?? unitParser(style[`${prefix}Top`]),
|
|
50
|
-
right: shorthand?.right ?? unitParser(style[`${prefix}Right`] ?? style[`${prefix}End`]),
|
|
51
|
-
bottom: shorthand?.bottom ?? unitParser(style[`${prefix}Bottom`]),
|
|
52
|
-
left: shorthand?.left ?? unitParser(style[`${prefix}Left`] ?? style[`${prefix}Start`]),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function toNumericSpacingValue(value: string | undefined): number | undefined {
|
|
57
|
-
if (value === undefined) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const parsed = Number(value);
|
|
62
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function resolveNumericDirectionalSpacing(
|
|
66
|
-
style: Record<string, NativePropValue>,
|
|
67
|
-
prefix: 'padding' | 'margin',
|
|
68
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
69
|
-
): { top?: number; right?: number; bottom?: number; left?: number } {
|
|
70
|
-
const shorthand = parseSpacingShorthand(style[prefix], (spacingValue) => {
|
|
71
|
-
const resolved = toScaledUnitNumber(spacingValue, styleResolveOptions);
|
|
72
|
-
return resolved !== undefined ? String(resolved) : undefined;
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
top: toNumericSpacingValue(shorthand?.top) ?? toScaledUnitNumber(style[`${prefix}Top`], styleResolveOptions),
|
|
77
|
-
right: toNumericSpacingValue(shorthand?.right) ?? toScaledUnitNumber(style[`${prefix}Right`] ?? style[`${prefix}End`], styleResolveOptions),
|
|
78
|
-
bottom: toNumericSpacingValue(shorthand?.bottom) ?? toScaledUnitNumber(style[`${prefix}Bottom`], styleResolveOptions),
|
|
79
|
-
left: toNumericSpacingValue(shorthand?.left) ?? toScaledUnitNumber(style[`${prefix}Left`] ?? style[`${prefix}Start`], styleResolveOptions),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function buildComposeMarginPaddingCalls(
|
|
84
|
-
style: Record<string, NativePropValue> | undefined,
|
|
85
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
86
|
-
): string[] {
|
|
87
|
-
if (!style) {
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const spacing = resolveNumericDirectionalSpacing(style, 'margin', styleResolveOptions);
|
|
92
|
-
const args: string[] = [];
|
|
93
|
-
if (spacing.top) args.push(`top = ${formatFloat(spacing.top)}.dp`);
|
|
94
|
-
if (spacing.right) args.push(`end = ${formatFloat(spacing.right)}.dp`);
|
|
95
|
-
if (spacing.bottom) args.push(`bottom = ${formatFloat(spacing.bottom)}.dp`);
|
|
96
|
-
if (spacing.left) args.push(`start = ${formatFloat(spacing.left)}.dp`);
|
|
97
|
-
|
|
98
|
-
return args.length > 0 ? [`padding(${args.join(', ')})`] : [];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function buildSwiftMarginPaddingModifiers(
|
|
102
|
-
style: Record<string, NativePropValue> | undefined,
|
|
103
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
104
|
-
): string[] {
|
|
105
|
-
if (!style) {
|
|
106
|
-
return [];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const spacing = resolveNumericDirectionalSpacing(style, 'margin', styleResolveOptions);
|
|
110
|
-
const modifiers: string[] = [];
|
|
111
|
-
if (spacing.top) modifiers.push(`.padding(.top, ${formatFloat(spacing.top)})`);
|
|
112
|
-
if (spacing.right) modifiers.push(`.padding(.trailing, ${formatFloat(spacing.right)})`);
|
|
113
|
-
if (spacing.bottom) modifiers.push(`.padding(.bottom, ${formatFloat(spacing.bottom)})`);
|
|
114
|
-
if (spacing.left) modifiers.push(`.padding(.leading, ${formatFloat(spacing.left)})`);
|
|
115
|
-
|
|
116
|
-
return modifiers;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function parseAutoMarginFlags(style: Record<string, NativePropValue> | undefined): NativeAutoMarginFlags {
|
|
120
|
-
const flags: NativeAutoMarginFlags = {
|
|
121
|
-
top: false,
|
|
122
|
-
right: false,
|
|
123
|
-
bottom: false,
|
|
124
|
-
left: false,
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
if (!style) {
|
|
128
|
-
return flags;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const markValue = (value: NativePropValue | undefined, sides: Array<keyof NativeAutoMarginFlags>): void => {
|
|
132
|
-
if (typeof value === 'string' && value.trim().toLowerCase() === 'auto') {
|
|
133
|
-
sides.forEach((side) => {
|
|
134
|
-
flags[side] = true;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
markValue(style.marginTop, ['top']);
|
|
140
|
-
markValue(style.marginRight ?? style.marginEnd, ['right']);
|
|
141
|
-
markValue(style.marginBottom, ['bottom']);
|
|
142
|
-
markValue(style.marginLeft ?? style.marginStart, ['left']);
|
|
143
|
-
|
|
144
|
-
if (typeof style.margin === 'string') {
|
|
145
|
-
const values = style.margin.trim().split(/\s+/).filter(Boolean);
|
|
146
|
-
const resolved = [values[0], values[1] ?? values[0], values[2] ?? values[0], values[3] ?? values[1] ?? values[0]];
|
|
147
|
-
markValue(resolved[0], ['top']);
|
|
148
|
-
markValue(resolved[1], ['right']);
|
|
149
|
-
markValue(resolved[2], ['bottom']);
|
|
150
|
-
markValue(resolved[3], ['left']);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return flags;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function hasHorizontalAutoMargins(style: Record<string, NativePropValue> | undefined): boolean {
|
|
157
|
-
const flags = parseAutoMarginFlags(style);
|
|
158
|
-
return flags.left && flags.right;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function shouldCenterConstrainedHorizontalAutoMargins(style: Record<string, NativePropValue> | undefined): boolean {
|
|
162
|
-
if (!style || !hasHorizontalAutoMargins(style)) {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (isFillValue(style.width)) {
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return style.width !== undefined || style.minWidth !== undefined || style.maxWidth !== undefined;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function buildComposeAutoMarginCalls(style: Record<string, NativePropValue> | undefined): string[] {
|
|
174
|
-
if (!shouldCenterConstrainedHorizontalAutoMargins(style)) {
|
|
175
|
-
return [];
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return ['wrapContentWidth(Alignment.CenterHorizontally)'];
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export function buildSwiftAutoMarginModifiers(style: Record<string, NativePropValue> | undefined): string[] {
|
|
182
|
-
if (!hasHorizontalAutoMargins(style)) {
|
|
183
|
-
return [];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return ['.frame(maxWidth: .infinity, alignment: .center)'];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function estimateHorizontalPadding(
|
|
190
|
-
style: Record<string, NativePropValue> | undefined,
|
|
191
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
192
|
-
): number {
|
|
193
|
-
if (!style) {
|
|
194
|
-
return 0;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const spacing = resolveNumericDirectionalSpacing(style, 'padding', styleResolveOptions);
|
|
198
|
-
if (spacing.left !== undefined || spacing.right !== undefined) {
|
|
199
|
-
return (spacing.left ?? 0) + (spacing.right ?? 0);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const horizontal = toScaledUnitNumber(style.paddingHorizontal, styleResolveOptions);
|
|
203
|
-
if (horizontal !== undefined) {
|
|
204
|
-
return horizontal * 2;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const padding = toScaledUnitNumber(style.padding, styleResolveOptions);
|
|
208
|
-
return padding !== undefined ? padding * 2 : 0;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function estimateVerticalPadding(
|
|
212
|
-
style: Record<string, NativePropValue> | undefined,
|
|
213
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
214
|
-
): number {
|
|
215
|
-
if (!style) {
|
|
216
|
-
return 0;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const spacing = resolveNumericDirectionalSpacing(style, 'padding', styleResolveOptions);
|
|
220
|
-
if (spacing.top !== undefined || spacing.bottom !== undefined) {
|
|
221
|
-
return (spacing.top ?? 0) + (spacing.bottom ?? 0);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const vertical = toScaledUnitNumber(style.paddingVertical, styleResolveOptions);
|
|
225
|
-
if (vertical !== undefined) {
|
|
226
|
-
return vertical * 2;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const padding = toScaledUnitNumber(style.padding, styleResolveOptions);
|
|
230
|
-
return padding !== undefined ? padding * 2 : 0;
|
|
231
|
-
}
|