@opentiny/next-sdk 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/WebMcp.ts +6 -0
  2. package/core.ts +1 -0
  3. package/dist/SimulatorMask-BHVXyogh-BFEGpD5S.js +1048 -0
  4. package/dist/SimulatorMask-BHVXyogh-CCYbrb84.js +801 -0
  5. package/dist/WebMcp.d.ts +3 -0
  6. package/dist/core.d.ts +1 -0
  7. package/dist/core.js +16 -15
  8. package/dist/index.d.ts +2 -1
  9. package/dist/index.es.dev.js +8192 -2602
  10. package/dist/index.es.js +21515 -16867
  11. package/dist/index.js +4033 -1847
  12. package/dist/index.umd.dev.js +9548 -3013
  13. package/dist/index.umd.js +500 -66
  14. package/dist/initialize-builtin-WebMCP-HgObT902.js +6279 -0
  15. package/dist/mcpsdk@1.25.3.dev.js +253 -94
  16. package/dist/mcpsdk@1.25.3.es.dev.js +253 -94
  17. package/dist/mcpsdk@1.25.3.es.js +5689 -5531
  18. package/dist/mcpsdk@1.25.3.js +32 -27
  19. package/dist/page-tools/a11y-tree.d.ts +103 -0
  20. package/dist/page-tools/bridge.d.ts +0 -6
  21. package/dist/page-tools/initialize-builtin-WebMCP.d.ts +1 -0
  22. package/dist/page-tools/page-agent-tool.d.ts +9 -0
  23. package/dist/page-tools/page-state-cache.d.ts +36 -0
  24. package/dist/webagent.dev.js +3604 -1841
  25. package/dist/webagent.es.dev.js +3360 -1493
  26. package/dist/webagent.es.js +16107 -14382
  27. package/dist/webagent.js +74 -66
  28. package/dist/webmcp-full.dev.js +7625 -719
  29. package/dist/webmcp-full.es.dev.js +6437 -580
  30. package/dist/webmcp-full.es.js +12146 -7590
  31. package/dist/webmcp-full.js +631 -29
  32. package/dist/webmcp.dev.js +8002 -25
  33. package/dist/webmcp.es.dev.js +6932 -3
  34. package/dist/webmcp.es.js +6180 -859
  35. package/dist/webmcp.js +602 -1
  36. package/index.ts +2 -14
  37. package/package.json +11 -4
  38. package/page-tools/a11y-tree.ts +532 -0
  39. package/page-tools/bridge.ts +48 -14
  40. package/page-tools/initialize-builtin-WebMCP.ts +20 -0
  41. package/page-tools/page-agent-prompt.md +123 -0
  42. package/page-tools/page-agent-tool.ts +223 -0
  43. package/page-tools/page-state-cache.ts +78 -0
  44. package/vite-env.d.ts +5 -0
  45. package/dist/AgentModelProvider-CwqOT28f.js +0 -4198
@@ -0,0 +1,1048 @@
1
+ function computeBorderGeometry(pixelWidth, pixelHeight, borderWidth, glowWidth) {
2
+ const shortSide = Math.max(1, Math.min(pixelWidth, pixelHeight));
3
+ const borderWidthPx = Math.min(borderWidth, 20);
4
+ const glowWidthPx = glowWidth;
5
+ const totalThick = Math.min(borderWidthPx + glowWidthPx, shortSide);
6
+ const insetX = Math.min(totalThick, Math.floor(pixelWidth / 2));
7
+ const insetY = Math.min(totalThick, Math.floor(pixelHeight / 2));
8
+ const toClipX = (x) => x / pixelWidth * 2 - 1;
9
+ const toClipY = (y) => y / pixelHeight * 2 - 1;
10
+ const x0 = 0;
11
+ const x1 = pixelWidth;
12
+ const y0 = 0;
13
+ const y1 = pixelHeight;
14
+ const xi0 = insetX;
15
+ const xi1 = pixelWidth - insetX;
16
+ const yi0 = insetY;
17
+ const yi1 = pixelHeight - insetY;
18
+ const X0 = toClipX(x0);
19
+ const X1 = toClipX(x1);
20
+ const Y0 = toClipY(y0);
21
+ const Y1 = toClipY(y1);
22
+ const Xi0 = toClipX(xi0);
23
+ const Xi1 = toClipX(xi1);
24
+ const Yi0 = toClipY(yi0);
25
+ const Yi1 = toClipY(yi1);
26
+ const u0 = 0;
27
+ const v0 = 0;
28
+ const u1 = 1;
29
+ const v1 = 1;
30
+ const ui0 = insetX / pixelWidth;
31
+ const ui1 = 1 - insetX / pixelWidth;
32
+ const vi0 = insetY / pixelHeight;
33
+ const vi1 = 1 - insetY / pixelHeight;
34
+ const positions = new Float32Array([
35
+ // Top strip
36
+ X0,
37
+ Y0,
38
+ X1,
39
+ Y0,
40
+ X0,
41
+ Yi0,
42
+ X0,
43
+ Yi0,
44
+ X1,
45
+ Y0,
46
+ X1,
47
+ Yi0,
48
+ // Bottom strip
49
+ X0,
50
+ Yi1,
51
+ X1,
52
+ Yi1,
53
+ X0,
54
+ Y1,
55
+ X0,
56
+ Y1,
57
+ X1,
58
+ Yi1,
59
+ X1,
60
+ Y1,
61
+ // Left strip
62
+ X0,
63
+ Yi0,
64
+ Xi0,
65
+ Yi0,
66
+ X0,
67
+ Yi1,
68
+ X0,
69
+ Yi1,
70
+ Xi0,
71
+ Yi0,
72
+ Xi0,
73
+ Yi1,
74
+ // Right strip
75
+ Xi1,
76
+ Yi0,
77
+ X1,
78
+ Yi0,
79
+ Xi1,
80
+ Yi1,
81
+ Xi1,
82
+ Yi1,
83
+ X1,
84
+ Yi0,
85
+ X1,
86
+ Yi1
87
+ ]);
88
+ const uvs = new Float32Array([
89
+ // Top strip
90
+ u0,
91
+ v0,
92
+ u1,
93
+ v0,
94
+ u0,
95
+ vi0,
96
+ u0,
97
+ vi0,
98
+ u1,
99
+ v0,
100
+ u1,
101
+ vi0,
102
+ // Bottom strip
103
+ u0,
104
+ vi1,
105
+ u1,
106
+ vi1,
107
+ u0,
108
+ v1,
109
+ u0,
110
+ v1,
111
+ u1,
112
+ vi1,
113
+ u1,
114
+ v1,
115
+ // Left strip
116
+ u0,
117
+ vi0,
118
+ ui0,
119
+ vi0,
120
+ u0,
121
+ vi1,
122
+ u0,
123
+ vi1,
124
+ ui0,
125
+ vi0,
126
+ ui0,
127
+ vi1,
128
+ // Right strip
129
+ ui1,
130
+ vi0,
131
+ u1,
132
+ vi0,
133
+ ui1,
134
+ vi1,
135
+ ui1,
136
+ vi1,
137
+ u1,
138
+ vi0,
139
+ u1,
140
+ vi1
141
+ ]);
142
+ return { positions, uvs };
143
+ }
144
+ function compileShader(gl, type, source) {
145
+ const shader = gl.createShader(type);
146
+ if (!shader) throw new Error("Failed to create shader");
147
+ gl.shaderSource(shader, source);
148
+ gl.compileShader(shader);
149
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
150
+ const info = gl.getShaderInfoLog(shader) || "Unknown shader error";
151
+ gl.deleteShader(shader);
152
+ throw new Error(info);
153
+ }
154
+ return shader;
155
+ }
156
+ function createProgram(gl, vertexSource, fragmentSource) {
157
+ const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);
158
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
159
+ const program = gl.createProgram();
160
+ if (!program) throw new Error("Failed to create program");
161
+ gl.attachShader(program, vs);
162
+ gl.attachShader(program, fs);
163
+ gl.linkProgram(program);
164
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
165
+ const info = gl.getProgramInfoLog(program) || "Unknown link error";
166
+ gl.deleteProgram(program);
167
+ gl.deleteShader(vs);
168
+ gl.deleteShader(fs);
169
+ throw new Error(info);
170
+ }
171
+ gl.deleteShader(vs);
172
+ gl.deleteShader(fs);
173
+ return program;
174
+ }
175
+ const fragmentShaderSource = `#version 300 es
176
+ precision lowp float;
177
+ in vec2 vUV;
178
+ out vec4 outColor;
179
+ uniform vec2 uResolution;
180
+ uniform float uTime;
181
+ uniform float uBorderWidth;
182
+ uniform float uGlowWidth;
183
+ uniform float uBorderRadius;
184
+ uniform vec3 uColors[4];
185
+ uniform float uGlowExponent;
186
+ uniform float uGlowFactor;
187
+ const float PI = 3.14159265359;
188
+ const float TWO_PI = 2.0 * PI;
189
+ const float HALF_PI = 0.5 * PI;
190
+ const vec4 startPositions = vec4(0.0, PI, HALF_PI, 1.5 * PI);
191
+ const vec4 speeds = vec4(-1.9, -1.9, -1.5, 2.1);
192
+ const vec4 innerRadius = vec4(PI * 0.8, PI * 0.7, PI * 0.3, PI * 0.1);
193
+ const vec4 outerRadius = vec4(PI * 1.2, PI * 0.9, PI * 0.6, PI * 0.4);
194
+ float random(vec2 st) {
195
+ return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
196
+ }
197
+ vec2 random2(vec2 st) {
198
+ return vec2(random(st), random(st + 1.0));
199
+ }
200
+ float aaStep(float edge, float d) {
201
+ float width = fwidth(d);
202
+ return smoothstep(edge - width * 0.5, edge + width * 0.5, d);
203
+ }
204
+ float aaFract(float x) {
205
+ float f = fract(x);
206
+ float w = fwidth(x);
207
+ float smooth_f = f * (1.0 - smoothstep(1.0 - w, 1.0, f));
208
+ return smooth_f;
209
+ }
210
+ float sdRoundedBox(in vec2 p, in vec2 b, in float r) {
211
+ vec2 q = abs(p) - b + r;
212
+ return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r;
213
+ }
214
+ float getInnerGlow(vec2 p, vec2 b, float radius) {
215
+ float dist_x = b.x - abs(p.x);
216
+ float dist_y = b.y - abs(p.y);
217
+ float glow_x = smoothstep(radius, 0.0, dist_x);
218
+ float glow_y = smoothstep(radius, 0.0, dist_y);
219
+ return 1.0 - (1.0 - glow_x) * (1.0 - glow_y);
220
+ }
221
+ float getVignette(vec2 uv) {
222
+ vec2 vignetteUv = uv;
223
+ vignetteUv = vignetteUv * (1.0 - vignetteUv);
224
+ float vignette = vignetteUv.x * vignetteUv.y * 25.0;
225
+ vignette = pow(vignette, 0.16);
226
+ vignette = 1.0 - vignette;
227
+ return vignette;
228
+ }
229
+ float uvToAngle(vec2 uv) {
230
+ vec2 center = vec2(0.5);
231
+ vec2 dir = uv - center;
232
+ return atan(dir.y, dir.x) + PI;
233
+ }
234
+ void main() {
235
+ vec2 uv = vUV;
236
+ vec2 pos = uv * uResolution;
237
+ vec2 centeredPos = pos - uResolution * 0.5;
238
+ vec2 size = uResolution - uBorderWidth;
239
+ vec2 halfSize = size * 0.5;
240
+ float dBorderBox = sdRoundedBox(centeredPos, halfSize, uBorderRadius);
241
+ float border = aaStep(0.0, dBorderBox);
242
+ float glow = getInnerGlow(centeredPos, halfSize, uGlowWidth);
243
+ float vignette = getVignette(uv);
244
+ glow *= vignette;
245
+ float posAngle = uvToAngle(uv);
246
+ vec4 lightCenter = mod(startPositions + speeds * uTime, TWO_PI);
247
+ vec4 angleDist = abs(posAngle - lightCenter);
248
+ vec4 disToLight = min(angleDist, TWO_PI - angleDist) / TWO_PI;
249
+ float intensityBorder[4];
250
+ intensityBorder[0] = 1.0;
251
+ intensityBorder[1] = smoothstep(0.4, 0.0, disToLight.y);
252
+ intensityBorder[2] = smoothstep(0.4, 0.0, disToLight.z);
253
+ intensityBorder[3] = smoothstep(0.2, 0.0, disToLight.w) * 0.5;
254
+ vec3 borderColor = vec3(0.0);
255
+ for(int i = 0; i < 4; i++) {
256
+ borderColor = mix(borderColor, uColors[i], intensityBorder[i]);
257
+ }
258
+ borderColor *= 1.1;
259
+ borderColor = clamp(borderColor, 0.0, 1.0);
260
+ float intensityGlow[4];
261
+ intensityGlow[0] = smoothstep(0.9, 0.0, disToLight.x);
262
+ intensityGlow[1] = smoothstep(0.7, 0.0, disToLight.y);
263
+ intensityGlow[2] = smoothstep(0.4, 0.0, disToLight.z);
264
+ intensityGlow[3] = smoothstep(0.1, 0.0, disToLight.w) * 0.7;
265
+ vec4 breath = smoothstep(0.0, 1.0, sin(uTime * 1.0 + startPositions * PI) * 0.2 + 0.8);
266
+ vec3 glowColor = vec3(0.0);
267
+ glowColor += uColors[0] * intensityGlow[0] * breath.x;
268
+ glowColor += uColors[1] * intensityGlow[1] * breath.y;
269
+ glowColor += uColors[2] * intensityGlow[2] * breath.z;
270
+ glowColor += uColors[3] * intensityGlow[3] * breath.w * glow;
271
+ glow = pow(glow, uGlowExponent);
272
+ glow *= random(pos + uTime) * 0.1 + 1.0;
273
+ glowColor *= glow * uGlowFactor;
274
+ glowColor = clamp(glowColor, 0.0, 1.0);
275
+ vec3 color = mix(glowColor, borderColor + glowColor * 0.2, border);
276
+ float alpha = mix(glow, 1.0, border);
277
+ outColor = vec4(color, alpha);
278
+ }`;
279
+ const vertexShaderSource = `#version 300 es
280
+ in vec2 aPosition;
281
+ in vec2 aUV;
282
+ out vec2 vUV;
283
+ void main() {
284
+ vUV = aUV;
285
+ gl_Position = vec4(aPosition, 0.0, 1.0);
286
+ }`;
287
+ const DEFAULT_COLORS = [
288
+ "rgb(57, 182, 255)",
289
+ "rgb(189, 69, 251)",
290
+ "rgb(255, 87, 51)",
291
+ "rgb(255, 214, 0)"
292
+ ];
293
+ function parseColor(colorStr) {
294
+ const match = colorStr.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
295
+ if (!match) {
296
+ throw new Error(`Invalid color format: ${colorStr}`);
297
+ }
298
+ const [, r, g, b] = match;
299
+ return [parseInt(r) / 255, parseInt(g) / 255, parseInt(b) / 255];
300
+ }
301
+ class Motion {
302
+ element;
303
+ canvas;
304
+ options;
305
+ running = false;
306
+ disposed = false;
307
+ startTime = 0;
308
+ lastTime = 0;
309
+ rafId = null;
310
+ glr;
311
+ observer;
312
+ constructor(options = {}) {
313
+ this.options = {
314
+ width: options.width ?? 600,
315
+ height: options.height ?? 600,
316
+ ratio: options.ratio ?? window.devicePixelRatio ?? 1,
317
+ borderWidth: options.borderWidth ?? 8,
318
+ glowWidth: options.glowWidth ?? 200,
319
+ borderRadius: options.borderRadius ?? 8,
320
+ mode: options.mode ?? "light",
321
+ ...options
322
+ };
323
+ this.canvas = document.createElement("canvas");
324
+ if (this.options.classNames) {
325
+ this.canvas.className = this.options.classNames;
326
+ }
327
+ if (this.options.styles) {
328
+ Object.assign(this.canvas.style, this.options.styles);
329
+ }
330
+ this.canvas.style.display = "block";
331
+ this.canvas.style.transformOrigin = "center";
332
+ this.canvas.style.pointerEvents = "none";
333
+ this.element = this.canvas;
334
+ this.setupGL();
335
+ if (!this.options.skipGreeting) this.greet();
336
+ }
337
+ start() {
338
+ if (this.disposed) throw new Error("Motion instance has been disposed.");
339
+ if (this.running) return;
340
+ if (!this.glr) {
341
+ console.error("WebGL resources are not initialized.");
342
+ return;
343
+ }
344
+ this.running = true;
345
+ this.startTime = performance.now();
346
+ this.resize(this.options.width ?? 600, this.options.height ?? 600, this.options.ratio);
347
+ this.glr.gl.viewport(0, 0, this.canvas.width, this.canvas.height);
348
+ this.glr.gl.useProgram(this.glr.program);
349
+ this.glr.gl.uniform2f(this.glr.uResolution, this.canvas.width, this.canvas.height);
350
+ this.checkGLError(this.glr.gl, "start: after initial setup");
351
+ const loop = () => {
352
+ if (!this.running || !this.glr) return;
353
+ this.rafId = requestAnimationFrame(loop);
354
+ const now = performance.now();
355
+ const delta = now - this.lastTime;
356
+ if (delta < 1e3 / 32) return;
357
+ this.lastTime = now;
358
+ const t = (now - this.startTime) * 1e-3;
359
+ this.render(t);
360
+ };
361
+ this.rafId = requestAnimationFrame(loop);
362
+ }
363
+ pause() {
364
+ if (this.disposed) throw new Error("Motion instance has been disposed.");
365
+ this.running = false;
366
+ if (this.rafId !== null) cancelAnimationFrame(this.rafId);
367
+ }
368
+ dispose() {
369
+ if (this.disposed) return;
370
+ this.disposed = true;
371
+ this.running = false;
372
+ if (this.rafId !== null) cancelAnimationFrame(this.rafId);
373
+ const { gl, vao, positionBuffer, uvBuffer, program } = this.glr;
374
+ if (vao) gl.deleteVertexArray(vao);
375
+ if (positionBuffer) gl.deleteBuffer(positionBuffer);
376
+ if (uvBuffer) gl.deleteBuffer(uvBuffer);
377
+ gl.deleteProgram(program);
378
+ if (this.observer) this.observer.disconnect();
379
+ this.canvas.remove();
380
+ }
381
+ resize(width, height, ratio) {
382
+ if (this.disposed) throw new Error("Motion instance has been disposed.");
383
+ this.options.width = width;
384
+ this.options.height = height;
385
+ if (ratio) this.options.ratio = ratio;
386
+ if (!this.running) return;
387
+ const { gl, program, vao, positionBuffer, uvBuffer, uResolution } = this.glr;
388
+ const dpr = ratio ?? this.options.ratio ?? window.devicePixelRatio ?? 1;
389
+ const desiredWidth = Math.max(1, Math.floor(width * dpr));
390
+ const desiredHeight = Math.max(1, Math.floor(height * dpr));
391
+ this.canvas.style.width = `${width}px`;
392
+ this.canvas.style.height = `${height}px`;
393
+ if (this.canvas.width !== desiredWidth || this.canvas.height !== desiredHeight) {
394
+ this.canvas.width = desiredWidth;
395
+ this.canvas.height = desiredHeight;
396
+ }
397
+ gl.viewport(0, 0, this.canvas.width, this.canvas.height);
398
+ this.checkGLError(gl, "resize: after viewport setup");
399
+ const { positions, uvs } = computeBorderGeometry(
400
+ this.canvas.width,
401
+ this.canvas.height,
402
+ this.options.borderWidth * dpr,
403
+ this.options.glowWidth * dpr
404
+ );
405
+ gl.bindVertexArray(vao);
406
+ gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
407
+ gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
408
+ const aPosition = gl.getAttribLocation(program, "aPosition");
409
+ gl.enableVertexAttribArray(aPosition);
410
+ gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, 0, 0);
411
+ this.checkGLError(gl, "resize: after position buffer update");
412
+ gl.bindBuffer(gl.ARRAY_BUFFER, uvBuffer);
413
+ gl.bufferData(gl.ARRAY_BUFFER, uvs, gl.STATIC_DRAW);
414
+ const aUV = gl.getAttribLocation(program, "aUV");
415
+ gl.enableVertexAttribArray(aUV);
416
+ gl.vertexAttribPointer(aUV, 2, gl.FLOAT, false, 0, 0);
417
+ this.checkGLError(gl, "resize: after UV buffer update");
418
+ gl.useProgram(program);
419
+ gl.uniform2f(uResolution, this.canvas.width, this.canvas.height);
420
+ gl.uniform1f(this.glr.uBorderWidth, this.options.borderWidth * dpr);
421
+ gl.uniform1f(this.glr.uGlowWidth, this.options.glowWidth * dpr);
422
+ gl.uniform1f(this.glr.uBorderRadius, this.options.borderRadius * dpr);
423
+ this.checkGLError(gl, "resize: after uniform updates");
424
+ const now = performance.now();
425
+ this.lastTime = now;
426
+ const t = (now - this.startTime) * 1e-3;
427
+ this.render(t);
428
+ }
429
+ /**
430
+ * Automatically resizes the canvas to match the dimensions of the given element.
431
+ * @note using ResizeObserver
432
+ */
433
+ autoResize(sourceElement) {
434
+ if (this.observer) {
435
+ this.observer.disconnect();
436
+ }
437
+ this.observer = new ResizeObserver(() => {
438
+ const rect = sourceElement.getBoundingClientRect();
439
+ this.resize(rect.width, rect.height);
440
+ });
441
+ this.observer.observe(sourceElement);
442
+ }
443
+ fadeIn() {
444
+ if (this.disposed) throw new Error("Motion instance has been disposed.");
445
+ return new Promise((resolve, reject) => {
446
+ const animation = this.canvas.animate(
447
+ [
448
+ { opacity: 0, transform: "scale(1.2)" },
449
+ { opacity: 1, transform: "scale(1)" }
450
+ ],
451
+ { duration: 300, easing: "ease-out", fill: "forwards" }
452
+ );
453
+ animation.onfinish = () => resolve();
454
+ animation.oncancel = () => reject("canceled");
455
+ });
456
+ }
457
+ fadeOut() {
458
+ if (this.disposed) throw new Error("Motion instance has been disposed.");
459
+ return new Promise((resolve, reject) => {
460
+ const animation = this.canvas.animate(
461
+ [
462
+ { opacity: 1, transform: "scale(1)" },
463
+ { opacity: 0, transform: "scale(1.2)" }
464
+ ],
465
+ { duration: 300, easing: "ease-in", fill: "forwards" }
466
+ );
467
+ animation.onfinish = () => resolve();
468
+ animation.oncancel = () => reject("canceled");
469
+ });
470
+ }
471
+ checkGLError(gl, context) {
472
+ let error = gl.getError();
473
+ if (error !== gl.NO_ERROR) {
474
+ console.group(`🔴 WebGL Error in ${context}`);
475
+ while (error !== gl.NO_ERROR) {
476
+ const errorName = this.getGLErrorName(gl, error);
477
+ console.error(`${errorName} (0x${error.toString(16)})`);
478
+ error = gl.getError();
479
+ }
480
+ console.groupEnd();
481
+ }
482
+ }
483
+ getGLErrorName(gl, error) {
484
+ switch (error) {
485
+ case gl.INVALID_ENUM:
486
+ return "INVALID_ENUM";
487
+ case gl.INVALID_VALUE:
488
+ return "INVALID_VALUE";
489
+ case gl.INVALID_OPERATION:
490
+ return "INVALID_OPERATION";
491
+ case gl.INVALID_FRAMEBUFFER_OPERATION:
492
+ return "INVALID_FRAMEBUFFER_OPERATION";
493
+ case gl.OUT_OF_MEMORY:
494
+ return "OUT_OF_MEMORY";
495
+ case gl.CONTEXT_LOST_WEBGL:
496
+ return "CONTEXT_LOST_WEBGL";
497
+ default:
498
+ return "UNKNOWN_ERROR";
499
+ }
500
+ }
501
+ setupGL() {
502
+ const gl = this.canvas.getContext("webgl2", { antialias: false, alpha: true });
503
+ if (!gl) {
504
+ throw new Error("WebGL2 is required but not available.");
505
+ }
506
+ const program = createProgram(gl, vertexShaderSource, fragmentShaderSource);
507
+ this.checkGLError(gl, "setupGL: after createProgram");
508
+ const vao = gl.createVertexArray();
509
+ gl.bindVertexArray(vao);
510
+ this.checkGLError(gl, "setupGL: after VAO creation");
511
+ const pw = this.canvas.width || 2;
512
+ const ph = this.canvas.height || 2;
513
+ const { positions, uvs } = computeBorderGeometry(
514
+ pw,
515
+ ph,
516
+ this.options.borderWidth,
517
+ this.options.glowWidth
518
+ );
519
+ const positionBuffer = gl.createBuffer();
520
+ gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
521
+ gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
522
+ const aPosition = gl.getAttribLocation(program, "aPosition");
523
+ gl.enableVertexAttribArray(aPosition);
524
+ gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, 0, 0);
525
+ this.checkGLError(gl, "setupGL: after position buffer setup");
526
+ const uvBuffer = gl.createBuffer();
527
+ gl.bindBuffer(gl.ARRAY_BUFFER, uvBuffer);
528
+ gl.bufferData(gl.ARRAY_BUFFER, uvs, gl.STATIC_DRAW);
529
+ const aUV = gl.getAttribLocation(program, "aUV");
530
+ gl.enableVertexAttribArray(aUV);
531
+ gl.vertexAttribPointer(aUV, 2, gl.FLOAT, false, 0, 0);
532
+ this.checkGLError(gl, "setupGL: after UV buffer setup");
533
+ const uResolution = gl.getUniformLocation(program, "uResolution");
534
+ const uTime = gl.getUniformLocation(program, "uTime");
535
+ const uBorderWidth = gl.getUniformLocation(program, "uBorderWidth");
536
+ const uGlowWidth = gl.getUniformLocation(program, "uGlowWidth");
537
+ const uBorderRadius = gl.getUniformLocation(program, "uBorderRadius");
538
+ const uColors = gl.getUniformLocation(program, "uColors");
539
+ const uGlowExponent = gl.getUniformLocation(program, "uGlowExponent");
540
+ const uGlowFactor = gl.getUniformLocation(program, "uGlowFactor");
541
+ gl.useProgram(program);
542
+ gl.uniform1f(uBorderWidth, this.options.borderWidth);
543
+ gl.uniform1f(uGlowWidth, this.options.glowWidth);
544
+ gl.uniform1f(uBorderRadius, this.options.borderRadius);
545
+ if (this.options.mode === "dark") {
546
+ gl.uniform1f(uGlowExponent, 2);
547
+ gl.uniform1f(uGlowFactor, 1.8);
548
+ } else {
549
+ gl.uniform1f(uGlowExponent, 1);
550
+ gl.uniform1f(uGlowFactor, 1);
551
+ }
552
+ const colorVecs = (this.options.colors || DEFAULT_COLORS).map(parseColor);
553
+ for (let i = 0; i < colorVecs.length; i++) {
554
+ gl.uniform3f(gl.getUniformLocation(program, `uColors[${i}]`), ...colorVecs[i]);
555
+ }
556
+ this.checkGLError(gl, "setupGL: after uniform setup");
557
+ gl.bindVertexArray(null);
558
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
559
+ this.glr = {
560
+ gl,
561
+ program,
562
+ vao,
563
+ positionBuffer,
564
+ uvBuffer,
565
+ uResolution,
566
+ uTime,
567
+ uBorderWidth,
568
+ uGlowWidth,
569
+ uBorderRadius,
570
+ uColors
571
+ };
572
+ }
573
+ render(t) {
574
+ if (!this.glr) return;
575
+ const { gl, program, vao, uTime } = this.glr;
576
+ gl.useProgram(program);
577
+ gl.bindVertexArray(vao);
578
+ gl.uniform1f(uTime, t);
579
+ gl.disable(gl.DEPTH_TEST);
580
+ gl.disable(gl.CULL_FACE);
581
+ gl.disable(gl.BLEND);
582
+ gl.clearColor(0, 0, 0, 0);
583
+ gl.clear(gl.COLOR_BUFFER_BIT);
584
+ gl.drawArrays(gl.TRIANGLES, 0, 24);
585
+ this.checkGLError(gl, "render: after draw call");
586
+ gl.bindVertexArray(null);
587
+ }
588
+ greet() {
589
+ console.log(
590
+ `%c🌈 ai-motion ${"0.4.8"} 🌈`,
591
+ "background: linear-gradient(90deg, #39b6ff, #bd45fb, #ff5733, #ffd600); color: white; text-shadow: 0 0 2px rgba(0, 0, 0, 0.2); font-weight: bold; font-size: 1em; padding: 2px 12px; border-radius: 6px;"
592
+ );
593
+ }
594
+ }
595
+ (function() {
596
+ try {
597
+ if (typeof document != "undefined") {
598
+ var elementStyle = document.createElement("style");
599
+ elementStyle.appendChild(document.createTextNode(`._wrapper_1ooyb_1 {
600
+ position: fixed;
601
+ inset: 0;
602
+ z-index: 2147483641; /* 确保在所有元素之上,除了 panel */
603
+ cursor: wait;
604
+ overflow: hidden;
605
+
606
+ display: none;
607
+ }
608
+
609
+ ._wrapper_1ooyb_1._visible_1ooyb_11 {
610
+ display: block;
611
+ }
612
+ /* AI 光标样式 */
613
+ ._cursor_1dgwb_2 {
614
+ position: absolute;
615
+ width: var(--cursor-size, 75px);
616
+ height: var(--cursor-size, 75px);
617
+ pointer-events: none;
618
+ z-index: 10000;
619
+ }
620
+
621
+ ._cursorBorder_1dgwb_10 {
622
+ position: absolute;
623
+ width: 100%;
624
+ height: 100%;
625
+ background: linear-gradient(45deg, rgb(57, 182, 255), rgb(189, 69, 251));
626
+ 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");
627
+ mask-size: 100% 100%;
628
+ mask-repeat: no-repeat;
629
+
630
+ transform-origin: center;
631
+ transform: rotate(-135deg) scale(1.2);
632
+ margin-left: -10px;
633
+ margin-top: -18px;
634
+ }
635
+
636
+ ._cursorFilling_1dgwb_25 {
637
+ position: absolute;
638
+ width: 100%;
639
+ height: 100%;
640
+ 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");
641
+ background-size: 100% 100%;
642
+ background-repeat: no-repeat;
643
+
644
+ transform-origin: center;
645
+ transform: rotate(-135deg) scale(1.2);
646
+ margin-left: -10px;
647
+ margin-top: -18px;
648
+ }
649
+
650
+ ._cursorRipple_1dgwb_39 {
651
+ position: absolute;
652
+ width: 100%;
653
+ height: 100%;
654
+ pointer-events: none;
655
+ margin-left: -50%;
656
+ margin-top: -50%;
657
+
658
+ &::after {
659
+ content: '';
660
+ opacity: 0;
661
+ position: absolute;
662
+ inset: 0;
663
+ border: 4px solid rgba(57, 182, 255, 1);
664
+ border-radius: 50%;
665
+ }
666
+ }
667
+
668
+ ._cursor_1dgwb_2._clicking_1dgwb_57 ._cursorRipple_1dgwb_39::after {
669
+ animation: _cursor-ripple_1dgwb_1 300ms ease-out forwards;
670
+ }
671
+
672
+ @keyframes _cursor-ripple_1dgwb_1 {
673
+ 0% {
674
+ transform: scale(0);
675
+ opacity: 1;
676
+ }
677
+ 100% {
678
+ transform: scale(2);
679
+ opacity: 0;
680
+ }
681
+ }`));
682
+ document.head.appendChild(elementStyle);
683
+ }
684
+ } catch (e) {
685
+ console.error("vite-plugin-css-injected-by-js", e);
686
+ }
687
+ })();
688
+ (function() {
689
+ try {
690
+ if (typeof document != "undefined") {
691
+ var elementStyle = document.createElement("style");
692
+ elementStyle.appendChild(document.createTextNode(`._wrapper_1ooyb_1 {
693
+ position: fixed;
694
+ inset: 0;
695
+ z-index: 2147483641; /* 确保在所有元素之上,除了 panel */
696
+ cursor: wait;
697
+ overflow: hidden;
698
+
699
+ display: none;
700
+ }
701
+
702
+ ._wrapper_1ooyb_1._visible_1ooyb_11 {
703
+ display: block;
704
+ }
705
+ /* AI 光标样式 */
706
+ ._cursor_1dgwb_2 {
707
+ position: absolute;
708
+ width: var(--cursor-size, 75px);
709
+ height: var(--cursor-size, 75px);
710
+ pointer-events: none;
711
+ z-index: 10000;
712
+ }
713
+
714
+ ._cursorBorder_1dgwb_10 {
715
+ position: absolute;
716
+ width: 100%;
717
+ height: 100%;
718
+ background: linear-gradient(45deg, rgb(57, 182, 255), rgb(189, 69, 251));
719
+ 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");
720
+ mask-size: 100% 100%;
721
+ mask-repeat: no-repeat;
722
+
723
+ transform-origin: center;
724
+ transform: rotate(-135deg) scale(1.2);
725
+ margin-left: -10px;
726
+ margin-top: -18px;
727
+ }
728
+
729
+ ._cursorFilling_1dgwb_25 {
730
+ position: absolute;
731
+ width: 100%;
732
+ height: 100%;
733
+ 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");
734
+ background-size: 100% 100%;
735
+ background-repeat: no-repeat;
736
+
737
+ transform-origin: center;
738
+ transform: rotate(-135deg) scale(1.2);
739
+ margin-left: -10px;
740
+ margin-top: -18px;
741
+ }
742
+
743
+ ._cursorRipple_1dgwb_39 {
744
+ position: absolute;
745
+ width: 100%;
746
+ height: 100%;
747
+ pointer-events: none;
748
+ margin-left: -50%;
749
+ margin-top: -50%;
750
+
751
+ &::after {
752
+ content: '';
753
+ opacity: 0;
754
+ position: absolute;
755
+ inset: 0;
756
+ border: 4px solid rgba(57, 182, 255, 1);
757
+ border-radius: 50%;
758
+ }
759
+ }
760
+
761
+ ._cursor_1dgwb_2._clicking_1dgwb_57 ._cursorRipple_1dgwb_39::after {
762
+ animation: _cursor-ripple_1dgwb_1 300ms ease-out forwards;
763
+ }
764
+
765
+ @keyframes _cursor-ripple_1dgwb_1 {
766
+ 0% {
767
+ transform: scale(0);
768
+ opacity: 1;
769
+ }
770
+ 100% {
771
+ transform: scale(2);
772
+ opacity: 0;
773
+ }
774
+ }`));
775
+ document.head.appendChild(elementStyle);
776
+ }
777
+ } catch (e) {
778
+ console.error("vite-plugin-css-injected-by-js", e);
779
+ }
780
+ })();
781
+ function isPageDark() {
782
+ try {
783
+ if (hasDarkModeClass()) return true;
784
+ if (hasDarkModeDataAttribute()) return true;
785
+ if (isColorSchemeDark()) return true;
786
+ if (isBackgroundDark()) return true;
787
+ if (isMainContentBackgroundDark()) return true;
788
+ if (isTextColorLight()) return true;
789
+ return false;
790
+ } catch (error) {
791
+ console.warn("Error determining if page is dark:", error);
792
+ return false;
793
+ }
794
+ }
795
+ function hasDarkModeClass() {
796
+ const DEFAULT_DARK_MODE_CLASSES = [
797
+ "dark",
798
+ "dark-mode",
799
+ "theme-dark",
800
+ "night",
801
+ "night-mode"
802
+ ];
803
+ const htmlElement = document.documentElement;
804
+ const bodyElement = document.body || document.documentElement;
805
+ for (const className of DEFAULT_DARK_MODE_CLASSES) if (htmlElement.classList.contains(className) || bodyElement?.classList.contains(className)) return true;
806
+ return false;
807
+ }
808
+ function hasDarkModeDataAttribute() {
809
+ const htmlElement = document.documentElement;
810
+ const bodyElement = document.body || document.documentElement;
811
+ for (const attr of [
812
+ "data-theme",
813
+ "data-color-mode",
814
+ "data-bs-theme",
815
+ "data-mui-color-scheme"
816
+ ]) {
817
+ const bodyValue = bodyElement?.getAttribute(attr);
818
+ const htmlValue = htmlElement.getAttribute(attr);
819
+ if (bodyValue?.toLowerCase() === "dark" || htmlValue?.toLowerCase() === "dark") return true;
820
+ }
821
+ return false;
822
+ }
823
+ function isColorSchemeDark() {
824
+ const metaContent = document.querySelector('meta[name="color-scheme"]')?.content.toLowerCase();
825
+ if (metaContent === "dark" || metaContent === "only dark") return true;
826
+ const colorScheme = window.getComputedStyle(document.documentElement).getPropertyValue("color-scheme").trim().toLowerCase();
827
+ return colorScheme === "dark" || colorScheme === "only dark";
828
+ }
829
+ function isBackgroundDark() {
830
+ const htmlStyle = window.getComputedStyle(document.documentElement);
831
+ const bodyStyle = window.getComputedStyle(document.body || document.documentElement);
832
+ const htmlBgColor = htmlStyle.backgroundColor;
833
+ const bodyBgColor = bodyStyle.backgroundColor;
834
+ if (isColorDark(bodyBgColor)) return true;
835
+ else if (bodyBgColor === "transparent" || bodyBgColor.startsWith("rgba(0, 0, 0, 0)")) return isColorDark(htmlBgColor);
836
+ return false;
837
+ }
838
+ function isTextColorLight() {
839
+ const LIGHT_TEXT_LUMINANCE = 200;
840
+ const luminance = getLuminance(window.getComputedStyle(document.body || document.documentElement).color);
841
+ return luminance !== null && luminance > LIGHT_TEXT_LUMINANCE;
842
+ }
843
+ function isMainContentBackgroundDark() {
844
+ const { innerWidth: vw, innerHeight: vh } = window;
845
+ const minArea = vw * vh * 0.5;
846
+ for (const selector of [
847
+ "#app",
848
+ "#root",
849
+ "#__next"
850
+ ]) {
851
+ const el = document.querySelector(selector);
852
+ if (!el) continue;
853
+ const rect = el.getBoundingClientRect();
854
+ if (rect.width * rect.height < minArea) continue;
855
+ if (isColorDark(window.getComputedStyle(el).backgroundColor)) return true;
856
+ }
857
+ return false;
858
+ }
859
+ function parseRgbColor(colorString) {
860
+ const rgbMatch = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(colorString);
861
+ if (!rgbMatch) return null;
862
+ return {
863
+ r: parseInt(rgbMatch[1]),
864
+ g: parseInt(rgbMatch[2]),
865
+ b: parseInt(rgbMatch[3])
866
+ };
867
+ }
868
+ function getLuminance(colorString) {
869
+ if (!colorString || colorString === "transparent" || colorString.startsWith("rgba(0, 0, 0, 0)")) return null;
870
+ const rgb = parseRgbColor(colorString);
871
+ if (!rgb) return null;
872
+ return 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b;
873
+ }
874
+ function isColorDark(colorString, threshold = 128) {
875
+ const luminance = getLuminance(colorString);
876
+ return luminance !== null && luminance < threshold;
877
+ }
878
+ var SimulatorMask_module_default = {
879
+ wrapper: "_wrapper_1ooyb_1",
880
+ visible: "_visible_1ooyb_11"
881
+ };
882
+ var cursor_module_default = {
883
+ cursor: "_cursor_1dgwb_2",
884
+ cursorBorder: "_cursorBorder_1dgwb_10",
885
+ cursorFilling: "_cursorFilling_1dgwb_25",
886
+ cursorRipple: "_cursorRipple_1dgwb_39",
887
+ clicking: "_clicking_1dgwb_57"
888
+ };
889
+ var SimulatorMask = class extends EventTarget {
890
+ shown = false;
891
+ wrapper = document.createElement("div");
892
+ motion = null;
893
+ #disposed = false;
894
+ #cursor = document.createElement("div");
895
+ #currentCursorX = 0;
896
+ #currentCursorY = 0;
897
+ #targetCursorX = 0;
898
+ #targetCursorY = 0;
899
+ constructor() {
900
+ super();
901
+ this.wrapper.id = "page-agent-runtime_simulator-mask";
902
+ this.wrapper.className = SimulatorMask_module_default.wrapper;
903
+ this.wrapper.setAttribute("data-browser-use-ignore", "true");
904
+ this.wrapper.setAttribute("data-page-agent-ignore", "true");
905
+ try {
906
+ const motion = new Motion({
907
+ mode: isPageDark() ? "dark" : "light",
908
+ styles: {
909
+ position: "absolute",
910
+ inset: "0"
911
+ }
912
+ });
913
+ this.motion = motion;
914
+ this.wrapper.appendChild(motion.element);
915
+ motion.autoResize(this.wrapper);
916
+ } catch (e) {
917
+ console.warn("[SimulatorMask] Motion overlay unavailable:", e);
918
+ }
919
+ this.wrapper.addEventListener("click", (e) => {
920
+ e.stopPropagation();
921
+ e.preventDefault();
922
+ });
923
+ this.wrapper.addEventListener("mousedown", (e) => {
924
+ e.stopPropagation();
925
+ e.preventDefault();
926
+ });
927
+ this.wrapper.addEventListener("mouseup", (e) => {
928
+ e.stopPropagation();
929
+ e.preventDefault();
930
+ });
931
+ this.wrapper.addEventListener("mousemove", (e) => {
932
+ e.stopPropagation();
933
+ e.preventDefault();
934
+ });
935
+ this.wrapper.addEventListener("wheel", (e) => {
936
+ e.stopPropagation();
937
+ e.preventDefault();
938
+ });
939
+ this.wrapper.addEventListener("keydown", (e) => {
940
+ e.stopPropagation();
941
+ e.preventDefault();
942
+ });
943
+ this.wrapper.addEventListener("keyup", (e) => {
944
+ e.stopPropagation();
945
+ e.preventDefault();
946
+ });
947
+ this.#createCursor();
948
+ document.body.appendChild(this.wrapper);
949
+ this.#moveCursorToTarget();
950
+ const movePointerToListener = (event) => {
951
+ const { x, y } = event.detail;
952
+ this.setCursorPosition(x, y);
953
+ };
954
+ const clickPointerListener = () => {
955
+ this.triggerClickAnimation();
956
+ };
957
+ const enablePassThroughListener = () => {
958
+ this.wrapper.style.pointerEvents = "none";
959
+ };
960
+ const disablePassThroughListener = () => {
961
+ this.wrapper.style.pointerEvents = "auto";
962
+ };
963
+ window.addEventListener("PageAgent::MovePointerTo", movePointerToListener);
964
+ window.addEventListener("PageAgent::ClickPointer", clickPointerListener);
965
+ window.addEventListener("PageAgent::EnablePassThrough", enablePassThroughListener);
966
+ window.addEventListener("PageAgent::DisablePassThrough", disablePassThroughListener);
967
+ this.addEventListener("dispose", () => {
968
+ window.removeEventListener("PageAgent::MovePointerTo", movePointerToListener);
969
+ window.removeEventListener("PageAgent::ClickPointer", clickPointerListener);
970
+ window.removeEventListener("PageAgent::EnablePassThrough", enablePassThroughListener);
971
+ window.removeEventListener("PageAgent::DisablePassThrough", disablePassThroughListener);
972
+ });
973
+ }
974
+ #createCursor() {
975
+ this.#cursor.className = cursor_module_default.cursor;
976
+ const rippleContainer = document.createElement("div");
977
+ rippleContainer.className = cursor_module_default.cursorRipple;
978
+ this.#cursor.appendChild(rippleContainer);
979
+ const fillingLayer = document.createElement("div");
980
+ fillingLayer.className = cursor_module_default.cursorFilling;
981
+ this.#cursor.appendChild(fillingLayer);
982
+ const borderLayer = document.createElement("div");
983
+ borderLayer.className = cursor_module_default.cursorBorder;
984
+ this.#cursor.appendChild(borderLayer);
985
+ this.wrapper.appendChild(this.#cursor);
986
+ }
987
+ #moveCursorToTarget() {
988
+ if (this.#disposed) return;
989
+ const newX = this.#currentCursorX + (this.#targetCursorX - this.#currentCursorX) * 0.2;
990
+ const newY = this.#currentCursorY + (this.#targetCursorY - this.#currentCursorY) * 0.2;
991
+ const xDistance = Math.abs(newX - this.#targetCursorX);
992
+ if (xDistance > 0) {
993
+ if (xDistance < 2) this.#currentCursorX = this.#targetCursorX;
994
+ else this.#currentCursorX = newX;
995
+ this.#cursor.style.left = `${this.#currentCursorX}px`;
996
+ }
997
+ const yDistance = Math.abs(newY - this.#targetCursorY);
998
+ if (yDistance > 0) {
999
+ if (yDistance < 2) this.#currentCursorY = this.#targetCursorY;
1000
+ else this.#currentCursorY = newY;
1001
+ this.#cursor.style.top = `${this.#currentCursorY}px`;
1002
+ }
1003
+ requestAnimationFrame(() => this.#moveCursorToTarget());
1004
+ }
1005
+ setCursorPosition(x, y) {
1006
+ if (this.#disposed) return;
1007
+ this.#targetCursorX = x;
1008
+ this.#targetCursorY = y;
1009
+ }
1010
+ triggerClickAnimation() {
1011
+ if (this.#disposed) return;
1012
+ this.#cursor.classList.remove(cursor_module_default.clicking);
1013
+ this.#cursor.offsetHeight;
1014
+ this.#cursor.classList.add(cursor_module_default.clicking);
1015
+ }
1016
+ show() {
1017
+ if (this.shown || this.#disposed) return;
1018
+ this.shown = true;
1019
+ this.motion?.start();
1020
+ this.motion?.fadeIn();
1021
+ this.wrapper.classList.add(SimulatorMask_module_default.visible);
1022
+ this.#currentCursorX = window.innerWidth / 2;
1023
+ this.#currentCursorY = window.innerHeight / 2;
1024
+ this.#targetCursorX = this.#currentCursorX;
1025
+ this.#targetCursorY = this.#currentCursorY;
1026
+ this.#cursor.style.left = `${this.#currentCursorX}px`;
1027
+ this.#cursor.style.top = `${this.#currentCursorY}px`;
1028
+ }
1029
+ hide() {
1030
+ if (!this.shown || this.#disposed) return;
1031
+ this.shown = false;
1032
+ this.motion?.fadeOut();
1033
+ this.motion?.pause();
1034
+ this.#cursor.classList.remove(cursor_module_default.clicking);
1035
+ setTimeout(() => {
1036
+ this.wrapper.classList.remove(SimulatorMask_module_default.visible);
1037
+ }, 800);
1038
+ }
1039
+ dispose() {
1040
+ this.#disposed = true;
1041
+ this.motion?.dispose();
1042
+ this.wrapper.remove();
1043
+ this.dispatchEvent(new Event("dispose"));
1044
+ }
1045
+ };
1046
+ export {
1047
+ SimulatorMask
1048
+ };