rnxsim 0.1.507 → 0.1.508
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-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +1 -1
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +19 -8
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +1 -1
- package/dist-lib/swift.cjs +507 -0
- package/dist-lib/vite.cjs +185 -5
- package/package.json +6 -1
- package/src/swift.ts +6 -0
- package/src/vite-plugin-one.ts +8 -0
- package/src/vite-plugin-swift.ts +254 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
/*! rnx v0.1.508 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
|
+
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
|
+
"use strict";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/swift.ts
|
|
23
|
+
var swift_exports = {};
|
|
24
|
+
__export(swift_exports, {
|
|
25
|
+
createSwiftModule: () => createSwiftModule
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(swift_exports);
|
|
28
|
+
|
|
29
|
+
// ../sootsim-swift/src/mount.tsx
|
|
30
|
+
var import_swift_ui = require("@expo/ui/swift-ui");
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
var import_react_native = require("react-native");
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
function isRecord(value) {
|
|
35
|
+
return typeof value === "object" && value !== null;
|
|
36
|
+
}
|
|
37
|
+
function readModifier(value) {
|
|
38
|
+
if (!isRecord(value) || typeof value.$type !== "string") {
|
|
39
|
+
throw new Error("swift modifier is not a { $type } object");
|
|
40
|
+
}
|
|
41
|
+
return { ...value, $type: value.$type };
|
|
42
|
+
}
|
|
43
|
+
function readNode(value) {
|
|
44
|
+
if (!isRecord(value)) throw new Error("swift node is not an object");
|
|
45
|
+
const { t, id, p, m, c, h } = value;
|
|
46
|
+
if (typeof t !== "string" || typeof id !== "string") {
|
|
47
|
+
throw new Error("swift node has no type or identity");
|
|
48
|
+
}
|
|
49
|
+
const node = { t, id };
|
|
50
|
+
if (p !== void 0) {
|
|
51
|
+
if (!isRecord(p)) throw new Error(`swift node ${id} has a non-object props`);
|
|
52
|
+
node.p = p;
|
|
53
|
+
}
|
|
54
|
+
if (m !== void 0) {
|
|
55
|
+
if (!Array.isArray(m)) throw new Error(`swift node ${id} has a non-array modifiers`);
|
|
56
|
+
node.m = m.map(readModifier);
|
|
57
|
+
}
|
|
58
|
+
if (c !== void 0) {
|
|
59
|
+
if (!Array.isArray(c)) throw new Error(`swift node ${id} has non-array children`);
|
|
60
|
+
node.c = c.map(readNode);
|
|
61
|
+
}
|
|
62
|
+
if (h !== void 0) {
|
|
63
|
+
if (!isRecord(h)) throw new Error(`swift node ${id} has non-object handlers`);
|
|
64
|
+
const handlers = {};
|
|
65
|
+
for (const [name, handlerId2] of Object.entries(h)) {
|
|
66
|
+
if (typeof handlerId2 !== "number") {
|
|
67
|
+
throw new Error(`swift node ${id} handler ${name} is not a number`);
|
|
68
|
+
}
|
|
69
|
+
handlers[name] = handlerId2;
|
|
70
|
+
}
|
|
71
|
+
node.h = handlers;
|
|
72
|
+
}
|
|
73
|
+
return node;
|
|
74
|
+
}
|
|
75
|
+
function readTree(text) {
|
|
76
|
+
const value = JSON.parse(text);
|
|
77
|
+
if (!Array.isArray(value)) throw new Error("swift tree is not an array");
|
|
78
|
+
return value.map(readNode);
|
|
79
|
+
}
|
|
80
|
+
var WASI_BADF = 8;
|
|
81
|
+
function wasiImports(host) {
|
|
82
|
+
return {
|
|
83
|
+
args_get: () => 0,
|
|
84
|
+
args_sizes_get: (argcPtr, argvSizePtr) => {
|
|
85
|
+
host.writeU32(argcPtr, 0);
|
|
86
|
+
host.writeU32(argvSizePtr, 0);
|
|
87
|
+
return 0;
|
|
88
|
+
},
|
|
89
|
+
environ_get: () => 0,
|
|
90
|
+
environ_sizes_get: (countPtr, sizePtr) => {
|
|
91
|
+
host.writeU32(countPtr, 0);
|
|
92
|
+
host.writeU32(sizePtr, 0);
|
|
93
|
+
return 0;
|
|
94
|
+
},
|
|
95
|
+
fd_close: () => WASI_BADF,
|
|
96
|
+
fd_fdstat_get: () => WASI_BADF,
|
|
97
|
+
fd_prestat_get: () => WASI_BADF,
|
|
98
|
+
fd_prestat_dir_name: () => WASI_BADF,
|
|
99
|
+
fd_read: () => WASI_BADF,
|
|
100
|
+
fd_seek: () => WASI_BADF,
|
|
101
|
+
fd_write: (_fd, iovsPtr, iovsLen, writtenPtr) => {
|
|
102
|
+
const view = new DataView(host.bytes().buffer);
|
|
103
|
+
let written = 0;
|
|
104
|
+
for (let index = 0; index < iovsLen; index += 1) {
|
|
105
|
+
written += view.getUint32(iovsPtr + index * 8 + 4, true);
|
|
106
|
+
}
|
|
107
|
+
host.writeU32(writtenPtr, written);
|
|
108
|
+
return 0;
|
|
109
|
+
},
|
|
110
|
+
path_open: () => WASI_BADF,
|
|
111
|
+
proc_exit: (code) => {
|
|
112
|
+
throw new Error(`swift app exited with code ${code}`);
|
|
113
|
+
},
|
|
114
|
+
random_get: (bufferPtr, length) => {
|
|
115
|
+
crypto.getRandomValues(host.bytes().subarray(bufferPtr, bufferPtr + length));
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function rawExport(exports2, name) {
|
|
121
|
+
const value = exports2[name];
|
|
122
|
+
if (typeof value !== "function") {
|
|
123
|
+
throw new Error(`swift artifact has no exported function ${name}`);
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
function pointerExport(exports2, name) {
|
|
128
|
+
const fn = rawExport(exports2, name);
|
|
129
|
+
return (...args) => {
|
|
130
|
+
const result = Reflect.apply(fn, void 0, args);
|
|
131
|
+
if (typeof result !== "number") {
|
|
132
|
+
throw new Error(`swift export ${name} returned ${typeof result}`);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function voidExport(exports2, name) {
|
|
138
|
+
const fn = rawExport(exports2, name);
|
|
139
|
+
return (...args) => {
|
|
140
|
+
Reflect.apply(fn, void 0, args);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function instantiate(module2) {
|
|
144
|
+
let memory;
|
|
145
|
+
const requireMemory = () => {
|
|
146
|
+
if (!memory) throw new Error("swift artifact memory is not live");
|
|
147
|
+
return memory;
|
|
148
|
+
};
|
|
149
|
+
const host = {
|
|
150
|
+
writeU32(ptr, value) {
|
|
151
|
+
new DataView(requireMemory().buffer).setUint32(ptr, value, true);
|
|
152
|
+
},
|
|
153
|
+
bytes: () => new Uint8Array(requireMemory().buffer)
|
|
154
|
+
};
|
|
155
|
+
const instance = new WebAssembly.Instance(module2, {
|
|
156
|
+
wasi_snapshot_preview1: wasiImports(host)
|
|
157
|
+
});
|
|
158
|
+
const exportedMemory = instance.exports.memory;
|
|
159
|
+
if (!(exportedMemory instanceof WebAssembly.Memory)) {
|
|
160
|
+
throw new Error("swift artifact does not export its memory");
|
|
161
|
+
}
|
|
162
|
+
memory = exportedMemory;
|
|
163
|
+
const initialize = voidExport(instance.exports, "_initialize");
|
|
164
|
+
const mainArgv = voidExport(instance.exports, "__main_argc_argv");
|
|
165
|
+
const mount = pointerExport(instance.exports, "rnx_mount");
|
|
166
|
+
const event = pointerExport(instance.exports, "rnx_event");
|
|
167
|
+
const stateExport = pointerExport(instance.exports, "rnx_state_export");
|
|
168
|
+
const stateImport = voidExport(instance.exports, "rnx_state_import");
|
|
169
|
+
const alloc = pointerExport(instance.exports, "rnx_alloc");
|
|
170
|
+
const free = voidExport(instance.exports, "rnx_free");
|
|
171
|
+
const readBuffer = (ptr) => {
|
|
172
|
+
const view = new DataView(requireMemory().buffer);
|
|
173
|
+
const length = view.getUint32(ptr, true);
|
|
174
|
+
return new TextDecoder().decode(
|
|
175
|
+
new Uint8Array(requireMemory().buffer, ptr + 4, length)
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
const withPayload = (value, run) => {
|
|
179
|
+
const encoded = new TextEncoder().encode(JSON.stringify(value));
|
|
180
|
+
const ptr = alloc(encoded.length);
|
|
181
|
+
new Uint8Array(requireMemory().buffer).set(encoded, ptr);
|
|
182
|
+
const result = run(ptr, encoded.length);
|
|
183
|
+
free(ptr);
|
|
184
|
+
return result;
|
|
185
|
+
};
|
|
186
|
+
initialize();
|
|
187
|
+
mainArgv(0, 0);
|
|
188
|
+
return {
|
|
189
|
+
mount: () => readTree(readBuffer(mount())),
|
|
190
|
+
deliver: (handlerId2, payload) => readTree(
|
|
191
|
+
readBuffer(
|
|
192
|
+
withPayload(
|
|
193
|
+
payload,
|
|
194
|
+
(ptr, length) => (
|
|
195
|
+
// handler ids are opaque to the tenant: they come from the tree
|
|
196
|
+
// this instance just returned and they are only meaningful to it
|
|
197
|
+
event(handlerId2, ptr, length)
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
)
|
|
201
|
+
),
|
|
202
|
+
exportState: () => readBuffer(stateExport()),
|
|
203
|
+
importState: (state) => {
|
|
204
|
+
withPayload(JSON.parse(state), (ptr, length) => {
|
|
205
|
+
stateImport(ptr, length);
|
|
206
|
+
return 0;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
var compiledModules = /* @__PURE__ */ new Map();
|
|
212
|
+
function compile(url) {
|
|
213
|
+
const cached = compiledModules.get(url);
|
|
214
|
+
if (cached) return cached;
|
|
215
|
+
const pending = fetch(url).then((response) => {
|
|
216
|
+
if (!response.ok) {
|
|
217
|
+
throw new Error(`swift artifact ${url} answered ${response.status}`);
|
|
218
|
+
}
|
|
219
|
+
return response.arrayBuffer();
|
|
220
|
+
}).then((bytes) => WebAssembly.compile(bytes));
|
|
221
|
+
compiledModules.set(url, pending);
|
|
222
|
+
return pending;
|
|
223
|
+
}
|
|
224
|
+
var HIERARCHICAL = /* @__PURE__ */ new Map([
|
|
225
|
+
["label", "primary"],
|
|
226
|
+
["secondaryLabel", "secondary"]
|
|
227
|
+
]);
|
|
228
|
+
function withAlpha(color, alpha) {
|
|
229
|
+
const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color);
|
|
230
|
+
if (hex) {
|
|
231
|
+
const digits = hex[1];
|
|
232
|
+
const full = digits.length === 3 ? digits.split("").map((digit) => digit + digit).join("") : digits;
|
|
233
|
+
const value = Number.parseInt(full, 16);
|
|
234
|
+
return `rgba(${value >> 16 & 255},${value >> 8 & 255},${value & 255},${alpha})`;
|
|
235
|
+
}
|
|
236
|
+
const rgba = /^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\s*\)$/.exec(color);
|
|
237
|
+
if (rgba) {
|
|
238
|
+
return `rgba(${rgba[1]},${rgba[2]},${rgba[3]},${Number(rgba[4]) * alpha})`;
|
|
239
|
+
}
|
|
240
|
+
throw new Error(`swift color ${color} cannot take opacity ${alpha}`);
|
|
241
|
+
}
|
|
242
|
+
function splitColor(value) {
|
|
243
|
+
const at = value.lastIndexOf("@");
|
|
244
|
+
return at === -1 ? { name: value, alpha: 1 } : { name: value.slice(0, at), alpha: Number(value.slice(at + 1)) };
|
|
245
|
+
}
|
|
246
|
+
function resolveColor(value) {
|
|
247
|
+
const { name, alpha } = splitColor(value);
|
|
248
|
+
const resolved = (0, import_react_native.PlatformColor)(name);
|
|
249
|
+
if (alpha === 1) return resolved;
|
|
250
|
+
if (typeof resolved === "string") return withAlpha(resolved, alpha);
|
|
251
|
+
if (isRecord(resolved) && isRecord(resolved.dynamic)) {
|
|
252
|
+
const variants = {};
|
|
253
|
+
for (const [scheme, variant] of Object.entries(resolved.dynamic)) {
|
|
254
|
+
if (typeof variant !== "string") {
|
|
255
|
+
throw new Error(`swift color ${name} has a non-string ${scheme} variant`);
|
|
256
|
+
}
|
|
257
|
+
variants[scheme] = withAlpha(variant, alpha);
|
|
258
|
+
}
|
|
259
|
+
return { dynamic: variants };
|
|
260
|
+
}
|
|
261
|
+
throw new Error(`swift color ${name} cannot take opacity ${alpha}`);
|
|
262
|
+
}
|
|
263
|
+
function resolveModifier(modifier) {
|
|
264
|
+
const color = modifier.color;
|
|
265
|
+
if (typeof color !== "string") {
|
|
266
|
+
const glass = modifier.glass;
|
|
267
|
+
if (modifier.$type === "glassEffect" && isRecord(glass) && typeof glass.tint === "string") {
|
|
268
|
+
return { ...modifier, glass: { ...glass, tint: resolveColor(glass.tint) } };
|
|
269
|
+
}
|
|
270
|
+
return modifier;
|
|
271
|
+
}
|
|
272
|
+
const { name, alpha } = splitColor(color);
|
|
273
|
+
const level = modifier.$type === "foregroundStyle" ? HIERARCHICAL.get(name) : void 0;
|
|
274
|
+
if (level !== void 0 && alpha === 1) {
|
|
275
|
+
return {
|
|
276
|
+
$type: "foregroundStyle",
|
|
277
|
+
styleType: "hierarchical",
|
|
278
|
+
hierarchicalStyle: level
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return { ...modifier, color: resolveColor(color) };
|
|
282
|
+
}
|
|
283
|
+
var NODE_COMPONENTS = {
|
|
284
|
+
Button: import_swift_ui.Button,
|
|
285
|
+
Capsule: import_swift_ui.Capsule,
|
|
286
|
+
Circle: import_swift_ui.Circle,
|
|
287
|
+
Divider: import_swift_ui.Divider,
|
|
288
|
+
Form: import_swift_ui.Form,
|
|
289
|
+
Group: import_swift_ui.Group,
|
|
290
|
+
HStack: import_swift_ui.HStack,
|
|
291
|
+
Image: import_swift_ui.Image,
|
|
292
|
+
List: import_swift_ui.List,
|
|
293
|
+
Rectangle: import_swift_ui.Rectangle,
|
|
294
|
+
RoundedRectangle: import_swift_ui.RoundedRectangle,
|
|
295
|
+
ScrollView: import_swift_ui.ScrollView,
|
|
296
|
+
Section: import_swift_ui.Section,
|
|
297
|
+
Slider: import_swift_ui.Slider,
|
|
298
|
+
Spacer: import_swift_ui.Spacer,
|
|
299
|
+
Text: import_swift_ui.Text,
|
|
300
|
+
TextField: import_swift_ui.TextField,
|
|
301
|
+
Toggle: import_swift_ui.Toggle,
|
|
302
|
+
VStack: import_swift_ui.VStack,
|
|
303
|
+
ZStack: import_swift_ui.ZStack
|
|
304
|
+
};
|
|
305
|
+
var TEXT_STYLE_SIZES = /* @__PURE__ */ new Map([
|
|
306
|
+
["largeTitle", 34],
|
|
307
|
+
["title", 28],
|
|
308
|
+
["title2", 22],
|
|
309
|
+
["title3", 20],
|
|
310
|
+
["headline", 17],
|
|
311
|
+
["subheadline", 15],
|
|
312
|
+
["body", 17],
|
|
313
|
+
["callout", 16],
|
|
314
|
+
["footnote", 13],
|
|
315
|
+
["caption", 12],
|
|
316
|
+
["caption2", 11]
|
|
317
|
+
]);
|
|
318
|
+
var FONT_WEIGHTS = /* @__PURE__ */ new Map([
|
|
319
|
+
["ultraLight", "100"],
|
|
320
|
+
["thin", "200"],
|
|
321
|
+
["light", "300"],
|
|
322
|
+
["regular", "400"],
|
|
323
|
+
["medium", "500"],
|
|
324
|
+
["semibold", "600"],
|
|
325
|
+
["bold", "700"],
|
|
326
|
+
["heavy", "800"],
|
|
327
|
+
["black", "900"]
|
|
328
|
+
]);
|
|
329
|
+
function fontModifier(modifiers) {
|
|
330
|
+
return modifiers?.find((modifier) => modifier.$type === "font");
|
|
331
|
+
}
|
|
332
|
+
function fontStyle(font) {
|
|
333
|
+
if (!font) return void 0;
|
|
334
|
+
const style = {};
|
|
335
|
+
if (typeof font.size === "number") style.fontSize = font.size;
|
|
336
|
+
else if (typeof font.style === "string") {
|
|
337
|
+
const size = TEXT_STYLE_SIZES.get(font.style);
|
|
338
|
+
if (size === void 0) throw new Error(`swift font style ${font.style} has no size`);
|
|
339
|
+
style.fontSize = size;
|
|
340
|
+
}
|
|
341
|
+
if (typeof font.weight === "string") {
|
|
342
|
+
const weight = FONT_WEIGHTS.get(font.weight);
|
|
343
|
+
if (weight === void 0)
|
|
344
|
+
throw new Error(`swift font weight ${font.weight} has no value`);
|
|
345
|
+
style.fontWeight = weight;
|
|
346
|
+
}
|
|
347
|
+
return style;
|
|
348
|
+
}
|
|
349
|
+
function handlerId(node, name) {
|
|
350
|
+
return node.h?.[name];
|
|
351
|
+
}
|
|
352
|
+
function nodeProps(node, deliver) {
|
|
353
|
+
const props = node.p ?? {};
|
|
354
|
+
switch (node.t) {
|
|
355
|
+
case "Text": {
|
|
356
|
+
const style = fontStyle(fontModifier(node.m));
|
|
357
|
+
return {
|
|
358
|
+
children: typeof props.children === "string" ? props.children : "",
|
|
359
|
+
...style ? { style } : {}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
case "Image": {
|
|
363
|
+
const font = fontModifier(node.m);
|
|
364
|
+
const size = typeof font?.size === "number" ? font.size : void 0;
|
|
365
|
+
return {
|
|
366
|
+
...typeof props.systemName === "string" ? { systemName: props.systemName } : {},
|
|
367
|
+
...size === void 0 ? {} : { size }
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
case "Toggle": {
|
|
371
|
+
const onValueChange = handlerId(node, "onValueChange");
|
|
372
|
+
return {
|
|
373
|
+
isOn: props.value === true,
|
|
374
|
+
...onValueChange === void 0 ? {} : { onIsOnChange: (value) => deliver(onValueChange, value) }
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
case "TextField": {
|
|
378
|
+
const onChangeText = handlerId(node, "onChangeText");
|
|
379
|
+
return {
|
|
380
|
+
...typeof props.placeholder === "string" ? { placeholder: props.placeholder } : {},
|
|
381
|
+
...typeof props.defaultValue === "string" ? { defaultValue: props.defaultValue } : {},
|
|
382
|
+
...onChangeText === void 0 ? {} : { onChangeText: (value) => deliver(onChangeText, value) }
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
case "Slider": {
|
|
386
|
+
const onValueChange = handlerId(node, "onValueChange");
|
|
387
|
+
return {
|
|
388
|
+
value: typeof props.value === "number" ? props.value : 0,
|
|
389
|
+
min: typeof props.min === "number" ? props.min : 0,
|
|
390
|
+
max: typeof props.max === "number" ? props.max : 1,
|
|
391
|
+
...onValueChange === void 0 ? {} : { onValueChange: (value) => deliver(onValueChange, value) }
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
case "Button": {
|
|
395
|
+
const onPress = handlerId(node, "onPress");
|
|
396
|
+
return onPress === void 0 ? {} : { onPress: () => deliver(onPress, null) };
|
|
397
|
+
}
|
|
398
|
+
default:
|
|
399
|
+
return props;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function buttonModifier(modifier) {
|
|
403
|
+
if (modifier.$type === "glassEffect") {
|
|
404
|
+
const glass = modifier.glass;
|
|
405
|
+
const variant = isRecord(glass) && typeof glass.variant === "string" ? glass.variant : "regular";
|
|
406
|
+
return variant === "identity" ? modifier : { $type: "buttonStyle", style: "glass" };
|
|
407
|
+
}
|
|
408
|
+
if (modifier.$type === "foregroundStyle" && modifier.color !== void 0) {
|
|
409
|
+
return { $type: "tint", color: modifier.color };
|
|
410
|
+
}
|
|
411
|
+
return modifier;
|
|
412
|
+
}
|
|
413
|
+
function nodeModifiers(node) {
|
|
414
|
+
const resolved = node.m?.map(resolveModifier);
|
|
415
|
+
if (node.t !== "Button") return resolved;
|
|
416
|
+
return resolved?.map(buttonModifier);
|
|
417
|
+
}
|
|
418
|
+
function renderNode(node, deliver) {
|
|
419
|
+
const component = NODE_COMPONENTS[node.t];
|
|
420
|
+
if (!component) throw new Error(`swift view ${node.t} has no rnx kit component`);
|
|
421
|
+
const modifiers = nodeModifiers(node);
|
|
422
|
+
const children = node.c?.map((child) => renderNode(child, deliver));
|
|
423
|
+
return (0, import_react.createElement)(
|
|
424
|
+
component,
|
|
425
|
+
{
|
|
426
|
+
key: node.id,
|
|
427
|
+
...modifiers === void 0 ? {} : { modifiers },
|
|
428
|
+
...nodeProps(node, deliver)
|
|
429
|
+
},
|
|
430
|
+
...children ?? []
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
var ROOT_KEY = "__rnx_swift_roots__";
|
|
434
|
+
function rootRegistry() {
|
|
435
|
+
const existing = Reflect.get(globalThis, ROOT_KEY);
|
|
436
|
+
if (existing instanceof Map) return existing;
|
|
437
|
+
const created = /* @__PURE__ */ new Map();
|
|
438
|
+
Reflect.set(globalThis, ROOT_KEY, created);
|
|
439
|
+
return created;
|
|
440
|
+
}
|
|
441
|
+
function createRoot() {
|
|
442
|
+
let instance = null;
|
|
443
|
+
let source = null;
|
|
444
|
+
let state = { tree: null, error: null };
|
|
445
|
+
let swap = Promise.resolve();
|
|
446
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
447
|
+
const publish = (next) => {
|
|
448
|
+
state = next;
|
|
449
|
+
for (const listener of listeners) listener();
|
|
450
|
+
};
|
|
451
|
+
const apply = async (options) => {
|
|
452
|
+
const carried = instance?.exportState() ?? null;
|
|
453
|
+
const created = instantiate(await compile(options.url));
|
|
454
|
+
if (carried !== null) created.importState(carried);
|
|
455
|
+
if (source !== options) return;
|
|
456
|
+
instance = created;
|
|
457
|
+
publish({ tree: created.mount(), error: null });
|
|
458
|
+
};
|
|
459
|
+
const component = function SwiftRoot() {
|
|
460
|
+
const rendered = (0, import_react.useSyncExternalStore)(
|
|
461
|
+
(listener) => {
|
|
462
|
+
listeners.add(listener);
|
|
463
|
+
return () => listeners.delete(listener);
|
|
464
|
+
},
|
|
465
|
+
() => state
|
|
466
|
+
);
|
|
467
|
+
if (rendered.error) throw rendered.error;
|
|
468
|
+
if (!rendered.tree) return null;
|
|
469
|
+
const deliver = (handlerId2, payload) => {
|
|
470
|
+
if (!instance) throw new Error("swift app received an event before it mounted");
|
|
471
|
+
publish({ tree: instance.deliver(handlerId2, payload), error: null });
|
|
472
|
+
};
|
|
473
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_swift_ui.Host, { style: { flex: 1 }, children: rendered.tree.map((node) => renderNode(node, deliver)) });
|
|
474
|
+
};
|
|
475
|
+
return {
|
|
476
|
+
component,
|
|
477
|
+
use(options) {
|
|
478
|
+
const changed = source === null || source.hash !== options.hash || source.url !== options.url;
|
|
479
|
+
if (changed) {
|
|
480
|
+
source = options;
|
|
481
|
+
swap = swap.then(
|
|
482
|
+
() => apply(options),
|
|
483
|
+
() => apply(options)
|
|
484
|
+
);
|
|
485
|
+
swap.catch((error) => {
|
|
486
|
+
publish({
|
|
487
|
+
tree: null,
|
|
488
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
return component;
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function createSwiftModule(options) {
|
|
497
|
+
const rootId = options.rootId ?? "root";
|
|
498
|
+
const registry = rootRegistry();
|
|
499
|
+
const existing = registry.get(rootId);
|
|
500
|
+
const root = existing ?? createRoot();
|
|
501
|
+
if (!existing) registry.set(rootId, root);
|
|
502
|
+
return root.use(options);
|
|
503
|
+
}
|
|
504
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
505
|
+
0 && (module.exports = {
|
|
506
|
+
createSwiftModule
|
|
507
|
+
});
|