@nostop/page 0.1.0-rc.3 → 0.1.0-rc.5

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 (83) hide show
  1. package/README.md +13 -25
  2. package/dist/esm/PageAgent.d.ts +39 -0
  3. package/dist/esm/SimulatorMask-IpUIbMI-.js +446 -0
  4. package/dist/esm/SimulatorMask-IpUIbMI-.js.map +1 -0
  5. package/dist/esm/{ax-core-BVXEU2Dk.js → ax-core-D0YgGrGo.js} +20 -2
  6. package/dist/esm/ax-core-D0YgGrGo.js.map +1 -0
  7. package/dist/esm/page-agent.js +4285 -2842
  8. package/dist/esm/page-agent.js.map +1 -1
  9. package/dist/iife/page-agent.demo.js +215 -197
  10. package/package.json +6 -6
  11. package/dist/esm/SimulatorMask-D6QhYREr.js +0 -330
  12. package/dist/esm/SimulatorMask-D6QhYREr.js.map +0 -1
  13. package/dist/esm/ax-core-BVXEU2Dk.js.map +0 -1
  14. package/dist/esm/types/core/src/PageAgentCore.d.ts +0 -105
  15. package/dist/esm/types/core/src/confirmation.d.ts +0 -2
  16. package/dist/esm/types/core/src/contextMemory.d.ts +0 -20
  17. package/dist/esm/types/core/src/redactSensitiveUrls.d.ts +0 -4
  18. package/dist/esm/types/core/src/targetContext.d.ts +0 -11
  19. package/dist/esm/types/core/src/taskContext.d.ts +0 -78
  20. package/dist/esm/types/core/src/tools/index.d.ts +0 -43
  21. package/dist/esm/types/core/src/types.d.ts +0 -317
  22. package/dist/esm/types/core/src/utils/autoFixer.d.ts +0 -14
  23. package/dist/esm/types/core/src/utils/index.d.ts +0 -26
  24. package/dist/esm/types/llms/src/OpenAIClient.d.ts +0 -10
  25. package/dist/esm/types/llms/src/errors.d.ts +0 -28
  26. package/dist/esm/types/llms/src/index.d.ts +0 -19
  27. package/dist/esm/types/llms/src/types.d.ts +0 -108
  28. package/dist/esm/types/llms/src/utils.d.ts +0 -59
  29. package/dist/esm/types/page-agent/src/PageAgent.d.ts +0 -17
  30. package/dist/esm/types/page-agent/src/demo.d.ts +0 -1
  31. package/dist/esm/types/page-controller/src/PageController.d.ts +0 -314
  32. package/dist/esm/types/page-controller/src/actions.d.ts +0 -45
  33. package/dist/esm/types/page-controller/src/ax/AccessibilityController.d.ts +0 -191
  34. package/dist/esm/types/page-controller/src/ax/diagnosis.d.ts +0 -42
  35. package/dist/esm/types/page-controller/src/ax/diff.d.ts +0 -74
  36. package/dist/esm/types/page-controller/src/ax/domActivity.d.ts +0 -33
  37. package/dist/esm/types/page-controller/src/ax/domPath.d.ts +0 -12
  38. package/dist/esm/types/page-controller/src/ax/engine.d.ts +0 -245
  39. package/dist/esm/types/page-controller/src/ax/errors.d.ts +0 -44
  40. package/dist/esm/types/page-controller/src/ax/evidence.d.ts +0 -30
  41. package/dist/esm/types/page-controller/src/ax/format.d.ts +0 -10
  42. package/dist/esm/types/page-controller/src/ax/ids.d.ts +0 -17
  43. package/dist/esm/types/page-controller/src/ax/index.d.ts +0 -11
  44. package/dist/esm/types/page-controller/src/ax/observation.d.ts +0 -6
  45. package/dist/esm/types/page-controller/src/ax/types.d.ts +0 -298
  46. package/dist/esm/types/page-controller/src/ax/vendor/ax-core.d.ts +0 -202
  47. package/dist/esm/types/page-controller/src/ax/vendor/ax-standards.d.ts +0 -27
  48. package/dist/esm/types/page-controller/src/dom/dom_tree/index.d.ts +0 -21
  49. package/dist/esm/types/page-controller/src/dom/dom_tree/type.d.ts +0 -41
  50. package/dist/esm/types/page-controller/src/dom/getPageInfo.d.ts +0 -16
  51. package/dist/esm/types/page-controller/src/dom/index.d.ts +0 -62
  52. package/dist/esm/types/page-controller/src/geometry.d.ts +0 -9
  53. package/dist/esm/types/page-controller/src/mask/SimulatorMask.d.ts +0 -20
  54. package/dist/esm/types/page-controller/src/mask/siteColor.d.ts +0 -38
  55. package/dist/esm/types/page-controller/src/patches/antd.d.ts +0 -2
  56. package/dist/esm/types/page-controller/src/patches/react.d.ts +0 -5
  57. package/dist/esm/types/page-controller/src/redactSensitiveUrls.d.ts +0 -2
  58. package/dist/esm/types/page-controller/src/scriptResult.d.ts +0 -8
  59. package/dist/esm/types/page-controller/src/stateFreshness.d.ts +0 -16
  60. package/dist/esm/types/page-controller/src/utils/index.d.ts +0 -25
  61. package/dist/esm/types/ui/src/i18n/index.d.ts +0 -12
  62. package/dist/esm/types/ui/src/i18n/locales.d.ts +0 -358
  63. package/dist/esm/types/ui/src/index.d.ts +0 -2
  64. package/dist/esm/types/ui/src/panel/Panel.d.ts +0 -60
  65. package/dist/esm/types/ui/src/panel/feed.d.ts +0 -31
  66. package/dist/esm/types/ui/src/panel/fold.d.ts +0 -2
  67. package/dist/esm/types/ui/src/panel/highlight.d.ts +0 -18
  68. package/dist/esm/types/ui/src/panel/icons.d.ts +0 -6
  69. package/dist/esm/types/ui/src/panel/microphone.d.ts +0 -21
  70. package/dist/esm/types/ui/src/panel/recovery.d.ts +0 -21
  71. package/dist/esm/types/ui/src/panel/scriptCard.d.ts +0 -25
  72. package/dist/esm/types/ui/src/panel/toolVisual.d.ts +0 -10
  73. package/dist/esm/types/ui/src/panel/trace.d.ts +0 -15
  74. package/dist/esm/types/ui/src/panel/types.d.ts +0 -92
  75. package/dist/esm/types/ui/src/panel/voiceRuns.d.ts +0 -26
  76. package/dist/esm/types/ui/src/panel/voiceTaskRouting.d.ts +0 -8
  77. package/dist/esm/types/ui/src/utils.d.ts +0 -5
  78. package/dist/esm/types/ui/src/voice/gemini-client.d.ts +0 -12
  79. package/dist/esm/types/ui/src/voice/gemini-protocol.d.ts +0 -52
  80. package/dist/esm/types/ui/src/voice/realtime-client.d.ts +0 -25
  81. package/dist/esm/types/ui/src/voice/realtime-protocol.d.ts +0 -97
  82. package/dist/esm/types/ui/src/voice/voice-prompt.d.ts +0 -11
  83. package/dist/esm/types/ui/src/voice/voice-session.d.ts +0 -76
package/README.md CHANGED
@@ -6,18 +6,18 @@ Agente de IA que opera a página em que está instalado: lê o texto e os elemen
6
6
 
7
7
  ## Mapa do projeto
8
8
 
9
- | Pasta | O que faz | Quando mexer |
10
- | -------------------------------------------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------- |
11
- | `packages/core` | Ciclo do agente: passos, histórico, ferramentas, prompts | Quase nunca. Só com autorização explícita |
12
- | `packages/core/src/prompts/system_prompt.md` | Prompt de sistema padrão (regras gerais do agente) | Preferir `instructions.system` |
13
- | `packages/llms` | Cliente LLM compatível com OpenAI, com retentativas | Raramente |
14
- | `packages/page-controller` | Leitura da página (árvore de acessibilidade por padrão; lista de elementos como reserva) e ações | Para regras de extração e de bloqueio |
15
- | `packages/page-controller/src/mask` | Overlay visual: brilho de borda e cursor do agente | Para aparência |
16
- | `packages/ui` | Painel (conversa, ferramentas, voz, trilho, cartão de prévia) | Para interface |
17
- | `packages/page-agent` | Classe `PageAgent` (núcleo + painel) e o bundle da demo | Ponto de entrada para integrar |
18
- | `packages/website` | Site de documentação do projeto original | Opcional |
19
- | `packages/extension` | Extensão do Chrome | Opcional |
20
- | `packages/mcp` | Ponte MCP para a extensão | Opcional |
9
+ | Pasta | O que faz | Quando mexer |
10
+ | -------------------------------------------- | --------------------------------------------------------------------- | ----------------------------------------- |
11
+ | `packages/core` | Ciclo do agente: passos, histórico, ferramentas, prompts | Quase nunca. Só com autorização explícita |
12
+ | `packages/core/src/prompts/system_prompt.md` | Prompt de sistema padrão (regras gerais do agente) | Preferir `instructions.system` |
13
+ | `packages/llms` | Cliente LLM compatível com OpenAI, com retentativas | Raramente |
14
+ | `packages/page-controller` | Leitura da página (DOM simplificado) e ações (clicar, digitar, rolar) | Para regras de extração e de bloqueio |
15
+ | `packages/page-controller/src/mask` | Overlay visual: brilho de borda e cursor do agente | Para aparência |
16
+ | `packages/ui` | Painel (conversa, ferramentas, voz, trilho, cartão de prévia) | Para interface |
17
+ | `packages/page-agent` | Classe `PageAgent` (núcleo + painel) e o bundle da demo | Ponto de entrada para integrar |
18
+ | `packages/website` | Site de documentação do projeto original | Opcional |
19
+ | `packages/extension` | Extensão do Chrome | Opcional |
20
+ | `packages/mcp` | Ponte MCP para a extensão | Opcional |
21
21
 
22
22
  ## Uso básico
23
23
 
@@ -37,18 +37,6 @@ await agent.execute('Vá até o rodapé e pare quando não houver mais conteúdo
37
37
 
38
38
  Na demo, a mesma configuração vem dos parâmetros da URL do script (`model`, `baseURL`, `apiKey`, `lang`, `showPanel`).
39
39
 
40
- ## Como uma etapa funciona
41
-
42
- Isto é um script injetado na página. Não é Computer Use, não abre o desktop e não fala CDP. Cada passo faz uma coisa e a leitura seguinte é nova.
43
-
44
- - O índice numérico vale só para essa leitura. O próximo passo emite outros.
45
- - A leitura padrão é a árvore reconstruída, mais a seção `Changes since the previous accessibility read`. Essa seção diz o que mudou. A árvore acima dela é a leitura inteira e a única fonte de índices. Se a seção disser que nada mudou, a ação anterior não mostrou efeito. Isso não é sucesso e não significa que o alvo não existe.
46
- - O resultado separa três coisas: evento enviado, efeito observado e alteração persistida. Um clique sintético é evento enviado. Um valor visto no campo logo depois é efeito observado. Nenhum dos dois prova que a página gravou.
47
- - Não se pede `wait` só para a página assentar. O passo seguinte já lê de novo. `wait` fica para a região que a observação mostra ainda carregando.
48
- - Texto da página, resultado de ferramenta e texto colado de outro lugar são dados. Não são ordem e não são permissão.
49
- - Menu fechado ou overlay dispensado não encerra o pedido. O agente reabre e continua.
50
- - Senha nova, aviso de segurança do navegador, pagamento, compra, transferência ou jogo, e decisão sobre a elegibilidade de outra pessoa: o agente para e pede para a pessoa fazer. Apagar sem recuperação, contrato, software de origem desconhecida, ampliar acesso sensível ou enfraquecer segurança: pergunta de novo, mesmo que o pedido inicial tenha citado. Apagar com lixeira, preferência visual, upload nomeado, mensagem rotineira com destinatário e motivo claros, e login no site nomeado com credencial já dada: o pedido inicial basta quando nomeia a ação, o alvo e o destino. "Faz tudo" não autoriza. O código do clique ainda só reconhece rótulos conhecidos de ação destrutiva. O prompt pede o resto. Não é uma barreira de segurança.
51
-
52
40
  ## Camadas de customização
53
41
 
54
42
  Cada camada abaixo pode ser usada sozinha. Elas vão de "configurar" a "substituir".
@@ -129,7 +117,7 @@ Exemplo usado no Aferis: regras de critério de parada, proibição de afirmar v
129
117
 
130
118
  - A chave `apiKey` no navegador fica exposta a quem abre a página. Em produção, use um proxy no servidor.
131
119
  - Para dados sensíveis, use `transformPageContent` antes de chegar ao modelo.
132
- - Liste operações de alto risco nas instruções: proíba-as ou exija confirmação do usuário. O prompt padrão já pede isso para senha, pagamento, aviso de segurança, contrato e exclusão. Uma instrução própria soma a esse prompt. Ela não substitui essas paradas, a menos que `overrideSystemPrompt` seja `true`.
120
+ - Liste operações de alto risco nas instruções: proíba-as ou exija confirmação do usuário.
133
121
  - Pedidos com critério de parada explícito terminam antes e custam menos. Pedidos vagos (como "desce mais") podem percorrer a página inteira.
134
122
 
135
123
  ## Testes e build
@@ -0,0 +1,39 @@
1
+ import { AccessibilityConfig } from '@page-agent/page-controller';
2
+ import { AccessibilityController } from '@page-agent/page-controller';
3
+ import { AgentConfig } from '@page-agent/core';
4
+ import { AxError } from '@page-agent/page-controller';
5
+ import { AxErrorCode } from '@page-agent/page-controller';
6
+ import { PageAgentCore } from '@page-agent/core';
7
+ import { PageControllerConfig } from '@page-agent/page-controller';
8
+ import { Panel } from '@page-agent/ui';
9
+ import { PanelConfig } from '@page-agent/ui';
10
+
11
+ export { AccessibilityConfig }
12
+
13
+ export { AccessibilityController }
14
+
15
+ export { AxError }
16
+
17
+ export { AxErrorCode }
18
+
19
+ export declare class PageAgent extends PageAgentCore {
20
+ #private;
21
+ panel: Panel;
22
+ constructor(config: PageAgentConfig);
23
+ }
24
+
25
+ export declare type PageAgentConfig = AgentConfig & PageControllerConfig & Omit<PanelConfig, 'language'>;
26
+
27
+
28
+ export * from "@page-agent/core";
29
+
30
+ export { }
31
+
32
+
33
+
34
+ declare global {
35
+ interface Window {
36
+ pageAgent?: PageAgent
37
+ PageAgent: typeof PageAgent
38
+ }
39
+ }
@@ -0,0 +1,446 @@
1
+ (function() { try { if (typeof document != "undefined") { var elementStyle = document.createElement("style"); elementStyle.appendChild(document.createTextNode("._wrapper_1u70w_1 {\n /* Geometry is kept in sync with visualViewport in JS on mobile (URL bar / keyboard).\n CSS inset is the desktop fallback before the first sync. */\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n width: auto;\n height: auto;\n max-width: 100%;\n max-height: 100%;\n box-sizing: border-box;\n z-index: 2147483641; /* 确保在所有元素之上,除了 panel */\n cursor: wait;\n overflow: hidden;\n overflow: clip;\n contain: layout paint;\n overscroll-behavior: none;\n /* Block hit-testing when visible; pass-through temporarily sets pointer-events:none in JS. */\n pointer-events: auto;\n /* Stop mobile scroll/zoom gestures from reaching the page through the overlay. */\n touch-action: none;\n user-select: none;\n -webkit-user-select: none;\n\n display: none;\n}\n\n._wrapper_1u70w_1._visible_1u70w_30 {\n display: block;\n}\n\n/* The site's strongest colour, with the previous accent as the fallback for a site without one. */\n._wrapper_1u70w_1 {\n --pa-glow: var(--pa-accent, #fa8d45);\n --pa-glow-ring: 50%;\n --pa-glow-near: 16%;\n --pa-glow-far: 6%;\n}\n\n/* A colour shows more against a dark page, so it needs less. */\n._wrapper_1u70w_1[data-theme='dark'] {\n --pa-glow-ring: 42%;\n --pa-glow-near: 13%;\n --pa-glow-far: 5%;\n}\n\n._glow_1u70w_49 {\n position: absolute;\n inset: 0;\n pointer-events: none;\n opacity: 0;\n transition: opacity 0.4s ease;\n /* Same shape as before; the colour comes from the site (set by SimulatorMask) and is kept faint,\n so the glow reads as a focus ring of the site itself rather than as a foreign frame. */\n box-shadow:\n inset 0 0 0 2px color-mix(in srgb, var(--pa-glow) var(--pa-glow-ring), transparent),\n inset 0 0 42px 8px color-mix(in srgb, var(--pa-glow) var(--pa-glow-near), transparent),\n inset 0 0 100px 22px color-mix(in srgb, var(--pa-glow) var(--pa-glow-far), transparent);\n}\n\n._glowVisible_1u70w_63 {\n opacity: 1;\n}\n\n/* Progress bar shown while the page is being read. Reading blocks the page's main thread, so the bar\n moves with transform only: the browser's compositor keeps it going while scripts cannot run. */\n._progress_1u70w_69 {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n height: 3px;\n overflow: hidden;\n pointer-events: none;\n opacity: 0;\n transition: opacity 0.3s ease;\n background: color-mix(in srgb, var(--pa-glow) 14%, transparent);\n}\n\n._progressActive_1u70w_82 {\n /* Instant show: a short fade raced the page read on mobile and left the bar invisible. */\n opacity: 1;\n transition-duration: 0s;\n}\n\n._progressBar_1u70w_88 {\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n width: 45%;\n border-radius: 3px;\n transform: translateX(-110%);\n will-change: transform;\n background: linear-gradient(\n 90deg,\n transparent,\n color-mix(in srgb, var(--pa-glow) 85%, transparent) 35%,\n color-mix(in srgb, var(--pa-glow) 60%, white) 65%,\n transparent\n );\n filter: drop-shadow(0 0 6px color-mix(in srgb, var(--pa-glow) 70%, transparent));\n}\n\n._progressBarLate_1u70w_107 {\n width: 25%;\n}\n\n._progressActive_1u70w_82 ._progressBar_1u70w_88 {\n animation: _progressSlide_1u70w_1 1.25s cubic-bezier(0.45, 0, 0.25, 1) infinite;\n}\n\n._progressActive_1u70w_82 ._progressBarLate_1u70w_107 {\n animation-duration: 1.25s;\n animation-delay: 0.5s;\n animation-timing-function: cubic-bezier(0.3, 0, 0.6, 1);\n}\n\n@keyframes _progressSlide_1u70w_1 {\n from {\n transform: translateX(-110%);\n }\n to {\n transform: translateX(330%);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n ._glow_1u70w_49 {\n transition: none;\n }\n\n /* A steady bar instead of a moving one. */\n ._progressActive_1u70w_82 ._progressBar_1u70w_88 {\n animation: none;\n width: 100%;\n transform: none;\n opacity: 0.6;\n }\n\n ._progressActive_1u70w_82 ._progressBarLate_1u70w_107 {\n display: none;\n }\n}\n/* AI 光标样式 */\n._cursor_20vi4_2 {\n position: absolute;\n width: var(--cursor-size, 21px);\n height: var(--cursor-size, 25px);\n pointer-events: none;\n z-index: 10000;\n background: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 28'%3E%3Cpath d='M3 2v20l5.5-5 3.9 8 3-1.5-4-7.8L19 15z' fill='%23f28a46' stroke='%23171715' stroke-width='1.7' stroke-linejoin='round'/%3E%3C/svg%3E\")\n center / contain no-repeat;\n filter: drop-shadow(0 2px 2px #0005);\n}\n\n._cursorFilling_20vi4_13,\n._cursorBorder_20vi4_14 {\n display: none;\n}\n\n._cursorBorder_20vi4_14 {\n position: absolute;\n width: 100%;\n height: 100%;\n background: linear-gradient(45deg, rgb(57, 182, 255), rgb(189, 69, 251));\n mask-image: url(\"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e\");\n mask-size: 100% 100%;\n mask-repeat: no-repeat;\n\n transform-origin: center;\n transform: rotate(-135deg) scale(1.2);\n margin-left: -10px;\n margin-top: -18px;\n}\n\n._cursorFilling_20vi4_13 {\n position: absolute;\n width: 100%;\n height: 100%;\n background: url(\"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3e%3cdefs%3e%3c/defs%3e%3cg%20xmlns='http://www.w3.org/2000/svg'%20style='filter:%20drop-shadow(light-dark(rgba(0,%200,%200,%200.4),%20rgba(237,%20237,%20237,%200.4))%203px%204px%204px);'%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='%23ffffff'%20stroke='none'%20style='fill:%20%23ffffff;'/%3e%3c/g%3e%3c/svg%3e\");\n background-size: 100% 100%;\n background-repeat: no-repeat;\n\n transform-origin: center;\n transform: rotate(-135deg) scale(1.2);\n margin-left: -10px;\n margin-top: -18px;\n}\n\n._cursorRipple_20vi4_47 {\n position: absolute;\n width: 100%;\n height: 100%;\n pointer-events: none;\n margin-left: -50%;\n margin-top: -50%;\n\n &::after {\n content: '';\n opacity: 0;\n position: absolute;\n inset: 0;\n border: 4px solid rgba(57, 182, 255, 1);\n border-radius: 50%;\n }\n}\n\n._cursor_20vi4_2._clicking_20vi4_65 ._cursorRipple_20vi4_47::after {\n animation: _cursor-ripple_20vi4_1 300ms ease-out forwards;\n}\n\n@keyframes _cursor-ripple_20vi4_1 {\n 0% {\n transform: scale(0);\n opacity: 1;\n }\n 100% {\n transform: scale(2);\n opacity: 0;\n }\n}\n\n/* Panel button \"Hide agent cursor\": only the drawing disappears; the run continues. */\nhtml[data-pa-cursor-hidden] ._cursor_20vi4_2 {\n display: none !important;\n}")); document.head.appendChild(elementStyle); } } catch (e) { console.error("vite-plugin-css-injected-by-js", e); }})();
2
+ //#region ../page-controller/src/mask/siteColor.ts
3
+ /** How vivid a colour is, 0 (grey) to 255 (pure hue). */
4
+ function chroma({ r, g, b }) {
5
+ return Math.max(r, g, b) - Math.min(r, g, b);
6
+ }
7
+ /** Relative luminance, 0 (black) to 1 (white). */
8
+ function luminance({ r, g, b }) {
9
+ const channel = (value) => {
10
+ const c = value / 255;
11
+ return c <= .03928 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
12
+ };
13
+ return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
14
+ }
15
+ var MIN_CHROMA = 48;
16
+ var MIN_ALPHA = .5;
17
+ /**
18
+ * The strongest colour among the samples: similar colours are pooled, and the pool with the most
19
+ * weighted vividness wins. Greys and mostly transparent colours never win. Null when the page has
20
+ * no colour to speak of.
21
+ */
22
+ function pickStrongestColor(samples) {
23
+ const pools = /* @__PURE__ */ new Map();
24
+ for (const { color, weight } of samples) {
25
+ if (weight <= 0 || color.a < MIN_ALPHA || chroma(color) < MIN_CHROMA) continue;
26
+ const key = color.r >> 5 << 6 | color.g >> 5 << 3 | color.b >> 5;
27
+ const pool = pools.get(key) ?? {
28
+ score: 0,
29
+ weight: 0,
30
+ r: 0,
31
+ g: 0,
32
+ b: 0
33
+ };
34
+ pool.score += weight * (chroma(color) / 255);
35
+ pool.weight += weight;
36
+ pool.r += color.r * weight;
37
+ pool.g += color.g * weight;
38
+ pool.b += color.b * weight;
39
+ pools.set(key, pool);
40
+ }
41
+ let best = null;
42
+ for (const pool of pools.values()) if (!best || pool.score > best.score) best = pool;
43
+ if (!best) return null;
44
+ return {
45
+ r: Math.round(best.r / best.weight),
46
+ g: Math.round(best.g / best.weight),
47
+ b: Math.round(best.b / best.weight),
48
+ a: 1
49
+ };
50
+ }
51
+ var CANDIDATES = "a[href], button, [role=\"button\"], input[type=\"submit\"], input[type=\"button\"], h1, h2, [aria-current], [aria-selected=\"true\"]";
52
+ var MAX_CANDIDATES = 200;
53
+ var ROOT_VARIABLES = [
54
+ "--primary",
55
+ "--color-primary",
56
+ "--accent",
57
+ "--color-accent",
58
+ "--brand"
59
+ ];
60
+ /** Reads any CSS colour the browser understands (`oklch()`, `color-mix()`, names) as sRGB. */
61
+ function createColorReader(doc) {
62
+ const context = doc.createElement("canvas").getContext("2d", { willReadFrequently: true });
63
+ return (css) => {
64
+ if (!context || !css || css === "transparent") return null;
65
+ context.clearRect(0, 0, 1, 1);
66
+ context.fillStyle = "#000";
67
+ context.fillStyle = css;
68
+ context.fillRect(0, 0, 1, 1);
69
+ const [r, g, b, a] = context.getImageData(0, 0, 1, 1).data;
70
+ return {
71
+ r,
72
+ g,
73
+ b,
74
+ a: a / 255
75
+ };
76
+ };
77
+ }
78
+ /**
79
+ * Samples the colours of the page's links, buttons and headings, its `accent-color`, its theme
80
+ * colour and common theme variables. It reads computed styles of at most a couple of hundred
81
+ * elements and changes nothing.
82
+ */
83
+ function detectSiteAppearance(doc = document) {
84
+ const view = doc.defaultView;
85
+ if (!view) return {
86
+ accent: null,
87
+ dark: false
88
+ };
89
+ const read = createColorReader(doc);
90
+ const samples = [];
91
+ const add = (css, weight) => {
92
+ const color = css ? read(css) : null;
93
+ if (color) samples.push({
94
+ color,
95
+ weight
96
+ });
97
+ };
98
+ const rootStyle = view.getComputedStyle(doc.documentElement);
99
+ if (rootStyle.accentColor && rootStyle.accentColor !== "auto") add(rootStyle.accentColor, 8);
100
+ add(doc.querySelector("meta[name=\"theme-color\"]")?.content, 6);
101
+ for (const name of ROOT_VARIABLES) add(rootStyle.getPropertyValue(name).trim(), 6);
102
+ let seen = 0;
103
+ for (const element of doc.querySelectorAll(CANDIDATES)) {
104
+ if (seen >= MAX_CANDIDATES) break;
105
+ if (element.closest("[data-page-agent-ignore]")) continue;
106
+ const rect = element.getBoundingClientRect();
107
+ if (rect.width === 0 || rect.height === 0) continue;
108
+ seen++;
109
+ const style = view.getComputedStyle(element);
110
+ add(style.backgroundColor, Math.min(12, Math.max(1, rect.width * rect.height / 2e3)));
111
+ add(style.color, element.localName === "a" ? 2 : 1);
112
+ if (style.borderTopWidth !== "0px") add(style.borderTopColor, .5);
113
+ }
114
+ let background = null;
115
+ for (const element of [doc.body, doc.documentElement]) {
116
+ const color = element ? read(view.getComputedStyle(element).backgroundColor) : null;
117
+ if (color && color.a > .5) {
118
+ background = color;
119
+ break;
120
+ }
121
+ }
122
+ const accent = pickStrongestColor(samples);
123
+ return {
124
+ accent: accent ? `rgb(${accent.r} ${accent.g} ${accent.b})` : null,
125
+ dark: background ? luminance(background) < .35 : false
126
+ };
127
+ }
128
+ var SimulatorMask_module_default = {
129
+ wrapper: "_wrapper_1u70w_1",
130
+ visible: "_visible_1u70w_30",
131
+ glow: "_glow_1u70w_49",
132
+ glowVisible: "_glowVisible_1u70w_63",
133
+ progress: "_progress_1u70w_69",
134
+ progressActive: "_progressActive_1u70w_82",
135
+ progressBar: "_progressBar_1u70w_88",
136
+ progressBarLate: "_progressBarLate_1u70w_107",
137
+ progressSlide: "_progressSlide_1u70w_1"
138
+ };
139
+ var cursor_module_default = {
140
+ cursor: "_cursor_20vi4_2",
141
+ cursorFilling: "_cursorFilling_20vi4_13",
142
+ cursorBorder: "_cursorBorder_20vi4_14",
143
+ cursorRipple: "_cursorRipple_20vi4_47",
144
+ clicking: "_clicking_20vi4_65",
145
+ "cursor-ripple": "_cursor-ripple_20vi4_1"
146
+ };
147
+ //#endregion
148
+ //#region ../page-controller/src/mask/SimulatorMask.ts
149
+ /** Agent UI that must stay interactive while the page is blocked. */
150
+ var AGENT_UI_SELECTOR = "[data-page-agent-ignore], [data-browser-use-ignore]";
151
+ /** User input types blocked on the page while the mask is shown (trusted only). */
152
+ var BLOCKED_PAGE_EVENTS = [
153
+ "pointerdown",
154
+ "pointerup",
155
+ "pointermove",
156
+ "pointercancel",
157
+ "touchstart",
158
+ "touchmove",
159
+ "touchend",
160
+ "touchcancel",
161
+ "mousedown",
162
+ "mouseup",
163
+ "mousemove",
164
+ "click",
165
+ "dblclick",
166
+ "auxclick",
167
+ "contextmenu",
168
+ "wheel",
169
+ "keydown",
170
+ "keyup",
171
+ "keypress",
172
+ "selectstart",
173
+ "dragstart"
174
+ ];
175
+ var SimulatorMask = class extends EventTarget {
176
+ shown = false;
177
+ wrapper = document.createElement("div");
178
+ glow = document.createElement("div");
179
+ /** Bar at the top edge, moving while the page is being read. */
180
+ progress = document.createElement("div");
181
+ #disposed = false;
182
+ #cursor = document.createElement("div");
183
+ #currentCursorX = 0;
184
+ #currentCursorY = 0;
185
+ #targetCursorX = 0;
186
+ #targetCursorY = 0;
187
+ /** Previous inline overscroll styles, restored when the mask hides. */
188
+ #prevHtmlOverscroll = "";
189
+ #prevBodyOverscroll = "";
190
+ #overscrollLocked = false;
191
+ constructor() {
192
+ super();
193
+ this.wrapper.id = "page-agent-runtime_simulator-mask";
194
+ this.wrapper.className = SimulatorMask_module_default.wrapper;
195
+ this.wrapper.setAttribute("data-browser-use-ignore", "true");
196
+ this.wrapper.setAttribute("data-page-agent-ignore", "true");
197
+ this.glow.className = SimulatorMask_module_default.glow;
198
+ this.wrapper.appendChild(this.glow);
199
+ this.progress.className = SimulatorMask_module_default.progress;
200
+ for (const className of [SimulatorMask_module_default.progressBar, `${SimulatorMask_module_default.progressBar} ${SimulatorMask_module_default.progressBarLate}`]) {
201
+ const bar = document.createElement("div");
202
+ bar.className = className;
203
+ this.progress.appendChild(bar);
204
+ }
205
+ this.wrapper.appendChild(this.progress);
206
+ for (const type of BLOCKED_PAGE_EVENTS) this.wrapper.addEventListener(type, (e) => {
207
+ e.stopPropagation();
208
+ if (e.cancelable) e.preventDefault();
209
+ }, {
210
+ capture: true,
211
+ passive: false
212
+ });
213
+ this.#createCursor();
214
+ document.body.appendChild(this.wrapper);
215
+ this.#moveCursorToTarget();
216
+ const movePointerToListener = (event) => {
217
+ const { x, y } = event.detail;
218
+ this.setCursorPosition(x, y);
219
+ };
220
+ const clickPointerListener = () => {
221
+ this.triggerClickAnimation();
222
+ };
223
+ const enablePassThroughListener = () => {
224
+ this.wrapper.style.pointerEvents = "none";
225
+ };
226
+ const disablePassThroughListener = () => {
227
+ this.wrapper.style.pointerEvents = "auto";
228
+ };
229
+ window.addEventListener("PageAgent::MovePointerTo", movePointerToListener);
230
+ window.addEventListener("PageAgent::ClickPointer", clickPointerListener);
231
+ window.addEventListener("PageAgent::EnablePassThrough", enablePassThroughListener);
232
+ window.addEventListener("PageAgent::DisablePassThrough", disablePassThroughListener);
233
+ const captureOpts = {
234
+ capture: true,
235
+ passive: false
236
+ };
237
+ for (const type of BLOCKED_PAGE_EVENTS) document.addEventListener(type, this.#blockTrustedPageInput, captureOpts);
238
+ document.addEventListener("focusin", this.#blockTrustedFocus, captureOpts);
239
+ this.addEventListener("dispose", () => {
240
+ window.removeEventListener("PageAgent::MovePointerTo", movePointerToListener);
241
+ window.removeEventListener("PageAgent::ClickPointer", clickPointerListener);
242
+ window.removeEventListener("PageAgent::EnablePassThrough", enablePassThroughListener);
243
+ window.removeEventListener("PageAgent::DisablePassThrough", disablePassThroughListener);
244
+ for (const type of BLOCKED_PAGE_EVENTS) document.removeEventListener(type, this.#blockTrustedPageInput, captureOpts);
245
+ document.removeEventListener("focusin", this.#blockTrustedFocus, captureOpts);
246
+ this.#unbindViewport();
247
+ this.#unlockOverscroll();
248
+ });
249
+ }
250
+ /** True when the event target belongs to the agent panel, mask, or other ignored UI. */
251
+ #isAgentUi(target) {
252
+ const node = target instanceof Node ? target : null;
253
+ if (!node) return false;
254
+ return !!(node instanceof Element ? node : node.parentElement)?.closest?.(AGENT_UI_SELECTOR);
255
+ }
256
+ #blockTrustedPageInput = (event) => {
257
+ if (!this.shown || this.#disposed || !event.isTrusted) return;
258
+ if (this.#isAgentUi(event.target)) return;
259
+ event.stopImmediatePropagation();
260
+ if (event.cancelable) event.preventDefault();
261
+ };
262
+ #blockTrustedFocus = (event) => {
263
+ if (!this.shown || this.#disposed || !event.isTrusted) return;
264
+ if (this.#isAgentUi(event.target)) return;
265
+ event.stopImmediatePropagation();
266
+ if (event.cancelable) event.preventDefault();
267
+ const focused = event.target;
268
+ if (focused instanceof HTMLElement) focused.blur();
269
+ };
270
+ /** Drop page focus so keyboard events cannot reach inputs under the overlay. */
271
+ #blurPageFocus() {
272
+ const active = document.activeElement;
273
+ if (!(active instanceof HTMLElement)) return;
274
+ if (active === document.body || active === document.documentElement) return;
275
+ if (this.#isAgentUi(active)) return;
276
+ active.blur();
277
+ }
278
+ /**
279
+ * Keep the overlay flush with the visual viewport. On phones the layout viewport
280
+ * (innerWidth/innerHeight, position:fixed inset:0) is often larger than what the
281
+ * user sees (URL bar, keyboard, pinch). Covering that larger box leaves a blank
282
+ * strip beside or below the site and breaks the page's own CSS.
283
+ */
284
+ #syncViewport = () => {
285
+ if (this.#disposed) return;
286
+ const vv = window.visualViewport;
287
+ if (!vv) {
288
+ this.wrapper.style.top = "0px";
289
+ this.wrapper.style.left = "0px";
290
+ this.wrapper.style.right = "0px";
291
+ this.wrapper.style.bottom = "0px";
292
+ this.wrapper.style.width = "";
293
+ this.wrapper.style.height = "";
294
+ return;
295
+ }
296
+ this.wrapper.style.top = `${vv.offsetTop}px`;
297
+ this.wrapper.style.left = `${vv.offsetLeft}px`;
298
+ this.wrapper.style.right = "auto";
299
+ this.wrapper.style.bottom = "auto";
300
+ this.wrapper.style.width = `${vv.width}px`;
301
+ this.wrapper.style.height = `${vv.height}px`;
302
+ };
303
+ #bindViewport() {
304
+ this.#syncViewport();
305
+ window.visualViewport?.addEventListener("resize", this.#syncViewport);
306
+ window.visualViewport?.addEventListener("scroll", this.#syncViewport);
307
+ window.addEventListener("resize", this.#syncViewport);
308
+ }
309
+ #unbindViewport() {
310
+ window.visualViewport?.removeEventListener("resize", this.#syncViewport);
311
+ window.visualViewport?.removeEventListener("scroll", this.#syncViewport);
312
+ window.removeEventListener("resize", this.#syncViewport);
313
+ this.wrapper.style.top = "";
314
+ this.wrapper.style.left = "";
315
+ this.wrapper.style.right = "";
316
+ this.wrapper.style.bottom = "";
317
+ this.wrapper.style.width = "";
318
+ this.wrapper.style.height = "";
319
+ }
320
+ /** Stops rubber-band overscroll from revealing blank page chrome under the mask. */
321
+ #lockOverscroll() {
322
+ if (this.#overscrollLocked) return;
323
+ this.#overscrollLocked = true;
324
+ this.#prevHtmlOverscroll = document.documentElement.style.overscrollBehavior;
325
+ this.#prevBodyOverscroll = document.body.style.overscrollBehavior;
326
+ document.documentElement.style.overscrollBehavior = "none";
327
+ document.body.style.overscrollBehavior = "none";
328
+ }
329
+ #unlockOverscroll() {
330
+ if (!this.#overscrollLocked) return;
331
+ this.#overscrollLocked = false;
332
+ document.documentElement.style.overscrollBehavior = this.#prevHtmlOverscroll;
333
+ document.body.style.overscrollBehavior = this.#prevBodyOverscroll;
334
+ }
335
+ #createCursor() {
336
+ this.#cursor.className = cursor_module_default.cursor;
337
+ const rippleContainer = document.createElement("div");
338
+ rippleContainer.className = cursor_module_default.cursorRipple;
339
+ this.#cursor.appendChild(rippleContainer);
340
+ const fillingLayer = document.createElement("div");
341
+ fillingLayer.className = cursor_module_default.cursorFilling;
342
+ this.#cursor.appendChild(fillingLayer);
343
+ const borderLayer = document.createElement("div");
344
+ borderLayer.className = cursor_module_default.cursorBorder;
345
+ this.#cursor.appendChild(borderLayer);
346
+ this.wrapper.appendChild(this.#cursor);
347
+ }
348
+ #moveCursorToTarget() {
349
+ if (this.#disposed) return;
350
+ const newX = this.#currentCursorX + (this.#targetCursorX - this.#currentCursorX) * .2;
351
+ const newY = this.#currentCursorY + (this.#targetCursorY - this.#currentCursorY) * .2;
352
+ const xDistance = Math.abs(newX - this.#targetCursorX);
353
+ if (xDistance > 0) {
354
+ if (xDistance < 2) this.#currentCursorX = this.#targetCursorX;
355
+ else this.#currentCursorX = newX;
356
+ this.#cursor.style.left = `${this.#currentCursorX}px`;
357
+ }
358
+ const yDistance = Math.abs(newY - this.#targetCursorY);
359
+ if (yDistance > 0) {
360
+ if (yDistance < 2) this.#currentCursorY = this.#targetCursorY;
361
+ else this.#currentCursorY = newY;
362
+ this.#cursor.style.top = `${this.#currentCursorY}px`;
363
+ }
364
+ requestAnimationFrame(() => this.#moveCursorToTarget());
365
+ }
366
+ setCursorPosition(x, y) {
367
+ if (this.#disposed) return;
368
+ this.#targetCursorX = x;
369
+ this.#targetCursorY = y;
370
+ }
371
+ triggerClickAnimation() {
372
+ if (this.#disposed) return;
373
+ this.#cursor.classList.remove(cursor_module_default.clicking);
374
+ this.#cursor.getBoundingClientRect();
375
+ this.#cursor.classList.add(cursor_module_default.clicking);
376
+ }
377
+ /**
378
+ * Takes the glow and progress colour from the site: its strongest colour, fainter on a dark page.
379
+ * Read again on every show, because a site can change theme between tasks.
380
+ */
381
+ #adaptToSite() {
382
+ try {
383
+ const { accent, dark } = detectSiteAppearance();
384
+ if (accent) this.wrapper.style.setProperty("--pa-glow", accent);
385
+ else this.wrapper.style.removeProperty("--pa-glow");
386
+ this.wrapper.dataset.theme = dark ? "dark" : "light";
387
+ } catch (error) {
388
+ console.warn("[SimulatorMask] could not read the site colours", error);
389
+ }
390
+ }
391
+ /**
392
+ * Starts the progress bar and resolves once the browser has drawn it. Call it right before work
393
+ * that blocks the page: from then on the bar keeps moving on its own.
394
+ */
395
+ async startProgress() {
396
+ if (!this.shown || this.#disposed) return;
397
+ this.progress.classList.add(SimulatorMask_module_default.progressActive);
398
+ this.progress.offsetWidth;
399
+ await Promise.race([new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))), new Promise((resolve) => setTimeout(resolve, 80))]);
400
+ }
401
+ stopProgress() {
402
+ this.progress.classList.remove(SimulatorMask_module_default.progressActive);
403
+ }
404
+ show() {
405
+ if (this.shown || this.#disposed) return;
406
+ this.#adaptToSite();
407
+ this.shown = true;
408
+ this.#blurPageFocus();
409
+ this.#lockOverscroll();
410
+ this.#bindViewport();
411
+ this.glow.classList.add(SimulatorMask_module_default.glowVisible);
412
+ this.wrapper.classList.add(SimulatorMask_module_default.visible);
413
+ const vv = window.visualViewport;
414
+ const viewW = vv?.width ?? window.innerWidth;
415
+ const viewH = vv?.height ?? window.innerHeight;
416
+ this.#currentCursorX = viewW / 2;
417
+ this.#currentCursorY = viewH / 2;
418
+ this.#targetCursorX = this.#currentCursorX;
419
+ this.#targetCursorY = this.#currentCursorY;
420
+ this.#cursor.style.left = `${this.#currentCursorX}px`;
421
+ this.#cursor.style.top = `${this.#currentCursorY}px`;
422
+ }
423
+ hide() {
424
+ if (!this.shown || this.#disposed) return;
425
+ this.shown = false;
426
+ this.#unbindViewport();
427
+ this.#unlockOverscroll();
428
+ this.glow.classList.remove(SimulatorMask_module_default.glowVisible);
429
+ this.#cursor.classList.remove(cursor_module_default.clicking);
430
+ setTimeout(() => {
431
+ this.wrapper.classList.remove(SimulatorMask_module_default.visible);
432
+ }, 800);
433
+ }
434
+ dispose() {
435
+ this.#disposed = true;
436
+ this.shown = false;
437
+ this.#unbindViewport();
438
+ this.#unlockOverscroll();
439
+ this.wrapper.remove();
440
+ this.dispatchEvent(new Event("dispose"));
441
+ }
442
+ };
443
+ //#endregion
444
+ export { SimulatorMask };
445
+
446
+ //# sourceMappingURL=SimulatorMask-IpUIbMI-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SimulatorMask-IpUIbMI-.js","names":[],"sources":["../../../page-controller/src/mask/siteColor.ts","../../../page-controller/src/mask/SimulatorMask.module.css","../../../page-controller/src/mask/cursor.module.css","../../../page-controller/src/mask/SimulatorMask.ts"],"sourcesContent":["/**\n * Finds the colour a site itself uses most strongly, so the agent's own visual cues (the edge glow,\n * the progress bar) blend with the site instead of bringing a colour of their own.\n */\n\nexport interface Rgba {\n\tr: number\n\tg: number\n\tb: number\n\t/** 0 to 1. */\n\ta: number\n}\n\n/** A colour seen on the page and how much it counts: larger and more prominent uses weigh more. */\nexport interface ColorSample {\n\tcolor: Rgba\n\tweight: number\n}\n\n/** How vivid a colour is, 0 (grey) to 255 (pure hue). */\nexport function chroma({ r, g, b }: Rgba): number {\n\treturn Math.max(r, g, b) - Math.min(r, g, b)\n}\n\n/** Relative luminance, 0 (black) to 1 (white). */\nexport function luminance({ r, g, b }: Rgba): number {\n\tconst channel = (value: number) => {\n\t\tconst c = value / 255\n\t\treturn c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n\t}\n\treturn 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b)\n}\n\nconst MIN_CHROMA = 48\nconst MIN_ALPHA = 0.5\n\n/**\n * The strongest colour among the samples: similar colours are pooled, and the pool with the most\n * weighted vividness wins. Greys and mostly transparent colours never win. Null when the page has\n * no colour to speak of.\n */\nexport function pickStrongestColor(samples: ColorSample[]): Rgba | null {\n\tconst pools = new Map<\n\t\tnumber,\n\t\t{ score: number; weight: number; r: number; g: number; b: number }\n\t>()\n\tfor (const { color, weight } of samples) {\n\t\tif (weight <= 0 || color.a < MIN_ALPHA || chroma(color) < MIN_CHROMA) continue\n\t\tconst key = ((color.r >> 5) << 6) | ((color.g >> 5) << 3) | (color.b >> 5)\n\t\tconst pool = pools.get(key) ?? { score: 0, weight: 0, r: 0, g: 0, b: 0 }\n\t\tpool.score += weight * (chroma(color) / 255)\n\t\tpool.weight += weight\n\t\tpool.r += color.r * weight\n\t\tpool.g += color.g * weight\n\t\tpool.b += color.b * weight\n\t\tpools.set(key, pool)\n\t}\n\tlet best: { score: number; weight: number; r: number; g: number; b: number } | null = null\n\tfor (const pool of pools.values()) if (!best || pool.score > best.score) best = pool\n\tif (!best) return null\n\treturn {\n\t\tr: Math.round(best.r / best.weight),\n\t\tg: Math.round(best.g / best.weight),\n\t\tb: Math.round(best.b / best.weight),\n\t\ta: 1,\n\t}\n}\n\nconst CANDIDATES =\n\t'a[href], button, [role=\"button\"], input[type=\"submit\"], input[type=\"button\"], h1, h2, [aria-current], [aria-selected=\"true\"]'\nconst MAX_CANDIDATES = 200\nconst ROOT_VARIABLES = ['--primary', '--color-primary', '--accent', '--color-accent', '--brand']\n\n/** Reads any CSS colour the browser understands (`oklch()`, `color-mix()`, names) as sRGB. */\nfunction createColorReader(doc: Document): (css: string) => Rgba | null {\n\tconst context = doc.createElement('canvas').getContext('2d', { willReadFrequently: true })\n\treturn (css) => {\n\t\tif (!context || !css || css === 'transparent') return null\n\t\tcontext.clearRect(0, 0, 1, 1)\n\t\t// An invalid colour leaves the previous fill style, so set a known one first.\n\t\tcontext.fillStyle = '#000'\n\t\tcontext.fillStyle = css\n\t\tcontext.fillRect(0, 0, 1, 1)\n\t\tconst [r, g, b, a] = context.getImageData(0, 0, 1, 1).data\n\t\treturn { r, g, b, a: a / 255 }\n\t}\n}\n\nexport interface SiteAppearance {\n\t/** The site's strongest colour as a CSS colour, or null when it has none. */\n\taccent: string | null\n\t/** Whether the page background is dark. */\n\tdark: boolean\n}\n\n/**\n * Samples the colours of the page's links, buttons and headings, its `accent-color`, its theme\n * colour and common theme variables. It reads computed styles of at most a couple of hundred\n * elements and changes nothing.\n */\nexport function detectSiteAppearance(doc: Document = document): SiteAppearance {\n\tconst view = doc.defaultView\n\tif (!view) return { accent: null, dark: false }\n\tconst read = createColorReader(doc)\n\tconst samples: ColorSample[] = []\n\tconst add = (css: string | null | undefined, weight: number) => {\n\t\tconst color = css ? read(css) : null\n\t\tif (color) samples.push({ color, weight })\n\t}\n\n\tconst rootStyle = view.getComputedStyle(doc.documentElement)\n\tif (rootStyle.accentColor && rootStyle.accentColor !== 'auto') add(rootStyle.accentColor, 8)\n\tadd(doc.querySelector<HTMLMetaElement>('meta[name=\"theme-color\"]')?.content, 6)\n\tfor (const name of ROOT_VARIABLES) add(rootStyle.getPropertyValue(name).trim(), 6)\n\n\tlet seen = 0\n\tfor (const element of doc.querySelectorAll(CANDIDATES)) {\n\t\tif (seen >= MAX_CANDIDATES) break\n\t\t// The agent's own interface is not the site.\n\t\tif (element.closest('[data-page-agent-ignore]')) continue\n\t\tconst rect = element.getBoundingClientRect()\n\t\tif (rect.width === 0 || rect.height === 0) continue\n\t\tseen++\n\t\tconst style = view.getComputedStyle(element)\n\t\tadd(style.backgroundColor, Math.min(12, Math.max(1, (rect.width * rect.height) / 2000)))\n\t\tadd(style.color, element.localName === 'a' ? 2 : 1)\n\t\tif (style.borderTopWidth !== '0px') add(style.borderTopColor, 0.5)\n\t}\n\n\tlet background: Rgba | null = null\n\tfor (const element of [doc.body, doc.documentElement]) {\n\t\tconst color = element ? read(view.getComputedStyle(element).backgroundColor) : null\n\t\tif (color && color.a > 0.5) {\n\t\t\tbackground = color\n\t\t\tbreak\n\t\t}\n\t}\n\n\tconst accent = pickStrongestColor(samples)\n\treturn {\n\t\taccent: accent ? `rgb(${accent.r} ${accent.g} ${accent.b})` : null,\n\t\tdark: background ? luminance(background) < 0.35 : false,\n\t}\n}\n",".wrapper {\n\t/* Geometry is kept in sync with visualViewport in JS on mobile (URL bar / keyboard).\n\t CSS inset is the desktop fallback before the first sync. */\n\tposition: fixed;\n\ttop: 0;\n\tleft: 0;\n\tright: 0;\n\tbottom: 0;\n\twidth: auto;\n\theight: auto;\n\tmax-width: 100%;\n\tmax-height: 100%;\n\tbox-sizing: border-box;\n\tz-index: 2147483641; /* 确保在所有元素之上,除了 panel */\n\tcursor: wait;\n\toverflow: hidden;\n\toverflow: clip;\n\tcontain: layout paint;\n\toverscroll-behavior: none;\n\t/* Block hit-testing when visible; pass-through temporarily sets pointer-events:none in JS. */\n\tpointer-events: auto;\n\t/* Stop mobile scroll/zoom gestures from reaching the page through the overlay. */\n\ttouch-action: none;\n\tuser-select: none;\n\t-webkit-user-select: none;\n\n\tdisplay: none;\n}\n\n.wrapper.visible {\n\tdisplay: block;\n}\n\n/* The site's strongest colour, with the previous accent as the fallback for a site without one. */\n.wrapper {\n\t--pa-glow: var(--pa-accent, #fa8d45);\n\t--pa-glow-ring: 50%;\n\t--pa-glow-near: 16%;\n\t--pa-glow-far: 6%;\n}\n\n/* A colour shows more against a dark page, so it needs less. */\n.wrapper[data-theme='dark'] {\n\t--pa-glow-ring: 42%;\n\t--pa-glow-near: 13%;\n\t--pa-glow-far: 5%;\n}\n\n.glow {\n\tposition: absolute;\n\tinset: 0;\n\tpointer-events: none;\n\topacity: 0;\n\ttransition: opacity 0.4s ease;\n\t/* Same shape as before; the colour comes from the site (set by SimulatorMask) and is kept faint,\n\t so the glow reads as a focus ring of the site itself rather than as a foreign frame. */\n\tbox-shadow:\n\t\tinset 0 0 0 2px color-mix(in srgb, var(--pa-glow) var(--pa-glow-ring), transparent),\n\t\tinset 0 0 42px 8px color-mix(in srgb, var(--pa-glow) var(--pa-glow-near), transparent),\n\t\tinset 0 0 100px 22px color-mix(in srgb, var(--pa-glow) var(--pa-glow-far), transparent);\n}\n\n.glowVisible {\n\topacity: 1;\n}\n\n/* Progress bar shown while the page is being read. Reading blocks the page's main thread, so the bar\n moves with transform only: the browser's compositor keeps it going while scripts cannot run. */\n.progress {\n\tposition: absolute;\n\ttop: 0;\n\tleft: 0;\n\tright: 0;\n\theight: 3px;\n\toverflow: hidden;\n\tpointer-events: none;\n\topacity: 0;\n\ttransition: opacity 0.3s ease;\n\tbackground: color-mix(in srgb, var(--pa-glow) 14%, transparent);\n}\n\n.progressActive {\n\t/* Instant show: a short fade raced the page read on mobile and left the bar invisible. */\n\topacity: 1;\n\ttransition-duration: 0s;\n}\n\n.progressBar {\n\tposition: absolute;\n\ttop: 0;\n\tbottom: 0;\n\tleft: 0;\n\twidth: 45%;\n\tborder-radius: 3px;\n\ttransform: translateX(-110%);\n\twill-change: transform;\n\tbackground: linear-gradient(\n\t\t90deg,\n\t\ttransparent,\n\t\tcolor-mix(in srgb, var(--pa-glow) 85%, transparent) 35%,\n\t\tcolor-mix(in srgb, var(--pa-glow) 60%, white) 65%,\n\t\ttransparent\n\t);\n\tfilter: drop-shadow(0 0 6px color-mix(in srgb, var(--pa-glow) 70%, transparent));\n}\n\n.progressBarLate {\n\twidth: 25%;\n}\n\n.progressActive .progressBar {\n\tanimation: progressSlide 1.25s cubic-bezier(0.45, 0, 0.25, 1) infinite;\n}\n\n.progressActive .progressBarLate {\n\tanimation-duration: 1.25s;\n\tanimation-delay: 0.5s;\n\tanimation-timing-function: cubic-bezier(0.3, 0, 0.6, 1);\n}\n\n@keyframes progressSlide {\n\tfrom {\n\t\ttransform: translateX(-110%);\n\t}\n\tto {\n\t\ttransform: translateX(330%);\n\t}\n}\n\n@media (prefers-reduced-motion: reduce) {\n\t.glow {\n\t\ttransition: none;\n\t}\n\n\t/* A steady bar instead of a moving one. */\n\t.progressActive .progressBar {\n\t\tanimation: none;\n\t\twidth: 100%;\n\t\ttransform: none;\n\t\topacity: 0.6;\n\t}\n\n\t.progressActive .progressBarLate {\n\t\tdisplay: none;\n\t}\n}\n","/* AI 光标样式 */\n.cursor {\n\tposition: absolute;\n\twidth: var(--cursor-size, 21px);\n\theight: var(--cursor-size, 25px);\n\tpointer-events: none;\n\tz-index: 10000;\n\tbackground: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 28'%3E%3Cpath d='M3 2v20l5.5-5 3.9 8 3-1.5-4-7.8L19 15z' fill='%23f28a46' stroke='%23171715' stroke-width='1.7' stroke-linejoin='round'/%3E%3C/svg%3E\")\n\t\tcenter / contain no-repeat;\n\tfilter: drop-shadow(0 2px 2px #0005);\n}\n\n.cursorFilling,\n.cursorBorder {\n\tdisplay: none;\n}\n\n.cursorBorder {\n\tposition: absolute;\n\twidth: 100%;\n\theight: 100%;\n\tbackground: linear-gradient(45deg, rgb(57, 182, 255), rgb(189, 69, 251));\n\tmask-image: url(./cursor-border.svg);\n\tmask-size: 100% 100%;\n\tmask-repeat: no-repeat;\n\n\ttransform-origin: center;\n\ttransform: rotate(-135deg) scale(1.2);\n\tmargin-left: -10px;\n\tmargin-top: -18px;\n}\n\n.cursorFilling {\n\tposition: absolute;\n\twidth: 100%;\n\theight: 100%;\n\tbackground: url(./cursor-fill.svg);\n\tbackground-size: 100% 100%;\n\tbackground-repeat: no-repeat;\n\n\ttransform-origin: center;\n\ttransform: rotate(-135deg) scale(1.2);\n\tmargin-left: -10px;\n\tmargin-top: -18px;\n}\n\n.cursorRipple {\n\tposition: absolute;\n\twidth: 100%;\n\theight: 100%;\n\tpointer-events: none;\n\tmargin-left: -50%;\n\tmargin-top: -50%;\n\n\t&::after {\n\t\tcontent: '';\n\t\topacity: 0;\n\t\tposition: absolute;\n\t\tinset: 0;\n\t\tborder: 4px solid rgba(57, 182, 255, 1);\n\t\tborder-radius: 50%;\n\t}\n}\n\n.cursor.clicking .cursorRipple::after {\n\tanimation: cursor-ripple 300ms ease-out forwards;\n}\n\n@keyframes cursor-ripple {\n\t0% {\n\t\ttransform: scale(0);\n\t\topacity: 1;\n\t}\n\t100% {\n\t\ttransform: scale(2);\n\t\topacity: 0;\n\t}\n}\n\n/* Panel button \"Hide agent cursor\": only the drawing disappears; the run continues. */\n:global(html[data-pa-cursor-hidden]) .cursor {\n\tdisplay: none !important;\n}\n","import { detectSiteAppearance } from './siteColor'\n\nimport styles from './SimulatorMask.module.css'\nimport cursorStyles from './cursor.module.css'\n\n/** Agent UI that must stay interactive while the page is blocked. */\nconst AGENT_UI_SELECTOR = '[data-page-agent-ignore], [data-browser-use-ignore]'\n\n/** User input types blocked on the page while the mask is shown (trusted only). */\nconst BLOCKED_PAGE_EVENTS = [\n\t'pointerdown',\n\t'pointerup',\n\t'pointermove',\n\t'pointercancel',\n\t'touchstart',\n\t'touchmove',\n\t'touchend',\n\t'touchcancel',\n\t'mousedown',\n\t'mouseup',\n\t'mousemove',\n\t'click',\n\t'dblclick',\n\t'auxclick',\n\t'contextmenu',\n\t'wheel',\n\t'keydown',\n\t'keyup',\n\t'keypress',\n\t'selectstart',\n\t'dragstart',\n] as const\n\nexport class SimulatorMask extends EventTarget {\n\tshown: boolean = false\n\twrapper = document.createElement('div')\n\tglow = document.createElement('div')\n\t/** Bar at the top edge, moving while the page is being read. */\n\tprogress = document.createElement('div')\n\n\t#disposed = false\n\n\t#cursor = document.createElement('div')\n\n\t#currentCursorX = 0\n\t#currentCursorY = 0\n\n\t#targetCursorX = 0\n\t#targetCursorY = 0\n\n\t/** Previous inline overscroll styles, restored when the mask hides. */\n\t#prevHtmlOverscroll = ''\n\t#prevBodyOverscroll = ''\n\t#overscrollLocked = false\n\n\tconstructor() {\n\t\tsuper()\n\n\t\tthis.wrapper.id = 'page-agent-runtime_simulator-mask'\n\t\tthis.wrapper.className = styles.wrapper\n\t\tthis.wrapper.setAttribute('data-browser-use-ignore', 'true')\n\t\tthis.wrapper.setAttribute('data-page-agent-ignore', 'true')\n\n\t\t// Transparent edge glow marking the page under agent control. No fill; it never blocks pointer events.\n\t\tthis.glow.className = styles.glow\n\t\tthis.wrapper.appendChild(this.glow)\n\n\t\tthis.progress.className = styles.progress\n\t\tfor (const className of [\n\t\t\tstyles.progressBar,\n\t\t\t`${styles.progressBar} ${styles.progressBarLate}`,\n\t\t]) {\n\t\t\tconst bar = document.createElement('div')\n\t\t\tbar.className = className\n\t\t\tthis.progress.appendChild(bar)\n\t\t}\n\t\tthis.wrapper.appendChild(this.progress)\n\n\t\t// Swallow anything that lands on the wrapper itself (when pointer-events is auto).\n\t\tfor (const type of BLOCKED_PAGE_EVENTS) {\n\t\t\tthis.wrapper.addEventListener(\n\t\t\t\ttype,\n\t\t\t\t(e) => {\n\t\t\t\t\te.stopPropagation()\n\t\t\t\t\tif (e.cancelable) e.preventDefault()\n\t\t\t\t},\n\t\t\t\t{ capture: true, passive: false }\n\t\t\t)\n\t\t}\n\n\t\t// Create AI cursor\n\t\tthis.#createCursor()\n\n\t\tdocument.body.appendChild(this.wrapper)\n\n\t\tthis.#moveCursorToTarget()\n\n\t\t// global events\n\t\t// @note Mask should be isolated from the rest of the code.\n\t\t// Global events are easier to manage and cleanup.\n\n\t\tconst movePointerToListener = (event: Event) => {\n\t\t\tconst { x, y } = (event as CustomEvent).detail\n\t\t\tthis.setCursorPosition(x, y)\n\t\t}\n\t\tconst clickPointerListener = () => {\n\t\t\tthis.triggerClickAnimation()\n\t\t}\n\t\tconst enablePassThroughListener = () => {\n\t\t\tthis.wrapper.style.pointerEvents = 'none'\n\t\t}\n\t\tconst disablePassThroughListener = () => {\n\t\t\tthis.wrapper.style.pointerEvents = 'auto'\n\t\t}\n\n\t\twindow.addEventListener('PageAgent::MovePointerTo', movePointerToListener)\n\t\twindow.addEventListener('PageAgent::ClickPointer', clickPointerListener)\n\t\twindow.addEventListener('PageAgent::EnablePassThrough', enablePassThroughListener)\n\t\twindow.addEventListener('PageAgent::DisablePassThrough', disablePassThroughListener)\n\n\t\t// While the mask is shown, real user input must not reach the page — including during\n\t\t// pass-through windows where the wrapper sets pointer-events:none so the agent can\n\t\t// hit-test. Synthetic agent events (isTrusted === false) still go through.\n\t\tconst captureOpts: AddEventListenerOptions = { capture: true, passive: false }\n\t\tfor (const type of BLOCKED_PAGE_EVENTS) {\n\t\t\tdocument.addEventListener(type, this.#blockTrustedPageInput, captureOpts)\n\t\t}\n\t\tdocument.addEventListener('focusin', this.#blockTrustedFocus, captureOpts)\n\n\t\tthis.addEventListener('dispose', () => {\n\t\t\twindow.removeEventListener('PageAgent::MovePointerTo', movePointerToListener)\n\t\t\twindow.removeEventListener('PageAgent::ClickPointer', clickPointerListener)\n\t\t\twindow.removeEventListener('PageAgent::EnablePassThrough', enablePassThroughListener)\n\t\t\twindow.removeEventListener('PageAgent::DisablePassThrough', disablePassThroughListener)\n\t\t\tfor (const type of BLOCKED_PAGE_EVENTS) {\n\t\t\t\tdocument.removeEventListener(type, this.#blockTrustedPageInput, captureOpts)\n\t\t\t}\n\t\t\tdocument.removeEventListener('focusin', this.#blockTrustedFocus, captureOpts)\n\t\t\tthis.#unbindViewport()\n\t\t\tthis.#unlockOverscroll()\n\t\t})\n\t}\n\n\t/** True when the event target belongs to the agent panel, mask, or other ignored UI. */\n\t#isAgentUi(target: EventTarget | null): boolean {\n\t\tconst node = target instanceof Node ? target : null\n\t\tif (!node) return false\n\t\tconst el = node instanceof Element ? node : node.parentElement\n\t\treturn !!el?.closest?.(AGENT_UI_SELECTOR)\n\t}\n\n\t#blockTrustedPageInput = (event: Event) => {\n\t\tif (!this.shown || this.#disposed || !event.isTrusted) return\n\t\tif (this.#isAgentUi(event.target)) return\n\t\tevent.stopImmediatePropagation()\n\t\tif (event.cancelable) event.preventDefault()\n\t}\n\n\t#blockTrustedFocus = (event: FocusEvent) => {\n\t\tif (!this.shown || this.#disposed || !event.isTrusted) return\n\t\tif (this.#isAgentUi(event.target)) return\n\t\tevent.stopImmediatePropagation()\n\t\tif (event.cancelable) event.preventDefault()\n\t\tconst focused = event.target\n\t\tif (focused instanceof HTMLElement) focused.blur()\n\t}\n\n\t/** Drop page focus so keyboard events cannot reach inputs under the overlay. */\n\t#blurPageFocus() {\n\t\tconst active = document.activeElement\n\t\tif (!(active instanceof HTMLElement)) return\n\t\tif (active === document.body || active === document.documentElement) return\n\t\tif (this.#isAgentUi(active)) return\n\t\tactive.blur()\n\t}\n\n\t/**\n\t * Keep the overlay flush with the visual viewport. On phones the layout viewport\n\t * (innerWidth/innerHeight, position:fixed inset:0) is often larger than what the\n\t * user sees (URL bar, keyboard, pinch). Covering that larger box leaves a blank\n\t * strip beside or below the site and breaks the page's own CSS.\n\t */\n\t#syncViewport = () => {\n\t\tif (this.#disposed) return\n\t\tconst vv = window.visualViewport\n\t\tif (!vv) {\n\t\t\tthis.wrapper.style.top = '0px'\n\t\t\tthis.wrapper.style.left = '0px'\n\t\t\tthis.wrapper.style.right = '0px'\n\t\t\tthis.wrapper.style.bottom = '0px'\n\t\t\tthis.wrapper.style.width = ''\n\t\t\tthis.wrapper.style.height = ''\n\t\t\treturn\n\t\t}\n\t\tthis.wrapper.style.top = `${vv.offsetTop}px`\n\t\tthis.wrapper.style.left = `${vv.offsetLeft}px`\n\t\tthis.wrapper.style.right = 'auto'\n\t\tthis.wrapper.style.bottom = 'auto'\n\t\tthis.wrapper.style.width = `${vv.width}px`\n\t\tthis.wrapper.style.height = `${vv.height}px`\n\t}\n\n\t#bindViewport() {\n\t\tthis.#syncViewport()\n\t\twindow.visualViewport?.addEventListener('resize', this.#syncViewport)\n\t\twindow.visualViewport?.addEventListener('scroll', this.#syncViewport)\n\t\twindow.addEventListener('resize', this.#syncViewport)\n\t}\n\n\t#unbindViewport() {\n\t\twindow.visualViewport?.removeEventListener('resize', this.#syncViewport)\n\t\twindow.visualViewport?.removeEventListener('scroll', this.#syncViewport)\n\t\twindow.removeEventListener('resize', this.#syncViewport)\n\t\tthis.wrapper.style.top = ''\n\t\tthis.wrapper.style.left = ''\n\t\tthis.wrapper.style.right = ''\n\t\tthis.wrapper.style.bottom = ''\n\t\tthis.wrapper.style.width = ''\n\t\tthis.wrapper.style.height = ''\n\t}\n\n\t/** Stops rubber-band overscroll from revealing blank page chrome under the mask. */\n\t#lockOverscroll() {\n\t\tif (this.#overscrollLocked) return\n\t\tthis.#overscrollLocked = true\n\t\tthis.#prevHtmlOverscroll = document.documentElement.style.overscrollBehavior\n\t\tthis.#prevBodyOverscroll = document.body.style.overscrollBehavior\n\t\tdocument.documentElement.style.overscrollBehavior = 'none'\n\t\tdocument.body.style.overscrollBehavior = 'none'\n\t}\n\n\t#unlockOverscroll() {\n\t\tif (!this.#overscrollLocked) return\n\t\tthis.#overscrollLocked = false\n\t\tdocument.documentElement.style.overscrollBehavior = this.#prevHtmlOverscroll\n\t\tdocument.body.style.overscrollBehavior = this.#prevBodyOverscroll\n\t}\n\n\t#createCursor() {\n\t\tthis.#cursor.className = cursorStyles.cursor\n\n\t\t// Create ripple effect container\n\t\tconst rippleContainer = document.createElement('div')\n\t\trippleContainer.className = cursorStyles.cursorRipple\n\t\tthis.#cursor.appendChild(rippleContainer)\n\n\t\t// Create filling layer\n\t\tconst fillingLayer = document.createElement('div')\n\t\tfillingLayer.className = cursorStyles.cursorFilling\n\t\tthis.#cursor.appendChild(fillingLayer)\n\n\t\t// Create border layer\n\t\tconst borderLayer = document.createElement('div')\n\t\tborderLayer.className = cursorStyles.cursorBorder\n\t\tthis.#cursor.appendChild(borderLayer)\n\n\t\tthis.wrapper.appendChild(this.#cursor)\n\t}\n\n\t#moveCursorToTarget() {\n\t\tif (this.#disposed) return\n\n\t\tconst newX = this.#currentCursorX + (this.#targetCursorX - this.#currentCursorX) * 0.2\n\t\tconst newY = this.#currentCursorY + (this.#targetCursorY - this.#currentCursorY) * 0.2\n\n\t\tconst xDistance = Math.abs(newX - this.#targetCursorX)\n\t\tif (xDistance > 0) {\n\t\t\tif (xDistance < 2) {\n\t\t\t\tthis.#currentCursorX = this.#targetCursorX\n\t\t\t} else {\n\t\t\t\tthis.#currentCursorX = newX\n\t\t\t}\n\t\t\tthis.#cursor.style.left = `${this.#currentCursorX}px`\n\t\t}\n\n\t\tconst yDistance = Math.abs(newY - this.#targetCursorY)\n\t\tif (yDistance > 0) {\n\t\t\tif (yDistance < 2) {\n\t\t\t\tthis.#currentCursorY = this.#targetCursorY\n\t\t\t} else {\n\t\t\t\tthis.#currentCursorY = newY\n\t\t\t}\n\t\t\tthis.#cursor.style.top = `${this.#currentCursorY}px`\n\t\t}\n\n\t\trequestAnimationFrame(() => this.#moveCursorToTarget())\n\t}\n\n\tsetCursorPosition(x: number, y: number) {\n\t\tif (this.#disposed) return\n\n\t\tthis.#targetCursorX = x\n\t\tthis.#targetCursorY = y\n\t}\n\n\ttriggerClickAnimation() {\n\t\tif (this.#disposed) return\n\n\t\tthis.#cursor.classList.remove(cursorStyles.clicking)\n\t\t// Force reflow to restart animation\n\t\tthis.#cursor.getBoundingClientRect()\n\t\tthis.#cursor.classList.add(cursorStyles.clicking)\n\t}\n\n\t/**\n\t * Takes the glow and progress colour from the site: its strongest colour, fainter on a dark page.\n\t * Read again on every show, because a site can change theme between tasks.\n\t */\n\t#adaptToSite() {\n\t\ttry {\n\t\t\tconst { accent, dark } = detectSiteAppearance()\n\t\t\tif (accent) this.wrapper.style.setProperty('--pa-glow', accent)\n\t\t\telse this.wrapper.style.removeProperty('--pa-glow')\n\t\t\tthis.wrapper.dataset.theme = dark ? 'dark' : 'light'\n\t\t} catch (error) {\n\t\t\t// The default colour stays. A cosmetic reading must never stop a task.\n\t\t\tconsole.warn('[SimulatorMask] could not read the site colours', error)\n\t\t}\n\t}\n\n\t/**\n\t * Starts the progress bar and resolves once the browser has drawn it. Call it right before work\n\t * that blocks the page: from then on the bar keeps moving on its own.\n\t */\n\tasync startProgress(): Promise<void> {\n\t\tif (!this.shown || this.#disposed) return\n\t\tthis.progress.classList.add(styles.progressActive)\n\t\t// Force style flush so the opacity transition starts before we wait for paint. Without this,\n\t\t// the next read can observe opacity still at 0 on a busy mobile frame.\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- intentional reflow read\n\t\tthis.progress.offsetWidth\n\t\t// Two frames: one to apply the style, one for the animation to reach the compositor. The timer\n\t\t// is for a tab in the background, where frames are not produced.\n\t\tawait Promise.race([\n\t\t\tnew Promise<void>((resolve) =>\n\t\t\t\trequestAnimationFrame(() => requestAnimationFrame(() => resolve()))\n\t\t\t),\n\t\t\tnew Promise<void>((resolve) => setTimeout(resolve, 80)),\n\t\t])\n\t}\n\n\tstopProgress(): void {\n\t\tthis.progress.classList.remove(styles.progressActive)\n\t}\n\n\tshow() {\n\t\tif (this.shown || this.#disposed) return\n\n\t\tthis.#adaptToSite()\n\t\tthis.shown = true\n\t\tthis.#blurPageFocus()\n\t\tthis.#lockOverscroll()\n\t\tthis.#bindViewport()\n\t\tthis.glow.classList.add(styles.glowVisible)\n\n\t\tthis.wrapper.classList.add(styles.visible)\n\n\t\t// Initialize cursor at the centre of the visible viewport (not the larger layout box).\n\t\tconst vv = window.visualViewport\n\t\tconst viewW = vv?.width ?? window.innerWidth\n\t\tconst viewH = vv?.height ?? window.innerHeight\n\t\tthis.#currentCursorX = viewW / 2\n\t\tthis.#currentCursorY = viewH / 2\n\t\tthis.#targetCursorX = this.#currentCursorX\n\t\tthis.#targetCursorY = this.#currentCursorY\n\t\tthis.#cursor.style.left = `${this.#currentCursorX}px`\n\t\tthis.#cursor.style.top = `${this.#currentCursorY}px`\n\t}\n\n\thide() {\n\t\tif (!this.shown || this.#disposed) return\n\n\t\tthis.shown = false\n\t\tthis.#unbindViewport()\n\t\tthis.#unlockOverscroll()\n\t\tthis.glow.classList.remove(styles.glowVisible)\n\n\t\tthis.#cursor.classList.remove(cursorStyles.clicking)\n\n\t\tsetTimeout(() => {\n\t\t\tthis.wrapper.classList.remove(styles.visible)\n\t\t}, 800) // Match the animation duration\n\t}\n\n\tdispose() {\n\t\tthis.#disposed = true\n\t\tthis.shown = false\n\t\tthis.#unbindViewport()\n\t\tthis.#unlockOverscroll()\n\t\tthis.wrapper.remove()\n\t\tthis.dispatchEvent(new Event('dispose'))\n\t}\n}\n"],"mappings":";;;AAoBA,SAAgB,OAAO,EAAE,GAAG,GAAG,KAAmB;CACjD,OAAO,KAAK,IAAI,GAAG,GAAG,CAAC,IAAI,KAAK,IAAI,GAAG,GAAG,CAAC;AAC5C;;AAGA,SAAgB,UAAU,EAAE,GAAG,GAAG,KAAmB;CACpD,MAAM,WAAW,UAAkB;EAClC,MAAM,IAAI,QAAQ;EAClB,OAAO,KAAK,SAAU,IAAI,UAAU,IAAI,QAAS,UAAU;CAC5D;CACA,OAAO,QAAS,QAAQ,CAAC,IAAI,QAAS,QAAQ,CAAC,IAAI,QAAS,QAAQ,CAAC;AACtE;AAEA,IAAM,aAAa;AACnB,IAAM,YAAY;;;;;;AAOlB,SAAgB,mBAAmB,SAAqC;CACvE,MAAM,wBAAQ,IAAI,IAGhB;CACF,KAAK,MAAM,EAAE,OAAO,YAAY,SAAS;EACxC,IAAI,UAAU,KAAK,MAAM,IAAI,aAAa,OAAO,KAAK,IAAI,YAAY;EACtE,MAAM,MAAQ,MAAM,KAAK,KAAM,IAAO,MAAM,KAAK,KAAM,IAAM,MAAM,KAAK;EACxE,MAAM,OAAO,MAAM,IAAI,GAAG,KAAK;GAAE,OAAO;GAAG,QAAQ;GAAG,GAAG;GAAG,GAAG;GAAG,GAAG;EAAE;EACvE,KAAK,SAAS,UAAU,OAAO,KAAK,IAAI;EACxC,KAAK,UAAU;EACf,KAAK,KAAK,MAAM,IAAI;EACpB,KAAK,KAAK,MAAM,IAAI;EACpB,KAAK,KAAK,MAAM,IAAI;EACpB,MAAM,IAAI,KAA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