ant0-browser 0.2.1 → 0.2.3-beta.1
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/LICENSE +0 -6
- package/README.md +9 -7
- package/dist/chromium-version.d.ts +2 -11
- package/dist/chromium-version.d.ts.map +1 -1
- package/dist/chromium-version.js +2 -11
- package/dist/chromium-version.js.map +1 -1
- package/dist/claim-hints.d.ts +2 -2
- package/dist/claim-hints.js +2 -2
- package/dist/content.js +1 -1
- package/dist/content.js.map +1 -1
- package/dist/fingerprint.d.ts +12 -14
- package/dist/fingerprint.d.ts.map +1 -1
- package/dist/fingerprint.js +5 -5
- package/dist/fingerprint.js.map +1 -1
- package/dist/fontpack.d.ts +7 -5
- package/dist/fontpack.d.ts.map +1 -1
- package/dist/fontpack.js +13 -110
- package/dist/fontpack.js.map +1 -1
- package/dist/fonts.d.ts +2 -2
- package/dist/fonts.d.ts.map +1 -1
- package/dist/fonts.js +9 -5
- package/dist/fonts.js.map +1 -1
- package/dist/geoip.d.ts.map +1 -1
- package/dist/geoip.js +1 -2
- package/dist/geoip.js.map +1 -1
- package/dist/humanize.d.ts +33 -0
- package/dist/humanize.d.ts.map +1 -1
- package/dist/humanize.js +136 -106
- package/dist/humanize.js.map +1 -1
- package/dist/identity-persistence.d.ts +6 -0
- package/dist/identity-persistence.d.ts.map +1 -1
- package/dist/identity-persistence.js +19 -1
- package/dist/identity-persistence.js.map +1 -1
- package/dist/identity.d.ts +10 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +58 -16
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +16 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -25
- package/dist/index.js.map +1 -1
- package/dist/launch-ticket.d.ts +2 -2
- package/dist/launch-ticket.d.ts.map +1 -1
- package/dist/launch-ticket.js +4 -4
- package/dist/launch-ticket.js.map +1 -1
- package/dist/launchopts.d.ts +12 -12
- package/dist/launchopts.js +12 -12
- package/dist/linux-population-table.d.ts +2 -0
- package/dist/linux-population-table.d.ts.map +1 -0
- package/dist/linux-population-table.js +4 -0
- package/dist/linux-population-table.js.map +1 -0
- package/dist/linux-population.d.ts +25 -0
- package/dist/linux-population.d.ts.map +1 -0
- package/dist/linux-population.js +203 -0
- package/dist/linux-population.js.map +1 -0
- package/dist/motion.d.ts +51 -7
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +192 -29
- package/dist/motion.js.map +1 -1
- package/dist/motionscore.js +1 -1
- package/dist/motionscore.js.map +1 -1
- package/dist/native/linux-x64/ant0_runtime.node +0 -0
- package/dist/native/windows-x64/ant0_runtime.node +0 -0
- package/dist/persona-migration.d.ts +2 -5
- package/dist/persona-migration.d.ts.map +1 -1
- package/dist/persona-migration.js +2 -5
- package/dist/persona-migration.js.map +1 -1
- package/dist/persona-profile-v4.d.ts +1 -1
- package/dist/persona-profile-v4.js +1 -1
- package/dist/persona-rejected.d.ts +1 -1
- package/dist/persona-rejected.js +1 -1
- package/dist/persona-rejected.js.map +1 -1
- package/dist/population-model.d.ts +13 -1
- package/dist/population-model.d.ts.map +1 -1
- package/dist/population-model.js +6 -6
- package/dist/population-model.js.map +1 -1
- package/dist/profile-file.d.ts +1 -2
- package/dist/profile-file.d.ts.map +1 -1
- package/dist/profile-file.js +3 -4
- package/dist/profile-file.js.map +1 -1
- package/dist/render.d.ts +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +4 -5
- package/dist/render.js.map +1 -1
- package/dist/scale.d.ts +1 -1
- package/dist/scale.js +2 -2
- package/dist/scale.js.map +1 -1
- package/dist/shaderdialect.d.ts +12 -12
- package/dist/shaderdialect.d.ts.map +1 -1
- package/dist/shaderdialect.js +16 -19
- package/dist/shaderdialect.js.map +1 -1
- package/dist/speech-coherence.d.ts +17 -5
- package/dist/speech-coherence.d.ts.map +1 -1
- package/dist/speech-coherence.js +43 -6
- package/dist/speech-coherence.js.map +1 -1
- package/dist/warnings.d.ts +29 -0
- package/dist/warnings.d.ts.map +1 -1
- package/dist/warnings.js +94 -5
- package/dist/warnings.js.map +1 -1
- package/dist/webgl-coherence.d.ts +1 -1
- package/dist/webgl-coherence.js +1 -1
- package/dist/webgpu-override.d.ts.map +1 -1
- package/dist/webgpu-override.js +4 -5
- package/dist/webgpu-override.js.map +1 -1
- package/dist/windows-coherence.d.ts +1 -1
- package/dist/windows-coherence.js +1 -1
- package/package.json +1 -2
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/** Offline Linux persona generation (ant0/persona-generate-linux/v1), schema 4.
|
|
2
|
+
*
|
|
3
|
+
* Deterministic and identical to the Python mirror. Data comes only from the generated table
|
|
4
|
+
* (./linux-population-table.ts), the measured LINUX_VOICES and the fixed shape constants below. The
|
|
5
|
+
* Windows generator (./population-model.ts) is not involved. Host-supplied surfaces (gpu.webgl,
|
|
6
|
+
* gpu.webgpu, media.webrtc, media.decoding, appearance.system_colors) are never emitted. */
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { Drbg, PopulationModelError, frame, keyBytes } from "./population-model.js";
|
|
9
|
+
import { LINUX_TABLE_JSON } from "./linux-population-table.js";
|
|
10
|
+
import { LINUX_VOICES } from "./speech-coherence.js";
|
|
11
|
+
import { assertPersonaProfileV4 } from "./persona-profile-v4.js";
|
|
12
|
+
export const LINUX_GENERATE_ALGORITHM = "ant0/persona-generate-linux/v1";
|
|
13
|
+
export const LINUX_GENERATOR_VERSION = "1.2.0";
|
|
14
|
+
const DOMAIN = Buffer.from("ant0/persona-generate-linux/v1\0", "ascii");
|
|
15
|
+
const SEED_ID_DOMAIN = Buffer.from("ant0/persona-seed-id/v1", "utf8");
|
|
16
|
+
/** Linux core families of the V2.2 model that render through the bundled font pack (sorted by code point). */
|
|
17
|
+
export const LINUX_FONT_FAMILIES = [
|
|
18
|
+
"Arial", "Arimo", "Courier New", "Cousine", "DejaVu Sans", "Times New Roman", "Tinos",
|
|
19
|
+
];
|
|
20
|
+
/** The GPU seam. Linux GPU strings are host-supplied until a generated Linux GPU exists; when this
|
|
21
|
+
* returns a surface, the generator adds `surfaces.gpu` and the matching `requires` entries. */
|
|
22
|
+
export function linuxGpuSurface() {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
let cachedTable;
|
|
26
|
+
function table() {
|
|
27
|
+
return (cachedTable ??= JSON.parse(LINUX_TABLE_JSON));
|
|
28
|
+
}
|
|
29
|
+
function pick(cell, drbg) {
|
|
30
|
+
let total = 0n;
|
|
31
|
+
for (const [, weight] of cell)
|
|
32
|
+
total += BigInt(weight);
|
|
33
|
+
const target = drbg.drawU64() % total;
|
|
34
|
+
let cumulative = 0n;
|
|
35
|
+
for (const [idx, weight] of cell) {
|
|
36
|
+
cumulative += BigInt(weight);
|
|
37
|
+
if (target < cumulative)
|
|
38
|
+
return idx;
|
|
39
|
+
}
|
|
40
|
+
return cell[cell.length - 1][0];
|
|
41
|
+
}
|
|
42
|
+
function node(nodes, name, ctx, drbg) {
|
|
43
|
+
const n = nodes[name];
|
|
44
|
+
if (!n)
|
|
45
|
+
return null;
|
|
46
|
+
for (const level of n.levels) {
|
|
47
|
+
const vals = level.key.map((k) => ctx[k]);
|
|
48
|
+
if (vals.some((v) => v === null || v === undefined))
|
|
49
|
+
continue;
|
|
50
|
+
const cell = level.cells[vals.map((v) => String(v)).join("|")];
|
|
51
|
+
if (cell && cell.length > 0)
|
|
52
|
+
return n.values[pick(cell, drbg)];
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
/** Canonical JSON: keys sorted, no whitespace. */
|
|
57
|
+
function canonical(value) {
|
|
58
|
+
if (Array.isArray(value))
|
|
59
|
+
return `[${value.map(canonical).join(",")}]`;
|
|
60
|
+
if (value !== null && typeof value === "object") {
|
|
61
|
+
return `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${canonical(value[k])}`).join(",")}}`;
|
|
62
|
+
}
|
|
63
|
+
return JSON.stringify(value);
|
|
64
|
+
}
|
|
65
|
+
function layoutId(n, kb) {
|
|
66
|
+
const want = canonical(kb);
|
|
67
|
+
if (n?.layout_ids) {
|
|
68
|
+
for (let i = 0; i < n.values.length; i += 1) {
|
|
69
|
+
if (canonical(n.values[i]) === want && n.layout_ids[i])
|
|
70
|
+
return n.layout_ids[i];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (kb.KeyQ === "q" && kb.KeyY === "y" && kb.KeyZ === "z" && kb.KeyA === "a")
|
|
74
|
+
return "linux-us";
|
|
75
|
+
return `linux-other-${createHash("sha256").update(want, "utf8").digest("hex").slice(0, 6)}`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The work area's left edge. The model's work_rest rows include a captured secondary-screen offset
|
|
79
|
+
* (avail_left 1920 with no dock, dw 0), and its platform-level cell, the one any display without its
|
|
80
|
+
* own cell falls back to, draws it about 18 percent of the time (the cloud sampler reads the row the
|
|
81
|
+
* same way). A left edge at or beyond the screen's own width is not a work area of that screen, so
|
|
82
|
+
* it is clamped to the screen's origin; a left dock (avail_left == dw) is kept.
|
|
83
|
+
*/
|
|
84
|
+
function availLeft(rest, width) {
|
|
85
|
+
return rest.avail_left >= width ? 0 : rest.avail_left;
|
|
86
|
+
}
|
|
87
|
+
/** Deterministically generate and validate one schema 4 Linux persona. */
|
|
88
|
+
export function generateLinuxPersona(identityKey, deviceKey) {
|
|
89
|
+
const t = table();
|
|
90
|
+
const seed = createHash("sha256")
|
|
91
|
+
.update(DOMAIN)
|
|
92
|
+
.update(frame(keyBytes(identityKey, "identityKey")))
|
|
93
|
+
.update(frame(keyBytes(deviceKey, "deviceKey")))
|
|
94
|
+
.update(frame(Buffer.from(t.model.version, "utf8")))
|
|
95
|
+
.digest();
|
|
96
|
+
const drbg = new Drbg(seed);
|
|
97
|
+
const L = t.linux;
|
|
98
|
+
const W = t.borrowed_windows;
|
|
99
|
+
const ctx = { P: "linux", brand: "chrome" };
|
|
100
|
+
const osRelease = node(L, "os_release", ctx, drbg);
|
|
101
|
+
ctx.os_release = osRelease;
|
|
102
|
+
node(L, "platform_version", ctx, drbg); // drawn, unused: Linux platform_version is ""
|
|
103
|
+
const ff = node(L, "form_factor", ctx, drbg);
|
|
104
|
+
ctx.ff = ff;
|
|
105
|
+
const hc = node(L, "hardware_concurrency", ctx, drbg);
|
|
106
|
+
ctx.hc = hc;
|
|
107
|
+
const dm = node(W, "device_memory", { P: "windows", hc, ff, brand: "chrome" }, drbg);
|
|
108
|
+
const disp = node(L, "display", ctx, drbg);
|
|
109
|
+
if (!disp)
|
|
110
|
+
throw new PopulationModelError("linux table produced no display");
|
|
111
|
+
ctx.display = `${disp.width}x${disp.height}@${disp.device_pixel_ratio}`;
|
|
112
|
+
const top = node(L, "work_top", ctx, drbg) ?? 0;
|
|
113
|
+
const rest = node(L, "work_rest", ctx, drbg) ?? { dw: 0, dh_extra: 0, avail_left: 0 };
|
|
114
|
+
const gamut = node(L, "color_gamut", ctx, drbg);
|
|
115
|
+
ctx.gamut = gamut;
|
|
116
|
+
const dr = node(L, "dynamic_range", ctx, drbg) ?? "standard";
|
|
117
|
+
const inp = node(L, "input", ctx, drbg);
|
|
118
|
+
const audio = node(L, "audio", ctx, drbg);
|
|
119
|
+
const scheme = node(L, "color_scheme", ctx, drbg);
|
|
120
|
+
const uach = node(L, "ua_ch", ctx, drbg);
|
|
121
|
+
const heap = node(W, "js_heap_size_limit", { P: "windows", hc, ff, brand: "chrome" }, drbg);
|
|
122
|
+
const sysf = node(L, "system_fonts", ctx, drbg);
|
|
123
|
+
const kb = node(L, "keyboard", ctx, drbg);
|
|
124
|
+
const bt = node(L, "bluetooth_available", ctx, drbg);
|
|
125
|
+
const dnt = node(L, "do_not_track", ctx, drbg);
|
|
126
|
+
const pdf = node(L, "pdf_viewer_enabled", ctx, drbg);
|
|
127
|
+
const kinds = node(L, "media_device_kinds", ctx, drbg) ?? [];
|
|
128
|
+
const gpu = linuxGpuSurface();
|
|
129
|
+
const surfaces = {
|
|
130
|
+
navigator: {
|
|
131
|
+
platform: "Linux x86_64", vendor: "Google Inc.", product_sub: "20030107",
|
|
132
|
+
hardware_concurrency: hc, device_memory_gb: dm, js_heap_size_limit: heap,
|
|
133
|
+
pdf_viewer_enabled: pdf !== null ? Boolean(pdf) : true,
|
|
134
|
+
do_not_track: dnt === "1" ? "1" : null,
|
|
135
|
+
bluetooth_available: bt,
|
|
136
|
+
ua_ch: {
|
|
137
|
+
architecture: uach?.architecture ?? "x86", bitness: uach?.bitness ?? "64",
|
|
138
|
+
wow64: uach?.wow64 ?? false, form_factors: ["Desktop"],
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
display: {
|
|
142
|
+
width: disp.width, height: disp.height,
|
|
143
|
+
avail_width: disp.width - rest.dw, avail_height: disp.height - (top + rest.dh_extra),
|
|
144
|
+
avail_left: availLeft(rest, disp.width), avail_top: top,
|
|
145
|
+
color_depth: disp.color_depth, pixel_depth: disp.color_depth,
|
|
146
|
+
device_pixel_ratio: disp.device_pixel_ratio, color_gamut: gamut, dynamic_range: dr,
|
|
147
|
+
orientation: { type: disp.width >= disp.height ? "landscape-primary" : "portrait-primary", angle: 0 },
|
|
148
|
+
},
|
|
149
|
+
input: inp ? { ...inp, touch_events: inp.max_touch_points > 0 } : null,
|
|
150
|
+
appearance: { color_scheme: scheme, ...(sysf ? { system_fonts: sysf } : {}) },
|
|
151
|
+
fonts: { families: [...LINUX_FONT_FAMILIES] },
|
|
152
|
+
speech: {
|
|
153
|
+
voices: LINUX_VOICES.map(([name, language, isDefault]) => ({
|
|
154
|
+
voice_uri: name, name, language, local_service: false, default: isDefault,
|
|
155
|
+
})),
|
|
156
|
+
},
|
|
157
|
+
audio,
|
|
158
|
+
media: {
|
|
159
|
+
can_play_type: { "application/vnd.apple.mpegurl": "" },
|
|
160
|
+
devices: kinds.map((k) => ({ kind: k, label: "", device_id: "", group_id: "" })),
|
|
161
|
+
},
|
|
162
|
+
battery: { present: ff === "laptop", charging: true, level: 1, charging_time_s: 0, discharging_time_s: null },
|
|
163
|
+
keyboard: kb ? { layout_id: layoutId(L.keyboard, kb), map: kb } : undefined,
|
|
164
|
+
...(gpu ? { gpu: gpu.surface } : {}),
|
|
165
|
+
};
|
|
166
|
+
for (const key of Object.keys(surfaces))
|
|
167
|
+
if (surfaces[key] === null || surfaces[key] === undefined)
|
|
168
|
+
delete surfaces[key];
|
|
169
|
+
const profile = {
|
|
170
|
+
schema_version: 4,
|
|
171
|
+
schema_revision: 1,
|
|
172
|
+
requires: [
|
|
173
|
+
"display", "input", "fonts", "speech", "media.devices",
|
|
174
|
+
...(sysf ? ["appearance.system_fonts"] : []),
|
|
175
|
+
...(kb ? ["keyboard.map"] : []),
|
|
176
|
+
...(gpu ? gpu.requires : []),
|
|
177
|
+
],
|
|
178
|
+
provenance: {
|
|
179
|
+
source: "synthetic",
|
|
180
|
+
model: { version: t.model.version, sha256: t.model.sha256, created_at: t.model.created_at },
|
|
181
|
+
generator: { name: "ant0-population-generator", version: LINUX_GENERATOR_VERSION, algorithm: LINUX_GENERATE_ALGORITHM },
|
|
182
|
+
seed_id: createHash("sha256").update(SEED_ID_DOMAIN).update(seed).digest("hex").slice(0, 32),
|
|
183
|
+
},
|
|
184
|
+
identity: {
|
|
185
|
+
os: {
|
|
186
|
+
family: "linux", release: osRelease, platform_version: "",
|
|
187
|
+
architecture: uach?.architecture === "arm" ? "arm64" : "x86_64",
|
|
188
|
+
},
|
|
189
|
+
engine: { family: "blink", major: t.engine.major },
|
|
190
|
+
brand: { id: "chrome", version: t.engine.chrome_version },
|
|
191
|
+
form_factor: ff,
|
|
192
|
+
device_model: "",
|
|
193
|
+
},
|
|
194
|
+
surfaces,
|
|
195
|
+
};
|
|
196
|
+
assertPersonaProfileV4(profile);
|
|
197
|
+
return profile;
|
|
198
|
+
}
|
|
199
|
+
/** Table identity of the Linux model (version and hash), for provenance checks. */
|
|
200
|
+
export function linuxModelInfo() {
|
|
201
|
+
return { version: table().model.version, sha256: table().model.sha256 };
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=linux-population.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linux-population.js","sourceRoot":"","sources":["../src/linux-population.ts"],"names":[],"mappings":"AAAA;;;;;4FAK4F;AAE5F,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAyB,MAAM,yBAAyB,CAAC;AAExF,MAAM,CAAC,MAAM,wBAAwB,GAAG,gCAAgC,CAAC;AACzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC;AAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,OAAO,CAAC,CAAC;AACxE,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;AAEtE,8GAA8G;AAC9G,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACpD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO;CACtF,CAAC;AAaF;+FAC+F;AAC/F,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CAAC;AACd,CAAC;AAED,IAAI,WAAmC,CAAC;AACxC,SAAS,KAAK;IACZ,OAAO,CAAC,WAAW,KAAK,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAe,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,IAAI,CAAC,IAAU,EAAE,IAAU;IAClC,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,IAAI;QAAE,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CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;SAC7F;QACD,QAAQ,EAAE;YACR,EAAE,EAAE;gBACF,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE;gBACzD,YAAY,EAAE,IAAI,EAAE,YAAY,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ;aAChE;YACD,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE;YAClD,KAAK,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE;YACzD,WAAW,EAAE,EAAE;YACf,YAAY,EAAE,EAAE;SACjB;QACD,QAAQ;KACT,CAAC;IACF,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAChC,OAAO,OAA2B,CAAC;AACrC,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,cAAc;IAC5B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;AAC1E,CAAC"}
|
package/dist/motion.d.ts
CHANGED
|
@@ -44,15 +44,21 @@ export interface Persona {
|
|
|
44
44
|
/** Per-key dwell window — keydown→keyup (ms). Human ~45–120 (right-skewed); scripted typing ~2–3 ms. */
|
|
45
45
|
keyDwellMinMs: number;
|
|
46
46
|
keyDwellMaxMs: number;
|
|
47
|
+
/** Per-identity typing speed multiplier on the down-to-down gap (0.8 fast … 1.3 slow). */
|
|
48
|
+
typeSpeed?: number;
|
|
49
|
+
/** Per-identity chance (0.2–0.36) that a reach (D ≥ 40 px) overshoots the target and comes back. */
|
|
50
|
+
overshootProb?: number;
|
|
47
51
|
}
|
|
48
52
|
/** Derive a stable motor persona from a fingerprint seed (or random when unseeded). */
|
|
49
53
|
export declare function makePersona(seed?: string | number): Persona;
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
/** Log-normal sample: `median · exp(sigma · z)`. */
|
|
55
|
+
export declare function logNormal(median: number, sigma: number, rng?: Rng): number;
|
|
56
|
+
/** A human mousedown→mouseup click hold (ms): log-normal 108·exp(0.45·z) clamped to 45–400 — median
|
|
57
|
+
* ≈110, long right tail (human reference: median 110, SD ≈98). */
|
|
58
|
+
export declare function clickHold(_p: Persona, rng?: Rng): number;
|
|
59
|
+
/** A human per-key keydown→keyup dwell (ms): log-normal, median ≈91 (human p5–p95 55–167), clamped
|
|
60
|
+
* to 40–400. */
|
|
61
|
+
export declare function keyDwell(_p: Persona, rng?: Rng): number;
|
|
56
62
|
export interface Point {
|
|
57
63
|
x: number;
|
|
58
64
|
y: number;
|
|
@@ -79,7 +85,8 @@ export declare function minJerk(tau: number): number;
|
|
|
79
85
|
* with Fitts-scaled duration and colored noise. Returns the samples to dispatch.
|
|
80
86
|
*/
|
|
81
87
|
export declare function planMove(from: Point, to: Point, p: Persona, opts?: PlanOpts): Step[];
|
|
82
|
-
/** Grab/release dwell times (ms) for a held-button drag
|
|
88
|
+
/** Grab/release dwell times (ms) for a held-button drag: log-normal around the geometric middle of the
|
|
89
|
+
* persona window (σ 0.3), clamped to [min, 1.6·max] so the tail can run past the window. */
|
|
83
90
|
export declare function dragDwell(p: Persona, rng?: Rng): {
|
|
84
91
|
grabMs: number;
|
|
85
92
|
releaseMs: number;
|
|
@@ -103,4 +110,41 @@ export interface Viewport {
|
|
|
103
110
|
* biggest reason a challenge/slider is shown to headless automation). Returns ~`ms` of samples.
|
|
104
111
|
*/
|
|
105
112
|
export declare function planAmbient(from: Point, vp: Viewport, p: Persona, ms: number, rng?: Rng): Step[];
|
|
113
|
+
/** One native wheel event: deltas to send, then sleep `sleepMs` before the next (0 after the last). */
|
|
114
|
+
export interface WheelEvent {
|
|
115
|
+
dx: number;
|
|
116
|
+
dy: number;
|
|
117
|
+
sleepMs: number;
|
|
118
|
+
}
|
|
119
|
+
/** A wheel detent, in px (Chrome: 100 per notch on Windows and Linux at 100% scale). */
|
|
120
|
+
export declare const WHEEL_NOTCH = 100;
|
|
121
|
+
/** Plan a wheel gesture as a stream of notches: one event per 100 px (so deltaY is a notch multiple,
|
|
122
|
+
* 1–2 distinct values per gesture), log-normal gaps (median 47 ms, σ 0.5, clamp 16–300 ms), and the
|
|
123
|
+
* remainder on the LAST event. Vertical events first, then horizontal ones. */
|
|
124
|
+
export declare function planWheel(dx: number, dy: number, rng?: Rng): WheelEvent[];
|
|
125
|
+
/** A plausible fat-finger neighbour of `ch` (case preserved); `ch` itself when it has none. */
|
|
126
|
+
export declare function nearbyKey(ch: string, rng?: Rng): string;
|
|
127
|
+
/** One keyboard event on a typing timeline (`at` = ms from the first event). */
|
|
128
|
+
export interface TypeEvent {
|
|
129
|
+
at: number;
|
|
130
|
+
kind: "down" | "up";
|
|
131
|
+
key: string;
|
|
132
|
+
}
|
|
133
|
+
/** True for a character the US layout types with Shift held (uppercase letters and the shifted row). */
|
|
134
|
+
export declare function needsShift(key: string): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Plan typing `text` as key down/up events on ONE timeline (the caller plays it on the wall clock).
|
|
137
|
+
* - down-to-down gap: log-normal, median 155 ms × bigram factor (same hand 1.15, hand change 0.9,
|
|
138
|
+
* around a space 1.15) × the persona's `typeSpeed`, σ 0.55, clamp 45–2000 ms, plus a 6% chance of
|
|
139
|
+
* a 250–800 ms thinking pause;
|
|
140
|
+
* - dwell: `keyDwell` (log-normal, median ≈91 ms). A gap shorter than the previous key's dwell means
|
|
141
|
+
* the next key goes down BEFORE the previous one is up (rollover, ≈15–20% of pairs);
|
|
142
|
+
* - a 2% fat-finger typo (letter/digit) is typed, deleted with Backspace and retyped.
|
|
143
|
+
* Ordering invariants: keydowns are strictly in text order whatever the overlap; a repeated key never
|
|
144
|
+
* overlaps itself; a shifted character is bracketed by its own Shift down/up, and no other key is down
|
|
145
|
+
* while Shift is held (so a lowercase key can never be turned into an uppercase one by rollover).
|
|
146
|
+
*/
|
|
147
|
+
export declare function planTyping(text: string, p: Persona, rng?: Rng, opts?: {
|
|
148
|
+
typoRate?: number;
|
|
149
|
+
}): TypeEvent[];
|
|
106
150
|
//# sourceMappingURL=motion.d.ts.map
|
package/dist/motion.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../src/motion.ts"],"names":[],"mappings":"AA6BA;iGACiG;AACjG,MAAM,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC;AAE/B,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAQ/C;AAED,+FAA+F;AAC/F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAUlE;AAED,4DAA4D;AAC5D,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAK1C;AAED,sGAAsG;AACtG,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,+FAA+F;IAC/F,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,WAAW,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,SAAS,EAAE,M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,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;CAAE;AACxE,wFAAwF;AACxF,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B;;+EAE+E;AAC/E,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,GAAE,GAAiB,GAAG,UAAU,EAAE,CAetF;AAWD,+FAA+F;AAC/F,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,GAAE,GAAiB,GAAG,MAAM,CAKpE;AAED,gFAAgF;AAChF,MAAM,WAAW,SAAS;IAAG,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;CAAE;AAG5E,wGAAwG;AACxG,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,GAAE,GAAiB,EAAE,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,SAAS,EAAE,CA2C1H"}
|
package/dist/motion.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// none of which a single ease curve produces. (A single bezier peaks at the wrong place and has
|
|
15
15
|
// exactly one submovement — a structural tell.)
|
|
16
16
|
// • Fitts's law duration. Movement time = a + b·log2(D/W+1), not ∝ distance, so duration is
|
|
17
|
-
// statistically human across short-big vs long-small targets (a distribution
|
|
17
|
+
// statistically human across short-big vs long-small targets (a distribution a script can check).
|
|
18
18
|
// • Colored noise. Sub-pixel jitter = slow Ornstein–Uhlenbeck drift + a band-limited 8–12 Hz
|
|
19
19
|
// physiological tremor, not flat white gauss (whose flat spectrum is itself detectable).
|
|
20
20
|
// • Seeded persona. One motor signature (mean speed, tremor, overshoot, handedness bias, cadence)
|
|
@@ -59,6 +59,8 @@ export function gaussFrom(rng) {
|
|
|
59
59
|
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
|
|
60
60
|
}
|
|
61
61
|
const lerp = (a, b, t) => a + (b - a) * t;
|
|
62
|
+
const log2 = (x) => Math.log(x) / Math.LN2;
|
|
63
|
+
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
|
|
62
64
|
/** Derive a stable motor persona from a fingerprint seed (or random when unseeded). */
|
|
63
65
|
export function makePersona(seed) {
|
|
64
66
|
const seedInt = hashSeed(seed);
|
|
@@ -85,20 +87,25 @@ export function makePersona(seed) {
|
|
|
85
87
|
clickHoldMaxMs: 150,
|
|
86
88
|
keyDwellMinMs: 45,
|
|
87
89
|
keyDwellMaxMs: 120,
|
|
90
|
+
// drawn LAST so every field above keeps its value for an existing seed
|
|
91
|
+
typeSpeed: lerp(0.8, 1.3, r()),
|
|
92
|
+
overshootProb: lerp(0.2, 0.36, r()),
|
|
88
93
|
};
|
|
89
94
|
}
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return p.clickHoldMinMs + Math.min(1, Math.abs(gaussFrom(rng)) * 0.5) * (p.clickHoldMaxMs - p.clickHoldMinMs);
|
|
95
|
+
/** Log-normal sample: `median · exp(sigma · z)`. */
|
|
96
|
+
export function logNormal(median, sigma, rng = Math.random) {
|
|
97
|
+
return median * Math.exp(sigma * gaussFrom(rng));
|
|
94
98
|
}
|
|
95
|
-
/** A human
|
|
96
|
-
*
|
|
97
|
-
export function
|
|
98
|
-
return
|
|
99
|
+
/** A human mousedown→mouseup click hold (ms): log-normal 108·exp(0.45·z) clamped to 45–400 — median
|
|
100
|
+
* ≈110, long right tail (human reference: median 110, SD ≈98). */
|
|
101
|
+
export function clickHold(_p, rng = Math.random) {
|
|
102
|
+
return clamp(logNormal(108, 0.45, rng), 45, 400);
|
|
103
|
+
}
|
|
104
|
+
/** A human per-key keydown→keyup dwell (ms): log-normal, median ≈91 (human p5–p95 55–167), clamped
|
|
105
|
+
* to 40–400. */
|
|
106
|
+
export function keyDwell(_p, rng = Math.random) {
|
|
107
|
+
return clamp(logNormal(91, 0.36, rng), 40, 400);
|
|
99
108
|
}
|
|
100
|
-
const log2 = (x) => Math.log(x) / Math.LN2;
|
|
101
|
-
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
|
|
102
109
|
/** Cubic bezier point at parameter e (0..1). */
|
|
103
110
|
function bez(p0, c1, c2, p1, e) {
|
|
104
111
|
const m = 1 - e;
|
|
@@ -121,9 +128,15 @@ function sampleSubmove(out, a, b, durMs, p, rng, t0, drift, jit, tremorPhase, la
|
|
|
121
128
|
// perpendicular unit for the path bow; sign follows the persona's handedness bias
|
|
122
129
|
const nx = -dy / dist, ny = dx / dist;
|
|
123
130
|
const bowSign = p.approachBias >= 0 ? 1 : -1;
|
|
124
|
-
|
|
131
|
+
// Path bow: peak deviation from the chord is a log-normal fraction of the chord (median ≈9.5%, so a
|
|
132
|
+
// typical reach bends ≈5–10% and an occasional one 15–20%), NOT capped at a fixed pixel length. The
|
|
133
|
+
// second control point carries a random share k of the first one's offset, so the arc is asymmetric
|
|
134
|
+
// (a cubic with offsets o1,o2 peaks at ≈0.375·(o1+o2)); `bow` is solved to hit the drawn peak.
|
|
135
|
+
const devFrac = clamp(logNormal(0.095, 0.5, rng), 0.015, 0.25);
|
|
136
|
+
const k2 = lerp(0.3, 1.1, rng());
|
|
137
|
+
const bow = bowSign * devFrac * dist / (0.375 * (1 + k2));
|
|
125
138
|
const c1x = a.x + dx * 0.33 + nx * bow, c1y = a.y + dy * 0.33 + ny * bow;
|
|
126
|
-
const c2x = a.x + dx * 0.66 + nx * bow, c2y = a.y + dy * 0.66 + ny * bow;
|
|
139
|
+
const c2x = a.x + dx * 0.66 + nx * bow * k2, c2y = a.y + dy * 0.66 + ny * bow * k2;
|
|
127
140
|
let t = t0;
|
|
128
141
|
for (let i = 1; i <= n; i++) {
|
|
129
142
|
const e = minJerk(i / n);
|
|
@@ -167,6 +180,7 @@ function sampleSubmove(out, a, b, durMs, p, rng, t0, drift, jit, tremorPhase, la
|
|
|
167
180
|
export function planMove(from, to, p, opts = {}) {
|
|
168
181
|
const rng = opts.rng ?? Math.random;
|
|
169
182
|
const W = Math.max(6, opts.targetW ?? 24);
|
|
183
|
+
const H = Math.max(6, opts.targetH ?? W);
|
|
170
184
|
const D = Math.hypot(to.x - from.x, to.y - from.y);
|
|
171
185
|
const out = [];
|
|
172
186
|
if (D < 1.5) {
|
|
@@ -178,17 +192,25 @@ export function planMove(from, to, p, opts = {}) {
|
|
|
178
192
|
// silently blow past the cap.
|
|
179
193
|
const id = log2(D / W + 1);
|
|
180
194
|
const mtLo = Math.min(1700, Math.max(70, 40 + D * 0.6));
|
|
181
|
-
const mt = clamp((p.fittsA + p.fittsB * id) * (
|
|
195
|
+
const mt = clamp((p.fittsA + p.fittsB * id) * clamp(Math.exp(0.14 * gaussFrom(rng)), 0.7, 1.45), mtLo, 1700);
|
|
182
196
|
// Submovement targets: primary lands near `to` with a small over/undershoot; corrections close the
|
|
183
197
|
// residual error, each covering ~55–80% of what's left.
|
|
184
198
|
const targets = [];
|
|
199
|
+
let gaps;
|
|
185
200
|
if (D >= 40) {
|
|
186
|
-
|
|
201
|
+
// Most reaches stop short and home in (primary at ~0.84–0.94 of D, never past the target); a share
|
|
202
|
+
// `overshootProb` (≈28%) fly PAST it by 2.5–7% of D (≥4 px) and come back — the human hook.
|
|
203
|
+
const ux = (to.x - from.x) / D, uy = (to.y - from.y) / D;
|
|
187
204
|
const spread = Math.min(16, D * p.overshoot);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
205
|
+
// Starting inside the target box (e.g. move→click on the same spot) there is nothing to overshoot.
|
|
206
|
+
// The draw is still consumed so the rng stream is unchanged.
|
|
207
|
+
const inside = Math.abs(to.x - from.x) <= W / 2 && Math.abs(to.y - from.y) <= H / 2;
|
|
208
|
+
const over = rng() < (p.overshootProb ?? 0.28) && !inside;
|
|
209
|
+
const along = over
|
|
210
|
+
? D + clamp(D * lerp(0.025, 0.07, rng()), 4, 36)
|
|
211
|
+
: clamp(D * p.primaryFrac + gaussFrom(rng) * Math.min(8, spread * 0.5), D * 0.6, D - 1.5);
|
|
212
|
+
const perp = gaussFrom(rng) * spread * (over ? 0.5 : 1);
|
|
213
|
+
targets.push({ x: from.x + ux * along - uy * perp, y: from.y + uy * along + ux * perp });
|
|
192
214
|
// 1 correction usually, occasionally 2 (a 3rd is rare) — keeps the corrective-submovement count
|
|
193
215
|
// in the human 1–3 band rather than over-generating homing bumps.
|
|
194
216
|
const nCorr = rng() < 0.08 * p.maxCorrections ? 2 : 1;
|
|
@@ -204,7 +226,14 @@ export function planMove(from, to, p, opts = {}) {
|
|
|
204
226
|
}
|
|
205
227
|
}
|
|
206
228
|
targets.push({ x: to.x, y: to.y });
|
|
207
|
-
// Allocate MT
|
|
229
|
+
// Allocate MT. The motor re-planning gaps between submovements (40–120 ms) are part of the movement
|
|
230
|
+
// time, so they are drawn first and the submovements share what is left: the plan's TOTAL duration
|
|
231
|
+
// then follows the Fitts time (intercept ≈ fittsA, slope ≈ fittsB) instead of running ~100 ms over.
|
|
232
|
+
const nGaps = targets.length - 1;
|
|
233
|
+
gaps = [];
|
|
234
|
+
for (let i = 0; i < nGaps; i++)
|
|
235
|
+
gaps.push(lerp(40, 120, rng()));
|
|
236
|
+
const moveMs = Math.max(mt * 0.55, mt - gaps.reduce((x, y) => x + y, 0));
|
|
208
237
|
const segDur = [];
|
|
209
238
|
if (targets.length === 1) {
|
|
210
239
|
segDur.push(mt);
|
|
@@ -212,11 +241,10 @@ export function planMove(from, to, p, opts = {}) {
|
|
|
212
241
|
else {
|
|
213
242
|
// Primary gets ~78% of the time (min-jerk peaks at its own mid-point ⇒ global peak lands ~0.35–0.4,
|
|
214
243
|
// the human sweet spot slightly before the whole-gesture midpoint), corrections share the rest.
|
|
215
|
-
segDur.push(
|
|
216
|
-
const rest =
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
segDur.push((rest / nc) * lerp(0.8, 1.2, rng()));
|
|
244
|
+
segDur.push(moveMs * 0.78);
|
|
245
|
+
const rest = moveMs * 0.22;
|
|
246
|
+
for (let i = 0; i < nGaps; i++)
|
|
247
|
+
segDur.push((rest / nGaps) * lerp(0.8, 1.2, rng()));
|
|
220
248
|
}
|
|
221
249
|
const drift = { x: 0, y: 0 };
|
|
222
250
|
const jit = { x: 0, y: 0 };
|
|
@@ -227,7 +255,7 @@ export function planMove(from, to, p, opts = {}) {
|
|
|
227
255
|
const last = s === targets.length - 1;
|
|
228
256
|
t = sampleSubmove(out, a, b, Math.max(20, segDur[s]), p, rng, t, drift, jit, tremorPhase, last && !opts.settle);
|
|
229
257
|
if (!last && out.length)
|
|
230
|
-
out[out.length - 1].sleepMs +=
|
|
258
|
+
out[out.length - 1].sleepMs += gaps[s]; // motor re-planning gap
|
|
231
259
|
a = b;
|
|
232
260
|
}
|
|
233
261
|
if (opts.settle) {
|
|
@@ -240,16 +268,39 @@ export function planMove(from, to, p, opts = {}) {
|
|
|
240
268
|
}
|
|
241
269
|
return out;
|
|
242
270
|
}
|
|
243
|
-
/** Grab/release dwell times (ms) for a held-button drag
|
|
271
|
+
/** Grab/release dwell times (ms) for a held-button drag: log-normal around the geometric middle of the
|
|
272
|
+
* persona window (σ 0.3), clamped to [min, 1.6·max] so the tail can run past the window. */
|
|
244
273
|
export function dragDwell(p, rng = Math.random) {
|
|
245
274
|
return {
|
|
246
|
-
grabMs:
|
|
247
|
-
releaseMs:
|
|
275
|
+
grabMs: clamp(logNormal(Math.sqrt(p.grabMinMs * p.grabMaxMs), 0.3, rng), p.grabMinMs, p.grabMaxMs * 1.6),
|
|
276
|
+
releaseMs: clamp(logNormal(Math.sqrt(p.releaseMinMs * p.releaseMaxMs), 0.3, rng), p.releaseMinMs, p.releaseMaxMs * 1.6),
|
|
248
277
|
};
|
|
249
278
|
}
|
|
250
279
|
/** A human click point inside `box`: a 2D gaussian around center, nudged toward the approach side
|
|
251
280
|
* (people undershoot toward where the cursor came from), clamped a couple px inside the edges. */
|
|
252
281
|
export function clickPoint(box, from, p, rng = Math.random) {
|
|
282
|
+
// Already resting inside the target (a mouse.move onto it, then a click): people click where the
|
|
283
|
+
// cursor is instead of re-aiming within the box, with a small hand tremor of 1-3 px per axis so
|
|
284
|
+
// repeated clicks on one box never hit one identical pixel. A tremor that would leave the 2 px
|
|
285
|
+
// inset is reflected back inside; a result on the exact centre is nudged off it.
|
|
286
|
+
if (box.width >= 4 && box.height >= 4 &&
|
|
287
|
+
from.x >= box.x + 2 && from.x <= box.x + box.width - 2 && from.y >= box.y + 2 && from.y <= box.y + box.height - 2) {
|
|
288
|
+
const hix = box.x + box.width - 2, hiy = box.y + box.height - 2;
|
|
289
|
+
const jitter = (v, lo, hi) => {
|
|
290
|
+
const mag = 1 + Math.floor(rng() * 3);
|
|
291
|
+
const dir = rng() < 0.5 ? -1 : 1;
|
|
292
|
+
let r = v + dir * mag;
|
|
293
|
+
if (r < lo || r > hi)
|
|
294
|
+
r = v - dir * mag;
|
|
295
|
+
return clamp(r, lo, hi);
|
|
296
|
+
};
|
|
297
|
+
let x = jitter(from.x, box.x + 2, hix), y = jitter(from.y, box.y + 2, hiy);
|
|
298
|
+
const mx = box.x + box.width / 2, my = box.y + box.height / 2;
|
|
299
|
+
if (Math.round(x) === Math.round(mx) && Math.round(y) === Math.round(my)) {
|
|
300
|
+
x = x + 1 <= hix ? x + 1 : x - 1;
|
|
301
|
+
}
|
|
302
|
+
return { x, y };
|
|
303
|
+
}
|
|
253
304
|
const cx = box.x + box.width / 2, cy = box.y + box.height / 2;
|
|
254
305
|
const dx = cx - from.x, dy = cy - from.y;
|
|
255
306
|
const d = Math.hypot(dx, dy) || 1;
|
|
@@ -308,4 +359,116 @@ export function planAmbient(from, vp, p, ms, rng = Math.random) {
|
|
|
308
359
|
}
|
|
309
360
|
return out;
|
|
310
361
|
}
|
|
362
|
+
/** A wheel detent, in px (Chrome: 100 per notch on Windows and Linux at 100% scale). */
|
|
363
|
+
export const WHEEL_NOTCH = 100;
|
|
364
|
+
/** Plan a wheel gesture as a stream of notches: one event per 100 px (so deltaY is a notch multiple,
|
|
365
|
+
* 1–2 distinct values per gesture), log-normal gaps (median 47 ms, σ 0.5, clamp 16–300 ms), and the
|
|
366
|
+
* remainder on the LAST event. Vertical events first, then horizontal ones. */
|
|
367
|
+
export function planWheel(dx, dy, rng = Math.random) {
|
|
368
|
+
const out = [];
|
|
369
|
+
const axis = (total, vertical) => {
|
|
370
|
+
if (!total)
|
|
371
|
+
return;
|
|
372
|
+
const n = Math.max(1, Math.round(Math.abs(total) / WHEEL_NOTCH));
|
|
373
|
+
const sign = Math.sign(total);
|
|
374
|
+
for (let i = 0; i < n; i++) {
|
|
375
|
+
const d = i === n - 1 ? total - sign * WHEEL_NOTCH * (n - 1) : sign * WHEEL_NOTCH;
|
|
376
|
+
out.push({ dx: vertical ? 0 : d, dy: vertical ? d : 0, sleepMs: clamp(logNormal(47, 0.5, rng), 16, 300) });
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
axis(dy, true);
|
|
380
|
+
axis(dx, false);
|
|
381
|
+
if (out.length)
|
|
382
|
+
out[out.length - 1].sleepMs = 0;
|
|
383
|
+
return out;
|
|
384
|
+
}
|
|
385
|
+
// ----------------------------------------------------------------------------------------- typing
|
|
386
|
+
// Compact keyboard-adjacency map for realistic fat-finger typos.
|
|
387
|
+
const NEARBY = {
|
|
388
|
+
a: "sqwz", b: "vghn", c: "xdfv", d: "sfecx", e: "wrsdf", f: "dgrtcv",
|
|
389
|
+
g: "fhtyb", h: "gjybn", i: "ujko", j: "hkunm", k: "jloi", l: "kop",
|
|
390
|
+
m: "njk", n: "bhjm", o: "iklp", p: "ol", q: "wa", r: "edft",
|
|
391
|
+
s: "awedxz", t: "rfgy", u: "yhji", v: "cfgb", w: "qase", x: "zsdc",
|
|
392
|
+
y: "tghu", z: "asx",
|
|
393
|
+
};
|
|
394
|
+
/** A plausible fat-finger neighbour of `ch` (case preserved); `ch` itself when it has none. */
|
|
395
|
+
export function nearbyKey(ch, rng = Math.random) {
|
|
396
|
+
const n = NEARBY[ch.toLowerCase()];
|
|
397
|
+
if (!n)
|
|
398
|
+
return ch;
|
|
399
|
+
const w = n[Math.floor(rng() * n.length)];
|
|
400
|
+
return ch === ch.toUpperCase() && ch !== ch.toLowerCase() ? w.toUpperCase() : w;
|
|
401
|
+
}
|
|
402
|
+
const SHIFT_SYMBOLS = '~!@#$%^&*()_+{}|:"<>?';
|
|
403
|
+
/** True for a character the US layout types with Shift held (uppercase letters and the shifted row). */
|
|
404
|
+
export function needsShift(key) {
|
|
405
|
+
return key.length === 1 && (/[A-Z]/.test(key) || SHIFT_SYMBOLS.includes(key));
|
|
406
|
+
}
|
|
407
|
+
const LEFT_HAND = "qwertasdfgzxcvb12345`~!@#$%";
|
|
408
|
+
const handOf = (k) => (LEFT_HAND.includes(k.toLowerCase()) ? 0 : 1);
|
|
409
|
+
/**
|
|
410
|
+
* Plan typing `text` as key down/up events on ONE timeline (the caller plays it on the wall clock).
|
|
411
|
+
* - down-to-down gap: log-normal, median 155 ms × bigram factor (same hand 1.15, hand change 0.9,
|
|
412
|
+
* around a space 1.15) × the persona's `typeSpeed`, σ 0.55, clamp 45–2000 ms, plus a 6% chance of
|
|
413
|
+
* a 250–800 ms thinking pause;
|
|
414
|
+
* - dwell: `keyDwell` (log-normal, median ≈91 ms). A gap shorter than the previous key's dwell means
|
|
415
|
+
* the next key goes down BEFORE the previous one is up (rollover, ≈15–20% of pairs);
|
|
416
|
+
* - a 2% fat-finger typo (letter/digit) is typed, deleted with Backspace and retyped.
|
|
417
|
+
* Ordering invariants: keydowns are strictly in text order whatever the overlap; a repeated key never
|
|
418
|
+
* overlaps itself; a shifted character is bracketed by its own Shift down/up, and no other key is down
|
|
419
|
+
* while Shift is held (so a lowercase key can never be turned into an uppercase one by rollover).
|
|
420
|
+
*/
|
|
421
|
+
export function planTyping(text, p, rng = Math.random, opts = {}) {
|
|
422
|
+
const typoRate = opts.typoRate ?? 0.02;
|
|
423
|
+
const keys = [];
|
|
424
|
+
for (const ch of Array.from(text)) {
|
|
425
|
+
if (/[a-zA-Z0-9]/.test(ch) && rng() < typoRate) {
|
|
426
|
+
keys.push({ k: nearbyKey(ch, rng), extra: 0 });
|
|
427
|
+
keys.push({ k: "Backspace", extra: lerp(120, 300, rng()) });
|
|
428
|
+
keys.push({ k: ch, extra: lerp(80, 200, rng()) });
|
|
429
|
+
}
|
|
430
|
+
else
|
|
431
|
+
keys.push({ k: ch, extra: 0 });
|
|
432
|
+
}
|
|
433
|
+
const ev = [];
|
|
434
|
+
let lastDown = 0, lastUp = -1e9, shiftUntil = -1e9, prev = null;
|
|
435
|
+
const keyUp = new Map(); // when each key was last released
|
|
436
|
+
for (const e of keys) {
|
|
437
|
+
const hold = keyDwell(p, rng);
|
|
438
|
+
let gap = 0;
|
|
439
|
+
if (prev !== null) {
|
|
440
|
+
const around = prev === " " || e.k === " ";
|
|
441
|
+
const f = around ? 1.15 : prev === "Backspace" || e.k === "Backspace" ? 1 : handOf(prev) === handOf(e.k) ? 1.15 : 0.9;
|
|
442
|
+
gap = clamp(logNormal(155 * f * (p.typeSpeed ?? 1.0), 0.55, rng), 45, 2000) + e.extra;
|
|
443
|
+
if (rng() < 0.06)
|
|
444
|
+
gap += lerp(250, 800, rng());
|
|
445
|
+
}
|
|
446
|
+
let down = prev === null ? 0 : lastDown + gap;
|
|
447
|
+
// a key cannot go down again before its OWN previous release (+15 ms), adjacent or not ("banana")
|
|
448
|
+
const own = keyUp.get(e.k);
|
|
449
|
+
if (own !== undefined)
|
|
450
|
+
down = Math.max(down, own + 15);
|
|
451
|
+
if (needsShift(e.k)) {
|
|
452
|
+
const lead = clamp(logNormal(40, 0.4, rng), 15, 120);
|
|
453
|
+
const sd = Math.max(down - lead, lastUp + 4, 0); // Shift goes down only once every earlier key is up
|
|
454
|
+
down = sd + lead;
|
|
455
|
+
const up = down + hold;
|
|
456
|
+
const sUp = up + clamp(logNormal(35, 0.5, rng), 8, 150);
|
|
457
|
+
ev.push({ at: sd, kind: "down", key: "Shift" }, { at: down, kind: "down", key: e.k }, { at: up, kind: "up", key: e.k }, { at: sUp, kind: "up", key: "Shift" });
|
|
458
|
+
lastUp = sUp;
|
|
459
|
+
shiftUntil = sUp;
|
|
460
|
+
keyUp.set(e.k, up);
|
|
461
|
+
keyUp.set("Shift", sUp);
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
down = Math.max(down, shiftUntil + 4); // never down while a previous Shift is still held
|
|
465
|
+
ev.push({ at: down, kind: "down", key: e.k }, { at: down + hold, kind: "up", key: e.k });
|
|
466
|
+
lastUp = Math.max(lastUp, down + hold);
|
|
467
|
+
keyUp.set(e.k, down + hold);
|
|
468
|
+
}
|
|
469
|
+
lastDown = down;
|
|
470
|
+
prev = e.k;
|
|
471
|
+
}
|
|
472
|
+
return ev.map((v, i) => ({ v, i })).sort((a, b) => a.v.at - b.v.at || a.i - b.i).map((x) => x.v);
|
|
473
|
+
}
|
|
311
474
|
//# sourceMappingURL=motion.js.map
|