@docyrus/signin 0.12.0 → 0.14.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.
package/README.md CHANGED
@@ -254,6 +254,77 @@ Pass props to `DocyrusAuthProvider` to override defaults:
254
254
  | `ssr` | `boolean` | `false` | Sync access token to cookie for server components |
255
255
  | `ssrCookieKey` | `string` | `docyrus-token` | Cookie name for SSR token sync |
256
256
  | `syncRouteToHost` | `boolean` | `false` | Iframe mode: post `route-change` to the host on every history change |
257
+ | `enableGuidyBridge` | `boolean` | `false` | Iframe mode: let the host assistant (Guidy) scan, highlight, and click this app's visible UI (see below) |
258
+ | `guidyRoutes` | `GuidyRoute[]` | `undefined` | Iframe mode: routes Guidy may navigate the user to inside this app (see below). Requires `enableGuidyBridge` |
259
+
260
+ ## Guidy Bridge (host-driven guidance)
261
+
262
+ When an app runs embedded in the Docyrus shell, the host AI assistant (Guidy)
263
+ can guide users _through the app_ — pointing at and clicking real in-app
264
+ buttons — once the app opts in:
265
+
266
+ ```tsx
267
+ <DocyrusAuthProvider apiUrl="..." clientId="..." enableGuidyBridge>
268
+ <App />
269
+ </DocyrusAuthProvider>
270
+ ```
271
+
272
+ This starts a small runtime (`GuidyBridge`) that, in iframe mode only:
273
+
274
+ - pushes the app's clickable inventory (`a[id]` / `button[id]` that are visible
275
+ and labeled) to the host on mount, route change, and DOM mutation;
276
+ - on a host `guidy:point`, scrolls to, highlights, optionally annotates, and
277
+ optionally clicks the target element, then acknowledges.
278
+
279
+ It is opt-in and intentionally narrow: it only exposes already-visible
280
+ interactive elements and only runs a fixed command vocabulary — **no arbitrary
281
+ script is accepted from the host**. All traffic rides the same origin-validated
282
+ postMessage channel as auth.
283
+
284
+ ```text
285
+ App → Host: { type: 'guidy:elements', path, elements: [{ id, label, tag }] }
286
+ App → Host: { type: 'guidy:routes', routes: [{ path, label }] }
287
+ Host → App: { type: 'guidy:scan' } // re-request inventory + routes
288
+ Host → App: { type: 'guidy:point', id, click?, message? } // point / click / annotate
289
+ App → Host: { type: 'guidy:point-ack', id, ok }
290
+ ```
291
+
292
+ Give the elements Guidy should reach a stable `id` and an accessible label
293
+ (`aria-label`, text content, or `title`).
294
+
295
+ ### In-app navigation (routes)
296
+
297
+ Elements are auto-discovered from the DOM; routes are not, so the app declares
298
+ which pages Guidy may send the user to. The host merges them into Guidy's
299
+ navigation tree as deep links and drives them through the existing host→app
300
+ `navigation` message. Declare them statically:
301
+
302
+ ```tsx
303
+ <DocyrusAuthProvider
304
+ apiUrl="..."
305
+ clientId="..."
306
+ enableGuidyBridge
307
+ guidyRoutes={[
308
+ { path: "/leads", label: "Leads" },
309
+ { path: "/leads/new", label: "New Lead" }
310
+ ]}
311
+ >
312
+ <App />
313
+ </DocyrusAuthProvider>
314
+ ```
315
+
316
+ …or dynamically (e.g. when routes depend on permissions) with the hook:
317
+
318
+ ```tsx
319
+ import { useDocyrusGuidyRoutes } from "@docyrus/signin"
320
+
321
+ useDocyrusGuidyRoutes(visibleRoutes) // re-syncs whenever the array changes
322
+ ```
323
+
324
+ Driving a route requires the app to handle inbound host navigation — wire
325
+ `useDocyrusHostNavigation` (or `syncRouteToHost`) so the deep link reaches your
326
+ router. `path` is app-internal (e.g. `/leads`); the host prefixes it with the
327
+ app's mount path.
257
328
 
258
329
  ## Hooks / Composables
259
330
 
@@ -1,5 +1,5 @@
1
1
  import { OAuth2Tokens, RestApiClient } from '@docyrus/api-client';
2
- import { D as DocyrusAuthConfig, a as AuthMode, c as AuthStatus, g as DocyrusUser, R as RouteChangePayload, H as HostNavigationHandler, h as HostNotificationHandler, f as DocyrusRole, P as PermissionConfig } from './types-DjG8tL1X.js';
2
+ import { D as DocyrusAuthConfig, a as AuthMode, c as AuthStatus, g as DocyrusUser, G as GuidyRoute, R as RouteChangePayload, H as HostNavigationHandler, h as HostNotificationHandler, f as DocyrusRole, P as PermissionConfig } from './types-D4ZAVj-B.js';
3
3
 
4
4
  type AuthStateListener = (state: {
5
5
  status: AuthStatus;
@@ -21,6 +21,7 @@ declare class AuthManager {
21
21
  private user;
22
22
  private standaloneAuth;
23
23
  private iframeAuth;
24
+ private guidyBridge;
24
25
  private reactNativeAuth;
25
26
  private tokenRefreshTimer;
26
27
  private listeners;
@@ -56,6 +57,16 @@ declare class AuthManager {
56
57
  * Status remains 'loading' until the host sends the first signin message.
57
58
  */
58
59
  private initializeIframeMode;
60
+ /**
61
+ * Start the Guidy bridge runtime: report the app's clickable inventory to
62
+ * the host and execute host scan/point/click commands. Iframe mode only.
63
+ */
64
+ private startGuidyBridge;
65
+ /**
66
+ * Iframe mode: replace the routes the Guidy bridge advertises to the host.
67
+ * No-op unless the bridge is running (`enableGuidyBridge`).
68
+ */
69
+ setGuidyRoutes(routes: GuidyRoute[]): void;
59
70
  /**
60
71
  * Iframe/WebView mode: start auto-syncing the embedded app's route
61
72
  * to the host. Patches history methods and listens for popstate /
@@ -1,7 +1,7 @@
1
- export { A as AuthManager, e as AuthStateListener, D as DEFAULT_API_URL, c as DEFAULT_CALLBACK_PATH, a as DEFAULT_OAUTH_SCOPES, g as getAllRoles, h as hasPermission, b as hasRole } from './constants-DuNDcs9I.js';
1
+ export { A as AuthManager, e as AuthStateListener, D as DEFAULT_API_URL, c as DEFAULT_CALLBACK_PATH, a as DEFAULT_OAUTH_SCOPES, g as getAllRoles, h as hasPermission, b as hasRole } from './constants-DtyJKJgJ.js';
2
2
  import { OAuth2Tokens } from '@docyrus/api-client';
3
- import { D as DocyrusAuthConfig, R as RouteChangePayload, H as HostNavigationHandler, h as HostNotificationHandler, a as AuthMode } from './types-DjG8tL1X.js';
4
- export { A as AclOperation, i as AppRouteChangeMessage, c as AuthStatus, d as DocyrusAclRule, e as DocyrusAuthContextValue, j as DocyrusNotification, f as DocyrusRole, g as DocyrusUser, k as HostNavigationMessage, l as HostNotificationMessage, m as HostSignInMessage, P as PermissionConfig, T as TokenRefreshRequestMessage } from './types-DjG8tL1X.js';
3
+ import { D as DocyrusAuthConfig, R as RouteChangePayload, H as HostNavigationHandler, h as HostNotificationHandler, k as GuidyCommandHandler, v as AppToHostMessage, n as GuidyElementsMessage, q as GuidyRoutesMessage, o as GuidyPointAckMessage, G as GuidyRoute, l as GuidyCommandMessage, a as AuthMode } from './types-D4ZAVj-B.js';
4
+ export { A as AclOperation, i as AppRouteChangeMessage, c as AuthStatus, d as DocyrusAclRule, e as DocyrusAuthContextValue, j as DocyrusNotification, f as DocyrusRole, g as DocyrusUser, m as GuidyElement, p as GuidyPointMessage, r as GuidyScanMessage, s as HostNavigationMessage, t as HostNotificationMessage, u as HostSignInMessage, P as PermissionConfig, T as TokenRefreshRequestMessage } from './types-D4ZAVj-B.js';
5
5
 
6
6
  /**
7
7
  * Standalone OAuth2 authorization code flow with PKCE via page redirect.
@@ -80,6 +80,7 @@ declare class IframeAuth {
80
80
  private onTokensReceived;
81
81
  private navigationHandlers;
82
82
  private notificationHandlers;
83
+ private guidyHandlers;
83
84
  private routeSyncEnabled;
84
85
  private originalPushState;
85
86
  private originalReplaceState;
@@ -118,6 +119,17 @@ declare class IframeAuth {
118
119
  * Returns an unsubscribe function.
119
120
  */
120
121
  onNotification(handler: HostNotificationHandler): () => void;
122
+ /**
123
+ * Subscribe to host `guidy:*` command messages (point/scan).
124
+ * Returns an unsubscribe function. Used by the Guidy bridge runtime.
125
+ */
126
+ onGuidyCommand(handler: GuidyCommandHandler): () => void;
127
+ /**
128
+ * Post an app → host message over the same validated channel used for
129
+ * route-change and token-refresh. Used by the Guidy bridge to push its
130
+ * element inventory and point acknowledgements.
131
+ */
132
+ sendToHost(message: AppToHostMessage): void;
121
133
  /**
122
134
  * Request fresh tokens from the host.
123
135
  * Posts a "token-refresh-request" to the host, then waits for
@@ -129,12 +141,68 @@ declare class IframeAuth {
129
141
  requestTokenRefresh(): Promise<OAuth2Tokens>;
130
142
  private isOriginAllowed;
131
143
  private handleMessage;
144
+ private handleGuidyCommand;
132
145
  private handleSignin;
133
146
  private handleNavigation;
134
147
  private handleNotification;
135
148
  private rejectPendingRefresh;
136
149
  }
137
150
 
151
+ /** Post an app → host message (elements, routes, or a point ack). */
152
+ type GuidyBridgeSender = (message: GuidyElementsMessage | GuidyRoutesMessage | GuidyPointAckMessage) => void;
153
+ /**
154
+ * Runs inside an embedded Docyrus app and lets the host assistant (Guidy)
155
+ * inspect and drive the app's visible UI over the existing postMessage
156
+ * channel.
157
+ *
158
+ * It only ever exposes labels/ids of already-visible interactive elements and
159
+ * only executes a fixed command vocabulary (scan / point / click) — the same
160
+ * exposure profile the host assistant already has on its own chrome. No
161
+ * arbitrary script is accepted from the host.
162
+ *
163
+ * Protocol (paired with the host's ExternalAppManager):
164
+ * - App → Host: `guidy:elements` (pushed on start, route change, mutation)
165
+ * - App → Host: `guidy:routes` (pushed on start and when routes change)
166
+ * - Host → App: `guidy:scan` → app re-posts `guidy:elements` + `guidy:routes`
167
+ * - Host → App: `guidy:point` → app scrolls/highlights/(clicks), then
168
+ * - App → Host: `guidy:point-ack`
169
+ */
170
+ declare class GuidyBridge {
171
+ private send;
172
+ private routes;
173
+ private started;
174
+ private observer;
175
+ private scanTimer;
176
+ private routeListener;
177
+ private highlightTimer;
178
+ private clickTimer;
179
+ private annotationTimer;
180
+ constructor(send: GuidyBridgeSender, routes?: GuidyRoute[]);
181
+ /** Replace the declared navigable routes and re-post them to the host. */
182
+ setRoutes(routes: GuidyRoute[]): void;
183
+ /**
184
+ * Begin reporting the element inventory and watching for changes.
185
+ * Idempotent. No-op outside a browser document.
186
+ */
187
+ start(): void;
188
+ /** Stop watching and tear down any injected overlay. Idempotent. */
189
+ stop(): void;
190
+ /** Dispatch a host `guidy:*` command. Wired to `IframeAuth.onGuidyCommand`. */
191
+ handleCommand(message: GuidyCommandMessage): void;
192
+ /** Collect every visible anchor/button that exposes an id and a label. */
193
+ private collectElements;
194
+ private postElements;
195
+ private postRoutes;
196
+ private scheduleScan;
197
+ private handlePoint;
198
+ private ensureStyle;
199
+ private highlight;
200
+ private clearHighlight;
201
+ private annotate;
202
+ private clearAnnotation;
203
+ private clearTimer;
204
+ }
205
+
138
206
  /**
139
207
  * Detect whether the app is inside an iframe from a trusted *.docyrus.app host
140
208
  * or running as a standalone page.
@@ -144,4 +212,4 @@ declare class IframeAuth {
144
212
  */
145
213
  declare function detectAuthMode(allowedOrigins?: string[], allowedPattern?: RegExp): AuthMode;
146
214
 
147
- export { AuthMode, DocyrusAuthConfig, HostNavigationHandler, HostNotificationHandler, IframeAuth, RouteChangePayload, StandaloneOAuth2Auth, detectAuthMode };
215
+ export { AuthMode, DocyrusAuthConfig, GuidyBridge, GuidyCommandHandler, GuidyCommandMessage, GuidyElementsMessage, GuidyPointAckMessage, GuidyRoute, GuidyRoutesMessage, HostNavigationHandler, HostNotificationHandler, IframeAuth, RouteChangePayload, StandaloneOAuth2Auth, detectAuthMode };
@@ -167,6 +167,7 @@ var IframeAuth = class {
167
167
  onTokensReceived = null;
168
168
  navigationHandlers = /* @__PURE__ */ new Set();
169
169
  notificationHandlers = /* @__PURE__ */ new Set();
170
+ guidyHandlers = /* @__PURE__ */ new Set();
170
171
  routeSyncEnabled = false;
171
172
  originalPushState = null;
172
173
  originalReplaceState = null;
@@ -199,6 +200,7 @@ var IframeAuth = class {
199
200
  this.rejectPendingRefresh("IframeAuth stopped");
200
201
  this.navigationHandlers.clear();
201
202
  this.notificationHandlers.clear();
203
+ this.guidyHandlers.clear();
202
204
  this.teardownRouteSync();
203
205
  }
204
206
  /**
@@ -290,6 +292,25 @@ var IframeAuth = class {
290
292
  this.notificationHandlers.delete(handler);
291
293
  };
292
294
  }
295
+ /**
296
+ * Subscribe to host `guidy:*` command messages (point/scan).
297
+ * Returns an unsubscribe function. Used by the Guidy bridge runtime.
298
+ */
299
+ onGuidyCommand(handler) {
300
+ this.guidyHandlers.add(handler);
301
+ return () => {
302
+ this.guidyHandlers.delete(handler);
303
+ };
304
+ }
305
+ /**
306
+ * Post an app → host message over the same validated channel used for
307
+ * route-change and token-refresh. Used by the Guidy bridge to push its
308
+ * element inventory and point acknowledgements.
309
+ */
310
+ sendToHost(message) {
311
+ if (this.stopped) return;
312
+ postToHost(message);
313
+ }
293
314
  /**
294
315
  * Request fresh tokens from the host.
295
316
  * Posts a "token-refresh-request" to the host, then waits for
@@ -342,6 +363,19 @@ var IframeAuth = class {
342
363
  }
343
364
  if (data.type === "notification") {
344
365
  this.handleNotification(data);
366
+ return;
367
+ }
368
+ if (data.type === "guidy:point" || data.type === "guidy:scan") {
369
+ this.handleGuidyCommand(data);
370
+ }
371
+ }
372
+ handleGuidyCommand(message) {
373
+ for (const handler of this.guidyHandlers) {
374
+ try {
375
+ handler(message);
376
+ } catch (err) {
377
+ console.warn("[docyrus-signin] guidy command handler threw:", err);
378
+ }
345
379
  }
346
380
  }
347
381
  handleSignin(signinData) {
@@ -391,6 +425,250 @@ var IframeAuth = class {
391
425
  }
392
426
  };
393
427
 
428
+ // src/core/guidy-bridge.ts
429
+ var GUIDY_INTERNAL_PREFIX = "guidy-";
430
+ var HIGHLIGHT_CLASS = "guidy-bridge-highlight";
431
+ var HIGHLIGHT_STYLE_ID = "guidy-bridge-style";
432
+ var ANNOTATION_ID = "guidy-bridge-annotation";
433
+ var HIGHLIGHT_DURATION_MS = 5200;
434
+ var SCAN_DEBOUNCE_MS = 250;
435
+ var CLICK_DELAY_MS = 450;
436
+ function elementLabel(node) {
437
+ const aria = node.getAttribute("aria-label")?.trim();
438
+ if (aria) return aria;
439
+ const text = node.textContent?.replace(/\s+/g, " ").trim();
440
+ if (text) return text;
441
+ return node.getAttribute("title")?.trim() ?? "";
442
+ }
443
+ function isVisible(node) {
444
+ const rect = node.getBoundingClientRect();
445
+ if (rect.width === 0 && rect.height === 0) return false;
446
+ const style = window.getComputedStyle(node);
447
+ return style.visibility !== "hidden" && style.display !== "none";
448
+ }
449
+ var GuidyBridge = class {
450
+ send;
451
+ routes;
452
+ started = false;
453
+ observer = null;
454
+ scanTimer = null;
455
+ routeListener = null;
456
+ highlightTimer = null;
457
+ clickTimer = null;
458
+ annotationTimer = null;
459
+ constructor(send, routes = []) {
460
+ this.send = send;
461
+ this.routes = routes;
462
+ }
463
+ /** Replace the declared navigable routes and re-post them to the host. */
464
+ setRoutes(routes) {
465
+ this.routes = routes;
466
+ this.postRoutes();
467
+ }
468
+ /**
469
+ * Begin reporting the element inventory and watching for changes.
470
+ * Idempotent. No-op outside a browser document.
471
+ */
472
+ start() {
473
+ if (this.started || typeof document === "undefined") return;
474
+ this.started = true;
475
+ this.ensureStyle();
476
+ this.postElements();
477
+ this.postRoutes();
478
+ this.observer = new MutationObserver(() => this.scheduleScan());
479
+ this.observer.observe(document.body, {
480
+ childList: true,
481
+ subtree: true,
482
+ attributes: true,
483
+ attributeFilter: [
484
+ "id",
485
+ "hidden",
486
+ "aria-label",
487
+ "title",
488
+ "style"
489
+ ]
490
+ });
491
+ this.routeListener = () => this.scheduleScan();
492
+ window.addEventListener("popstate", this.routeListener);
493
+ window.addEventListener("hashchange", this.routeListener);
494
+ }
495
+ /** Stop watching and tear down any injected overlay. Idempotent. */
496
+ stop() {
497
+ if (!this.started) return;
498
+ this.started = false;
499
+ this.observer?.disconnect();
500
+ this.observer = null;
501
+ if (this.routeListener) {
502
+ window.removeEventListener("popstate", this.routeListener);
503
+ window.removeEventListener("hashchange", this.routeListener);
504
+ this.routeListener = null;
505
+ }
506
+ this.clearTimer("scanTimer");
507
+ this.clearTimer("highlightTimer");
508
+ this.clearTimer("clickTimer");
509
+ this.clearTimer("annotationTimer");
510
+ this.clearHighlight();
511
+ this.clearAnnotation();
512
+ }
513
+ /** Dispatch a host `guidy:*` command. Wired to `IframeAuth.onGuidyCommand`. */
514
+ handleCommand(message) {
515
+ if (message.type === "guidy:scan") {
516
+ this.postElements();
517
+ this.postRoutes();
518
+ return;
519
+ }
520
+ if (message.type === "guidy:point") {
521
+ this.handlePoint(message);
522
+ }
523
+ }
524
+ /** Collect every visible anchor/button that exposes an id and a label. */
525
+ collectElements() {
526
+ if (typeof document === "undefined") return [];
527
+ const nodes = document.querySelectorAll("a[id], button[id]");
528
+ const seen = /* @__PURE__ */ new Set();
529
+ const result = [];
530
+ nodes.forEach((node) => {
531
+ const { id } = node;
532
+ if (!id || id.startsWith(GUIDY_INTERNAL_PREFIX) || seen.has(id)) return;
533
+ if (!isVisible(node)) return;
534
+ const label = elementLabel(node);
535
+ if (!label) return;
536
+ seen.add(id);
537
+ result.push({
538
+ id,
539
+ label,
540
+ tag: node.tagName.toLowerCase() === "a" ? "a" : "button"
541
+ });
542
+ });
543
+ return result;
544
+ }
545
+ postElements() {
546
+ if (!this.started) return;
547
+ const path = typeof window === "undefined" ? "" : window.location.pathname;
548
+ this.send({
549
+ type: "guidy:elements",
550
+ path,
551
+ elements: this.collectElements()
552
+ });
553
+ }
554
+ postRoutes() {
555
+ if (!this.started) return;
556
+ this.send({ type: "guidy:routes", routes: this.routes });
557
+ }
558
+ scheduleScan() {
559
+ if (this.scanTimer) return;
560
+ this.scanTimer = setTimeout(() => {
561
+ this.scanTimer = null;
562
+ this.postElements();
563
+ }, SCAN_DEBOUNCE_MS);
564
+ }
565
+ handlePoint(message) {
566
+ const element = typeof document === "undefined" ? null : document.getElementById(message.id);
567
+ if (!element) {
568
+ this.send({ type: "guidy:point-ack", id: message.id, ok: false });
569
+ return;
570
+ }
571
+ element.scrollIntoView({ block: "center", behavior: "smooth" });
572
+ this.highlight(element);
573
+ if (message.message) {
574
+ this.annotate(element, message.message);
575
+ }
576
+ if (message.click) {
577
+ this.clearTimer("clickTimer");
578
+ this.clickTimer = setTimeout(() => {
579
+ this.clickTimer = null;
580
+ element.click();
581
+ }, CLICK_DELAY_MS);
582
+ }
583
+ this.send({ type: "guidy:point-ack", id: message.id, ok: true });
584
+ }
585
+ ensureStyle() {
586
+ if (typeof document === "undefined") return;
587
+ if (document.getElementById(HIGHLIGHT_STYLE_ID)) return;
588
+ const style = document.createElement("style");
589
+ style.id = HIGHLIGHT_STYLE_ID;
590
+ style.textContent = `
591
+ .${HIGHLIGHT_CLASS} {
592
+ outline: 2px solid #3b82f6 !important;
593
+ outline-offset: 2px;
594
+ border-radius: 8px;
595
+ animation: guidy-bridge-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
596
+ }
597
+ @keyframes guidy-bridge-ping {
598
+ 0% {
599
+ box-shadow: 0 0 0 0 color-mix(in srgb, #3b82f6 50%, transparent);
600
+ }
601
+ 75%, 100% {
602
+ box-shadow: 0 0 0 10px color-mix(in srgb, #3b82f6 0%, transparent);
603
+ }
604
+ }
605
+ #${ANNOTATION_ID} {
606
+ position: fixed;
607
+ z-index: 2147483647;
608
+ max-width: 240px;
609
+ padding: 8px 12px;
610
+ border-radius: 10px;
611
+ background: #111827;
612
+ color: #f9fafb;
613
+ font: 13px/1.4 system-ui, -apple-system, sans-serif;
614
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
615
+ pointer-events: none;
616
+ }
617
+ `;
618
+ document.head.appendChild(style);
619
+ }
620
+ highlight(element) {
621
+ this.clearTimer("highlightTimer");
622
+ this.clearHighlight();
623
+ element.classList.add(HIGHLIGHT_CLASS);
624
+ this.highlightTimer = setTimeout(() => {
625
+ this.highlightTimer = null;
626
+ this.clearHighlight();
627
+ }, HIGHLIGHT_DURATION_MS);
628
+ }
629
+ clearHighlight() {
630
+ if (typeof document === "undefined") return;
631
+ document.querySelectorAll(`.${HIGHLIGHT_CLASS}`).forEach((node) => node.classList.remove(HIGHLIGHT_CLASS));
632
+ }
633
+ annotate(element, message) {
634
+ if (typeof document === "undefined") return;
635
+ this.clearTimer("annotationTimer");
636
+ this.clearAnnotation();
637
+ const bubble = document.createElement("div");
638
+ bubble.id = ANNOTATION_ID;
639
+ bubble.textContent = message;
640
+ document.body.appendChild(bubble);
641
+ const rect = element.getBoundingClientRect();
642
+ const bubbleRect = bubble.getBoundingClientRect();
643
+ const gap = 10;
644
+ let top = rect.bottom + gap;
645
+ if (top + bubbleRect.height > window.innerHeight) {
646
+ top = Math.max(gap, rect.top - bubbleRect.height - gap);
647
+ }
648
+ const left = Math.min(
649
+ Math.max(gap, rect.left),
650
+ window.innerWidth - bubbleRect.width - gap
651
+ );
652
+ bubble.style.top = `${Math.round(top)}px`;
653
+ bubble.style.left = `${Math.round(left)}px`;
654
+ this.annotationTimer = setTimeout(() => {
655
+ this.annotationTimer = null;
656
+ this.clearAnnotation();
657
+ }, HIGHLIGHT_DURATION_MS);
658
+ }
659
+ clearAnnotation() {
660
+ if (typeof document === "undefined") return;
661
+ document.getElementById(ANNOTATION_ID)?.remove();
662
+ }
663
+ clearTimer(key) {
664
+ const timer = this[key];
665
+ if (timer) {
666
+ clearTimeout(timer);
667
+ this[key] = null;
668
+ }
669
+ }
670
+ };
671
+
394
672
  // src/core/sso-auth.ts
395
673
  var SsoAuth = class {
396
674
  config;
@@ -551,6 +829,7 @@ var AuthManager = class {
551
829
  user = null;
552
830
  standaloneAuth = null;
553
831
  iframeAuth = null;
832
+ guidyBridge = null;
554
833
  reactNativeAuth = null;
555
834
  tokenRefreshTimer = null;
556
835
  listeners = /* @__PURE__ */ new Set();
@@ -715,6 +994,31 @@ var AuthManager = class {
715
994
  if (this.config.syncRouteToHost) {
716
995
  this.iframeAuth.enableRouteSync();
717
996
  }
997
+ if (this.config.enableGuidyBridge) {
998
+ this.startGuidyBridge();
999
+ }
1000
+ }
1001
+ /**
1002
+ * Start the Guidy bridge runtime: report the app's clickable inventory to
1003
+ * the host and execute host scan/point/click commands. Iframe mode only.
1004
+ */
1005
+ startGuidyBridge() {
1006
+ if (!this.iframeAuth || this.guidyBridge) return;
1007
+ const bridge = new GuidyBridge(
1008
+ (message) => this.iframeAuth?.sendToHost(message),
1009
+ this.config.guidyRoutes ?? []
1010
+ );
1011
+ this.iframeAuth.onGuidyCommand((message) => bridge.handleCommand(message));
1012
+ bridge.start();
1013
+ this.guidyBridge = bridge;
1014
+ }
1015
+ /**
1016
+ * Iframe mode: replace the routes the Guidy bridge advertises to the host.
1017
+ * No-op unless the bridge is running (`enableGuidyBridge`).
1018
+ */
1019
+ setGuidyRoutes(routes) {
1020
+ this.config.guidyRoutes = routes;
1021
+ this.guidyBridge?.setRoutes(routes);
718
1022
  }
719
1023
  /**
720
1024
  * Iframe/WebView mode: start auto-syncing the embedded app's route
@@ -849,6 +1153,10 @@ var AuthManager = class {
849
1153
  await this.reactNativeAuth.logout();
850
1154
  }
851
1155
  if (this.mode === "iframe" && this.iframeAuth) {
1156
+ if (this.guidyBridge) {
1157
+ this.guidyBridge.stop();
1158
+ this.guidyBridge = null;
1159
+ }
852
1160
  this.iframeAuth.stop();
853
1161
  }
854
1162
  if (this.config.ssr) {
@@ -1019,6 +1327,10 @@ var AuthManager = class {
1019
1327
  /** Cleanup: remove listeners, timers, stop iframe auth. */
1020
1328
  destroy() {
1021
1329
  this.clearTokenRefreshTimer();
1330
+ if (this.guidyBridge) {
1331
+ this.guidyBridge.stop();
1332
+ this.guidyBridge = null;
1333
+ }
1022
1334
  if (this.iframeAuth) this.iframeAuth.stop();
1023
1335
  this.listeners.clear();
1024
1336
  this.navigationHandlers.clear();
@@ -1126,6 +1438,6 @@ function hasPermission(user, operation, dataSourceId, config) {
1126
1438
  );
1127
1439
  }
1128
1440
 
1129
- export { AuthManager, DEFAULT_API_URL, DEFAULT_CALLBACK_PATH, DEFAULT_OAUTH_SCOPES, IframeAuth, StandaloneOAuth2Auth, detectAuthMode, getAllRoles, hasPermission, hasRole };
1441
+ export { AuthManager, DEFAULT_API_URL, DEFAULT_CALLBACK_PATH, DEFAULT_OAUTH_SCOPES, GuidyBridge, IframeAuth, StandaloneOAuth2Auth, detectAuthMode, getAllRoles, hasPermission, hasRole };
1130
1442
  //# sourceMappingURL=core-index.js.map
1131
1443
  //# sourceMappingURL=core-index.js.map