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