@nostop/page 0.1.0-rc.1 → 0.1.0-rc.2
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 +3 -1
- package/dist/esm/PageAgent.d.ts +12 -0
- package/dist/esm/SimulatorMask-A9fOKtEZ.js +330 -0
- package/dist/esm/SimulatorMask-A9fOKtEZ.js.map +1 -0
- package/dist/esm/ax-core-oj-p6gBY.js +2922 -0
- package/dist/esm/ax-core-oj-p6gBY.js.map +1 -0
- package/dist/esm/ax-standards-O5KzTs6G.js +1711 -0
- package/dist/esm/ax-standards-O5KzTs6G.js.map +1 -0
- package/dist/esm/page-agent.js +1570 -16
- package/dist/esm/page-agent.js.map +1 -1
- package/dist/iife/page-agent.demo.js +16 -9
- package/package.json +2 -1
- package/dist/esm/SimulatorMask-Dft-xqkt.js +0 -163
- package/dist/esm/SimulatorMask-Dft-xqkt.js.map +0 -1
package/README.md
CHANGED
|
@@ -75,7 +75,9 @@ Exemplo usado no Aferis: regras de critério de parada, proibição de afirmar v
|
|
|
75
75
|
|
|
76
76
|
### Camada 6: prompt completo (use com cuidado)
|
|
77
77
|
|
|
78
|
-
- **`customSystemPrompt`**:
|
|
78
|
+
- **`customSystemPrompt`**: texto somado ao fim do prompt de sistema interno, que é mantido inteiro.
|
|
79
|
+
- **`overrideSystemPrompt: true`** (padrão `false`): faz o `customSystemPrompt` substituir o prompt interno. Perde as regras padrão de fábrica; é experimental.
|
|
80
|
+
- Na voz vale a mesma regra: `voice.systemPrompt` é somado ao prompt padrão da voz, e só o substitui com `voice.overrideSystemPrompt: true`.
|
|
79
81
|
|
|
80
82
|
### Camada 7: ciclo de vida (hooks)
|
|
81
83
|
|
package/dist/esm/PageAgent.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
import { AccessibilityConfig } from '@page-agent/page-controller';
|
|
2
|
+
import { AccessibilityController } from '@page-agent/page-controller';
|
|
1
3
|
import { AgentConfig } from '@page-agent/core';
|
|
4
|
+
import { AxError } from '@page-agent/page-controller';
|
|
5
|
+
import { AxErrorCode } from '@page-agent/page-controller';
|
|
2
6
|
import { PageAgentCore } from '@page-agent/core';
|
|
3
7
|
import { PageControllerConfig } from '@page-agent/page-controller';
|
|
4
8
|
import { Panel } from '@page-agent/ui';
|
|
5
9
|
import { PanelConfig } from '@page-agent/ui';
|
|
6
10
|
|
|
11
|
+
export { AccessibilityConfig }
|
|
12
|
+
|
|
13
|
+
export { AccessibilityController }
|
|
14
|
+
|
|
15
|
+
export { AxError }
|
|
16
|
+
|
|
17
|
+
export { AxErrorCode }
|
|
18
|
+
|
|
7
19
|
export declare class PageAgent extends PageAgentCore {
|
|
8
20
|
#private;
|
|
9
21
|
panel: Panel;
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
(function() { try { if (typeof document != "undefined") { var elementStyle = document.createElement("style"); elementStyle.appendChild(document.createTextNode("._wrapper_1nr74_1 {\n position: fixed;\n inset: 0;\n z-index: 2147483641; /* 确保在所有元素之上,除了 panel */\n cursor: wait;\n overflow: hidden;\n\n display: none;\n}\n\n._wrapper_1nr74_1._visible_1nr74_11 {\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_1nr74_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_1nr74_1[data-theme='dark'] {\n --pa-glow-ring: 42%;\n --pa-glow-near: 13%;\n --pa-glow-far: 5%;\n}\n\n._glow_1nr74_30 {\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_1nr74_44 {\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_1nr74_50 {\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_1nr74_63 {\n opacity: 1;\n transition-duration: 0.12s;\n}\n\n._progressBar_1nr74_68 {\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_1nr74_87 {\n width: 25%;\n}\n\n._progressActive_1nr74_63 ._progressBar_1nr74_68 {\n animation: _progressSlide_1nr74_1 1.25s cubic-bezier(0.45, 0, 0.25, 1) infinite;\n}\n\n._progressActive_1nr74_63 ._progressBarLate_1nr74_87 {\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_1nr74_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_1nr74_30 {\n transition: none;\n }\n\n /* A steady bar instead of a moving one. */\n ._progressActive_1nr74_63 ._progressBar_1nr74_68 {\n animation: none;\n width: 100%;\n transform: none;\n opacity: 0.6;\n }\n\n ._progressActive_1nr74_63 ._progressBarLate_1nr74_87 {\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_1nr74_1",
|
|
130
|
+
visible: "_visible_1nr74_11",
|
|
131
|
+
glow: "_glow_1nr74_30",
|
|
132
|
+
glowVisible: "_glowVisible_1nr74_44",
|
|
133
|
+
progress: "_progress_1nr74_50",
|
|
134
|
+
progressActive: "_progressActive_1nr74_63",
|
|
135
|
+
progressBar: "_progressBar_1nr74_68",
|
|
136
|
+
progressBarLate: "_progressBarLate_1nr74_87",
|
|
137
|
+
progressSlide: "_progressSlide_1nr74_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
|
+
var SimulatorMask = class extends EventTarget {
|
|
150
|
+
shown = false;
|
|
151
|
+
wrapper = document.createElement("div");
|
|
152
|
+
glow = document.createElement("div");
|
|
153
|
+
/** Bar at the top edge, moving while the page is being read. */
|
|
154
|
+
progress = document.createElement("div");
|
|
155
|
+
#disposed = false;
|
|
156
|
+
#cursor = document.createElement("div");
|
|
157
|
+
#currentCursorX = 0;
|
|
158
|
+
#currentCursorY = 0;
|
|
159
|
+
#targetCursorX = 0;
|
|
160
|
+
#targetCursorY = 0;
|
|
161
|
+
constructor() {
|
|
162
|
+
super();
|
|
163
|
+
this.wrapper.id = "page-agent-runtime_simulator-mask";
|
|
164
|
+
this.wrapper.className = SimulatorMask_module_default.wrapper;
|
|
165
|
+
this.wrapper.setAttribute("data-browser-use-ignore", "true");
|
|
166
|
+
this.wrapper.setAttribute("data-page-agent-ignore", "true");
|
|
167
|
+
this.glow.className = SimulatorMask_module_default.glow;
|
|
168
|
+
this.wrapper.appendChild(this.glow);
|
|
169
|
+
this.progress.className = SimulatorMask_module_default.progress;
|
|
170
|
+
for (const className of [SimulatorMask_module_default.progressBar, `${SimulatorMask_module_default.progressBar} ${SimulatorMask_module_default.progressBarLate}`]) {
|
|
171
|
+
const bar = document.createElement("div");
|
|
172
|
+
bar.className = className;
|
|
173
|
+
this.progress.appendChild(bar);
|
|
174
|
+
}
|
|
175
|
+
this.wrapper.appendChild(this.progress);
|
|
176
|
+
this.wrapper.addEventListener("click", (e) => {
|
|
177
|
+
e.stopPropagation();
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
});
|
|
180
|
+
this.wrapper.addEventListener("mousedown", (e) => {
|
|
181
|
+
e.stopPropagation();
|
|
182
|
+
e.preventDefault();
|
|
183
|
+
});
|
|
184
|
+
this.wrapper.addEventListener("mouseup", (e) => {
|
|
185
|
+
e.stopPropagation();
|
|
186
|
+
e.preventDefault();
|
|
187
|
+
});
|
|
188
|
+
this.wrapper.addEventListener("mousemove", (e) => {
|
|
189
|
+
e.stopPropagation();
|
|
190
|
+
e.preventDefault();
|
|
191
|
+
});
|
|
192
|
+
this.wrapper.addEventListener("wheel", (e) => {
|
|
193
|
+
e.stopPropagation();
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
});
|
|
196
|
+
this.wrapper.addEventListener("keydown", (e) => {
|
|
197
|
+
e.stopPropagation();
|
|
198
|
+
e.preventDefault();
|
|
199
|
+
});
|
|
200
|
+
this.wrapper.addEventListener("keyup", (e) => {
|
|
201
|
+
e.stopPropagation();
|
|
202
|
+
e.preventDefault();
|
|
203
|
+
});
|
|
204
|
+
this.#createCursor();
|
|
205
|
+
document.body.appendChild(this.wrapper);
|
|
206
|
+
this.#moveCursorToTarget();
|
|
207
|
+
const movePointerToListener = (event) => {
|
|
208
|
+
const { x, y } = event.detail;
|
|
209
|
+
this.setCursorPosition(x, y);
|
|
210
|
+
};
|
|
211
|
+
const clickPointerListener = () => {
|
|
212
|
+
this.triggerClickAnimation();
|
|
213
|
+
};
|
|
214
|
+
const enablePassThroughListener = () => {
|
|
215
|
+
this.wrapper.style.pointerEvents = "none";
|
|
216
|
+
};
|
|
217
|
+
const disablePassThroughListener = () => {
|
|
218
|
+
this.wrapper.style.pointerEvents = "auto";
|
|
219
|
+
};
|
|
220
|
+
window.addEventListener("PageAgent::MovePointerTo", movePointerToListener);
|
|
221
|
+
window.addEventListener("PageAgent::ClickPointer", clickPointerListener);
|
|
222
|
+
window.addEventListener("PageAgent::EnablePassThrough", enablePassThroughListener);
|
|
223
|
+
window.addEventListener("PageAgent::DisablePassThrough", disablePassThroughListener);
|
|
224
|
+
this.addEventListener("dispose", () => {
|
|
225
|
+
window.removeEventListener("PageAgent::MovePointerTo", movePointerToListener);
|
|
226
|
+
window.removeEventListener("PageAgent::ClickPointer", clickPointerListener);
|
|
227
|
+
window.removeEventListener("PageAgent::EnablePassThrough", enablePassThroughListener);
|
|
228
|
+
window.removeEventListener("PageAgent::DisablePassThrough", disablePassThroughListener);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
#createCursor() {
|
|
232
|
+
this.#cursor.className = cursor_module_default.cursor;
|
|
233
|
+
const rippleContainer = document.createElement("div");
|
|
234
|
+
rippleContainer.className = cursor_module_default.cursorRipple;
|
|
235
|
+
this.#cursor.appendChild(rippleContainer);
|
|
236
|
+
const fillingLayer = document.createElement("div");
|
|
237
|
+
fillingLayer.className = cursor_module_default.cursorFilling;
|
|
238
|
+
this.#cursor.appendChild(fillingLayer);
|
|
239
|
+
const borderLayer = document.createElement("div");
|
|
240
|
+
borderLayer.className = cursor_module_default.cursorBorder;
|
|
241
|
+
this.#cursor.appendChild(borderLayer);
|
|
242
|
+
this.wrapper.appendChild(this.#cursor);
|
|
243
|
+
}
|
|
244
|
+
#moveCursorToTarget() {
|
|
245
|
+
if (this.#disposed) return;
|
|
246
|
+
const newX = this.#currentCursorX + (this.#targetCursorX - this.#currentCursorX) * .2;
|
|
247
|
+
const newY = this.#currentCursorY + (this.#targetCursorY - this.#currentCursorY) * .2;
|
|
248
|
+
const xDistance = Math.abs(newX - this.#targetCursorX);
|
|
249
|
+
if (xDistance > 0) {
|
|
250
|
+
if (xDistance < 2) this.#currentCursorX = this.#targetCursorX;
|
|
251
|
+
else this.#currentCursorX = newX;
|
|
252
|
+
this.#cursor.style.left = `${this.#currentCursorX}px`;
|
|
253
|
+
}
|
|
254
|
+
const yDistance = Math.abs(newY - this.#targetCursorY);
|
|
255
|
+
if (yDistance > 0) {
|
|
256
|
+
if (yDistance < 2) this.#currentCursorY = this.#targetCursorY;
|
|
257
|
+
else this.#currentCursorY = newY;
|
|
258
|
+
this.#cursor.style.top = `${this.#currentCursorY}px`;
|
|
259
|
+
}
|
|
260
|
+
requestAnimationFrame(() => this.#moveCursorToTarget());
|
|
261
|
+
}
|
|
262
|
+
setCursorPosition(x, y) {
|
|
263
|
+
if (this.#disposed) return;
|
|
264
|
+
this.#targetCursorX = x;
|
|
265
|
+
this.#targetCursorY = y;
|
|
266
|
+
}
|
|
267
|
+
triggerClickAnimation() {
|
|
268
|
+
if (this.#disposed) return;
|
|
269
|
+
this.#cursor.classList.remove(cursor_module_default.clicking);
|
|
270
|
+
this.#cursor.getBoundingClientRect();
|
|
271
|
+
this.#cursor.classList.add(cursor_module_default.clicking);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Takes the glow and progress colour from the site: its strongest colour, fainter on a dark page.
|
|
275
|
+
* Read again on every show, because a site can change theme between tasks.
|
|
276
|
+
*/
|
|
277
|
+
#adaptToSite() {
|
|
278
|
+
try {
|
|
279
|
+
const { accent, dark } = detectSiteAppearance();
|
|
280
|
+
if (accent) this.wrapper.style.setProperty("--pa-glow", accent);
|
|
281
|
+
else this.wrapper.style.removeProperty("--pa-glow");
|
|
282
|
+
this.wrapper.dataset.theme = dark ? "dark" : "light";
|
|
283
|
+
} catch (error) {
|
|
284
|
+
console.warn("[SimulatorMask] could not read the site colours", error);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Starts the progress bar and resolves once the browser has drawn it. Call it right before work
|
|
289
|
+
* that blocks the page: from then on the bar keeps moving on its own.
|
|
290
|
+
*/
|
|
291
|
+
async startProgress() {
|
|
292
|
+
if (!this.shown || this.#disposed) return;
|
|
293
|
+
this.progress.classList.add(SimulatorMask_module_default.progressActive);
|
|
294
|
+
await Promise.race([new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))), new Promise((resolve) => setTimeout(resolve, 80))]);
|
|
295
|
+
}
|
|
296
|
+
stopProgress() {
|
|
297
|
+
this.progress.classList.remove(SimulatorMask_module_default.progressActive);
|
|
298
|
+
}
|
|
299
|
+
show() {
|
|
300
|
+
if (this.shown || this.#disposed) return;
|
|
301
|
+
this.#adaptToSite();
|
|
302
|
+
this.shown = true;
|
|
303
|
+
this.glow.classList.add(SimulatorMask_module_default.glowVisible);
|
|
304
|
+
this.wrapper.classList.add(SimulatorMask_module_default.visible);
|
|
305
|
+
this.#currentCursorX = window.innerWidth / 2;
|
|
306
|
+
this.#currentCursorY = window.innerHeight / 2;
|
|
307
|
+
this.#targetCursorX = this.#currentCursorX;
|
|
308
|
+
this.#targetCursorY = this.#currentCursorY;
|
|
309
|
+
this.#cursor.style.left = `${this.#currentCursorX}px`;
|
|
310
|
+
this.#cursor.style.top = `${this.#currentCursorY}px`;
|
|
311
|
+
}
|
|
312
|
+
hide() {
|
|
313
|
+
if (!this.shown || this.#disposed) return;
|
|
314
|
+
this.shown = false;
|
|
315
|
+
this.glow.classList.remove(SimulatorMask_module_default.glowVisible);
|
|
316
|
+
this.#cursor.classList.remove(cursor_module_default.clicking);
|
|
317
|
+
setTimeout(() => {
|
|
318
|
+
this.wrapper.classList.remove(SimulatorMask_module_default.visible);
|
|
319
|
+
}, 800);
|
|
320
|
+
}
|
|
321
|
+
dispose() {
|
|
322
|
+
this.#disposed = true;
|
|
323
|
+
this.wrapper.remove();
|
|
324
|
+
this.dispatchEvent(new Event("dispose"));
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
//#endregion
|
|
328
|
+
export { SimulatorMask };
|
|
329
|
+
|
|
330
|
+
//# sourceMappingURL=SimulatorMask-A9fOKtEZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimulatorMask-A9fOKtEZ.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\tposition: fixed;\n\tinset: 0;\n\tz-index: 2147483641; /* 确保在所有元素之上,除了 panel */\n\tcursor: wait;\n\toverflow: hidden;\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\topacity: 1;\n\ttransition-duration: 0.12s;\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\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\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// Capture all mouse, keyboard, and wheel events\n\t\tthis.wrapper.addEventListener('click', (e) => {\n\t\t\te.stopPropagation()\n\t\t\te.preventDefault()\n\t\t})\n\t\tthis.wrapper.addEventListener('mousedown', (e) => {\n\t\t\te.stopPropagation()\n\t\t\te.preventDefault()\n\t\t})\n\t\tthis.wrapper.addEventListener('mouseup', (e) => {\n\t\t\te.stopPropagation()\n\t\t\te.preventDefault()\n\t\t})\n\t\tthis.wrapper.addEventListener('mousemove', (e) => {\n\t\t\te.stopPropagation()\n\t\t\te.preventDefault()\n\t\t})\n\t\tthis.wrapper.addEventListener('wheel', (e) => {\n\t\t\te.stopPropagation()\n\t\t\te.preventDefault()\n\t\t})\n\t\tthis.wrapper.addEventListener('keydown', (e) => {\n\t\t\te.stopPropagation()\n\t\t\te.preventDefault()\n\t\t})\n\t\tthis.wrapper.addEventListener('keyup', (e) => {\n\t\t\te.stopPropagation()\n\t\t\te.preventDefault()\n\t\t})\n\n\t\t// Create AI cursor\n\t\tthis.#createCursor()\n\t\t// this.show()\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\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})\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// 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.glow.classList.add(styles.glowVisible)\n\n\t\tthis.wrapper.classList.add(styles.visible)\n\n\t\t// Initialize cursor position\n\t\tthis.#currentCursorX = window.innerWidth / 2\n\t\tthis.#currentCursorY = window.innerHeight / 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.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.wrapper.remove()\n\t\tthis.dispatchEvent(new Event('dispose'))\n\t}\n}\n"],"mappings":";;;AAoBA,SAAgB,OAAO,EAAE,GAAG,GAAG,KAAmB;CACjD,OAAO,K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