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
package/src/native-units.ts
DELETED
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
import { type NativeStyleResolveOptions } from './style';
|
|
2
|
-
import type { NativePlatform, NativePropValue, NativeFlexStyleValues, NativeRenderHints } from './native-types';
|
|
3
|
-
export function formatFloat(value: number): string {
|
|
4
|
-
return Number(value.toFixed(3)).toString();
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export function splitCssFunctionArguments(value: string): string[] {
|
|
9
|
-
const args: string[] = [];
|
|
10
|
-
let token = '';
|
|
11
|
-
let depth = 0;
|
|
12
|
-
|
|
13
|
-
for (const char of value.trim()) {
|
|
14
|
-
if (char === '(') {
|
|
15
|
-
depth += 1;
|
|
16
|
-
} else if (char === ')' && depth > 0) {
|
|
17
|
-
depth -= 1;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (char === ',' && depth === 0) {
|
|
21
|
-
const trimmed = token.trim();
|
|
22
|
-
if (trimmed) {
|
|
23
|
-
args.push(trimmed);
|
|
24
|
-
}
|
|
25
|
-
token = '';
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
token += char;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const trailing = token.trim();
|
|
33
|
-
if (trailing) {
|
|
34
|
-
args.push(trailing);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return args;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function evaluateCssLengthExpression(value: string, styleResolveOptions: NativeStyleResolveOptions): number | undefined {
|
|
41
|
-
let total = 0;
|
|
42
|
-
let token = '';
|
|
43
|
-
let depth = 0;
|
|
44
|
-
let operator: 1 | -1 = 1;
|
|
45
|
-
let hasValue = false;
|
|
46
|
-
let invalid = false;
|
|
47
|
-
|
|
48
|
-
const flushToken = (): void => {
|
|
49
|
-
const trimmed = token.trim();
|
|
50
|
-
token = '';
|
|
51
|
-
|
|
52
|
-
if (!trimmed) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const resolved = toScaledUnitNumber(trimmed, styleResolveOptions);
|
|
57
|
-
if (resolved === undefined) {
|
|
58
|
-
invalid = true;
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
total += operator * resolved;
|
|
63
|
-
hasValue = true;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
for (const char of value.trim()) {
|
|
67
|
-
if (char === '(') {
|
|
68
|
-
depth += 1;
|
|
69
|
-
} else if (char === ')' && depth > 0) {
|
|
70
|
-
depth -= 1;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (depth === 0 && (char === '+' || char === '-')) {
|
|
74
|
-
if (token.trim().length === 0) {
|
|
75
|
-
token += char;
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
flushToken();
|
|
80
|
-
operator = char === '+' ? 1 : -1;
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
token += char;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
flushToken();
|
|
88
|
-
return invalid || !hasValue ? undefined : total;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function toDpLiteral(
|
|
92
|
-
value: NativePropValue | undefined,
|
|
93
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
94
|
-
): string | undefined {
|
|
95
|
-
const resolved = toScaledUnitNumber(value, styleResolveOptions);
|
|
96
|
-
return resolved !== undefined ? `${formatFloat(resolved)}.dp` : undefined;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function toPointLiteral(
|
|
100
|
-
value: NativePropValue | undefined,
|
|
101
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
102
|
-
): string | undefined {
|
|
103
|
-
const resolved = toScaledUnitNumber(value, styleResolveOptions);
|
|
104
|
-
return resolved !== undefined ? formatFloat(resolved) : undefined;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function toSpLiteral(
|
|
108
|
-
value: NativePropValue | undefined,
|
|
109
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
110
|
-
): string | undefined {
|
|
111
|
-
const resolved = toScaledUnitNumber(value, styleResolveOptions);
|
|
112
|
-
return resolved !== undefined ? `${formatFloat(resolved)}.sp` : undefined;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function parsePlainNumericValue(value: NativePropValue | undefined): number | undefined {
|
|
116
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
117
|
-
return value;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (typeof value !== 'string') {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const trimmed = value.trim();
|
|
125
|
-
if (!/^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(trimmed)) {
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const parsed = Number(trimmed);
|
|
130
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function parseNativeSvgNumber(value: NativePropValue | undefined): number | undefined {
|
|
134
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
135
|
-
return value;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (typeof value !== 'string') {
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const trimmed = value.trim();
|
|
143
|
-
const match = trimmed.match(/^(-?(?:\d+(?:\.\d*)?|\.\d+))(?:px)?$/i);
|
|
144
|
-
if (!match) {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const parsed = Number(match[1]);
|
|
149
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function parseFlexShorthand(value: NativePropValue | undefined): NativeFlexStyleValues | undefined {
|
|
153
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
154
|
-
return { grow: value, shrink: 1, basis: 0 };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (typeof value !== 'string') {
|
|
158
|
-
return undefined;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const trimmed = value.trim();
|
|
162
|
-
if (!trimmed) {
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const normalized = trimmed.toLowerCase();
|
|
167
|
-
if (normalized === 'none') {
|
|
168
|
-
return { grow: 0, shrink: 0, basis: 'auto' };
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (normalized === 'auto') {
|
|
172
|
-
return { grow: 1, shrink: 1, basis: 'auto' };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (normalized === 'initial') {
|
|
176
|
-
return { grow: 0, shrink: 1, basis: 'auto' };
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const numericValue = parsePlainNumericValue(trimmed);
|
|
180
|
-
if (numericValue !== undefined) {
|
|
181
|
-
return { grow: numericValue, shrink: 1, basis: 0 };
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const tokens = trimmed.split(/\s+/).filter(Boolean);
|
|
185
|
-
if (tokens.length === 1) {
|
|
186
|
-
return { grow: 1, shrink: 1, basis: tokens[0] };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (tokens.length === 2) {
|
|
190
|
-
const grow = parsePlainNumericValue(tokens[0]);
|
|
191
|
-
if (grow === undefined) {
|
|
192
|
-
return undefined;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const shrink = parsePlainNumericValue(tokens[1]);
|
|
196
|
-
return shrink !== undefined
|
|
197
|
-
? { grow, shrink, basis: 0 }
|
|
198
|
-
: { grow, shrink: 1, basis: tokens[1] };
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (tokens.length === 3) {
|
|
202
|
-
const grow = parsePlainNumericValue(tokens[0]);
|
|
203
|
-
const shrink = parsePlainNumericValue(tokens[1]);
|
|
204
|
-
if (grow === undefined || shrink === undefined) {
|
|
205
|
-
return undefined;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return { grow, shrink, basis: tokens[2] };
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return undefined;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function resolveFlexStyleValues(style: Record<string, NativePropValue> | undefined): NativeFlexStyleValues {
|
|
215
|
-
const shorthand = parseFlexShorthand(style?.flex);
|
|
216
|
-
return {
|
|
217
|
-
grow: parsePlainNumericValue(style?.flexGrow) ?? shorthand?.grow,
|
|
218
|
-
shrink: parsePlainNumericValue(style?.flexShrink) ?? shorthand?.shrink,
|
|
219
|
-
basis: style?.flexBasis ?? shorthand?.basis,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function resolveOpacityValue(value: NativePropValue | undefined): number | undefined {
|
|
224
|
-
const opacity = parsePlainNumericValue(value);
|
|
225
|
-
if (opacity === undefined) {
|
|
226
|
-
return undefined;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return Math.min(1, Math.max(0, opacity));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export function resolveAspectRatioValue(value: NativePropValue | undefined): number | undefined {
|
|
233
|
-
const direct = parsePlainNumericValue(value);
|
|
234
|
-
if (direct !== undefined) {
|
|
235
|
-
return direct > 0 ? direct : undefined;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (typeof value !== 'string') {
|
|
239
|
-
return undefined;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const ratioMatch = value.trim().match(/^(-?(?:\d+(?:\.\d*)?|\.\d+))\s*\/\s*(-?(?:\d+(?:\.\d*)?|\.\d+))$/);
|
|
243
|
-
if (!ratioMatch) {
|
|
244
|
-
return undefined;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const numerator = Number(ratioMatch[1]);
|
|
248
|
-
const denominator = Number(ratioMatch[2]);
|
|
249
|
-
if (!Number.isFinite(numerator) || !Number.isFinite(denominator) || denominator === 0) {
|
|
250
|
-
return undefined;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const ratio = numerator / denominator;
|
|
254
|
-
return ratio > 0 ? ratio : undefined;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export function parsePercentageValue(value: NativePropValue | undefined): number | undefined {
|
|
258
|
-
if (typeof value !== 'string') {
|
|
259
|
-
return undefined;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const match = value.trim().match(/^(-?(?:\d+(?:\.\d*)?|\.\d+))%$/);
|
|
263
|
-
if (!match) {
|
|
264
|
-
return undefined;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const parsed = Number(match[1]);
|
|
268
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export function resolveAxisReferenceLength(
|
|
272
|
-
axis: 'horizontal' | 'vertical',
|
|
273
|
-
hints: NativeRenderHints | undefined,
|
|
274
|
-
styleResolveOptions: NativeStyleResolveOptions,
|
|
275
|
-
): number {
|
|
276
|
-
if (axis === 'horizontal') {
|
|
277
|
-
return hints?.availableWidth ?? styleResolveOptions.viewportWidth ?? 390;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return hints?.availableHeight ?? styleResolveOptions.viewportHeight ?? 844;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export function resolveAxisUnitNumber(
|
|
284
|
-
value: NativePropValue | undefined,
|
|
285
|
-
axis: 'horizontal' | 'vertical',
|
|
286
|
-
hints: NativeRenderHints | undefined,
|
|
287
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
288
|
-
): number | undefined {
|
|
289
|
-
const percentage = parsePercentageValue(value);
|
|
290
|
-
if (percentage !== undefined) {
|
|
291
|
-
return resolveAxisReferenceLength(axis, hints, styleResolveOptions) * (percentage / 100);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return toScaledUnitNumber(value, styleResolveOptions);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export function toAxisDpLiteral(
|
|
298
|
-
value: NativePropValue | undefined,
|
|
299
|
-
axis: 'horizontal' | 'vertical',
|
|
300
|
-
hints: NativeRenderHints | undefined,
|
|
301
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
302
|
-
): string | undefined {
|
|
303
|
-
const resolved = resolveAxisUnitNumber(value, axis, hints, styleResolveOptions);
|
|
304
|
-
return resolved !== undefined ? `${formatFloat(resolved)}.dp` : undefined;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export function toAxisPointLiteral(
|
|
308
|
-
value: NativePropValue | undefined,
|
|
309
|
-
axis: 'horizontal' | 'vertical',
|
|
310
|
-
hints: NativeRenderHints | undefined,
|
|
311
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
312
|
-
): string | undefined {
|
|
313
|
-
const resolved = resolveAxisUnitNumber(value, axis, hints, styleResolveOptions);
|
|
314
|
-
return resolved !== undefined ? formatFloat(resolved) : undefined;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export function isHiddenOverflowValue(value: NativePropValue | undefined): boolean {
|
|
318
|
-
if (typeof value !== 'string') {
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const normalized = value.trim().toLowerCase();
|
|
323
|
-
return normalized === 'hidden' || normalized === 'clip';
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
export function shouldClipNativeOverflow(style: Record<string, NativePropValue> | undefined): boolean {
|
|
327
|
-
if (!style) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return isHiddenOverflowValue(style.overflow)
|
|
332
|
-
|| isHiddenOverflowValue(style.overflowX)
|
|
333
|
-
|| isHiddenOverflowValue(style.overflowY);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
export function parseCssUnitValue(value: NativePropValue | undefined): { value: number; unit: string } | undefined {
|
|
337
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
338
|
-
return { value, unit: '' };
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
if (typeof value !== 'string') {
|
|
342
|
-
return undefined;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
const trimmed = value.trim();
|
|
346
|
-
const match = trimmed.match(/^(-?\d+(?:\.\d+)?)(px|dp|pt|sp|rem|em|vh|vw|vmin|vmax)?$/i);
|
|
347
|
-
if (!match) {
|
|
348
|
-
return undefined;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
return {
|
|
352
|
-
value: Number(match[1]),
|
|
353
|
-
unit: (match[2] ?? '').toLowerCase(),
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
export function toScaledUnitNumber(
|
|
358
|
-
value: NativePropValue | undefined,
|
|
359
|
-
styleResolveOptions: NativeStyleResolveOptions = getNativeStyleResolveOptions('generic'),
|
|
360
|
-
): number | undefined {
|
|
361
|
-
const parsed = parseCssUnitValue(value);
|
|
362
|
-
if (parsed) {
|
|
363
|
-
if (parsed.unit === 'rem' || parsed.unit === 'em') {
|
|
364
|
-
return parsed.value * 16;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (parsed.unit === 'vw') {
|
|
368
|
-
return (styleResolveOptions.viewportWidth ?? 1024) * (parsed.value / 100);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (parsed.unit === 'vh') {
|
|
372
|
-
return (styleResolveOptions.viewportHeight ?? 768) * (parsed.value / 100);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (parsed.unit === 'vmin') {
|
|
376
|
-
const viewportWidth = styleResolveOptions.viewportWidth ?? 1024;
|
|
377
|
-
const viewportHeight = styleResolveOptions.viewportHeight ?? 768;
|
|
378
|
-
return Math.min(viewportWidth, viewportHeight) * (parsed.value / 100);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
if (parsed.unit === 'vmax') {
|
|
382
|
-
const viewportWidth = styleResolveOptions.viewportWidth ?? 1024;
|
|
383
|
-
const viewportHeight = styleResolveOptions.viewportHeight ?? 768;
|
|
384
|
-
return Math.max(viewportWidth, viewportHeight) * (parsed.value / 100);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return parsed.value;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
if (typeof value !== 'string') {
|
|
391
|
-
return undefined;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const trimmed = value.trim();
|
|
395
|
-
const openParen = trimmed.indexOf('(');
|
|
396
|
-
if (openParen <= 0 || !trimmed.endsWith(')')) {
|
|
397
|
-
return undefined;
|
|
398
|
-
}
|
|
399
|
-
const functionName = trimmed.slice(0, openParen).toLowerCase();
|
|
400
|
-
if (!/^[a-z]+$/.test(functionName)) {
|
|
401
|
-
return undefined;
|
|
402
|
-
}
|
|
403
|
-
const innerValue = trimmed.slice(openParen + 1, -1).trim();
|
|
404
|
-
|
|
405
|
-
if (functionName === 'calc') {
|
|
406
|
-
return evaluateCssLengthExpression(innerValue, styleResolveOptions);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (functionName !== 'clamp' && functionName !== 'min' && functionName !== 'max') {
|
|
410
|
-
return undefined;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
const resolvedArguments = splitCssFunctionArguments(innerValue)
|
|
414
|
-
.map((entry) => toScaledUnitNumber(entry, styleResolveOptions));
|
|
415
|
-
if (resolvedArguments.length === 0 || resolvedArguments.some((entry) => entry === undefined)) {
|
|
416
|
-
return undefined;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
const numericArguments = resolvedArguments as number[];
|
|
420
|
-
if (functionName === 'clamp') {
|
|
421
|
-
if (numericArguments.length !== 3) {
|
|
422
|
-
return undefined;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
return Math.min(numericArguments[2], Math.max(numericArguments[0], numericArguments[1]));
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return functionName === 'min'
|
|
429
|
-
? Math.min(...numericArguments)
|
|
430
|
-
: Math.max(...numericArguments);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
export function getNativeStyleResolveOptions(platform: NativePlatform): NativeStyleResolveOptions {
|
|
435
|
-
return {
|
|
436
|
-
viewportWidth: platform === 'generic' ? 1024 : 390,
|
|
437
|
-
viewportHeight: platform === 'generic' ? 768 : 844,
|
|
438
|
-
colorScheme: 'light',
|
|
439
|
-
mediaType: 'screen',
|
|
440
|
-
};
|
|
441
|
-
}
|