@qontinui/ui-bridge 0.2.0 → 0.3.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.
Files changed (108) hide show
  1. package/dist/ai/index.d.mts +4 -4
  2. package/dist/ai/index.d.ts +4 -4
  3. package/dist/babel-plugin/index.js +515 -0
  4. package/dist/babel-plugin/index.js.map +1 -0
  5. package/dist/babel-plugin/index.mjs +499 -0
  6. package/dist/babel-plugin/index.mjs.map +1 -0
  7. package/dist/control/index.d.mts +5 -5
  8. package/dist/control/index.d.ts +5 -5
  9. package/dist/core/index.d.mts +115 -44
  10. package/dist/core/index.d.ts +115 -44
  11. package/dist/core/index.js +0 -1560
  12. package/dist/core/index.js.map +1 -1
  13. package/dist/core/index.mjs +1 -1549
  14. package/dist/core/index.mjs.map +1 -1
  15. package/dist/debug/index.d.mts +3 -3
  16. package/dist/debug/index.d.ts +3 -3
  17. package/dist/index.d.mts +7 -8
  18. package/dist/index.d.ts +7 -8
  19. package/dist/index.js +859 -873
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +860 -862
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/{metrics-C9XRi_mL.d.ts → metrics-BfiT_rhZ.d.ts} +2 -2
  24. package/dist/{metrics-NC3csD0R.d.mts → metrics-DTA2bwG7.d.mts} +2 -2
  25. package/dist/native/control/index.js +453 -0
  26. package/dist/native/control/index.js.map +1 -0
  27. package/dist/native/control/index.mjs +450 -0
  28. package/dist/native/control/index.mjs.map +1 -0
  29. package/dist/native/core/index.js +486 -0
  30. package/dist/native/core/index.js.map +1 -0
  31. package/dist/native/core/index.mjs +475 -0
  32. package/dist/native/core/index.mjs.map +1 -0
  33. package/dist/native/debug/index.js +451 -0
  34. package/dist/native/debug/index.js.map +1 -0
  35. package/dist/native/debug/index.mjs +449 -0
  36. package/dist/native/debug/index.mjs.map +1 -0
  37. package/dist/native/index.js +2274 -0
  38. package/dist/native/index.js.map +1 -0
  39. package/dist/native/index.mjs +2246 -0
  40. package/dist/native/index.mjs.map +1 -0
  41. package/dist/native/react/index.js +1401 -0
  42. package/dist/native/react/index.js.map +1 -0
  43. package/dist/native/react/index.mjs +1389 -0
  44. package/dist/native/react/index.mjs.map +1 -0
  45. package/dist/native/server/index.js +415 -0
  46. package/dist/native/server/index.js.map +1 -0
  47. package/dist/native/server/index.mjs +410 -0
  48. package/dist/native/server/index.mjs.map +1 -0
  49. package/dist/react/index.d.mts +20 -7
  50. package/dist/react/index.d.ts +20 -7
  51. package/dist/react/index.js +42 -4
  52. package/dist/react/index.js.map +1 -1
  53. package/dist/react/index.mjs +42 -4
  54. package/dist/react/index.mjs.map +1 -1
  55. package/dist/{registry-CIEDjbQ9.d.ts → registry-BKLEm-yk.d.ts} +9 -15
  56. package/dist/{registry-SsSDq46X.d.mts → registry-BmZgyCz8.d.mts} +9 -15
  57. package/dist/render-log/index.d.mts +1 -1
  58. package/dist/render-log/index.d.ts +1 -1
  59. package/dist/server/express.d.mts +36 -0
  60. package/dist/server/express.d.ts +36 -0
  61. package/dist/server/express.js +196 -0
  62. package/dist/server/express.js.map +1 -0
  63. package/dist/server/express.mjs +192 -0
  64. package/dist/server/express.mjs.map +1 -0
  65. package/dist/server/handlers.d.mts +93 -0
  66. package/dist/server/handlers.d.ts +93 -0
  67. package/dist/server/handlers.js +4278 -0
  68. package/dist/server/handlers.js.map +1 -0
  69. package/dist/server/handlers.mjs +4275 -0
  70. package/dist/server/handlers.mjs.map +1 -0
  71. package/dist/server/index.d.mts +10 -0
  72. package/dist/server/index.d.ts +10 -0
  73. package/dist/server/index.js +5352 -0
  74. package/dist/server/index.js.map +1 -0
  75. package/dist/server/index.mjs +5337 -0
  76. package/dist/server/index.mjs.map +1 -0
  77. package/dist/server/nextjs.d.mts +126 -0
  78. package/dist/server/nextjs.d.ts +126 -0
  79. package/dist/server/nextjs.js +287 -0
  80. package/dist/server/nextjs.js.map +1 -0
  81. package/dist/server/nextjs.mjs +282 -0
  82. package/dist/server/nextjs.mjs.map +1 -0
  83. package/dist/server/standalone.d.mts +6 -0
  84. package/dist/server/standalone.d.ts +6 -0
  85. package/dist/server/standalone.js +719 -0
  86. package/dist/server/standalone.js.map +1 -0
  87. package/dist/server/standalone.mjs +715 -0
  88. package/dist/server/standalone.mjs.map +1 -0
  89. package/dist/standalone-BURj8J3G.d.ts +212 -0
  90. package/dist/standalone-Dwmel29d.d.mts +212 -0
  91. package/dist/swc-plugin/index.d.mts +79 -0
  92. package/dist/swc-plugin/index.d.ts +79 -0
  93. package/dist/swc-plugin/index.js +15 -0
  94. package/dist/swc-plugin/index.js.map +1 -0
  95. package/dist/swc-plugin/index.mjs +9 -0
  96. package/dist/swc-plugin/index.mjs.map +1 -0
  97. package/dist/{types-CFT3Dnx4.d.mts → types-B5Q0GVo0.d.mts} +115 -3
  98. package/dist/{types-Dr6tH-bm.d.mts → types-B7J7noLK.d.mts} +1 -1
  99. package/dist/{types-oCTrRxSw.d.ts → types-BkNRILUa.d.ts} +1 -1
  100. package/dist/types-CEQLnFMv.d.mts +156 -0
  101. package/dist/types-CHnlwiTK.d.ts +156 -0
  102. package/dist/{types-BvCfFuEV.d.ts → types-DfPqwU-i.d.ts} +115 -3
  103. package/dist/{types-CPMbN_Iw.d.mts → types-jKVgTI6_.d.mts} +356 -160
  104. package/dist/{types-CPMbN_Iw.d.ts → types-jKVgTI6_.d.ts} +356 -160
  105. package/package.json +106 -3
  106. package/swc-plugin-wasm/ui_bridge_swc_plugin.wasm +0 -0
  107. package/dist/websocket-client-CX4QJesI.d.ts +0 -124
  108. package/dist/websocket-client-C_Na0OSp.d.mts +0 -124
@@ -0,0 +1,2246 @@
1
+ import { createContext, useRef, useState, useCallback, useEffect, useMemo, useContext } from 'react';
2
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
+ import { Dimensions, StyleSheet, TouchableOpacity, Text, Modal, View, ScrollView } from 'react-native';
4
+
5
+ // src/native/core/registry.ts
6
+ function inferActions(type) {
7
+ const baseActions = ["focus", "blur"];
8
+ switch (type) {
9
+ case "button":
10
+ case "touchable":
11
+ case "pressable":
12
+ return [...baseActions, "press", "longPress", "doubleTap"];
13
+ case "input":
14
+ return [...baseActions, "press", "type", "clear"];
15
+ case "text":
16
+ return [...baseActions, "press", "longPress"];
17
+ case "view":
18
+ return [...baseActions, "press"];
19
+ case "scroll":
20
+ return [...baseActions, "scroll", "swipe"];
21
+ case "list":
22
+ return [...baseActions, "scroll", "swipe"];
23
+ case "listItem":
24
+ return [...baseActions, "press", "longPress", "swipe"];
25
+ case "switch":
26
+ case "checkbox":
27
+ return [...baseActions, "press", "toggle"];
28
+ case "radio":
29
+ return [...baseActions, "press"];
30
+ case "image":
31
+ return [...baseActions, "press", "longPress"];
32
+ case "modal":
33
+ return ["focus", "blur"];
34
+ case "custom":
35
+ default:
36
+ return [...baseActions, "press"];
37
+ }
38
+ }
39
+ var NativeUIBridgeRegistry = class {
40
+ constructor(config = {}) {
41
+ this.elements = /* @__PURE__ */ new Map();
42
+ this.components = /* @__PURE__ */ new Map();
43
+ this.workflows = /* @__PURE__ */ new Map();
44
+ this.eventListeners = /* @__PURE__ */ new Map();
45
+ this.config = config;
46
+ }
47
+ // ============================================================================
48
+ // Element Management
49
+ // ============================================================================
50
+ /**
51
+ * Register a native element
52
+ */
53
+ registerElement(id, ref, options = {}) {
54
+ const {
55
+ type = "custom",
56
+ label,
57
+ actions = inferActions(type),
58
+ customActions,
59
+ props,
60
+ treePath = id,
61
+ testId,
62
+ accessibilityLabel
63
+ } = options;
64
+ const getState = () => {
65
+ const element = ref.current;
66
+ if (!element) {
67
+ return {
68
+ mounted: false,
69
+ visible: false,
70
+ enabled: false,
71
+ focused: false,
72
+ layout: null
73
+ };
74
+ }
75
+ const stored = this.elements.get(id);
76
+ if (stored && stored.getState !== getState) {
77
+ return stored.getState();
78
+ }
79
+ return {
80
+ mounted: true,
81
+ visible: true,
82
+ enabled: true,
83
+ focused: false,
84
+ layout: null
85
+ };
86
+ };
87
+ const getIdentifier = () => ({
88
+ uiId: id,
89
+ testId: testId || id,
90
+ accessibilityLabel,
91
+ treePath
92
+ });
93
+ const registered = {
94
+ id,
95
+ ref,
96
+ type,
97
+ label,
98
+ actions,
99
+ customActions,
100
+ props,
101
+ getState,
102
+ getIdentifier,
103
+ registeredAt: Date.now(),
104
+ mounted: true
105
+ };
106
+ this.elements.set(id, registered);
107
+ this.emit("element:registered", { id, type, label });
108
+ if (this.config.verbose) {
109
+ console.log(`[ui-bridge-native] Registered element: ${id} (${type})`);
110
+ }
111
+ return registered;
112
+ }
113
+ /**
114
+ * Unregister an element
115
+ */
116
+ unregisterElement(id) {
117
+ const element = this.elements.get(id);
118
+ if (element) {
119
+ this.elements.delete(id);
120
+ this.emit("element:unregistered", { id });
121
+ if (this.config.verbose) {
122
+ console.log(`[ui-bridge-native] Unregistered element: ${id}`);
123
+ }
124
+ }
125
+ }
126
+ /**
127
+ * Get a registered element
128
+ */
129
+ getElement(id) {
130
+ return this.elements.get(id);
131
+ }
132
+ /**
133
+ * Get all registered elements
134
+ */
135
+ getAllElements() {
136
+ return Array.from(this.elements.values());
137
+ }
138
+ /**
139
+ * Update element state
140
+ */
141
+ updateElementState(id, state) {
142
+ const element = this.elements.get(id);
143
+ if (element) {
144
+ const currentState = element.getState();
145
+ const newState = { ...currentState, ...state };
146
+ const updated = {
147
+ ...element,
148
+ getState: () => newState
149
+ };
150
+ this.elements.set(id, updated);
151
+ this.emit("element:stateChanged", { id, state: newState });
152
+ }
153
+ }
154
+ /**
155
+ * Update element props (for action execution)
156
+ */
157
+ updateElementProps(id, props) {
158
+ const element = this.elements.get(id);
159
+ if (element) {
160
+ const updated = {
161
+ ...element,
162
+ props: { ...element.props, ...props }
163
+ };
164
+ this.elements.set(id, updated);
165
+ }
166
+ }
167
+ /**
168
+ * Find element by testID
169
+ */
170
+ findByTestId(testId) {
171
+ for (const element of this.elements.values()) {
172
+ const identifier = element.getIdentifier();
173
+ if (identifier.testId === testId) {
174
+ return element;
175
+ }
176
+ }
177
+ return void 0;
178
+ }
179
+ /**
180
+ * Find elements by type
181
+ */
182
+ findByType(type) {
183
+ return Array.from(this.elements.values()).filter((e) => e.type === type);
184
+ }
185
+ // ============================================================================
186
+ // Component Management
187
+ // ============================================================================
188
+ /**
189
+ * Register a component
190
+ */
191
+ registerComponent(id, options) {
192
+ const { name, description, actions = [], elementIds } = options;
193
+ const registered = {
194
+ id,
195
+ name,
196
+ description,
197
+ actions: actions.map((a) => ({
198
+ id: a.id,
199
+ label: a.label,
200
+ description: a.description,
201
+ handler: a.handler
202
+ })),
203
+ elementIds,
204
+ registeredAt: Date.now(),
205
+ mounted: true
206
+ };
207
+ this.components.set(id, registered);
208
+ this.emit("component:registered", { id, name });
209
+ if (this.config.verbose) {
210
+ console.log(`[ui-bridge-native] Registered component: ${id} (${name})`);
211
+ }
212
+ return registered;
213
+ }
214
+ /**
215
+ * Unregister a component
216
+ */
217
+ unregisterComponent(id) {
218
+ const component = this.components.get(id);
219
+ if (component) {
220
+ this.components.delete(id);
221
+ this.emit("component:unregistered", { id });
222
+ if (this.config.verbose) {
223
+ console.log(`[ui-bridge-native] Unregistered component: ${id}`);
224
+ }
225
+ }
226
+ }
227
+ /**
228
+ * Get a registered component
229
+ */
230
+ getComponent(id) {
231
+ return this.components.get(id);
232
+ }
233
+ /**
234
+ * Get all registered components
235
+ */
236
+ getAllComponents() {
237
+ return Array.from(this.components.values());
238
+ }
239
+ // ============================================================================
240
+ // Workflow Management
241
+ // ============================================================================
242
+ /**
243
+ * Register a workflow
244
+ */
245
+ registerWorkflow(workflow) {
246
+ this.workflows.set(workflow.id, workflow);
247
+ if (this.config.verbose) {
248
+ console.log(`[ui-bridge-native] Registered workflow: ${workflow.id}`);
249
+ }
250
+ }
251
+ /**
252
+ * Unregister a workflow
253
+ */
254
+ unregisterWorkflow(id) {
255
+ this.workflows.delete(id);
256
+ }
257
+ /**
258
+ * Get a workflow
259
+ */
260
+ getWorkflow(id) {
261
+ return this.workflows.get(id);
262
+ }
263
+ /**
264
+ * Get all workflows
265
+ */
266
+ getAllWorkflows() {
267
+ return Array.from(this.workflows.values());
268
+ }
269
+ // ============================================================================
270
+ // Event System
271
+ // ============================================================================
272
+ /**
273
+ * Subscribe to events
274
+ */
275
+ on(type, listener) {
276
+ if (!this.eventListeners.has(type)) {
277
+ this.eventListeners.set(type, /* @__PURE__ */ new Set());
278
+ }
279
+ this.eventListeners.get(type).add(listener);
280
+ return () => this.off(type, listener);
281
+ }
282
+ /**
283
+ * Unsubscribe from events
284
+ */
285
+ off(type, listener) {
286
+ this.eventListeners.get(type)?.delete(listener);
287
+ }
288
+ /**
289
+ * Emit an event
290
+ */
291
+ emit(type, data) {
292
+ const event = {
293
+ type,
294
+ timestamp: Date.now(),
295
+ data
296
+ };
297
+ const listeners = this.eventListeners.get(type);
298
+ if (listeners) {
299
+ for (const listener of listeners) {
300
+ try {
301
+ listener(event);
302
+ } catch (error2) {
303
+ console.error(`[ui-bridge-native] Event listener error:`, error2);
304
+ }
305
+ }
306
+ }
307
+ if (this.config.onEvent) {
308
+ try {
309
+ this.config.onEvent(event);
310
+ } catch (error2) {
311
+ console.error(`[ui-bridge-native] Global event handler error:`, error2);
312
+ }
313
+ }
314
+ }
315
+ // ============================================================================
316
+ // Snapshots
317
+ // ============================================================================
318
+ /**
319
+ * Create a snapshot of the current state
320
+ */
321
+ createSnapshot() {
322
+ return {
323
+ timestamp: Date.now(),
324
+ elements: this.getAllElements().map((e) => ({
325
+ id: e.id,
326
+ type: e.type,
327
+ label: e.label,
328
+ identifier: e.getIdentifier(),
329
+ state: e.getState(),
330
+ actions: e.actions,
331
+ customActions: e.customActions ? Object.keys(e.customActions) : void 0
332
+ })),
333
+ components: this.getAllComponents().map((c) => ({
334
+ id: c.id,
335
+ name: c.name,
336
+ description: c.description,
337
+ actions: c.actions.map((a) => a.id),
338
+ elementIds: c.elementIds
339
+ })),
340
+ workflows: this.getAllWorkflows().map((w) => ({
341
+ id: w.id,
342
+ name: w.name,
343
+ description: w.description,
344
+ stepCount: w.steps.length
345
+ }))
346
+ };
347
+ }
348
+ /**
349
+ * Get registry statistics
350
+ */
351
+ getStats() {
352
+ return {
353
+ elements: this.elements.size,
354
+ components: this.components.size,
355
+ workflows: this.workflows.size
356
+ };
357
+ }
358
+ /**
359
+ * Clear all registrations
360
+ */
361
+ clear() {
362
+ this.elements.clear();
363
+ this.components.clear();
364
+ this.workflows.clear();
365
+ if (this.config.verbose) {
366
+ console.log(`[ui-bridge-native] Registry cleared`);
367
+ }
368
+ }
369
+ };
370
+ var globalRegistry = null;
371
+ function setGlobalRegistry(registry) {
372
+ globalRegistry = registry;
373
+ }
374
+ function getGlobalRegistry() {
375
+ return globalRegistry;
376
+ }
377
+ function resetGlobalRegistry() {
378
+ globalRegistry?.clear();
379
+ globalRegistry = null;
380
+ }
381
+
382
+ // src/native/core/element-identifier.ts
383
+ function createNativeElementIdentifier(id, options = {}) {
384
+ return {
385
+ uiId: id,
386
+ testId: options.testId || id,
387
+ accessibilityLabel: options.accessibilityLabel,
388
+ accessibilityHint: options.accessibilityHint,
389
+ treePath: options.treePath || id
390
+ };
391
+ }
392
+ function findElementByIdentifier(identifier) {
393
+ const registry = getGlobalRegistry();
394
+ if (!registry) return null;
395
+ if (typeof identifier === "string") {
396
+ const byId = registry.getElement(identifier);
397
+ if (byId) return byId;
398
+ const byTestId = registry.findByTestId(identifier);
399
+ if (byTestId) return byTestId;
400
+ return findByPattern(registry, identifier);
401
+ }
402
+ if (identifier.uiId) {
403
+ const byId = registry.getElement(identifier.uiId);
404
+ if (byId) return byId;
405
+ }
406
+ if (identifier.testId) {
407
+ const byTestId = registry.findByTestId(identifier.testId);
408
+ if (byTestId) return byTestId;
409
+ }
410
+ return null;
411
+ }
412
+ function findByPattern(registry, pattern) {
413
+ if (!registry) return null;
414
+ const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
415
+ const regex = new RegExp(`^${regexPattern}$`, "i");
416
+ for (const element of registry.getAllElements()) {
417
+ const identifier = element.getIdentifier();
418
+ if (identifier.testId && regex.test(identifier.testId)) {
419
+ return element;
420
+ }
421
+ if (identifier.uiId && regex.test(identifier.uiId)) {
422
+ return element;
423
+ }
424
+ if (identifier.treePath && regex.test(identifier.treePath)) {
425
+ return element;
426
+ }
427
+ if (identifier.accessibilityLabel && regex.test(identifier.accessibilityLabel)) {
428
+ return element;
429
+ }
430
+ }
431
+ return null;
432
+ }
433
+ function findAllByPattern(pattern) {
434
+ const registry = getGlobalRegistry();
435
+ if (!registry) return [];
436
+ const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
437
+ const regex = new RegExp(`^${regexPattern}$`, "i");
438
+ const results = [];
439
+ for (const element of registry.getAllElements()) {
440
+ const identifier = element.getIdentifier();
441
+ if (identifier.testId && regex.test(identifier.testId) || identifier.uiId && regex.test(identifier.uiId) || identifier.treePath && regex.test(identifier.treePath) || identifier.accessibilityLabel && regex.test(identifier.accessibilityLabel)) {
442
+ results.push(element);
443
+ }
444
+ }
445
+ return results;
446
+ }
447
+ function buildTreePath(componentPath, elementIndex) {
448
+ let path = componentPath.join("/");
449
+ if (elementIndex !== void 0) {
450
+ path += `[${elementIndex}]`;
451
+ }
452
+ return path;
453
+ }
454
+ function parseTreePath(treePath) {
455
+ const indexMatch = treePath.match(/\[(\d+)\]$/);
456
+ const index = indexMatch ? parseInt(indexMatch[1], 10) : void 0;
457
+ const pathWithoutIndex = treePath.replace(/\[\d+\]$/, "");
458
+ const components = pathWithoutIndex.split("/").filter(Boolean);
459
+ return { components, index };
460
+ }
461
+ function matchesIdentifier(identifier, criteria) {
462
+ if (criteria.uiId && identifier.uiId !== criteria.uiId) {
463
+ return false;
464
+ }
465
+ if (criteria.testId && identifier.testId !== criteria.testId) {
466
+ return false;
467
+ }
468
+ if (criteria.accessibilityLabel && identifier.accessibilityLabel !== criteria.accessibilityLabel) {
469
+ return false;
470
+ }
471
+ if (criteria.treePath && identifier.treePath !== criteria.treePath) {
472
+ return false;
473
+ }
474
+ return true;
475
+ }
476
+
477
+ // src/native/control/action-executor.ts
478
+ var DEFAULT_WAIT_OPTIONS = {
479
+ visible: true,
480
+ enabled: true,
481
+ focused: false,
482
+ state: {},
483
+ timeout: 1e4,
484
+ interval: 100
485
+ };
486
+ function sleep(ms) {
487
+ return new Promise((resolve) => setTimeout(resolve, ms));
488
+ }
489
+ var DefaultNativeActionExecutor = class {
490
+ constructor(registry) {
491
+ this.registry = registry;
492
+ }
493
+ /**
494
+ * Execute an action on an element
495
+ */
496
+ async executeAction(elementId, request) {
497
+ const startTime = Date.now();
498
+ let waitDurationMs = 0;
499
+ try {
500
+ let registered = this.registry.getElement(elementId);
501
+ if (!registered) {
502
+ registered = findElementByIdentifier(elementId) ?? void 0;
503
+ }
504
+ if (!registered) {
505
+ return {
506
+ success: false,
507
+ error: `Element not found: ${elementId}`,
508
+ durationMs: Date.now() - startTime,
509
+ timestamp: Date.now(),
510
+ requestId: request.requestId
511
+ };
512
+ }
513
+ if (request.waitOptions) {
514
+ const waitResult = await this.waitForElementInternal(
515
+ registered.id,
516
+ request.waitOptions
517
+ );
518
+ waitDurationMs = waitResult.waitedMs;
519
+ if (!waitResult.met) {
520
+ return {
521
+ success: false,
522
+ error: waitResult.error || "Wait condition not met",
523
+ durationMs: Date.now() - startTime,
524
+ timestamp: Date.now(),
525
+ requestId: request.requestId,
526
+ waitDurationMs
527
+ };
528
+ }
529
+ }
530
+ const result = await this.performAction(registered, request.action, request.params);
531
+ return {
532
+ success: true,
533
+ elementState: registered.getState(),
534
+ result,
535
+ durationMs: Date.now() - startTime,
536
+ timestamp: Date.now(),
537
+ requestId: request.requestId,
538
+ waitDurationMs
539
+ };
540
+ } catch (error2) {
541
+ return {
542
+ success: false,
543
+ error: error2 instanceof Error ? error2.message : String(error2),
544
+ stack: error2 instanceof Error ? error2.stack : void 0,
545
+ durationMs: Date.now() - startTime,
546
+ timestamp: Date.now(),
547
+ requestId: request.requestId,
548
+ waitDurationMs
549
+ };
550
+ }
551
+ }
552
+ /**
553
+ * Perform an action on an element
554
+ */
555
+ async performAction(element, action, params) {
556
+ if (!element) {
557
+ throw new Error("Element not found");
558
+ }
559
+ const props = element.props || {};
560
+ if (element.customActions && action in element.customActions) {
561
+ return element.customActions[action].handler(params);
562
+ }
563
+ switch (action) {
564
+ case "press":
565
+ return this.performPress(props, params);
566
+ case "longPress":
567
+ return this.performLongPress(props, params);
568
+ case "doubleTap":
569
+ return this.performDoubleTap(props);
570
+ case "type":
571
+ return this.performType(element, props, params);
572
+ case "clear":
573
+ return this.performClear(element, props);
574
+ case "focus":
575
+ return this.performFocus(element);
576
+ case "blur":
577
+ return this.performBlur(element);
578
+ case "scroll":
579
+ return this.performScroll(props, params);
580
+ case "swipe":
581
+ return this.performSwipe(props, params);
582
+ case "toggle":
583
+ return this.performToggle(props);
584
+ default:
585
+ throw new Error(`Unknown action: ${action}`);
586
+ }
587
+ }
588
+ /**
589
+ * Perform press action
590
+ */
591
+ async performPress(props, params) {
592
+ const handlers = ["onPress", "onPressIn", "onResponderRelease"];
593
+ for (const handler of handlers) {
594
+ if (typeof props[handler] === "function") {
595
+ const event = this.createPressEvent(params);
596
+ props[handler](event);
597
+ return;
598
+ }
599
+ }
600
+ throw new Error("No press handler found on element");
601
+ }
602
+ /**
603
+ * Perform long press action
604
+ */
605
+ async performLongPress(props, params) {
606
+ if (typeof props.onLongPress === "function") {
607
+ const event = this.createPressEvent(params);
608
+ props.onLongPress(event);
609
+ return;
610
+ }
611
+ throw new Error("No long press handler found on element");
612
+ }
613
+ /**
614
+ * Perform double tap action
615
+ */
616
+ async performDoubleTap(props) {
617
+ if (typeof props.onDoubleTap === "function") {
618
+ props.onDoubleTap();
619
+ return;
620
+ }
621
+ if (typeof props.onPress === "function") {
622
+ const event = this.createPressEvent();
623
+ props.onPress(event);
624
+ await sleep(50);
625
+ props.onPress(event);
626
+ return;
627
+ }
628
+ throw new Error("No press handler found for double tap");
629
+ }
630
+ /**
631
+ * Perform type action
632
+ */
633
+ async performType(element, props, params) {
634
+ if (!params?.text) {
635
+ throw new Error("Type action requires text parameter");
636
+ }
637
+ if (params.clearFirst) {
638
+ await this.performClear(element, props);
639
+ }
640
+ if (params.delay && params.delay > 0) {
641
+ const currentValue = element?.getState().value || "";
642
+ for (const char of params.text) {
643
+ const newValue = currentValue + char;
644
+ if (typeof props.onChangeText === "function") {
645
+ props.onChangeText(newValue);
646
+ }
647
+ await sleep(params.delay);
648
+ }
649
+ } else {
650
+ if (typeof props.onChangeText === "function") {
651
+ props.onChangeText(params.text);
652
+ } else if (typeof props.onChange === "function") {
653
+ props.onChange({
654
+ nativeEvent: { text: params.text }
655
+ });
656
+ } else {
657
+ throw new Error("No text change handler found on element");
658
+ }
659
+ }
660
+ if (element) {
661
+ this.registry.updateElementState(element.id, { value: params.text });
662
+ }
663
+ }
664
+ /**
665
+ * Perform clear action
666
+ */
667
+ async performClear(element, props) {
668
+ if (typeof props.onChangeText === "function") {
669
+ props.onChangeText("");
670
+ } else if (typeof props.onChange === "function") {
671
+ props.onChange({
672
+ nativeEvent: { text: "" }
673
+ });
674
+ }
675
+ if (element) {
676
+ this.registry.updateElementState(element.id, { value: "" });
677
+ }
678
+ }
679
+ /**
680
+ * Perform focus action
681
+ */
682
+ async performFocus(element) {
683
+ if (element?.ref.current && "focus" in element.ref.current) {
684
+ element.ref.current.focus();
685
+ }
686
+ if (element) {
687
+ this.registry.updateElementState(element.id, { focused: true });
688
+ }
689
+ }
690
+ /**
691
+ * Perform blur action
692
+ */
693
+ async performBlur(element) {
694
+ if (element?.ref.current && "blur" in element.ref.current) {
695
+ element.ref.current.blur();
696
+ }
697
+ if (element) {
698
+ this.registry.updateElementState(element.id, { focused: false });
699
+ }
700
+ }
701
+ /**
702
+ * Perform scroll action
703
+ */
704
+ async performScroll(props, params) {
705
+ if (typeof props.onScroll === "function") {
706
+ const event = {
707
+ nativeEvent: {
708
+ contentOffset: params?.offset || { x: 0, y: 0 }
709
+ }
710
+ };
711
+ props.onScroll(event);
712
+ }
713
+ }
714
+ /**
715
+ * Perform swipe action
716
+ */
717
+ async performSwipe(props, params) {
718
+ if (!params?.direction) {
719
+ throw new Error("Swipe action requires direction parameter");
720
+ }
721
+ const handlerMap = {
722
+ left: "onSwipeLeft",
723
+ right: "onSwipeRight",
724
+ up: "onSwipeUp",
725
+ down: "onSwipeDown"
726
+ };
727
+ const handler = handlerMap[params.direction];
728
+ if (handler && typeof props[handler] === "function") {
729
+ props[handler]();
730
+ return;
731
+ }
732
+ if (typeof props.onSwipe === "function") {
733
+ props.onSwipe(params.direction);
734
+ }
735
+ }
736
+ /**
737
+ * Perform toggle action
738
+ */
739
+ async performToggle(props) {
740
+ if (typeof props.onValueChange === "function") {
741
+ const currentValue = props.value;
742
+ props.onValueChange(!currentValue);
743
+ return;
744
+ }
745
+ if (typeof props.onPress === "function") {
746
+ props.onPress();
747
+ return;
748
+ }
749
+ throw new Error("No toggle handler found on element");
750
+ }
751
+ /**
752
+ * Create a synthetic press event
753
+ */
754
+ createPressEvent(params) {
755
+ return {
756
+ nativeEvent: {
757
+ locationX: params?.position?.x ?? 0,
758
+ locationY: params?.position?.y ?? 0,
759
+ timestamp: Date.now()
760
+ },
761
+ persist: () => {
762
+ }
763
+ };
764
+ }
765
+ /**
766
+ * Execute a component action
767
+ */
768
+ async executeComponentAction(componentId, request) {
769
+ const startTime = Date.now();
770
+ try {
771
+ const component = this.registry.getComponent(componentId);
772
+ if (!component) {
773
+ return {
774
+ success: false,
775
+ error: `Component not found: ${componentId}`,
776
+ durationMs: Date.now() - startTime,
777
+ timestamp: Date.now(),
778
+ requestId: request.requestId
779
+ };
780
+ }
781
+ const action = component.actions.find((a) => a.id === request.action);
782
+ if (!action) {
783
+ return {
784
+ success: false,
785
+ error: `Action not found: ${request.action}`,
786
+ durationMs: Date.now() - startTime,
787
+ timestamp: Date.now(),
788
+ requestId: request.requestId
789
+ };
790
+ }
791
+ const result = await action.handler(request.params);
792
+ return {
793
+ success: true,
794
+ result,
795
+ durationMs: Date.now() - startTime,
796
+ timestamp: Date.now(),
797
+ requestId: request.requestId
798
+ };
799
+ } catch (error2) {
800
+ return {
801
+ success: false,
802
+ error: error2 instanceof Error ? error2.message : String(error2),
803
+ stack: error2 instanceof Error ? error2.stack : void 0,
804
+ durationMs: Date.now() - startTime,
805
+ timestamp: Date.now(),
806
+ requestId: request.requestId
807
+ };
808
+ }
809
+ }
810
+ /**
811
+ * Find elements
812
+ */
813
+ async find(request) {
814
+ const startTime = Date.now();
815
+ const allElements = this.registry.getAllElements();
816
+ let filtered = allElements;
817
+ if (request.types && request.types.length > 0) {
818
+ filtered = filtered.filter((e) => request.types.includes(e.type));
819
+ }
820
+ if (request.testIdPattern) {
821
+ const regex = new RegExp(
822
+ request.testIdPattern.replace(/\*/g, ".*").replace(/\?/g, ".")
823
+ );
824
+ filtered = filtered.filter((e) => {
825
+ const identifier = e.getIdentifier();
826
+ return identifier.testId && regex.test(identifier.testId);
827
+ });
828
+ }
829
+ if (request.accessibilityLabelPattern) {
830
+ const regex = new RegExp(
831
+ request.accessibilityLabelPattern.replace(/\*/g, ".*").replace(/\?/g, ".")
832
+ );
833
+ filtered = filtered.filter((e) => {
834
+ const identifier = e.getIdentifier();
835
+ return identifier.accessibilityLabel && regex.test(identifier.accessibilityLabel);
836
+ });
837
+ }
838
+ if (request.visibleOnly) {
839
+ filtered = filtered.filter((e) => e.getState().visible);
840
+ }
841
+ if (request.limit && request.limit > 0) {
842
+ filtered = filtered.slice(0, request.limit);
843
+ }
844
+ const elements = filtered.map((e) => ({
845
+ id: e.id,
846
+ type: e.type,
847
+ identifier: e.getIdentifier(),
848
+ state: e.getState(),
849
+ actions: e.actions,
850
+ label: e.label
851
+ }));
852
+ return {
853
+ elements,
854
+ total: elements.length,
855
+ durationMs: Date.now() - startTime,
856
+ timestamp: Date.now()
857
+ };
858
+ }
859
+ /**
860
+ * Wait for element conditions
861
+ */
862
+ async waitForElement(elementId, options) {
863
+ return this.waitForElementInternal(elementId, options);
864
+ }
865
+ /**
866
+ * Internal wait implementation
867
+ */
868
+ async waitForElementInternal(elementId, options) {
869
+ const opts = { ...DEFAULT_WAIT_OPTIONS, ...options };
870
+ const startTime = Date.now();
871
+ while (Date.now() - startTime < opts.timeout) {
872
+ const element = this.registry.getElement(elementId);
873
+ if (!element) {
874
+ await sleep(opts.interval);
875
+ continue;
876
+ }
877
+ const state = element.getState();
878
+ let conditionsMet = true;
879
+ if (opts.visible && !state.visible) {
880
+ conditionsMet = false;
881
+ }
882
+ if (opts.enabled && !state.enabled) {
883
+ conditionsMet = false;
884
+ }
885
+ if (opts.focused && !state.focused) {
886
+ conditionsMet = false;
887
+ }
888
+ if (opts.state && Object.keys(opts.state).length > 0) {
889
+ const stateRecord = state;
890
+ for (const [key, value] of Object.entries(opts.state)) {
891
+ if (stateRecord[key] !== value) {
892
+ conditionsMet = false;
893
+ break;
894
+ }
895
+ }
896
+ }
897
+ if (conditionsMet) {
898
+ return {
899
+ met: true,
900
+ waitedMs: Date.now() - startTime,
901
+ state
902
+ };
903
+ }
904
+ await sleep(opts.interval);
905
+ }
906
+ return {
907
+ met: false,
908
+ waitedMs: Date.now() - startTime,
909
+ error: `Timeout waiting for conditions on element: ${elementId}`
910
+ };
911
+ }
912
+ };
913
+ function createNativeActionExecutor(registry) {
914
+ return new DefaultNativeActionExecutor(registry);
915
+ }
916
+ var UIBridgeNativeContext = createContext(null);
917
+ function UIBridgeNativeProvider({
918
+ children,
919
+ features = {},
920
+ config = {},
921
+ onEvent
922
+ }) {
923
+ const registryRef = useRef(null);
924
+ const executorRef = useRef(null);
925
+ const [serverRunning, setServerRunning] = useState(false);
926
+ if (!registryRef.current) {
927
+ registryRef.current = new NativeUIBridgeRegistry({
928
+ verbose: config.verbose,
929
+ onEvent
930
+ });
931
+ setGlobalRegistry(registryRef.current);
932
+ }
933
+ const registry = registryRef.current;
934
+ if (!executorRef.current) {
935
+ executorRef.current = createNativeActionExecutor(registry);
936
+ }
937
+ const executor = executorRef.current;
938
+ const startServer = useCallback(async () => {
939
+ if (!features.server) {
940
+ console.warn("[ui-bridge-native] Server feature not enabled");
941
+ return;
942
+ }
943
+ console.log(
944
+ `[ui-bridge-native] Would start HTTP server on port ${config.serverPort || 9876}`
945
+ );
946
+ setServerRunning(true);
947
+ }, [features.server, config.serverPort]);
948
+ const stopServer = useCallback(() => {
949
+ console.log("[ui-bridge-native] Would stop HTTP server");
950
+ setServerRunning(false);
951
+ }, []);
952
+ useEffect(() => {
953
+ if (features.server) {
954
+ startServer();
955
+ return () => stopServer();
956
+ }
957
+ }, [features.server, startServer, stopServer]);
958
+ useEffect(() => {
959
+ return () => {
960
+ stopServer();
961
+ resetGlobalRegistry();
962
+ };
963
+ }, [stopServer]);
964
+ const getElements = useCallback(() => registry.getAllElements(), [registry]);
965
+ const getComponents = useCallback(() => registry.getAllComponents(), [registry]);
966
+ const createSnapshot = useCallback(() => registry.createSnapshot(), [registry]);
967
+ const on = useCallback(
968
+ (type, listener) => registry.on(type, listener),
969
+ [registry]
970
+ );
971
+ const off = useCallback(
972
+ (type, listener) => registry.off(type, listener),
973
+ [registry]
974
+ );
975
+ const contextValue = useMemo(
976
+ () => ({
977
+ features,
978
+ config,
979
+ registry,
980
+ executor,
981
+ getElements,
982
+ getComponents,
983
+ createSnapshot,
984
+ on,
985
+ off,
986
+ initialized: true,
987
+ serverRunning,
988
+ startServer,
989
+ stopServer
990
+ }),
991
+ [
992
+ features,
993
+ config,
994
+ registry,
995
+ executor,
996
+ getElements,
997
+ getComponents,
998
+ createSnapshot,
999
+ on,
1000
+ off,
1001
+ serverRunning,
1002
+ startServer,
1003
+ stopServer
1004
+ ]
1005
+ );
1006
+ return /* @__PURE__ */ jsx(UIBridgeNativeContext.Provider, { value: contextValue, children });
1007
+ }
1008
+ function useUIBridgeNative() {
1009
+ const context = useContext(UIBridgeNativeContext);
1010
+ if (!context) {
1011
+ throw new Error("useUIBridgeNative must be used within a UIBridgeNativeProvider");
1012
+ }
1013
+ return context;
1014
+ }
1015
+ function useUIBridgeNativeOptional() {
1016
+ return useContext(UIBridgeNativeContext);
1017
+ }
1018
+ var useUIBridgeNativeRequired = useUIBridgeNative;
1019
+ function useUIElement(options) {
1020
+ const bridge = useUIBridgeNativeOptional();
1021
+ const ref = useRef(null);
1022
+ const [registered, setRegistered] = useState(false);
1023
+ const [_layout, setLayout] = useState(null);
1024
+ const propsRef = useRef({});
1025
+ const {
1026
+ id,
1027
+ type = "custom",
1028
+ label,
1029
+ actions,
1030
+ customActions,
1031
+ autoRegister = true,
1032
+ onStateChange,
1033
+ parentPath
1034
+ } = options;
1035
+ const treePath = parentPath ? `${parentPath}/${id}` : id;
1036
+ const bridgeProps = useMemo(
1037
+ () => ({
1038
+ testID: id,
1039
+ accessibilityLabel: label
1040
+ }),
1041
+ [id, label]
1042
+ );
1043
+ const register = useCallback(() => {
1044
+ if (!bridge || registered) return;
1045
+ bridge.registry.registerElement(id, ref, {
1046
+ type,
1047
+ label,
1048
+ actions,
1049
+ customActions,
1050
+ treePath,
1051
+ testId: id,
1052
+ accessibilityLabel: label
1053
+ });
1054
+ setRegistered(true);
1055
+ }, [bridge, registered, id, type, label, actions, customActions, treePath]);
1056
+ const unregister = useCallback(() => {
1057
+ if (!bridge || !registered) return;
1058
+ bridge.registry.unregisterElement(id);
1059
+ setRegistered(false);
1060
+ }, [bridge, registered, id]);
1061
+ const onLayout = useCallback(
1062
+ (event) => {
1063
+ const { x, y, width, height } = event.nativeEvent.layout;
1064
+ if (ref.current && "measureInWindow" in ref.current) {
1065
+ ref.current.measureInWindow(
1066
+ (pageX, pageY) => {
1067
+ const newLayout = {
1068
+ x,
1069
+ y,
1070
+ width,
1071
+ height,
1072
+ pageX,
1073
+ pageY
1074
+ };
1075
+ setLayout(newLayout);
1076
+ if (bridge && registered) {
1077
+ const newState = {
1078
+ mounted: true,
1079
+ visible: width > 0 && height > 0,
1080
+ enabled: true,
1081
+ focused: false,
1082
+ layout: newLayout
1083
+ };
1084
+ bridge.registry.updateElementState(id, newState);
1085
+ onStateChange?.(newState);
1086
+ }
1087
+ }
1088
+ );
1089
+ } else {
1090
+ const newLayout = {
1091
+ x,
1092
+ y,
1093
+ width,
1094
+ height,
1095
+ pageX: x,
1096
+ pageY: y
1097
+ };
1098
+ setLayout(newLayout);
1099
+ if (bridge && registered) {
1100
+ const newState = {
1101
+ mounted: true,
1102
+ visible: width > 0 && height > 0,
1103
+ enabled: true,
1104
+ focused: false,
1105
+ layout: newLayout
1106
+ };
1107
+ bridge.registry.updateElementState(id, newState);
1108
+ onStateChange?.(newState);
1109
+ }
1110
+ }
1111
+ },
1112
+ [bridge, registered, id, onStateChange]
1113
+ );
1114
+ useEffect(() => {
1115
+ if (autoRegister) {
1116
+ register();
1117
+ }
1118
+ return () => {
1119
+ unregister();
1120
+ };
1121
+ }, [autoRegister, register, unregister]);
1122
+ useCallback(
1123
+ (props) => {
1124
+ propsRef.current = { ...propsRef.current, ...props };
1125
+ if (bridge && registered) {
1126
+ bridge.registry.updateElementProps(id, props);
1127
+ }
1128
+ },
1129
+ [bridge, registered, id]
1130
+ );
1131
+ const getState = useCallback(() => {
1132
+ if (!bridge) return null;
1133
+ const element = bridge.registry.getElement(id);
1134
+ return element?.getState() || null;
1135
+ }, [bridge, id]);
1136
+ const getIdentifier = useCallback(() => {
1137
+ if (!bridge) return null;
1138
+ const element = bridge.registry.getElement(id);
1139
+ return element?.getIdentifier() || null;
1140
+ }, [bridge, id]);
1141
+ const trigger = useCallback(
1142
+ async (action, params) => {
1143
+ if (!bridge) {
1144
+ throw new Error("UI Bridge Native not available");
1145
+ }
1146
+ const response = await bridge.executor.executeAction(id, {
1147
+ action,
1148
+ params
1149
+ });
1150
+ if (!response.success) {
1151
+ throw new Error(response.error || "Action failed");
1152
+ }
1153
+ },
1154
+ [bridge, id]
1155
+ );
1156
+ const registeredElement = useMemo(() => {
1157
+ if (!bridge) return null;
1158
+ return bridge.registry.getElement(id) || null;
1159
+ }, [bridge, id, registered]);
1160
+ return {
1161
+ ref,
1162
+ onLayout,
1163
+ bridgeProps,
1164
+ registered,
1165
+ getState,
1166
+ getIdentifier,
1167
+ trigger,
1168
+ register,
1169
+ unregister,
1170
+ registeredElement
1171
+ };
1172
+ }
1173
+ function useUIElementWithProps(options) {
1174
+ const elementReturn = useUIElement(options);
1175
+ const bridge = useUIBridgeNativeOptional();
1176
+ const captureProps = useCallback(
1177
+ (props) => {
1178
+ if (bridge && elementReturn.registered) {
1179
+ bridge.registry.updateElementProps(options.id, props);
1180
+ }
1181
+ },
1182
+ [bridge, elementReturn.registered, options.id]
1183
+ );
1184
+ return {
1185
+ ...elementReturn,
1186
+ captureProps
1187
+ };
1188
+ }
1189
+ function useUIComponent(options) {
1190
+ const bridge = useUIBridgeNativeOptional();
1191
+ const registeredRef = useRef(false);
1192
+ const actionsRef = useRef(options.actions || []);
1193
+ const elementIdsRef = useRef(options.elementIds || []);
1194
+ const { id, name, description, autoRegister = true } = options;
1195
+ useEffect(() => {
1196
+ actionsRef.current = options.actions || [];
1197
+ elementIdsRef.current = options.elementIds || [];
1198
+ }, [options.actions, options.elementIds]);
1199
+ const register = useCallback(() => {
1200
+ if (!bridge || registeredRef.current) return;
1201
+ bridge.registry.registerComponent(id, {
1202
+ name,
1203
+ description,
1204
+ actions: actionsRef.current.map((a) => ({
1205
+ id: a.id,
1206
+ label: a.label,
1207
+ description: a.description,
1208
+ handler: a.handler
1209
+ })),
1210
+ elementIds: elementIdsRef.current
1211
+ });
1212
+ registeredRef.current = true;
1213
+ }, [bridge, id, name, description]);
1214
+ const unregister = useCallback(() => {
1215
+ if (!bridge || !registeredRef.current) return;
1216
+ bridge.registry.unregisterComponent(id);
1217
+ registeredRef.current = false;
1218
+ }, [bridge, id]);
1219
+ const executeAction = useCallback(
1220
+ async (actionId, params) => {
1221
+ if (!bridge) {
1222
+ throw new Error("UI Bridge Native not available");
1223
+ }
1224
+ const response = await bridge.executor.executeComponentAction(id, {
1225
+ action: actionId,
1226
+ params
1227
+ });
1228
+ if (!response.success) {
1229
+ throw new Error(response.error || "Action failed");
1230
+ }
1231
+ return response.result;
1232
+ },
1233
+ [bridge, id]
1234
+ );
1235
+ const updateActions = useCallback(
1236
+ (actions) => {
1237
+ actionsRef.current = actions;
1238
+ if (registeredRef.current && bridge) {
1239
+ bridge.registry.unregisterComponent(id);
1240
+ registeredRef.current = false;
1241
+ register();
1242
+ }
1243
+ },
1244
+ [bridge, id, register]
1245
+ );
1246
+ const addElement = useCallback((elementId) => {
1247
+ if (!elementIdsRef.current.includes(elementId)) {
1248
+ elementIdsRef.current = [...elementIdsRef.current, elementId];
1249
+ }
1250
+ }, []);
1251
+ const removeElement = useCallback((elementId) => {
1252
+ elementIdsRef.current = elementIdsRef.current.filter((eid) => eid !== elementId);
1253
+ }, []);
1254
+ useEffect(() => {
1255
+ if (autoRegister) {
1256
+ register();
1257
+ }
1258
+ return () => {
1259
+ unregister();
1260
+ };
1261
+ }, [autoRegister, register, unregister]);
1262
+ const registeredComponent = useMemo(() => {
1263
+ if (!bridge) return null;
1264
+ return bridge.registry.getComponent(id) || null;
1265
+ }, [bridge, id, registeredRef.current]);
1266
+ return {
1267
+ registered: registeredRef.current,
1268
+ executeAction,
1269
+ register,
1270
+ unregister,
1271
+ updateActions,
1272
+ addElement,
1273
+ removeElement,
1274
+ registeredComponent
1275
+ };
1276
+ }
1277
+ function useUIComponentAction(handler, deps) {
1278
+ return useCallback(handler, deps);
1279
+ }
1280
+ function useUIBridge() {
1281
+ const bridge = useUIBridgeNativeOptional();
1282
+ const available = bridge !== null;
1283
+ const initialized = bridge?.initialized ?? false;
1284
+ const elements = useMemo(
1285
+ () => bridge ? bridge.getElements() : [],
1286
+ [bridge]
1287
+ );
1288
+ const components = useMemo(
1289
+ () => bridge ? bridge.getComponents() : [],
1290
+ [bridge]
1291
+ );
1292
+ const workflows = useMemo(
1293
+ () => bridge ? bridge.registry.getAllWorkflows() : [],
1294
+ [bridge]
1295
+ );
1296
+ const createSnapshot = useCallback(() => {
1297
+ if (!bridge) {
1298
+ return {
1299
+ timestamp: Date.now(),
1300
+ elements: [],
1301
+ components: [],
1302
+ workflows: []
1303
+ };
1304
+ }
1305
+ return bridge.createSnapshot();
1306
+ }, [bridge]);
1307
+ const executeAction = useCallback(
1308
+ async (elementId, request) => {
1309
+ if (!bridge) {
1310
+ return {
1311
+ success: false,
1312
+ error: "UI Bridge not available",
1313
+ durationMs: 0,
1314
+ timestamp: Date.now()
1315
+ };
1316
+ }
1317
+ return bridge.executor.executeAction(elementId, request);
1318
+ },
1319
+ [bridge]
1320
+ );
1321
+ const executeComponentAction = useCallback(
1322
+ async (componentId, request) => {
1323
+ if (!bridge) {
1324
+ return {
1325
+ success: false,
1326
+ error: "UI Bridge not available",
1327
+ durationMs: 0,
1328
+ timestamp: Date.now()
1329
+ };
1330
+ }
1331
+ return bridge.executor.executeComponentAction(componentId, request);
1332
+ },
1333
+ [bridge]
1334
+ );
1335
+ const find = useCallback(
1336
+ async (request) => {
1337
+ if (!bridge) {
1338
+ return {
1339
+ elements: [],
1340
+ total: 0,
1341
+ durationMs: 0,
1342
+ timestamp: Date.now()
1343
+ };
1344
+ }
1345
+ return bridge.executor.find(request || {});
1346
+ },
1347
+ [bridge]
1348
+ );
1349
+ const getElement = useCallback(
1350
+ (id) => bridge?.registry.getElement(id),
1351
+ [bridge]
1352
+ );
1353
+ const getComponent = useCallback(
1354
+ (id) => bridge?.registry.getComponent(id),
1355
+ [bridge]
1356
+ );
1357
+ const getElementState = useCallback(
1358
+ (id) => {
1359
+ const element = bridge?.registry.getElement(id);
1360
+ return element?.getState() ?? null;
1361
+ },
1362
+ [bridge]
1363
+ );
1364
+ const registerWorkflow = useCallback(
1365
+ (workflow) => {
1366
+ bridge?.registry.registerWorkflow(workflow);
1367
+ },
1368
+ [bridge]
1369
+ );
1370
+ const unregisterWorkflow = useCallback(
1371
+ (id) => {
1372
+ bridge?.registry.unregisterWorkflow(id);
1373
+ },
1374
+ [bridge]
1375
+ );
1376
+ return {
1377
+ available,
1378
+ initialized,
1379
+ elements,
1380
+ components,
1381
+ workflows,
1382
+ createSnapshot,
1383
+ executeAction,
1384
+ executeComponentAction,
1385
+ find,
1386
+ getElement,
1387
+ getComponent,
1388
+ getElementState,
1389
+ registerWorkflow,
1390
+ unregisterWorkflow
1391
+ };
1392
+ }
1393
+ function useUIBridgeRequired() {
1394
+ const result = useUIBridge();
1395
+ if (!result.available) {
1396
+ throw new Error("useUIBridgeRequired must be used within a UIBridgeNativeProvider");
1397
+ }
1398
+ return result;
1399
+ }
1400
+
1401
+ // src/native/server/types.ts
1402
+ var UI_BRIDGE_NATIVE_ROUTES = {
1403
+ // Control - Elements
1404
+ GET_ELEMENTS: {
1405
+ method: "GET",
1406
+ path: "/ui-bridge/control/elements",
1407
+ description: "List all registered elements"
1408
+ },
1409
+ GET_ELEMENT: {
1410
+ method: "GET",
1411
+ path: "/ui-bridge/control/element/:id",
1412
+ description: "Get element details"
1413
+ },
1414
+ GET_ELEMENT_STATE: {
1415
+ method: "GET",
1416
+ path: "/ui-bridge/control/element/:id/state",
1417
+ description: "Get element state"
1418
+ },
1419
+ EXECUTE_ACTION: {
1420
+ method: "POST",
1421
+ path: "/ui-bridge/control/element/:id/action",
1422
+ description: "Execute action on element"
1423
+ },
1424
+ // Control - Components
1425
+ GET_COMPONENTS: {
1426
+ method: "GET",
1427
+ path: "/ui-bridge/control/components",
1428
+ description: "List all registered components"
1429
+ },
1430
+ GET_COMPONENT: {
1431
+ method: "GET",
1432
+ path: "/ui-bridge/control/component/:id",
1433
+ description: "Get component details"
1434
+ },
1435
+ EXECUTE_COMPONENT_ACTION: {
1436
+ method: "POST",
1437
+ path: "/ui-bridge/control/component/:id/action/:actionId",
1438
+ description: "Execute component action"
1439
+ },
1440
+ // Discovery
1441
+ FIND: {
1442
+ method: "POST",
1443
+ path: "/ui-bridge/control/find",
1444
+ description: "Find elements matching criteria"
1445
+ },
1446
+ GET_SNAPSHOT: {
1447
+ method: "GET",
1448
+ path: "/ui-bridge/control/snapshot",
1449
+ description: "Get full bridge snapshot"
1450
+ },
1451
+ // Workflows
1452
+ GET_WORKFLOWS: {
1453
+ method: "GET",
1454
+ path: "/ui-bridge/control/workflows",
1455
+ description: "List all workflows"
1456
+ },
1457
+ RUN_WORKFLOW: {
1458
+ method: "POST",
1459
+ path: "/ui-bridge/control/workflow/:id/run",
1460
+ description: "Run a workflow"
1461
+ },
1462
+ // Health
1463
+ HEALTH: {
1464
+ method: "GET",
1465
+ path: "/ui-bridge/health",
1466
+ description: "Health check"
1467
+ }
1468
+ };
1469
+
1470
+ // src/native/server/handlers.ts
1471
+ function success(data) {
1472
+ return {
1473
+ success: true,
1474
+ data,
1475
+ timestamp: Date.now()
1476
+ };
1477
+ }
1478
+ function error(message, code) {
1479
+ return {
1480
+ success: false,
1481
+ error: message,
1482
+ code,
1483
+ timestamp: Date.now()
1484
+ };
1485
+ }
1486
+ function createServerHandlers(registry, executor) {
1487
+ return {
1488
+ // Elements
1489
+ getElements: async () => {
1490
+ const elements = registry.getAllElements().map((e) => ({
1491
+ id: e.id,
1492
+ type: e.type,
1493
+ label: e.label,
1494
+ identifier: e.getIdentifier(),
1495
+ state: e.getState(),
1496
+ actions: e.actions,
1497
+ customActions: e.customActions ? Object.keys(e.customActions) : void 0
1498
+ }));
1499
+ return success({ elements });
1500
+ },
1501
+ getElement: async (ctx) => {
1502
+ const { id } = ctx.params;
1503
+ const element = registry.getElement(id);
1504
+ if (!element) {
1505
+ return error(`Element not found: ${id}`, "ELEMENT_NOT_FOUND");
1506
+ }
1507
+ return success({
1508
+ element: {
1509
+ id: element.id,
1510
+ type: element.type,
1511
+ label: element.label,
1512
+ identifier: element.getIdentifier(),
1513
+ state: element.getState(),
1514
+ actions: element.actions,
1515
+ customActions: element.customActions ? Object.keys(element.customActions) : void 0
1516
+ }
1517
+ });
1518
+ },
1519
+ getElementState: async (ctx) => {
1520
+ const { id } = ctx.params;
1521
+ const element = registry.getElement(id);
1522
+ if (!element) {
1523
+ return error(`Element not found: ${id}`, "ELEMENT_NOT_FOUND");
1524
+ }
1525
+ return success({ state: element.getState() });
1526
+ },
1527
+ executeAction: async (ctx) => {
1528
+ const { id } = ctx.params;
1529
+ const body = ctx.body;
1530
+ if (!body?.action) {
1531
+ return error("Action is required", "INVALID_REQUEST");
1532
+ }
1533
+ const response = await executor.executeAction(id, {
1534
+ action: body.action,
1535
+ params: body.params,
1536
+ waitOptions: body.waitOptions
1537
+ });
1538
+ if (!response.success) {
1539
+ return error(response.error || "Action failed", "ACTION_FAILED");
1540
+ }
1541
+ return success(response);
1542
+ },
1543
+ // Components
1544
+ getComponents: async () => {
1545
+ const components = registry.getAllComponents().map((c) => ({
1546
+ id: c.id,
1547
+ name: c.name,
1548
+ description: c.description,
1549
+ actions: c.actions.map((a) => ({ id: a.id, label: a.label })),
1550
+ elementIds: c.elementIds
1551
+ }));
1552
+ return success({ components });
1553
+ },
1554
+ getComponent: async (ctx) => {
1555
+ const { id } = ctx.params;
1556
+ const component = registry.getComponent(id);
1557
+ if (!component) {
1558
+ return error(`Component not found: ${id}`, "COMPONENT_NOT_FOUND");
1559
+ }
1560
+ return success({
1561
+ component: {
1562
+ id: component.id,
1563
+ name: component.name,
1564
+ description: component.description,
1565
+ actions: component.actions.map((a) => ({
1566
+ id: a.id,
1567
+ label: a.label,
1568
+ description: a.description
1569
+ })),
1570
+ elementIds: component.elementIds
1571
+ }
1572
+ });
1573
+ },
1574
+ executeComponentAction: async (ctx) => {
1575
+ const { id, actionId } = ctx.params;
1576
+ const body = ctx.body;
1577
+ const response = await executor.executeComponentAction(id, {
1578
+ action: actionId,
1579
+ params: body?.params
1580
+ });
1581
+ if (!response.success) {
1582
+ return error(response.error || "Action failed", "ACTION_FAILED");
1583
+ }
1584
+ return success(response);
1585
+ },
1586
+ // Discovery
1587
+ find: async (ctx) => {
1588
+ const body = ctx.body;
1589
+ const response = await executor.find({
1590
+ types: body?.types,
1591
+ testIdPattern: body?.testIdPattern,
1592
+ accessibilityLabelPattern: body?.accessibilityLabelPattern,
1593
+ visibleOnly: body?.visibleOnly,
1594
+ limit: body?.limit
1595
+ });
1596
+ return success(response);
1597
+ },
1598
+ getSnapshot: async () => {
1599
+ const snapshot = registry.createSnapshot();
1600
+ return success(snapshot);
1601
+ },
1602
+ // Workflows
1603
+ getWorkflows: async () => {
1604
+ const workflows = registry.getAllWorkflows().map((w) => ({
1605
+ id: w.id,
1606
+ name: w.name,
1607
+ description: w.description,
1608
+ stepCount: w.steps.length
1609
+ }));
1610
+ return success({ workflows });
1611
+ },
1612
+ runWorkflow: async (ctx) => {
1613
+ const { id } = ctx.params;
1614
+ const workflow = registry.getWorkflow(id);
1615
+ if (!workflow) {
1616
+ return error(`Workflow not found: ${id}`, "WORKFLOW_NOT_FOUND");
1617
+ }
1618
+ return success({
1619
+ runId: `run-${Date.now()}`,
1620
+ status: "pending"
1621
+ });
1622
+ },
1623
+ // Health
1624
+ health: async () => {
1625
+ const stats = registry.getStats();
1626
+ return success({
1627
+ status: "healthy",
1628
+ timestamp: Date.now(),
1629
+ ...stats
1630
+ });
1631
+ }
1632
+ };
1633
+ }
1634
+
1635
+ // src/native/server/http-server.ts
1636
+ var NativeUIBridgeServer = class {
1637
+ constructor(registry, executor, config = {}) {
1638
+ this.registry = registry;
1639
+ this.executor = executor;
1640
+ this.running = false;
1641
+ this.config = {
1642
+ serverPort: 9876,
1643
+ cors: true,
1644
+ ...config
1645
+ };
1646
+ this.handlers = createServerHandlers(registry, executor);
1647
+ }
1648
+ /**
1649
+ * Set the server adapter
1650
+ */
1651
+ setAdapter(adapter) {
1652
+ this.adapter = adapter;
1653
+ }
1654
+ /**
1655
+ * Start the HTTP server
1656
+ */
1657
+ async start() {
1658
+ if (this.running) {
1659
+ console.warn("[ui-bridge-native] Server already running");
1660
+ return;
1661
+ }
1662
+ if (!this.adapter) {
1663
+ console.warn(
1664
+ "[ui-bridge-native] No server adapter configured. Call setAdapter() first."
1665
+ );
1666
+ console.warn(
1667
+ "[ui-bridge-native] See documentation for supported adapters."
1668
+ );
1669
+ return;
1670
+ }
1671
+ await this.adapter.start(
1672
+ this.config.serverPort,
1673
+ this.handleRequest.bind(this)
1674
+ );
1675
+ this.running = true;
1676
+ console.log(
1677
+ `[ui-bridge-native] HTTP server started on port ${this.config.serverPort}`
1678
+ );
1679
+ }
1680
+ /**
1681
+ * Stop the HTTP server
1682
+ */
1683
+ async stop() {
1684
+ if (!this.running || !this.adapter) {
1685
+ return;
1686
+ }
1687
+ await this.adapter.stop();
1688
+ this.running = false;
1689
+ console.log("[ui-bridge-native] HTTP server stopped");
1690
+ }
1691
+ /**
1692
+ * Check if server is running
1693
+ */
1694
+ isRunning() {
1695
+ return this.running;
1696
+ }
1697
+ /**
1698
+ * Handle incoming HTTP request
1699
+ */
1700
+ async handleRequest(request) {
1701
+ const headers = {
1702
+ "Content-Type": "application/json"
1703
+ };
1704
+ if (this.config.cors) {
1705
+ headers["Access-Control-Allow-Origin"] = this.config.allowedOrigins ? this.config.allowedOrigins.join(",") : "*";
1706
+ headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS";
1707
+ headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization";
1708
+ }
1709
+ if (request.method === "OPTIONS") {
1710
+ return { status: 204, headers, body: "" };
1711
+ }
1712
+ try {
1713
+ const response = await this.routeRequest(request);
1714
+ return {
1715
+ status: response.success ? 200 : 400,
1716
+ headers,
1717
+ body: JSON.stringify(response)
1718
+ };
1719
+ } catch (error2) {
1720
+ const errorResponse = {
1721
+ success: false,
1722
+ error: error2 instanceof Error ? error2.message : "Internal server error",
1723
+ code: "INTERNAL_ERROR",
1724
+ timestamp: Date.now()
1725
+ };
1726
+ return {
1727
+ status: 500,
1728
+ headers,
1729
+ body: JSON.stringify(errorResponse)
1730
+ };
1731
+ }
1732
+ }
1733
+ /**
1734
+ * Route request to appropriate handler
1735
+ */
1736
+ async routeRequest(request) {
1737
+ const { method, path, query, body } = request;
1738
+ const parsePath = (pattern, actual) => {
1739
+ const patternParts = pattern.split("/");
1740
+ const actualParts = actual.split("/");
1741
+ if (patternParts.length !== actualParts.length) {
1742
+ return null;
1743
+ }
1744
+ const params2 = {};
1745
+ for (let i = 0; i < patternParts.length; i++) {
1746
+ if (patternParts[i].startsWith(":")) {
1747
+ params2[patternParts[i].slice(1)] = actualParts[i];
1748
+ } else if (patternParts[i] !== actualParts[i]) {
1749
+ return null;
1750
+ }
1751
+ }
1752
+ return params2;
1753
+ };
1754
+ if (method === "GET" && path === "/ui-bridge/health") {
1755
+ return this.handlers.health({ params: {}, query, body });
1756
+ }
1757
+ if (method === "GET" && path === "/ui-bridge/control/elements") {
1758
+ return this.handlers.getElements({ params: {}, query, body });
1759
+ }
1760
+ let params = parsePath("/ui-bridge/control/element/:id", path);
1761
+ if (method === "GET" && params) {
1762
+ return this.handlers.getElement({ params, query, body });
1763
+ }
1764
+ params = parsePath("/ui-bridge/control/element/:id/state", path);
1765
+ if (method === "GET" && params) {
1766
+ return this.handlers.getElementState({ params, query, body });
1767
+ }
1768
+ params = parsePath("/ui-bridge/control/element/:id/action", path);
1769
+ if (method === "POST" && params) {
1770
+ return this.handlers.executeAction({ params, query, body });
1771
+ }
1772
+ if (method === "GET" && path === "/ui-bridge/control/components") {
1773
+ return this.handlers.getComponents({ params: {}, query, body });
1774
+ }
1775
+ params = parsePath("/ui-bridge/control/component/:id", path);
1776
+ if (method === "GET" && params) {
1777
+ return this.handlers.getComponent({ params, query, body });
1778
+ }
1779
+ params = parsePath("/ui-bridge/control/component/:id/action/:actionId", path);
1780
+ if (method === "POST" && params) {
1781
+ return this.handlers.executeComponentAction({ params, query, body });
1782
+ }
1783
+ if (method === "POST" && path === "/ui-bridge/control/find") {
1784
+ return this.handlers.find({ params: {}, query, body });
1785
+ }
1786
+ if (method === "GET" && path === "/ui-bridge/control/snapshot") {
1787
+ return this.handlers.getSnapshot({ params: {}, query, body });
1788
+ }
1789
+ if (method === "GET" && path === "/ui-bridge/control/workflows") {
1790
+ return this.handlers.getWorkflows({ params: {}, query, body });
1791
+ }
1792
+ params = parsePath("/ui-bridge/control/workflow/:id/run", path);
1793
+ if (method === "POST" && params) {
1794
+ return this.handlers.runWorkflow({ params, query, body });
1795
+ }
1796
+ return {
1797
+ success: false,
1798
+ error: `Route not found: ${method} ${path}`,
1799
+ code: "NOT_FOUND",
1800
+ timestamp: Date.now()
1801
+ };
1802
+ }
1803
+ };
1804
+ function createNativeServer(registry, executor, config) {
1805
+ return new NativeUIBridgeServer(registry, executor, config);
1806
+ }
1807
+ function ElementCard({
1808
+ element,
1809
+ onPress
1810
+ }) {
1811
+ const state = element.getState();
1812
+ const identifier = element.getIdentifier();
1813
+ return /* @__PURE__ */ jsxs(
1814
+ TouchableOpacity,
1815
+ {
1816
+ style: styles.elementCard,
1817
+ onPress: () => onPress(element),
1818
+ children: [
1819
+ /* @__PURE__ */ jsxs(View, { style: styles.elementHeader, children: [
1820
+ /* @__PURE__ */ jsx(Text, { style: styles.elementId, children: element.id }),
1821
+ /* @__PURE__ */ jsx(Text, { style: styles.elementType, children: element.type })
1822
+ ] }),
1823
+ element.label && /* @__PURE__ */ jsx(Text, { style: styles.elementLabel, children: element.label }),
1824
+ /* @__PURE__ */ jsxs(View, { style: styles.stateRow, children: [
1825
+ /* @__PURE__ */ jsx(StateIndicator, { label: "Mounted", value: state.mounted }),
1826
+ /* @__PURE__ */ jsx(StateIndicator, { label: "Visible", value: state.visible }),
1827
+ /* @__PURE__ */ jsx(StateIndicator, { label: "Enabled", value: state.enabled })
1828
+ ] }),
1829
+ identifier.testId && /* @__PURE__ */ jsxs(Text, { style: styles.testId, children: [
1830
+ "testID: ",
1831
+ identifier.testId
1832
+ ] })
1833
+ ]
1834
+ }
1835
+ );
1836
+ }
1837
+ function StateIndicator({ label, value }) {
1838
+ return /* @__PURE__ */ jsxs(View, { style: styles.stateIndicator, children: [
1839
+ /* @__PURE__ */ jsx(
1840
+ View,
1841
+ {
1842
+ style: [
1843
+ styles.stateDot,
1844
+ { backgroundColor: value ? "#4CAF50" : "#F44336" }
1845
+ ]
1846
+ }
1847
+ ),
1848
+ /* @__PURE__ */ jsx(Text, { style: styles.stateLabel, children: label })
1849
+ ] });
1850
+ }
1851
+ function ElementDetail({
1852
+ element,
1853
+ onClose
1854
+ }) {
1855
+ const state = element.getState();
1856
+ const identifier = element.getIdentifier();
1857
+ return /* @__PURE__ */ jsxs(View, { style: styles.detailContainer, children: [
1858
+ /* @__PURE__ */ jsxs(View, { style: styles.detailHeader, children: [
1859
+ /* @__PURE__ */ jsx(Text, { style: styles.detailTitle, children: element.id }),
1860
+ /* @__PURE__ */ jsx(TouchableOpacity, { onPress: onClose, children: /* @__PURE__ */ jsx(Text, { style: styles.closeButton, children: "Close" }) })
1861
+ ] }),
1862
+ /* @__PURE__ */ jsxs(ScrollView, { style: styles.detailContent, children: [
1863
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionTitle, children: "Type" }),
1864
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionValue, children: element.type }),
1865
+ element.label && /* @__PURE__ */ jsxs(Fragment, { children: [
1866
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionTitle, children: "Label" }),
1867
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionValue, children: element.label })
1868
+ ] }),
1869
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionTitle, children: "State" }),
1870
+ /* @__PURE__ */ jsxs(View, { style: styles.stateSection, children: [
1871
+ /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1872
+ "Mounted: ",
1873
+ String(state.mounted)
1874
+ ] }),
1875
+ /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1876
+ "Visible: ",
1877
+ String(state.visible)
1878
+ ] }),
1879
+ /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1880
+ "Enabled: ",
1881
+ String(state.enabled)
1882
+ ] }),
1883
+ /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1884
+ "Focused: ",
1885
+ String(state.focused)
1886
+ ] }),
1887
+ state.value !== void 0 && /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1888
+ "Value: ",
1889
+ state.value
1890
+ ] })
1891
+ ] }),
1892
+ state.layout && /* @__PURE__ */ jsxs(Fragment, { children: [
1893
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionTitle, children: "Layout" }),
1894
+ /* @__PURE__ */ jsxs(View, { style: styles.stateSection, children: [
1895
+ /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1896
+ "Position: (",
1897
+ state.layout.x,
1898
+ ", ",
1899
+ state.layout.y,
1900
+ ")"
1901
+ ] }),
1902
+ /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1903
+ "Size: ",
1904
+ state.layout.width,
1905
+ " x ",
1906
+ state.layout.height
1907
+ ] }),
1908
+ /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1909
+ "Page: (",
1910
+ state.layout.pageX,
1911
+ ", ",
1912
+ state.layout.pageY,
1913
+ ")"
1914
+ ] })
1915
+ ] })
1916
+ ] }),
1917
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionTitle, children: "Identifier" }),
1918
+ /* @__PURE__ */ jsxs(View, { style: styles.stateSection, children: [
1919
+ identifier.uiId && /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1920
+ "uiId: ",
1921
+ identifier.uiId
1922
+ ] }),
1923
+ identifier.testId && /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1924
+ "testId: ",
1925
+ identifier.testId
1926
+ ] }),
1927
+ identifier.accessibilityLabel && /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1928
+ "a11yLabel: ",
1929
+ identifier.accessibilityLabel
1930
+ ] }),
1931
+ /* @__PURE__ */ jsxs(Text, { style: styles.stateText, children: [
1932
+ "treePath: ",
1933
+ identifier.treePath
1934
+ ] })
1935
+ ] }),
1936
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionTitle, children: "Actions" }),
1937
+ /* @__PURE__ */ jsx(View, { style: styles.actionsSection, children: element.actions.map((action) => /* @__PURE__ */ jsx(View, { style: styles.actionBadge, children: /* @__PURE__ */ jsx(Text, { style: styles.actionText, children: action }) }, action)) }),
1938
+ element.customActions && Object.keys(element.customActions).length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
1939
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionTitle, children: "Custom Actions" }),
1940
+ /* @__PURE__ */ jsx(View, { style: styles.actionsSection, children: Object.keys(element.customActions).map((action) => /* @__PURE__ */ jsx(View, { style: [styles.actionBadge, styles.customActionBadge], children: /* @__PURE__ */ jsx(Text, { style: styles.actionText, children: action }) }, action)) })
1941
+ ] })
1942
+ ] })
1943
+ ] });
1944
+ }
1945
+ function UIBridgeInspector({
1946
+ visible = false,
1947
+ onClose,
1948
+ togglePosition = "bottom-right"
1949
+ }) {
1950
+ const bridge = useUIBridgeNativeOptional();
1951
+ const [showInspector, setShowInspector] = useState(visible);
1952
+ const [selectedElement, setSelectedElement] = useState(
1953
+ null
1954
+ );
1955
+ const elements = useMemo(
1956
+ () => bridge ? bridge.getElements() : [],
1957
+ [bridge, showInspector]
1958
+ );
1959
+ const components = useMemo(
1960
+ () => bridge ? bridge.getComponents() : [],
1961
+ [bridge, showInspector]
1962
+ );
1963
+ const handleToggle = useCallback(() => {
1964
+ setShowInspector((prev) => !prev);
1965
+ }, []);
1966
+ const handleClose = useCallback(() => {
1967
+ setShowInspector(false);
1968
+ onClose?.();
1969
+ }, [onClose]);
1970
+ const handleSelectElement = useCallback((element) => {
1971
+ setSelectedElement(element);
1972
+ }, []);
1973
+ const handleCloseDetail = useCallback(() => {
1974
+ setSelectedElement(null);
1975
+ }, []);
1976
+ const toggleStyle = useMemo(() => {
1977
+ switch (togglePosition) {
1978
+ case "top-left":
1979
+ return { top: 50, left: 10 };
1980
+ case "top-right":
1981
+ return { top: 50, right: 10 };
1982
+ case "bottom-left":
1983
+ return { bottom: 50, left: 10 };
1984
+ case "bottom-right":
1985
+ default:
1986
+ return { bottom: 50, right: 10 };
1987
+ }
1988
+ }, [togglePosition]);
1989
+ if (!bridge) {
1990
+ return null;
1991
+ }
1992
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1993
+ /* @__PURE__ */ jsx(
1994
+ TouchableOpacity,
1995
+ {
1996
+ style: [styles.toggleButton, toggleStyle],
1997
+ onPress: handleToggle,
1998
+ children: /* @__PURE__ */ jsx(Text, { style: styles.toggleText, children: "UI" })
1999
+ }
2000
+ ),
2001
+ /* @__PURE__ */ jsx(
2002
+ Modal,
2003
+ {
2004
+ visible: showInspector,
2005
+ animationType: "slide",
2006
+ transparent: true,
2007
+ onRequestClose: handleClose,
2008
+ children: /* @__PURE__ */ jsx(View, { style: styles.modalContainer, children: /* @__PURE__ */ jsxs(View, { style: styles.inspectorContainer, children: [
2009
+ /* @__PURE__ */ jsxs(View, { style: styles.header, children: [
2010
+ /* @__PURE__ */ jsx(Text, { style: styles.headerTitle, children: "UI Bridge Inspector" }),
2011
+ /* @__PURE__ */ jsx(TouchableOpacity, { onPress: handleClose, children: /* @__PURE__ */ jsx(Text, { style: styles.closeButton, children: "X" }) })
2012
+ ] }),
2013
+ /* @__PURE__ */ jsxs(View, { style: styles.statsRow, children: [
2014
+ /* @__PURE__ */ jsxs(View, { style: styles.stat, children: [
2015
+ /* @__PURE__ */ jsx(Text, { style: styles.statValue, children: elements.length }),
2016
+ /* @__PURE__ */ jsx(Text, { style: styles.statLabel, children: "Elements" })
2017
+ ] }),
2018
+ /* @__PURE__ */ jsxs(View, { style: styles.stat, children: [
2019
+ /* @__PURE__ */ jsx(Text, { style: styles.statValue, children: components.length }),
2020
+ /* @__PURE__ */ jsx(Text, { style: styles.statLabel, children: "Components" })
2021
+ ] }),
2022
+ /* @__PURE__ */ jsxs(View, { style: styles.stat, children: [
2023
+ /* @__PURE__ */ jsx(Text, { style: styles.statValue, children: bridge.serverRunning ? "ON" : "OFF" }),
2024
+ /* @__PURE__ */ jsx(Text, { style: styles.statLabel, children: "Server" })
2025
+ ] })
2026
+ ] }),
2027
+ selectedElement ? /* @__PURE__ */ jsx(
2028
+ ElementDetail,
2029
+ {
2030
+ element: selectedElement,
2031
+ onClose: handleCloseDetail
2032
+ }
2033
+ ) : /* @__PURE__ */ jsxs(ScrollView, { style: styles.elementList, children: [
2034
+ elements.map((element) => /* @__PURE__ */ jsx(
2035
+ ElementCard,
2036
+ {
2037
+ element,
2038
+ onPress: handleSelectElement
2039
+ },
2040
+ element.id
2041
+ )),
2042
+ elements.length === 0 && /* @__PURE__ */ jsx(Text, { style: styles.emptyText, children: "No elements registered yet" })
2043
+ ] })
2044
+ ] }) })
2045
+ }
2046
+ )
2047
+ ] });
2048
+ }
2049
+ var { height: screenHeight } = Dimensions.get("window");
2050
+ var styles = StyleSheet.create({
2051
+ toggleButton: {
2052
+ position: "absolute",
2053
+ width: 44,
2054
+ height: 44,
2055
+ borderRadius: 22,
2056
+ backgroundColor: "#2196F3",
2057
+ justifyContent: "center",
2058
+ alignItems: "center",
2059
+ shadowColor: "#000",
2060
+ shadowOffset: { width: 0, height: 2 },
2061
+ shadowOpacity: 0.25,
2062
+ shadowRadius: 4,
2063
+ elevation: 5,
2064
+ zIndex: 1e3
2065
+ },
2066
+ toggleText: {
2067
+ color: "#fff",
2068
+ fontWeight: "bold",
2069
+ fontSize: 14
2070
+ },
2071
+ modalContainer: {
2072
+ flex: 1,
2073
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
2074
+ justifyContent: "flex-end"
2075
+ },
2076
+ inspectorContainer: {
2077
+ backgroundColor: "#1e1e1e",
2078
+ borderTopLeftRadius: 16,
2079
+ borderTopRightRadius: 16,
2080
+ maxHeight: screenHeight * 0.8
2081
+ },
2082
+ header: {
2083
+ flexDirection: "row",
2084
+ justifyContent: "space-between",
2085
+ alignItems: "center",
2086
+ padding: 16,
2087
+ borderBottomWidth: 1,
2088
+ borderBottomColor: "#333"
2089
+ },
2090
+ headerTitle: {
2091
+ color: "#fff",
2092
+ fontSize: 18,
2093
+ fontWeight: "bold"
2094
+ },
2095
+ closeButton: {
2096
+ color: "#2196F3",
2097
+ fontSize: 16,
2098
+ fontWeight: "bold"
2099
+ },
2100
+ statsRow: {
2101
+ flexDirection: "row",
2102
+ padding: 12,
2103
+ borderBottomWidth: 1,
2104
+ borderBottomColor: "#333"
2105
+ },
2106
+ stat: {
2107
+ flex: 1,
2108
+ alignItems: "center"
2109
+ },
2110
+ statValue: {
2111
+ color: "#fff",
2112
+ fontSize: 20,
2113
+ fontWeight: "bold"
2114
+ },
2115
+ statLabel: {
2116
+ color: "#888",
2117
+ fontSize: 12,
2118
+ marginTop: 2
2119
+ },
2120
+ elementList: {
2121
+ padding: 12
2122
+ },
2123
+ elementCard: {
2124
+ backgroundColor: "#2d2d2d",
2125
+ borderRadius: 8,
2126
+ padding: 12,
2127
+ marginBottom: 8
2128
+ },
2129
+ elementHeader: {
2130
+ flexDirection: "row",
2131
+ justifyContent: "space-between",
2132
+ alignItems: "center"
2133
+ },
2134
+ elementId: {
2135
+ color: "#fff",
2136
+ fontSize: 14,
2137
+ fontWeight: "bold"
2138
+ },
2139
+ elementType: {
2140
+ color: "#888",
2141
+ fontSize: 12,
2142
+ backgroundColor: "#444",
2143
+ paddingHorizontal: 8,
2144
+ paddingVertical: 2,
2145
+ borderRadius: 4
2146
+ },
2147
+ elementLabel: {
2148
+ color: "#aaa",
2149
+ fontSize: 12,
2150
+ marginTop: 4
2151
+ },
2152
+ stateRow: {
2153
+ flexDirection: "row",
2154
+ marginTop: 8
2155
+ },
2156
+ stateIndicator: {
2157
+ flexDirection: "row",
2158
+ alignItems: "center",
2159
+ marginRight: 12
2160
+ },
2161
+ stateDot: {
2162
+ width: 8,
2163
+ height: 8,
2164
+ borderRadius: 4,
2165
+ marginRight: 4
2166
+ },
2167
+ stateLabel: {
2168
+ color: "#888",
2169
+ fontSize: 10
2170
+ },
2171
+ testId: {
2172
+ color: "#666",
2173
+ fontSize: 10,
2174
+ marginTop: 4,
2175
+ fontFamily: "monospace"
2176
+ },
2177
+ emptyText: {
2178
+ color: "#888",
2179
+ textAlign: "center",
2180
+ marginTop: 20
2181
+ },
2182
+ detailContainer: {
2183
+ flex: 1
2184
+ },
2185
+ detailHeader: {
2186
+ flexDirection: "row",
2187
+ justifyContent: "space-between",
2188
+ alignItems: "center",
2189
+ padding: 12,
2190
+ borderBottomWidth: 1,
2191
+ borderBottomColor: "#333"
2192
+ },
2193
+ detailTitle: {
2194
+ color: "#fff",
2195
+ fontSize: 16,
2196
+ fontWeight: "bold"
2197
+ },
2198
+ detailContent: {
2199
+ padding: 12
2200
+ },
2201
+ sectionTitle: {
2202
+ color: "#888",
2203
+ fontSize: 12,
2204
+ marginTop: 12,
2205
+ marginBottom: 4,
2206
+ textTransform: "uppercase"
2207
+ },
2208
+ sectionValue: {
2209
+ color: "#fff",
2210
+ fontSize: 14
2211
+ },
2212
+ stateSection: {
2213
+ backgroundColor: "#2d2d2d",
2214
+ borderRadius: 8,
2215
+ padding: 8
2216
+ },
2217
+ stateText: {
2218
+ color: "#ddd",
2219
+ fontSize: 12,
2220
+ fontFamily: "monospace",
2221
+ marginBottom: 2
2222
+ },
2223
+ actionsSection: {
2224
+ flexDirection: "row",
2225
+ flexWrap: "wrap"
2226
+ },
2227
+ actionBadge: {
2228
+ backgroundColor: "#2196F3",
2229
+ paddingHorizontal: 8,
2230
+ paddingVertical: 4,
2231
+ borderRadius: 4,
2232
+ marginRight: 6,
2233
+ marginBottom: 6
2234
+ },
2235
+ customActionBadge: {
2236
+ backgroundColor: "#9C27B0"
2237
+ },
2238
+ actionText: {
2239
+ color: "#fff",
2240
+ fontSize: 12
2241
+ }
2242
+ });
2243
+
2244
+ export { DefaultNativeActionExecutor, NativeUIBridgeRegistry, NativeUIBridgeServer, UIBridgeInspector, UIBridgeNativeProvider, UI_BRIDGE_NATIVE_ROUTES, buildTreePath, createNativeActionExecutor, createNativeElementIdentifier, createNativeServer, createServerHandlers, findAllByPattern, findElementByIdentifier, getGlobalRegistry, matchesIdentifier, parseTreePath, resetGlobalRegistry, setGlobalRegistry, useUIBridge, useUIBridgeNative, useUIBridgeNativeOptional, useUIBridgeNativeRequired, useUIBridgeRequired, useUIComponent, useUIComponentAction, useUIElement, useUIElementWithProps };
2245
+ //# sourceMappingURL=index.mjs.map
2246
+ //# sourceMappingURL=index.mjs.map