@algorisys/tinyfly 0.108.0 → 0.110.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.
@@ -0,0 +1,125 @@
1
+ import { vec3 as v, mat4 as k, quat as z, getEasingFunction as C, loopNoise as S } from "@algorisys/tinyfly";
2
+ function q(e, s, n = {}) {
3
+ const r = v.normalize(v.subtract(s, e)), t = n.up ?? (Math.abs(r[1]) > 0.9999 ? [0, 0, -1] : [0, 1, 0]);
4
+ return E(k.lookAt(e, s, t), n.roll ?? 0);
5
+ }
6
+ function E(e, s) {
7
+ return s ? k.multiply(k.fromQuat(z.fromAxisAngle([0, 0, 1], -s)), e) : e;
8
+ }
9
+ function A(e, s, n, r) {
10
+ const t = s * Math.PI / 180, o = n * Math.PI / 180;
11
+ return [e[0] + r * Math.cos(o) * Math.sin(t), e[1] + r * Math.sin(o), e[2] + r * Math.cos(o) * Math.cos(t)];
12
+ }
13
+ function B(e, s, n) {
14
+ const r = v.subtract(e, s), t = v.length(r);
15
+ if (t === 0) return e;
16
+ const o = Math.max(1e-3, t - n);
17
+ return v.add(s, v.scale(r, o / t));
18
+ }
19
+ function H(e, s) {
20
+ if (e.projection === "perspective") return k.perspective(e.fov, s, e.near, e.far);
21
+ const n = e.height / 2;
22
+ return k.orthographic(-n * s, n * s, -n, n, e.near, e.far);
23
+ }
24
+ function N(e, s) {
25
+ let n;
26
+ for (const r of [...e].sort((t, o) => t.start - o.start)) r.start <= s && (n = r);
27
+ return n;
28
+ }
29
+ function Q(e) {
30
+ const s = [], n = [...e].sort((t, o) => t.start - o.start), r = /* @__PURE__ */ new Set();
31
+ return n.forEach((t, o) => {
32
+ r.has(t.id) && s.push(`two shots share the id "${t.id}"`), r.add(t.id), t.end > t.start || s.push(`shot "${t.id}" ends before it starts`), o > 0 && t.start < n[o - 1].end && s.push(`shot "${t.id}" starts before "${n[o - 1].id}" ends`), t.transition && o === 0 && s.push(`shot "${t.id}" is first: nothing to transition from`), t.transition && t.transition.duration > t.end - t.start && s.push(`shot "${t.id}": its transition is longer than the shot`);
33
+ }), s;
34
+ }
35
+ function D(e, s) {
36
+ const n = [...e].sort((t, o) => t.start - o.start);
37
+ if (n.length === 0) return [];
38
+ const r = n.map((t) => ({ time: t.start, value: t.camera }));
39
+ return [{ id: `${s}-shots`, target: s, property: "activeCamera", keyframes: r }];
40
+ }
41
+ function G(e) {
42
+ return [...e].sort((s, n) => s.start - n.start).map((s) => ({ id: s.id, time: s.start, label: s.label ?? s.id }));
43
+ }
44
+ function I(e, s) {
45
+ const n = [...e].sort((r, t) => r.start - t.start);
46
+ for (let r = 1; r < n.length; r++) {
47
+ const t = n[r], o = t.transition;
48
+ if (!(!o || o.kind === "cut" || !(o.duration > 0)) && s >= t.start && s < t.start + o.duration)
49
+ return { kind: o.kind, progress: (s - t.start) / o.duration, from: n[r - 1], to: t, direction: o.direction ?? "left", color: o.color ?? "#000000" };
50
+ }
51
+ }
52
+ function J(e, s) {
53
+ const n = 6e4 / s.bpm, r = (o) => s.offset + Math.round((o - s.offset) / n) * n, t = [...e].sort((o, c) => o.start - c.start).map((o) => ({ ...o }));
54
+ for (let o = 1; o < t.length; o++) {
55
+ const c = Math.max(t[o - 1].start + 1, r(t[o].start));
56
+ t[o - 1].end = c, t[o].start = c;
57
+ }
58
+ return t;
59
+ }
60
+ function K(e, s, n) {
61
+ const r = new Map(e ?? []), t = new Map(r.get(s) ?? []);
62
+ return t.set("activeCamera", n), r.set(s, t), r;
63
+ }
64
+ const w = (e, s, n) => [e[0] + (s[0] - e[0]) * n, e[1] + (s[1] - e[1]) * n, e[2] + (s[2] - e[2]) * n];
65
+ function F(e, s, n) {
66
+ const r = { target: [0, 0, 0], yaw: 0, pitch: 15, distance: 8, ...e }, t = { ...r, ...s }, o = w(r.target, t.target, n), c = r.position || t.position ? w(r.position ?? A(r.target, r.yaw, r.pitch, r.distance), t.position ?? A(t.target, t.yaw, t.pitch, t.distance), n) : A(o, r.yaw + (t.yaw - r.yaw) * n, r.pitch + (t.pitch - r.pitch) * n, r.distance + (t.distance - r.distance) * n), f = w(r.lookAt ?? r.target, t.lookAt ?? t.target, n), u = r.fov !== void 0 || t.fov !== void 0 ? (r.fov ?? t.fov) + ((t.fov ?? r.fov) - (r.fov ?? t.fov)) * n : void 0;
67
+ return { position: c, lookAt: f, fov: u };
68
+ }
69
+ function L(e) {
70
+ const s = Math.max(1, e.every ?? 33), n = C(e.easing ?? "ease-in-out"), r = `${e.scene}/${e.camera}`, t = [], o = [], c = [];
71
+ for (let u = e.start; ; u = Math.min(e.end, u + s)) {
72
+ const h = e.end > e.start ? n((u - e.start) / (e.end - e.start)) : 1, l = F(e.from, e.to, h);
73
+ if (t.push({ time: u, value: l.position }), o.push({ time: u, value: l.lookAt }), l.fov !== void 0 && c.push({ time: u, value: l.fov }), u >= e.end) break;
74
+ }
75
+ const f = [
76
+ { id: `${r}-move-position`, target: r, property: "position", keyframes: t },
77
+ { id: `${r}-move-lookAt`, target: r, property: "lookAt", keyframes: o }
78
+ ];
79
+ return c.length > 0 && f.push({ id: `${r}-move-fov`, target: r, property: "fov", keyframes: c }), f;
80
+ }
81
+ function O(e) {
82
+ const s = Math.max(1, e.every ?? 33), n = e.offset ?? [0, 2, 6], r = e.lag ?? 0, t = `${e.scene}/${e.camera}`, o = [], c = [];
83
+ for (let f = e.start; ; f = Math.min(e.end, f + s)) {
84
+ const u = e.subjectAt(f), h = e.subjectAt(Math.max(e.start, f - r));
85
+ if (o.push({ time: f, value: [h[0] + n[0], h[1] + n[1], h[2] + n[2]] }), c.push({ time: f, value: u }), f >= e.end) break;
86
+ }
87
+ return [
88
+ { id: `${t}-follow-position`, target: t, property: "position", keyframes: o },
89
+ { id: `${t}-follow-lookAt`, target: t, property: "lookAt", keyframes: c }
90
+ ];
91
+ }
92
+ function R(e, s) {
93
+ const n = `${s.scene}/${s.camera}`, r = s.amount ?? 0.04, t = s.aim ?? 0.08, o = s.rate ?? 1.2, c = Math.max(1, s.every ?? 33), f = s.end - s.start, u = Math.max(1, f), h = Math.max(1, Math.round(u / 1e3 * o)), l = typeof s.seed == "string" ? s.seed : `handheld-${s.seed ?? 0}`, m = (a, d) => S(a - s.start, { period: u, seed: `${l}-${d}`, cycles: h, octaves: 2 }), b = e.filter((a) => a.target === n), T = e.filter((a) => a.target !== n), x = (a, d, g) => {
94
+ const y = b.find((i) => i.property === a), M = [];
95
+ if (y)
96
+ for (const i of y.keyframes) {
97
+ const p = i.value;
98
+ M.push({ time: i.time, value: [p[0] + m(i.time, `${a}x`) * d, p[1] + m(i.time, `${a}y`) * d, p[2] + m(i.time, `${a}z`) * d * 0.5], easing: i.easing });
99
+ }
100
+ else if (g)
101
+ for (let i = s.start; M.push({ time: i, value: [g[0] + m(i, `${a}x`) * d, g[1] + m(i, `${a}y`) * d, g[2] + m(i, `${a}z`) * d * 0.5] }), !(i >= s.end); i = Math.min(s.end, i + c))
102
+ ;
103
+ else return;
104
+ return { id: y?.id ?? `${n}-handheld-${a}`, target: n, property: a, keyframes: M };
105
+ }, $ = [...T, ...b.filter((a) => a.property !== "position" && a.property !== "lookAt")], j = x("position", r, s.base?.position), P = x("lookAt", t, s.base?.lookAt);
106
+ return j && $.push(j), P && $.push(P), $;
107
+ }
108
+ export {
109
+ R as a,
110
+ L as b,
111
+ O as c,
112
+ F as d,
113
+ Q as e,
114
+ B as f,
115
+ G as g,
116
+ D as h,
117
+ J as i,
118
+ q as l,
119
+ A as o,
120
+ H as p,
121
+ E as r,
122
+ N as s,
123
+ I as t,
124
+ K as w
125
+ };
@@ -0,0 +1,445 @@
1
+ import { c as He, s as ye, H as I, a as Be, r as ze, b as _e, d as We, e as ue, f as J, C as fe, g as Le, h as xe, S as Ce, o as Ge, i as ae, j as Ke, k as Ve } from "./cricket-camera-tMg3Ag3F.js";
2
+ import { l as ut, m as ht, n as dt } from "./cricket-camera-tMg3Ag3F.js";
3
+ import { vec3 as y, quat as Ee } from "@algorisys/tinyfly";
4
+ function me(t, n) {
5
+ if (!Array.isArray(t) || t.length !== 3 || !t.every(Number.isFinite)) throw new Error(`${n}: expected three finite coordinates`);
6
+ }
7
+ function je(t, n, e = 40, i = []) {
8
+ if (!Number.isFinite(t) || !Number.isFinite(n) || t < 0 || n < t) throw new Error("sampleTimes: expected finite ordered nonnegative times");
9
+ if (!Number.isFinite(e) || e < 16 || e > 1e3) throw new Error("sampleTimes: every must be between 16 and 1000 ms");
10
+ if ((n - t) / e > 2e4) throw new Error("sampleTimes: too many samples");
11
+ const o = /* @__PURE__ */ new Set([t, n, ...i.filter((l) => l >= t && l <= n && Number.isFinite(l))]);
12
+ for (let l = t + e; l < n; l += e) o.add(l);
13
+ return [...o].sort((l, c) => l - c);
14
+ }
15
+ function Fe(t, n) {
16
+ if (Ne(t), !Number.isFinite(n)) throw new Error("ballFlightPoint: time must be finite");
17
+ const e = Math.max(0, Math.min(1, (n - t.start) / (t.end - t.start))), i = 4 * e * (1 - e), o = t.to[0] - t.from[0], l = t.to[2] - t.from[2], c = Math.hypot(o, l) || 1;
18
+ return [
19
+ t.from[0] + o * e - l / c * (t.curve ?? 0) * i,
20
+ t.from[1] + (t.to[1] - t.from[1]) * e + (t.arc ?? 0) * i,
21
+ t.from[2] + l * e + o / c * (t.curve ?? 0) * i
22
+ ];
23
+ }
24
+ function Ne(t) {
25
+ if (!t.target?.trim()) throw new Error("ballFlight: target is required");
26
+ if (me(t.from, "ballFlight.from"), me(t.to, "ballFlight.to"), !Number.isFinite(t.start) || !Number.isFinite(t.end) || t.start < 0 || t.end <= t.start) throw new Error("ballFlight: end must be greater than start, both finite and nonnegative");
27
+ if (!Number.isFinite(t.arc ?? 0) || (t.arc ?? 0) < 0 || !Number.isFinite(t.curve ?? 0)) throw new Error("ballFlight: arc must be finite and nonnegative; curve must be finite");
28
+ }
29
+ function ot(t) {
30
+ Ne(t);
31
+ const n = je(t.start, t.end, t.every), e = n.map((i) => Fe(t, i));
32
+ return ["x", "y", "z"].map((i, o) => ({
33
+ id: `${t.id ?? "flight"}-${i}`,
34
+ target: t.target,
35
+ property: i,
36
+ keyframes: n.map((l, c) => ({ time: l, value: e[c][o] }))
37
+ }));
38
+ }
39
+ const C = (t, n, e) => Math.max(0, Math.min(1, (t - n) / (e - n))), E = (t) => t * t * (3 - 2 * t), T = (t, n) => y.add(t, n), ve = (t, n) => y.scale(t, n);
40
+ function ke(t, n) {
41
+ const e = n + ((t - n + 2) % 4 + 4) % 4 - 2;
42
+ return e === 0 ? 0 : e;
43
+ }
44
+ function Q(t, n, e = 0) {
45
+ return Math.hypot(n[0] - t[0], n[2] - t[2]) < 1e-3 ? e : ke(Math.atan2(n[0] - t[0], n[2] - t[2]) * 2 / Math.PI, e);
46
+ }
47
+ function Oe() {
48
+ return {
49
+ turn: 1,
50
+ "head.turn": 90,
51
+ "leg.left.spread": 12,
52
+ "leg.right.spread": 12,
53
+ "leg.left.swing": 6,
54
+ "leg.right.swing": 6,
55
+ "leg.left.knee": 12,
56
+ "leg.right.knee": 12
57
+ };
58
+ }
59
+ function Ae(t, n) {
60
+ const e = t.objects.find((i) => i.id === n);
61
+ if (!e || e.kind !== "character") throw new Error(`cricketAction: required character '${n}' is missing`);
62
+ if (e.parent || e.rotation?.some((i) => i !== 0) || e.quaternion || e.scale !== void 0) throw new Error(`cricketAction: '${n}' must use position and pose.turn, without a transformed parent, scale or object rotation`);
63
+ return { object: e, who: He({ ...e.character, height: e.height ?? 1.78 }) };
64
+ }
65
+ function De(t) {
66
+ return { position: [...t.object.position ?? [0, 0, 0]], pose: { ...I, ...t.object.pose } };
67
+ }
68
+ function re(t, n, e, i) {
69
+ const o = ye(t.who.plan, n.pose, { height: t.who.height, contact: t.who.contact });
70
+ return T(n.position, o.chains[e][i]);
71
+ }
72
+ function ne(t, n, e) {
73
+ const i = re(t, n, `arm.${e}`, 2), o = re(t, n, `arm.${e}`, 1);
74
+ return T(i, ve(y.normalize(y.subtract(i, o)), t.who.lineWidth * 0.5));
75
+ }
76
+ function Je(t, n, e) {
77
+ const i = { ...n.pose, "head.turn": 0, "head.nod": 0, "head.tilt": 0 }, o = ye(t.who.plan, i, { height: t.who.height, contact: t.who.contact }).head, l = y.subtract(e, T(n.position, o.center)), c = o.axes.map((w) => y.dot(l, w)), d = Math.atan2(c[0], c[2]) * 180 / Math.PI, p = Math.atan2(-c[1], Math.hypot(c[0], c[2])) * 180 / Math.PI;
78
+ return { ...n, pose: { ...n.pose, "head.turn": Math.max(-90, Math.min(90, d)), "head.nod": Math.max(-25, Math.min(30, p)), "head.tilt": 0 } };
79
+ }
80
+ function D(t, n, e, i, o = "hold") {
81
+ let l = { ...n.pose };
82
+ for (let c = 0; c < 10; c++) {
83
+ const d = { ...n, pose: l }, p = ye(t.who.plan, l, { height: t.who.height, contact: t.who.contact }), w = Be(t.who.plan, l, t.who.height), m = y.subtract(ne(t, d, e), re(t, d, `arm.${e}`, 2)), h = y.subtract(y.subtract(y.subtract(i, m), n.position), p.hip), M = ze(h, (l.roll ?? 0) * Math.PI / 180), A = T(w.root, _e(M, -(l.turn ?? 0) * Math.PI / 2));
84
+ l = We(t.who.plan, l, `arm.${e}`, A, { height: t.who.height });
85
+ }
86
+ for (const [c, d] of Object.entries(ue[o])) l[`hand.${e}.${c}`] = d;
87
+ return { ...n, pose: l };
88
+ }
89
+ function Ue(t, n, e, i) {
90
+ const o = y.normalize(i), l = t.who.height / 1.78;
91
+ let c = D(t, n, "left", e);
92
+ return c = D(t, c, "right", T(ne(t, c, "left"), ve(o, 0.105 * l))), { ...c, bat: { grip: ne(t, c, "left"), axis: o, scale: l } };
93
+ }
94
+ function Ye(t) {
95
+ return T(t.grip, ve(t.axis, 0.51 * t.scale));
96
+ }
97
+ function Ie(t) {
98
+ const n = y.normalize(t), e = Math.max(-1, Math.min(1, n[1]));
99
+ return e > 0.999999 ? [0, 0, 0, 1] : e < -0.999999 ? Ee.fromAxisAngle([1, 0, 0], 180) : Ee.fromAxisAngle(y.normalize(y.cross([0, 1, 0], n)), Math.acos(e) * 180 / Math.PI).map((i) => i === 0 ? 0 : i);
100
+ }
101
+ function de(t, n, e) {
102
+ const i = {};
103
+ for (const o of Object.keys({ ...t, ...n })) {
104
+ const l = t[o] ?? I[o] ?? 0;
105
+ i[o] = l + ((n[o] ?? I[o] ?? 0) - l) * e;
106
+ }
107
+ return i;
108
+ }
109
+ function Se(t, n) {
110
+ if (t <= n[0][0]) return { ...I, ...n[0][1] };
111
+ for (let e = 1; e < n.length; e++)
112
+ if (t <= n[e][0]) return de({ ...I, ...n[e - 1][1] }, { ...I, ...n[e][1] }, E(C(t, n[e - 1][0], n[e][0])));
113
+ return { ...I, ...n.at(-1)[1] };
114
+ }
115
+ const O = Object.freeze({ length: 20.12, width: 3.05, poppingCrease: 1.22, returnCrease: 1.32, stumpHeight: 0.711, wicketWidth: 0.2286 });
116
+ function Ze(t) {
117
+ if (!t.id?.trim()) throw new Error("cricketPlayer: id is required");
118
+ J({ batter: 1, bowler: 1, keeper: 1, fielder: 1, umpire: 1 }, t.role, "cricketPlayer.role");
119
+ const n = J(Ce, t.preset ?? "youngMan", "cricketPlayer.preset"), e = J(fe, t.format ?? "t20", "cricketPlayer.format"), i = J({ none: 1, cap: 1, "sun-hat": 1 }, t.headwear ?? "none", "cricketPlayer.headwear"), o = n === "childBoy" || n === "childGirl", l = t.height ?? (o ? 1.24 : 1.78);
120
+ if (!Number.isFinite(l) || l < 0.5 || l > 3) throw new Error("cricketPlayer: height must be between .5 and 3 metres");
121
+ me(t.position ?? [0, 0, 0], "cricketPlayer.position");
122
+ const c = t.role === "umpire" ? "#f5ebd5" : e === "test" ? "#f5f0df" : t.color ?? "#3577b5", d = JSON.parse(JSON.stringify({
123
+ ...Ce[n],
124
+ ...t.appearance,
125
+ outfit: Ge("casual", { top: "shirt", shirt: c, trousers: t.role === "umpire" ? "#405058" : c, bottom: "trousers", trouserStyle: "plain", sleeves: "short", collar: !0, tie: null, shoes: "boots", shoeColor: "#f3ead7" }),
126
+ hat: i === "none" ? null : { style: i === "sun-hat" ? "sunHat" : "cap", color: c }
127
+ }));
128
+ return { id: t.id, name: t.role, kind: "character", look: "pen", height: l, position: [...t.position ?? [0, 0, 0]], character: d, pose: t.role === "batter" ? Oe() : { turn: t.role === "keeper" ? 2 : 0 } };
129
+ }
130
+ function he(t, n, e, i, o = 0) {
131
+ return { id: t, kind: "mesh", position: n, geometry: { type: "box", size: e }, material: i, layer: o };
132
+ }
133
+ function Qe(t, n) {
134
+ const e = O.stumpHeight, i = (O.wicketWidth - 0.036) / 2;
135
+ return [
136
+ ...[-1, 0, 1].map((o, l) => ({ id: `${t}-stump-${l}`, kind: "mesh", position: [o * i, e / 2, n], geometry: { type: "cylinder", radius: 0.018, height: e, segments: 10 }, material: "wicket" })),
137
+ ...[-1, 1].map((o, l) => he(`${t}-bail-${l}`, [o * i / 2, e + 0.015, n], [0.105, 0.025, 0.035], "bail"))
138
+ ];
139
+ }
140
+ function Pe(t, n) {
141
+ return [
142
+ { id: t, kind: "group", scale: n, visible: !1 },
143
+ he(`${t}-grip`, [0, 0.1, 0], [0.036, 0.28, 0.036], "bat-grip"),
144
+ he(`${t}-blade`, [0, 0.51, 0], [0.108, 0.54, 0.055], "bat-blade"),
145
+ he(`${t}-label`, [0, 0.41, 0.029], [0.07, 0.16, 4e-3], "bat-label")
146
+ ].map((i, o) => o === 0 ? i : { ...i, parent: t });
147
+ }
148
+ function Xe(t = {}) {
149
+ const n = J(fe, t.format ?? "t20", "cricketField.format"), e = J(Le, t.cast ?? "adults", "cricketField.cast"), i = t.boundaryRadius ?? 64;
150
+ if (!Number.isFinite(i) || i < 24 || i > 250) throw new Error("cricketField: boundaryRadius must be between 24 and 250 metres");
151
+ const o = t.id ?? "cricket";
152
+ if (!o.trim()) throw new Error("cricketField: id is required");
153
+ const l = O.length / 2, c = {
154
+ "striker-wicket": [0, 0, l],
155
+ "bowler-wicket": [0, 0, -l],
156
+ "striker-crease": [0, 0, l - O.poppingCrease],
157
+ "bowler-crease": [0, 0, -l + O.poppingCrease]
158
+ }, d = [
159
+ { id: "camera", kind: "camera", projection: "perspective", position: [25, 9, 6], lookAt: [0, 0.65, 0], fov: 48, near: 0.02, far: Math.max(600, i * 4) },
160
+ { id: "sun", kind: "light", light: "directional", position: [4, 8, 5], intensity: 0.8, color: "#fff2dd" },
161
+ { id: "ambient", kind: "light", light: "ambient", intensity: 0.85, color: "#eaf6f4" },
162
+ { id: "outfield", kind: "mesh", layer: -4, position: [0, -0.04, 0], geometry: { type: "cylinder", radius: i + 1, height: 0.06, segments: 80 }, material: "grass" },
163
+ { id: "square", kind: "mesh", layer: -3, geometry: { type: "plane", size: [8, 25] }, position: [0, 3e-3, 0], material: "square" },
164
+ { id: "pitch", kind: "mesh", layer: -2, geometry: { type: "plane", size: [O.width, O.length] }, position: [0, 8e-3, 0], material: "pitch" },
165
+ { id: "boundary", kind: "line", layer: -1, closed: !0, width: 0.15, color: "#f8f2db", points: Array.from({ length: 96 }, (h, M) => [Math.cos(M * Math.PI / 48) * i, 0.022, Math.sin(M * Math.PI / 48) * i]) }
166
+ ];
167
+ n !== "test" && d.push({ id: "fielding-circle", kind: "line", layer: -1, closed: !0, width: 0.06, color: "#d6e4c8", points: Array.from({ length: 80 }, (h, M) => [Math.cos(M * Math.PI / 40) * 27.43, 0.018, Math.sin(M * Math.PI / 40) * 27.43]) });
168
+ for (const h of [-1, 1]) {
169
+ const M = h > 0 ? "striker" : "bowler", A = h * l, R = A - h * O.poppingCrease;
170
+ d.push(...Qe(M, A));
171
+ const L = (q, G) => d.push({ id: `${M}-${q}`, kind: "line", layer: -1, color: "#fffdf0", width: 0.045, points: G });
172
+ L("popping-line", [[-1.83, 0.02, R], [1.83, 0.02, R]]), L("bowling-line", [[-1.32, 0.02, A], [1.32, 0.02, A]]);
173
+ for (const q of [-1, 1]) L(`return-line-${q < 0 ? "left" : "right"}`, [[q * 1.32, 0.02, R], [q * 1.32, 0.02, A + h * 2.5]]);
174
+ }
175
+ const p = [
176
+ ["batter", "batter", [-0.38, 0, 9.3]],
177
+ ["non-striker", "batter", [-0.85, 0, -9.3]],
178
+ ["bowler", "bowler", [0.68, 0, -17]],
179
+ ["keeper", "keeper", [0, 0, 11.25]],
180
+ ["fielder", "fielder", [12, 0, -3]],
181
+ ["slip", "fielder", [3.5, 0, 12]],
182
+ ["point", "fielder", [20, 0, 6]],
183
+ ["cover", "fielder", [22, 0, -16]],
184
+ ["mid-off", "fielder", [9, 0, -25]],
185
+ ["mid-on", "fielder", [-9, 0, -25]],
186
+ ["square-leg", "fielder", [-20, 0, 7]],
187
+ ["fine-leg", "fielder", [-20, 0, 35]],
188
+ ["third-man", "fielder", [23, 0, 35]],
189
+ ["umpire", "umpire", [0, 0, -12.4]],
190
+ ["square-umpire", "umpire", [-15, 0, 8.84]]
191
+ ];
192
+ p.forEach(([h, M, A], R) => {
193
+ const L = e === "children" || e === "mixed" && R % 3 === 0, q = e === "men" ? "youngMan" : L ? R % 2 ? "childGirl" : "childBoy" : R % 2 ? "youngWoman" : "youngMan", G = Math.hypot(A[0], A[2]), H = G > i * 0.88 ? [A[0] * i * 0.88 / G, 0, A[2] * i * 0.88 / G] : [...A];
194
+ c[h] = [...H];
195
+ const F = Ze({ id: h, role: M, preset: q, format: n, position: H, color: M === "batter" ? t.battingColor ?? "#397cb9" : t.fieldingColor ?? "#bf604e" });
196
+ if (Object.hasOwn(xe, h) && (F.name = xe[h]), h !== "batter") {
197
+ const S = h === "non-striker" || h === "bowler" ? p[0][2] : p.find(([ge]) => ge === "bowler")[2];
198
+ F.pose = { turn: Q(H, S) };
199
+ }
200
+ d.push(F);
201
+ });
202
+ const w = (h) => d.find((M) => M.id === h).height / 1.78;
203
+ d.push(...Pe("bat", w("batter")), ...Pe("non-striker-bat", w("non-striker"))), d.push({ id: "ball", kind: "mesh", position: [0, 0.075, 0], geometry: { type: "sphere", radius: 0.075, segments: 12 }, material: "ball" }), d.push({ id: "lbw-guide", kind: "group", visible: !1 }, { id: "lbw-projection", kind: "line", parent: "lbw-guide", points: [[0, 0, 0], [0, 1, 0]], width: 0.04, color: "#e9ae38" });
204
+ const m = (h) => ({ color: h, shading: "toon", outline: { color: "#69513a", width: 0.8 } });
205
+ return { format: n, boundaryRadius: i, landmarks: c, scene: {
206
+ id: o,
207
+ formatVersion: 1,
208
+ camera: "camera",
209
+ background: { top: "#c8e5ef", bottom: "#e9efcc" },
210
+ ground: 0,
211
+ objects: d,
212
+ materials: {
213
+ grass: { color: "#81a95c", shading: "unlit" },
214
+ square: { color: "#a6b76a", shading: "unlit", doubleSided: !0 },
215
+ pitch: { color: "#ddbd85", shading: "unlit", doubleSided: !0 },
216
+ wicket: m("#edd99e"),
217
+ bail: m("#bd8c4d"),
218
+ "bat-grip": m("#385b5c"),
219
+ "bat-blade": m("#e8c58d"),
220
+ "bat-label": m("#c34d4c"),
221
+ ball: { color: n === "test" ? "#b32d36" : "#fff9e7", shading: "toon", outline: { color: "#9b3840", width: 1 } }
222
+ }
223
+ } };
224
+ }
225
+ const N = 1900, ee = 2450, $ = 2900, te = 4100, V = 4200, Z = 4600, le = 5300, pe = 5500;
226
+ function ce(t, n, e, i, o, l, c = t.object.pose?.turn ?? 0) {
227
+ const d = C(n, e, i), p = y.distance(o, l), w = Q(o, l, c), m = c + (w - c) * E(C(n, e, e + 200)), h = { ...I, ...t.object.pose, turn: m }, M = Ke("run", t.who.height, 1, t.object.character?.legLength ?? 1), A = Ve("run", p * d / M, h), R = Math.min(d * 12, (1 - d) * 12, 1);
228
+ return { position: y.lerp(o, l, d), pose: de(h, A, Math.max(0, R)) };
229
+ }
230
+ function we(t, n, e) {
231
+ const i = (t.pose.turn ?? 0) * Math.PI / 2;
232
+ return T(t.position, [Math.sin(i) * n, e, Math.cos(i) * n]);
233
+ }
234
+ function et(t, n, e, i, o) {
235
+ const l = `${n}/${e.object.id}`, c = { ...I, ...e.object.pose }, d = new Set(o.flatMap((p) => Object.keys(p.pose)));
236
+ for (const p of d) {
237
+ const w = c[p] ?? 0;
238
+ o.some((m) => m.pose[p] !== w) && t.push({ id: `${e.object.id}-${p}`, target: l, property: p, keyframes: i.map((m, h) => ({ time: m, value: o[h].pose[p] ?? w })) });
239
+ }
240
+ for (const [p, w] of ["x", "y", "z"].entries())
241
+ o.some((m) => m.position[p] !== (e.object.position?.[p] ?? 0)) && t.push({ id: `${e.object.id}-${w}`, target: l, property: w, keyframes: i.map((m, h) => ({ time: m, value: o[h].position[p] })) });
242
+ if (o[0].bat) {
243
+ const p = e.object.id === "batter" ? "bat" : "non-striker-bat", w = `${n}/${p}`;
244
+ t.push({ id: `${p}-visible`, target: w, property: "visible", keyframes: [{ time: 0, value: 1 }] }), t.push({ id: `${p}-position`, target: w, property: "position", keyframes: i.map((m, h) => ({ time: m, value: [...o[h].bat.grip] })) }), t.push({ id: `${p}-rotation`, target: w, property: "quaternion", interpolation: "slerp", keyframes: i.map((m, h) => ({ time: m, value: Ie(o[h].bat.axis) })) });
245
+ }
246
+ }
247
+ function tt(t, n) {
248
+ const e = { runs: 0, extras: 0, wickets: 0, legalBall: !0, freeHitNext: !1 };
249
+ t === "running" && (e.runs = 1), t === "four" && (e.runs = 4), t === "six" && (e.runs = 6), (t === "wide" || t === "no-ball") && (e.extras = 1, e.legalBall = !1), t === "no-ball" && (e.freeHitNext = fe[n].freeHitAfterNoBall);
250
+ const o = { catch: "caught", bowled: "bowled", lbw: "lbw", stumping: "stumped", "run-out": "run-out" }[t];
251
+ return o && (e.wickets = 1, e.dismissal = o), e;
252
+ }
253
+ function rt(t, n = {}) {
254
+ const e = J(ae, n.action ?? "bowling", "cricketAction.action");
255
+ J(fe, t.format, "cricketAction.format");
256
+ const i = n.duration ?? 6e3;
257
+ if (!Number.isFinite(i) || i < 4e3 || i > 6e4) throw new Error("cricketAction: duration must be between 4000 and 60000 ms");
258
+ const o = t.scene.id;
259
+ for (const r of ["ball", "bat", "non-striker-bat", "lbw-guide", "striker-bail-0", "striker-bail-1", "bowler-bail-0", "bowler-bail-1"])
260
+ if (!t.scene.objects.some((a) => a.id === r)) throw new Error(`cricketAction: required equipment '${r}' is missing`);
261
+ const l = Object.fromEntries(["batter", "non-striker", "bowler", "keeper", "fielder", "umpire"].map((r) => [r, Ae(t.scene, r)]));
262
+ for (const r of ["slip", "point", "cover", "mid-off", "mid-on", "square-leg", "fine-leg", "third-man", "square-umpire"])
263
+ t.scene.objects.some((a) => a.id === r && a.kind === "character") && (l[r] = Ae(t.scene, r));
264
+ const c = (r) => l[r].who.height, d = (r) => De(l[r]), p = (r) => Math.round(r * 6e3 / i * 1e9) / 1e9, w = (r) => r * i / 6e3, m = ["batting", "defend", "running", "four", "six", "catch", "fielding", "throw", "run-out"].includes(e), h = ["bowling", "spin", "no-ball", "stumping"].includes(e), M = ["catch", "fielding", "throw", "run-out", "batting", "running"].includes(e), A = e === "running" || e === "run-out", R = /* @__PURE__ */ new Map(), L = [d("bowler").position[0], 0, e === "no-ball" ? -8.25 : -9.55], q = e === "fielding" ? [10.5, 0, 2] : [9, 0, -1], G = d("fielder").position, H = (r, a) => {
265
+ let v = R.get(r);
266
+ v || (v = /* @__PURE__ */ new Map(), R.set(r, v));
267
+ const g = v.get(a);
268
+ if (g) return g;
269
+ const k = l[r];
270
+ let s = d(r);
271
+ if (r === "bowler") {
272
+ const u = s.position;
273
+ if (a < 1400) {
274
+ const f = T(L, [0, 0, -0.65]);
275
+ s = ce(k, a, 0, 1400, u, f), s.pose["arm.right.swing"] = 45, s.pose["arm.right.elbow"] = 80;
276
+ } else
277
+ s.position = a <= N ? y.lerp(T(L, [0, 0, -0.65]), L, E(C(a, 1400, N))) : T(L, [0, 0, 0.8 * E(C(a, N, 2600))]), s.pose = Se(a, [
278
+ [1400, { turn: 0, "arm.right.swing": 285, "arm.right.elbow": 8, "arm.left.swing": 115, "leg.right.swing": 15, "leg.left.knee": 45 }],
279
+ [1800, { turn: 0, "arm.right.swing": 180, "arm.right.elbow": 0, "arm.left.swing": 80, "leg.right.swing": 25, "leg.right.knee": 0, "leg.left.swing": -25, "leg.left.knee": 60 }],
280
+ [N, { turn: 0, lean: 8, "arm.right.swing": 155, "arm.right.elbow": 0, "arm.left.swing": 45, "leg.right.swing": 25, "leg.right.knee": 0, "leg.left.swing": -25, "leg.left.knee": 60 }],
281
+ [2250, { turn: 0, lean: 26, bend: 12, "arm.right.swing": 40, "arm.right.elbow": 0, "arm.left.swing": -35, "leg.left.swing": -35, "leg.left.knee": 55 }],
282
+ [3e3, { turn: 0, "head.turn": 10 }],
283
+ [6e3, { turn: 0, "head.turn": 10 }]
284
+ ]);
285
+ e === "spin" && (s.pose = { ...s.pose, "arm.right.spread": 18, "head.tilt": -5 });
286
+ for (const [f, b] of Object.entries(a < N ? ue.hold : ue.open)) s.pose[`hand.right.${f}`] = b;
287
+ } else if (r === "batter" || r === "non-striker") {
288
+ const u = c(r);
289
+ if (e === "lbw" && r === "batter" && (s.position[0] = 0), e === "stumping" && r === "batter" && (s.position[2] -= 1.1 * E(C(a, 2150, 2800))), A && a > 3050) {
290
+ const f = H(r, 3050), b = r === "batter" ? [1, 0, -9.5] : [-1, 0, 9.5];
291
+ s = ce(k, a, 3050, e === "run-out" ? 6e3 : pe, f.position, b, f.pose.turn);
292
+ const W = ne(k, s, "right");
293
+ s.bat = { grip: W, axis: y.normalize([0.7, -0.35, 0.5]), scale: u / 1.78 };
294
+ } else {
295
+ s.pose = { ...s.pose, ...r === "batter" ? Oe() : { turn: 0.15, "leg.left.knee": 8, "leg.right.knee": 8 } };
296
+ let b = [0, -1, r === "batter" ? 0.05 : 0.12], x = T(s.position, [u * 0.15, u * 0.44, u * 0.04]);
297
+ if (r === "non-striker" && (x = T(s.position, [u * 0.08, u * 0.44, u * 0.17])), r === "batter") {
298
+ const W = E(C(a, 2100, 2600)) * (1 - E(C(a, 2600, $))), K = E(C(a, 2600, $)) * (1 - E(C(a, $, 3800))), z = E(C(a, $, 3250)) * (1 - E(C(a, 3250, 4e3)));
299
+ if (m) {
300
+ x = T(s.position, [u * (0.15 + 0.03 * W - 0.02 * K - 0.03 * z), u * (0.44 + 0.14 * W + 0.07 * K + 0.23 * z), u * (0.04 + 0.16 * W - 0.12 * K - 0.06 * z)]), b = y.normalize([0.15 * W + 0.25 * z, -1 + 1.85 * W + 1.6 * z, 0.05 + 0.55 * W - 0.4 * K - 0.8 * z]), s.pose.turn = 1 + 0.12 * K + 0.3 * z, s.pose.lean = 3 + 4 * K;
301
+ const _ = 12 + 4 * K;
302
+ s.pose["leg.left.spread"] = _, s.pose["leg.right.spread"] = _, e === "defend" && (b = [0, -1, -0.08], x = T(s.position, [u * 0.1, u * 0.5, -u * 0.12]));
303
+ } else if (["stumping", "bowled", "lbw"].includes(e)) {
304
+ const _ = E(C(a, 2100, 2700)) * (1 - E(C(a, 4e3, 4500)));
305
+ b = y.normalize([0.15 * _, -1 + 1.85 * _, 0.05 + 0.55 * _]), x = T(s.position, [u * (0.15 + 0.03 * _), u * (0.44 + 0.14 * _), u * (0.04 + 0.16 * _)]);
306
+ }
307
+ }
308
+ s = Ue(k, s, x, b);
309
+ }
310
+ } else if (r === "keeper") {
311
+ s.pose = { ...s.pose, turn: Q(s.position, d("bowler").position, 2), lean: 20, "leg.left.swing": 22, "leg.right.swing": 22, "leg.left.knee": 50, "leg.right.knee": 50 }, e === "wide" && (s.position[0] = 2.15 * E(C(a, 2900, 3500))), e === "stumping" && (s.position[2] -= 0.85 * E(C(a, 3400, 3900)));
312
+ const u = we(s, c(r) * 0.27, c(r) * 0.44);
313
+ if (e === "stumping" && a >= 3500) {
314
+ const f = we({ ...s, position: d(r).position }, c(r) * 0.27, c(r) * 0.44), b = [0, O.stumpHeight, O.length / 2], x = y.lerp(f, b, E(C(a, 3500, 3900)));
315
+ s = D(k, s, "right", x), s = D(k, s, "left", T(x, [0.045, 0, 0]));
316
+ } else
317
+ s = D(k, s, "right", u), s = D(k, s, "left", T(u, [0.045, 0, 0]));
318
+ } else if (r === "fielder" && M) {
319
+ if (s = ce(k, a, 3050, e === "catch" ? 3800 : 3950, G, q), a >= 3800) {
320
+ const u = { ...I, turn: Q(q, d("batter").position, s.pose.turn), lean: e === "catch" ? 5 : 42, bend: e === "catch" ? 0 : 18, "leg.left.swing": e === "catch" ? 0 : 45, "leg.right.swing": e === "catch" ? 0 : 45, "leg.left.knee": e === "catch" ? 0 : 85, "leg.right.knee": e === "catch" ? 0 : 85, smile: 0.7 };
321
+ s.pose = de(s.pose, u, E(C(a, 3800, V)));
322
+ const f = we(s, c(r) * 0.22, c(r) * (e === "catch" ? 0.73 : 0.2));
323
+ if (s = D(k, s, "right", f), s = D(k, s, "left", T(f, [0.035, 0, 0])), (e === "throw" || e === "run-out") && a > V) {
324
+ const b = { ...I, turn: Q(q, e === "throw" ? d("keeper").position : t.landmarks["bowler-wicket"], s.pose.turn), "arm.right.swing": 225, "arm.right.elbow": 60, "arm.left.spread": 70, "leg.left.swing": 15 }, x = { ...b, "arm.right.swing": 110, "arm.right.elbow": 0, lean: 15 };
325
+ s.pose = Se(a, [[V, s.pose], [4450, b], [Z, x], [4900, { ...I, turn: b.turn, "arm.right.swing": 25, lean: 22 }], [6e3, { ...I, turn: b.turn }]]);
326
+ }
327
+ }
328
+ } else if (r === "umpire") {
329
+ let u = { ...I };
330
+ const f = e === "stumping" ? 4150 : e === "run-out" ? 5150 : e === "bowled" || e === "lbw" ? 3500 : e === "catch" ? 4350 : 5100;
331
+ if (e === "no-ball") u = { ...u, "arm.right.spread": 90, "arm.right.elbow": 0 };
332
+ else if (e === "wide") u = { ...u, "arm.right.spread": 90, "arm.left.spread": 90, "arm.right.elbow": 0, "arm.left.elbow": 0 };
333
+ else if (e === "six") u = { ...u, "arm.right.spread": 180, "arm.left.spread": 180, "arm.right.elbow": 0, "arm.left.elbow": 0 };
334
+ else if (e === "four") u = { ...u, "arm.right.spread": 90 - 70 * (0.5 + Math.sin((a - 5100) / 180) * 0.5), "arm.right.elbow": 12 };
335
+ else if (["catch", "bowled", "lbw", "stumping", "run-out"].includes(e)) {
336
+ u = { ...u, "arm.right.swing": 165, "arm.right.elbow": 0 };
337
+ for (const [b, x] of Object.entries(ue.point)) u[`hand.right.${b}`] = x;
338
+ }
339
+ s.pose = de(s.pose, u, E(C(a, e === "no-ball" ? N : e === "wide" ? 3100 : f, (e === "no-ball" ? N : e === "wide" ? 3100 : f) + 350)));
340
+ }
341
+ return v.set(a, s), s;
342
+ }, F = (r, a) => ne(l[r], H(r, a), "right"), S = m ? Ye(H("batter", $).bat) : e === "lbw" ? y.lerp(re(l.batter, H("batter", $), "leg.right", 1), re(l.batter, H("batter", $), "leg.right", 2), 0.6) : [h ? O.wicketWidth / 2 + 0.075 + 0.15 : 0, 0.45, 9.25], ge = F("bowler", N), $e = [e === "wide" ? 0.85 : e === "spin" ? -0.35 : e === "lbw" ? S[0] * 0.6 : 0, 0.075, 3.9], ie = F("keeper", e === "stumping" ? 3400 : 3500), Re = F("fielder", te), Te = F("fielder", V), be = e === "run-out" ? "bowler" : "striker", B = e === "run-out" ? 5e3 : e === "stumping" ? 3900 : 3200, oe = [t.boundaryRadius * 0.8, e === "six" ? 2.1 : 0.075, -t.boundaryRadius * 0.6], P = (r, a, v, g, k, s = 0, u = 0) => Fe({ target: `${o}/ball`, start: a, end: v, from: g, to: k, arc: s, curve: u }, r), qe = (r) => {
343
+ if (r <= N) return F("bowler", r);
344
+ if (r <= ee) return P(r, N, ee, ge, $e, 0.15, e === "spin" ? 0.35 : 0);
345
+ const a = e === "wide" ? T(ie, [0, 0, -0.6]) : S;
346
+ if (r <= $) return P(r, ee, $, $e, a, 0.08);
347
+ if (e === "bowled") {
348
+ const g = [0, 0.36, O.length / 2];
349
+ return r <= B ? P(r, $, B, S, g) : P(r, B, 4100, g, [0, 0.075, 12.5], 0.2);
350
+ }
351
+ if (e === "lbw") return [...S];
352
+ if (["bowling", "spin", "no-ball", "wide", "stumping"].includes(e)) {
353
+ const g = e === "stumping" ? 3400 : 3500;
354
+ if (h && r <= g) {
355
+ const k = [a[0], ie[1], O.length / 2 + 0.2];
356
+ return r <= 3200 ? P(r, $, 3200, a, k, 0.04) : P(r, 3200, g, k, ie, 0.04);
357
+ }
358
+ return r <= g ? P(r, $, g, a, ie, 0.04) : F("keeper", r);
359
+ }
360
+ if (e === "defend") return P(r, $, 3400, S, T(S, [-0.5, -S[1] + 0.075, -0.7]), 0.12);
361
+ if (e === "four" || e === "six") {
362
+ if (e === "six") return r <= 5e3 ? P(r, $, 5e3, S, oe, 12) : P(r, 5e3, 5700, oe, T(oe, [2, -2.025, -1.5]));
363
+ const g = [5, 0.075, 5];
364
+ return r <= 3300 ? P(r, $, 3300, S, g, 0.5) : P(r, 3300, 5e3, g, oe);
365
+ }
366
+ if (e === "catch") return r <= te ? P(r, $, te, S, Re, 5) : F("fielder", r);
367
+ const v = [4, 0.075, 5];
368
+ if (r <= 3300) return P(r, $, 3300, S, v, 0.8);
369
+ if (r <= V) return P(r, 3300, V, v, Te);
370
+ if (e === "throw" || e === "run-out") {
371
+ if (r <= Z) return F("fielder", r);
372
+ const g = F("fielder", Z), k = e === "run-out" ? [0, 0.42, -O.length / 2] : F("keeper", le), s = e === "run-out" ? B : le;
373
+ return r <= s ? P(r, Z, s, g, k, 1.2) : e === "run-out" ? P(r, s, 5700, k, [0, 0.075, -12], 0.18) : F("keeper", r);
374
+ }
375
+ return [...Te];
376
+ }, X = [], j = (r, a, v, g, k) => X.push({ id: r, time: w(a), kind: v, label: g, caption: k });
377
+ j("setup", 0, "setup", ae[e].name, ae[e].summary), j("release", N, "release", "Ball released", e === "no-ball" ? "The front foot has landed beyond the popping crease. No-ball." : "The bowler releases the ball; the front foot is behind the popping crease."), j("bounce", ee, "bounce", "Pitch bounce", e === "spin" ? "The curved flight is illustrative. Spin can change the ball’s path after it bounces." : "The delivery bounces on the pitch on its way to the striker."), m ? j("contact", $, "contact", "Bat contact", "The ball meets the blade. The bat is keyed from the same two hand grips.") : e === "lbw" ? j("pad-contact", $, "contact", "Pad contact", "The highlighted path illustrates a ball that would hit the stumps. This is an authored LBW example.") : j("miss", $, "contact", e === "wide" ? "Beyond normal reach" : "The batter misses", e === "wide" ? "The untouched ball is too far away for a normal stroke. The umpire calls Wide." : "The untouched delivery passes the striker."), e === "catch" && j("catch", te, "collect", "Catch controlled", "The fielder controls the ball before it touches the ground: caught."), ["fielding", "throw", "run-out", "batting", "running"].includes(e) && j("gather", V, "collect", "Ground ball gathered", "The ball has touched the ground. Gathering it is fielding, not a catch dismissal."), ["bowling", "spin", "wide", "no-ball", "stumping"].includes(e) && j("keeper", e === "stumping" ? 3400 : 3500, "collect", "Keeper gathers", "The keeper controls the ball behind the striker’s wicket."), (e === "throw" || e === "run-out") && j("throw", Z, "throw", "Throw released", "The fielder releases the gathered ball toward the wicket."), e === "throw" && j("return", le, "collect", "Return received", "The keeper receives and controls the return throw."), e === "stumping" && j("wicket", B, "wicket", "Stumped", "Holding the ball, the keeper removes a bail. The striker is out of ground and is not attempting a run."), e === "run-out" && j("wicket", B, "wicket", "Run out", "The direct throw removes a bail before the running batter makes this ground."), e === "bowled" && j("wicket", B, "wicket", "Bowled", "The legal delivery hits the wicket and removes a bail."), (e === "four" || e === "six") && j("boundary", 5e3, "boundary", e === "four" ? "Four runs" : "Six runs", e === "four" ? "The struck ball reaches the boundary after touching the ground: four." : "The struck ball clears the boundary without touching the ground: six."), e === "running" && j("run", pe, "result", "One run completed", "Both batters have reached the opposite ground. One run is completed.");
378
+ const U = tt(e, t.format);
379
+ j("result", 5700, "result", "Illustrated result", e === "no-ball" ? `One no-ball extra; it does not count in the over.${U.freeHitNext ? " The next legitimate delivery is a free hit." : " Test cricket has no automatic free hit."}` : e === "wide" ? "One wide extra; the delivery does not count in the over." : e === "lbw" ? "LBW is declared for this illustrated legal delivery. A full decision also checks pitching, impact and any bat contact." : `${U.runs} bat runs · ${U.extras} extras · ${U.wickets} wicket${U.wickets === 1 ? "" : "s"}.`), X.sort((r, a) => r.time - a.time);
380
+ const se = je(0, i, n.every, [1400, 1800, N, 2100, 2150, 2250, ee, 2600, 2800, $, 3050, 3100, 3200, 3250, 3300, 3400, 3500, 3800, 3900, 3950, 4e3, te, V, 4350, 4450, Z, 4900, 5e3, 5100, 5150, le, pe, 5700].map(w)), Me = se.map((r) => qe(p(r))), Y = [];
381
+ for (const [r, a] of Object.entries(l)) {
382
+ let v = a.object.pose?.turn ?? 0, g = v;
383
+ const k = se.map((s, u) => {
384
+ const f = p(s);
385
+ let b = r === "fielder" && M && f > 3050 && f < 3250 ? ce(a, f, 3050, e === "catch" ? 3800 : 3950, G, q, g) : H(r, f), x = Me[u];
386
+ const W = !["batter", "non-striker", "bowler", "keeper"].includes(r);
387
+ if (W) {
388
+ const z = H("bowler", Math.min(f, N)), _ = T(z.position, [0, c("bowler") * 0.8, 0]);
389
+ x = f <= N ? _ : f < 2100 ? y.lerp(_, x, E(C(f, N, 2100))) : x;
390
+ }
391
+ if (A && (r === "batter" || r === "non-striker") && f > 3050 && (x = r === "batter" ? [1, c(r) * 0.8, -10.5] : [-1, c(r) * 0.8, 10.5]), r === "bowler" && f <= $ && (x = T(H("batter", f).position, [0, c("batter") * 0.65, 0])), W && (r !== "fielder" || !M || f <= 3050) || r === "bowler" && f >= 3e3) {
392
+ const z = Q(b.position, x, v);
393
+ v = r === "bowler" && f < 3500 ? (b.pose.turn ?? 0) + (ke(z, b.pose.turn ?? 0) - (b.pose.turn ?? 0)) * E(C(f, 3e3, 3500)) : z, b = { ...b, pose: { ...b.pose, turn: v } };
394
+ }
395
+ return r === "fielder" && M && (f === 3050 ? g = v : f > 3050 && (v = ke(b.pose.turn ?? 0, v), b = { ...b, pose: { ...b.pose, turn: v } })), Je(a, b, x);
396
+ });
397
+ et(Y, o, a, se, k);
398
+ }
399
+ for (const [r, a] of ["x", "y", "z"].entries()) Y.push({ id: `ball-${a}`, target: `${o}/ball`, property: a, keyframes: se.map((v, g) => ({ time: v, value: Me[g][r] })) });
400
+ if (["bowled", "stumping", "run-out"].includes(e))
401
+ for (let r = 0; r < 2; r++) {
402
+ const a = `${be}-bail-${r}`, g = t.scene.objects.find((k) => k.id === a).position;
403
+ Y.push({ id: `${a}-fall`, target: `${o}/${a}`, property: "position", keyframes: [{ time: 0, value: [...g] }, { time: w(B), value: [...g] }, { time: w(B + 180), value: T(g, [r ? 0.25 : -0.25, 0.22, be === "striker" ? 0.22 : -0.22]), easing: "ease-out" }, { time: w(B + 650), value: [g[0] + (r ? 0.4 : -0.4), 0.035, g[2] + (be === "striker" ? 0.45 : -0.45)], easing: "ease-in" }] }), Y.push({ id: `${a}-spin`, target: `${o}/${a}`, property: "rotateZ", keyframes: [{ time: 0, value: 0 }, { time: w(B), value: 0 }, { time: w(B + 650), value: r ? 145 : -145 }] });
404
+ }
405
+ if (e === "lbw") {
406
+ const r = [S[0] * 0.8, S[1], O.length / 2], a = y.subtract(r, S);
407
+ Y.push(
408
+ { id: "lbw-position", target: `${o}/lbw-guide`, property: "position", keyframes: [{ time: 0, value: [...S] }] },
409
+ { id: "lbw-rotation", target: `${o}/lbw-guide`, property: "quaternion", interpolation: "slerp", keyframes: [{ time: 0, value: Ie(a) }] },
410
+ { id: "lbw-length", target: `${o}/lbw-guide`, property: "scaleY", keyframes: [{ time: 0, value: y.distance(S, r) }] },
411
+ { id: "lbw-visible", target: `${o}/lbw-guide`, property: "visible", keyframes: [{ time: 0, value: 0 }, { time: w($) - 1e-3, value: 0 }, { time: w($), value: 1 }] }
412
+ );
413
+ }
414
+ return { action: e, duration: i, events: X, result: U, timeline: { id: `${o}-${e}`, formatVersion: 2, name: ae[e].name, config: { duration: i, markers: X.map((r) => ({ id: r.id, time: r.time, label: r.label })) }, captions: { en: Object.fromEntries(X.map((r) => [r.id, r.caption])) }, tracks: Y } };
415
+ }
416
+ function st(t = {}) {
417
+ const n = Xe(t);
418
+ return { ...n, ...rt(n, t) };
419
+ }
420
+ function at(t, n) {
421
+ if (!Number.isFinite(n)) throw new Error("cricketEventAt: time must be finite");
422
+ let e;
423
+ for (const i of t) {
424
+ if (i.time > n) break;
425
+ e = i;
426
+ }
427
+ return e;
428
+ }
429
+ export {
430
+ ae as CRICKET_ACTIONS,
431
+ ut as CRICKET_CAMERA_ANGLES,
432
+ Le as CRICKET_CASTS,
433
+ xe as CRICKET_FIELDING_POSITIONS,
434
+ fe as CRICKET_FORMATS,
435
+ O as CRICKET_PITCH,
436
+ ht as CRICKET_VIEWS,
437
+ Fe as ballFlightPoint,
438
+ ot as ballFlightTracks,
439
+ rt as cricketAction,
440
+ dt as cricketCameraTracks,
441
+ st as cricketClip,
442
+ at as cricketEventAt,
443
+ Xe as cricketField,
444
+ Ze as cricketPlayer
445
+ };