@qontinui/ui-bridge-native 0.6.15 → 0.7.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 (43) hide show
  1. package/README.md +17 -0
  2. package/dist/control/index.js.map +1 -1
  3. package/dist/control/index.mjs.map +1 -1
  4. package/dist/core/index.js +42 -0
  5. package/dist/core/index.js.map +1 -1
  6. package/dist/core/index.mjs +42 -0
  7. package/dist/core/index.mjs.map +1 -1
  8. package/dist/core/registry.d.ts +23 -1
  9. package/dist/core/registry.d.ts.map +1 -1
  10. package/dist/core/types.d.ts +66 -2
  11. package/dist/core/types.d.ts.map +1 -1
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +425 -24
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +421 -25
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/observation/index.d.ts +12 -0
  19. package/dist/observation/index.d.ts.map +1 -0
  20. package/dist/observation/observation.d.ts +233 -0
  21. package/dist/observation/observation.d.ts.map +1 -0
  22. package/dist/react/index.d.ts +4 -0
  23. package/dist/react/index.d.ts.map +1 -1
  24. package/dist/react/index.js +425 -24
  25. package/dist/react/index.js.map +1 -1
  26. package/dist/react/index.mjs +421 -25
  27. package/dist/react/index.mjs.map +1 -1
  28. package/dist/react/routePattern.d.ts +145 -0
  29. package/dist/react/routePattern.d.ts.map +1 -0
  30. package/dist/react/useRouteAwareness.d.ts +106 -0
  31. package/dist/react/useRouteAwareness.d.ts.map +1 -0
  32. package/dist/server/handlers.d.ts.map +1 -1
  33. package/dist/server/index.d.ts +2 -0
  34. package/dist/server/index.d.ts.map +1 -1
  35. package/dist/server/index.js +314 -21
  36. package/dist/server/index.js.map +1 -1
  37. package/dist/server/index.mjs +308 -22
  38. package/dist/server/index.mjs.map +1 -1
  39. package/dist/server/page-health.d.ts +50 -7
  40. package/dist/server/page-health.d.ts.map +1 -1
  41. package/dist/server/types.d.ts +5 -3
  42. package/dist/server/types.d.ts.map +1 -1
  43. package/package.json +1 -1
@@ -313,6 +313,13 @@ function computeVisibility(state, clip) {
313
313
  const onScreen = spansOverlap(rect.left, rect.right, clip.left, clip.right) && spansOverlap(rect.top, rect.bottom, clip.top, clip.bottom);
314
314
  return onScreen ? { visibility: "visible" } : { visibility: "hidden", visibilityReason: "off-screen" };
315
315
  }
316
+ function copyRouteInfo(info) {
317
+ const copy = { ...info };
318
+ if (info.params) copy.params = { ...info.params };
319
+ if (info.queryParams) copy.queryParams = { ...info.queryParams };
320
+ if (info.routeStack) copy.routeStack = [...info.routeStack];
321
+ return copy;
322
+ }
316
323
  function inferActions(type, scrollAncestorId) {
317
324
  const baseActions = scrollAncestorId ? ["focus", "blur", "scrollIntoView"] : ["focus", "blur"];
318
325
  switch (type) {
@@ -377,6 +384,16 @@ var NativeUIBridgeRegistry = class {
377
384
  * already installs.
378
385
  */
379
386
  this.routeProvider = null;
387
+ /**
388
+ * The route TEMPLATE the app last reported through `useRouteAwareness`
389
+ * (via {@link setRouteInfo}), emitted on every snapshot as `page.route`.
390
+ *
391
+ * Deliberately NOT named `routeInfo`: `createSnapshot`'s parameter of that
392
+ * name is the CONCRETE `{currentRoute, segments, activeTab}` read from the
393
+ * route provider. The two must never be confused — the concrete path is
394
+ * user input, and this slot is the router-asserted template.
395
+ */
396
+ this.reportedRoute = void 0;
380
397
  /**
381
398
  * Device pixel ratio used to project `state.layout` (logical dp) into the
382
399
  * physical-pixel `bbox` emitted on each snapshot element. Defaults to `1`
@@ -435,6 +452,22 @@ var NativeUIBridgeRegistry = class {
435
452
  getRouteProvider() {
436
453
  return this.routeProvider;
437
454
  }
455
+ /**
456
+ * Set the route info emitted as `page.route` on every snapshot — the
457
+ * router-asserted TEMPLATE, normally reported by `useRouteAwareness`.
458
+ * Pass `undefined` to clear it (the hook does so on unmount), after which
459
+ * snapshots omit `page` again.
460
+ *
461
+ * The value is copied, so a later mutation by the caller cannot alter what
462
+ * is stored or what an already-emitted snapshot holds.
463
+ */
464
+ setRouteInfo(info) {
465
+ this.reportedRoute = info ? copyRouteInfo(info) : void 0;
466
+ }
467
+ /** Read-only accessor for the reported route info, if any (a copy). */
468
+ getRouteInfo() {
469
+ return this.reportedRoute ? copyRouteInfo(this.reportedRoute) : void 0;
470
+ }
438
471
  /**
439
472
  * Resolve the snapshot's `activeTab`: an explicit `getActiveTab()` on the
440
473
  * route provider wins, otherwise derive it from the Expo Router segments the
@@ -1275,6 +1308,12 @@ var NativeUIBridgeRegistry = class {
1275
1308
  // hosts that wire no route provider.
1276
1309
  ...resolvedRoute.currentRoute ? { route: resolvedRoute.currentRoute } : {},
1277
1310
  ...resolvedRoute.activeTab ? { activeTab: resolvedRoute.activeTab } : {},
1311
+ // The router-asserted route TEMPLATE, spelled as the web SDK's
1312
+ // `snapshot.page.route`. Emitted on the ONE assembly point both route
1313
+ // branches above share (the explicit-`routeInfo` branch the server's
1314
+ // `getSnapshot` override uses, and the provider fallback). Omitted, not
1315
+ // nulled, when unset — the same convention as the aliases above.
1316
+ ...this.reportedRoute ? { page: { route: copyRouteInfo(this.reportedRoute) } } : {},
1278
1317
  registration: this.getRegistrationCoverage()
1279
1318
  };
1280
1319
  if (this.appInfo) {
@@ -1321,6 +1360,9 @@ var NativeUIBridgeRegistry = class {
1321
1360
  }
1322
1361
  }
1323
1362
  }
1363
+ if (this.reportedRoute) {
1364
+ snapshot.page = { route: copyRouteInfo(this.reportedRoute) };
1365
+ }
1324
1366
  }
1325
1367
  return snapshot;
1326
1368
  }
@@ -2339,7 +2381,7 @@ var DefaultNativeActionExecutor = class {
2339
2381
  if (rect && clip && !isEmptyRect(clip) && rect.right > rect.left && rect.bottom > rect.top && rect.top >= clip.top && rect.left >= clip.left && rect.bottom <= clip.bottom && rect.right <= clip.right) {
2340
2382
  return { alreadyVisible: true, scrolled: false };
2341
2383
  }
2342
- const measured = await new Promise(
2384
+ const measured2 = await new Promise(
2343
2385
  (resolve, reject) => {
2344
2386
  let settled = false;
2345
2387
  const timer = setTimeout(() => {
@@ -2376,13 +2418,13 @@ var DefaultNativeActionExecutor = class {
2376
2418
  }
2377
2419
  }
2378
2420
  );
2379
- if (ancestorRect && Number.isFinite(measured.x) && Number.isFinite(measured.width) && measured.x + measured.width > ancestorRect.right - ancestorRect.left + 1) {
2421
+ if (ancestorRect && Number.isFinite(measured2.x) && Number.isFinite(measured2.width) && measured2.x + measured2.width > ancestorRect.right - ancestorRect.left + 1) {
2380
2422
  throw new NativeActionError(
2381
2423
  `scrollIntoView is not supported on element "${element.id}": it is laid out beyond the horizontal extent of its scroll ancestor "${ancestorId}" (sideways overflow, a horizontal container, or a nested horizontal container \u2014 declare that inner container as its scrollAncestorId); only vertical scrolling is supported`,
2382
2424
  "NOT_SUPPORTED"
2383
2425
  );
2384
2426
  }
2385
- container.scrollTo({ y: Math.max(0, measured.y - padding), animated: false });
2427
+ container.scrollTo({ y: Math.max(0, measured2.y - padding), animated: false });
2386
2428
  return { alreadyVisible: false, scrolled: true };
2387
2429
  }
2388
2430
  /**
@@ -3119,7 +3161,219 @@ function createDesignHandlers(registry, viewportProvider) {
3119
3161
  };
3120
3162
  }
3121
3163
 
3164
+ // src/observation/observation.ts
3165
+ var UNKNOWN_CODES = [
3166
+ "app_unreachable",
3167
+ "capability_unavailable_in_build",
3168
+ "producer_failed",
3169
+ "producer_not_run",
3170
+ "input_missing",
3171
+ "below_confidence_floor",
3172
+ "model_reply_unparseable",
3173
+ "needs_multi_frame_input",
3174
+ "stale_input"
3175
+ ];
3176
+ function isUnknownCode(value) {
3177
+ return typeof value === "string" && UNKNOWN_CODES.includes(value);
3178
+ }
3179
+ var ObservationError = class extends Error {
3180
+ constructor(message) {
3181
+ super(message);
3182
+ this.name = "ObservationError";
3183
+ }
3184
+ };
3185
+ function toRfc3339(t) {
3186
+ const d = t instanceof Date ? t : new Date(t);
3187
+ if (Number.isNaN(d.getTime())) {
3188
+ throw new ObservationError(`not a valid timestamp: ${String(t)}`);
3189
+ }
3190
+ return d.toISOString();
3191
+ }
3192
+ function normalizeConfidence(c) {
3193
+ if (c === null || c === void 0 || !Number.isFinite(c)) return null;
3194
+ return Math.min(1, Math.max(0, c));
3195
+ }
3196
+ function fullCoverage(n) {
3197
+ return { considered: n, measured: n, unmeasured: [] };
3198
+ }
3199
+ function assertCount(value, what) {
3200
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
3201
+ throw new ObservationError(`${what} must be a non-negative integer, got ${String(value)}`);
3202
+ }
3203
+ }
3204
+ function assertCoverage(coverage) {
3205
+ if (!coverage || typeof coverage !== "object") {
3206
+ throw new ObservationError("coverage must be an object");
3207
+ }
3208
+ assertCount(coverage.considered, "coverage.considered");
3209
+ assertCount(coverage.measured, "coverage.measured");
3210
+ if (!Array.isArray(coverage.unmeasured)) {
3211
+ throw new ObservationError("coverage.unmeasured must be an array");
3212
+ }
3213
+ coverage.unmeasured.forEach((u, i) => {
3214
+ if (!u || typeof u.dimension !== "string") {
3215
+ throw new ObservationError(`coverage.unmeasured[${i}].dimension must be a string`);
3216
+ }
3217
+ assertCount(u.count, `coverage.unmeasured[${i}].count`);
3218
+ if (!isUnknownCode(u.code)) {
3219
+ throw new ObservationError(
3220
+ `coverage.unmeasured[${i}].code is not an UnknownCode: ${String(u.code)}`
3221
+ );
3222
+ }
3223
+ });
3224
+ }
3225
+ function assertSource(source) {
3226
+ if (source === null) return;
3227
+ if (typeof source !== "object" || Array.isArray(source)) {
3228
+ throw new ObservationError("source must be a JSON object or null");
3229
+ }
3230
+ }
3231
+ var RFC3339 = /^(\d{4})-(\d{2})-(\d{2})[Tt ](\d{2}):(\d{2}):(\d{2})(\.\d+)?([Zz]|[+-](\d{2}):(\d{2}))$/;
3232
+ function isRfc3339(value) {
3233
+ if (typeof value !== "string") return false;
3234
+ const m = RFC3339.exec(value);
3235
+ if (!m) return false;
3236
+ const [y, mo, d, h, mi, s] = [m[1], m[2], m[3], m[4], m[5], m[6]].map(Number);
3237
+ if (mo < 1 || mo > 12 || d < 1 || h > 23 || mi > 59 || s > 60) return false;
3238
+ const leap = y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
3239
+ const daysInMonth = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][mo - 1];
3240
+ if (d > daysInMonth) return false;
3241
+ if (m[9] !== void 0 && (Number(m[9]) > 23 || Number(m[10]) > 59)) return false;
3242
+ return true;
3243
+ }
3244
+ function assertProvenance(prov) {
3245
+ if (!prov || typeof prov !== "object") throw new ObservationError("provenance is required");
3246
+ if (!prov.producer || typeof prov.producer.id !== "string" || typeof prov.producer.version !== "string") {
3247
+ throw new ObservationError("producer must carry a string id and version");
3248
+ }
3249
+ if (!isRfc3339(prov.evaluatedAt)) {
3250
+ throw new ObservationError(
3251
+ `evaluatedAt must be an RFC3339 date-time, got ${String(prov.evaluatedAt)}`
3252
+ );
3253
+ }
3254
+ if (prov.observedAt !== null && !isRfc3339(prov.observedAt)) {
3255
+ throw new ObservationError(
3256
+ `observedAt must be an RFC3339 date-time or null, got ${String(prov.observedAt)}`
3257
+ );
3258
+ }
3259
+ assertCoverage(prov.coverage);
3260
+ if (prov.confidence !== null && (typeof prov.confidence !== "number" || !Number.isFinite(prov.confidence) || prov.confidence < 0 || prov.confidence > 1)) {
3261
+ throw new ObservationError(
3262
+ `confidence must be in [0, 1] or null, got ${String(prov.confidence)}`
3263
+ );
3264
+ }
3265
+ if (prov.cache !== null) {
3266
+ if (typeof prov.cache !== "object" || typeof prov.cache.hit !== "boolean" || !Array.isArray(prov.cache.keyInputs) || !prov.cache.keyInputs.every((k) => typeof k === "string")) {
3267
+ throw new ObservationError(
3268
+ "cache must be { hit: boolean, storedAt, keyInputs: string[] } or null"
3269
+ );
3270
+ }
3271
+ if (prov.cache.storedAt !== null && !isRfc3339(prov.cache.storedAt)) {
3272
+ throw new ObservationError(
3273
+ `cache.storedAt must be an RFC3339 date-time or null, got ${String(prov.cache.storedAt)}`
3274
+ );
3275
+ }
3276
+ }
3277
+ assertSource(prov.source);
3278
+ }
3279
+ function provenance(init) {
3280
+ if (!init.producer || typeof init.producer.id !== "string" || typeof init.producer.version !== "string") {
3281
+ throw new ObservationError("producer must carry a string id and version");
3282
+ }
3283
+ const coverage = init.coverage ?? fullCoverage(0);
3284
+ assertCoverage(coverage);
3285
+ const source = init.source ?? null;
3286
+ assertSource(source);
3287
+ const built = {
3288
+ producer: { id: init.producer.id, version: init.producer.version },
3289
+ observedAt: init.observedAt === void 0 || init.observedAt === null ? null : toRfc3339(init.observedAt),
3290
+ evaluatedAt: toRfc3339(init.evaluatedAt ?? /* @__PURE__ */ new Date()),
3291
+ coverage: {
3292
+ considered: coverage.considered,
3293
+ measured: coverage.measured,
3294
+ unmeasured: coverage.unmeasured.map((u) => ({
3295
+ dimension: u.dimension,
3296
+ count: u.count,
3297
+ code: u.code
3298
+ }))
3299
+ },
3300
+ confidence: normalizeConfidence(init.confidence),
3301
+ cache: init.cache ? {
3302
+ hit: init.cache.hit,
3303
+ storedAt: init.cache.storedAt === null ? null : toRfc3339(init.cache.storedAt),
3304
+ keyInputs: [...init.cache.keyInputs]
3305
+ } : null,
3306
+ source
3307
+ };
3308
+ assertProvenance(built);
3309
+ return built;
3310
+ }
3311
+ function measured(value, prov) {
3312
+ if (value === void 0) {
3313
+ throw new ObservationError(
3314
+ 'measured requires a value; report "nothing there" as absent and "could not look" as unknown'
3315
+ );
3316
+ }
3317
+ assertProvenance(prov);
3318
+ return { status: "measured", value, provenance: prov };
3319
+ }
3320
+ function absent(prov) {
3321
+ assertProvenance(prov);
3322
+ const { considered, measured: measured2, unmeasured } = prov.coverage;
3323
+ if (unmeasured.length > 0) {
3324
+ const dims = unmeasured.map((u) => `${u.dimension} x${u.count} (${u.code})`).join(", ");
3325
+ throw new ObservationError(
3326
+ `cannot assert absent over unmeasured coverage: ${dims}. Report the observation as measured (degraded) or unknown instead.`
3327
+ );
3328
+ }
3329
+ if (considered === 0) {
3330
+ throw new ObservationError(
3331
+ "cannot assert absent over zero considered items: the producer looked at nothing. Report the observation as unknown instead."
3332
+ );
3333
+ }
3334
+ if (measured2 !== considered) {
3335
+ throw new ObservationError(
3336
+ `an \`absent\` observation must have measured every considered item (measured ${measured2} of ${considered}); a partial look is \`measured\` with its gaps in \`coverage.unmeasured\`, never \`absent\``
3337
+ );
3338
+ }
3339
+ return { status: "absent", provenance: prov };
3340
+ }
3341
+ function unknown(code, detail, prov) {
3342
+ if (!isUnknownCode(code)) {
3343
+ throw new ObservationError(`not an UnknownCode: ${String(code)}`);
3344
+ }
3345
+ if (typeof detail !== "string") {
3346
+ throw new ObservationError("unknown requires a string detail");
3347
+ }
3348
+ assertProvenance(prov);
3349
+ return { status: "unknown", unknown: { code, detail }, provenance: prov };
3350
+ }
3351
+ var Observation = {
3352
+ provenance,
3353
+ fullCoverage,
3354
+ measured,
3355
+ absent,
3356
+ unknown
3357
+ };
3358
+
3122
3359
  // src/server/page-health.ts
3360
+ var NATIVE_PAGE_HEALTH_PRODUCER_ID = "sdk-native/page-health";
3361
+ function defaultProducer() {
3362
+ return {
3363
+ id: NATIVE_PAGE_HEALTH_PRODUCER_ID,
3364
+ version: "0.7.0"
3365
+ };
3366
+ }
3367
+ function pageHealthUnknown(code, detail, options = {}) {
3368
+ return Observation.unknown(
3369
+ code,
3370
+ detail,
3371
+ Observation.provenance({
3372
+ producer: options.producer ?? defaultProducer(),
3373
+ evaluatedAt: options.evaluatedAt
3374
+ })
3375
+ );
3376
+ }
3123
3377
  var GRID_SIZE = 20;
3124
3378
  var NAV_TYPES = /* @__PURE__ */ new Set(["button", "heading", "badge", "status-message"]);
3125
3379
  var SKIP_TEXT_TYPES = /* @__PURE__ */ new Set(["button", "link", "tab", "menuitem"]);
@@ -3188,13 +3442,66 @@ function normalizeRect(state, viewport) {
3188
3442
  height: layout.height / viewport.height
3189
3443
  };
3190
3444
  }
3191
- function diagnosePageHealth(elements, viewport) {
3445
+ function diagnosePageHealth(input, options = {}) {
3446
+ const producer = options.producer ?? defaultProducer();
3447
+ try {
3448
+ return observe(input, producer, options.evaluatedAt);
3449
+ } catch (err) {
3450
+ return Observation.unknown(
3451
+ "producer_failed",
3452
+ `page-health producer threw: ${err instanceof Error ? err.message : String(err)}`,
3453
+ Observation.provenance({ producer })
3454
+ );
3455
+ }
3456
+ }
3457
+ function observe(input, producer, evaluatedAt) {
3458
+ const base = {
3459
+ producer,
3460
+ observedAt: input.observedAt,
3461
+ evaluatedAt
3462
+ };
3463
+ if (!Array.isArray(input.elements)) {
3464
+ return Observation.unknown(
3465
+ "input_missing",
3466
+ "the registry handed over no `elements` array, so there was nothing to analyze; this says nothing about the screen itself",
3467
+ Observation.provenance({ ...base, observedAt: null })
3468
+ );
3469
+ }
3470
+ const elements = input.elements;
3471
+ const viewport = input.viewport;
3472
+ if (!viewport || !(viewport.width > 0) || !(viewport.height > 0)) {
3473
+ return Observation.unknown(
3474
+ "input_missing",
3475
+ viewport ? `the device viewport is degenerate (${viewport.width}x${viewport.height}), so no element can be placed on screen \u2014 pass \`body.viewport\` or wire \`viewportProvider\`` : "the device viewport is unknown, so no element can be placed on screen \u2014 pass `body.viewport` or wire `viewportProvider`",
3476
+ Observation.provenance(base)
3477
+ );
3478
+ }
3479
+ if (elements.length === 0 && (input.registeredComponents ?? 0) === 0) {
3480
+ return Observation.unknown(
3481
+ "producer_not_run",
3482
+ "the registry reports zero elements and zero components \u2014 nothing has registered yet, so there was nothing to look at",
3483
+ Observation.provenance(base)
3484
+ );
3485
+ }
3486
+ return analyze(elements, viewport, base);
3487
+ }
3488
+ function analyze(elements, viewport, base) {
3192
3489
  const findings = [];
3193
- const projected = elements.map((el) => ({
3194
- el,
3195
- rect: el.state.visible ? normalizeRect(el.state, viewport) : null
3196
- }));
3197
- const visible = projected.filter((p) => p.rect !== null);
3490
+ const considered = elements.filter((el) => el.state.visible);
3491
+ const visible = considered.flatMap((el) => {
3492
+ const rect = normalizeRect(el.state, viewport);
3493
+ return rect ? [{ el, rect }] : [];
3494
+ });
3495
+ const withoutGeometry = considered.length - visible.length;
3496
+ const unmeasured = withoutGeometry > 0 ? [{ dimension: "geometry", count: withoutGeometry, code: "input_missing" }] : [];
3497
+ const coverage = { considered: considered.length, measured: visible.length, unmeasured };
3498
+ if (considered.length > 0 && visible.length === 0) {
3499
+ return Observation.unknown(
3500
+ "input_missing",
3501
+ `all ${considered.length} visible element(s) have no measured layout yet, so spatial coverage, layout regions and visual anomalies cannot be measured`,
3502
+ Observation.provenance({ ...base, coverage })
3503
+ );
3504
+ }
3198
3505
  const grid = Array.from(
3199
3506
  { length: GRID_SIZE },
3200
3507
  () => Array.from({ length: GRID_SIZE }, () => false)
@@ -3349,13 +3656,17 @@ function diagnosePageHealth(elements, viewport) {
3349
3656
  const heatmap = grid.map(
3350
3657
  (row) => row.map((cell) => cell ? "#" : ".").join("")
3351
3658
  );
3352
- return {
3353
- summary: worstSeverity(findings),
3354
- findings,
3355
- heatmap,
3356
- element_count: elements.length,
3357
- visible_count: visible.length
3358
- };
3659
+ return Observation.measured(
3660
+ {
3661
+ summary: worstSeverity(findings),
3662
+ findings,
3663
+ heatmap,
3664
+ element_count: elements.length,
3665
+ visible_count: visible.length
3666
+ },
3667
+ // A deduction over the registry, not an estimate.
3668
+ Observation.provenance({ ...base, coverage })
3669
+ );
3359
3670
  }
3360
3671
 
3361
3672
  // src/server/handlers.ts
@@ -3803,13 +4114,30 @@ function createServerHandlers(registry, executor, config) {
3803
4114
  },
3804
4115
  getPageHealth: async (ctx) => {
3805
4116
  const bodyViewport = ctx.body?.viewport;
3806
- const viewport = bodyViewport ?? config?.viewportProvider?.() ?? { width: 0, height: 0 };
3807
- const elements = registry.getAllElements().map((e) => ({
3808
- type: e.type,
3809
- state: e.getState()
3810
- }));
3811
- const report = diagnosePageHealth(elements, viewport);
3812
- return success2(report);
4117
+ let viewport;
4118
+ try {
4119
+ viewport = bodyViewport ?? config?.viewportProvider?.() ?? null;
4120
+ } catch {
4121
+ viewport = null;
4122
+ }
4123
+ const observedAt = Date.now();
4124
+ let elements;
4125
+ let registeredComponents;
4126
+ try {
4127
+ elements = registry.getAllElements().map((e) => ({
4128
+ type: e.type,
4129
+ state: e.getState()
4130
+ }));
4131
+ registeredComponents = registry.getAllComponents().length;
4132
+ } catch (err) {
4133
+ return success2(
4134
+ pageHealthUnknown(
4135
+ "producer_failed",
4136
+ `could not read the registry: ${err instanceof Error ? err.message : String(err)}`
4137
+ )
4138
+ );
4139
+ }
4140
+ return success2(diagnosePageHealth({ elements, registeredComponents, viewport, observedAt }));
3813
4141
  },
3814
4142
  // Workflows
3815
4143
  getWorkflows: async () => {
@@ -4313,7 +4641,7 @@ function createServerHandlers(registry, executor, config) {
4313
4641
  };
4314
4642
  if (config?.appInfo) {
4315
4643
  response.uiBridge = {
4316
- version: "0.6.15",
4644
+ version: "0.7.0",
4317
4645
  ...config.appInfo,
4318
4646
  capabilities: ["elements", "components", "actions", "design"],
4319
4647
  elementCount: stats.elements,
@@ -7875,11 +8203,84 @@ function State(props) {
7875
8203
  function TransitionTo(props) {
7876
8204
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
7877
8205
  }
8206
+ function effectiveInfo(info, unmatched) {
8207
+ return unmatched ? { ...info, pattern: null, params: void 0 } : info;
8208
+ }
8209
+ function useRouteAwareness(info, options = {}) {
8210
+ const bridge = useUIBridgeNativeOptional();
8211
+ const unmatched = options.unmatched === true;
8212
+ const infoRef = react.useRef(info);
8213
+ infoRef.current = info;
8214
+ const pattern = info.pattern;
8215
+ const patternSource = info.patternSource;
8216
+ const paramsKey = info.params ? JSON.stringify(info.params) : "";
8217
+ const queryParamsKey = info.queryParams ? JSON.stringify(info.queryParams) : "";
8218
+ const routeStackKey = info.routeStack?.join(",");
8219
+ react.useEffect(() => {
8220
+ if (!bridge) return;
8221
+ const registry = bridge.registry;
8222
+ registry.setRouteInfo(effectiveInfo(infoRef.current, unmatched));
8223
+ return () => {
8224
+ registry.setRouteInfo(void 0);
8225
+ };
8226
+ }, [bridge, unmatched, pattern, patternSource, paramsKey, queryParamsKey, routeStackKey]);
8227
+ }
8228
+
8229
+ // src/react/routePattern.ts
8230
+ function focusedIndex(state, routeCount) {
8231
+ if (state.index !== void 0) return state.index;
8232
+ return typeof state.type === "string" && state.type !== "stack" ? 0 : routeCount - 1;
8233
+ }
8234
+ function isRouteIdentifier(value) {
8235
+ return typeof value === "string" && value.length > 0 && !value.includes("/") && !value.includes("?") && !value.includes("#");
8236
+ }
8237
+ function isExpoRouterUnmatched(segments) {
8238
+ return segments.some((s) => typeof s === "string" && s.startsWith("+"));
8239
+ }
8240
+ function expoRouterPattern(segments) {
8241
+ if (!Array.isArray(segments)) return null;
8242
+ for (const segment of segments) {
8243
+ if (!isRouteIdentifier(segment)) return null;
8244
+ if (segment.startsWith("+")) return null;
8245
+ }
8246
+ return "/" + segments.join("/");
8247
+ }
8248
+ function expoRouterRouteStack(segments) {
8249
+ if (expoRouterPattern(segments) === null) return void 0;
8250
+ const stack = ["/"];
8251
+ for (let depth = 1; depth <= segments.length; depth++) {
8252
+ stack.push("/" + segments.slice(0, depth).join("/"));
8253
+ }
8254
+ return stack;
8255
+ }
8256
+ function reactNavigationPattern(state, options = {}) {
8257
+ const names = [];
8258
+ let level = state ?? void 0;
8259
+ while (level) {
8260
+ const routes = level.routes;
8261
+ if (!Array.isArray(routes) || routes.length === 0) return null;
8262
+ const index = focusedIndex(level, routes.length);
8263
+ if (!Number.isInteger(index) || index < 0 || index >= routes.length) return null;
8264
+ const route = routes[index];
8265
+ if (!route || !isRouteIdentifier(route.name)) return null;
8266
+ names.push(route.name);
8267
+ level = route.state;
8268
+ }
8269
+ if (names.length === 0) return null;
8270
+ const leaf = names[names.length - 1];
8271
+ if (options.notFoundRouteNames?.includes(leaf)) return null;
8272
+ return "/" + names.join("/");
8273
+ }
7878
8274
 
7879
8275
  exports.State = State;
7880
8276
  exports.TransitionTo = TransitionTo;
7881
8277
  exports.UIBridgeNativeProvider = UIBridgeNativeProvider;
8278
+ exports.expoRouterPattern = expoRouterPattern;
8279
+ exports.expoRouterRouteStack = expoRouterRouteStack;
8280
+ exports.isExpoRouterUnmatched = isExpoRouterUnmatched;
8281
+ exports.reactNavigationPattern = reactNavigationPattern;
7882
8282
  exports.useAutoRegister = useAutoRegister;
8283
+ exports.useRouteAwareness = useRouteAwareness;
7883
8284
  exports.useToastRecorder = useToastRecorder;
7884
8285
  exports.useUIBridge = useUIBridge;
7885
8286
  exports.useUIBridgeModal = useUIBridgeModal;