@namzu/computer-use 4.1.0 → 4.2.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 (75) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/SubprocessComputerUseHost.d.ts +18 -1
  3. package/dist/SubprocessComputerUseHost.d.ts.map +1 -1
  4. package/dist/SubprocessComputerUseHost.js +28 -2
  5. package/dist/SubprocessComputerUseHost.js.map +1 -1
  6. package/dist/a11y/a11y-script.d.ts +47 -0
  7. package/dist/a11y/a11y-script.d.ts.map +1 -0
  8. package/dist/a11y/a11y-script.js +738 -0
  9. package/dist/a11y/a11y-script.js.map +1 -0
  10. package/dist/a11y/a11y.d.ts +60 -0
  11. package/dist/a11y/a11y.d.ts.map +1 -0
  12. package/dist/a11y/a11y.js +400 -0
  13. package/dist/a11y/a11y.js.map +1 -0
  14. package/dist/a11y/index.d.ts +8 -0
  15. package/dist/a11y/index.d.ts.map +1 -0
  16. package/dist/a11y/index.js +5 -0
  17. package/dist/a11y/index.js.map +1 -0
  18. package/dist/a11y/interface.d.ts +198 -0
  19. package/dist/a11y/interface.d.ts.map +1 -0
  20. package/dist/a11y/interface.js +22 -0
  21. package/dist/a11y/interface.js.map +1 -0
  22. package/dist/a11y/windows.d.ts +20 -0
  23. package/dist/a11y/windows.d.ts.map +1 -0
  24. package/dist/a11y/windows.js +40 -0
  25. package/dist/a11y/windows.js.map +1 -0
  26. package/dist/adapters/cua-driver/adapter.d.ts +47 -0
  27. package/dist/adapters/cua-driver/adapter.d.ts.map +1 -1
  28. package/dist/adapters/cua-driver/adapter.js +138 -3
  29. package/dist/adapters/cua-driver/adapter.js.map +1 -1
  30. package/dist/adapters/types.d.ts +11 -0
  31. package/dist/adapters/types.d.ts.map +1 -1
  32. package/dist/adapters/types.js.map +1 -1
  33. package/dist/adapters/win32.d.ts +3 -0
  34. package/dist/adapters/win32.d.ts.map +1 -1
  35. package/dist/adapters/win32.js +1 -0
  36. package/dist/adapters/win32.js.map +1 -1
  37. package/dist/foreground/guard.d.ts.map +1 -1
  38. package/dist/foreground/guard.js +1 -0
  39. package/dist/foreground/guard.js.map +1 -1
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +1 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/presence/helper-script.d.ts +18 -11
  45. package/dist/presence/helper-script.d.ts.map +1 -1
  46. package/dist/presence/helper-script.js +301 -86
  47. package/dist/presence/helper-script.js.map +1 -1
  48. package/dist/presence/index.d.ts +3 -1
  49. package/dist/presence/index.d.ts.map +1 -1
  50. package/dist/presence/index.js +2 -1
  51. package/dist/presence/index.js.map +1 -1
  52. package/dist/presence/motion.d.ts +84 -0
  53. package/dist/presence/motion.d.ts.map +1 -0
  54. package/dist/presence/motion.js +114 -0
  55. package/dist/presence/motion.js.map +1 -0
  56. package/dist/presence/preview.d.ts +25 -0
  57. package/dist/presence/preview.d.ts.map +1 -0
  58. package/dist/presence/preview.js +32 -0
  59. package/dist/presence/preview.js.map +1 -0
  60. package/package.json +2 -2
  61. package/src/SubprocessComputerUseHost.ts +48 -1
  62. package/src/a11y/a11y-script.ts +740 -0
  63. package/src/a11y/a11y.ts +499 -0
  64. package/src/a11y/index.ts +24 -0
  65. package/src/a11y/interface.ts +226 -0
  66. package/src/a11y/windows.ts +56 -0
  67. package/src/adapters/cua-driver/adapter.ts +151 -6
  68. package/src/adapters/types.ts +8 -0
  69. package/src/adapters/win32.ts +4 -0
  70. package/src/foreground/guard.ts +1 -0
  71. package/src/index.ts +19 -0
  72. package/src/presence/helper-script.ts +327 -87
  73. package/src/presence/index.ts +10 -1
  74. package/src/presence/motion.ts +141 -0
  75. package/src/presence/preview.ts +42 -0
@@ -0,0 +1,141 @@
1
+ /**
2
+ * The numbers and the small maths of the presence overlay's motion. The helper
3
+ * script is C# inside a string and cannot be unit-tested from here, so the
4
+ * constants live here and are written into it, and the formulas are written
5
+ * once more in plain TypeScript as the reference the tests pin; the C# in
6
+ * `helper-script.ts` follows them line for line.
7
+ *
8
+ * Sizes are in logical pixels: the helper multiplies them by the operated
9
+ * window's display scale (its DPI divided by 96).
10
+ */
11
+
12
+ /** The shortest glide, for a pointer that has hardly to move. */
13
+ export const GLIDE_MIN_MS = 140
14
+ /** The longest glide, however far the pointer goes. */
15
+ export const GLIDE_MAX_MS = 420
16
+ /** Added to the shortest glide per logical pixel travelled, up to the longest. */
17
+ export const GLIDE_MS_PER_PX = 0.45
18
+ /** How far the path bows away from a straight line, as a fraction of its length. */
19
+ export const GLIDE_BOW = 0.1
20
+
21
+ /** The first appearance in a window: fade in and grow from {@link APPEAR_FROM_SCALE}. */
22
+ export const APPEAR_MS = 160
23
+ export const APPEAR_FROM_SCALE = 0.85
24
+
25
+ /** How long the pointer and frame stay after the last action, then fade. */
26
+ export const HOLD_MS = 2_000
27
+ export const FADE_MS = 500
28
+
29
+ /** A click: the pointer dips to {@link DIP_SCALE} and returns. */
30
+ export const DIP_SCALE = 0.88
31
+ export const DIP_DOWN_MS = 70
32
+ export const DIP_UP_MS = 110
33
+
34
+ /** The ripple around the tip: a click's, then a key press's (smaller and softer). */
35
+ export const RIPPLE_MS = 420
36
+ export const CLICK_RIPPLE = { from: 5, to: 26, alpha: 0.55, stroke: 2 } as const
37
+ export const KEY_RIPPLE = { from: 4, to: 14, alpha: 0.35, stroke: 1.5 } as const
38
+
39
+ /** The frame breathes by this fraction of its opacity over this period. */
40
+ export const FRAME_PULSE_MS = 2_400
41
+ export const FRAME_PULSE_DEPTH = 0.08
42
+
43
+ export interface Point {
44
+ readonly x: number
45
+ readonly y: number
46
+ }
47
+
48
+ const clamp = (v: number, lo: number, hi: number): number => (v < lo ? lo : v > hi ? hi : v)
49
+
50
+ /** Slow, fast, slow: the glide's timing curve. `u` runs 0 to 1. */
51
+ export function easeInOut(u: number): number {
52
+ const t = clamp(u, 0, 1)
53
+ return t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2
54
+ }
55
+
56
+ /** Fast, then settling: the ripple's and the appearance's curve. */
57
+ export function easeOut(u: number): number {
58
+ return 1 - (1 - clamp(u, 0, 1)) ** 3
59
+ }
60
+
61
+ /** How long a glide over `logicalDistance` pixels takes, in whole milliseconds. */
62
+ export function glideDurationMs(logicalDistance: number): number {
63
+ return Math.round(
64
+ clamp(GLIDE_MIN_MS + logicalDistance * GLIDE_MS_PER_PX, GLIDE_MIN_MS, GLIDE_MAX_MS),
65
+ )
66
+ }
67
+
68
+ /**
69
+ * The control point of the glide's quadratic curve: the middle of the path,
70
+ * moved sideways by {@link GLIDE_BOW} of its length. The side depends on the
71
+ * line alone, never on which way it is travelled (up on the screen; to the
72
+ * right for a vertical line), so going to a point and back bows to the same
73
+ * side both times instead of zigzagging.
74
+ */
75
+ export function glideControl(from: Point, to: Point): Point {
76
+ const dx = to.x - from.x
77
+ const dy = to.y - from.y
78
+ const len = Math.hypot(dx, dy)
79
+ const mid = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 }
80
+ if (len < 1e-9) return mid
81
+ let nx = -dy / len
82
+ let ny = dx / len
83
+ if (ny > 1e-9 || (Math.abs(ny) <= 1e-9 && nx < 0)) {
84
+ nx = -nx
85
+ ny = -ny
86
+ }
87
+ return { x: mid.x + nx * len * GLIDE_BOW, y: mid.y + ny * len * GLIDE_BOW }
88
+ }
89
+
90
+ /** The point at `t` (0 to 1) on the quadratic curve from `from` through `control` to `to`. */
91
+ export function glidePoint(from: Point, control: Point, to: Point, t: number): Point {
92
+ const b = 1 - t
93
+ return {
94
+ x: b * b * from.x + 2 * b * t * control.x + t * t * to.x,
95
+ y: b * b * from.y + 2 * b * t * control.y + t * t * to.y,
96
+ }
97
+ }
98
+
99
+ /** The pointer's scale `ms` after a click lands: 1, dipping to {@link DIP_SCALE}, back to 1. */
100
+ export function dipScale(ms: number): number {
101
+ if (ms < 0 || ms >= DIP_DOWN_MS + DIP_UP_MS) return 1
102
+ if (ms < DIP_DOWN_MS) return 1 - (1 - DIP_SCALE) * easeOut(ms / DIP_DOWN_MS)
103
+ return DIP_SCALE + (1 - DIP_SCALE) * easeOut((ms - DIP_DOWN_MS) / DIP_UP_MS)
104
+ }
105
+
106
+ export interface RippleFrame {
107
+ /** Logical pixels from the tip. */
108
+ readonly radius: number
109
+ /** 0 to 1. */
110
+ readonly alpha: number
111
+ /** Logical pixels. */
112
+ readonly stroke: number
113
+ }
114
+
115
+ /** The ripple `ms` after the action lands, or undefined before it and once it has faded. */
116
+ export function rippleFrame(kind: 'click' | 'type', ms: number): RippleFrame | undefined {
117
+ if (ms < 0 || ms >= RIPPLE_MS) return undefined
118
+ const spec = kind === 'click' ? CLICK_RIPPLE : KEY_RIPPLE
119
+ const p = ms / RIPPLE_MS
120
+ return {
121
+ radius: spec.from + (spec.to - spec.from) * easeOut(p),
122
+ alpha: spec.alpha * (1 - p),
123
+ stroke: spec.stroke,
124
+ }
125
+ }
126
+
127
+ /** The frame's opacity factor at `ms`: it breathes between 1 and 1 minus twice the depth. */
128
+ export function framePulse(ms: number): number {
129
+ return 1 - FRAME_PULSE_DEPTH + FRAME_PULSE_DEPTH * Math.sin((2 * Math.PI * ms) / FRAME_PULSE_MS)
130
+ }
131
+
132
+ /** How opaque the overlay is `msSinceLastAction` after the last action: whole, then fading to nothing. */
133
+ export function idleAlpha(msSinceLastAction: number): number {
134
+ if (msSinceLastAction <= HOLD_MS) return 1
135
+ return clamp(1 - (msSinceLastAction - HOLD_MS) / FADE_MS, 0, 1)
136
+ }
137
+
138
+ /** The display scale for a window: its DPI over the 96 of an unscaled display. */
139
+ export function displayScale(dpi: number): number {
140
+ return dpi > 0 ? dpi / 96 : 1
141
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A development aid: the line that asks the presence helper to draw one state
3
+ * of the overlay into a PNG file instead of onto the screen. It shows the
4
+ * pointer (or, for `frame`, the border) on a mid-grey checker, a white and a
5
+ * near-black panel, so the shadow and the transparency can be judged, and it
6
+ * shows no window. The helper answers `{ ok: true, id, r: { path } }`.
7
+ */
8
+
9
+ /** Display scales worth checking: 100 %, 150 % and 200 %. */
10
+ export const PREVIEW_DPIS = [96, 144, 192] as const
11
+ export type PreviewDpi = (typeof PREVIEW_DPIS)[number]
12
+
13
+ /**
14
+ * What a preview draws: the pointer at rest, at the bottom of a click's dip,
15
+ * with a click ripple half grown, or the frame around a window.
16
+ */
17
+ export const PREVIEW_STATES = ['rest', 'press', 'ripple', 'frame'] as const
18
+ export type PreviewState = (typeof PREVIEW_STATES)[number]
19
+
20
+ export interface PreviewRequest {
21
+ readonly dpi: PreviewDpi
22
+ readonly state: PreviewState
23
+ /** Where the helper writes the PNG, as the helper's own operating system names it. */
24
+ readonly path: string
25
+ }
26
+
27
+ /** The helper's `preview` command as one line of input. Throws on a value the helper would refuse. */
28
+ export function previewCommandLine(request: PreviewRequest): string {
29
+ if (!PREVIEW_DPIS.includes(request.dpi)) {
30
+ throw new Error(`preview dpi must be one of ${PREVIEW_DPIS.join(', ')}`)
31
+ }
32
+ if (!PREVIEW_STATES.includes(request.state)) {
33
+ throw new Error(`preview state must be one of ${PREVIEW_STATES.join(', ')}`)
34
+ }
35
+ if (request.path.trim() === '') throw new Error('preview needs a path')
36
+ return JSON.stringify({
37
+ cmd: 'preview',
38
+ dpi: request.dpi,
39
+ state: request.state,
40
+ path: request.path,
41
+ })
42
+ }