@qontinui/ui-bridge 0.2.0 → 0.3.1

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