@algorisys/tinyfly 0.116.0 → 0.117.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.
@@ -1,68 +1,68 @@
1
- import { closestName as je, unknownName as it, deserializeTimeline as ie, playheadCrossings as De } from "@algorisys/tinyfly";
2
- import { D as re } from "./dom-adapter-Cphr2HZn.js";
3
- const _e = (t, e) => [t[0] + e[0], t[1] + e[1]], Xt = (t, e) => [t[0] - e[0], t[1] - e[1]], qt = (t, e) => [t[0] * e, t[1] * e], Re = (t, e) => t[0] * e[0] + t[1] * e[1], Ve = (t, e) => t[0] * e[1] - t[1] * e[0], ve = (t) => Math.hypot(t[0], t[1]);
4
- function we(t) {
5
- const e = ve(t);
1
+ import { randomNormal as De, createRandom as ce, hashSeed as ue, closestName as dn, unknownName as J, deserializeTimeline as ke, playheadCrossings as hn } from "@algorisys/tinyfly";
2
+ import { D as $e } from "./dom-adapter-Cphr2HZn.js";
3
+ const pn = (t, e) => [t[0] + e[0], t[1] + e[1]], de = (t, e) => [t[0] - e[0], t[1] - e[1]], Jt = (t, e) => [t[0] * e, t[1] * e], fn = (t, e) => t[0] * e[0] + t[1] * e[1], mn = (t, e) => t[0] * e[1] - t[1] * e[0], Re = (t) => Math.hypot(t[0], t[1]);
4
+ function _e(t) {
5
+ const e = Re(t);
6
6
  return e === 0 ? [0, 0] : [t[0] / e, t[1] / e];
7
7
  }
8
- const We = (t, e, n) => [t[0] + (e[0] - t[0]) * n, t[1] + (e[1] - t[1]) * n];
9
- function tt(t) {
8
+ const yn = (t, e, n) => [t[0] + (e[0] - t[0]) * n, t[1] + (e[1] - t[1]) * n];
9
+ function it(t) {
10
10
  return Array.isArray(t) && t.length === 2 && t.every(Number.isFinite);
11
11
  }
12
- const hi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
12
+ const Xi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
13
13
  __proto__: null,
14
- add: _e,
15
- cross: Ve,
16
- dot: Re,
17
- isVec2: tt,
18
- length: ve,
19
- lerp: We,
20
- normalize: we,
21
- scale: qt,
22
- sub: Xt
23
- }, Symbol.toStringTag, { value: "Module" })), yt = [1, 0, 0, 1], B = ([t, e, n, i], [r, s]) => [t * r + e * s, n * r + i * s];
24
- function Be(t, e) {
25
- const [n, i, r, s] = t, [o, l, c, f] = e;
26
- return [n * o + i * c, n * l + i * f, r * o + s * c, r * l + s * f];
27
- }
28
- const gt = ([t, e, n, i]) => t * i - e * n;
29
- function Ue(t) {
30
- const e = gt(t);
14
+ add: pn,
15
+ cross: mn,
16
+ dot: fn,
17
+ isVec2: it,
18
+ length: Re,
19
+ lerp: yn,
20
+ normalize: _e,
21
+ scale: Jt,
22
+ sub: de
23
+ }, Symbol.toStringTag, { value: "Module" })), xt = [1, 0, 0, 1], U = ([t, e, n, i], [s, r]) => [t * s + e * r, n * s + i * r];
24
+ function gn(t, e) {
25
+ const [n, i, s, r] = t, [o, l, c, d] = e;
26
+ return [n * o + i * c, n * l + i * d, s * o + r * c, s * l + r * d];
27
+ }
28
+ const St = ([t, e, n, i]) => t * i - e * n;
29
+ function bn(t) {
30
+ const e = St(t);
31
31
  if (Math.abs(e) < 1e-12) return;
32
- const [n, i, r, s] = t;
33
- return [s / e, -i / e, -r / e, n / e];
32
+ const [n, i, s, r] = t;
33
+ return [r / e, -i / e, -s / e, n / e];
34
34
  }
35
- const He = (t, e, n) => t.map((i, r) => i + (e[r] - i) * n), Xe = (t) => [Math.cos(t), -Math.sin(t), Math.sin(t), Math.cos(t)];
36
- function ke(t) {
37
- const [e, n, i, r] = t, s = e + r, o = gt(t), l = s * s - 4 * o, c = 1e-9;
35
+ const vn = (t, e, n) => t.map((i, s) => i + (e[s] - i) * n), wn = (t) => [Math.cos(t), -Math.sin(t), Math.sin(t), Math.cos(t)];
36
+ function Ve(t) {
37
+ const [e, n, i, s] = t, r = e + s, o = St(t), l = r * r - 4 * o, c = 1e-9;
38
38
  if (l < -c) return [];
39
- const f = Math.sqrt(Math.max(0, l)), u = f < c ? [s / 2] : [(s + f) / 2, (s - f) / 2], h = [];
40
- for (const d of u) {
41
- const a = [[e - d, n], [i, r - d]].reduce((w, $) => Math.hypot(...$) > Math.hypot(...w) ? $ : w);
42
- if (Math.hypot(...a) < c) {
43
- h.push({ value: d, vector: [1, 0] }, { value: d, vector: [0, 1] });
39
+ const d = Math.sqrt(Math.max(0, l)), u = d < c ? [r / 2] : [(r + d) / 2, (r - d) / 2], p = [];
40
+ for (const h of u) {
41
+ const f = [[e - h, n], [i, s - h]].reduce((w, M) => Math.hypot(...M) > Math.hypot(...w) ? M : w);
42
+ if (Math.hypot(...f) < c) {
43
+ p.push({ value: h, vector: [1, 0] }, { value: h, vector: [0, 1] });
44
44
  continue;
45
45
  }
46
- const p = [-a[1], a[0]], m = Math.hypot(...p), b = p[0] < -c || Math.abs(p[0]) <= c && p[1] < 0 ? -1 : 1;
47
- h.push({ value: d, vector: [b * p[0] / m + 0, b * p[1] / m + 0] });
46
+ const y = [-f[1], f[0]], a = Math.hypot(...y), g = y[0] < -c || Math.abs(y[0]) <= c && y[1] < 0 ? -1 : 1;
47
+ p.push({ value: h, vector: [g * y[0] / a + 0, g * y[1] / a + 0] });
48
48
  }
49
- return h;
49
+ return p;
50
50
  }
51
- function lt(t) {
51
+ function pt(t) {
52
52
  return Array.isArray(t) && t.length === 4 && t.every(Number.isFinite);
53
53
  }
54
- const fi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
54
+ const Yi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
55
55
  __proto__: null,
56
- IDENTITY: yt,
57
- apply: B,
58
- determinant: gt,
59
- eigen: ke,
60
- inverse: Ue,
61
- isMat2: lt,
62
- lerp: He,
63
- multiply: Be,
64
- rotation: Xe
65
- }, Symbol.toStringTag, { value: "Module" })), zt = {
56
+ IDENTITY: xt,
57
+ apply: U,
58
+ determinant: St,
59
+ eigen: Ve,
60
+ inverse: bn,
61
+ isMat2: pt,
62
+ lerp: vn,
63
+ multiply: gn,
64
+ rotation: wn
65
+ }, Symbol.toStringTag, { value: "Module" })), Qt = {
66
66
  sin: { arity: 1, apply: Math.sin },
67
67
  cos: { arity: 1, apply: Math.cos },
68
68
  tan: { arity: 1, apply: Math.tan },
@@ -88,8 +88,8 @@ const fi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
88
88
  // The logistic function, common in ML lessons
89
89
  sigmoid: { arity: 1, apply: (t) => 1 / (1 + Math.exp(-t)) },
90
90
  relu: { arity: 1, apply: (t) => Math.max(0, t) }
91
- }, Et = { pi: Math.PI, e: Math.E, tau: Math.PI * 2 };
92
- class ot extends Error {
91
+ }, Ct = { pi: Math.PI, e: Math.E, tau: Math.PI * 2 };
92
+ class ht extends Error {
93
93
  source;
94
94
  /** 0-based index into the source */
95
95
  position;
@@ -97,7 +97,7 @@ class ot extends Error {
97
97
  super(`${e} at ${i + 1} in "${n}"`), this.name = "ExpressionError", this.source = n, this.position = i;
98
98
  }
99
99
  }
100
- function Ye(t) {
100
+ function kn(t) {
101
101
  const e = [];
102
102
  let n = 0;
103
103
  for (; n < t.length; ) {
@@ -106,192 +106,192 @@ function Ye(t) {
106
106
  n++;
107
107
  continue;
108
108
  }
109
- const r = /^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(t.slice(n));
110
- if (r) {
111
- e.push({ kind: "number", value: Number(r[0]), at: n }), n += r[0].length;
109
+ const s = /^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(t.slice(n));
110
+ if (s) {
111
+ e.push({ kind: "number", value: Number(s[0]), at: n }), n += s[0].length;
112
112
  continue;
113
113
  }
114
- const s = /^[A-Za-z_][A-Za-z_0-9]*/.exec(t.slice(n));
115
- if (s) {
116
- e.push({ kind: "name", value: s[0], at: n }), n += s[0].length;
114
+ const r = /^[A-Za-z_][A-Za-z_0-9]*/.exec(t.slice(n));
115
+ if (r) {
116
+ e.push({ kind: "name", value: r[0], at: n }), n += r[0].length;
117
117
  continue;
118
118
  }
119
119
  if ("+-*/^(),".includes(i)) {
120
120
  e.push({ kind: "op", value: i, at: n }), n++;
121
121
  continue;
122
122
  }
123
- throw new ot(`Unexpected "${i}"`, t, n);
123
+ throw new ht(`Unexpected "${i}"`, t, n);
124
124
  }
125
125
  return e.push({ kind: "end", at: t.length }), e;
126
126
  }
127
- function At(t) {
127
+ function lt(t) {
128
128
  if (typeof t != "string") throw new TypeError("parseExpression: expected a string");
129
- const e = Ye(t);
129
+ const e = kn(t);
130
130
  let n = 0;
131
- const i = () => e[n], r = (d) => {
132
- const y = i();
133
- return y.kind === "op" && y.value === d;
134
- }, s = (d) => {
135
- if (!r(d)) throw new ot(`Expected "${d}"`, t, i().at);
131
+ const i = () => e[n], s = (h) => {
132
+ const m = i();
133
+ return m.kind === "op" && m.value === h;
134
+ }, r = (h) => {
135
+ if (!s(h)) throw new ht(`Expected "${h}"`, t, i().at);
136
136
  n++;
137
137
  }, o = () => {
138
- let d = l();
139
- for (; r("+") || r("-"); )
140
- d = { type: "binary", operator: e[n++].value, left: d, right: l() };
141
- return d;
138
+ let h = l();
139
+ for (; s("+") || s("-"); )
140
+ h = { type: "binary", operator: e[n++].value, left: h, right: l() };
141
+ return h;
142
142
  }, l = () => {
143
- let d = c();
143
+ let h = c();
144
144
  for (; ; )
145
- if (r("*") || r("/"))
146
- d = { type: "binary", operator: e[n++].value, left: d, right: c() };
147
- else if (i().kind === "name" || i().kind === "number" || r("("))
148
- d = { type: "binary", operator: "*", left: d, right: f() };
145
+ if (s("*") || s("/"))
146
+ h = { type: "binary", operator: e[n++].value, left: h, right: c() };
147
+ else if (i().kind === "name" || i().kind === "number" || s("("))
148
+ h = { type: "binary", operator: "*", left: h, right: d() };
149
149
  else
150
- return d;
151
- }, c = () => r("-") || r("+") ? { type: "unary", operator: e[n++].value, operand: c() } : f(), f = () => {
152
- const d = u();
153
- return r("^") ? (n++, { type: "binary", operator: "^", left: d, right: c() }) : d;
150
+ return h;
151
+ }, c = () => s("-") || s("+") ? { type: "unary", operator: e[n++].value, operand: c() } : d(), d = () => {
152
+ const h = u();
153
+ return s("^") ? (n++, { type: "binary", operator: "^", left: h, right: c() }) : h;
154
154
  }, u = () => {
155
- const d = i();
156
- if (d.kind === "number")
157
- return n++, { type: "number", value: d.value };
158
- if (d.kind === "name") {
159
- if (n++, !r("(")) return { type: "name", name: d.value };
160
- const y = Object.prototype.hasOwnProperty.call(zt, d.value) ? zt[d.value] : void 0;
161
- if (!y) throw new ot(`Unknown function "${d.value}"`, t, d.at);
155
+ const h = i();
156
+ if (h.kind === "number")
157
+ return n++, { type: "number", value: h.value };
158
+ if (h.kind === "name") {
159
+ if (n++, !s("(")) return { type: "name", name: h.value };
160
+ const m = Object.prototype.hasOwnProperty.call(Qt, h.value) ? Qt[h.value] : void 0;
161
+ if (!m) throw new ht(`Unknown function "${h.value}"`, t, h.at);
162
162
  n++;
163
- const a = [];
164
- if (!r(")"))
165
- for (a.push(o()); r(","); )
166
- n++, a.push(o());
167
- if (s(")"), a.length !== y.arity)
168
- throw new ot(`"${d.value}" takes ${y.arity} argument${y.arity === 1 ? "" : "s"}, got ${a.length}`, t, d.at);
169
- return { type: "call", name: d.value, args: a };
170
- }
171
- if (r("(")) {
163
+ const f = [];
164
+ if (!s(")"))
165
+ for (f.push(o()); s(","); )
166
+ n++, f.push(o());
167
+ if (r(")"), f.length !== m.arity)
168
+ throw new ht(`"${h.value}" takes ${m.arity} argument${m.arity === 1 ? "" : "s"}, got ${f.length}`, t, h.at);
169
+ return { type: "call", name: h.value, args: f };
170
+ }
171
+ if (s("(")) {
172
172
  n++;
173
- const y = o();
174
- return s(")"), y;
173
+ const m = o();
174
+ return r(")"), m;
175
175
  }
176
- throw new ot(d.kind === "end" ? "Unexpected end" : `Unexpected "${d.value}"`, t, d.at);
177
- }, h = o();
178
- if (i().kind !== "end") throw new ot(`Unexpected "${i().value}"`, t, i().at);
179
- return h;
176
+ throw new ht(h.kind === "end" ? "Unexpected end" : `Unexpected "${h.value}"`, t, h.at);
177
+ }, p = o();
178
+ if (i().kind !== "end") throw new ht(`Unexpected "${i().value}"`, t, i().at);
179
+ return p;
180
180
  }
181
- function Ze(t) {
181
+ function Me(t) {
182
182
  const e = /* @__PURE__ */ new Set(), n = (i) => {
183
- i.type === "name" && !(i.name in Et) ? e.add(i.name) : i.type === "unary" ? n(i.operand) : i.type === "binary" ? (n(i.left), n(i.right)) : i.type === "call" && i.args.forEach(n);
183
+ i.type === "name" && !(i.name in Ct) ? e.add(i.name) : i.type === "unary" ? n(i.operand) : i.type === "binary" ? (n(i.left), n(i.right)) : i.type === "call" && i.args.forEach(n);
184
184
  };
185
185
  return n(t), [...e].sort();
186
186
  }
187
- const E = (t) => ({ type: "number", value: t }), ft = E(0), O = E(1), I = (t) => t.type === "number", _ = (t, e) => t.type === "number" && t.value === e;
188
- function J(t, e) {
189
- return I(t) && I(e) ? E(t.value + e.value) : _(t, 0) ? e : _(e, 0) ? t : { type: "binary", operator: "+", left: t, right: e };
187
+ const O = (t) => ({ type: "number", value: t }), kt = O(0), I = O(1), C = (t) => t.type === "number", _ = (t, e) => t.type === "number" && t.value === e;
188
+ function nt(t, e) {
189
+ return C(t) && C(e) ? O(t.value + e.value) : _(t, 0) ? e : _(e, 0) ? t : { type: "binary", operator: "+", left: t, right: e };
190
190
  }
191
- function H(t, e) {
192
- return I(t) && I(e) ? E(t.value - e.value) : _(e, 0) ? t : _(t, 0) ? Mt(e) : { type: "binary", operator: "-", left: t, right: e };
191
+ function X(t, e) {
192
+ return C(t) && C(e) ? O(t.value - e.value) : _(e, 0) ? t : _(t, 0) ? Lt(e) : { type: "binary", operator: "-", left: t, right: e };
193
193
  }
194
- function A(t, e) {
195
- return I(t) && I(e) ? E(t.value * e.value) : _(t, 0) || _(e, 0) ? ft : _(t, 1) ? e : _(e, 1) ? t : I(e) ? A(e, t) : I(t) && e.type === "binary" && e.operator === "*" && I(e.left) ? A(E(t.value * e.left.value), e.right) : { type: "binary", operator: "*", left: t, right: e };
194
+ function P(t, e) {
195
+ return C(t) && C(e) ? O(t.value * e.value) : _(t, 0) || _(e, 0) ? kt : _(t, 1) ? e : _(e, 1) ? t : C(e) ? P(e, t) : C(t) && e.type === "binary" && e.operator === "*" && C(e.left) ? P(O(t.value * e.left.value), e.right) : { type: "binary", operator: "*", left: t, right: e };
196
196
  }
197
- function q(t, e) {
198
- return _(t, 0) ? ft : _(e, 1) ? t : I(t) && I(e) && e.value !== 0 ? E(t.value / e.value) : { type: "binary", operator: "/", left: t, right: e };
197
+ function j(t, e) {
198
+ return _(t, 0) ? kt : _(e, 1) ? t : C(t) && C(e) && e.value !== 0 ? O(t.value / e.value) : { type: "binary", operator: "/", left: t, right: e };
199
199
  }
200
- function Z(t, e) {
201
- return _(e, 0) ? O : _(e, 1) ? t : I(t) && I(e) ? E(t.value ** e.value) : { type: "binary", operator: "^", left: t, right: e };
200
+ function Q(t, e) {
201
+ return _(e, 0) ? I : _(e, 1) ? t : C(t) && C(e) ? O(t.value ** e.value) : { type: "binary", operator: "^", left: t, right: e };
202
202
  }
203
- function Mt(t) {
204
- return I(t) ? E(-t.value) : t.type === "unary" && t.operator === "-" ? t.operand : { type: "unary", operator: "-", operand: t };
203
+ function Lt(t) {
204
+ return C(t) ? O(-t.value) : t.type === "unary" && t.operator === "-" ? t.operand : { type: "unary", operator: "-", operand: t };
205
205
  }
206
- const z = (t, ...e) => ({ type: "call", name: t, args: e });
207
- function rt(t, e) {
206
+ const D = (t, ...e) => ({ type: "call", name: t, args: e });
207
+ function at(t, e) {
208
208
  switch (t.type) {
209
209
  case "number":
210
210
  return !0;
211
211
  case "name":
212
212
  return t.name !== e;
213
213
  case "unary":
214
- return rt(t.operand, e);
214
+ return at(t.operand, e);
215
215
  case "binary":
216
- return rt(t.left, e) && rt(t.right, e);
216
+ return at(t.left, e) && at(t.right, e);
217
217
  case "call":
218
- return t.args.every((n) => rt(n, e));
218
+ return t.args.every((n) => at(n, e));
219
219
  }
220
220
  }
221
- function G(t, e = "x") {
222
- if (rt(t, e)) return ft;
221
+ function tt(t, e = "x") {
222
+ if (at(t, e)) return kt;
223
223
  switch (t.type) {
224
224
  case "number":
225
- return ft;
225
+ return kt;
226
226
  case "name":
227
- return t.name === e ? O : ft;
227
+ return t.name === e ? I : kt;
228
228
  case "unary":
229
- return t.operator === "-" ? Mt(G(t.operand, e)) : G(t.operand, e);
229
+ return t.operator === "-" ? Lt(tt(t.operand, e)) : tt(t.operand, e);
230
230
  case "binary": {
231
- const { left: n, right: i } = t, r = () => G(n, e), s = () => G(i, e);
231
+ const { left: n, right: i } = t, s = () => tt(n, e), r = () => tt(i, e);
232
232
  switch (t.operator) {
233
233
  case "+":
234
- return J(r(), s());
234
+ return nt(s(), r());
235
235
  case "-":
236
- return H(r(), s());
236
+ return X(s(), r());
237
237
  case "*":
238
- return J(A(r(), i), A(n, s()));
238
+ return nt(P(s(), i), P(n, r()));
239
239
  case "/":
240
- return q(H(A(r(), i), A(n, s())), Z(i, E(2)));
240
+ return j(X(P(s(), i), P(n, r())), Q(i, O(2)));
241
241
  case "^":
242
- if (rt(i, e)) {
243
- const o = I(i) ? E(i.value - 1) : H(i, O);
244
- return A(A(i, Z(n, o)), r());
242
+ if (at(i, e)) {
243
+ const o = C(i) ? O(i.value - 1) : X(i, I);
244
+ return P(P(i, Q(n, o)), s());
245
245
  }
246
- return rt(n, e) ? A(A(t, z("ln", n)), s()) : A(t, J(A(s(), z("ln", n)), q(A(i, r()), n)));
246
+ return at(n, e) ? P(P(t, D("ln", n)), r()) : P(t, nt(P(r(), D("ln", n)), j(P(i, s()), n)));
247
247
  }
248
248
  break;
249
249
  }
250
250
  case "call": {
251
- const [n, i] = t.args, r = () => G(n, e), s = (o) => A(o, r());
251
+ const [n, i] = t.args, s = () => tt(n, e), r = (o) => P(o, s());
252
252
  switch (t.name) {
253
253
  case "sin":
254
- return s(z("cos", n));
254
+ return r(D("cos", n));
255
255
  case "cos":
256
- return s(Mt(z("sin", n)));
256
+ return r(Lt(D("sin", n)));
257
257
  case "tan":
258
- return s(q(O, Z(z("cos", n), E(2))));
258
+ return r(j(I, Q(D("cos", n), O(2))));
259
259
  case "asin":
260
- return s(q(O, z("sqrt", H(O, Z(n, E(2))))));
260
+ return r(j(I, D("sqrt", X(I, Q(n, O(2))))));
261
261
  case "acos":
262
- return s(Mt(q(O, z("sqrt", H(O, Z(n, E(2)))))));
262
+ return r(Lt(j(I, D("sqrt", X(I, Q(n, O(2)))))));
263
263
  case "atan":
264
- return s(q(O, J(O, Z(n, E(2)))));
264
+ return r(j(I, nt(I, Q(n, O(2)))));
265
265
  case "sinh":
266
- return s(z("cosh", n));
266
+ return r(D("cosh", n));
267
267
  case "cosh":
268
- return s(z("sinh", n));
268
+ return r(D("sinh", n));
269
269
  case "tanh":
270
- return s(H(O, Z(z("tanh", n), E(2))));
270
+ return r(X(I, Q(D("tanh", n), O(2))));
271
271
  case "exp":
272
- return s(t);
272
+ return r(t);
273
273
  case "ln":
274
- return s(q(O, n));
274
+ return r(j(I, n));
275
275
  case "log":
276
- return s(q(O, A(n, E(Math.LN10))));
276
+ return r(j(I, P(n, O(Math.LN10))));
277
277
  case "log2":
278
- return s(q(O, A(n, E(Math.LN2))));
278
+ return r(j(I, P(n, O(Math.LN2))));
279
279
  case "sqrt":
280
- return s(q(O, A(E(2), t)));
280
+ return r(j(I, P(O(2), t)));
281
281
  case "abs":
282
- return s(z("sign", n));
282
+ return r(D("sign", n));
283
283
  case "sigmoid":
284
- return s(A(t, H(O, t)));
284
+ return r(P(t, X(I, t)));
285
285
  case "relu":
286
- return s(q(J(z("sign", n), O), E(2)));
286
+ return r(j(nt(D("sign", n), I), O(2)));
287
287
  case "atan2": {
288
- const o = G(i, e);
289
- return q(H(A(i, r()), A(n, o)), J(Z(n, E(2)), Z(i, E(2))));
288
+ const o = tt(i, e);
289
+ return j(X(P(i, s()), P(n, o)), nt(Q(n, O(2)), Q(i, O(2))));
290
290
  }
291
291
  case "min":
292
292
  case "max": {
293
- const o = t.name === "max" ? 1 : -1, l = G(i, e), c = q(J(O, A(E(o), z("sign", H(n, i)))), E(2));
294
- return J(A(c, r()), A(H(O, c), l));
293
+ const o = t.name === "max" ? 1 : -1, l = tt(i, e), c = j(nt(I, P(O(o), D("sign", X(n, i)))), O(2));
294
+ return nt(P(c, s()), P(X(I, c), l));
295
295
  }
296
296
  }
297
297
  throw new Error(`differentiate: "${t.name}" has no derivative rule`);
@@ -299,40 +299,40 @@ function G(t, e = "x") {
299
299
  }
300
300
  throw new Error("differentiate: malformed expression");
301
301
  }
302
- function Ge(t, e, n = "x") {
302
+ function $n(t, e, n = "x") {
303
303
  let i = t;
304
- for (let r = 0; r < e; r++) i = G(i, n);
304
+ for (let s = 0; s < e; s++) i = tt(i, n);
305
305
  return i;
306
306
  }
307
- function $t(t) {
307
+ function Pt(t) {
308
308
  switch (t.type) {
309
309
  case "number":
310
310
  return t.value < 0 ? `(${t.value})` : String(t.value);
311
311
  case "name":
312
312
  return t.name;
313
313
  case "unary":
314
- return `(${t.operator}${$t(t.operand)})`;
314
+ return `(${t.operator}${Pt(t.operand)})`;
315
315
  case "binary":
316
- return `(${$t(t.left)} ${t.operator} ${$t(t.right)})`;
316
+ return `(${Pt(t.left)} ${t.operator} ${Pt(t.right)})`;
317
317
  case "call":
318
- return `${t.name}(${t.args.map($t).join(", ")})`;
318
+ return `${t.name}(${t.args.map(Pt).join(", ")})`;
319
319
  }
320
320
  }
321
- function at(t, e = {}) {
321
+ function rt(t, e = {}) {
322
322
  switch (t.type) {
323
323
  case "number":
324
324
  return t.value;
325
325
  case "name": {
326
326
  if (Object.prototype.hasOwnProperty.call(e, t.name)) return e[t.name];
327
- if (Object.prototype.hasOwnProperty.call(Et, t.name)) return Et[t.name];
327
+ if (Object.prototype.hasOwnProperty.call(Ct, t.name)) return Ct[t.name];
328
328
  throw new Error(`evaluate: unknown name "${t.name}"`);
329
329
  }
330
330
  case "unary": {
331
- const n = at(t.operand, e);
331
+ const n = rt(t.operand, e);
332
332
  return t.operator === "-" ? -n : n;
333
333
  }
334
334
  case "binary": {
335
- const n = at(t.left, e), i = at(t.right, e);
335
+ const n = rt(t.left, e), i = rt(t.right, e);
336
336
  switch (t.operator) {
337
337
  case "+":
338
338
  return n + i;
@@ -348,110 +348,356 @@ function at(t, e = {}) {
348
348
  break;
349
349
  }
350
350
  case "call":
351
- return zt[t.name].apply(...t.args.map((n) => at(n, e)));
351
+ return Qt[t.name].apply(...t.args.map((n) => rt(n, e)));
352
352
  }
353
353
  throw new Error("evaluate: malformed expression");
354
354
  }
355
- const St = /* @__PURE__ */ new Map();
356
- function D(t, e = "x") {
357
- let n = St.get(t);
358
- n || (n = At(t), St.size < 256 && St.set(t, n));
355
+ const Ft = /* @__PURE__ */ new Map();
356
+ function R(t, e = "x") {
357
+ let n = Ft.get(t);
358
+ n || (n = lt(t), Ft.size < 256 && Ft.set(t, n));
359
359
  const i = n;
360
- return (r, s = {}) => at(i, { ...s, [e]: r });
360
+ return (s, r = {}) => rt(i, { ...r, [e]: s });
361
361
  }
362
- const Nt = /* @__PURE__ */ new Map();
363
- function Yt(t, e, n = "x") {
362
+ const Wt = /* @__PURE__ */ new Map();
363
+ function he(t, e, n = "x") {
364
364
  if (!Number.isInteger(e) || e < 0) throw new Error(`compileDerivative: order must be a whole number ≥ 0, got ${e}`);
365
365
  const i = `${n}|${e}|${t}`;
366
- let r = Nt.get(i);
367
- if (!r) {
368
- let o = St.get(t);
369
- o || (o = At(t)), r = Ge(o, e, n), Nt.size < 512 && Nt.set(i, r);
366
+ let s = Wt.get(i);
367
+ if (!s) {
368
+ let o = Ft.get(t);
369
+ o || (o = lt(t)), s = $n(o, e, n), Wt.size < 512 && Wt.set(i, s);
370
370
  }
371
- const s = r;
372
- return (o, l = {}) => at(s, { ...l, [n]: o });
371
+ const r = s;
372
+ return (o, l = {}) => rt(r, { ...l, [n]: o });
373
373
  }
374
- function $e(t) {
374
+ function Be(t) {
375
375
  const e = {};
376
376
  for (const [n, i] of Object.entries(t))
377
377
  if (typeof i == "number")
378
378
  e[n] = i;
379
- else if (lt(i)) {
380
- const [r, s, o, l] = i;
381
- Object.assign(e, { [`${n}.a`]: r, [`${n}.b`]: s, [`${n}.c`]: o, [`${n}.d`]: l, [`${n}.det`]: gt(i) });
382
- } else tt(i) && Object.assign(e, { [`${n}.x`]: i[0], [`${n}.y`]: i[1], [`${n}.length`]: Math.hypot(i[0], i[1]) });
379
+ else if (pt(i)) {
380
+ const [s, r, o, l] = i;
381
+ Object.assign(e, { [`${n}.a`]: s, [`${n}.b`]: r, [`${n}.c`]: o, [`${n}.d`]: l, [`${n}.det`]: St(i) });
382
+ } else it(i) && Object.assign(e, { [`${n}.x`]: i[0], [`${n}.y`]: i[1], [`${n}.length`]: Math.hypot(i[0], i[1]) });
383
383
  return e;
384
384
  }
385
- function F(t, e, n) {
385
+ function E(t, e, n) {
386
386
  return e ? Object.prototype.hasOwnProperty.call(t.colors, e) ? t.colors[e] : e : n;
387
387
  }
388
- function pt(t, e) {
388
+ function $t(t, e) {
389
389
  if (typeof e != "string") return e;
390
390
  const n = t[e];
391
- if (!tt(n)) throw new Error(`math figure: value "${e}" is not an [x, y] vector`);
391
+ if (!it(n)) throw new Error(`math figure: value "${e}" is not an [x, y] vector`);
392
392
  return n;
393
393
  }
394
- function st(t, e) {
395
- if (e === void 0) return yt;
394
+ function ct(t, e) {
395
+ if (e === void 0) return xt;
396
396
  const n = t[e];
397
- if (!lt(n)) throw new Error(`math figure: value "${e}" is not a [a, b, c, d] matrix`);
397
+ if (!pt(n)) throw new Error(`math figure: value "${e}" is not a [a, b, c, d] matrix`);
398
398
  return n;
399
399
  }
400
- function N(t, e) {
400
+ function S(t, e) {
401
401
  if (typeof e == "number") return e;
402
402
  const n = t[e];
403
403
  if (typeof n != "number") throw new Error(`math figure: value "${e}" is not a number`);
404
404
  return n;
405
405
  }
406
- function se(t, e, n, i = 512) {
407
- if (e === n) return 0;
408
- const r = (n - e) / i;
409
- let s = t(e) + t(n);
410
- for (let o = 1; o < i; o++) s += t(e + o * r) * (o % 2 ? 4 : 2);
411
- return s * r / 3;
406
+ function ft(t, e) {
407
+ const n = (s) => s === void 0 ? void 0 : S(t, s), i = (s) => s === void 0 ? void 0 : Math.round(S(t, s));
408
+ switch (e.kind) {
409
+ case "normal":
410
+ return { kind: "normal", mean: n(e.mean), sd: n(e.sd) };
411
+ case "uniform":
412
+ return { kind: "uniform", min: n(e.min), max: n(e.max) };
413
+ case "exponential":
414
+ return { kind: "exponential", rate: n(e.rate) };
415
+ case "binomial":
416
+ return { kind: "binomial", n: i(e.n), p: n(e.p) };
417
+ case "poisson":
418
+ return { kind: "poisson", rate: n(e.rate) };
419
+ case "dice":
420
+ return { kind: "dice", count: i(e.count), sides: i(e.sides) };
421
+ case "mean":
422
+ return { kind: "mean", of: ft(t, e.of), count: i(e.count) };
423
+ }
424
+ }
425
+ const zt = ["normal", "uniform", "exponential", "binomial", "poisson", "dice", "mean"];
426
+ function Mn(t) {
427
+ switch (t.kind) {
428
+ case "binomial":
429
+ return [0, t.n];
430
+ case "dice":
431
+ return [t.count ?? 2, (t.count ?? 2) * (t.sides ?? 6)];
432
+ case "poisson":
433
+ return [0, 1 / 0];
434
+ default:
435
+ return [-1 / 0, 1 / 0];
436
+ }
412
437
  }
413
- function xe(t, e, n, i, r) {
414
- const s = (n - e) / i;
415
- return Array.from({ length: i }, (o, l) => {
416
- const c = e + l * s, f = c + s;
417
- if (r === "trapezoid") return [c, f, t(c), t(f)];
418
- const u = t(r === "left" ? c : r === "right" ? f : (c + f) / 2);
419
- return [c, f, u, u];
438
+ function _t(t) {
439
+ return t.kind === "binomial" || t.kind === "poisson" || t.kind === "dice";
440
+ }
441
+ const qt = /* @__PURE__ */ (() => {
442
+ const t = [0];
443
+ return (e) => {
444
+ for (let n = t.length; n <= e; n++) t[n] = t[n - 1] + Math.log(n);
445
+ return t[e];
446
+ };
447
+ })(), Ut = (t, e) => Math.exp(qt(t) - qt(e) - qt(t - e));
448
+ function st(t, e) {
449
+ switch (t.kind) {
450
+ case "normal": {
451
+ const { mean: n = 0, sd: i = 1 } = t;
452
+ return Math.exp(-(((e - n) / i) ** 2) / 2) / (i * Math.sqrt(2 * Math.PI));
453
+ }
454
+ case "uniform": {
455
+ const { min: n = 0, max: i = 1 } = t;
456
+ return e >= n && e <= i ? 1 / (i - n) : 0;
457
+ }
458
+ case "exponential": {
459
+ const { rate: n = 1 } = t;
460
+ return e < 0 ? 0 : n * Math.exp(-n * e);
461
+ }
462
+ case "binomial":
463
+ return !Number.isInteger(e) || e < 0 || e > t.n ? 0 : Ut(t.n, e) * t.p ** e * (1 - t.p) ** (t.n - e);
464
+ case "poisson":
465
+ return !Number.isInteger(e) || e < 0 ? 0 : Math.exp(e * Math.log(t.rate) - t.rate - qt(e));
466
+ case "dice": {
467
+ const { count: n = 2, sides: i = 6 } = t;
468
+ if (!Number.isInteger(e) || e < n || e > n * i) return 0;
469
+ let s = 0;
470
+ for (let r = 0; r <= Math.floor((e - n) / i); r++)
471
+ s += (r % 2 ? -1 : 1) * Ut(n, r) * Ut(e - i * r - 1, n - 1);
472
+ return s / i ** n;
473
+ }
474
+ case "mean":
475
+ return t.count === 1 ? st(t.of, e) : st({ kind: "normal", mean: At(t.of), sd: Et(t.of) / Math.sqrt(t.count) }, e);
476
+ }
477
+ }
478
+ function At(t) {
479
+ switch (t.kind) {
480
+ case "normal":
481
+ return t.mean ?? 0;
482
+ case "uniform":
483
+ return ((t.min ?? 0) + (t.max ?? 1)) / 2;
484
+ case "exponential":
485
+ return 1 / (t.rate ?? 1);
486
+ case "binomial":
487
+ return t.n * t.p;
488
+ case "poisson":
489
+ return t.rate;
490
+ case "dice":
491
+ return (t.count ?? 2) * ((t.sides ?? 6) + 1) / 2;
492
+ case "mean":
493
+ return At(t.of);
494
+ }
495
+ }
496
+ function Et(t) {
497
+ switch (t.kind) {
498
+ case "normal":
499
+ return t.sd ?? 1;
500
+ case "uniform":
501
+ return ((t.max ?? 1) - (t.min ?? 0)) / Math.sqrt(12);
502
+ case "exponential":
503
+ return 1 / (t.rate ?? 1);
504
+ case "binomial":
505
+ return Math.sqrt(t.n * t.p * (1 - t.p));
506
+ case "poisson":
507
+ return Math.sqrt(t.rate);
508
+ case "dice":
509
+ return Math.sqrt((t.count ?? 2) * ((t.sides ?? 6) ** 2 - 1) / 12);
510
+ case "mean":
511
+ return Et(t.of) / Math.sqrt(t.count);
512
+ }
513
+ }
514
+ function We(t, e) {
515
+ switch (t.kind) {
516
+ case "normal":
517
+ return De(e, t.mean ?? 0, t.sd ?? 1);
518
+ case "uniform":
519
+ return (t.min ?? 0) + e.next() * ((t.max ?? 1) - (t.min ?? 0));
520
+ case "exponential":
521
+ return -Math.log(1 - e.next()) / (t.rate ?? 1);
522
+ case "binomial": {
523
+ let n = 0;
524
+ for (let i = 0; i < t.n; i++) e.next() < t.p && n++;
525
+ return n;
526
+ }
527
+ case "poisson": {
528
+ const n = Math.exp(-t.rate);
529
+ let i = 0, s = e.next();
530
+ for (; s > n; )
531
+ i++, s *= e.next();
532
+ return i;
533
+ }
534
+ case "dice": {
535
+ let n = 0;
536
+ for (let i = 0; i < (t.count ?? 2); i++) n += 1 + Math.floor(e.next() * (t.sides ?? 6));
537
+ return n;
538
+ }
539
+ case "mean": {
540
+ let n = 0;
541
+ for (let i = 0; i < t.count; i++) n += We(t.of, e);
542
+ return n / t.count;
543
+ }
544
+ }
545
+ }
546
+ const Nt = /* @__PURE__ */ new Map();
547
+ function Ue(t, e, n) {
548
+ const i = `${JSON.stringify(t)}|${e}`;
549
+ let s = Nt.get(i);
550
+ if (s || (s = [], Nt.size > 64 && Nt.clear(), Nt.set(i, s)), s.length < n) {
551
+ const r = ce(typeof e == "number" ? e : ue(e)), o = [];
552
+ for (let l = 0; l < n; l++) o.push(We(t, r));
553
+ s.splice(0, s.length, ...o);
554
+ }
555
+ return s.slice(0, n);
556
+ }
557
+ function He(t) {
558
+ if (!t || typeof t != "object" || !zt.includes(t.kind)) return `kind must be one of ${zt.join(", ")}`;
559
+ const e = (n, i) => n !== void 0 && !(n > 0) ? `${i} must be positive` : void 0;
560
+ switch (t.kind) {
561
+ case "normal":
562
+ return e(t.sd, "sd");
563
+ case "uniform":
564
+ return (t.max ?? 1) > (t.min ?? 0) ? void 0 : "max must be greater than min";
565
+ case "exponential":
566
+ return e(t.rate, "rate");
567
+ case "binomial":
568
+ return Number.isInteger(t.n) && t.n >= 0 && t.n <= 1e3 && t.p >= 0 && t.p <= 1 ? void 0 : "n must be a whole number 0..1000 and p in 0..1";
569
+ case "poisson":
570
+ return t.rate > 0 && t.rate <= 200 ? void 0 : "rate must be in (0, 200]";
571
+ case "dice":
572
+ return Number.isInteger(t.count ?? 2) && (t.count ?? 2) >= 1 && (t.count ?? 2) <= 50 && Number.isInteger(t.sides ?? 6) && (t.sides ?? 6) >= 2 ? void 0 : "count must be 1..50 and sides a whole number ≥ 2";
573
+ case "mean":
574
+ return Number.isInteger(t.count) && t.count >= 1 && t.count <= 200 ? He(t.of) : "count must be a whole number 1..200";
575
+ }
576
+ }
577
+ function xe(t) {
578
+ const e = At(t), n = Et(t);
579
+ if (_t(t)) {
580
+ const [i, s] = Mn(t), r = Math.max(i, Math.floor(e - 4 * n)), o = Math.min(s, Math.ceil(e + 4 * n));
581
+ return [r - 0.5, o + 0.5, o - r + 1];
582
+ }
583
+ return [e - 4 * n, e + 4 * n, 30];
584
+ }
585
+ function xn(t, [e, n, i], s) {
586
+ const r = (n - e) / i, o = new Array(i).fill(0);
587
+ for (const c of t) {
588
+ const d = Math.floor((c - e) / r);
589
+ d >= 0 && d < i ? o[d]++ : c === n && o[i - 1]++;
590
+ }
591
+ const l = t.length || 1;
592
+ return o.map((c, d) => ({
593
+ left: e + d * r,
594
+ right: e + (d + 1) * r,
595
+ count: c,
596
+ height: s === "density" ? c / (l * r) : c
597
+ }));
598
+ }
599
+ function Sn(t) {
600
+ if (t.length === 0) return { mean: 0, sd: 0 };
601
+ const e = t.reduce((i, s) => i + s, 0) / t.length, n = t.reduce((i, s) => i + (s - e) ** 2, 0) / t.length;
602
+ return { mean: e, sd: Math.sqrt(n) };
603
+ }
604
+ function Xe(t, e, n) {
605
+ const i = ce(typeof e == "number" ? e : ue(e));
606
+ return Array.from({ length: Math.max(0, Math.floor(n)) }, () => {
607
+ const s = i.next();
608
+ if (t.kind === "uniform") {
609
+ const o = i.next();
610
+ return [t.x[0] + s * (t.x[1] - t.x[0]), t.y[0] + o * (t.y[1] - t.y[0])];
611
+ }
612
+ const r = t.x[0] + s * (t.x[1] - t.x[0]);
613
+ return [r, t.slope * r + t.intercept + t.noise * De(i)];
420
614
  });
421
615
  }
422
- const Me = (t) => Math.min(400, Math.max(1, Math.round(t)));
616
+ function Ye(t) {
617
+ const e = t.length;
618
+ if (e < 2) return;
619
+ const n = t.reduce((c, d) => c + d[0], 0) / e, i = t.reduce((c, d) => c + d[1], 0) / e;
620
+ let s = 0, r = 0, o = 0;
621
+ for (const [c, d] of t)
622
+ s += (c - n) * (d - i), r += (c - n) ** 2, o += (d - i) ** 2;
623
+ if (r === 0) return;
624
+ const l = s / r;
625
+ return { slope: l, intercept: i - l * n, r: o === 0 ? 0 : s / Math.sqrt(r * o) };
626
+ }
627
+ function An(t, e, n) {
628
+ const i = Math.min(1, Math.max(0, t)), s = i * Math.min(1, Math.max(0, e)), r = (1 - i) * Math.min(1, Math.max(0, n)), o = s + r;
629
+ return { truePositive: s, falsePositive: r, positive: o, posterior: o > 0 ? s / o : 0 };
630
+ }
423
631
  function Se(t, e, n) {
424
- const i = {}, r = { ...n };
425
- for (const s of t)
426
- switch (s.kind) {
427
- case "tangent": {
428
- const o = D(s.expr), l = N(e, s.at), c = s.h === void 0 ? 0 : N(e, s.h), f = Math.abs(c) > 1e-9 ? (o(l + c, r) - o(l, r)) / c : Yt(s.expr, 1)(l, r);
429
- Object.assign(i, { [`${s.id}.slope`]: f, [`${s.id}.x`]: l, [`${s.id}.y`]: o(l, r) });
430
- break;
431
- }
432
- case "riemann": {
433
- const o = D(s.expr), l = N(e, s.from), c = N(e, s.to), f = Me(N(e, s.n)), h = xe((d) => o(d, r), l, c, f, s.rule ?? "left").reduce((d, [y, a, p, m]) => d + (p + m) / 2 * (a - y), 0);
434
- Object.assign(i, { [`${s.id}.sum`]: h, [`${s.id}.exact`]: se((d) => o(d, r), l, c), [`${s.id}.n`]: f });
435
- break;
436
- }
437
- case "area": {
438
- const o = D(s.expr), l = s.lower ? D(s.lower) : () => 0;
439
- i[`${s.id}.value`] = se((c) => o(c, r) - l(c, r), N(e, s.from), N(e, s.to));
440
- break;
441
- }
442
- case "point":
443
- if (s.on !== void 0 && s.x !== void 0) {
444
- const o = N(e, s.x);
445
- Object.assign(i, { [`${s.id}.x`]: o, [`${s.id}.y`]: D(s.on)(o, r) });
446
- }
447
- break;
448
- case "taylor":
449
- i[`${s.id}.order`] = Math.min(20, Math.max(0, N(e, s.order))), i[`${s.id}.degree`] = Math.floor(i[`${s.id}.order`]);
450
- break;
451
- }
452
- return i;
632
+ const i = ce(ue(`${t}:${e}`));
633
+ return Array.from({ length: n }, () => i.next() < 0.5);
634
+ }
635
+ const Ht = (t) => t.filter(Boolean).length;
636
+ function En(t, e) {
637
+ const n = t.length, i = Math.min(1, Math.max(0, e)) * n, s = Math.min(n - 1, Math.floor(i)), r = i - s, l = t.slice(0, s).filter(Boolean).length - s / 2, c = l + (t[s] ? 0.5 : -0.5), d = 0.18 * Math.sin(Math.PI * r);
638
+ return { x: l + (c - l) * r, depth: s + r - d };
453
639
  }
454
- const jt = {
640
+ const Tn = '"Latin Modern Math", "STIX Two Math", "Cambria Math", "Times New Roman", "Liberation Serif", "Noto Serif", Times, serif', Ze = 0.25, Mt = 0.05, Ae = {
641
+ a: 0.5,
642
+ b: 0.56,
643
+ c: 0.44,
644
+ d: 0.56,
645
+ e: 0.44,
646
+ f: 0.31,
647
+ g: 0.5,
648
+ h: 0.56,
649
+ i: 0.28,
650
+ j: 0.31,
651
+ k: 0.53,
652
+ l: 0.28,
653
+ m: 0.83,
654
+ n: 0.56,
655
+ o: 0.5,
656
+ p: 0.56,
657
+ q: 0.53,
658
+ r: 0.39,
659
+ s: 0.39,
660
+ t: 0.39,
661
+ u: 0.56,
662
+ v: 0.53,
663
+ w: 0.72,
664
+ x: 0.53,
665
+ y: 0.53,
666
+ z: 0.44,
667
+ A: 0.75,
668
+ B: 0.71,
669
+ C: 0.72,
670
+ D: 0.76,
671
+ E: 0.68,
672
+ F: 0.65,
673
+ G: 0.78,
674
+ H: 0.75,
675
+ I: 0.36,
676
+ J: 0.51,
677
+ K: 0.78,
678
+ L: 0.63,
679
+ M: 0.92,
680
+ N: 0.75,
681
+ O: 0.78,
682
+ P: 0.68,
683
+ Q: 0.78,
684
+ R: 0.74,
685
+ S: 0.56,
686
+ T: 0.72,
687
+ U: 0.75,
688
+ V: 0.75,
689
+ W: 1.03,
690
+ X: 0.75,
691
+ Y: 0.75,
692
+ Z: 0.61
693
+ };
694
+ function te(t) {
695
+ return t.length !== 1 ? t.length * 0.5 : /[0-9]/.test(t) ? 0.5 : Object.prototype.hasOwnProperty.call(Ae, t) ? Ae[t] + 0.04 : "()[]".includes(t) ? 0.39 : "{}".includes(t) ? 0.5 : "|".includes(t) || ",.;:!".includes(t) ? 0.28 : "+−=<>±×÷≤≥≠≈∼≡∝→←↔⇒⇔∈∉⊂⊃⊆⊇∪∩∧∨".includes(t) ? 0.78 : "·∘".includes(t) ? 0.28 : "∑∏".includes(t) ? 1.05 : "∫".includes(t) ? 0.56 : "∞".includes(t) || "…⋯".includes(t) ? 1 : /[Α-Ω]/.test(t) ? 0.72 : /[α-ω]/.test(t) ? 0.56 : 0.6;
696
+ }
697
+ function Ge(t) {
698
+ return "gjpqy(),;[]{}|∫".includes(t) || "βγζημξρφχψ".includes(t) ? { height: 0.72, depth: 0.22 } : "∑∏".includes(t) ? { height: 0.75, depth: 0.25 } : /[a-z]/.test(t) && !"bdfhklt".includes(t) ? { height: 0.45, depth: 0 } : { height: 0.7, depth: 0 };
699
+ }
700
+ const ee = {
455
701
  alpha: "α",
456
702
  beta: "β",
457
703
  gamma: "γ",
@@ -487,7 +733,7 @@ const jt = {
487
733
  Phi: "Φ",
488
734
  Psi: "Ψ",
489
735
  Omega: "Ω"
490
- }, Dt = {
736
+ }, ne = {
491
737
  cdot: ["·", "bin"],
492
738
  times: ["×", "bin"],
493
739
  div: ["÷", "bin"],
@@ -543,7 +789,7 @@ const jt = {
543
789
  rangle: ["⟩", "close"],
544
790
  lbrace: ["{", "open"],
545
791
  rbrace: ["}", "close"]
546
- }, _t = { sum: ["∑", !0], prod: ["∏", !0], int: ["∫", !1], oint: ["∮", !1] }, Rt = {
792
+ }, ie = { sum: ["∑", !0], prod: ["∏", !0], int: ["∫", !1], oint: ["∮", !1] }, re = {
547
793
  sin: !1,
548
794
  cos: !1,
549
795
  tan: !1,
@@ -564,8 +810,8 @@ const jt = {
564
810
  Pr: !1,
565
811
  E: !1,
566
812
  Var: !1
567
- }, Vt = { ",": 3 / 18, ":": 4 / 18, ";": 5 / 18, "!": -3 / 18, quad: 1, qquad: 2 }, oe = /* @__PURE__ */ new Set(["pmatrix", "bmatrix", "vmatrix", "matrix"]);
568
- class Ke extends Error {
813
+ }, se = { ",": 3 / 18, ":": 4 / 18, ";": 5 / 18, "!": -3 / 18, quad: 1, qquad: 2 }, Ee = /* @__PURE__ */ new Set(["pmatrix", "bmatrix", "vmatrix", "matrix"]);
814
+ class On extends Error {
569
815
  source;
570
816
  /** 0-based index into the source */
571
817
  position;
@@ -573,12 +819,12 @@ class Ke extends Error {
573
819
  super(`${e} at ${i + 1} in "${n}"`), this.name = "TexError", this.source = n, this.position = i;
574
820
  }
575
821
  }
576
- const Qe = [
577
- ...Object.keys(jt),
578
- ...Object.keys(Dt),
579
- ...Object.keys(_t),
580
- ...Object.keys(Rt),
581
- ...Object.keys(Vt).filter((t) => t.length > 1),
822
+ const Pn = [
823
+ ...Object.keys(ee),
824
+ ...Object.keys(ne),
825
+ ...Object.keys(ie),
826
+ ...Object.keys(re),
827
+ ...Object.keys(se).filter((t) => t.length > 1),
582
828
  "frac",
583
829
  "sqrt",
584
830
  "vec",
@@ -593,82 +839,82 @@ const Qe = [
593
839
  "left",
594
840
  "right"
595
841
  ].sort();
596
- function Je(t) {
842
+ function Nn(t) {
597
843
  if (typeof t != "string") throw new TypeError("parseTex: expected a string");
598
844
  let e = 0;
599
845
  const n = () => {
600
846
  for (; e < t.length && /\s/.test(t[e]); ) e++;
601
- }, i = (u, h = e) => {
602
- throw new Ke(u, t, h);
603
- }, r = () => {
847
+ }, i = (u, p = e) => {
848
+ throw new On(u, t, p);
849
+ }, s = () => {
604
850
  const u = e;
605
851
  if (/[A-Za-z]/.test(t[e] ?? ""))
606
852
  for (; /[A-Za-z]/.test(t[e] ?? ""); ) e++;
607
853
  else e < t.length ? e++ : i("A backslash with no command");
608
854
  return t.slice(u, e);
609
- }, s = (u) => {
855
+ }, r = (u) => {
610
856
  n(), t[e] !== "{" && i(`Expected "{" for ${u}`);
611
- const h = t.indexOf("}", e);
612
- h < 0 && i(`Missing "}" for ${u}`);
613
- const d = t.slice(e + 1, h);
614
- return e = h + 1, d;
857
+ const p = t.indexOf("}", e);
858
+ p < 0 && i(`Missing "}" for ${u}`);
859
+ const h = t.slice(e + 1, p);
860
+ return e = p + 1, h;
615
861
  }, o = (u) => {
616
862
  if (n(), e >= t.length && i(`Missing ${u}`), t[e] === "{") {
617
863
  e++;
618
- const d = l("}");
619
- return e++, { type: "group", body: d };
864
+ const h = l("}");
865
+ return e++, { type: "group", body: h };
620
866
  }
621
- const h = c();
622
- return h || i(`Missing ${u}`), h;
867
+ const p = c();
868
+ return p || i(`Missing ${u}`), p;
623
869
  }, l = (u) => {
624
- const h = [];
870
+ const p = [];
625
871
  for (; ; ) {
626
872
  if (n(), e >= t.length)
627
- return u === "}" && i('Missing "}"'), u === "cell" && i("Missing \\end"), h;
628
- if (u === "}" && t[e] === "}" || (t[e] === "}" && i('Unexpected "}"'), u === "cell" && (t[e] === "&" || t.startsWith("\\\\", e) || t.startsWith("\\end", e)))) return h;
873
+ return u === "}" && i('Missing "}"'), u === "cell" && i("Missing \\end"), p;
874
+ if (u === "}" && t[e] === "}" || (t[e] === "}" && i('Unexpected "}"'), u === "cell" && (t[e] === "&" || t.startsWith("\\\\", e) || t.startsWith("\\end", e)))) return p;
629
875
  if (t[e] === "^" || t[e] === "_") {
630
- const y = e, a = t[e] === "^";
876
+ const m = e, f = t[e] === "^";
631
877
  e++;
632
- const p = o(a ? "superscript" : "subscript");
633
- let m = h.pop() ?? { type: "group", body: [] };
634
- m.type !== "scripts" && (m = { type: "scripts", base: m }), m.type === "scripts" && ((a && m.sup || !a && m.sub) && i(`Double ${a ? "superscript" : "subscript"}`, y), a ? m.sup = p : m.sub = p), h.push(m);
878
+ const y = o(f ? "superscript" : "subscript");
879
+ let a = p.pop() ?? { type: "group", body: [] };
880
+ a.type !== "scripts" && (a = { type: "scripts", base: a }), a.type === "scripts" && ((f && a.sup || !f && a.sub) && i(`Double ${f ? "superscript" : "subscript"}`, m), f ? a.sup = y : a.sub = y), p.push(a);
635
881
  continue;
636
882
  }
637
883
  if (t[e] === "'") {
638
884
  e++;
639
- const y = { type: "symbol", text: "′", cls: "ord", italic: !1 }, a = h.pop() ?? { type: "group", body: [] };
640
- h.push(a.type === "scripts" && !a.sup ? { ...a, sup: y } : { type: "scripts", base: a, sup: y });
885
+ const m = { type: "symbol", text: "′", cls: "ord", italic: !1 }, f = p.pop() ?? { type: "group", body: [] };
886
+ p.push(f.type === "scripts" && !f.sup ? { ...f, sup: m } : { type: "scripts", base: f, sup: m });
641
887
  continue;
642
888
  }
643
- const d = c();
644
- d && h.push(d);
889
+ const h = c();
890
+ h && p.push(h);
645
891
  }
646
892
  }, c = () => {
647
893
  const u = t[e];
648
894
  if (u === "{") {
649
895
  e++;
650
- const h = l("}");
651
- return e++, { type: "group", body: h };
896
+ const p = l("}");
897
+ return e++, { type: "group", body: p };
652
898
  }
653
899
  if (u === "&" && i('"&" outside a matrix'), u === "\\") {
654
- const h = e;
900
+ const p = e;
655
901
  e++;
656
- const d = r();
657
- if (d === "\\" && i('"\\\\" outside a matrix', h), d in Vt) return { type: "space", width: Vt[d] };
658
- if (d === "{" || d === "}") return { type: "symbol", text: d, cls: d === "{" ? "open" : "close", italic: !1 };
659
- if (d === "|") return { type: "symbol", text: "‖", cls: "ord", italic: !1 };
660
- if (Object.prototype.hasOwnProperty.call(jt, d))
661
- return { type: "symbol", text: jt[d], cls: "ord", italic: d[0] === d[0].toLowerCase() };
662
- if (Object.prototype.hasOwnProperty.call(Dt, d)) {
663
- const [a, p] = Dt[d];
664
- return { type: "symbol", text: a, cls: p, italic: !1 };
902
+ const h = s();
903
+ if (h === "\\" && i('"\\\\" outside a matrix', p), h in se) return { type: "space", width: se[h] };
904
+ if (h === "{" || h === "}") return { type: "symbol", text: h, cls: h === "{" ? "open" : "close", italic: !1 };
905
+ if (h === "|") return { type: "symbol", text: "‖", cls: "ord", italic: !1 };
906
+ if (Object.prototype.hasOwnProperty.call(ee, h))
907
+ return { type: "symbol", text: ee[h], cls: "ord", italic: h[0] === h[0].toLowerCase() };
908
+ if (Object.prototype.hasOwnProperty.call(ne, h)) {
909
+ const [f, y] = ne[h];
910
+ return { type: "symbol", text: f, cls: y, italic: !1 };
665
911
  }
666
- if (Object.prototype.hasOwnProperty.call(_t, d)) {
667
- const [a, p] = _t[d];
668
- return { type: "bigop", text: a, limits: p };
912
+ if (Object.prototype.hasOwnProperty.call(ie, h)) {
913
+ const [f, y] = ie[h];
914
+ return { type: "bigop", text: f, limits: y };
669
915
  }
670
- if (Object.prototype.hasOwnProperty.call(Rt, d)) return { type: "opname", text: d, limits: Rt[d] };
671
- switch (d) {
916
+ if (Object.prototype.hasOwnProperty.call(re, h)) return { type: "opname", text: h, limits: re[h] };
917
+ switch (h) {
672
918
  case "frac":
673
919
  return { type: "frac", num: o("numerator"), den: o("denominator") };
674
920
  case "sqrt":
@@ -676,149 +922,89 @@ function Je(t) {
676
922
  case "vec":
677
923
  case "hat":
678
924
  case "bar":
679
- return { type: "accent", accent: d, body: o(`\\${d}'s body`) };
925
+ return { type: "accent", accent: h, body: o(`\\${h}'s body`) };
680
926
  case "text":
681
- return { type: "text", text: s("\\text") };
927
+ return { type: "text", text: r("\\text") };
682
928
  case "color": {
683
- const a = s("\\color").trim();
684
- return /^(#[0-9a-fA-F]{3,8}|[a-zA-Z]+)$/.test(a) || i(`"${a}" is not a colour name or #hex`, h), { type: "color", color: a, body: o("\\color's body") };
929
+ const f = r("\\color").trim();
930
+ return /^(#[0-9a-fA-F]{3,8}|[a-zA-Z]+)$/.test(f) || i(`"${f}" is not a colour name or #hex`, p), { type: "color", color: f, body: o("\\color's body") };
685
931
  }
686
932
  case "id": {
687
- const a = s("\\id").trim();
688
- return /^[\w.-]+$/.test(a) || i(`"${a}" is not a term id (letters, digits, _ . -)`, h), { type: "id", id: a, body: o("\\id's body") };
933
+ const f = r("\\id").trim();
934
+ return /^[\w.-]+$/.test(f) || i(`"${f}" is not a term id (letters, digits, _ . -)`, p), { type: "id", id: f, body: o("\\id's body") };
689
935
  }
690
936
  case "val": {
691
- const a = s("\\val").trim(), p = /^([A-Za-z_][\w.]*)(?::(\d))?$/.exec(a);
692
- return p || i(`"${a}" is not a value name (name or name:digits)`, h), { type: "value", name: p[1], digits: p[2] === void 0 ? 2 : Number(p[2]) };
937
+ const f = r("\\val").trim(), y = /^([A-Za-z_][\w.]*)(?::(\d))?$/.exec(f);
938
+ return y || i(`"${f}" is not a value name (name or name:digits)`, p), { type: "value", name: y[1], digits: y[2] === void 0 ? 2 : Number(y[2]) };
693
939
  }
694
940
  case "left":
695
941
  case "right": {
696
942
  n();
697
- const a = t[e] === "\\" ? (e++, r()) : t[e++];
698
- if (a === ".") return { type: "space", width: 0 };
699
- const m = { "(": "(", ")": ")", "[": "[", "]": "]", "|": "|", "{": "{", "}": "}", langle: "⟨", rangle: "⟩", "|.": "‖" }[a];
700
- return m || i(`"${a}" is not a delimiter`, h), { type: "symbol", text: m, cls: d === "left" ? "open" : "close", italic: !1 };
943
+ const f = t[e] === "\\" ? (e++, s()) : t[e++];
944
+ if (f === ".") return { type: "space", width: 0 };
945
+ const a = { "(": "(", ")": ")", "[": "[", "]": "]", "|": "|", "{": "{", "}": "}", langle: "⟨", rangle: "⟩", "|.": "‖" }[f];
946
+ return a || i(`"${f}" is not a delimiter`, p), { type: "symbol", text: a, cls: h === "left" ? "open" : "close", italic: !1 };
701
947
  }
702
948
  case "begin": {
703
- const a = s("\\begin").trim();
704
- oe.has(a) || i(`Unknown environment "${a}" (use ${[...oe].join(", ")})`, h);
705
- const p = [[]];
949
+ const f = r("\\begin").trim();
950
+ Ee.has(f) || i(`Unknown environment "${f}" (use ${[...Ee].join(", ")})`, p);
951
+ const y = [[]];
706
952
  for (; ; ) {
707
- const m = l("cell");
708
- if (p[p.length - 1].push({ type: "group", body: m }), t[e] === "&")
953
+ const a = l("cell");
954
+ if (y[y.length - 1].push({ type: "group", body: a }), t[e] === "&")
709
955
  e++;
710
956
  else if (t.startsWith("\\\\", e))
711
- e += 2, p.push([]);
957
+ e += 2, y.push([]);
712
958
  else {
713
959
  e += 4;
714
- const b = s("\\end").trim();
715
- b !== a && i(`\\begin{${a}} ended by \\end{${b}}`);
960
+ const g = r("\\end").trim();
961
+ g !== f && i(`\\begin{${f}} ended by \\end{${g}}`);
716
962
  break;
717
963
  }
718
964
  }
719
- return p.length > 1 && p[p.length - 1].every((m) => m.type === "group" && m.body.length === 0) && p.pop(), { type: "matrix", delimiters: a, rows: p };
965
+ return y.length > 1 && y[y.length - 1].every((a) => a.type === "group" && a.body.length === 0) && y.pop(), { type: "matrix", delimiters: f, rows: y };
720
966
  }
721
967
  case "end":
722
- return i("\\end without \\begin", h);
968
+ return i("\\end without \\begin", p);
723
969
  }
724
- const y = je(d, Qe);
725
- return i(`Unknown command "\\${d}"${y ? ` (did you mean "\\${y}"?)` : ""}`, h);
970
+ const m = dn(h, Pn);
971
+ return i(`Unknown command "\\${h}"${m ? ` (did you mean "\\${m}"?)` : ""}`, p);
726
972
  }
727
973
  return e++, /[A-Za-z]/.test(u) ? { type: "symbol", text: u, cls: "ord", italic: !0 } : /[0-9.]/.test(u) ? { type: "symbol", text: u, cls: "ord", italic: !1 } : u === "+" ? { type: "symbol", text: "+", cls: "bin", italic: !1 } : u === "-" ? { type: "symbol", text: "−", cls: "bin", italic: !1 } : u === "*" ? { type: "symbol", text: "∗", cls: "bin", italic: !1 } : "=<>".includes(u) ? { type: "symbol", text: u, cls: "rel", italic: !1 } : "([".includes(u) ? { type: "symbol", text: u, cls: "open", italic: !1 } : ")]".includes(u) ? { type: "symbol", text: u, cls: "close", italic: !1 } : ",;".includes(u) ? { type: "symbol", text: u, cls: "punct", italic: !1 } : "|/!:".includes(u) ? { type: "symbol", text: u, cls: u === ":" ? "rel" : "ord", italic: !1 } : i(`Unexpected "${u}"`, e - 1);
728
974
  };
729
975
  return { type: "group", body: l("") };
730
976
  }
731
- const tn = '"Latin Modern Math", "STIX Two Math", "Cambria Math", "Times New Roman", "Liberation Serif", "Noto Serif", Times, serif', Ee = 0.25, mt = 0.05, ae = {
732
- a: 0.5,
733
- b: 0.56,
734
- c: 0.44,
735
- d: 0.56,
736
- e: 0.44,
737
- f: 0.31,
738
- g: 0.5,
739
- h: 0.56,
740
- i: 0.28,
741
- j: 0.31,
742
- k: 0.53,
743
- l: 0.28,
744
- m: 0.83,
745
- n: 0.56,
746
- o: 0.5,
747
- p: 0.56,
748
- q: 0.53,
749
- r: 0.39,
750
- s: 0.39,
751
- t: 0.39,
752
- u: 0.56,
753
- v: 0.53,
754
- w: 0.72,
755
- x: 0.53,
756
- y: 0.53,
757
- z: 0.44,
758
- A: 0.75,
759
- B: 0.71,
760
- C: 0.72,
761
- D: 0.76,
762
- E: 0.68,
763
- F: 0.65,
764
- G: 0.78,
765
- H: 0.75,
766
- I: 0.36,
767
- J: 0.51,
768
- K: 0.78,
769
- L: 0.63,
770
- M: 0.92,
771
- N: 0.75,
772
- O: 0.78,
773
- P: 0.68,
774
- Q: 0.78,
775
- R: 0.74,
776
- S: 0.56,
777
- T: 0.72,
778
- U: 0.75,
779
- V: 0.75,
780
- W: 1.03,
781
- X: 0.75,
782
- Y: 0.75,
783
- Z: 0.61
784
- };
785
- function Wt(t) {
786
- return t.length !== 1 ? t.length * 0.5 : /[0-9]/.test(t) ? 0.5 : Object.prototype.hasOwnProperty.call(ae, t) ? ae[t] + 0.04 : "()[]".includes(t) ? 0.39 : "{}".includes(t) ? 0.5 : "|".includes(t) || ",.;:!".includes(t) ? 0.28 : "+−=<>±×÷≤≥≠≈∼≡∝→←↔⇒⇔∈∉⊂⊃⊆⊇∪∩∧∨".includes(t) ? 0.78 : "·∘".includes(t) ? 0.28 : "∑∏".includes(t) ? 1.05 : "∫".includes(t) ? 0.56 : "∞".includes(t) || "…⋯".includes(t) ? 1 : /[Α-Ω]/.test(t) ? 0.72 : /[α-ω]/.test(t) ? 0.56 : 0.6;
787
- }
788
- function Ae(t) {
789
- return "gjpqy(),;[]{}|∫".includes(t) || "βγζημξρφχψ".includes(t) ? { height: 0.72, depth: 0.22 } : "∑∏".includes(t) ? { height: 0.75, depth: 0.25 } : /[a-z]/.test(t) && !"bdfhklt".includes(t) ? { height: 0.45, depth: 0 } : { height: 0.7, depth: 0 };
790
- }
791
- const Y = [1, 1, 0.7, 0.5], en = (t) => t <= 1 ? 2 : 3, nn = (t) => Math.min(3, t + 1), Zt = () => ({ width: 0, height: 0, depth: 0, pieces: [] });
792
- function X(t, e, n) {
793
- return t.pieces.map((i) => i.kind === "stroke" ? { ...i, points: i.points.map(([r, s]) => [r + e, s + n]) } : { ...i, x: i.x + e, y: i.y + n });
977
+ const Z = [1, 1, 0.7, 0.5], In = (t) => t <= 1 ? 2 : 3, Ln = (t) => Math.min(3, t + 1), pe = () => ({ width: 0, height: 0, depth: 0, pieces: [] });
978
+ function Y(t, e, n) {
979
+ return t.pieces.map((i) => i.kind === "stroke" ? { ...i, points: i.points.map(([s, r]) => [s + e, r + n]) } : { ...i, x: i.x + e, y: i.y + n });
794
980
  }
795
- function ct(t, e) {
981
+ function mt(t, e) {
796
982
  if (t.id) return t.id;
797
983
  const n = (t.counts.get(e) ?? 0) + 1;
798
984
  return t.counts.set(e, n), `${e}#${n}`;
799
985
  }
800
- function le(t, e, n, i = 1, r = t) {
801
- const s = Y[n.level] * i, o = Wt(t) * s, { height: l, depth: c } = Ae(t);
986
+ function Te(t, e, n, i = 1, s = t) {
987
+ const r = Z[n.level] * i, o = te(t) * r, { height: l, depth: c } = Ge(t);
802
988
  return {
803
989
  width: o,
804
- height: l * s,
805
- depth: c * s,
806
- pieces: [{ kind: "glyph", text: t, x: 0, y: 0, width: o, size: s, italic: e, ...n.color ? { color: n.color } : {}, id: ct(n, r) }]
990
+ height: l * r,
991
+ depth: c * r,
992
+ pieces: [{ kind: "glyph", text: t, x: 0, y: 0, width: o, size: r, italic: e, ...n.color ? { color: n.color } : {}, id: mt(n, s) }]
807
993
  };
808
994
  }
809
- function Ft(t, e, n) {
810
- const i = Zt(), r = ct(e, n), s = Y[e.level];
995
+ function Xt(t, e, n) {
996
+ const i = pe(), s = mt(e, n), r = Z[e.level];
811
997
  for (const o of t) {
812
- const l = (o === " " ? 0.28 : /[A-Za-z]/.test(o) ? Wt(o) - 0.04 : Wt(o)) * s;
998
+ const l = (o === " " ? 0.28 : /[A-Za-z]/.test(o) ? te(o) - 0.04 : te(o)) * r;
813
999
  if (o !== " ") {
814
- const { height: c, depth: f } = Ae(o);
815
- i.pieces.push({ kind: "glyph", text: o, x: i.width, y: 0, width: l, size: s, italic: !1, ...e.color ? { color: e.color } : {}, id: r }), i.height = Math.max(i.height, c * s), i.depth = Math.max(i.depth, f * s);
1000
+ const { height: c, depth: d } = Ge(o);
1001
+ i.pieces.push({ kind: "glyph", text: o, x: i.width, y: 0, width: l, size: r, italic: !1, ...e.color ? { color: e.color } : {}, id: s }), i.height = Math.max(i.height, c * r), i.depth = Math.max(i.depth, d * r);
816
1002
  }
817
1003
  i.width += l;
818
1004
  }
819
1005
  return i;
820
1006
  }
821
- function Bt(t) {
1007
+ function oe(t) {
822
1008
  switch (t.type) {
823
1009
  case "symbol":
824
1010
  return t.cls;
@@ -826,212 +1012,503 @@ function Bt(t) {
826
1012
  case "opname":
827
1013
  return "op";
828
1014
  case "scripts":
829
- return Bt(t.base);
1015
+ return oe(t.base);
830
1016
  case "id":
831
1017
  case "color":
832
- return Bt(t.body);
1018
+ return oe(t.body);
833
1019
  default:
834
1020
  return "ord";
835
1021
  }
836
1022
  }
837
- function rn(t, e) {
1023
+ function Fn(t, e) {
838
1024
  return t === "bin" || e === "bin" ? 4 : t === "rel" || e === "rel" ? t === "open" || e === "close" || e === "punct" ? 0 : 5 : t === "punct" || t === "op" && (e === "ord" || e === "op") || e === "op" && t === "ord" ? 3 : 0;
839
1025
  }
840
- function sn(t, e) {
841
- const n = Zt();
1026
+ function qn(t, e) {
1027
+ const n = pe();
842
1028
  let i;
843
- return t.forEach((r) => {
844
- if (r.type === "space") {
845
- n.width += r.width * Y[e.level];
1029
+ return t.forEach((s) => {
1030
+ if (s.type === "space") {
1031
+ n.width += s.width * Z[e.level];
846
1032
  return;
847
1033
  }
848
- let s = Bt(r);
849
- s === "bin" && (i === void 0 || i === "bin" || i === "rel" || i === "open" || i === "punct" || i === "op") && (s = "ord"), i !== void 0 && e.level <= 1 && (n.width += rn(i, s) / 18 * Y[e.level]);
850
- const o = R(r, e);
851
- n.pieces.push(...X(o, n.width, 0)), n.width += o.width, n.height = Math.max(n.height, o.height), n.depth = Math.max(n.depth, o.depth), i = s;
1034
+ let r = oe(s);
1035
+ r === "bin" && (i === void 0 || i === "bin" || i === "rel" || i === "open" || i === "punct" || i === "op") && (r = "ord"), i !== void 0 && e.level <= 1 && (n.width += Fn(i, r) / 18 * Z[e.level]);
1036
+ const o = V(s, e);
1037
+ n.pieces.push(...Y(o, n.width, 0)), n.width += o.width, n.height = Math.max(n.height, o.height), n.depth = Math.max(n.depth, o.depth), i = r;
852
1038
  }), n;
853
1039
  }
854
- function on(t, e) {
1040
+ function Cn(t, e) {
855
1041
  if (!Number.isFinite(t)) return t > 0 ? "∞" : t < 0 ? "−∞" : "?";
856
1042
  const n = t.toFixed(e), i = n.includes(".") ? n.replace(/\.?0+$/, "") : n;
857
1043
  return (i === "-0" ? "0" : i).replace("-", "−");
858
1044
  }
859
- function R(t, e) {
860
- const n = Y[e.level];
1045
+ function V(t, e) {
1046
+ const n = Z[e.level];
861
1047
  switch (t.type) {
862
1048
  case "symbol":
863
- return le(t.text, t.italic, e);
1049
+ return Te(t.text, t.italic, e);
864
1050
  case "group":
865
- return sn(t.body, e);
1051
+ return qn(t.body, e);
866
1052
  case "space":
867
- return { ...Zt(), width: t.width * n };
1053
+ return { ...pe(), width: t.width * n };
868
1054
  case "text":
869
- return Ft(t.text, e, `text:${t.text}`);
1055
+ return Xt(t.text, e, `text:${t.text}`);
870
1056
  case "opname":
871
- return Ft(t.text, e, t.text);
1057
+ return Xt(t.text, e, t.text);
872
1058
  case "value": {
873
1059
  const i = e.values[t.name];
874
1060
  if (i === void 0) throw new Error(`\\val{${t.name}}: no value named "${t.name}"`);
875
- return Ft(on(i, t.digits), { ...e, id: e.id ?? `val:${t.name}` }, `val:${t.name}`);
1061
+ return Xt(Cn(i, t.digits), { ...e, id: e.id ?? `val:${t.name}` }, `val:${t.name}`);
876
1062
  }
877
1063
  case "bigop":
878
- return le(t.text, !1, e, e.level === 0 ? 1.4 : 1.1);
1064
+ return Te(t.text, !1, e, e.level === 0 ? 1.4 : 1.1);
879
1065
  case "color":
880
- return R(t.body, { ...e, color: t.color });
1066
+ return V(t.body, { ...e, color: t.color });
881
1067
  case "id":
882
- return R(t.body, { ...e, id: t.id });
1068
+ return V(t.body, { ...e, id: t.id });
883
1069
  case "scripts":
884
- return an(t, e);
1070
+ return zn(t, e);
885
1071
  case "frac":
886
- return ln(t, e);
1072
+ return jn(t, e);
887
1073
  case "sqrt":
888
- return cn(t, e);
1074
+ return Dn(t, e);
889
1075
  case "accent":
890
- return un(t, e);
1076
+ return Rn(t, e);
891
1077
  case "matrix":
892
- return dn(t, e);
1078
+ return _n(t, e);
893
1079
  }
894
1080
  }
895
- function an(t, e) {
896
- const n = R(t.base, e), i = { ...e, level: en(e.level) }, r = t.sup ? R(t.sup, i) : void 0, s = t.sub ? R(t.sub, i) : void 0, o = Y[e.level], l = e.level === 0 && (t.base.type === "bigop" && t.base.limits || t.base.type === "opname" && t.base.limits), c = { ...n, pieces: [...n.pieces] };
1081
+ function zn(t, e) {
1082
+ const n = V(t.base, e), i = { ...e, level: In(e.level) }, s = t.sup ? V(t.sup, i) : void 0, r = t.sub ? V(t.sub, i) : void 0, o = Z[e.level], l = e.level === 0 && (t.base.type === "bigop" && t.base.limits || t.base.type === "opname" && t.base.limits), c = { ...n, pieces: [...n.pieces] };
897
1083
  if (l) {
898
- const y = Math.max(n.width, r?.width ?? 0, s?.width ?? 0), a = X(n, (y - n.width) / 2, 0);
899
- let p = n.height, m = n.depth;
900
- const b = 0.12 * o;
901
- if (r) {
902
- const w = -(n.height + b + r.depth);
903
- a.push(...X(r, (y - r.width) / 2, w)), p = -w + r.height;
904
- }
1084
+ const m = Math.max(n.width, s?.width ?? 0, r?.width ?? 0), f = Y(n, (m - n.width) / 2, 0);
1085
+ let y = n.height, a = n.depth;
1086
+ const g = 0.12 * o;
905
1087
  if (s) {
906
- const w = n.depth + b + s.height;
907
- a.push(...X(s, (y - s.width) / 2, w)), m = w + s.depth;
1088
+ const w = -(n.height + g + s.depth);
1089
+ f.push(...Y(s, (m - s.width) / 2, w)), y = -w + s.height;
1090
+ }
1091
+ if (r) {
1092
+ const w = n.depth + g + r.height;
1093
+ f.push(...Y(r, (m - r.width) / 2, w)), a = w + r.depth;
908
1094
  }
909
- return { width: y, height: p, depth: m, pieces: a };
1095
+ return { width: m, height: y, depth: a, pieces: f };
910
1096
  }
911
- let f = r ? Math.max(0.42 * o, n.height - 0.3 * o, r.depth + 0.25 * o) : 0, u = s ? Math.max(0.2 * o, n.depth + 0.12 * o, s.height - 0.4 * o) : 0;
912
- if (r && s) {
913
- const y = f - r.depth - (s.height - u);
914
- y < 0.2 * o && (u += 0.2 * o - y);
1097
+ let d = s ? Math.max(0.42 * o, n.height - 0.3 * o, s.depth + 0.25 * o) : 0, u = r ? Math.max(0.2 * o, n.depth + 0.12 * o, r.height - 0.4 * o) : 0;
1098
+ if (s && r) {
1099
+ const m = d - s.depth - (r.height - u);
1100
+ m < 0.2 * o && (u += 0.2 * o - m);
915
1101
  }
916
- const h = n.width + 0.03 * o;
917
- let d = n.width;
918
- return r ? (c.pieces.push(...X(r, h, -f)), c.height = Math.max(c.height, f + r.height), d = Math.max(d, h + r.width)) : f = 0, s && (c.pieces.push(...X(s, h, u)), c.depth = Math.max(c.depth, u + s.depth), d = Math.max(d, h + s.width)), c.width = d + 0.04 * o, c;
1102
+ const p = n.width + 0.03 * o;
1103
+ let h = n.width;
1104
+ return s ? (c.pieces.push(...Y(s, p, -d)), c.height = Math.max(c.height, d + s.height), h = Math.max(h, p + s.width)) : d = 0, r && (c.pieces.push(...Y(r, p, u)), c.depth = Math.max(c.depth, u + r.depth), h = Math.max(h, p + r.width)), c.width = h + 0.04 * o, c;
919
1105
  }
920
- function ln(t, e) {
921
- const n = { ...e, level: nn(e.level) }, i = R(t.num, n), r = R(t.den, n), s = Y[e.level], o = mt * s, l = Ee * s, c = (e.level === 0 ? 0.16 : 0.1) * s, f = 0.1 * s, u = Math.max(i.width, r.width) + f * 2, h = -(l + o / 2 + c + i.depth), d = -l + o / 2 + c + r.height;
1106
+ function jn(t, e) {
1107
+ const n = { ...e, level: Ln(e.level) }, i = V(t.num, n), s = V(t.den, n), r = Z[e.level], o = Mt * r, l = Ze * r, c = (e.level === 0 ? 0.16 : 0.1) * r, d = 0.1 * r, u = Math.max(i.width, s.width) + d * 2, p = -(l + o / 2 + c + i.depth), h = -l + o / 2 + c + s.height;
922
1108
  return {
923
1109
  width: u,
924
- height: -h + i.height,
925
- depth: d + r.depth,
1110
+ height: -p + i.height,
1111
+ depth: h + s.depth,
926
1112
  pieces: [
927
- ...X(i, (u - i.width) / 2, h),
928
- { kind: "rule", x: 0, y: -l - o / 2, width: u, height: o, ...e.color ? { color: e.color } : {}, id: ct(e, "frac") },
929
- ...X(r, (u - r.width) / 2, d)
1113
+ ...Y(i, (u - i.width) / 2, p),
1114
+ { kind: "rule", x: 0, y: -l - o / 2, width: u, height: o, ...e.color ? { color: e.color } : {}, id: mt(e, "frac") },
1115
+ ...Y(s, (u - s.width) / 2, h)
930
1116
  ]
931
1117
  };
932
1118
  }
933
- function cn(t, e) {
934
- const n = R(t.body, e), i = Y[e.level], r = Math.max(n.height, 0.7 * i) + 0.14 * i, s = Math.max(n.depth, 0.05 * i) + 0.05 * i, o = 0.56 * i, l = o + n.width + 0.08 * i, c = [
1119
+ function Dn(t, e) {
1120
+ const n = V(t.body, e), i = Z[e.level], s = Math.max(n.height, 0.7 * i) + 0.14 * i, r = Math.max(n.depth, 0.05 * i) + 0.05 * i, o = 0.56 * i, l = o + n.width + 0.08 * i, c = [
935
1121
  [0.02 * i, -0.36 * i],
936
1122
  [0.13 * i, -0.44 * i],
937
- [0.3 * i, s],
938
- [o - 0.04 * i, -r],
939
- [l, -r]
1123
+ [0.3 * i, r],
1124
+ [o - 0.04 * i, -s],
1125
+ [l, -s]
940
1126
  ];
941
1127
  return {
942
1128
  width: l,
943
- height: r + mt * i,
944
- depth: s,
945
- pieces: [{ kind: "stroke", points: c, width: mt * i, ...e.color ? { color: e.color } : {}, id: ct(e, "sqrt") }, ...X(n, o, 0)]
1129
+ height: s + Mt * i,
1130
+ depth: r,
1131
+ pieces: [{ kind: "stroke", points: c, width: Mt * i, ...e.color ? { color: e.color } : {}, id: mt(e, "sqrt") }, ...Y(n, o, 0)]
946
1132
  };
947
1133
  }
948
- function un(t, e) {
949
- const n = R(t.body, e), i = Y[e.level], r = -(n.height + 0.12 * i), s = 0.04 * i, o = Math.max(n.width - 0.02 * i, s + 0.3 * i), l = e.color ? { color: e.color } : {}, c = ct(e, t.accent);
950
- let f;
1134
+ function Rn(t, e) {
1135
+ const n = V(t.body, e), i = Z[e.level], s = -(n.height + 0.12 * i), r = 0.04 * i, o = Math.max(n.width - 0.02 * i, r + 0.3 * i), l = e.color ? { color: e.color } : {}, c = mt(e, t.accent);
1136
+ let d;
951
1137
  if (t.accent === "vec") {
952
1138
  const u = 0.12 * i;
953
- f = [[[s, r], [o, r]], [[o - u, r - u * 0.7], [o, r], [o - u, r + u * 0.7]]];
1139
+ d = [[[r, s], [o, s]], [[o - u, s - u * 0.7], [o, s], [o - u, s + u * 0.7]]];
954
1140
  } else if (t.accent === "hat") {
955
- const u = (s + o) / 2;
956
- f = [[[u - 0.16 * i, r + 0.02 * i], [u, r - 0.12 * i], [u + 0.16 * i, r + 0.02 * i]]];
1141
+ const u = (r + o) / 2;
1142
+ d = [[[u - 0.16 * i, s + 0.02 * i], [u, s - 0.12 * i], [u + 0.16 * i, s + 0.02 * i]]];
957
1143
  } else
958
- f = [[[s, r], [o, r]]];
1144
+ d = [[[r, s], [o, s]]];
959
1145
  return {
960
1146
  width: Math.max(n.width, o + 0.02 * i),
961
- height: -r + 0.14 * i,
1147
+ height: -s + 0.14 * i,
962
1148
  depth: n.depth,
963
- pieces: [...n.pieces, ...f.map((u) => ({ kind: "stroke", points: u, width: mt * i * 0.9, ...l, id: c }))]
1149
+ pieces: [...n.pieces, ...d.map((u) => ({ kind: "stroke", points: u, width: Mt * i * 0.9, ...l, id: c }))]
964
1150
  };
965
1151
  }
966
- function dn(t, e) {
967
- const n = { ...e, level: Math.max(e.level, 1) }, i = Y[n.level], r = t.rows.map((v) => v.map((x) => R(x, n))), s = Math.max(...r.map((v) => v.length)), o = Array.from({ length: s }, (v, x) => Math.max(0, ...r.map((M) => M[x]?.width ?? 0))), l = r.map((v) => Math.max(0.7 * i, ...v.map((x) => x.height))), c = r.map((v) => Math.max(0.2 * i, ...v.map((x) => x.depth))), f = 0.9 * i, u = 0.25 * i, h = t.delimiters === "matrix" ? 0 : 0.55 * i, d = o.reduce((v, x) => v + x, 0) + f * (s - 1), y = l.reduce((v, x, M) => v + x + c[M], 0) + u * (r.length - 1), a = -Ee * i - y / 2, p = [];
968
- let m = a;
969
- r.forEach((v, x) => {
970
- m += l[x];
971
- let M = h;
972
- v.forEach((T, P) => {
973
- p.push(...X(T, M + (o[P] - T.width) / 2, m)), M += o[P] + f;
974
- }), m += c[x] + u;
1152
+ function _n(t, e) {
1153
+ const n = { ...e, level: Math.max(e.level, 1) }, i = Z[n.level], s = t.rows.map((k) => k.map(($) => V($, n))), r = Math.max(...s.map((k) => k.length)), o = Array.from({ length: r }, (k, $) => Math.max(0, ...s.map((x) => x[$]?.width ?? 0))), l = s.map((k) => Math.max(0.7 * i, ...k.map(($) => $.height))), c = s.map((k) => Math.max(0.2 * i, ...k.map(($) => $.depth))), d = 0.9 * i, u = 0.25 * i, p = t.delimiters === "matrix" ? 0 : 0.55 * i, h = o.reduce((k, $) => k + $, 0) + d * (r - 1), m = l.reduce((k, $, x) => k + $ + c[x], 0) + u * (s.length - 1), f = -Ze * i - m / 2, y = [];
1154
+ let a = f;
1155
+ s.forEach((k, $) => {
1156
+ a += l[$];
1157
+ let x = p;
1158
+ k.forEach((T, N) => {
1159
+ y.push(...Y(T, x + (o[N] - T.width) / 2, a)), x += o[N] + d;
1160
+ }), a += c[$] + u;
975
1161
  });
976
- const b = d + h * 2, w = a + y, $ = e.color ? { color: e.color } : {}, g = (v, x) => ({ kind: "stroke", points: v, width: mt * i * 1.1, ...$, id: ct(e, x) }), k = 0.08 * i;
1162
+ const g = h + p * 2, w = f + m, M = e.color ? { color: e.color } : {}, v = (k, $) => ({ kind: "stroke", points: k, width: Mt * i * 1.1, ...M, id: mt(e, $) }), b = 0.08 * i;
977
1163
  if (t.delimiters === "pmatrix") {
978
- const v = (x) => {
979
- const M = x === 1 ? h * 0.75 : b - h * 0.75, T = x * h * 0.5;
980
- return Array.from({ length: 17 }, (P, K) => {
981
- const j = K / 16;
982
- return [M - T * Math.sin(Math.PI * j), a - k + (y + k * 2) * j];
1164
+ const k = ($) => {
1165
+ const x = $ === 1 ? p * 0.75 : g - p * 0.75, T = $ * p * 0.5;
1166
+ return Array.from({ length: 17 }, (N, q) => {
1167
+ const F = q / 16;
1168
+ return [x - T * Math.sin(Math.PI * F), f - b + (m + b * 2) * F];
983
1169
  });
984
1170
  };
985
- p.push(g(v(1), "("), g(v(-1), ")"));
1171
+ y.push(v(k(1), "("), v(k(-1), ")"));
986
1172
  } else if (t.delimiters === "bmatrix") {
987
- const v = h * 0.35, x = h * 0.2, M = b - h * 0.2;
988
- p.push(
989
- g([[x + v, a - k], [x, a - k], [x, w + k], [x + v, w + k]], "["),
990
- g([[M - v, a - k], [M, a - k], [M, w + k], [M - v, w + k]], "]")
1173
+ const k = p * 0.35, $ = p * 0.2, x = g - p * 0.2;
1174
+ y.push(
1175
+ v([[$ + k, f - b], [$, f - b], [$, w + b], [$ + k, w + b]], "["),
1176
+ v([[x - k, f - b], [x, f - b], [x, w + b], [x - k, w + b]], "]")
991
1177
  );
992
- } else t.delimiters === "vmatrix" && p.push(g([[h * 0.4, a - k], [h * 0.4, w + k]], "|"), g([[b - h * 0.4, a - k], [b - h * 0.4, w + k]], "|"));
993
- return { width: b, height: -a + k, depth: w + k, pieces: p };
1178
+ } else t.delimiters === "vmatrix" && y.push(v([[p * 0.4, f - b], [p * 0.4, w + b]], "|"), v([[g - p * 0.4, f - b], [g - p * 0.4, w + b]], "|"));
1179
+ return { width: g, height: -f + b, depth: w + b, pieces: y };
994
1180
  }
995
1181
  function ut(t, e = {}) {
996
- const n = typeof t == "string" ? Je(t) : t, i = { level: e.style === "inline" ? 1 : 0, values: e.values ?? {}, counts: /* @__PURE__ */ new Map() }, r = R(n, i);
997
- return { width: r.width, height: r.height, depth: r.depth, pieces: r.pieces };
1182
+ const n = typeof t == "string" ? Nn(t) : t, i = { level: e.style === "inline" ? 1 : 0, values: e.values ?? {}, counts: /* @__PURE__ */ new Map() }, s = V(n, i);
1183
+ return { width: s.width, height: s.height, depth: s.depth, pieces: s.pieces };
998
1184
  }
999
- const V = (t, e, n) => t + (e - t) * n;
1000
- function ce(t, e, n) {
1001
- return t.kind === "stroke" ? { ...t, points: t.points.map(([i, r]) => [i + e, r + n]) } : { ...t, x: t.x + e, y: t.y + n };
1185
+ const Oe = 'system-ui, -apple-system, "Segoe UI", sans-serif', Pe = (t, e) => Math.hypot(e[0] - t[0], e[1] - t[1]);
1186
+ function G(t, e) {
1187
+ if (e >= 1) return t;
1188
+ if (e <= 0) return [];
1189
+ const n = t.map((r) => r.slice(1).reduce((o, l, c) => o + Pe(r[c], l), 0));
1190
+ let i = n.reduce((r, o) => r + o, 0) * e;
1191
+ const s = [];
1192
+ for (const [r, o] of t.entries()) {
1193
+ if (i <= 0) break;
1194
+ if (n[r] <= i) {
1195
+ s.push(o), i -= n[r];
1196
+ continue;
1197
+ }
1198
+ const l = [o[0]];
1199
+ for (let c = 1; c < o.length; c++) {
1200
+ const d = Pe(o[c - 1], o[c]);
1201
+ if (d >= i) {
1202
+ const u = d === 0 ? 0 : i / d;
1203
+ l.push([o[c - 1][0] + (o[c][0] - o[c - 1][0]) * u, o[c - 1][1] + (o[c][1] - o[c - 1][1]) * u]);
1204
+ break;
1205
+ }
1206
+ l.push(o[c]), i -= d;
1207
+ }
1208
+ s.push(l), i = 0;
1209
+ }
1210
+ return s;
1211
+ }
1212
+ function fe(t, e) {
1213
+ const n = e.align ?? "center", i = n === "left" ? 0 : n === "right" ? -t.width : -t.width / 2, s = e.baseline === "baseline" ? 0 : (t.height - t.depth) / 2;
1214
+ return [e.x + i * e.size, e.y + s * e.size];
1215
+ }
1216
+ function Ke(t, e, n) {
1217
+ const [i, s] = e, r = n.size, o = n.opacity ?? 1;
1218
+ return t.map((l) => {
1219
+ const c = l.color ?? n.color, d = o * (l.opacity ?? 1), u = `${n.idPrefix}${l.id}`;
1220
+ if (l.kind === "glyph")
1221
+ return {
1222
+ type: "text",
1223
+ id: u,
1224
+ text: l.text,
1225
+ x: i + (l.x + l.width / 2) * r,
1226
+ y: s + l.y * r,
1227
+ size: l.size * r,
1228
+ font: Tn,
1229
+ italic: l.italic,
1230
+ color: c,
1231
+ align: "center",
1232
+ opacity: d
1233
+ };
1234
+ if (l.kind === "rule") {
1235
+ const p = i + l.x * r, h = s + l.y * r, m = l.width * r, f = Math.max(1, l.height * r);
1236
+ return { type: "line", id: u, points: [[p, h], [p + m, h], [p + m, h + f], [p, h + f]], closed: !0, fill: c, opacity: d };
1237
+ }
1238
+ return { type: "line", id: u, points: l.points.map(([p, h]) => [i + p * r, s + h * r]), stroke: c, width: Math.max(1, l.width * r), opacity: d };
1239
+ });
1240
+ }
1241
+ function yt(t, e) {
1242
+ return Ke(t.pieces, fe(t, e), e);
1243
+ }
1244
+ const jt = 480;
1245
+ function Je(t, e) {
1246
+ const n = [];
1247
+ let i = [];
1248
+ return t.forEach((s, r) => {
1249
+ const o = t[r - 1];
1250
+ (!s || o && Math.abs(s[1] - o[1]) > e * 1.5) && (i.length >= 2 && n.push(i), i = []), s && i.push(s);
1251
+ }), i.length >= 2 && n.push(i), n;
1252
+ }
1253
+ function Qe(t, e) {
1254
+ const n = Math.max(e.plane.width, e.plane.height) * 20;
1255
+ if (!(!Number.isFinite(t[0]) || !Number.isFinite(t[1])))
1256
+ return [Math.max(-n, Math.min(n, t[0])), Math.max(-n, Math.min(n, t[1]))];
1257
+ }
1258
+ function tn(t, e, n, i, s, r) {
1259
+ return G(e, s.draw).map((o, l) => ({ type: "line", id: `${t}.${l}`, points: o, stroke: n, width: i, opacity: s.opacity, ...r ? { dash: r } : {} }));
1260
+ }
1261
+ function Vt(t, e, n, i, s, r, o, l) {
1262
+ const c = Array.from({ length: jt + 1 }, (d, u) => {
1263
+ const p = n + (i - n) * u / jt;
1264
+ return Qe(o.plane.toScreen([p, e(p)]), o);
1265
+ });
1266
+ return tn(t, Je(c, o.plane.height), s, r, o, l);
1267
+ }
1268
+ function Vn(t, e) {
1269
+ const n = t.derivative ? he(t.expr, t.derivative) : R(t.expr, "x"), [i, s] = t.domain ?? e.plane.x, r = E(e.theme, t.color, e.theme.colors.blue), o = t.dashed ? [10 * e.plane.scale, 8 * e.plane.scale] : void 0;
1270
+ return Vt(t.id, (l) => n(l, e.scope), i, s, r, (t.width ?? 3.5) * e.plane.scale, e, o);
1271
+ }
1272
+ function Bn(t, e) {
1273
+ const n = R(t.x, "t"), i = R(t.y, "t"), s = ct(e.values, t.transform), [r, o] = t.t ?? [0, Math.PI * 2], l = Array.from({ length: jt + 1 }, (d, u) => {
1274
+ const p = r + (o - r) * u / jt;
1275
+ return Qe(e.plane.toScreen(U(s, [n(p, e.scope), i(p, e.scope)])), e);
1276
+ }), c = E(e.theme, t.color, e.theme.colors.blue);
1277
+ return tn(t.id, Je(l, e.plane.height), c, (t.width ?? 3.5) * e.plane.scale, e);
1278
+ }
1279
+ const me = (t, e, n, i, s) => [[e, n], [i, n], [i, s], [e, s]].map(t.plane.toScreen), Dt = (t) => Math.min(2e4, Math.max(0, Math.floor(t)));
1280
+ function Wn(t, e) {
1281
+ const n = ft(e.values, t.distribution), i = Ue(n, t.seed ?? t.id, Dt(S(e.values, t.count))), s = xn(i, t.bins ?? xe(n), t.scale ?? "density"), r = E(e.theme, t.color, e.theme.colors.blue), o = e.opacity * e.draw, l = s.flatMap(
1282
+ (c, d) => c.height > 0 ? [{ type: "line", id: `${t.id}.${d}`, points: me(e, c.left, 0, c.right, c.height), closed: !0, fill: r, stroke: e.theme.background, width: 1 * e.plane.scale, opacity: o * (t.fillOpacity ?? 0.75) }] : []
1283
+ );
1284
+ if (t.curve && (t.scale ?? "density") === "density") {
1285
+ const [c, d] = t.bins ?? xe(n), u = E(e.theme, "yellow", e.theme.colors.yellow);
1286
+ l.push(...Vt(`${t.id}.curve`, (p) => st(_t(n) ? { kind: "normal", mean: At(n), sd: Et(n) } : n, p), c, d, u, 3 * e.plane.scale, { ...e, draw: 1 }));
1287
+ }
1288
+ return l;
1289
+ }
1290
+ function Un(t, e) {
1291
+ const n = ft(e.values, t.distribution), i = E(e.theme, t.color, e.theme.colors.blue), [s, r] = t.domain ?? e.plane.x, o = t.shade ? [S(e.values, t.shade[0]), S(e.values, t.shade[1])].sort((d, u) => d - u) : void 0, l = E(e.theme, "yellow", e.theme.colors.yellow);
1292
+ if (_t(n)) {
1293
+ const d = [], u = Math.max(0, Math.ceil(s)), p = Math.floor(r), h = u + Math.ceil((p - u + 1) * e.draw);
1294
+ for (let m = u; m < h && m <= p; m++) {
1295
+ const f = st(n, m);
1296
+ if (f <= 0) continue;
1297
+ const y = o && m >= o[0] && m <= o[1];
1298
+ d.push({ type: "line", id: `${t.id}.${m}`, points: me(e, m - 0.4, 0, m + 0.4, f), closed: !0, fill: y ? l : i, opacity: e.opacity * (t.fillOpacity ?? 0.8) });
1299
+ }
1300
+ return d;
1301
+ }
1302
+ const c = [];
1303
+ if (o && e.draw >= 1) {
1304
+ const [d, u] = [Math.max(o[0], s), Math.min(o[1], r)];
1305
+ if (u > d) {
1306
+ const h = Array.from({ length: 121 }, (f, y) => {
1307
+ const a = d + (u - d) * y / 120;
1308
+ return [a, st(n, a)];
1309
+ }), m = [[d, 0], ...h, [u, 0]].map(e.plane.toScreen);
1310
+ c.push({ type: "line", id: `${t.id}.shade`, points: m, closed: !0, fill: l, opacity: e.opacity * (t.fillOpacity ?? 0.4) });
1311
+ }
1312
+ }
1313
+ return c.push(...Vt(t.id, (d) => st(n, d), s, r, i, (t.width ?? 3.5) * e.plane.scale, e)), c;
1314
+ }
1315
+ function Hn(t, e) {
1316
+ const n = t.rows ?? 10, i = t.spacing ?? 0.5, s = t.top ?? e.plane.y[1] - i, r = i * 0.9, o = (b, k) => [b * i, s - k * r], l = E(e.theme, "grey", e.theme.colors.grey), c = E(e.theme, t.color, e.theme.colors.yellow), d = i * 0.19 * e.plane.unitX, u = [];
1317
+ for (let b = 0; b < n; b++)
1318
+ for (let k = 0; k <= b; k++) {
1319
+ const [$, x] = e.plane.toScreen(o(k - b / 2, b));
1320
+ u.push({ type: "circle", id: `${t.id}.peg.${b}.${k}`, x: $, y: x, r: d * 0.45, fill: l, opacity: e.opacity * e.draw });
1321
+ }
1322
+ const p = n + 0.3, h = Math.max(n + 2, (s - e.plane.y[0]) / r - 0.2);
1323
+ for (let b = 0; b <= n + 1; b++) {
1324
+ const k = b - (n + 1) / 2, $ = G([[o(k, p), o(k, h)].map(e.plane.toScreen)], e.draw);
1325
+ for (const x of $) u.push({ type: "line", id: `${t.id}.bin.${b}`, points: x, stroke: l, width: 1.2 * e.plane.scale, opacity: e.opacity * 0.6 });
1326
+ }
1327
+ const m = G([[o(-(n + 1) / 2, h), o((n + 1) / 2, h)].map(e.plane.toScreen)], e.draw);
1328
+ for (const b of m) u.push({ type: "line", id: `${t.id}.floor`, points: b, stroke: l, width: 1.2 * e.plane.scale, opacity: e.opacity * 0.6 });
1329
+ const f = Math.max(0, S(e.values, t.balls)), y = Math.floor(f), a = t.seed ?? t.id, g = new Array(n + 1).fill(0), w = 2 * d / e.plane.unitY / r, M = (b, k) => ({ x: b - n / 2 + (k % 2 ? 0.22 : -0.22), depth: h - w * (Math.floor(k / 2) + 0.5) });
1330
+ for (let b = 0; b < y; b++) {
1331
+ const k = Ht(Se(a, b, n)), $ = M(k, g[k]), [x, T] = e.plane.toScreen(o($.x, $.depth));
1332
+ g[k]++, u.push({ type: "circle", id: `${t.id}.ball.${b}`, x, y: T, r: d, fill: c, opacity: e.opacity });
1333
+ }
1334
+ const v = f - y;
1335
+ if (v > 0) {
1336
+ const b = Se(a, y, n), k = Math.min(1, v / 0.8);
1337
+ let { x: $, depth: x } = En(b, k);
1338
+ if (x -= 1, v > 0.8) {
1339
+ const q = ((v - 0.8) / 0.2) ** 2, F = Ht(b), vt = M(F, g[F]), K = { x: Ht(b) - n / 2, depth: n - 1 };
1340
+ x = K.depth + (vt.depth - K.depth) * q, $ = K.x + (vt.x - K.x) * q;
1341
+ }
1342
+ const [T, N] = e.plane.toScreen(o($, x));
1343
+ u.push({ type: "circle", id: `${t.id}.falling`, x: T, y: N, r: d, fill: c, opacity: e.opacity });
1344
+ }
1345
+ return u;
1346
+ }
1347
+ function Xn(t, e) {
1348
+ const n = en(t, e), i = Xe(n, t.seed ?? t.id, Dt(S(e.values, t.count))), s = E(e.theme, t.color, e.theme.colors.blue), r = E(e.theme, t.insideColor, e.theme.colors.yellow), o = t.inside ? lt(t.inside) : void 0, l = (t.radius ?? 3) * e.plane.scale, c = i.map(([d, u], p) => {
1349
+ const [h, m] = e.plane.toScreen([d, u]), f = o ? rt(o, { ...e.scope, x: d, y: u }) <= 0 : !1;
1350
+ return { type: "circle", id: `${t.id}.${p}`, x: h, y: m, r: l, fill: f ? r : s, opacity: e.opacity * e.draw * 0.85 };
1351
+ });
1352
+ if (t.fit) {
1353
+ const d = Ye(i);
1354
+ if (d) {
1355
+ const [u, p] = e.plane.x;
1356
+ c.push({ type: "line", id: `${t.id}.fit`, points: [[u, d.slope * u + d.intercept], [p, d.slope * p + d.intercept]].map(e.plane.toScreen), stroke: E(e.theme, "red", e.theme.colors.red), width: 3 * e.plane.scale, opacity: e.opacity });
1357
+ }
1358
+ }
1359
+ return c;
1002
1360
  }
1003
- function hn(t, e, n) {
1361
+ function en(t, e) {
1362
+ const n = t.points;
1363
+ return n.kind === "uniform" ? n : { kind: "linear", slope: S(e.values, n.slope), intercept: S(e.values, n.intercept), noise: S(e.values, n.noise), x: n.x };
1364
+ }
1365
+ function Yn(t, e) {
1366
+ const n = S(e.values, t.prior), i = S(e.values, t.truePositive), s = S(e.values, t.falsePositive), r = e.plane.x[1] - e.plane.x[0], o = e.plane.y[1] - e.plane.y[0], [l, c] = t.size ?? [r * 0.8, o * 0.7], [d, u] = t.at ?? [e.plane.x[0] + r * 0.1, e.plane.y[0] + o * 0.08], p = d + l * Math.min(1, Math.max(0, n)), h = E(e.theme, t.color, e.theme.colors.yellow), m = E(e.theme, "red", e.theme.colors.red), f = E(e.theme, "grey", e.theme.colors.grey), y = e.opacity * e.draw, a = (b, k, $, x, T, N, q) => ({
1367
+ type: "line",
1368
+ id: `${t.id}.${b}`,
1369
+ points: me(e, k, $, x, T),
1370
+ closed: !0,
1371
+ fill: N,
1372
+ stroke: e.theme.background,
1373
+ width: 2 * e.plane.scale,
1374
+ opacity: y * q
1375
+ }), g = u + c, w = g - c * Math.min(1, Math.max(0, i)), M = g - c * Math.min(1, Math.max(0, s)), v = [
1376
+ a("tp", d, w, p, g, h, 0.85),
1377
+ a("fn", d, u, p, w, f, 0.35),
1378
+ a("fp", p, M, d + l, g, m, 0.8),
1379
+ a("tn", p, u, d + l, M, f, 0.2)
1380
+ ];
1381
+ if (t.labels !== !1 && e.draw >= 1) {
1382
+ const b = 20 * e.plane.scale, k = ($, x, T, N) => {
1383
+ const [q, F] = e.plane.toScreen(T);
1384
+ v.push(...yt(ut(x, { values: e.scope, style: "inline" }), { x: q, y: F, size: b, color: N, opacity: e.opacity, idPrefix: `${t.id}.label.${$}.` }));
1385
+ };
1386
+ k("prior", `\\text{has it: } \\val{${t.id}.prior:3}`, [d + l / 2, u - o * 0.04], e.theme.ink), k("tp", `\\text{has it, tests positive: } \\val{${t.id}.truePositive:3}`, [d + l / 2, u - o * 0.09], h), k("fp", `\\text{does not, tests positive: } \\val{${t.id}.falsePositive:3}`, [d + l / 2, u - o * 0.14], m), k("posterior", `P(\\text{has it} \\mid +) = \\val{${t.id}.posterior:3}`, [d + l / 2, u + c + o * 0.05], h);
1387
+ }
1388
+ return v;
1389
+ }
1390
+ function Yt(t, e, n, i = 512) {
1391
+ if (e === n) return 0;
1392
+ const s = (n - e) / i;
1393
+ let r = t(e) + t(n);
1394
+ for (let o = 1; o < i; o++) r += t(e + o * s) * (o % 2 ? 4 : 2);
1395
+ return r * s / 3;
1396
+ }
1397
+ function nn(t, e, n, i, s) {
1398
+ const r = (n - e) / i;
1399
+ return Array.from({ length: i }, (o, l) => {
1400
+ const c = e + l * r, d = c + r;
1401
+ if (s === "trapezoid") return [c, d, t(c), t(d)];
1402
+ const u = t(s === "left" ? c : s === "right" ? d : (c + d) / 2);
1403
+ return [c, d, u, u];
1404
+ });
1405
+ }
1406
+ const rn = (t) => Math.min(400, Math.max(1, Math.round(t)));
1407
+ function sn(t, e, n) {
1408
+ const i = {}, s = { ...n };
1409
+ for (const r of t)
1410
+ switch (r.kind) {
1411
+ case "tangent": {
1412
+ const o = R(r.expr), l = S(e, r.at), c = r.h === void 0 ? 0 : S(e, r.h), d = Math.abs(c) > 1e-9 ? (o(l + c, s) - o(l, s)) / c : he(r.expr, 1)(l, s);
1413
+ Object.assign(i, { [`${r.id}.slope`]: d, [`${r.id}.x`]: l, [`${r.id}.y`]: o(l, s) });
1414
+ break;
1415
+ }
1416
+ case "riemann": {
1417
+ const o = R(r.expr), l = S(e, r.from), c = S(e, r.to), d = rn(S(e, r.n)), p = nn((h) => o(h, s), l, c, d, r.rule ?? "left").reduce((h, [m, f, y, a]) => h + (y + a) / 2 * (f - m), 0);
1418
+ Object.assign(i, { [`${r.id}.sum`]: p, [`${r.id}.exact`]: Yt((h) => o(h, s), l, c), [`${r.id}.n`]: d });
1419
+ break;
1420
+ }
1421
+ case "area": {
1422
+ const o = R(r.expr), l = r.lower ? R(r.lower) : () => 0;
1423
+ i[`${r.id}.value`] = Yt((c) => o(c, s) - l(c, s), S(e, r.from), S(e, r.to));
1424
+ break;
1425
+ }
1426
+ case "point":
1427
+ if (r.on !== void 0 && r.x !== void 0) {
1428
+ const o = S(e, r.x);
1429
+ Object.assign(i, { [`${r.id}.x`]: o, [`${r.id}.y`]: R(r.on)(o, s) });
1430
+ }
1431
+ break;
1432
+ case "histogram": {
1433
+ const o = Ue(ft(e, r.distribution), r.seed ?? r.id, Dt(S(e, r.count))), { mean: l, sd: c } = Sn(o);
1434
+ Object.assign(i, { [`${r.id}.count`]: o.length, [`${r.id}.mean`]: l, [`${r.id}.sd`]: c });
1435
+ break;
1436
+ }
1437
+ case "distribution": {
1438
+ const o = ft(e, r.distribution);
1439
+ let l = 0;
1440
+ if (r.shade) {
1441
+ const [c, d] = [S(e, r.shade[0]), S(e, r.shade[1])].sort((u, p) => u - p);
1442
+ if (_t(o))
1443
+ for (let u = Math.max(0, Math.ceil(c)); u <= Math.floor(d) && u <= 5e3; u++) l += st(o, u);
1444
+ else
1445
+ l = Yt((u) => st(o, u), c, d, 2048);
1446
+ }
1447
+ Object.assign(i, { [`${r.id}.p`]: l, [`${r.id}.mean`]: At(o), [`${r.id}.sd`]: Et(o) });
1448
+ break;
1449
+ }
1450
+ case "galton":
1451
+ i[`${r.id}.landed`] = Math.max(0, Math.floor(S(e, r.balls)));
1452
+ break;
1453
+ case "scatter": {
1454
+ const o = Xe(en(r, { values: e }), r.seed ?? r.id, Dt(S(e, r.count))), l = r.inside ? lt(r.inside) : void 0, c = l ? o.filter(([u, p]) => rt(l, { ...s, x: u, y: p }) <= 0).length : 0, d = Ye(o);
1455
+ Object.assign(i, {
1456
+ [`${r.id}.count`]: o.length,
1457
+ [`${r.id}.inside`]: c,
1458
+ [`${r.id}.ratio`]: o.length ? c / o.length : 0,
1459
+ [`${r.id}.slope`]: d?.slope ?? 0,
1460
+ [`${r.id}.intercept`]: d?.intercept ?? 0,
1461
+ [`${r.id}.r`]: d?.r ?? 0
1462
+ });
1463
+ break;
1464
+ }
1465
+ case "bayes": {
1466
+ const o = S(e, r.prior), l = An(o, S(e, r.truePositive), S(e, r.falsePositive));
1467
+ Object.assign(i, { [`${r.id}.prior`]: o, [`${r.id}.posterior`]: l.posterior, [`${r.id}.positive`]: l.positive, [`${r.id}.truePositive`]: l.truePositive, [`${r.id}.falsePositive`]: l.falsePositive });
1468
+ break;
1469
+ }
1470
+ case "taylor":
1471
+ i[`${r.id}.order`] = Math.min(20, Math.max(0, S(e, r.order))), i[`${r.id}.degree`] = Math.floor(i[`${r.id}.order`]);
1472
+ break;
1473
+ }
1474
+ return i;
1475
+ }
1476
+ const B = (t, e, n) => t + (e - t) * n;
1477
+ function Ne(t, e, n) {
1478
+ return t.kind === "stroke" ? { ...t, points: t.points.map(([i, s]) => [i + e, s + n]) } : { ...t, x: t.x + e, y: t.y + n };
1479
+ }
1480
+ function Zn(t, e, n) {
1004
1481
  if (t.kind === "glyph" && e.kind === "glyph" && t.text === e.text)
1005
- return { ...e, x: V(t.x, e.x, n), y: V(t.y, e.y, n), width: V(t.width, e.width, n), size: V(t.size, e.size, n) };
1482
+ return { ...e, x: B(t.x, e.x, n), y: B(t.y, e.y, n), width: B(t.width, e.width, n), size: B(t.size, e.size, n) };
1006
1483
  if (t.kind === "rule" && e.kind === "rule")
1007
- return { ...e, x: V(t.x, e.x, n), y: V(t.y, e.y, n), width: V(t.width, e.width, n), height: V(t.height, e.height, n) };
1484
+ return { ...e, x: B(t.x, e.x, n), y: B(t.y, e.y, n), width: B(t.width, e.width, n), height: B(t.height, e.height, n) };
1008
1485
  if (t.kind === "stroke" && e.kind === "stroke" && t.points.length === e.points.length)
1009
- return { ...e, width: V(t.width, e.width, n), points: t.points.map(([i, r], s) => [V(i, e.points[s][0], n), V(r, e.points[s][1], n)]) };
1010
- }
1011
- const fn = (t) => t * t * (3 - 2 * t);
1012
- function pn(t, e, n) {
1013
- const i = Math.min(1, Math.max(0, n)), r = t.layout.pieces.map((y) => ce(y, t.x, t.y)), s = e.layout.pieces.map((y) => ce(y, e.x, e.y));
1014
- if (i === 0) return r.map((y) => ({ ...y, opacity: 1 }));
1015
- if (i === 1) return s.map((y) => ({ ...y, opacity: 1 }));
1016
- const o = (y) => {
1017
- const a = /* @__PURE__ */ new Map();
1018
- for (const p of y) a.set(p.id, [...a.get(p.id) ?? [], p]);
1019
- return a;
1020
- }, l = o(r), c = o(s), f = [], u = fn(i), h = Math.max(0, 1 - i * 2), d = Math.max(0, i * 2 - 1);
1021
- for (const y of /* @__PURE__ */ new Set([...l.keys(), ...c.keys()])) {
1022
- const a = l.get(y) ?? [], p = c.get(y) ?? [], m = Math.max(a.length, p.length);
1023
- for (let b = 0; b < m; b++) {
1024
- const w = a[b], $ = p[b], g = w && $ ? hn(w, $, u) : void 0;
1025
- if (g) {
1026
- f.push({ ...g, opacity: 1 });
1486
+ return { ...e, width: B(t.width, e.width, n), points: t.points.map(([i, s], r) => [B(i, e.points[r][0], n), B(s, e.points[r][1], n)]) };
1487
+ }
1488
+ const Gn = (t) => t * t * (3 - 2 * t);
1489
+ function Kn(t, e, n) {
1490
+ const i = Math.min(1, Math.max(0, n)), s = t.layout.pieces.map((m) => Ne(m, t.x, t.y)), r = e.layout.pieces.map((m) => Ne(m, e.x, e.y));
1491
+ if (i === 0) return s.map((m) => ({ ...m, opacity: 1 }));
1492
+ if (i === 1) return r.map((m) => ({ ...m, opacity: 1 }));
1493
+ const o = (m) => {
1494
+ const f = /* @__PURE__ */ new Map();
1495
+ for (const y of m) f.set(y.id, [...f.get(y.id) ?? [], y]);
1496
+ return f;
1497
+ }, l = o(s), c = o(r), d = [], u = Gn(i), p = Math.max(0, 1 - i * 2), h = Math.max(0, i * 2 - 1);
1498
+ for (const m of /* @__PURE__ */ new Set([...l.keys(), ...c.keys()])) {
1499
+ const f = l.get(m) ?? [], y = c.get(m) ?? [], a = Math.max(f.length, y.length);
1500
+ for (let g = 0; g < a; g++) {
1501
+ const w = f[g], M = y[g], v = w && M ? Zn(w, M, u) : void 0;
1502
+ if (v) {
1503
+ d.push({ ...v, opacity: 1 });
1027
1504
  continue;
1028
1505
  }
1029
- w && f.push({ ...w, opacity: h }), $ && f.push({ ...$, opacity: d });
1506
+ w && d.push({ ...w, opacity: p }), M && d.push({ ...M, opacity: h });
1030
1507
  }
1031
1508
  }
1032
- return f.filter((y) => y.opacity > 0);
1509
+ return d.filter((m) => m.opacity > 0);
1033
1510
  }
1034
- const ue = [
1511
+ const Ie = [
1035
1512
  "grid",
1036
1513
  "axes",
1037
1514
  "vector",
@@ -1046,8 +1523,13 @@ const ue = [
1046
1523
  "tangent",
1047
1524
  "riemann",
1048
1525
  "area",
1049
- "taylor"
1050
- ], Ut = {
1526
+ "taylor",
1527
+ "histogram",
1528
+ "distribution",
1529
+ "galton",
1530
+ "scatter",
1531
+ "bayes"
1532
+ ], ae = {
1051
1533
  dark: {
1052
1534
  background: "#0f1117",
1053
1535
  ink: "#f2f2f2",
@@ -1072,7 +1554,7 @@ const ue = [
1072
1554
  axes: "#eef0e6",
1073
1555
  colors: { blue: "#9fd3f0", green: "#b9e39a", red: "#f59a8f", yellow: "#f6e58d", purple: "#d0b5f2", orange: "#f7c08a", teal: "#a3e4d4", pink: "#f4b6dc", ink: "#eef0e6", grey: "#a9b0a6" }
1074
1556
  }
1075
- }, mn = /* @__PURE__ */ new Set([
1557
+ }, Jn = /* @__PURE__ */ new Set([
1076
1558
  "x",
1077
1559
  "y",
1078
1560
  "z",
@@ -1106,488 +1588,434 @@ const ue = [
1106
1588
  "clipLeft",
1107
1589
  "quaternion"
1108
1590
  ]);
1109
- function bt(t) {
1591
+ function Tt(t) {
1110
1592
  const e = (a) => {
1111
1593
  throw new Error(`math figure: ${a}`);
1112
1594
  };
1113
1595
  (!t || typeof t != "object") && e("expected a figure object"), (!(t.width > 0) || !(t.height > 0)) && e("width and height must be positive numbers (px)");
1114
1596
  for (const a of ["x", "y"]) {
1115
- const p = t[a];
1116
- p !== void 0 && !(Array.isArray(p) && p.length === 2 && p.every(Number.isFinite) && p[0] < p[1]) && e(`${a} must be [min, max] with min < max`);
1597
+ const g = t[a];
1598
+ g !== void 0 && !(Array.isArray(g) && g.length === 2 && g.every(Number.isFinite) && g[0] < g[1]) && e(`${a} must be [min, max] with min < max`);
1117
1599
  }
1118
- t.theme !== void 0 && !(t.theme in Ut) && e(it("theme", t.theme, Object.keys(Ut))), Array.isArray(t.items) || e("items must be an array");
1600
+ t.theme !== void 0 && !(t.theme in ae) && e(J("theme", t.theme, Object.keys(ae))), Array.isArray(t.items) || e("items must be an array");
1119
1601
  const n = t.values ?? {};
1120
- for (const [a, p] of Object.entries(n))
1121
- /^[A-Za-z_]\w*$/.test(a) || e(`value name "${a}" must be letters, digits and _ (starting with a letter)`), mn.has(a) && e(`"${a}" cannot name a value: it is ${a === "x" || a === "t" ? "the variable of functions and curves" : "a property of the figure itself (its place, size or look)"}`), typeof p == "number" && Number.isFinite(p) || tt(p) || lt(p) || e(`value "${a}" must be a number, an [x, y] vector or an [a, b, c, d] matrix`);
1122
- const i = $e(n), r = Object.keys(n).filter((a) => typeof n[a] == "number"), s = (a, p, m) => {
1123
- m !== void 0 && (typeof m == "string" ? (m in n || e(`${a.id}.${p}: ${it("value", m, Object.keys(n))}`), tt(n[m]) || e(`${a.id}.${p}: value "${m}" is not an [x, y] vector`)) : tt(m) || e(`${a.id}.${p} must be [x, y] or the name of a vector value`));
1124
- }, o = (a, p, m) => {
1125
- m !== void 0 && (m in n || e(`${a.id}.${p}: ${it("value", m, Object.keys(n))}`), lt(n[m]) || e(`${a.id}.${p}: value "${m}" is not an [a, b, c, d] matrix`));
1126
- }, l = (a, p, m, b) => {
1127
- let w = [];
1602
+ for (const [a, g] of Object.entries(n))
1603
+ /^[A-Za-z_]\w*$/.test(a) || e(`value name "${a}" must be letters, digits and _ (starting with a letter)`), Jn.has(a) && e(`"${a}" cannot name a value: it is ${a === "x" || a === "t" ? "the variable of functions and curves" : "a property of the figure itself (its place, size or look)"}`), typeof g == "number" && Number.isFinite(g) || it(g) || pt(g) || e(`value "${a}" must be a number, an [x, y] vector or an [a, b, c, d] matrix`);
1604
+ const i = Be(n), s = Object.keys(n).filter((a) => typeof n[a] == "number"), r = (a, g, w) => {
1605
+ w !== void 0 && (typeof w == "string" ? (w in n || e(`${a.id}.${g}: ${J("value", w, Object.keys(n))}`), it(n[w]) || e(`${a.id}.${g}: value "${w}" is not an [x, y] vector`)) : it(w) || e(`${a.id}.${g} must be [x, y] or the name of a vector value`));
1606
+ }, o = (a, g, w) => {
1607
+ w !== void 0 && (w in n || e(`${a.id}.${g}: ${J("value", w, Object.keys(n))}`), pt(n[w]) || e(`${a.id}.${g}: value "${w}" is not an [a, b, c, d] matrix`));
1608
+ }, l = (a, g, w, M) => {
1609
+ let v = [];
1610
+ try {
1611
+ v = Me(lt(w));
1612
+ } catch (b) {
1613
+ e(`${a.id}.${g}: ${b.message}`);
1614
+ }
1615
+ for (const b of v)
1616
+ b !== M && !(b in Ct) && !s.includes(b) && e(`${a.id}.${g}: "${b}" is neither ${M} nor a number value (${J("value", b, [M, ...s])})`);
1617
+ }, c = [], d = (a, g, w) => {
1618
+ c.push([a, g, w]);
1619
+ }, u = (a, g, w) => {
1620
+ w !== void 0 && (typeof w == "string" ? (w in n || e(`${a.id}.${g}: ${J("value", w, s)}`), typeof n[w] != "number" && e(`${a.id}.${g}: value "${w}" is not a number`)) : Number.isFinite(w) || e(`${a.id}.${g} must be a number or the name of a number value`));
1621
+ }, p = (a, g, w) => {
1622
+ (!w || typeof w != "object" || !zt.includes(w.kind)) && e(`${a.id}.${g}: ${J("distribution", w?.kind, zt)}`);
1623
+ for (const [v, b] of Object.entries(w))
1624
+ v !== "kind" && (v === "of" ? p(a, `${g}.of`, b) : u(a, `${g}.${v}`, b));
1625
+ const M = He(ft(n, w));
1626
+ M && e(`${a.id}.${g}: ${M}`);
1627
+ }, h = (a, g, w) => {
1628
+ let M = [];
1128
1629
  try {
1129
- w = Ze(At(m));
1130
- } catch ($) {
1131
- e(`${a.id}.${p}: ${$.message}`);
1132
- }
1133
- for (const $ of w)
1134
- $ !== b && !($ in Et) && !r.includes($) && e(`${a.id}.${p}: "${$}" is neither ${b} nor a number value (${it("value", $, [b, ...r])})`);
1135
- }, c = [], f = (a, p, m) => {
1136
- c.push([a, p, m]);
1137
- }, u = (a, p, m) => {
1138
- m !== void 0 && (typeof m == "string" ? (m in n || e(`${a.id}.${p}: ${it("value", m, r)}`), typeof n[m] != "number" && e(`${a.id}.${p}: value "${m}" is not a number`)) : Number.isFinite(m) || e(`${a.id}.${p} must be a number or the name of a number value`));
1139
- }, h = (a, p, m, b) => {
1630
+ M = Me(lt(w));
1631
+ } catch (v) {
1632
+ e(`${a.id}.${g}: ${v.message}`);
1633
+ }
1634
+ for (const v of M)
1635
+ v !== "x" && v !== "y" && !s.includes(v) && e(`${a.id}.${g}: "${v}" is neither x, y nor a number value`);
1636
+ }, m = (a, g, w, M) => {
1140
1637
  try {
1141
- let w = At(m);
1142
- for (let $ = 0; $ < b; $++) w = G(w);
1143
- } catch (w) {
1144
- e(`${a.id}.${p}: ${w.message} (calculus needs functions with derivatives)`);
1638
+ let v = lt(w);
1639
+ for (let b = 0; b < M; b++) v = tt(v);
1640
+ } catch (v) {
1641
+ e(`${a.id}.${g}: ${v.message} (calculus needs functions with derivatives)`);
1145
1642
  }
1146
- }, d = /* @__PURE__ */ new Set();
1643
+ }, f = /* @__PURE__ */ new Set();
1147
1644
  for (const a of t.items)
1148
- switch ((!a || typeof a != "object") && e("every item must be an object"), ue.includes(a.kind) || e(it("item kind", a.kind, ue)), (typeof a.id != "string" || !/^[A-Za-z_][\w-]*$/.test(a.id)) && e(`a ${a.kind} needs an id (letters, digits, _ and -)`), d.has(a.id) && e(`two items have the id "${a.id}"`), a.id in n && e(`"${a.id}" is both an item id and a value name`), d.add(a.id), a.kind) {
1645
+ switch ((!a || typeof a != "object") && e("every item must be an object"), Ie.includes(a.kind) || e(J("item kind", a.kind, Ie)), (typeof a.id != "string" || !/^[A-Za-z_][\w-]*$/.test(a.id)) && e(`a ${a.kind} needs an id (letters, digits, _ and -)`), f.has(a.id) && e(`two items have the id "${a.id}"`), a.id in n && e(`"${a.id}" is both an item id and a value name`), f.add(a.id), a.kind) {
1149
1646
  case "grid":
1150
1647
  a.step !== void 0 && !(a.step > 0) && e(`${a.id}.step must be positive`), o(a, "transform", a.transform);
1151
1648
  break;
1152
1649
  case "vector":
1153
- s(a, "to", a.to), s(a, "from", a.from), o(a, "transform", a.transform), a.label && f(a, "label", a.label);
1650
+ r(a, "to", a.to), r(a, "from", a.from), o(a, "transform", a.transform), a.label && d(a, "label", a.label);
1154
1651
  break;
1155
1652
  case "basis":
1156
1653
  o(a, "transform", a.transform);
1157
1654
  break;
1158
1655
  case "point":
1159
- a.at === void 0 == (a.on === void 0) && e(`${a.id} needs at, or on with x (a point on a curve)`), a.on !== void 0 && (a.x === void 0 && e(`${a.id}: a point on a curve needs x`), l(a, "on", a.on, "x"), u(a, "x", a.x)), s(a, "at", a.at), o(a, "transform", a.transform), a.label && f(a, "label", a.label);
1656
+ a.at === void 0 == (a.on === void 0) && e(`${a.id} needs at, or on with x (a point on a curve)`), a.on !== void 0 && (a.x === void 0 && e(`${a.id}: a point on a curve needs x`), l(a, "on", a.on, "x"), u(a, "x", a.x)), r(a, "at", a.at), o(a, "transform", a.transform), a.label && d(a, "label", a.label);
1160
1657
  break;
1161
1658
  case "function":
1162
- l(a, "expr", a.expr, "x"), a.derivative !== void 0 && ((!Number.isInteger(a.derivative) || a.derivative < 0 || a.derivative > 8) && e(`${a.id}.derivative must be a whole number from 0 to 8`), h(a, "expr", a.expr, a.derivative));
1659
+ l(a, "expr", a.expr, "x"), a.derivative !== void 0 && ((!Number.isInteger(a.derivative) || a.derivative < 0 || a.derivative > 8) && e(`${a.id}.derivative must be a whole number from 0 to 8`), m(a, "expr", a.expr, a.derivative));
1163
1660
  break;
1164
1661
  case "tangent":
1165
- l(a, "expr", a.expr, "x"), h(a, "expr", a.expr, 1), u(a, "at", a.at), u(a, "h", a.h), a.label && f(a, "label", a.label);
1662
+ l(a, "expr", a.expr, "x"), m(a, "expr", a.expr, 1), u(a, "at", a.at), u(a, "h", a.h), a.label && d(a, "label", a.label);
1166
1663
  break;
1167
1664
  case "riemann":
1168
- l(a, "expr", a.expr, "x"), u(a, "from", a.from), u(a, "to", a.to), u(a, "n", a.n), a.rule !== void 0 && !["left", "right", "midpoint", "trapezoid"].includes(a.rule) && e(`${a.id}.rule: ${it("rule", a.rule, ["left", "right", "midpoint", "trapezoid"])}`);
1665
+ l(a, "expr", a.expr, "x"), u(a, "from", a.from), u(a, "to", a.to), u(a, "n", a.n), a.rule !== void 0 && !["left", "right", "midpoint", "trapezoid"].includes(a.rule) && e(`${a.id}.rule: ${J("rule", a.rule, ["left", "right", "midpoint", "trapezoid"])}`);
1169
1666
  break;
1170
1667
  case "area":
1171
1668
  l(a, "expr", a.expr, "x"), a.lower !== void 0 && l(a, "lower", a.lower, "x"), u(a, "from", a.from), u(a, "to", a.to);
1172
1669
  break;
1670
+ case "histogram":
1671
+ p(a, "distribution", a.distribution), u(a, "count", a.count), a.bins !== void 0 && !(Array.isArray(a.bins) && a.bins.length === 3 && a.bins[1] > a.bins[0] && Number.isInteger(a.bins[2]) && a.bins[2] >= 1 && a.bins[2] <= 500) && e(`${a.id}.bins must be [from, to, count] with from < to and a whole count 1..500`);
1672
+ break;
1673
+ case "distribution":
1674
+ p(a, "distribution", a.distribution), a.shade && a.shade.forEach((g, w) => u(a, `shade[${w}]`, g));
1675
+ break;
1676
+ case "galton":
1677
+ a.rows !== void 0 && !(Number.isInteger(a.rows) && a.rows >= 1 && a.rows <= 30) && e(`${a.id}.rows must be a whole number 1..30`), u(a, "balls", a.balls);
1678
+ break;
1679
+ case "scatter":
1680
+ (!a.points || !["uniform", "linear"].includes(a.points.kind)) && e(`${a.id}.points: ${J("points kind", a.points?.kind, ["uniform", "linear"])}`), a.points.kind === "linear" && (u(a, "points.slope", a.points.slope), u(a, "points.intercept", a.points.intercept), u(a, "points.noise", a.points.noise)), u(a, "count", a.count), a.inside && h(a, "inside", a.inside);
1681
+ break;
1682
+ case "bayes":
1683
+ u(a, "prior", a.prior), u(a, "truePositive", a.truePositive), u(a, "falsePositive", a.falsePositive);
1684
+ break;
1173
1685
  case "taylor":
1174
- l(a, "expr", a.expr, "x"), h(a, "expr", a.expr, 3), u(a, "at", a.at), u(a, "order", a.order);
1686
+ l(a, "expr", a.expr, "x"), m(a, "expr", a.expr, 3), u(a, "at", a.at), u(a, "order", a.order);
1175
1687
  break;
1176
1688
  case "parametric":
1177
1689
  l(a, "x", a.x, "t"), l(a, "y", a.y, "t"), o(a, "transform", a.transform);
1178
1690
  break;
1179
1691
  case "polygon":
1180
- a.points !== void 0 && !(Array.isArray(a.points) && a.points.length >= 3 && a.points.every(tt)) && e(`${a.id}.points must be three or more [x, y] points`), o(a, "transform", a.transform), a.label && f(a, "label", a.label);
1692
+ a.points !== void 0 && !(Array.isArray(a.points) && a.points.length >= 3 && a.points.every(it)) && e(`${a.id}.points must be three or more [x, y] points`), o(a, "transform", a.transform), a.label && d(a, "label", a.label);
1181
1693
  break;
1182
1694
  case "line":
1183
- a.along === void 0 == (a.eigen === void 0) && e(`${a.id} needs exactly one of along or eigen`), s(a, "along", a.along), o(a, "eigen", a.eigen);
1695
+ a.along === void 0 == (a.eigen === void 0) && e(`${a.id} needs exactly one of along or eigen`), r(a, "along", a.along), o(a, "eigen", a.eigen);
1184
1696
  break;
1185
1697
  case "label":
1186
- s(a, "at", a.at), f(a, "tex", a.tex);
1698
+ r(a, "at", a.at), d(a, "tex", a.tex);
1187
1699
  break;
1188
1700
  case "equation":
1189
- s(a, "at", a.at), (!Array.isArray(a.steps) || a.steps.length === 0) && e(`${a.id}.steps needs at least one TeX step`), a.steps.forEach((p, m) => f(a, `steps[${m}]`, p));
1701
+ r(a, "at", a.at), (!Array.isArray(a.steps) || a.steps.length === 0) && e(`${a.id}.steps needs at least one TeX step`), a.steps.forEach((g, w) => d(a, `steps[${w}]`, g));
1190
1702
  break;
1191
1703
  }
1192
- const y = { ...i, ...Se(t.items, n, i) };
1193
- for (const [a, p, m] of c)
1704
+ const y = { ...i, ...sn(t.items, n, i) };
1705
+ for (const [a, g, w] of c)
1194
1706
  try {
1195
- ut(m, { values: y });
1196
- } catch (b) {
1197
- e(`${a.id}.${p}: ${b.message}`);
1707
+ ut(w, { values: y });
1708
+ } catch (M) {
1709
+ e(`${a.id}.${g}: ${M.message}`);
1198
1710
  }
1199
1711
  return t;
1200
1712
  }
1201
- function Te(t) {
1202
- const { width: e, height: n } = t, i = t.x ?? [-5, 5], r = e / (i[1] - i[0]), s = t.y ?? [-(n / r) / 2, n / r / 2], o = n / (s[1] - s[0]);
1713
+ function on(t) {
1714
+ const { width: e, height: n } = t, i = t.x ?? [-5, 5], s = e / (i[1] - i[0]), r = t.y ?? [-(n / s) / 2, n / s / 2], o = n / (r[1] - r[0]);
1203
1715
  return {
1204
1716
  width: e,
1205
1717
  height: n,
1206
1718
  x: i,
1207
- y: s,
1208
- unitX: r,
1719
+ y: r,
1720
+ unitX: s,
1209
1721
  unitY: o,
1210
1722
  scale: Math.min(e, n) / 600,
1211
- toScreen: ([l, c]) => [(l - i[0]) * r, (s[1] - c) * o],
1212
- toWorld: ([l, c]) => [i[0] + l / r, s[1] - c / o]
1723
+ toScreen: ([l, c]) => [(l - i[0]) * s, (r[1] - c) * o],
1724
+ toWorld: ([l, c]) => [i[0] + l / s, r[1] - c / o]
1213
1725
  };
1214
1726
  }
1215
- const de = 'system-ui, -apple-system, "Segoe UI", sans-serif', he = (t, e) => Math.hypot(e[0] - t[0], e[1] - t[1]);
1216
- function et(t, e) {
1217
- if (e >= 1) return t;
1218
- if (e <= 0) return [];
1219
- const n = t.map((s) => s.slice(1).reduce((o, l, c) => o + he(s[c], l), 0));
1220
- let i = n.reduce((s, o) => s + o, 0) * e;
1221
- const r = [];
1222
- for (const [s, o] of t.entries()) {
1223
- if (i <= 0) break;
1224
- if (n[s] <= i) {
1225
- r.push(o), i -= n[s];
1226
- continue;
1227
- }
1228
- const l = [o[0]];
1229
- for (let c = 1; c < o.length; c++) {
1230
- const f = he(o[c - 1], o[c]);
1231
- if (f >= i) {
1232
- const u = f === 0 ? 0 : i / f;
1233
- l.push([o[c - 1][0] + (o[c][0] - o[c - 1][0]) * u, o[c - 1][1] + (o[c][1] - o[c - 1][1]) * u]);
1234
- break;
1235
- }
1236
- l.push(o[c]), i -= f;
1237
- }
1238
- r.push(l), i = 0;
1239
- }
1240
- return r;
1241
- }
1242
- function Gt(t, e) {
1243
- const n = e.align ?? "center", i = n === "left" ? 0 : n === "right" ? -t.width : -t.width / 2, r = e.baseline === "baseline" ? 0 : (t.height - t.depth) / 2;
1244
- return [e.x + i * e.size, e.y + r * e.size];
1245
- }
1246
- function Oe(t, e, n) {
1247
- const [i, r] = e, s = n.size, o = n.opacity ?? 1;
1248
- return t.map((l) => {
1249
- const c = l.color ?? n.color, f = o * (l.opacity ?? 1), u = `${n.idPrefix}${l.id}`;
1250
- if (l.kind === "glyph")
1251
- return {
1252
- type: "text",
1253
- id: u,
1254
- text: l.text,
1255
- x: i + (l.x + l.width / 2) * s,
1256
- y: r + l.y * s,
1257
- size: l.size * s,
1258
- font: tn,
1259
- italic: l.italic,
1260
- color: c,
1261
- align: "center",
1262
- opacity: f
1263
- };
1264
- if (l.kind === "rule") {
1265
- const h = i + l.x * s, d = r + l.y * s, y = l.width * s, a = Math.max(1, l.height * s);
1266
- return { type: "line", id: u, points: [[h, d], [h + y, d], [h + y, d + a], [h, d + a]], closed: !0, fill: c, opacity: f };
1267
- }
1268
- return { type: "line", id: u, points: l.points.map(([h, d]) => [i + h * s, r + d * s]), stroke: c, width: Math.max(1, l.width * s), opacity: f };
1269
- });
1270
- }
1271
- function vt(t, e) {
1272
- return Oe(t.pieces, Gt(t, e), e);
1273
- }
1274
- function yn(t, e) {
1275
- const n = Math.max(Math.abs(t.x[0]), Math.abs(t.x[1]), Math.abs(t.y[0]), Math.abs(t.y[1])), [i, r, s, o] = e, l = Math.hypot(i, r, s, o), c = l === 0 ? 0 : Math.abs(gt(e)) / l;
1727
+ function Qn(t, e) {
1728
+ const n = Math.max(Math.abs(t.x[0]), Math.abs(t.x[1]), Math.abs(t.y[0]), Math.abs(t.y[1])), [i, s, r, o] = e, l = Math.hypot(i, s, r, o), c = l === 0 ? 0 : Math.abs(St(e)) / l;
1276
1729
  return Math.min(n * 12, n / Math.max(c, 0.08)) + 1;
1277
1730
  }
1278
- function fe(t, e, n) {
1279
- const i = yn(t, e), r = Math.min(120, Math.ceil(i / n)), s = [];
1280
- for (let o = -r; o <= r; o++) {
1731
+ function Le(t, e, n) {
1732
+ const i = Qn(t, e), s = Math.min(120, Math.ceil(i / n)), r = [];
1733
+ for (let o = -s; o <= s; o++) {
1281
1734
  const l = o * n;
1282
- s.push({ line: [B(e, [l, -i]), B(e, [l, i])].map(t.toScreen), axis: o === 0 }), s.push({ line: [B(e, [-i, l]), B(e, [i, l])].map(t.toScreen), axis: o === 0 });
1735
+ r.push({ line: [U(e, [l, -i]), U(e, [l, i])].map(t.toScreen), axis: o === 0 }), r.push({ line: [U(e, [-i, l]), U(e, [i, l])].map(t.toScreen), axis: o === 0 });
1283
1736
  }
1284
- return s;
1737
+ return r;
1285
1738
  }
1286
- function gn(t, e) {
1287
- const { plane: n, theme: i } = e, r = t.step ?? 1, s = [], o = 1.4 * n.scale;
1739
+ function ti(t, e) {
1740
+ const { plane: n, theme: i } = e, s = t.step ?? 1, r = [], o = 1.4 * n.scale;
1288
1741
  if (t.ghost)
1289
- for (const [c, { line: f }] of fe(n, [1, 0, 0, 1], r).entries())
1290
- s.push({ type: "line", id: `${t.id}.ghost.${c}`, points: f, stroke: i.ghost, width: o, opacity: e.opacity });
1291
- const l = F(i, t.color, i.grid);
1292
- for (const [c, { line: f, axis: u }] of fe(n, st(e.values, t.transform), r).entries()) {
1293
- const [h] = et([f], e.draw);
1294
- h && s.push({ type: "line", id: `${t.id}.${c}`, points: h, stroke: u ? i.ink : l, width: u ? o * 1.6 : o, opacity: e.opacity });
1742
+ for (const [c, { line: d }] of Le(n, [1, 0, 0, 1], s).entries())
1743
+ r.push({ type: "line", id: `${t.id}.ghost.${c}`, points: d, stroke: i.ghost, width: o, opacity: e.opacity });
1744
+ const l = E(i, t.color, i.grid);
1745
+ for (const [c, { line: d, axis: u }] of Le(n, ct(e.values, t.transform), s).entries()) {
1746
+ const [p] = G([d], e.draw);
1747
+ p && r.push({ type: "line", id: `${t.id}.${c}`, points: p, stroke: u ? i.ink : l, width: u ? o * 1.6 : o, opacity: e.opacity });
1295
1748
  }
1296
- return s;
1749
+ return r;
1297
1750
  }
1298
- function bn(t, e) {
1299
- const { plane: n, theme: i } = e, r = F(i, t.color, i.axes), s = 2 * n.scale, o = e.opacity, l = et([[n.toScreen([n.x[0], 0]), n.toScreen([n.x[1], 0])]], e.draw), c = et([[n.toScreen([0, n.y[0]]), n.toScreen([0, n.y[1]])]], e.draw), f = [...l, ...c].map((p, m) => ({ type: "line", id: `${t.id}.${m ? "y" : "x"}`, points: p, stroke: r, width: s, opacity: o })), u = t.ticks ?? 1;
1300
- if (u <= 0 || e.draw < 1) return f;
1301
- const h = 5 * n.scale, d = 13 * n.scale, y = (p, m) => {
1302
- const b = [];
1303
- for (let w = Math.ceil(p / u) * u; w <= m + 1e-9; w += u) Math.abs(w) > 1e-9 && b.push(Number(w.toFixed(6)));
1304
- return b;
1305
- }, a = (p) => String(p).replace("-", "−");
1306
- for (const p of y(n.x[0], n.x[1])) {
1307
- const [m, b] = n.toScreen([p, 0]);
1308
- f.push({ type: "line", id: `${t.id}.tick.x${p}`, points: [[m, b - h], [m, b + h]], stroke: r, width: s * 0.8, opacity: o }), t.labels !== !1 && f.push({ type: "text", id: `${t.id}.label.x${p}`, text: a(p), x: m, y: b + h + d * 1.1, size: d, font: de, color: r, align: "center", opacity: o * 0.8 });
1309
- }
1310
- for (const p of y(n.y[0], n.y[1])) {
1311
- const [m, b] = n.toScreen([0, p]);
1312
- f.push({ type: "line", id: `${t.id}.tick.y${p}`, points: [[m - h, b], [m + h, b]], stroke: r, width: s * 0.8, opacity: o }), t.labels !== !1 && f.push({ type: "text", id: `${t.id}.label.y${p}`, text: a(p), x: m - h - d * 0.4, y: b + d * 0.35, size: d, font: de, color: r, align: "right", opacity: o * 0.8 });
1313
- }
1314
- return f;
1315
- }
1316
- function Tt(t, e, n, i, r, s) {
1317
- const o = 26 * s.plane.scale, [l, c] = we(n), f = ut(t, { values: s.scope, style: "inline" }), u = o * (0.55 + Math.abs(l) * f.width * 0.5);
1318
- return vt(f, { x: e[0] + l * u, y: e[1] + c * u, size: o, color: i, opacity: s.opacity, idPrefix: `${r}.label.` });
1319
- }
1320
- function Le(t, e, n, i, r, s) {
1321
- const o = s.plane.toScreen(e), l = s.plane.toScreen(n), [c] = et([[o, l]], s.draw);
1751
+ function ei(t, e) {
1752
+ const { plane: n, theme: i } = e, s = E(i, t.color, i.axes), r = 2 * n.scale, o = e.opacity, l = G([[n.toScreen([n.x[0], 0]), n.toScreen([n.x[1], 0])]], e.draw), c = G([[n.toScreen([0, n.y[0]]), n.toScreen([0, n.y[1]])]], e.draw), d = [...l, ...c].map((y, a) => ({ type: "line", id: `${t.id}.${a ? "y" : "x"}`, points: y, stroke: s, width: r, opacity: o })), u = t.ticks ?? 1;
1753
+ if (u <= 0 || e.draw < 1) return d;
1754
+ const p = 5 * n.scale, h = 13 * n.scale, m = (y, a) => {
1755
+ const g = [];
1756
+ for (let w = Math.ceil(y / u) * u; w <= a + 1e-9; w += u) Math.abs(w) > 1e-9 && g.push(Number(w.toFixed(6)));
1757
+ return g;
1758
+ }, f = (y) => String(y).replace("-", "−");
1759
+ for (const y of m(n.x[0], n.x[1])) {
1760
+ const [a, g] = n.toScreen([y, 0]);
1761
+ d.push({ type: "line", id: `${t.id}.tick.x${y}`, points: [[a, g - p], [a, g + p]], stroke: s, width: r * 0.8, opacity: o }), t.labels !== !1 && d.push({ type: "text", id: `${t.id}.label.x${y}`, text: f(y), x: a, y: g + p + h * 1.1, size: h, font: Oe, color: s, align: "center", opacity: o * 0.8 });
1762
+ }
1763
+ for (const y of m(n.y[0], n.y[1])) {
1764
+ const [a, g] = n.toScreen([0, y]);
1765
+ d.push({ type: "line", id: `${t.id}.tick.y${y}`, points: [[a - p, g], [a + p, g]], stroke: s, width: r * 0.8, opacity: o }), t.labels !== !1 && d.push({ type: "text", id: `${t.id}.label.y${y}`, text: f(y), x: a - p - h * 0.4, y: g + h * 0.35, size: h, font: Oe, color: s, align: "right", opacity: o * 0.8 });
1766
+ }
1767
+ return d;
1768
+ }
1769
+ function Rt(t, e, n, i, s, r) {
1770
+ const o = 26 * r.plane.scale, [l, c] = _e(n), d = ut(t, { values: r.scope, style: "inline" }), u = o * (0.55 + Math.abs(l) * d.width * 0.5);
1771
+ return yt(d, { x: e[0] + l * u, y: e[1] + c * u, size: o, color: i, opacity: r.opacity, idPrefix: `${s}.label.` });
1772
+ }
1773
+ function an(t, e, n, i, s, r) {
1774
+ const o = r.plane.toScreen(e), l = r.plane.toScreen(n), [c] = G([[o, l]], r.draw);
1322
1775
  if (!c) return [];
1323
- const f = Math.hypot(l[0] - o[0], l[1] - o[1]), u = Math.min(r * 3.6, f * 0.45);
1324
- return [{ type: "arrow", id: t, points: c, stroke: i, width: r, head: u, opacity: s.opacity }];
1776
+ const d = Math.hypot(l[0] - o[0], l[1] - o[1]), u = Math.min(s * 3.6, d * 0.45);
1777
+ return [{ type: "arrow", id: t, points: c, stroke: i, width: s, head: u, opacity: r.opacity }];
1325
1778
  }
1326
- function vn(t, e) {
1327
- const n = st(e.values, t.transform), i = B(n, t.from === void 0 ? [0, 0] : pt(e.values, t.from)), r = B(n, pt(e.values, t.to)), s = F(e.theme, t.color, e.theme.colors.yellow), o = Le(t.id, i, r, s, (t.width ?? 4) * e.plane.scale, e);
1779
+ function ni(t, e) {
1780
+ const n = ct(e.values, t.transform), i = U(n, t.from === void 0 ? [0, 0] : $t(e.values, t.from)), s = U(n, $t(e.values, t.to)), r = E(e.theme, t.color, e.theme.colors.yellow), o = an(t.id, i, s, r, (t.width ?? 4) * e.plane.scale, e);
1328
1781
  if (t.label && e.draw >= 1) {
1329
- const l = e.plane.toScreen(r), c = e.plane.toScreen(i), f = Xt(l, c);
1782
+ const l = e.plane.toScreen(s), c = e.plane.toScreen(i), d = de(l, c);
1330
1783
  if (t.labelAt === "middle") {
1331
1784
  const u = [(l[0] + c[0]) / 2, (l[1] + c[1]) / 2];
1332
- o.push(...Tt(t.label, u, [f[1], -f[0]], s, t.id, e));
1785
+ o.push(...Rt(t.label, u, [d[1], -d[0]], r, t.id, e));
1333
1786
  } else
1334
- o.push(...Tt(t.label, l, f, s, t.id, e));
1787
+ o.push(...Rt(t.label, l, d, r, t.id, e));
1335
1788
  }
1336
1789
  return o;
1337
1790
  }
1338
- function wn(t, e) {
1339
- const n = st(e.values, t.transform), i = 4.5 * e.plane.scale, r = e.plane.toScreen([0, 0]), s = [], o = [
1791
+ function ii(t, e) {
1792
+ const n = ct(e.values, t.transform), i = 4.5 * e.plane.scale, s = e.plane.toScreen([0, 0]), r = [], o = [
1340
1793
  ["i", [1, 0], e.theme.colors.green, "\\hat{i}"],
1341
1794
  ["j", [0, 1], e.theme.colors.red, "\\hat{j}"]
1342
1795
  ];
1343
- for (const [l, c, f, u] of o) {
1344
- const h = B(n, c);
1345
- if (s.push(...Le(`${t.id}.${l}`, [0, 0], h, f, i, e)), t.labels !== !1 && e.draw >= 1) {
1346
- const d = e.plane.toScreen(h);
1347
- s.push(...Tt(u, d, Xt(d, r), f, `${t.id}.${l}`, e));
1796
+ for (const [l, c, d, u] of o) {
1797
+ const p = U(n, c);
1798
+ if (r.push(...an(`${t.id}.${l}`, [0, 0], p, d, i, e)), t.labels !== !1 && e.draw >= 1) {
1799
+ const h = e.plane.toScreen(p);
1800
+ r.push(...Rt(u, h, de(h, s), d, `${t.id}.${l}`, e));
1348
1801
  }
1349
1802
  }
1350
- return s;
1803
+ return r;
1351
1804
  }
1352
- function kn(t, e) {
1353
- const n = t.on !== void 0 ? [e.scope[`${t.id}.x`], e.scope[`${t.id}.y`]] : pt(e.values, t.at);
1805
+ function ri(t, e) {
1806
+ const n = t.on !== void 0 ? [e.scope[`${t.id}.x`], e.scope[`${t.id}.y`]] : $t(e.values, t.at);
1354
1807
  if (!Number.isFinite(n[0]) || !Number.isFinite(n[1])) return [];
1355
- const i = B(st(e.values, t.transform), n), [r, s] = e.plane.toScreen(i), o = F(e.theme, t.color, e.theme.colors.yellow), l = (t.radius ?? 6) * e.plane.scale * Math.min(1, e.draw * 2), c = t.hollow ? { type: "circle", id: t.id, x: r, y: s, r: l, fill: e.theme.background, stroke: o, width: 2.5 * e.plane.scale, opacity: e.opacity } : { type: "circle", id: t.id, x: r, y: s, r: l, fill: o, opacity: e.opacity }, f = l > 0 ? [c] : [];
1356
- return t.label && e.draw >= 1 && f.push(...Tt(t.label, [r, s], [0.7, -0.7], o, t.id, e)), f;
1357
- }
1358
- const Ot = 480;
1359
- function Ne(t, e) {
1360
- const n = [];
1361
- let i = [];
1362
- return t.forEach((r, s) => {
1363
- const o = t[s - 1];
1364
- (!r || o && Math.abs(r[1] - o[1]) > e * 1.5) && (i.length >= 2 && n.push(i), i = []), r && i.push(r);
1365
- }), i.length >= 2 && n.push(i), n;
1366
- }
1367
- function Fe(t, e) {
1368
- const n = Math.max(e.plane.width, e.plane.height) * 20;
1369
- if (!(!Number.isFinite(t[0]) || !Number.isFinite(t[1])))
1370
- return [Math.max(-n, Math.min(n, t[0])), Math.max(-n, Math.min(n, t[1]))];
1371
- }
1372
- function Ie(t, e, n, i, r, s) {
1373
- return et(e, r.draw).map((o, l) => ({ type: "line", id: `${t}.${l}`, points: o, stroke: n, width: i, opacity: r.opacity, ...s ? { dash: s } : {} }));
1374
- }
1375
- function Ce(t, e, n, i, r, s, o, l) {
1376
- const c = Array.from({ length: Ot + 1 }, (f, u) => {
1377
- const h = n + (i - n) * u / Ot;
1378
- return Fe(o.plane.toScreen([h, e(h)]), o);
1379
- });
1380
- return Ie(t, Ne(c, o.plane.height), r, s, o, l);
1381
- }
1382
- function $n(t, e) {
1383
- const n = t.derivative ? Yt(t.expr, t.derivative) : D(t.expr, "x"), [i, r] = t.domain ?? e.plane.x, s = F(e.theme, t.color, e.theme.colors.blue), o = t.dashed ? [10 * e.plane.scale, 8 * e.plane.scale] : void 0;
1384
- return Ce(t.id, (l) => n(l, e.scope), i, r, s, (t.width ?? 3.5) * e.plane.scale, e, o);
1385
- }
1386
- function xn(t, e) {
1387
- const n = D(t.x, "t"), i = D(t.y, "t"), r = st(e.values, t.transform), [s, o] = t.t ?? [0, Math.PI * 2], l = Array.from({ length: Ot + 1 }, (f, u) => {
1388
- const h = s + (o - s) * u / Ot;
1389
- return Fe(e.plane.toScreen(B(r, [n(h, e.scope), i(h, e.scope)])), e);
1390
- }), c = F(e.theme, t.color, e.theme.colors.blue);
1391
- return Ie(t.id, Ne(l, e.plane.height), c, (t.width ?? 3.5) * e.plane.scale, e);
1392
- }
1393
- const Mn = [[0, 0], [1, 0], [1, 1], [0, 1]];
1394
- function Sn(t, e) {
1395
- const n = st(e.values, t.transform), i = (t.points ?? Mn).map((l) => B(n, l)), r = i.map(e.plane.toScreen), s = F(e.theme, t.color, e.theme.colors.yellow), o = [
1396
- { type: "line", id: `${t.id}.fill`, points: r, closed: !0, fill: s, opacity: e.opacity * (t.fillOpacity ?? 0.3) * e.draw },
1397
- ...et([[...r, r[0]]], e.draw).map((l) => ({ type: "line", id: `${t.id}.outline`, points: l, stroke: s, width: 2.5 * e.plane.scale, opacity: e.opacity }))
1808
+ const i = U(ct(e.values, t.transform), n), [s, r] = e.plane.toScreen(i), o = E(e.theme, t.color, e.theme.colors.yellow), l = (t.radius ?? 6) * e.plane.scale * Math.min(1, e.draw * 2), c = t.hollow ? { type: "circle", id: t.id, x: s, y: r, r: l, fill: e.theme.background, stroke: o, width: 2.5 * e.plane.scale, opacity: e.opacity } : { type: "circle", id: t.id, x: s, y: r, r: l, fill: o, opacity: e.opacity }, d = l > 0 ? [c] : [];
1809
+ return t.label && e.draw >= 1 && d.push(...Rt(t.label, [s, r], [0.7, -0.7], o, t.id, e)), d;
1810
+ }
1811
+ const si = [[0, 0], [1, 0], [1, 1], [0, 1]];
1812
+ function oi(t, e) {
1813
+ const n = ct(e.values, t.transform), i = (t.points ?? si).map((l) => U(n, l)), s = i.map(e.plane.toScreen), r = E(e.theme, t.color, e.theme.colors.yellow), o = [
1814
+ { type: "line", id: `${t.id}.fill`, points: s, closed: !0, fill: r, opacity: e.opacity * (t.fillOpacity ?? 0.3) * e.draw },
1815
+ ...G([[...s, s[0]]], e.draw).map((l) => ({ type: "line", id: `${t.id}.outline`, points: l, stroke: r, width: 2.5 * e.plane.scale, opacity: e.opacity }))
1398
1816
  ];
1399
1817
  if (t.label && e.draw >= 1) {
1400
- const l = i.reduce((u, h) => [u[0] + h[0] / i.length, u[1] + h[1] / i.length], [0, 0]), [c, f] = e.plane.toScreen(l);
1401
- o.push(...vt(ut(t.label, { values: e.scope, style: "inline" }), { x: c, y: f, size: 24 * e.plane.scale, color: e.theme.ink, opacity: e.opacity, idPrefix: `${t.id}.label.` }));
1818
+ const l = i.reduce((u, p) => [u[0] + p[0] / i.length, u[1] + p[1] / i.length], [0, 0]), [c, d] = e.plane.toScreen(l);
1819
+ o.push(...yt(ut(t.label, { values: e.scope, style: "inline" }), { x: c, y: d, size: 24 * e.plane.scale, color: e.theme.ink, opacity: e.opacity, idPrefix: `${t.id}.label.` }));
1402
1820
  }
1403
1821
  return o;
1404
1822
  }
1405
- function En(t, e) {
1406
- const n = t.eigen ? ke(st(e.values, t.eigen)).map((o) => o.vector) : t.along !== void 0 ? [pt(e.values, t.along)] : [], i = Math.max(Math.abs(e.plane.x[0]), Math.abs(e.plane.x[1]), Math.abs(e.plane.y[0]), Math.abs(e.plane.y[1])) * 1.5, r = F(e.theme, t.color, e.theme.colors.yellow), s = (t.width ?? 2.5) * e.plane.scale;
1823
+ function ai(t, e) {
1824
+ const n = t.eigen ? Ve(ct(e.values, t.eigen)).map((o) => o.vector) : t.along !== void 0 ? [$t(e.values, t.along)] : [], i = Math.max(Math.abs(e.plane.x[0]), Math.abs(e.plane.x[1]), Math.abs(e.plane.y[0]), Math.abs(e.plane.y[1])) * 1.5, s = E(e.theme, t.color, e.theme.colors.yellow), r = (t.width ?? 2.5) * e.plane.scale;
1407
1825
  return n.flatMap((o, l) => {
1408
1826
  const c = Math.hypot(o[0], o[1]);
1409
1827
  if (c === 0) return [];
1410
- const f = qt(o, i / c), u = [qt(f, -1), f].map(e.plane.toScreen);
1411
- return et([u], e.draw).map((h) => ({
1828
+ const d = Jt(o, i / c), u = [Jt(d, -1), d].map(e.plane.toScreen);
1829
+ return G([u], e.draw).map((p) => ({
1412
1830
  type: "line",
1413
1831
  id: `${t.id}.${l}`,
1414
- points: h,
1415
- stroke: r,
1416
- width: s,
1832
+ points: p,
1833
+ stroke: s,
1834
+ width: r,
1417
1835
  opacity: e.opacity,
1418
1836
  ...t.dashed ? { dash: [10 * e.plane.scale, 8 * e.plane.scale] } : {}
1419
1837
  }));
1420
1838
  });
1421
1839
  }
1422
- function Ht(t, e, n, i) {
1423
- const r = n.size * 0.35;
1424
- let s = 1 / 0, o = 1 / 0, l = -1 / 0, c = -1 / 0;
1425
- for (const f of e) {
1426
- const [u, h] = Gt(f, n);
1427
- s = Math.min(s, u - r), l = Math.max(l, u + f.width * n.size + r), o = Math.min(o, h - f.height * n.size - r), c = Math.max(c, h + f.depth * n.size + r);
1840
+ function le(t, e, n, i) {
1841
+ const s = n.size * 0.35;
1842
+ let r = 1 / 0, o = 1 / 0, l = -1 / 0, c = -1 / 0;
1843
+ for (const d of e) {
1844
+ const [u, p] = fe(d, n);
1845
+ r = Math.min(r, u - s), l = Math.max(l, u + d.width * n.size + s), o = Math.min(o, p - d.height * n.size - s), c = Math.max(c, p + d.depth * n.size + s);
1428
1846
  }
1429
1847
  return [{
1430
1848
  type: "line",
1431
1849
  id: `${t}.backdrop`,
1432
- points: [[s, o], [l, o], [l, c], [s, c]],
1850
+ points: [[r, o], [l, o], [l, c], [r, c]],
1433
1851
  closed: !0,
1434
1852
  fill: i.theme.background,
1435
1853
  opacity: (n.opacity ?? 1) * 0.85
1436
1854
  }];
1437
1855
  }
1438
- function Pe(t, e, n) {
1439
- const i = pt(n.values, t);
1856
+ function ln(t, e, n) {
1857
+ const i = $t(n.values, t);
1440
1858
  return e ? i : n.plane.toScreen(i);
1441
1859
  }
1442
- function An(t, e) {
1443
- const [n, i] = Pe(t.at, t.screen, e), r = (t.size ?? 28) * e.plane.scale, s = F(e.theme, t.color, e.theme.ink), o = { x: n, y: i, size: r, color: s, align: t.align, opacity: e.opacity * e.draw, idPrefix: `${t.id}.` }, l = ut(t.tex, { values: e.scope });
1444
- return [...t.backdrop ?? t.screen ?? !1 ? Ht(t.id, [l], o, e) : [], ...vt(l, o)];
1860
+ function li(t, e) {
1861
+ const [n, i] = ln(t.at, t.screen, e), s = (t.size ?? 28) * e.plane.scale, r = E(e.theme, t.color, e.theme.ink), o = { x: n, y: i, size: s, color: r, align: t.align, opacity: e.opacity * e.draw, idPrefix: `${t.id}.` }, l = ut(t.tex, { values: e.scope });
1862
+ return [...t.backdrop ?? t.screen ?? !1 ? le(t.id, [l], o, e) : [], ...yt(l, o)];
1445
1863
  }
1446
- function Tn(t, e) {
1447
- const [n, i] = Pe(t.at, t.screen, e), r = (t.size ?? 36) * e.plane.scale, s = F(e.theme, t.color, e.theme.ink), o = t.steps.length - 1, l = Math.min(o, Math.max(0, e.prop("step") ?? t.step ?? 0)), c = Math.floor(l), f = l - c, u = { x: n, y: i, size: r, color: s, align: t.align, opacity: e.opacity * e.draw, idPrefix: `${t.id}.` }, h = (m) => ut(t.steps[m], { values: e.scope }), d = t.backdrop ?? t.screen ?? !1;
1448
- if (f === 0 || c >= o) {
1449
- const m = h(c);
1450
- return [...d ? Ht(t.id, [m], u, e) : [], ...vt(m, u)];
1864
+ function ci(t, e) {
1865
+ const [n, i] = ln(t.at, t.screen, e), s = (t.size ?? 36) * e.plane.scale, r = E(e.theme, t.color, e.theme.ink), o = t.steps.length - 1, l = Math.min(o, Math.max(0, e.prop("step") ?? t.step ?? 0)), c = Math.floor(l), d = l - c, u = { x: n, y: i, size: s, color: r, align: t.align, opacity: e.opacity * e.draw, idPrefix: `${t.id}.` }, p = (a) => ut(t.steps[a], { values: e.scope }), h = t.backdrop ?? t.screen ?? !1;
1866
+ if (d === 0 || c >= o) {
1867
+ const a = p(c);
1868
+ return [...h ? le(t.id, [a], u, e) : [], ...yt(a, u)];
1451
1869
  }
1452
- const y = (m) => {
1453
- const [b, w] = Gt(m, u);
1454
- return { layout: m, x: b / r, y: w / r };
1455
- }, a = h(c), p = h(c + 1);
1870
+ const m = (a) => {
1871
+ const [g, w] = fe(a, u);
1872
+ return { layout: a, x: g / s, y: w / s };
1873
+ }, f = p(c), y = p(c + 1);
1456
1874
  return [
1457
- ...d ? Ht(t.id, [a, p], u, e) : [],
1458
- ...Oe(pn(y(a), y(p), f), [0, 0], u)
1875
+ ...h ? le(t.id, [f, y], u, e) : [],
1876
+ ...Ke(Kn(m(f), m(y), d), [0, 0], u)
1459
1877
  ];
1460
1878
  }
1461
- function On(t, e) {
1462
- const n = D(t.expr), i = N(e.values, t.at), r = t.h === void 0 ? 0 : N(e.values, t.h), s = n(i, e.scope), o = e.scope[`${t.id}.slope`];
1463
- if (!Number.isFinite(s) || !Number.isFinite(o)) return [];
1464
- const l = t.length !== void 0 ? t.length / 2 : Math.max(Math.abs(e.plane.x[0] - i), Math.abs(e.plane.x[1] - i)), c = [[i - l, s - o * l], [i + l, s + o * l]], f = F(e.theme, t.color, e.theme.colors.yellow), u = e.plane.toScreen([i, s]), h = c.map(e.plane.toScreen), d = [h[0], h[1]].flatMap(
1465
- (y, a) => et([[u, y]], e.draw).map((p) => ({ type: "line", id: `${t.id}.${a}`, points: p, stroke: f, width: (t.width ?? 3) * e.plane.scale, opacity: e.opacity }))
1879
+ function ui(t, e) {
1880
+ const n = R(t.expr), i = S(e.values, t.at), s = t.h === void 0 ? 0 : S(e.values, t.h), r = n(i, e.scope), o = e.scope[`${t.id}.slope`];
1881
+ if (!Number.isFinite(r) || !Number.isFinite(o)) return [];
1882
+ const l = t.length !== void 0 ? t.length / 2 : Math.max(Math.abs(e.plane.x[0] - i), Math.abs(e.plane.x[1] - i)), c = [[i - l, r - o * l], [i + l, r + o * l]], d = E(e.theme, t.color, e.theme.colors.yellow), u = e.plane.toScreen([i, r]), p = c.map(e.plane.toScreen), h = [p[0], p[1]].flatMap(
1883
+ (m, f) => G([[u, m]], e.draw).map((y) => ({ type: "line", id: `${t.id}.${f}`, points: y, stroke: d, width: (t.width ?? 3) * e.plane.scale, opacity: e.opacity }))
1466
1884
  );
1467
1885
  if (t.points !== !1) {
1468
- const y = 6 * e.plane.scale;
1469
- if (d.push({ type: "circle", id: `${t.id}.point`, x: u[0], y: u[1], r: y, fill: f, opacity: e.opacity }), Math.abs(r) > 1e-9) {
1470
- const [a, p] = e.plane.toScreen([i + r, n(i + r, e.scope)]);
1471
- Number.isFinite(p) && d.push({ type: "circle", id: `${t.id}.secant`, x: a, y: p, r: y, fill: f, opacity: e.opacity });
1886
+ const m = 6 * e.plane.scale;
1887
+ if (h.push({ type: "circle", id: `${t.id}.point`, x: u[0], y: u[1], r: m, fill: d, opacity: e.opacity }), Math.abs(s) > 1e-9) {
1888
+ const [f, y] = e.plane.toScreen([i + s, n(i + s, e.scope)]);
1889
+ Number.isFinite(y) && h.push({ type: "circle", id: `${t.id}.secant`, x: f, y, r: m, fill: d, opacity: e.opacity });
1472
1890
  }
1473
1891
  }
1474
1892
  if (t.label && e.draw >= 1) {
1475
- const y = 24 * e.plane.scale, a = ut(t.label, { values: e.scope, style: "inline" });
1476
- d.push(...vt(a, { x: u[0], y: u[1] - y * 1.6, size: y, color: f, opacity: e.opacity, idPrefix: `${t.id}.label.` }));
1893
+ const m = 24 * e.plane.scale, f = ut(t.label, { values: e.scope, style: "inline" });
1894
+ h.push(...yt(f, { x: u[0], y: u[1] - m * 1.6, size: m, color: d, opacity: e.opacity, idPrefix: `${t.id}.label.` }));
1477
1895
  }
1478
- return d;
1896
+ return h;
1479
1897
  }
1480
- function Ln(t, e) {
1481
- const n = D(t.expr), i = N(e.values, t.from), r = N(e.values, t.to), s = Me(N(e.values, t.n)), o = xe((u) => n(u, e.scope), i, r, s, t.rule ?? "left"), l = F(e.theme, t.color, e.theme.colors.blue), c = Math.ceil(o.length * e.draw), f = Math.max(0.5, Math.min(1.5, 60 / s)) * e.plane.scale;
1482
- return o.slice(0, c).flatMap(([u, h, d, y], a) => {
1483
- if (!Number.isFinite(d) || !Number.isFinite(y)) return [];
1484
- const p = [[u, 0], [h, 0], [h, y], [u, d]].map(e.plane.toScreen), b = (d + y) / 2 < 0 ? F(e.theme, "red", e.theme.colors.red) : l;
1485
- return [{ type: "line", id: `${t.id}.${a}`, points: p, closed: !0, fill: b, stroke: b, width: f, opacity: e.opacity * (t.fillOpacity ?? 0.35) }];
1898
+ function di(t, e) {
1899
+ const n = R(t.expr), i = S(e.values, t.from), s = S(e.values, t.to), r = rn(S(e.values, t.n)), o = nn((u) => n(u, e.scope), i, s, r, t.rule ?? "left"), l = E(e.theme, t.color, e.theme.colors.blue), c = Math.ceil(o.length * e.draw), d = Math.max(0.5, Math.min(1.5, 60 / r)) * e.plane.scale;
1900
+ return o.slice(0, c).flatMap(([u, p, h, m], f) => {
1901
+ if (!Number.isFinite(h) || !Number.isFinite(m)) return [];
1902
+ const y = [[u, 0], [p, 0], [p, m], [u, h]].map(e.plane.toScreen), g = (h + m) / 2 < 0 ? E(e.theme, "red", e.theme.colors.red) : l;
1903
+ return [{ type: "line", id: `${t.id}.${f}`, points: y, closed: !0, fill: g, stroke: g, width: d, opacity: e.opacity * (t.fillOpacity ?? 0.35) }];
1486
1904
  });
1487
1905
  }
1488
- function Nn(t, e) {
1489
- const n = D(t.expr), i = t.lower ? D(t.lower) : () => 0, r = N(e.values, t.from), s = r + (N(e.values, t.to) - r) * e.draw;
1490
- if (r === s) return [];
1491
- const o = 240, l = F(e.theme, t.color, e.theme.colors.blue), c = F(e.theme, t.negativeColor, e.theme.colors.red), f = e.opacity * (t.fillOpacity ?? 0.4), u = [];
1492
- let h = [], d = [], y;
1493
- const a = () => {
1494
- h.length >= 2 && u.push({ type: "line", id: `${t.id}.${u.length}`, points: [...h, ...d.reverse()].map(e.plane.toScreen), closed: !0, fill: y ? l : c, opacity: f }), h = [], d = [];
1906
+ function hi(t, e) {
1907
+ const n = R(t.expr), i = t.lower ? R(t.lower) : () => 0, s = S(e.values, t.from), r = s + (S(e.values, t.to) - s) * e.draw;
1908
+ if (s === r) return [];
1909
+ const o = 240, l = E(e.theme, t.color, e.theme.colors.blue), c = E(e.theme, t.negativeColor, e.theme.colors.red), d = e.opacity * (t.fillOpacity ?? 0.4), u = [];
1910
+ let p = [], h = [], m;
1911
+ const f = () => {
1912
+ p.length >= 2 && u.push({ type: "line", id: `${t.id}.${u.length}`, points: [...p, ...h.reverse()].map(e.plane.toScreen), closed: !0, fill: m ? l : c, opacity: d }), p = [], h = [];
1495
1913
  };
1496
- let p;
1497
- for (let m = 0; m <= o; m++) {
1498
- const b = r + (s - r) * m / o, w = n(b, e.scope), $ = i(b, e.scope);
1499
- if (!Number.isFinite(w) || !Number.isFinite($)) {
1500
- a(), p = void 0;
1914
+ let y;
1915
+ for (let a = 0; a <= o; a++) {
1916
+ const g = s + (r - s) * a / o, w = n(g, e.scope), M = i(g, e.scope);
1917
+ if (!Number.isFinite(w) || !Number.isFinite(M)) {
1918
+ f(), y = void 0;
1501
1919
  continue;
1502
1920
  }
1503
- const g = w - $ >= 0;
1504
- if (p && y !== void 0 && g !== y) {
1505
- const k = p.fy - p.gy, v = w - $, x = k / (k - v), M = p.x + (b - p.x) * x, T = p.gy + ($ - p.gy) * x;
1506
- h.push([M, T]), d.push([M, T]), a(), h.push([M, T]), d.push([M, T]);
1921
+ const v = w - M >= 0;
1922
+ if (y && m !== void 0 && v !== m) {
1923
+ const b = y.fy - y.gy, k = w - M, $ = b / (b - k), x = y.x + (g - y.x) * $, T = y.gy + (M - y.gy) * $;
1924
+ p.push([x, T]), h.push([x, T]), f(), p.push([x, T]), h.push([x, T]);
1507
1925
  }
1508
- y = g, h.push([b, w]), d.push([b, $]), p = { x: b, fy: w, gy: $ };
1926
+ m = v, p.push([g, w]), h.push([g, M]), y = { x: g, fy: w, gy: M };
1509
1927
  }
1510
- return a(), u;
1928
+ return f(), u;
1511
1929
  }
1512
- const Fn = Array.from({ length: 22 }, (t, e) => e).map((t) => t === 0 ? 1 : Array.from({ length: t }, (e, n) => n + 1).reduce((e, n) => e * n, 1));
1513
- function In(t, e) {
1514
- const n = N(e.values, t.at), i = e.scope[`${t.id}.order`], r = Math.floor(i), s = i - r, o = Array.from({ length: Math.min(20, r + 1) + 1 }, (h, d) => Yt(t.expr, d)(n, e.scope) / Fn[d]), l = (h) => {
1515
- let d = 0, y = 1;
1516
- for (let a = 0; a <= r; a++)
1517
- d += o[a] * y, y *= h - n;
1518
- return s > 0 && r < 20 ? d + s * o[r + 1] * y : d;
1519
- }, c = F(e.theme, t.color, e.theme.colors.yellow), [f, u] = t.domain ?? e.plane.x;
1520
- return Ce(t.id, (h) => l(h), f, u, c, (t.width ?? 3.5) * e.plane.scale, e);
1930
+ const pi = Array.from({ length: 22 }, (t, e) => e).map((t) => t === 0 ? 1 : Array.from({ length: t }, (e, n) => n + 1).reduce((e, n) => e * n, 1));
1931
+ function fi(t, e) {
1932
+ const n = S(e.values, t.at), i = e.scope[`${t.id}.order`], s = Math.floor(i), r = i - s, o = Array.from({ length: Math.min(20, s + 1) + 1 }, (p, h) => he(t.expr, h)(n, e.scope) / pi[h]), l = (p) => {
1933
+ let h = 0, m = 1;
1934
+ for (let f = 0; f <= s; f++)
1935
+ h += o[f] * m, m *= p - n;
1936
+ return r > 0 && s < 20 ? h + r * o[s + 1] * m : h;
1937
+ }, c = E(e.theme, t.color, e.theme.colors.yellow), [d, u] = t.domain ?? e.plane.x;
1938
+ return Vt(t.id, (p) => l(p), d, u, c, (t.width ?? 3.5) * e.plane.scale, e);
1521
1939
  }
1522
- function Cn(t, e) {
1940
+ function mi(t, e) {
1523
1941
  switch (t.kind) {
1524
1942
  case "grid":
1525
- return gn(t, e);
1943
+ return ti(t, e);
1526
1944
  case "axes":
1527
- return bn(t, e);
1945
+ return ei(t, e);
1528
1946
  case "vector":
1529
- return vn(t, e);
1947
+ return ni(t, e);
1530
1948
  case "basis":
1531
- return wn(t, e);
1949
+ return ii(t, e);
1532
1950
  case "point":
1533
- return kn(t, e);
1951
+ return ri(t, e);
1534
1952
  case "function":
1535
- return $n(t, e);
1953
+ return Vn(t, e);
1536
1954
  case "parametric":
1537
- return xn(t, e);
1955
+ return Bn(t, e);
1538
1956
  case "polygon":
1539
- return Sn(t, e);
1957
+ return oi(t, e);
1540
1958
  case "line":
1541
- return En(t, e);
1959
+ return ai(t, e);
1542
1960
  case "label":
1543
- return An(t, e);
1961
+ return li(t, e);
1544
1962
  case "equation":
1545
- return Tn(t, e);
1963
+ return ci(t, e);
1546
1964
  case "tangent":
1547
- return On(t, e);
1965
+ return ui(t, e);
1548
1966
  case "riemann":
1549
- return Ln(t, e);
1967
+ return di(t, e);
1550
1968
  case "area":
1551
- return Nn(t, e);
1969
+ return hi(t, e);
1552
1970
  case "taylor":
1553
- return In(t, e);
1554
- }
1555
- }
1556
- const pe = (t) => Math.min(1, Math.max(0, t));
1557
- function Lt(t, e = {}) {
1558
- const n = Ut[t.theme ?? "dark"], i = Te(t), r = { ...t.values }, s = /* @__PURE__ */ new Map();
1559
- for (const [u, h] of Object.entries(e))
1560
- u.indexOf(".") < 0 ? typeof h != "string" && (r[u] = h) : typeof h == "number" && s.set(u, h);
1561
- const o = $e(r), l = { ...o, ...Se(t.items, r, o) }, c = [];
1971
+ return fi(t, e);
1972
+ case "histogram":
1973
+ return Wn(t, e);
1974
+ case "distribution":
1975
+ return Un(t, e);
1976
+ case "galton":
1977
+ return Hn(t, e);
1978
+ case "scatter":
1979
+ return Xn(t, e);
1980
+ case "bayes":
1981
+ return Yn(t, e);
1982
+ }
1983
+ }
1984
+ const Fe = (t) => Math.min(1, Math.max(0, t));
1985
+ function Bt(t, e = {}) {
1986
+ const n = ae[t.theme ?? "dark"], i = on(t), s = { ...t.values }, r = /* @__PURE__ */ new Map();
1987
+ for (const [u, p] of Object.entries(e))
1988
+ u.indexOf(".") < 0 ? typeof p != "string" && (s[u] = p) : typeof p == "number" && r.set(u, p);
1989
+ const o = Be(s), l = { ...o, ...sn(t.items, s, o) }, c = [];
1562
1990
  for (const u of t.items) {
1563
- const h = (a) => s.get(`${u.id}.${a}`), d = pe(h("draw") ?? u.draw ?? 1), y = pe(h("opacity") ?? u.opacity ?? 1);
1564
- d <= 0 || y <= 0 || c.push(...Cn(u, { plane: i, theme: n, values: r, scope: l, draw: d, opacity: y, prop: h }));
1991
+ const p = (f) => r.get(`${u.id}.${f}`), h = Fe(p("draw") ?? u.draw ?? 1), m = Fe(p("opacity") ?? u.opacity ?? 1);
1992
+ h <= 0 || m <= 0 || c.push(...mi(u, { plane: i, theme: n, values: s, scope: l, draw: h, opacity: m, prop: p }));
1565
1993
  }
1566
- const f = t.background === "none" ? void 0 : t.background ?? n.background;
1567
- return { width: t.width, height: t.height, ...f ? { background: f } : {}, shapes: c };
1994
+ const d = t.background === "none" ? void 0 : t.background ?? n.background;
1995
+ return { width: t.width, height: t.height, ...d ? { background: d } : {}, shapes: c };
1568
1996
  }
1569
- function qe(t, e) {
1997
+ function cn(t, e) {
1570
1998
  if (t.length < 2) return { shaft: t, head: void 0 };
1571
- const n = t[t.length - 1], i = t[t.length - 2], r = n[0] - i[0], s = n[1] - i[1], o = Math.hypot(r, s);
1999
+ const n = t[t.length - 1], i = t[t.length - 2], s = n[0] - i[0], r = n[1] - i[1], o = Math.hypot(s, r);
1572
2000
  if (o === 0 || e <= 0) return { shaft: t, head: void 0 };
1573
- const l = r / o, c = s / o, f = Math.min(e, o), u = [n[0] - l * f, n[1] - c * f], h = f * 0.55;
2001
+ const l = s / o, c = r / o, d = Math.min(e, o), u = [n[0] - l * d, n[1] - c * d], p = d * 0.55;
1574
2002
  return {
1575
2003
  shaft: [...t.slice(0, -1), u],
1576
- head: [n, [u[0] - c * h, u[1] + l * h], [u[0] + c * h, u[1] - l * h]]
2004
+ head: [n, [u[0] - c * p, u[1] + l * p], [u[0] + c * p, u[1] - l * p]]
1577
2005
  };
1578
2006
  }
1579
- function It(t, e, n = !1) {
1580
- t.beginPath(), e.forEach(([i, r], s) => s === 0 ? t.moveTo(i, r) : t.lineTo(i, r)), n && t.closePath();
2007
+ function Zt(t, e, n = !1) {
2008
+ t.beginPath(), e.forEach(([i, s], r) => r === 0 ? t.moveTo(i, s) : t.lineTo(i, s)), n && t.closePath();
1581
2009
  }
1582
- function Pn(t, e) {
2010
+ function yi(t, e) {
1583
2011
  switch (t.globalAlpha = e.opacity ?? 1, e.type) {
1584
2012
  case "line":
1585
2013
  if (e.points.length < 2) return;
1586
- It(t, e.points, e.closed), e.fill && (t.fillStyle = e.fill, t.fill()), e.stroke && (e.width ?? 1) > 0 && (t.strokeStyle = e.stroke, t.lineWidth = e.width ?? 1, t.setLineDash(e.dash ?? []), t.stroke(), t.setLineDash([]));
2014
+ Zt(t, e.points, e.closed), e.fill && (t.fillStyle = e.fill, t.fill()), e.stroke && (e.width ?? 1) > 0 && (t.strokeStyle = e.stroke, t.lineWidth = e.width ?? 1, t.setLineDash(e.dash ?? []), t.stroke(), t.setLineDash([]));
1587
2015
  return;
1588
2016
  case "arrow": {
1589
- const { shaft: n, head: i } = qe(e.points, e.head);
1590
- t.strokeStyle = e.stroke, t.fillStyle = e.stroke, t.lineWidth = e.width, n.length >= 2 && (It(t, n), t.stroke()), i && (It(t, i, !0), t.fill());
2017
+ const { shaft: n, head: i } = cn(e.points, e.head);
2018
+ t.strokeStyle = e.stroke, t.fillStyle = e.stroke, t.lineWidth = e.width, n.length >= 2 && (Zt(t, n), t.stroke()), i && (Zt(t, i, !0), t.fill());
1591
2019
  return;
1592
2020
  }
1593
2021
  case "circle":
@@ -1597,53 +2025,53 @@ function Pn(t, e) {
1597
2025
  t.font = `${e.italic ? "italic " : ""}${e.size}px ${e.font}`, t.textAlign = e.align, t.textBaseline = "alphabetic", t.fillStyle = e.color, t.fillText(e.text, e.x, e.y);
1598
2026
  }
1599
2027
  }
1600
- function qn(t, e) {
2028
+ function gi(t, e) {
1601
2029
  t.save(), t.beginPath(), t.rect(0, 0, e.width, e.height), t.clip(), e.background && (t.fillStyle = e.background, t.fillRect(0, 0, e.width, e.height)), t.lineCap = "round", t.lineJoin = "round";
1602
- for (const n of e.shapes) Pn(t, n);
2030
+ for (const n of e.shapes) yi(t, n);
1603
2031
  t.restore();
1604
2032
  }
1605
- const L = (t) => String(Math.round(t * 100) / 100), W = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), Ct = (t, e = !1) => t.map(([n, i], r) => `${r ? "L" : "M"}${L(n)} ${L(i)}`).join("") + (e ? "Z" : ""), xt = (t) => t.opacity !== void 0 && t.opacity < 1 ? ` opacity="${L(t.opacity)}"` : "";
1606
- function zn(t) {
2033
+ const L = (t) => String(Math.round(t * 100) / 100), W = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), Gt = (t, e = !1) => t.map(([n, i], s) => `${s ? "L" : "M"}${L(n)} ${L(i)}`).join("") + (e ? "Z" : ""), It = (t) => t.opacity !== void 0 && t.opacity < 1 ? ` opacity="${L(t.opacity)}"` : "";
2034
+ function bi(t) {
1607
2035
  switch (t.type) {
1608
2036
  case "line": {
1609
2037
  if (t.points.length < 2) return "";
1610
2038
  const e = t.fill ? ` fill="${W(t.fill)}"` : ' fill="none"', n = t.stroke && (t.width ?? 1) > 0 ? ` stroke="${W(t.stroke)}" stroke-width="${L(t.width ?? 1)}"` : "", i = t.dash?.length ? ` stroke-dasharray="${t.dash.map(L).join(" ")}"` : "";
1611
- return `<path d="${Ct(t.points, t.closed)}"${e}${n}${i}${xt(t)}/>`;
2039
+ return `<path d="${Gt(t.points, t.closed)}"${e}${n}${i}${It(t)}/>`;
1612
2040
  }
1613
2041
  case "arrow": {
1614
- const { shaft: e, head: n } = qe(t.points, t.head), i = W(t.stroke), r = e.length >= 2 ? `<path d="${Ct(e)}" fill="none" stroke="${i}" stroke-width="${L(t.width)}"/>` : "", s = n ? `<path d="${Ct(n, !0)}" fill="${i}"/>` : "";
1615
- return `<g${xt(t)}>${r}${s}</g>`;
2042
+ const { shaft: e, head: n } = cn(t.points, t.head), i = W(t.stroke), s = e.length >= 2 ? `<path d="${Gt(e)}" fill="none" stroke="${i}" stroke-width="${L(t.width)}"/>` : "", r = n ? `<path d="${Gt(n, !0)}" fill="${i}"/>` : "";
2043
+ return `<g${It(t)}>${s}${r}</g>`;
1616
2044
  }
1617
2045
  case "circle": {
1618
2046
  const e = t.fill ? ` fill="${W(t.fill)}"` : ' fill="none"', n = t.stroke ? ` stroke="${W(t.stroke)}" stroke-width="${L(t.width ?? 1)}"` : "";
1619
- return `<circle cx="${L(t.x)}" cy="${L(t.y)}" r="${L(t.r)}"${e}${n}${xt(t)}/>`;
2047
+ return `<circle cx="${L(t.x)}" cy="${L(t.y)}" r="${L(t.r)}"${e}${n}${It(t)}/>`;
1620
2048
  }
1621
2049
  case "text": {
1622
2050
  const e = t.align === "center" ? "middle" : t.align === "right" ? "end" : "start", n = t.italic ? ' font-style="italic"' : "";
1623
- return `<text x="${L(t.x)}" y="${L(t.y)}" font-size="${L(t.size)}" font-family="${W(t.font)}"${n} text-anchor="${e}" fill="${W(t.color)}"${xt(t)}>${W(t.text)}</text>`;
2051
+ return `<text x="${L(t.x)}" y="${L(t.y)}" font-size="${L(t.size)}" font-family="${W(t.font)}"${n} text-anchor="${e}" fill="${W(t.color)}"${It(t)}>${W(t.text)}</text>`;
1624
2052
  }
1625
2053
  }
1626
2054
  }
1627
- function Kt(t) {
1628
- return `${t.background ? `<rect width="${L(t.width)}" height="${L(t.height)}" fill="${W(t.background)}"/>` : ""}<g stroke-linecap="round" stroke-linejoin="round">${t.shapes.map(zn).join("")}</g>`;
2055
+ function ye(t) {
2056
+ return `${t.background ? `<rect width="${L(t.width)}" height="${L(t.height)}" fill="${W(t.background)}"/>` : ""}<g stroke-linecap="round" stroke-linejoin="round">${t.shapes.map(bi).join("")}</g>`;
1629
2057
  }
1630
- function jn(t, e = {}) {
2058
+ function vi(t, e = {}) {
1631
2059
  const n = e.title ? `<title>${W(e.title)}</title>` : "", i = e.title ? ` role="img" aria-label="${W(e.title)}"` : "";
1632
- return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${L(t.width)} ${L(t.height)}" width="${L(t.width)}" height="${L(t.height)}"${i}>${n}${Kt(t)}</svg>`;
2060
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${L(t.width)} ${L(t.height)}" width="${L(t.width)}" height="${L(t.height)}"${i}>${n}${ye(t)}</svg>`;
1633
2061
  }
1634
- function Dn(t) {
2062
+ function wi(t) {
1635
2063
  const e = {};
1636
2064
  for (const [n, i] of Object.entries(t.values ?? {})) {
1637
- const r = typeof i == "number" ? "number" : i.length === 2 ? "[x, y] vector" : "[a, b, c, d] matrix";
1638
- e[n] = { description: `The value ${n} (a ${r})`, kind: typeof i == "number" ? "number" : "list" };
2065
+ const s = typeof i == "number" ? "number" : i.length === 2 ? "[x, y] vector" : "[a, b, c, d] matrix";
2066
+ e[n] = { description: `The value ${n} (a ${s})`, kind: typeof i == "number" ? "number" : "list" };
1639
2067
  }
1640
2068
  for (const n of t.items)
1641
2069
  e[`${n.id}.draw`] = { description: `How much of the ${n.kind} "${n.id}" is drawn`, unit: "0..1", min: 0, max: 1 }, e[`${n.id}.opacity`] = { description: `Opacity of the ${n.kind} "${n.id}"`, unit: "0..1", min: 0, max: 1 }, n.kind === "equation" && (e[`${n.id}.step`] = { description: `Which step of "${n.id}" shows; in between, terms glide`, unit: "step", min: 0, max: n.steps.length - 1 });
1642
2070
  return e;
1643
2071
  }
1644
- function pi(t, e = {}) {
1645
- bt(t);
1646
- const n = Dn(t), i = { ...t.values ?? {} };
2072
+ function Zi(t, e = {}) {
2073
+ Tt(t);
2074
+ const n = wi(t), i = { ...t.values ?? {} };
1647
2075
  return {
1648
2076
  type: "custom",
1649
2077
  x: e.x ?? 0,
@@ -1651,52 +2079,52 @@ function pi(t, e = {}) {
1651
2079
  width: t.width,
1652
2080
  height: t.height,
1653
2081
  props: i,
1654
- acceptsProp: (r) => Object.prototype.hasOwnProperty.call(n, r),
1655
- draw(r, s) {
1656
- qn(r, Lt(t, s.props ?? {}));
2082
+ acceptsProp: (s) => Object.prototype.hasOwnProperty.call(n, s),
2083
+ draw(s, r) {
2084
+ gi(s, Bt(t, r.props ?? {}));
1657
2085
  },
1658
2086
  about: {
1659
2087
  kind: "math figure",
1660
- summary: `A ${t.width}×${t.height} maths figure with ${t.items.map((r) => `${r.kind} "${r.id}"`).join(", ")}. Animate its values by name and each item's draw / opacity (an equation's step).`,
2088
+ summary: `A ${t.width}×${t.height} maths figure with ${t.items.map((s) => `${s.kind} "${s.id}"`).join(", ")}. Animate its values by name and each item's draw / opacity (an equation's step).`,
1661
2089
  props: n
1662
2090
  }
1663
2091
  };
1664
2092
  }
1665
- function mi(t, e, n, i = {}) {
1666
- const r = new Set(n.items.map((c) => c.id)), s = (c) => {
1667
- if (!r.has(c)) throw new Error(`mathSteps: no item "${c}" (items: ${[...r].join(", ")})`);
2093
+ function Gi(t, e, n, i = {}) {
2094
+ const s = new Set(n.items.map((c) => c.id)), r = (c) => {
2095
+ if (!s.has(c)) throw new Error(`mathSteps: no item "${c}" (items: ${[...s].join(", ")})`);
1668
2096
  }, o = { ...n.values ?? {} };
1669
2097
  for (const c of n.items)
1670
2098
  o[`${c.id}.draw`] = c.draw ?? 1, o[`${c.id}.opacity`] = c.opacity ?? 1, c.kind === "equation" && (o[`${c.id}.step`] = c.step ?? 0);
1671
2099
  for (const c of i.hidden ?? [])
1672
- s(c), o[`${c}.draw`] = 0;
2100
+ r(c), o[`${c}.draw`] = 0;
1673
2101
  t.initial(e, o);
1674
2102
  const l = {
1675
- toValue(c, f, u) {
2103
+ toValue(c, d, u) {
1676
2104
  if (!(c in o)) throw new Error(`mathSteps: no value "${c}" (values: ${Object.keys(n.values ?? {}).join(", ")})`);
1677
- return t.to(e, { [c]: f }, { duration: 1200, ...u }), l;
2105
+ return t.to(e, { [c]: d }, { duration: 1200, ...u }), l;
1678
2106
  },
1679
- applyMatrix(c, f = {}) {
1680
- const { name: u = "M", ...h } = f;
2107
+ applyMatrix(c, d = {}) {
2108
+ const { name: u = "M", ...p } = d;
1681
2109
  if (c.length !== 4 || !c.every(Number.isFinite)) throw new Error("mathSteps.applyMatrix: expected [a, b, c, d]");
1682
- return l.toValue(u, c, { duration: 1600, ...h });
2110
+ return l.toValue(u, c, { duration: 1600, ...p });
1683
2111
  },
1684
- drawOn(c, f) {
1685
- return s(c), t.to(e, { [`${c}.draw`]: 1 }, { duration: 900, ...f }), l;
2112
+ drawOn(c, d) {
2113
+ return r(c), t.to(e, { [`${c}.draw`]: 1 }, { duration: 900, ...d }), l;
1686
2114
  },
1687
- fadeIn(c, f) {
1688
- return s(c), t.set(e, { [`${c}.draw`]: 1, [`${c}.opacity`]: 0 }), t.to(e, { [`${c}.opacity`]: 1 }, { duration: 500, ...f }), l;
2115
+ fadeIn(c, d) {
2116
+ return r(c), t.set(e, { [`${c}.draw`]: 1, [`${c}.opacity`]: 0 }), t.to(e, { [`${c}.opacity`]: 1 }, { duration: 500, ...d }), l;
1689
2117
  },
1690
- fadeOut(c, f) {
1691
- return s(c), t.to(e, { [`${c}.opacity`]: 0 }, { duration: 500, ...f }), l;
2118
+ fadeOut(c, d) {
2119
+ return r(c), t.to(e, { [`${c}.opacity`]: 0 }, { duration: 500, ...d }), l;
1692
2120
  },
1693
- showStep(c, f, u) {
1694
- return s(c), t.to(e, { [`${c}.step`]: f }, { duration: 900, ...u }), l;
2121
+ showStep(c, d, u) {
2122
+ return r(c), t.to(e, { [`${c}.step`]: d }, { duration: 900, ...u }), l;
1695
2123
  }
1696
2124
  };
1697
2125
  return l;
1698
2126
  }
1699
- class me {
2127
+ class qe {
1700
2128
  media;
1701
2129
  offset;
1702
2130
  driftTolerance;
@@ -1735,15 +2163,15 @@ class me {
1735
2163
  });
1736
2164
  }
1737
2165
  }
1738
- function _n(t, e, n, i, r) {
1739
- const s = n - r;
1740
- if (s < 0) {
2166
+ function ki(t, e, n, i, s) {
2167
+ const r = n - s;
2168
+ if (r < 0) {
1741
2169
  e.paused || e.pause(), e.currentTime = 0;
1742
2170
  return;
1743
2171
  }
1744
- t.update(s, i);
2172
+ t.update(r, i);
1745
2173
  }
1746
- class Rn {
2174
+ class $i {
1747
2175
  container;
1748
2176
  timeline = null;
1749
2177
  adapter;
@@ -1782,7 +2210,7 @@ class Rn {
1782
2210
  this.container = i;
1783
2211
  } else
1784
2212
  this.container = e;
1785
- this.options = n, this.adapter = new re();
2213
+ this.options = n, this.adapter = new $e();
1786
2214
  }
1787
2215
  /**
1788
2216
  * Load animation from a URL or JSON object.
@@ -1808,7 +2236,7 @@ class Rn {
1808
2236
  */
1809
2237
  useDefinition(e) {
1810
2238
  const n = { ...e.config };
1811
- this.options.speed !== void 0 && (n.speed = this.options.speed), this.options.loop !== void 0 && (n.loop = this.options.loop), this.options.alternate !== void 0 && (n.alternate = this.options.alternate), this.timeline = ie({ ...e, config: n }), this.markerList = this.timeline.markers, this.lastMarkerId = null, this.options.onComplete && (this.timeline.onComplete = this.options.onComplete), this.options.onUpdate && (this.timeline.onUpdate = this.options.onUpdate), this.autoRegisterTargets(), this.setupSymbolInstances(), this.scanMedia();
2239
+ this.options.speed !== void 0 && (n.speed = this.options.speed), this.options.loop !== void 0 && (n.loop = this.options.loop), this.options.alternate !== void 0 && (n.alternate = this.options.alternate), this.timeline = ke({ ...e, config: n }), this.markerList = this.timeline.markers, this.lastMarkerId = null, this.options.onComplete && (this.timeline.onComplete = this.options.onComplete), this.options.onUpdate && (this.timeline.onUpdate = this.options.onUpdate), this.autoRegisterTargets(), this.setupSymbolInstances(), this.scanMedia();
1812
2240
  }
1813
2241
  // --- scenarios: the reader chooses which timeline plays --------------------
1814
2242
  /**
@@ -1819,13 +2247,13 @@ class Rn {
1819
2247
  async loadScenarios(e, n = {}) {
1820
2248
  if (e.length === 0) throw new Error("tinyfly: loadScenarios needs at least one scenario");
1821
2249
  const i = /* @__PURE__ */ new Set();
1822
- for (const s of e) {
1823
- if (i.has(s.id)) throw new Error(`tinyfly: scenario id "${s.id}" is used more than once`);
1824
- i.add(s.id);
2250
+ for (const r of e) {
2251
+ if (i.has(r.id)) throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);
2252
+ i.add(r.id);
1825
2253
  }
1826
- const r = n.initial === void 0 ? e[0] : e.find((s) => s.id === n.initial);
1827
- if (!r) throw new Error(`tinyfly: there is no scenario "${n.initial}"`);
1828
- this.scenarioList = [...e], this.scenarioId = r.id, await this.loadSource(r.timeline);
2254
+ const s = n.initial === void 0 ? e[0] : e.find((r) => r.id === n.initial);
2255
+ if (!s) throw new Error(`tinyfly: there is no scenario "${n.initial}"`);
2256
+ this.scenarioList = [...e], this.scenarioId = s.id, await this.loadSource(s.timeline);
1829
2257
  }
1830
2258
  /** The scenarios to choose from (empty for a single timeline). */
1831
2259
  get scenarios() {
@@ -1846,10 +2274,10 @@ class Rn {
1846
2274
  const n = this.scenarioList.find((l) => l.id === e);
1847
2275
  if (!n || !this.timeline) return !1;
1848
2276
  if (e === this.scenarioId) return !0;
1849
- const i = this.isPlaying, r = this.currentTime >= this.duration - 0.5, s = this.currentMarker?.id;
2277
+ const i = this.isPlaying, s = this.currentTime >= this.duration - 0.5, r = this.currentMarker?.id;
1850
2278
  this.stopAnimationLoop(), this.stepping = !1, this.pausedByVisibility = !1, this.restoreAuthored(), this.scenarioId = e, this.useDefinition(n.timeline), this.lastMarkerId = null;
1851
2279
  let o = 0;
1852
- return this.reducedMotion || r ? o = this.duration : s !== void 0 && (o = this.markers.find((l) => l.id === s)?.time ?? 0), this.seek(o), i && !this.reducedMotion ? (this.stepping = this.options.stepMode === !0, this.startPlaying()) : this.notify(), !0;
2280
+ return this.reducedMotion || s ? o = this.duration : r !== void 0 && (o = this.markers.find((l) => l.id === r)?.time ?? 0), this.seek(o), i && !this.reducedMotion ? (this.stepping = this.options.stepMode === !0, this.startPlaying()) : this.notify(), !0;
1853
2281
  }
1854
2282
  /** Remember how an element was authored, the first time it becomes a target. */
1855
2283
  rememberAuthored(e) {
@@ -1903,8 +2331,8 @@ class Rn {
1903
2331
  caption(e, n) {
1904
2332
  const i = e ? this.markers.find((o) => o.id === e) : this.currentMarker;
1905
2333
  if (!i) return;
1906
- const r = n ?? this.language(), s = (o) => o?.[r]?.[i.id] ?? o?.[r.split("-")[0]]?.[i.id];
1907
- return s(this.options.captions) ?? s(this.timeline?.captions) ?? i.label;
2334
+ const s = n ?? this.language(), r = (o) => o?.[s]?.[i.id] ?? o?.[s.split("-")[0]]?.[i.id];
2335
+ return r(this.options.captions) ?? r(this.timeline?.captions) ?? i.label;
1908
2336
  }
1909
2337
  /** Move to the next marker: animated, or a jump under reduced motion. At the last marker, to the end. */
1910
2338
  next() {
@@ -1974,14 +2402,14 @@ class Rn {
1974
2402
  */
1975
2403
  scanMedia() {
1976
2404
  this.mediaTargets = [], this.container.querySelectorAll("[data-tinyfly-media]").forEach((n) => {
1977
- const i = n, r = Number(i.getAttribute("data-tinyfly-start") ?? "0") || 0, s = i.getAttribute("data-volume");
1978
- s !== null && (i.volume = Math.max(0, Math.min(1, Number(s) || 0))), this.mediaTargets.push({ el: i, startTime: r, sync: new me(i) });
2405
+ const i = n, s = Number(i.getAttribute("data-tinyfly-start") ?? "0") || 0, r = i.getAttribute("data-volume");
2406
+ r !== null && (i.volume = Math.max(0, Math.min(1, Number(r) || 0))), this.mediaTargets.push({ el: i, startTime: s, sync: new qe(i) });
1979
2407
  });
1980
2408
  }
1981
2409
  /** Sync all discovered media targets to a timeline time. */
1982
2410
  syncAllMedia(e, n) {
1983
2411
  for (const i of this.mediaTargets)
1984
- _n(i.sync, i.el, e, n, i.startTime);
2412
+ ki(i.sync, i.el, e, n, i.startTime);
1985
2413
  }
1986
2414
  /**
1987
2415
  * Load animation from inline JSON string.
@@ -2007,12 +2435,12 @@ class Rn {
2007
2435
  this.container.querySelectorAll("[data-tinyfly]").forEach((n) => {
2008
2436
  const i = n.closest("[data-tinyfly-symbol]");
2009
2437
  if (i && i !== n) return;
2010
- const r = n.getAttribute("data-tinyfly");
2011
- r && this.registerTarget(r, n);
2438
+ const s = n.getAttribute("data-tinyfly");
2439
+ s && this.registerTarget(s, n);
2012
2440
  }), this.timeline && new Set(this.timeline.tracks.map((i) => i.target)).forEach((i) => {
2013
2441
  if (!this.targets[i]) {
2014
- const r = this.container.querySelector(`[data-tinyfly="${i}"]`) || this.container.querySelector(`.${i}`) || this.container.querySelector(`#${i}`);
2015
- r && this.registerTarget(i, r);
2442
+ const s = this.container.querySelector(`[data-tinyfly="${i}"]`) || this.container.querySelector(`.${i}`) || this.container.querySelector(`#${i}`);
2443
+ s && this.registerTarget(i, s);
2016
2444
  }
2017
2445
  });
2018
2446
  }
@@ -2027,15 +2455,15 @@ class Rn {
2027
2455
  if (!e || e.length === 0) return;
2028
2456
  const n = new Map(e.map((i) => [i.id, i]));
2029
2457
  this.container.querySelectorAll("[data-tinyfly-symbol]").forEach((i) => {
2030
- const r = i.getAttribute("data-tinyfly-symbol");
2031
- if (!r) return;
2032
- const s = n.get(r);
2033
- if (!s || !s.timeline.tracks?.length) return;
2034
- const o = new re();
2458
+ const s = i.getAttribute("data-tinyfly-symbol");
2459
+ if (!s) return;
2460
+ const r = n.get(s);
2461
+ if (!r || !r.timeline.tracks?.length) return;
2462
+ const o = new $e();
2035
2463
  i.querySelectorAll("[data-tinyfly]").forEach((l) => {
2036
2464
  const c = l.getAttribute("data-tinyfly");
2037
2465
  c && o.registerTarget(c, l);
2038
- }), this.symbolInstances.push({ adapter: o, timeline: ie(s.timeline) });
2466
+ }), this.symbolInstances.push({ adapter: o, timeline: ke(r.timeline) });
2039
2467
  });
2040
2468
  }
2041
2469
  /**
@@ -2045,7 +2473,7 @@ class Rn {
2045
2473
  * plays. Pass `{ offset }` to start the media at a timeline offset.
2046
2474
  */
2047
2475
  attachMedia(e, n) {
2048
- this.mediaSync = new me(e, n), this.timeline && (this.mediaSync.setRate(this.timeline.speed), this.mediaSync.update(this.timeline.currentTime, this.isPlaying));
2476
+ this.mediaSync = new qe(e, n), this.timeline && (this.mediaSync.setRate(this.timeline.speed), this.mediaSync.update(this.timeline.currentTime, this.isPlaying));
2049
2477
  }
2050
2478
  /** Detach and pause the currently synced media, if any. */
2051
2479
  detachMedia() {
@@ -2136,10 +2564,10 @@ class Rn {
2136
2564
  if (this.isDestroyed || !this.timeline) return;
2137
2565
  const i = n - (this.lastTime ?? n);
2138
2566
  this.lastTime = n;
2139
- const r = this.playhead;
2140
- this.timeline.tick(i), this.stopAtMarker(r), this.applyState();
2141
- const s = this.timeline.playbackState === "playing";
2142
- this.mediaSync?.update(this.timeline.currentTime, s), this.syncAllMedia(this.timeline.currentTime, s), this.timeline.playbackState === "playing" ? this.animationFrameId = requestAnimationFrame(e) : (this.animationFrameId = void 0, this.notify());
2567
+ const s = this.playhead;
2568
+ this.timeline.tick(i), this.stopAtMarker(s), this.applyState();
2569
+ const r = this.timeline.playbackState === "playing";
2570
+ this.mediaSync?.update(this.timeline.currentTime, r), this.syncAllMedia(this.timeline.currentTime, r), this.timeline.playbackState === "playing" ? this.animationFrameId = requestAnimationFrame(e) : (this.animationFrameId = void 0, this.notify());
2143
2571
  };
2144
2572
  this.animationFrameId = requestAnimationFrame(e);
2145
2573
  }
@@ -2150,17 +2578,17 @@ class Rn {
2150
2578
  stopAtMarker(e) {
2151
2579
  const n = this.timeline, i = { time: n.currentTime, iteration: n.loopIteration, direction: n.direction };
2152
2580
  this.playhead = i;
2153
- const r = this.markers;
2154
- if (r.length === 0) return;
2155
- const { crossings: s } = De(
2156
- r.map((o) => o.time),
2581
+ const s = this.markers;
2582
+ if (s.length === 0) return;
2583
+ const { crossings: r } = hn(
2584
+ s.map((o) => o.time),
2157
2585
  e,
2158
2586
  i,
2159
2587
  { duration: n.duration, alternate: n.config.alternate === !0, holding: n.repeatDelayRemaining > 0 }
2160
2588
  );
2161
- for (const o of s) {
2589
+ for (const o of r) {
2162
2590
  if (o.kind !== "event") continue;
2163
- const l = r[o.index];
2591
+ const l = s[o.index];
2164
2592
  if (this.stepping || l.pause) {
2165
2593
  this.stepping = !1, n.pause(), n.seek(l.time), this.playhead = { time: l.time, iteration: n.loopIteration, direction: n.direction };
2166
2594
  return;
@@ -2180,7 +2608,7 @@ class Rn {
2180
2608
  }
2181
2609
  }
2182
2610
  }
2183
- const Vn = {
2611
+ const Mi = {
2184
2612
  play: "Play",
2185
2613
  pause: "Pause",
2186
2614
  prev: "Previous step",
@@ -2195,7 +2623,7 @@ const Vn = {
2195
2623
  scenario: "Scenario",
2196
2624
  fullscreen: "Full screen",
2197
2625
  exitFullscreen: "Exit full screen"
2198
- }, ye = "tinyfly-controls-style", Wn = `
2626
+ }, Ce = "tinyfly-controls-style", xi = `
2199
2627
  .tf-ctl { --tf-ctl-fg: #1d1d1f; --tf-ctl-bg: #f4f2ee; --tf-ctl-accent: #c2410c; --tf-ctl-radius: 8px;
2200
2628
  font: 14px/1.4 var(--tf-ctl-font, system-ui, sans-serif); color: var(--tf-ctl-fg); margin-top: 8px; }
2201
2629
  .tf-ctl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; border-radius: var(--tf-ctl-radius); background: var(--tf-ctl-bg); }
@@ -2244,249 +2672,249 @@ const Vn = {
2244
2672
  .tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
2245
2673
  }
2246
2674
  `;
2247
- let Bn = 0;
2248
- function Un(t) {
2249
- if (t.getElementById(ye)) return;
2675
+ let Si = 0;
2676
+ function Ai(t) {
2677
+ if (t.getElementById(Ce)) return;
2250
2678
  const e = t.createElement("style");
2251
- e.id = ye, e.textContent = Wn, t.head.appendChild(e);
2679
+ e.id = Ce, e.textContent = xi, t.head.appendChild(e);
2252
2680
  }
2253
- function Hn(t, e, n = {}) {
2681
+ function Ei(t, e, n = {}) {
2254
2682
  const i = e.ownerDocument;
2255
- Un(i);
2256
- const r = { ...Vn, ...n.labels }, s = n.speeds ?? [0.5, 1, 2], o = () => t.markers.length > 0, l = () => t.markers.some((S) => S.label !== void 0 || t.caption(S.id) !== void 0), c = i.createElement("div");
2683
+ Ai(i);
2684
+ const s = { ...Mi, ...n.labels }, r = n.speeds ?? [0.5, 1, 2], o = () => t.markers.length > 0, l = () => t.markers.some((A) => A.label !== void 0 || t.caption(A.id) !== void 0), c = i.createElement("div");
2257
2685
  c.className = "tf-ctl";
2258
- const f = i.createElement("div");
2259
- f.className = "tf-ctl-bar", f.setAttribute("role", "group");
2260
- const u = (S, C, nt, Q = "") => {
2261
- const U = i.createElement("button");
2262
- return U.type = "button", U.className = `tf-ctl-btn ${Q}`.trim(), U.setAttribute("aria-label", S), U.title = S, U.textContent = C, U.addEventListener("click", nt), U;
2263
- }, h = u(r.restart, "⟲", () => {
2686
+ const d = i.createElement("div");
2687
+ d.className = "tf-ctl-bar", d.setAttribute("role", "group");
2688
+ const u = (A, z, ot, et = "") => {
2689
+ const H = i.createElement("button");
2690
+ return H.type = "button", H.className = `tf-ctl-btn ${et}`.trim(), H.setAttribute("aria-label", A), H.title = A, H.textContent = z, H.addEventListener("click", ot), H;
2691
+ }, p = u(s.restart, "⟲", () => {
2264
2692
  t.pause(), t.seek(0);
2265
- }), d = u(r.prev, "|◀", () => t.prev()), y = u(r.play, "▶", () => t.isPlaying ? t.pause() : p(), "tf-ctl-primary"), a = u(r.next, "▶|", () => t.next()), p = () => {
2693
+ }), h = u(s.prev, "|◀", () => t.prev()), m = u(s.play, "▶", () => t.isPlaying ? t.pause() : y(), "tf-ctl-primary"), f = u(s.next, "▶|", () => t.next()), y = () => {
2266
2694
  t.currentTime >= t.duration - 0.5 && t.seek(0), t.play();
2267
- }, m = i.createElement("input");
2268
- m.type = "range", m.className = "tf-ctl-scrub", m.min = "0", m.max = "1000", m.step = "1", m.setAttribute("aria-label", r.scrub), m.addEventListener("input", () => {
2269
- t.pause(), t.seek(Number(m.value) / 1e3 * t.duration);
2695
+ }, a = i.createElement("input");
2696
+ a.type = "range", a.className = "tf-ctl-scrub", a.min = "0", a.max = "1000", a.step = "1", a.setAttribute("aria-label", s.scrub), a.addEventListener("input", () => {
2697
+ t.pause(), t.seek(Number(a.value) / 1e3 * t.duration);
2270
2698
  });
2271
- const b = i.createElement("span");
2272
- b.className = "tf-ctl-step";
2699
+ const g = i.createElement("span");
2700
+ g.className = "tf-ctl-step";
2273
2701
  const w = i.createElement("select");
2274
- w.className = "tf-ctl-speed", w.setAttribute("aria-label", r.speed);
2275
- for (const S of s) {
2276
- const C = i.createElement("option");
2277
- C.value = String(S), C.textContent = `${S}×`, S === 1 && (C.selected = !0), w.appendChild(C);
2278
- }
2279
- w.addEventListener("change", () => t.setSpeed(Number(w.value))), f.append(h, d, y, a, m, b), s.length > 0 && f.append(w), c.append(f);
2280
- const $ = n.fullscreen ? Gn(e, i, r) : void 0;
2281
- $ && f.append($.button);
2282
- const g = i.createElement("p");
2283
- g.className = "tf-ctl-caption", g.setAttribute("aria-live", "polite"), n.captions !== !1 && c.append(g);
2284
- const k = i.createElement("div");
2285
- k.className = "tf-ctl-question", k.hidden = !0;
2286
- const v = i.createElement("span"), x = u(r.reveal, r.reveal, () => t.play(), "tf-ctl-primary");
2287
- k.append(v, x), c.append(k);
2288
- const M = Xn(t, i, r.scenario, n.scenarioControl ?? "buttons");
2289
- M && c.append(M.element);
2702
+ w.className = "tf-ctl-speed", w.setAttribute("aria-label", s.speed);
2703
+ for (const A of r) {
2704
+ const z = i.createElement("option");
2705
+ z.value = String(A), z.textContent = `${A}×`, A === 1 && (z.selected = !0), w.appendChild(z);
2706
+ }
2707
+ w.addEventListener("change", () => t.setSpeed(Number(w.value))), d.append(p, h, m, f, a, g), r.length > 0 && d.append(w), c.append(d);
2708
+ const M = n.fullscreen ? Ni(e, i, s) : void 0;
2709
+ M && d.append(M.button);
2710
+ const v = i.createElement("p");
2711
+ v.className = "tf-ctl-caption", v.setAttribute("aria-live", "polite"), n.captions !== !1 && c.append(v);
2712
+ const b = i.createElement("div");
2713
+ b.className = "tf-ctl-question", b.hidden = !0;
2714
+ const k = i.createElement("span"), $ = u(s.reveal, s.reveal, () => t.play(), "tf-ctl-primary");
2715
+ b.append(k, $), c.append(b);
2716
+ const x = Ti(t, i, s.scenario, n.scenarioControl ?? "buttons");
2717
+ x && c.append(x.element);
2290
2718
  const T = n.mount;
2291
2719
  T ? T.appendChild(c) : e.insertAdjacentElement("afterend", c);
2292
- const P = () => {
2293
- const S = t.isPlaying;
2294
- y.textContent = S ? "❚❚" : "▶", y.setAttribute("aria-label", S ? r.pause : r.play), y.title = S ? r.pause : r.play;
2295
- const C = t.duration;
2296
- i.activeElement !== m && (m.value = String(C > 0 ? Math.round(t.currentTime / C * 1e3) : 0));
2297
- const nt = t.markers;
2298
- if (d.hidden = a.hidden = b.hidden = nt.length === 0, nt.length > 0) {
2299
- const Q = t.currentMarker, U = Q ? nt.indexOf(Q) + 1 : 0;
2300
- b.textContent = r.stepFormat.replace("{index}", String(U)).replace("{total}", String(nt.length)), b.setAttribute("aria-label", `${r.step} ${U} ${r.of} ${nt.length}`), d.disabled = t.currentTime <= 0.5, a.disabled = t.currentTime >= C - 0.5;
2301
- const ee = t.caption() ?? "";
2302
- g.textContent !== ee && (g.textContent = ee), g.hidden = !l();
2303
- const ne = !S && Q?.question !== void 0 && Math.abs(t.currentTime - Q.time) < 1;
2304
- k.hidden = !ne, ne && v.textContent !== Q.question && (v.textContent = Q.question);
2720
+ const N = () => {
2721
+ const A = t.isPlaying;
2722
+ m.textContent = A ? "❚❚" : "▶", m.setAttribute("aria-label", A ? s.pause : s.play), m.title = A ? s.pause : s.play;
2723
+ const z = t.duration;
2724
+ i.activeElement !== a && (a.value = String(z > 0 ? Math.round(t.currentTime / z * 1e3) : 0));
2725
+ const ot = t.markers;
2726
+ if (h.hidden = f.hidden = g.hidden = ot.length === 0, ot.length > 0) {
2727
+ const et = t.currentMarker, H = et ? ot.indexOf(et) + 1 : 0;
2728
+ g.textContent = s.stepFormat.replace("{index}", String(H)).replace("{total}", String(ot.length)), g.setAttribute("aria-label", `${s.step} ${H} ${s.of} ${ot.length}`), h.disabled = t.currentTime <= 0.5, f.disabled = t.currentTime >= z - 0.5;
2729
+ const ve = t.caption() ?? "";
2730
+ v.textContent !== ve && (v.textContent = ve), v.hidden = !l();
2731
+ const we = !A && et?.question !== void 0 && Math.abs(t.currentTime - et.time) < 1;
2732
+ b.hidden = !we, we && k.textContent !== et.question && (k.textContent = et.question);
2305
2733
  } else
2306
- k.hidden = !0, g.hidden = !0;
2307
- M?.update();
2308
- }, K = t.subscribe(P);
2309
- P();
2310
- const j = n.keyboardScope ?? e;
2311
- !j.hasAttribute("tabindex") && j.tabIndex < 0 && (j.tabIndex = 0);
2312
- const te = /* @__PURE__ */ new WeakSet(), kt = (S) => {
2313
- if (te.has(S) || (te.add(S), S.defaultPrevented || S.altKey || S.ctrlKey || S.metaKey)) return;
2314
- const C = S.target;
2315
- if (!(C.tagName === "INPUT" || C.tagName === "SELECT") && !(S.key === " " && C.tagName === "BUTTON"))
2316
- switch (S.key) {
2734
+ b.hidden = !0, v.hidden = !0;
2735
+ x?.update();
2736
+ }, q = t.subscribe(N);
2737
+ N();
2738
+ const F = n.keyboardScope ?? e;
2739
+ !F.hasAttribute("tabindex") && F.tabIndex < 0 && (F.tabIndex = 0);
2740
+ const vt = /* @__PURE__ */ new WeakSet(), K = (A) => {
2741
+ if (vt.has(A) || (vt.add(A), A.defaultPrevented || A.altKey || A.ctrlKey || A.metaKey)) return;
2742
+ const z = A.target;
2743
+ if (!(z.tagName === "INPUT" || z.tagName === "SELECT") && !(A.key === " " && z.tagName === "BUTTON"))
2744
+ switch (A.key) {
2317
2745
  case " ":
2318
- S.preventDefault(), t.isPlaying ? t.pause() : p();
2746
+ A.preventDefault(), t.isPlaying ? t.pause() : y();
2319
2747
  break;
2320
2748
  case "ArrowRight":
2321
2749
  if (!o()) return;
2322
- S.preventDefault(), t.next();
2750
+ A.preventDefault(), t.next();
2323
2751
  break;
2324
2752
  case "ArrowLeft":
2325
2753
  if (!o()) return;
2326
- S.preventDefault(), t.prev();
2754
+ A.preventDefault(), t.prev();
2327
2755
  break;
2328
2756
  case "Home":
2329
- S.preventDefault(), t.pause(), t.seek(0);
2757
+ A.preventDefault(), t.pause(), t.seek(0);
2330
2758
  break;
2331
2759
  case "f":
2332
2760
  case "F":
2333
- if (!$) return;
2334
- S.preventDefault(), $.active ? $.exit() : $.enter();
2761
+ if (!M) return;
2762
+ A.preventDefault(), M.active ? M.exit() : M.enter();
2335
2763
  break;
2336
2764
  }
2337
2765
  };
2338
- return j.addEventListener("keydown", kt), c.addEventListener("keydown", kt), {
2766
+ return F.addEventListener("keydown", K), c.addEventListener("keydown", K), {
2339
2767
  element: c,
2340
- fullscreen: $ && {
2768
+ fullscreen: M && {
2341
2769
  get active() {
2342
- return $.active;
2770
+ return M.active;
2343
2771
  },
2344
- enter: $.enter,
2345
- exit: $.exit
2772
+ enter: M.enter,
2773
+ exit: M.exit
2346
2774
  },
2347
2775
  destroy() {
2348
- $?.destroy(), K(), j.removeEventListener("keydown", kt), c.removeEventListener("keydown", kt), c.remove();
2776
+ M?.destroy(), q(), F.removeEventListener("keydown", K), c.removeEventListener("keydown", K), c.remove();
2349
2777
  }
2350
2778
  };
2351
2779
  }
2352
- function Xn(t, e, n, i) {
2353
- const r = t.scenarios;
2354
- if (r.length < 2) return;
2780
+ function Ti(t, e, n, i) {
2781
+ const s = t.scenarios;
2782
+ if (s.length < 2) return;
2355
2783
  if (i === "slider") {
2356
2784
  const u = e.createElement("div");
2357
2785
  u.className = "tf-ctl-choice-slider";
2358
- const h = e.createElement("span");
2359
- h.textContent = n, h.setAttribute("aria-hidden", "true");
2360
- const d = e.createElement("input");
2361
- d.type = "range", d.min = "0", d.max = String(r.length - 1), d.step = "1", d.setAttribute("aria-label", n);
2362
- const y = e.createElement("output");
2363
- return y.setAttribute("aria-hidden", "true"), d.addEventListener("input", () => {
2364
- const p = r[Number(d.value)];
2365
- p && t.setScenario(p.id);
2366
- }), u.append(h, d, y), { element: u, update: () => {
2367
- const p = Math.max(0, r.findIndex((b) => b.id === t.scenario));
2368
- e.activeElement !== d && (d.value = String(p));
2369
- const m = r[p].label;
2370
- y.textContent !== m && (y.textContent = m), d.setAttribute("aria-valuetext", m);
2786
+ const p = e.createElement("span");
2787
+ p.textContent = n, p.setAttribute("aria-hidden", "true");
2788
+ const h = e.createElement("input");
2789
+ h.type = "range", h.min = "0", h.max = String(s.length - 1), h.step = "1", h.setAttribute("aria-label", n);
2790
+ const m = e.createElement("output");
2791
+ return m.setAttribute("aria-hidden", "true"), h.addEventListener("input", () => {
2792
+ const y = s[Number(h.value)];
2793
+ y && t.setScenario(y.id);
2794
+ }), u.append(p, h, m), { element: u, update: () => {
2795
+ const y = Math.max(0, s.findIndex((g) => g.id === t.scenario));
2796
+ e.activeElement !== h && (h.value = String(y));
2797
+ const a = s[y].label;
2798
+ m.textContent !== a && (m.textContent = a), h.setAttribute("aria-valuetext", a);
2371
2799
  } };
2372
2800
  }
2373
- const s = e.createElement("fieldset");
2374
- s.className = "tf-ctl-choices";
2801
+ const r = e.createElement("fieldset");
2802
+ r.className = "tf-ctl-choices";
2375
2803
  const o = e.createElement("legend");
2376
- o.textContent = n, s.append(o);
2377
- const l = `tf-ctl-scenario-${++Bn}`, c = r.map((u) => {
2378
- const h = e.createElement("label");
2379
- h.className = "tf-ctl-choice";
2380
- const d = e.createElement("input");
2381
- d.type = "radio", d.name = l, d.value = u.id, d.addEventListener("change", () => {
2382
- d.checked && t.setScenario(u.id);
2804
+ o.textContent = n, r.append(o);
2805
+ const l = `tf-ctl-scenario-${++Si}`, c = s.map((u) => {
2806
+ const p = e.createElement("label");
2807
+ p.className = "tf-ctl-choice";
2808
+ const h = e.createElement("input");
2809
+ h.type = "radio", h.name = l, h.value = u.id, h.addEventListener("change", () => {
2810
+ h.checked && t.setScenario(u.id);
2383
2811
  });
2384
- const y = e.createElement("span");
2385
- return y.textContent = u.label, h.append(d, y), s.append(h), d;
2812
+ const m = e.createElement("span");
2813
+ return m.textContent = u.label, p.append(h, m), r.append(p), h;
2386
2814
  });
2387
- return { element: s, update: () => {
2815
+ return { element: r, update: () => {
2388
2816
  for (const u of c) {
2389
- const h = u.value === t.scenario;
2390
- u.checked !== h && (u.checked = h);
2817
+ const p = u.value === t.scenario;
2818
+ u.checked !== p && (u.checked = p);
2391
2819
  }
2392
2820
  } };
2393
2821
  }
2394
- const Yn = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>', Zn = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';
2395
- function Gn(t, e, n) {
2396
- const i = e, r = t, s = e.createElement("button");
2397
- s.type = "button", s.className = "tf-ctl-btn tf-ctl-fullscreen";
2822
+ const Oi = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>', Pi = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';
2823
+ function Ni(t, e, n) {
2824
+ const i = e, s = t, r = e.createElement("button");
2825
+ r.type = "button", r.className = "tf-ctl-btn tf-ctl-fullscreen";
2398
2826
  let o, l = "";
2399
2827
  const c = () => {
2400
- const p = o !== void 0;
2401
- s.innerHTML = p ? Zn : Yn;
2402
- const m = p ? n.exitFullscreen : n.fullscreen;
2403
- s.setAttribute("aria-label", m), s.title = m, s.setAttribute("aria-pressed", String(p)), t.classList.toggle("tf-fullscreen", p), t.classList.toggle("tf-fullscreen-overlay", o === "overlay");
2404
- }, f = () => i.fullscreenElement ?? i.webkitFullscreenElement ?? null, u = () => {
2405
- f() === t ? o = "native" : o === "native" && (o = void 0), c();
2406
- }, h = (p) => {
2407
- p.key === "Escape" && a();
2408
- }, d = () => {
2409
- o = "overlay", l = e.documentElement.style.overflow, e.documentElement.style.overflow = "hidden", e.addEventListener("keydown", h), c();
2828
+ const y = o !== void 0;
2829
+ r.innerHTML = y ? Pi : Oi;
2830
+ const a = y ? n.exitFullscreen : n.fullscreen;
2831
+ r.setAttribute("aria-label", a), r.title = a, r.setAttribute("aria-pressed", String(y)), t.classList.toggle("tf-fullscreen", y), t.classList.toggle("tf-fullscreen-overlay", o === "overlay");
2832
+ }, d = () => i.fullscreenElement ?? i.webkitFullscreenElement ?? null, u = () => {
2833
+ d() === t ? o = "native" : o === "native" && (o = void 0), c();
2834
+ }, p = (y) => {
2835
+ y.key === "Escape" && f();
2836
+ }, h = () => {
2837
+ o = "overlay", l = e.documentElement.style.overflow, e.documentElement.style.overflow = "hidden", e.addEventListener("keydown", p), c();
2410
2838
  };
2411
- async function y() {
2839
+ async function m() {
2412
2840
  if (o) return;
2413
- const p = r.requestFullscreen?.bind(r) ?? r.webkitRequestFullscreen?.bind(r), m = i.fullscreenEnabled ?? i.webkitFullscreenEnabled ?? !1;
2414
- if (p && m)
2841
+ const y = s.requestFullscreen?.bind(s) ?? s.webkitRequestFullscreen?.bind(s), a = i.fullscreenEnabled ?? i.webkitFullscreenEnabled ?? !1;
2842
+ if (y && a)
2415
2843
  try {
2416
- if (await p(), f() === t) {
2844
+ if (await y(), d() === t) {
2417
2845
  o = "native", c();
2418
2846
  return;
2419
2847
  }
2420
2848
  } catch {
2421
2849
  }
2422
- d();
2850
+ h();
2423
2851
  }
2424
- async function a() {
2852
+ async function f() {
2425
2853
  if (o === "overlay")
2426
- e.removeEventListener("keydown", h), e.documentElement.style.overflow = l, o = void 0, c();
2854
+ e.removeEventListener("keydown", p), e.documentElement.style.overflow = l, o = void 0, c();
2427
2855
  else if (o === "native") {
2428
2856
  o = void 0, c();
2429
- const p = i.exitFullscreen?.bind(i) ?? i.webkitExitFullscreen?.bind(i);
2430
- f() === t && p && await p();
2857
+ const y = i.exitFullscreen?.bind(i) ?? i.webkitExitFullscreen?.bind(i);
2858
+ d() === t && y && await y();
2431
2859
  }
2432
2860
  }
2433
- return s.addEventListener("click", () => {
2434
- o ? a() : y();
2861
+ return r.addEventListener("click", () => {
2862
+ o ? f() : m();
2435
2863
  }), e.addEventListener("fullscreenchange", u), e.addEventListener("webkitfullscreenchange", u), c(), {
2436
- button: s,
2864
+ button: r,
2437
2865
  get active() {
2438
2866
  return o !== void 0;
2439
2867
  },
2440
- enter: y,
2441
- exit: a,
2868
+ enter: m,
2869
+ exit: f,
2442
2870
  destroy() {
2443
- a(), e.removeEventListener("fullscreenchange", u), e.removeEventListener("webkitfullscreenchange", u), s.remove();
2871
+ f(), e.removeEventListener("fullscreenchange", u), e.removeEventListener("webkitfullscreenchange", u), r.remove();
2444
2872
  }
2445
2873
  };
2446
2874
  }
2447
- const ge = "tinyfly-choices-style", Kn = `
2875
+ const ze = "tinyfly-choices-style", Ii = `
2448
2876
  [data-tinyfly-choose] { cursor: pointer; }
2449
2877
  [data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
2450
2878
  `;
2451
- function Qn(t) {
2452
- if (t.getElementById(ge)) return;
2879
+ function Li(t) {
2880
+ if (t.getElementById(ze)) return;
2453
2881
  const e = t.createElement("style");
2454
- e.id = ge, e.textContent = Kn, t.head.appendChild(e);
2882
+ e.id = ze, e.textContent = Ii, t.head.appendChild(e);
2455
2883
  }
2456
- function Jn(t, e) {
2884
+ function Fi(t, e) {
2457
2885
  const n = Array.from(e.querySelectorAll("[data-tinyfly-choose]"));
2458
2886
  if (n.length === 0) return () => {
2459
2887
  };
2460
- Qn(e.ownerDocument);
2461
- const i = [], r = [];
2888
+ Li(e.ownerDocument);
2889
+ const i = [], s = [];
2462
2890
  for (const l of n) {
2463
- const c = l.getAttribute("data-tinyfly-choose") ?? "", f = [], u = (a, p) => {
2464
- l.hasAttribute(a) || (l.setAttribute(a, p), f.push(a));
2891
+ const c = l.getAttribute("data-tinyfly-choose") ?? "", d = [], u = (f, y) => {
2892
+ l.hasAttribute(f) || (l.setAttribute(f, y), d.push(f));
2465
2893
  };
2466
2894
  u("role", "button"), u("tabindex", "0");
2467
- const h = t.scenarios.find((a) => a.id === c)?.label;
2468
- h !== void 0 && u("aria-label", h), l.setAttribute("aria-pressed", "false"), f.push("aria-pressed"), i.push({ element: l, attributes: f });
2469
- const d = () => t.setScenario(c), y = (a) => {
2470
- const p = a.key;
2471
- p !== "Enter" && p !== " " || (a.preventDefault(), d());
2895
+ const p = t.scenarios.find((f) => f.id === c)?.label;
2896
+ p !== void 0 && u("aria-label", p), l.setAttribute("aria-pressed", "false"), d.push("aria-pressed"), i.push({ element: l, attributes: d });
2897
+ const h = () => t.setScenario(c), m = (f) => {
2898
+ const y = f.key;
2899
+ y !== "Enter" && y !== " " || (f.preventDefault(), h());
2472
2900
  };
2473
- l.addEventListener("click", d), l.addEventListener("keydown", y), r.push(() => {
2474
- l.removeEventListener("click", d), l.removeEventListener("keydown", y);
2901
+ l.addEventListener("click", h), l.addEventListener("keydown", m), s.push(() => {
2902
+ l.removeEventListener("click", h), l.removeEventListener("keydown", m);
2475
2903
  });
2476
2904
  }
2477
- const s = () => {
2905
+ const r = () => {
2478
2906
  for (const { element: l } of i)
2479
2907
  l.setAttribute("aria-pressed", String(l.getAttribute("data-tinyfly-choose") === t.scenario));
2480
- }, o = t.subscribe(s);
2481
- return s(), () => {
2908
+ }, o = t.subscribe(r);
2909
+ return r(), () => {
2482
2910
  o();
2483
- for (const l of r) l();
2484
- for (const { element: l, attributes: c } of i) for (const f of c) l.removeAttribute(f);
2911
+ for (const l of s) l();
2912
+ for (const { element: l, attributes: c } of i) for (const d of c) l.removeAttribute(d);
2485
2913
  };
2486
2914
  }
2487
- const be = /* @__PURE__ */ new WeakMap(), ti = /* @__PURE__ */ new WeakMap();
2488
- let ei = 0;
2489
- function ht(t, e, n) {
2915
+ const je = /* @__PURE__ */ new WeakMap(), qi = /* @__PURE__ */ new WeakMap();
2916
+ let Ci = 0;
2917
+ function wt(t, e, n) {
2490
2918
  if (t)
2491
2919
  try {
2492
2920
  return JSON.parse(t);
@@ -2495,222 +2923,222 @@ function ht(t, e, n) {
2495
2923
  return;
2496
2924
  }
2497
2925
  }
2498
- async function ni(t, e = {}) {
2499
- const n = be.get(t);
2926
+ async function zi(t, e = {}) {
2927
+ const n = je.get(t);
2500
2928
  if (n) return n;
2501
- const i = Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")), r = i[0], s = t.getAttribute("data-src"), o = ri(t.getAttribute("data-markers")), l = i.length > 1 || r?.hasAttribute("data-scenario") ? ii(i, o, t) : void 0;
2929
+ const i = Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")), s = i[0], r = t.getAttribute("data-src"), o = Di(t.getAttribute("data-markers")), l = i.length > 1 || s?.hasAttribute("data-scenario") ? ji(i, o, t) : void 0;
2502
2930
  if (l && l.length === 0) return;
2503
- let c = r && !l ? ht(r.textContent, "timeline", t) : void 0;
2504
- if (!c && s && o) {
2505
- const y = await fetch(s);
2506
- y.ok && (c = await y.json());
2931
+ let c = s && !l ? wt(s.textContent, "timeline", t) : void 0;
2932
+ if (!c && r && o) {
2933
+ const m = await fetch(r);
2934
+ m.ok && (c = await m.json());
2507
2935
  }
2508
- if (c && o && (c = ze(c, o)), !c && !s && !l) {
2936
+ if (c && o && (c = un(c, o)), !c && !r && !l) {
2509
2937
  console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)', t);
2510
2938
  return;
2511
2939
  }
2512
- const f = ht(t.querySelector("script[data-tinyfly-captions]")?.textContent, "captions", t), u = {
2940
+ const d = wt(t.querySelector("script[data-tinyfly-captions]")?.textContent, "captions", t), u = {
2513
2941
  playWhenVisible: !0,
2514
2942
  ...e.player,
2515
- ...f && { captions: f },
2516
- ...ht(t.getAttribute("data-options"), "data-options", t)
2943
+ ...d && { captions: d },
2944
+ ...wt(t.getAttribute("data-options"), "data-options", t)
2517
2945
  };
2518
- si(t);
2519
- const h = new Rn(t, u), d = { element: t, player: h };
2520
- if (be.set(t, d), t.setAttribute("data-tinyfly-mounted", ""), l) {
2521
- const y = t.getAttribute("data-scenario") ?? void 0;
2522
- await h.loadScenarios(l, { initial: l.some((a) => a.id === y) ? y : void 0 }), ti.set(t, Jn(h, t));
2946
+ Ri(t);
2947
+ const p = new $i(t, u), h = { element: t, player: p };
2948
+ if (je.set(t, h), t.setAttribute("data-tinyfly-mounted", ""), l) {
2949
+ const m = t.getAttribute("data-scenario") ?? void 0;
2950
+ await p.loadScenarios(l, { initial: l.some((f) => f.id === m) ? m : void 0 }), qi.set(t, Fi(p, t));
2523
2951
  } else
2524
- await h.load(c ?? s);
2952
+ await p.load(c ?? r);
2525
2953
  if (t.getAttribute("data-controls") !== "false") {
2526
- const y = ht(t.getAttribute("data-labels"), "data-labels", t), a = t.querySelector("figcaption"), p = t.getAttribute("data-scenario-legend"), m = t.getAttribute("data-scenario-control");
2527
- d.controls = Hn(h, t, {
2954
+ const m = wt(t.getAttribute("data-labels"), "data-labels", t), f = t.querySelector("figcaption"), y = t.getAttribute("data-scenario-legend"), a = t.getAttribute("data-scenario-control");
2955
+ h.controls = Ei(p, t, {
2528
2956
  ...e.controls,
2529
2957
  ...t.getAttribute("data-fullscreen") === "true" ? { fullscreen: !0 } : {},
2530
- ...m === "slider" || m === "buttons" ? { scenarioControl: m } : {},
2531
- labels: { ...e.controls?.labels, ...y, ...p ? { scenario: p } : {} },
2958
+ ...a === "slider" || a === "buttons" ? { scenarioControl: a } : {},
2959
+ labels: { ...e.controls?.labels, ...m, ...y ? { scenario: y } : {} },
2532
2960
  // Inside the figure, before its figcaption, so the caption stays last.
2533
2961
  mount: void 0
2534
- }), a ? t.insertBefore(d.controls.element, a) : t.appendChild(d.controls.element);
2962
+ }), f ? t.insertBefore(h.controls.element, f) : t.appendChild(h.controls.element);
2535
2963
  }
2536
- return d;
2964
+ return h;
2537
2965
  }
2538
- function ii(t, e, n) {
2966
+ function ji(t, e, n) {
2539
2967
  const i = [];
2540
- return t.forEach((r, s) => {
2541
- const o = ht(r.textContent, "timeline", n);
2968
+ return t.forEach((s, r) => {
2969
+ const o = wt(s.textContent, "timeline", n);
2542
2970
  if (!o) return;
2543
- const l = r.getAttribute("data-scenario") || `scenario-${s + 1}`;
2544
- if (i.some((f) => f.id === l)) {
2971
+ const l = s.getAttribute("data-scenario") || `scenario-${r + 1}`;
2972
+ if (i.some((d) => d.id === l)) {
2545
2973
  console.warn(`tinyfly: scenario id "${l}" is used more than once; the later one is skipped`, n);
2546
2974
  return;
2547
2975
  }
2548
- const c = r.getAttribute("data-scenario-label") ?? void 0;
2549
- i.push({ id: l, label: c, timeline: e ? ze(o, e) : o });
2976
+ const c = s.getAttribute("data-scenario-label") ?? void 0;
2977
+ i.push({ id: l, label: c, timeline: e ? un(o, e) : o });
2550
2978
  }), i;
2551
2979
  }
2552
- function ze(t, e) {
2980
+ function un(t, e) {
2553
2981
  return t.config.markers?.length ? t : { ...t, config: { ...t.config, markers: e.map((n, i) => ({ id: `step-${i + 1}`, time: n })) } };
2554
2982
  }
2555
- function ri(t) {
2983
+ function Di(t) {
2556
2984
  if (!t) return;
2557
2985
  const e = t.split(/[\s,]+/).filter(Boolean).map(Number).filter((n) => Number.isFinite(n) && n >= 0).sort((n, i) => n - i);
2558
2986
  return e.length > 0 ? e : void 0;
2559
2987
  }
2560
- function si(t) {
2988
+ function Ri(t) {
2561
2989
  const e = t.querySelector("svg");
2562
2990
  if (!e || e.hasAttribute("role") || e.hasAttribute("aria-hidden")) return;
2563
2991
  const n = t.getAttribute("data-alt"), i = t.querySelector("figcaption");
2564
- e.setAttribute("role", "img"), n ? e.setAttribute("aria-label", n) : i && (i.id ||= `tinyfly-caption-${++ei}`, e.setAttribute("aria-labelledby", i.id));
2992
+ e.setAttribute("role", "img"), n ? e.setAttribute("aria-label", n) : i && (i.id ||= `tinyfly-caption-${++Ci}`, e.setAttribute("aria-labelledby", i.id));
2565
2993
  }
2566
- const oi = "http://www.w3.org/2000/svg", Pt = /* @__PURE__ */ new WeakMap();
2567
- function ai(t, e) {
2994
+ const _i = "http://www.w3.org/2000/svg", Kt = /* @__PURE__ */ new WeakMap();
2995
+ function Vi(t, e) {
2568
2996
  const n = t?.values.get(e);
2569
2997
  return n ? Object.fromEntries(n) : {};
2570
2998
  }
2571
- async function li(t, e = {}) {
2572
- const n = Pt.get(t);
2999
+ async function Bi(t, e = {}) {
3000
+ const n = Kt.get(t);
2573
3001
  if (n) return n;
2574
3002
  const i = t.querySelector("script[data-tinyfly-figure]");
2575
- let r;
3003
+ let s;
2576
3004
  try {
2577
- r = bt(JSON.parse(i?.textContent ?? "null"));
2578
- } catch (d) {
2579
- console.warn("tinyfly: math figure is missing or invalid", t, d);
3005
+ s = Tt(JSON.parse(i?.textContent ?? "null"));
3006
+ } catch (h) {
3007
+ console.warn("tinyfly: math figure is missing or invalid", t, h);
2580
3008
  return;
2581
3009
  }
2582
- const s = t.getAttribute("data-target") ?? "fig";
3010
+ const r = t.getAttribute("data-target") ?? "fig";
2583
3011
  let o = t.querySelector("svg[data-tinyfly-math-svg]");
2584
- o || (o = t.ownerDocument.createElementNS(oi, "svg"), o.setAttribute("data-tinyfly-math-svg", ""), o.setAttribute("viewBox", `0 0 ${r.width} ${r.height}`), o.setAttribute("style", "display:block;width:100%;height:auto"), t.insertBefore(o, t.querySelector("figcaption")));
2585
- const l = (d) => {
2586
- o.innerHTML = Kt(Lt(r, d));
3012
+ o || (o = t.ownerDocument.createElementNS(_i, "svg"), o.setAttribute("data-tinyfly-math-svg", ""), o.setAttribute("viewBox", `0 0 ${s.width} ${s.height}`), o.setAttribute("style", "display:block;width:100%;height:auto"), t.insertBefore(o, t.querySelector("figcaption")));
3013
+ const l = (h) => {
3014
+ o.innerHTML = ye(Bt(s, h));
2587
3015
  };
2588
3016
  if (l({}), !(t.querySelector("script[data-tinyfly-timeline]") || t.hasAttribute("data-src"))) {
2589
- const d = { element: t, figure: r, redraw: () => l({}) };
2590
- return Pt.set(t, d), d;
3017
+ const h = { element: t, figure: s, redraw: () => l({}) };
3018
+ return Kt.set(t, h), h;
2591
3019
  }
2592
- const f = await ni(t, e);
2593
- if (!f) return;
2594
- const u = () => l(ai(f.player.state, s));
2595
- f.player.subscribe(u), u();
2596
- const h = { ...f, figure: r, redraw: u };
2597
- return Pt.set(t, h), h;
3020
+ const d = await zi(t, e);
3021
+ if (!d) return;
3022
+ const u = () => l(Vi(d.player.state, r));
3023
+ d.player.subscribe(u), u();
3024
+ const p = { ...d, figure: s, redraw: u };
3025
+ return Kt.set(t, p), p;
2598
3026
  }
2599
- async function yi(t = document, e = {}) {
3027
+ async function Ki(t = document, e = {}) {
2600
3028
  const n = Array.from(t.querySelectorAll("[data-tinyfly-math]"));
2601
- return (await Promise.all(n.map((r) => li(r, e)))).filter((r) => r !== void 0);
3029
+ return (await Promise.all(n.map((s) => Bi(s, e)))).filter((s) => s !== void 0);
2602
3030
  }
2603
- const ci = "http://www.w3.org/2000/svg";
2604
- function gi(t, e, n = {}) {
2605
- bt(e);
3031
+ const Wi = "http://www.w3.org/2000/svg";
3032
+ function Ji(t, e, n = {}) {
3033
+ Tt(e);
2606
3034
  const i = { ...e.values ?? {} };
2607
- for (const g of n.sliders ?? [])
2608
- if (typeof i[g.value] != "number") throw new Error(`mathExplorable: slider value "${g.value}" is not a number value of the figure`);
2609
- for (const g of n.drag ?? []) {
2610
- if ("vector" in g && !tt(i[g.vector])) throw new Error(`mathExplorable: "${g.vector}" is not a vector value of the figure`);
2611
- if ("matrix" in g && !lt(i[g.matrix])) throw new Error(`mathExplorable: "${g.matrix}" is not a matrix value of the figure`);
3035
+ for (const v of n.sliders ?? [])
3036
+ if (typeof i[v.value] != "number") throw new Error(`mathExplorable: slider value "${v.value}" is not a number value of the figure`);
3037
+ for (const v of n.drag ?? []) {
3038
+ if ("vector" in v && !it(i[v.vector])) throw new Error(`mathExplorable: "${v.vector}" is not a vector value of the figure`);
3039
+ if ("matrix" in v && !pt(i[v.matrix])) throw new Error(`mathExplorable: "${v.matrix}" is not a matrix value of the figure`);
2612
3040
  }
2613
- const r = Te(e), s = t.ownerDocument, o = s.createElementNS(ci, "svg");
3041
+ const s = on(e), r = t.ownerDocument, o = r.createElementNS(Wi, "svg");
2614
3042
  o.setAttribute("viewBox", `0 0 ${e.width} ${e.height}`), o.setAttribute("style", "display:block;width:100%;height:auto;touch-action:none"), o.setAttribute("role", "img"), t.appendChild(o);
2615
- const l = n.drag ?? [], c = (g) => {
2616
- if ("vector" in g) return i[g.vector];
2617
- const [k, v, x, M] = i[g.matrix];
2618
- return g.column === 0 ? [k, x] : [v, M];
2619
- }, f = () => {
2620
- const g = l.map((k) => {
2621
- const [v, x] = r.toScreen(c(k));
2622
- return `<circle cx="${v}" cy="${x}" r="${14 * r.scale}" fill="rgba(255,255,255,0.08)" stroke="rgba(255,255,255,0.55)" stroke-width="${1.5 * r.scale}" style="cursor:grab"/>`;
3043
+ const l = n.drag ?? [], c = (v) => {
3044
+ if ("vector" in v) return i[v.vector];
3045
+ const [b, k, $, x] = i[v.matrix];
3046
+ return v.column === 0 ? [b, $] : [k, x];
3047
+ }, d = () => {
3048
+ const v = l.map((b) => {
3049
+ const [k, $] = s.toScreen(c(b));
3050
+ return `<circle cx="${k}" cy="${$}" r="${14 * s.scale}" fill="rgba(255,255,255,0.08)" stroke="rgba(255,255,255,0.55)" stroke-width="${1.5 * s.scale}" style="cursor:grab"/>`;
2623
3051
  });
2624
- o.innerHTML = Kt(Lt(e, i)) + g.join(""), n.onChange?.({ ...i });
2625
- }, u = (g, k) => {
2626
- if (!(g in i)) throw new Error(`mathExplorable: no value "${g}"`);
2627
- i[g] = k;
2628
- const v = h.get(g);
2629
- v && typeof k == "number" && (v.value = String(k), d.get(g).textContent = String(k)), f();
2630
- }, h = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
2631
- let y;
3052
+ o.innerHTML = ye(Bt(e, i)) + v.join(""), n.onChange?.({ ...i });
3053
+ }, u = (v, b) => {
3054
+ if (!(v in i)) throw new Error(`mathExplorable: no value "${v}"`);
3055
+ i[v] = b;
3056
+ const k = p.get(v);
3057
+ k && typeof b == "number" && (k.value = String(b), h.get(v).textContent = String(b)), d();
3058
+ }, p = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
3059
+ let m;
2632
3060
  if (n.sliders?.length) {
2633
- y = s.createElement("div"), y.setAttribute("style", "display:flex;flex-wrap:wrap;gap:8px 18px;align-items:center;padding:8px 0;font:14px system-ui,sans-serif");
2634
- for (const g of n.sliders) {
2635
- const k = s.createElement("label");
2636
- k.setAttribute("style", "display:flex;align-items:center;gap:6px");
2637
- const v = s.createElement("input");
2638
- v.type = "range", v.min = String(g.min), v.max = String(g.max), v.step = String(g.step ?? (g.max - g.min) / 100), v.value = String(i[g.value]), v.setAttribute("aria-label", g.label ?? g.value);
2639
- const x = s.createElement("output");
2640
- x.textContent = String(i[g.value]), v.addEventListener("input", () => u(g.value, Number(v.value))), k.append(g.label ?? g.value, v, x), y.appendChild(k), h.set(g.value, v), d.set(g.value, x);
2641
- }
2642
- t.appendChild(y);
2643
- }
2644
- const a = n.snap ?? 0.1, p = (g) => {
2645
- const k = o.getBoundingClientRect(), v = (g.clientX - k.left) / (k.width || e.width) * e.width, x = (g.clientY - k.top) / (k.height || e.height) * e.height, [M, T] = r.toWorld([v, x]), P = (K) => a > 0 ? Math.round(K / a) * a : K;
2646
- return [Number(P(M).toFixed(6)), Number(P(T).toFixed(6))];
3061
+ m = r.createElement("div"), m.setAttribute("style", "display:flex;flex-wrap:wrap;gap:8px 18px;align-items:center;padding:8px 0;font:14px system-ui,sans-serif");
3062
+ for (const v of n.sliders) {
3063
+ const b = r.createElement("label");
3064
+ b.setAttribute("style", "display:flex;align-items:center;gap:6px");
3065
+ const k = r.createElement("input");
3066
+ k.type = "range", k.min = String(v.min), k.max = String(v.max), k.step = String(v.step ?? (v.max - v.min) / 100), k.value = String(i[v.value]), k.setAttribute("aria-label", v.label ?? v.value);
3067
+ const $ = r.createElement("output");
3068
+ $.textContent = String(i[v.value]), k.addEventListener("input", () => u(v.value, Number(k.value))), b.append(v.label ?? v.value, k, $), m.appendChild(b), p.set(v.value, k), h.set(v.value, $);
3069
+ }
3070
+ t.appendChild(m);
3071
+ }
3072
+ const f = n.snap ?? 0.1, y = (v) => {
3073
+ const b = o.getBoundingClientRect(), k = (v.clientX - b.left) / (b.width || e.width) * e.width, $ = (v.clientY - b.top) / (b.height || e.height) * e.height, [x, T] = s.toWorld([k, $]), N = (q) => f > 0 ? Math.round(q / f) * f : q;
3074
+ return [Number(N(x).toFixed(6)), Number(N(T).toFixed(6))];
2647
3075
  };
2648
- let m;
2649
- const b = (g) => {
2650
- const k = o.getBoundingClientRect(), v = e.width / (k.width || e.width), x = [(g.clientX - k.left) * v, (g.clientY - k.top) * v];
2651
- let M;
3076
+ let a;
3077
+ const g = (v) => {
3078
+ const b = o.getBoundingClientRect(), k = e.width / (b.width || e.width), $ = [(v.clientX - b.left) * k, (v.clientY - b.top) * k];
3079
+ let x;
2652
3080
  for (const T of l) {
2653
- const [P, K] = r.toScreen(c(T)), j = Math.hypot(P - x[0], K - x[1]);
2654
- j < 30 * r.scale * Math.max(1, v) && (!M || j < M.distance) && (M = { handle: T, distance: j });
2655
- }
2656
- M && (m = M.handle, o.setPointerCapture?.(g.pointerId), g.preventDefault());
2657
- }, w = (g) => {
2658
- if (!m) return;
2659
- const [k, v] = p(g);
2660
- if ("vector" in m)
2661
- u(m.vector, [k, v]);
3081
+ const [N, q] = s.toScreen(c(T)), F = Math.hypot(N - $[0], q - $[1]);
3082
+ F < 30 * s.scale * Math.max(1, k) && (!x || F < x.distance) && (x = { handle: T, distance: F });
3083
+ }
3084
+ x && (a = x.handle, o.setPointerCapture?.(v.pointerId), v.preventDefault());
3085
+ }, w = (v) => {
3086
+ if (!a) return;
3087
+ const [b, k] = y(v);
3088
+ if ("vector" in a)
3089
+ u(a.vector, [b, k]);
2662
3090
  else {
2663
- const [x, M, T, P] = i[m.matrix];
2664
- u(m.matrix, m.column === 0 ? [k, M, v, P] : [x, k, T, v]);
3091
+ const [$, x, T, N] = i[a.matrix];
3092
+ u(a.matrix, a.column === 0 ? [b, x, k, N] : [$, b, T, k]);
2665
3093
  }
2666
- }, $ = () => {
2667
- m = void 0;
3094
+ }, M = () => {
3095
+ a = void 0;
2668
3096
  };
2669
- return o.addEventListener("pointerdown", b), o.addEventListener("pointermove", w), o.addEventListener("pointerup", $), o.addEventListener("pointercancel", $), f(), {
3097
+ return o.addEventListener("pointerdown", g), o.addEventListener("pointermove", w), o.addEventListener("pointerup", M), o.addEventListener("pointercancel", M), d(), {
2670
3098
  get values() {
2671
3099
  return { ...i };
2672
3100
  },
2673
3101
  set: u,
2674
3102
  destroy() {
2675
- o.removeEventListener("pointerdown", b), o.removeEventListener("pointermove", w), o.removeEventListener("pointerup", $), o.removeEventListener("pointercancel", $), y?.remove();
3103
+ o.removeEventListener("pointerdown", g), o.removeEventListener("pointermove", w), o.removeEventListener("pointerup", M), o.removeEventListener("pointercancel", M), m?.remove();
2676
3104
  }
2677
3105
  };
2678
3106
  }
2679
- const wt = (t, e, n) => ({
3107
+ const Ot = (t, e, n) => ({
2680
3108
  width: t.width ?? 600,
2681
3109
  height: t.height ?? 600,
2682
3110
  ...t.theme ? { theme: t.theme } : {},
2683
3111
  ...t.x ? { x: t.x } : {},
2684
3112
  values: e,
2685
3113
  items: n
2686
- }), Qt = "\\begin{bmatrix} \\val{M.a} & \\val{M.b} \\\\ \\val{M.c} & \\val{M.d} \\end{bmatrix}", Jt = (t) => [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.1];
2687
- function bi(t = {}) {
2688
- return wt(t, { M: t.matrix ?? yt }, [
3114
+ }), ge = "\\begin{bmatrix} \\val{M.a} & \\val{M.b} \\\\ \\val{M.c} & \\val{M.d} \\end{bmatrix}", be = (t) => [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.1];
3115
+ function Qi(t = {}) {
3116
+ return Ot(t, { M: t.matrix ?? xt }, [
2689
3117
  { id: "grid", kind: "grid", transform: "M", ghost: !0 },
2690
3118
  { id: "square", kind: "polygon", transform: "M", color: "yellow", fillOpacity: 0.25 },
2691
3119
  { id: "basis", kind: "basis", transform: "M" },
2692
- { id: "matrix", kind: "label", tex: Qt, at: Jt(t), screen: !0, align: "left" }
3120
+ { id: "matrix", kind: "label", tex: ge, at: be(t), screen: !0, align: "left" }
2693
3121
  ]);
2694
3122
  }
2695
- function vi(t = {}) {
2696
- return wt(t, { M: t.matrix ?? yt }, [
3123
+ function tr(t = {}) {
3124
+ return Ot(t, { M: t.matrix ?? xt }, [
2697
3125
  { id: "grid", kind: "grid", transform: "M", ghost: !0 },
2698
3126
  { id: "square", kind: "polygon", transform: "M", color: "yellow", fillOpacity: 0.35, label: "\\det = \\val{M.det}" },
2699
3127
  { id: "basis", kind: "basis", transform: "M" },
2700
- { id: "matrix", kind: "label", tex: Qt, at: Jt(t), screen: !0, align: "left" }
3128
+ { id: "matrix", kind: "label", tex: ge, at: be(t), screen: !0, align: "left" }
2701
3129
  ]);
2702
3130
  }
2703
- function wi(t) {
2704
- return wt(t, { M: yt, A: t.matrix }, [
3131
+ function er(t) {
3132
+ return Ot(t, { M: xt, A: t.matrix }, [
2705
3133
  { id: "grid", kind: "grid", transform: "M", ghost: !0 },
2706
3134
  { id: "eigen", kind: "line", eigen: "A", color: "yellow", width: 3 },
2707
3135
  { id: "basis", kind: "basis", transform: "M" },
2708
- { id: "matrix", kind: "label", tex: Qt, at: Jt(t), screen: !0, align: "left" }
3136
+ { id: "matrix", kind: "label", tex: ge, at: be(t), screen: !0, align: "left" }
2709
3137
  ]);
2710
3138
  }
2711
- function ki(t) {
3139
+ function nr(t) {
2712
3140
  const e = [t.u[0] + t.v[0], t.u[1] + t.v[1]];
2713
- return wt(t, { u: t.u, v: t.v, s: e }, [
3141
+ return Ot(t, { u: t.u, v: t.v, s: e }, [
2714
3142
  { id: "grid", kind: "grid", ghost: !1, color: "grey", opacity: 0.5 },
2715
3143
  { id: "axes", kind: "axes" },
2716
3144
  { id: "arrowU", kind: "vector", to: "u", color: "green", label: "\\vec{u}", labelAt: "middle" },
@@ -2718,15 +3146,15 @@ function ki(t) {
2718
3146
  { id: "sum", kind: "vector", to: "s", color: "yellow", label: "\\vec{u} + \\vec{v}" }
2719
3147
  ]);
2720
3148
  }
2721
- function $i(t) {
3149
+ function ir(t) {
2722
3150
  const e = [
2723
3151
  { id: "axes", kind: "axes" },
2724
3152
  { id: "spanU", kind: "line", along: "u", color: "green", dashed: !0 },
2725
3153
  { id: "arrowU", kind: "vector", to: "u", color: "green", label: "\\vec{u}" }
2726
3154
  ], n = { u: t.u };
2727
- return t.v && (n.v = t.v, e.splice(2, 0, { id: "spanV", kind: "line", along: "v", color: "red", dashed: !0 }), e.push({ id: "arrowV", kind: "vector", to: "v", color: "red", label: "\\vec{v}" })), wt(t, n, e);
3155
+ return t.v && (n.v = t.v, e.splice(2, 0, { id: "spanV", kind: "line", along: "v", color: "red", dashed: !0 }), e.push({ id: "arrowV", kind: "vector", to: "v", color: "red", label: "\\vec{v}" })), Ot(t, n, e);
2728
3156
  }
2729
- const dt = (t, e, n) => ({
3157
+ const gt = (t, e, n) => ({
2730
3158
  width: t.width ?? 600,
2731
3159
  height: t.height ?? 600,
2732
3160
  ...t.theme ? { theme: t.theme } : {},
@@ -2735,18 +3163,18 @@ const dt = (t, e, n) => ({
2735
3163
  values: e,
2736
3164
  items: [{ id: "axes", kind: "axes" }, { id: "f", kind: "function", expr: t.expr, color: "blue" }, ...n]
2737
3165
  });
2738
- function xi(t) {
2739
- return dt(t, { a: t.at ?? 1 }, [
3166
+ function rr(t) {
3167
+ return gt(t, { a: t.at ?? 1 }, [
2740
3168
  { id: "tangent", kind: "tangent", expr: t.expr, at: "a", color: "yellow", label: "\\text{slope} = \\val{tangent.slope}" }
2741
3169
  ]);
2742
3170
  }
2743
- function Mi(t) {
2744
- return dt(t, { a: t.at ?? 1, h: t.h ?? 2 }, [
3171
+ function sr(t) {
3172
+ return gt(t, { a: t.at ?? 1, h: t.h ?? 2 }, [
2745
3173
  { id: "secant", kind: "tangent", expr: t.expr, at: "a", h: "h", color: "yellow", label: "\\frac{\\Delta y}{\\Delta x} = \\val{secant.slope}" }
2746
3174
  ]);
2747
3175
  }
2748
- function Si(t) {
2749
- const e = dt(t, { n: t.n ?? 4 }, [
3176
+ function or(t) {
3177
+ const e = gt(t, { n: t.n ?? 4 }, [
2750
3178
  { id: "sum", kind: "riemann", expr: t.expr, from: t.from, to: t.to, n: "n", rule: t.rule ?? "left", color: "teal" }
2751
3179
  ]);
2752
3180
  return e.items.push(e.items.splice(1, 1)[0]), e.items.push({
@@ -2759,8 +3187,8 @@ function Si(t) {
2759
3187
  tex: "n = \\val{sum.n:0} \\quad \\text{sum} = \\val{sum.sum:3} \\quad \\int = \\val{sum.exact:3}"
2760
3188
  }), e;
2761
3189
  }
2762
- function Ei(t) {
2763
- const e = dt(t, { b: t.to }, [
3190
+ function ar(t) {
3191
+ const e = gt(t, { b: t.to }, [
2764
3192
  { id: "area", kind: "area", expr: t.expr, from: t.from, to: "b", color: "teal" }
2765
3193
  ]);
2766
3194
  return e.items.push(e.items.splice(1, 1)[0]), e.items.push({
@@ -2773,8 +3201,8 @@ function Ei(t) {
2773
3201
  tex: `\\int_{${t.from}}^{\\val{b:2}} f(x)\\,dx = \\val{area.value:3}`
2774
3202
  }), e;
2775
3203
  }
2776
- function Ai(t) {
2777
- const e = dt(t, { order: t.order ?? 1 }, [
3204
+ function lr(t) {
3205
+ const e = gt(t, { order: t.order ?? 1 }, [
2778
3206
  { id: "taylor", kind: "taylor", expr: t.expr, at: t.at ?? 0, order: "order", color: "yellow" },
2779
3207
  { id: "centre", kind: "point", on: t.expr, x: t.at ?? 0, color: "yellow" }
2780
3208
  ]);
@@ -2788,8 +3216,8 @@ function Ai(t) {
2788
3216
  tex: "\\text{degree } \\val{taylor.degree:0}"
2789
3217
  }), e;
2790
3218
  }
2791
- function Ti(t) {
2792
- const e = dt(t, { p: t.from ?? t.at - 2 }, [
3219
+ function cr(t) {
3220
+ const e = gt(t, { p: t.from ?? t.at - 2 }, [
2793
3221
  { id: "hole", kind: "point", at: [t.at, t.limit], hollow: !0, color: "blue", radius: 7 },
2794
3222
  { id: "moving", kind: "point", on: t.expr, x: "p", color: "yellow" }
2795
3223
  ]);
@@ -2803,62 +3231,154 @@ function Ti(t) {
2803
3231
  tex: "f(\\val{moving.x:3}) = \\val{moving.y:4}"
2804
3232
  }), e;
2805
3233
  }
2806
- function Oi(t) {
2807
- return bt(t);
3234
+ const dt = (t, e, n, i) => ({
3235
+ width: t.width ?? 600,
3236
+ height: t.height ?? 600,
3237
+ ...t.theme ? { theme: t.theme } : {},
3238
+ x: t.x ?? e.x,
3239
+ y: t.y ?? e.y,
3240
+ values: n,
3241
+ items: i
3242
+ }), bt = (t, e) => ({
3243
+ id: "readout",
3244
+ kind: "label",
3245
+ screen: !0,
3246
+ align: "left",
3247
+ size: 24,
3248
+ at: [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.08],
3249
+ tex: e
3250
+ });
3251
+ function ur(t = {}) {
3252
+ const [e, n] = t.shade ?? [-1, 1];
3253
+ return dt(t, { x: [-4, 4], y: [-0.08, 0.55] }, { mu: t.mean ?? 0, sigma: t.sd ?? 1, a: e, b: n }, [
3254
+ { id: "axes", kind: "axes", ticks: 1, labels: !0 },
3255
+ { id: "dist", kind: "distribution", distribution: { kind: "normal", mean: "mu", sd: "sigma" }, shade: ["a", "b"] },
3256
+ bt(t, "P(\\val{a:2} \\le X \\le \\val{b:2}) = \\val{dist.p:3}")
3257
+ ]);
3258
+ }
3259
+ function dr(t = {}) {
3260
+ const e = t.n ?? 10;
3261
+ return dt(t, { x: [-1, e + 1], y: [-0.04, 0.4] }, { n: e, p: t.p ?? 0.5 }, [
3262
+ { id: "axes", kind: "axes", ticks: Math.max(1, Math.round(e / 10)) },
3263
+ { id: "dist", kind: "distribution", distribution: { kind: "binomial", n: "n", p: "p" } },
3264
+ bt(t, "n = \\val{n:0} \\quad p = \\val{p:2} \\quad \\mu = \\val{dist.mean:2}")
3265
+ ]);
3266
+ }
3267
+ function hr(t = {}) {
3268
+ return dt(t, { x: [-0.2, 3.2], y: [-0.2, 3] }, { k: t.k ?? 1, samples: t.samples ?? 2e3 }, [
3269
+ { id: "axes", kind: "axes", ticks: 1 },
3270
+ { id: "hist", kind: "histogram", distribution: { kind: "mean", of: t.of ?? { kind: "exponential", rate: 1 }, count: "k" }, count: "samples", bins: [0, 3, 45], curve: !0, color: "teal" },
3271
+ bt(t, "k = \\val{k:0} \\text{ draws averaged} \\quad \\bar{x} = \\val{hist.mean:3} \\quad s = \\val{hist.sd:3}")
3272
+ ]);
3273
+ }
3274
+ function pr(t = {}) {
3275
+ const e = t.rows ?? 10;
3276
+ return dt(t, { x: [-(e + 2) * 0.25, (e + 2) * 0.25], y: [-12, 1] }, { balls: t.balls ?? 0 }, [
3277
+ { id: "board", kind: "galton", rows: e, balls: "balls", spacing: 0.5, top: 0 },
3278
+ bt(t, "\\val{board.landed:0} \\text{ balls}")
3279
+ ]);
3280
+ }
3281
+ function fr(t = {}) {
3282
+ return dt(t, { x: [-1.3, 1.3], y: [-1.3, 1.3] }, { count: t.count ?? 0 }, [
3283
+ { id: "square", kind: "polygon", points: [[-1, -1], [1, -1], [1, 1], [-1, 1]], color: "grey", fillOpacity: 0 },
3284
+ { id: "circle", kind: "parametric", x: "cos(t)", y: "sin(t)", color: "yellow", width: 2.5 },
3285
+ { id: "pts", kind: "scatter", points: { kind: "uniform", x: [-1, 1], y: [-1, 1] }, count: "count", inside: "x^2 + y^2 - 1", color: "blue", radius: 2.2 },
3286
+ bt(t, "\\frac{\\text{inside}}{\\text{all}} = \\frac{\\val{pts.inside:0}}{\\val{pts.count:0}} = \\val{pts.ratio:4} \\approx \\frac{\\pi}{4}")
3287
+ ]);
3288
+ }
3289
+ function mr(t = {}) {
3290
+ return dt(t, { x: [-1, 11], y: [-2, 10] }, { slope: t.slope ?? 0.6, intercept: t.intercept ?? 1, noise: t.noise ?? 1, count: t.count ?? 60 }, [
3291
+ { id: "axes", kind: "axes", ticks: 2 },
3292
+ { id: "pts", kind: "scatter", points: { kind: "linear", slope: "slope", intercept: "intercept", noise: "noise", x: [0, 10] }, count: "count", fit: !0, radius: 3.5 },
3293
+ bt(t, "y = \\val{pts.slope:2}\\,x + \\val{pts.intercept:2} \\quad r = \\val{pts.r:2}")
3294
+ ]);
3295
+ }
3296
+ function yr(t = {}) {
3297
+ return dt(t, { x: [0, 1], y: [0, 1] }, { prior: t.prior ?? 0.1, sensitivity: t.sensitivity ?? 0.9, falsePositive: t.falsePositive ?? 0.1 }, [
3298
+ { id: "test", kind: "bayes", prior: "prior", truePositive: "sensitivity", falsePositive: "falsePositive", at: [0.08, 0.2], size: [0.84, 0.66] }
3299
+ ]);
3300
+ }
3301
+ function gr(t) {
3302
+ return Tt(t);
2808
3303
  }
2809
- function Li(t, e = {}, n = {}) {
2810
- return jn(Lt(bt(t), e), n);
3304
+ function br(t, e = {}, n = {}) {
3305
+ return vi(Bt(Tt(t), e), n);
2811
3306
  }
2812
3307
  export {
2813
- Et as CONSTANTS,
2814
- ot as ExpressionError,
2815
- zt as FUNCTIONS,
2816
- ue as ITEM_KINDS,
2817
- tn as MATH_FONT,
2818
- Ut as MATH_THEMES,
2819
- Qt as MATRIX_TEX,
2820
- Dt as SYMBOLS,
2821
- Qe as TEX_COMMANDS,
2822
- Ke as TexError,
2823
- Ei as areaFigure,
2824
- D as compile,
2825
- Yt as compileDerivative,
2826
- vi as determinantFigure,
2827
- G as differentiate,
2828
- jn as displayListToSvg,
2829
- Kt as displayListToSvgContent,
2830
- qn as drawDisplayList,
2831
- wi as eigenFigure,
2832
- at as evaluate,
2833
- Ze as expressionNames,
2834
- $t as expressionToString,
2835
- se as integrate,
2836
- Lt as layoutFigure,
3308
+ Ct as CONSTANTS,
3309
+ zt as DISTRIBUTION_KINDS,
3310
+ ht as ExpressionError,
3311
+ Qt as FUNCTIONS,
3312
+ Ie as ITEM_KINDS,
3313
+ Tn as MATH_FONT,
3314
+ ae as MATH_THEMES,
3315
+ ge as MATRIX_TEX,
3316
+ ne as SYMBOLS,
3317
+ Pn as TEX_COMMANDS,
3318
+ On as TexError,
3319
+ ar as areaFigure,
3320
+ En as ballAt,
3321
+ Se as ballPath,
3322
+ An as bayesAreas,
3323
+ yr as bayesFigure,
3324
+ Ht as binOf,
3325
+ xn as binSamples,
3326
+ dr as binomialFigure,
3327
+ hr as cltFigure,
3328
+ R as compile,
3329
+ he as compileDerivative,
3330
+ xe as defaultBins,
3331
+ st as density,
3332
+ tr as determinantFigure,
3333
+ tt as differentiate,
3334
+ vi as displayListToSvg,
3335
+ ye as displayListToSvgContent,
3336
+ He as distributionProblem,
3337
+ gi as drawDisplayList,
3338
+ er as eigenFigure,
3339
+ rt as evaluate,
3340
+ Me as expressionNames,
3341
+ Pt as expressionToString,
3342
+ pr as galtonFigure,
3343
+ Yt as integrate,
3344
+ _t as isDiscrete,
3345
+ Bt as layoutFigure,
2837
3346
  ut as layoutTex,
2838
- Ti as limitFigure,
2839
- bi as linearMapFigure,
2840
- fi as mat2,
2841
- gi as mathExplorable,
2842
- Oi as mathFigure,
2843
- Dn as mathFigureProps,
2844
- Li as mathFigureToSvg,
2845
- mi as mathSteps,
2846
- pi as mathTarget,
2847
- pn as morphEquation,
2848
- yi as mountAllMath,
2849
- li as mountMath,
2850
- Ge as nthDerivative,
2851
- At as parseExpression,
2852
- Je as parseTex,
2853
- Te as planeOf,
2854
- Si as riemannFigure,
2855
- Mi as secantFigure,
2856
- $i as spanFigure,
2857
- xi as tangentFigure,
2858
- Ai as taylorFigure,
2859
- vt as texToShapes,
2860
- et as trimPolylines,
2861
- bt as validateMathFigure,
2862
- hi as vec2,
2863
- ki as vectorSumFigure
3347
+ Ye as leastSquares,
3348
+ cr as limitFigure,
3349
+ Qi as linearMapFigure,
3350
+ Yi as mat2,
3351
+ Ji as mathExplorable,
3352
+ gr as mathFigure,
3353
+ wi as mathFigureProps,
3354
+ br as mathFigureToSvg,
3355
+ Gi as mathSteps,
3356
+ Zi as mathTarget,
3357
+ At as meanOf,
3358
+ fr as monteCarloPiFigure,
3359
+ Kn as morphEquation,
3360
+ Ki as mountAllMath,
3361
+ Bi as mountMath,
3362
+ ur as normalFigure,
3363
+ $n as nthDerivative,
3364
+ lt as parseExpression,
3365
+ Nn as parseTex,
3366
+ on as planeOf,
3367
+ mr as regressionFigure,
3368
+ or as riemannFigure,
3369
+ We as sample,
3370
+ Ue as samples,
3371
+ Xe as scatterPoints,
3372
+ Et as sdOf,
3373
+ sr as secantFigure,
3374
+ ir as spanFigure,
3375
+ Sn as summary,
3376
+ Mn as supportOf,
3377
+ rr as tangentFigure,
3378
+ lr as taylorFigure,
3379
+ yt as texToShapes,
3380
+ G as trimPolylines,
3381
+ Tt as validateMathFigure,
3382
+ Xi as vec2,
3383
+ nr as vectorSumFigure
2864
3384
  };