@algorisys/tinyfly 0.116.0 → 0.118.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +6 -6
  2. package/docs/editor-guide.md +1 -1
  3. package/docs/examples.md +1 -1
  4. package/docs/getting-started.md +1 -1
  5. package/docs/gsap-compat.md +1 -1
  6. package/docs/llm-guide.md +5 -1
  7. package/docs/maps.md +2 -2
  8. package/docs/math.md +68 -9
  9. package/docs/teaching.md +1 -1
  10. package/lib/addons/characters.js +1661 -1649
  11. package/lib/addons/math.js +2134 -1184
  12. package/lib/browser/tinyfly-math.iife.js +4 -4
  13. package/lib/browser/tinyfly.iife.js +12 -12
  14. package/lib/browser/tinyfly.js +306 -280
  15. package/lib/browser/tinyfly.umd.js +12 -12
  16. package/lib/engine/tinyfly-engine.js +112 -98
  17. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  18. package/lib/types/engine/authoring/random.d.ts +7 -0
  19. package/lib/types/math/discrete/graph-search.d.ts +38 -0
  20. package/lib/types/math/discrete/set-expression.d.ts +33 -0
  21. package/lib/types/math/figure/display-list.d.ts +8 -0
  22. package/lib/types/math/figure/figure-spec.d.ts +178 -1
  23. package/lib/types/math/figure/item-context.d.ts +7 -1
  24. package/lib/types/math/figure/items/discrete.d.ts +23 -0
  25. package/lib/types/math/figure/items/probability.d.ts +13 -0
  26. package/lib/types/math/figure/items/shapes.d.ts +3 -0
  27. package/lib/types/math/index.d.ts +10 -1
  28. package/lib/types/math/presets/discrete.d.ts +49 -0
  29. package/lib/types/math/presets/probability.d.ts +62 -0
  30. package/lib/types/math/prob/bayes.d.ts +16 -0
  31. package/lib/types/math/prob/distributions.d.ts +58 -0
  32. package/lib/types/math/prob/galton.d.ts +18 -0
  33. package/lib/types/math/prob/histogram.d.ts +20 -0
  34. package/lib/types/math/prob/scatter.d.ts +24 -0
  35. package/lib/types/math/tex/glyph-metrics.d.ts +8 -0
  36. package/lib/types/math/tex/tex-parser.d.ts +2 -1
  37. package/llms-full.txt +93 -18
  38. package/llms.txt +31 -31
  39. package/package.json +1 -1
  40. package/skills/tinyfly/SKILL.md +4 -1
@@ -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 Ye, createRandom as we, hashSeed as Kt, closestName as En, unknownName as W, deserializeTimeline as Ie, playheadCrossings as Tn } from "@algorisys/tinyfly";
2
+ import { D as Ne } from "./dom-adapter-Cphr2HZn.js";
3
+ const On = (t, e) => [t[0] + e[0], t[1] + e[1]], ke = (t, e) => [t[0] - e[0], t[1] - e[1]], le = (t, e) => [t[0] * e, t[1] * e], Pn = (t, e) => t[0] * e[0] + t[1] * e[1], In = (t, e) => t[0] * e[1] - t[1] * e[0], Ze = (t) => Math.hypot(t[0], t[1]);
4
+ function St(t) {
5
+ const e = Ze(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 Nn = (t, e, n) => [t[0] + (e[0] - t[0]) * n, t[1] + (e[1] - t[1]) * n];
9
+ function at(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 kr = /* @__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: On,
15
+ cross: In,
16
+ dot: Pn,
17
+ isVec2: at,
18
+ length: Ze,
19
+ lerp: Nn,
20
+ normalize: St,
21
+ scale: le,
22
+ sub: ke
23
+ }, Symbol.toStringTag, { value: "Module" })), Tt = [1, 0, 0, 1], K = ([t, e, n, i], [r, s]) => [t * r + e * s, n * r + i * s];
24
+ function Ln(t, e) {
25
+ const [n, i, r, s] = t, [o, l, c, d] = e;
26
+ return [n * o + i * c, n * l + i * d, r * o + s * c, r * l + s * d];
27
+ }
28
+ const Ot = ([t, e, n, i]) => t * i - e * n;
29
+ function Fn(t) {
30
+ const e = Ot(t);
31
31
  if (Math.abs(e) < 1e-12) return;
32
32
  const [n, i, r, s] = t;
33
33
  return [s / e, -i / e, -r / 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 Cn = (t, e, n) => t.map((i, r) => i + (e[r] - i) * n), qn = (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 = Ot(t), l = s * s - 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 ? [s / 2] : [(s + d) / 2, (s - d) / 2], p = [];
40
+ for (const h of u) {
41
+ const f = [[e - h, n], [i, r - h]].reduce((b, x) => Math.hypot(...x) > Math.hypot(...b) ? x : b);
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 m = [-f[1], f[0]], a = Math.hypot(...m), g = m[0] < -c || Math.abs(m[0]) <= c && m[1] < 0 ? -1 : 1;
47
+ p.push({ value: h, vector: [g * m[0] / a + 0, g * m[1] / a + 0] });
48
48
  }
49
- return h;
49
+ return p;
50
50
  }
51
- function lt(t) {
51
+ function gt(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 $r = /* @__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: Tt,
57
+ apply: K,
58
+ determinant: Ot,
59
+ eigen: Ke,
60
+ inverse: Fn,
61
+ isMat2: gt,
62
+ lerp: Cn,
63
+ multiply: Ln,
64
+ rotation: qn
65
+ }, Symbol.toStringTag, { value: "Module" })), ce = {
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
+ }, Wt = { pi: Math.PI, e: Math.E, tau: Math.PI * 2 };
92
+ class yt 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 zn(t) {
101
101
  const e = [];
102
102
  let n = 0;
103
103
  for (; n < t.length; ) {
@@ -120,178 +120,178 @@ function Ye(t) {
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 yt(`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 dt(t) {
128
128
  if (typeof t != "string") throw new TypeError("parseExpression: expected a string");
129
- const e = Ye(t);
129
+ const e = zn(t);
130
130
  let n = 0;
131
- const i = () => e[n], r = (d) => {
131
+ const i = () => e[n], r = (h) => {
132
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);
133
+ return y.kind === "op" && y.value === h;
134
+ }, s = (h) => {
135
+ if (!r(h)) throw new yt(`Expected "${h}"`, t, i().at);
136
136
  n++;
137
137
  }, o = () => {
138
- let d = l();
138
+ let h = l();
139
139
  for (; r("+") || r("-"); )
140
- d = { type: "binary", operator: e[n++].value, left: d, right: l() };
141
- return d;
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
145
  if (r("*") || r("/"))
146
- d = { type: "binary", operator: e[n++].value, left: d, right: c() };
146
+ h = { type: "binary", operator: e[n++].value, left: h, right: c() };
147
147
  else if (i().kind === "name" || i().kind === "number" || r("("))
148
- d = { type: "binary", operator: "*", left: d, right: f() };
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 = () => r("-") || r("+") ? { type: "unary", operator: e[n++].value, operand: c() } : d(), d = () => {
152
+ const h = u();
153
+ return r("^") ? (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++, !r("(")) return { type: "name", name: h.value };
160
+ const y = Object.prototype.hasOwnProperty.call(ce, h.value) ? ce[h.value] : void 0;
161
+ if (!y) throw new yt(`Unknown function "${h.value}"`, t, h.at);
162
162
  n++;
163
- const a = [];
163
+ const f = [];
164
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 };
165
+ for (f.push(o()); r(","); )
166
+ n++, f.push(o());
167
+ if (s(")"), f.length !== y.arity)
168
+ throw new yt(`"${h.value}" takes ${y.arity} argument${y.arity === 1 ? "" : "s"}, got ${f.length}`, t, h.at);
169
+ return { type: "call", name: h.value, args: f };
170
170
  }
171
171
  if (r("(")) {
172
172
  n++;
173
173
  const y = o();
174
174
  return s(")"), y;
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 yt(h.kind === "end" ? "Unexpected end" : `Unexpected "${h.value}"`, t, h.at);
177
+ }, p = o();
178
+ if (i().kind !== "end") throw new yt(`Unexpected "${i().value}"`, t, i().at);
179
+ return p;
180
180
  }
181
- function Ze(t) {
181
+ function Le(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 Wt) ? 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 N = (t) => ({ type: "number", value: t }), xt = N(0), C = N(1), _ = (t) => t.type === "number", G = (t, e) => t.type === "number" && t.value === e;
188
+ function ot(t, e) {
189
+ return _(t) && _(e) ? N(t.value + e.value) : G(t, 0) ? e : G(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 tt(t, e) {
192
+ return _(t) && _(e) ? N(t.value - e.value) : G(e, 0) ? t : G(t, 0) ? _t(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 L(t, e) {
195
+ return _(t) && _(e) ? N(t.value * e.value) : G(t, 0) || G(e, 0) ? xt : G(t, 1) ? e : G(e, 1) ? t : _(e) ? L(e, t) : _(t) && e.type === "binary" && e.operator === "*" && _(e.left) ? L(N(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 V(t, e) {
198
+ return G(t, 0) ? xt : G(e, 1) ? t : _(t) && _(e) && e.value !== 0 ? N(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 rt(t, e) {
201
+ return G(e, 0) ? C : G(e, 1) ? t : _(t) && _(e) ? N(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 _t(t) {
204
+ return _(t) ? N(-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 H = (t, ...e) => ({ type: "call", name: t, args: e });
207
+ function ut(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 ut(t.operand, e);
215
215
  case "binary":
216
- return rt(t.left, e) && rt(t.right, e);
216
+ return ut(t.left, e) && ut(t.right, e);
217
217
  case "call":
218
- return t.args.every((n) => rt(n, e));
218
+ return t.args.every((n) => ut(n, e));
219
219
  }
220
220
  }
221
- function G(t, e = "x") {
222
- if (rt(t, e)) return ft;
221
+ function st(t, e = "x") {
222
+ if (ut(t, e)) return xt;
223
223
  switch (t.type) {
224
224
  case "number":
225
- return ft;
225
+ return xt;
226
226
  case "name":
227
- return t.name === e ? O : ft;
227
+ return t.name === e ? C : xt;
228
228
  case "unary":
229
- return t.operator === "-" ? Mt(G(t.operand, e)) : G(t.operand, e);
229
+ return t.operator === "-" ? _t(st(t.operand, e)) : st(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, r = () => st(n, e), s = () => st(i, e);
232
232
  switch (t.operator) {
233
233
  case "+":
234
- return J(r(), s());
234
+ return ot(r(), s());
235
235
  case "-":
236
- return H(r(), s());
236
+ return tt(r(), s());
237
237
  case "*":
238
- return J(A(r(), i), A(n, s()));
238
+ return ot(L(r(), i), L(n, s()));
239
239
  case "/":
240
- return q(H(A(r(), i), A(n, s())), Z(i, E(2)));
240
+ return V(tt(L(r(), i), L(n, s())), rt(i, N(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 (ut(i, e)) {
243
+ const o = _(i) ? N(i.value - 1) : tt(i, C);
244
+ return L(L(i, rt(n, o)), r());
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 ut(n, e) ? L(L(t, H("ln", n)), s()) : L(t, ot(L(s(), H("ln", n)), V(L(i, r()), 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, r = () => st(n, e), s = (o) => L(o, r());
252
252
  switch (t.name) {
253
253
  case "sin":
254
- return s(z("cos", n));
254
+ return s(H("cos", n));
255
255
  case "cos":
256
- return s(Mt(z("sin", n)));
256
+ return s(_t(H("sin", n)));
257
257
  case "tan":
258
- return s(q(O, Z(z("cos", n), E(2))));
258
+ return s(V(C, rt(H("cos", n), N(2))));
259
259
  case "asin":
260
- return s(q(O, z("sqrt", H(O, Z(n, E(2))))));
260
+ return s(V(C, H("sqrt", tt(C, rt(n, N(2))))));
261
261
  case "acos":
262
- return s(Mt(q(O, z("sqrt", H(O, Z(n, E(2)))))));
262
+ return s(_t(V(C, H("sqrt", tt(C, rt(n, N(2)))))));
263
263
  case "atan":
264
- return s(q(O, J(O, Z(n, E(2)))));
264
+ return s(V(C, ot(C, rt(n, N(2)))));
265
265
  case "sinh":
266
- return s(z("cosh", n));
266
+ return s(H("cosh", n));
267
267
  case "cosh":
268
- return s(z("sinh", n));
268
+ return s(H("sinh", n));
269
269
  case "tanh":
270
- return s(H(O, Z(z("tanh", n), E(2))));
270
+ return s(tt(C, rt(H("tanh", n), N(2))));
271
271
  case "exp":
272
272
  return s(t);
273
273
  case "ln":
274
- return s(q(O, n));
274
+ return s(V(C, n));
275
275
  case "log":
276
- return s(q(O, A(n, E(Math.LN10))));
276
+ return s(V(C, L(n, N(Math.LN10))));
277
277
  case "log2":
278
- return s(q(O, A(n, E(Math.LN2))));
278
+ return s(V(C, L(n, N(Math.LN2))));
279
279
  case "sqrt":
280
- return s(q(O, A(E(2), t)));
280
+ return s(V(C, L(N(2), t)));
281
281
  case "abs":
282
- return s(z("sign", n));
282
+ return s(H("sign", n));
283
283
  case "sigmoid":
284
- return s(A(t, H(O, t)));
284
+ return s(L(t, tt(C, t)));
285
285
  case "relu":
286
- return s(q(J(z("sign", n), O), E(2)));
286
+ return s(V(ot(H("sign", n), C), N(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 = st(i, e);
289
+ return V(tt(L(i, r()), L(n, o)), ot(rt(n, N(2)), rt(i, N(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 = st(i, e), c = V(ot(C, L(N(o), H("sign", tt(n, i)))), N(2));
294
+ return ot(L(c, r()), L(tt(C, 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 jn(t, e, n = "x") {
303
303
  let i = t;
304
- for (let r = 0; r < e; r++) i = G(i, n);
304
+ for (let r = 0; r < e; r++) i = st(i, n);
305
305
  return i;
306
306
  }
307
- function $t(t) {
307
+ function Ct(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}${Ct(t.operand)})`;
315
315
  case "binary":
316
- return `(${$t(t.left)} ${t.operator} ${$t(t.right)})`;
316
+ return `(${Ct(t.left)} ${t.operator} ${Ct(t.right)})`;
317
317
  case "call":
318
- return `${t.name}(${t.args.map($t).join(", ")})`;
318
+ return `${t.name}(${t.args.map(Ct).join(", ")})`;
319
319
  }
320
320
  }
321
- function at(t, e = {}) {
321
+ function lt(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(Wt, t.name)) return Wt[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 = lt(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 = lt(t.left, e), i = lt(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 ce[t.name].apply(...t.args.map((n) => lt(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 Rt = /* @__PURE__ */ new Map();
356
+ function U(t, e = "x") {
357
+ let n = Rt.get(t);
358
+ n || (n = dt(t), Rt.size < 256 && Rt.set(t, n));
359
359
  const i = n;
360
- return (r, s = {}) => at(i, { ...s, [e]: r });
360
+ return (r, s = {}) => lt(i, { ...s, [e]: r });
361
361
  }
362
- const Nt = /* @__PURE__ */ new Map();
363
- function Yt(t, e, n = "x") {
362
+ const ne = /* @__PURE__ */ new Map();
363
+ function $e(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);
366
+ let r = ne.get(i);
367
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);
368
+ let o = Rt.get(t);
369
+ o || (o = dt(t)), r = jn(o, e, n), ne.size < 512 && ne.set(i, r);
370
370
  }
371
371
  const s = r;
372
- return (o, l = {}) => at(s, { ...l, [n]: o });
372
+ return (o, l = {}) => lt(s, { ...l, [n]: o });
373
373
  }
374
- function $e(t) {
374
+ function Je(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)) {
379
+ else if (gt(i)) {
380
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]) });
381
+ Object.assign(e, { [`${n}.a`]: r, [`${n}.b`]: s, [`${n}.c`]: o, [`${n}.d`]: l, [`${n}.det`]: Ot(i) });
382
+ } else at(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 O(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 At(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 (!at(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 pt(t, e) {
395
+ if (e === void 0) return Tt;
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 (!gt(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 T(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 bt(t, e) {
407
+ const n = (r) => r === void 0 ? void 0 : T(t, r), i = (r) => r === void 0 ? void 0 : Math.round(T(t, r));
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: bt(t, e.of), count: i(e.count) };
423
+ }
424
+ }
425
+ const Ut = ["normal", "uniform", "exponential", "binomial", "poisson", "dice", "mean"];
426
+ function Dn(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];
420
- });
438
+ function Jt(t) {
439
+ return t.kind === "binomial" || t.kind === "poisson" || t.kind === "dice";
421
440
  }
422
- const Me = (t) => Math.min(400, Math.max(1, Math.round(t)));
423
- 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;
441
+ const Bt = /* @__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
+ })(), ie = (t, e) => Math.exp(Bt(t) - Bt(e) - Bt(t - e));
448
+ function ct(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));
451
453
  }
452
- return i;
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 : ie(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 - Bt(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 r = 0;
470
+ for (let s = 0; s <= Math.floor((e - n) / i); s++)
471
+ r += (s % 2 ? -1 : 1) * ie(n, s) * ie(e - i * s - 1, n - 1);
472
+ return r / i ** n;
473
+ }
474
+ case "mean":
475
+ return t.count === 1 ? ct(t.of, e) : ct({ kind: "normal", mean: Pt(t.of), sd: It(t.of) / Math.sqrt(t.count) }, e);
476
+ }
477
+ }
478
+ function Pt(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 Pt(t.of);
494
+ }
495
+ }
496
+ function It(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 It(t.of) / Math.sqrt(t.count);
512
+ }
513
+ }
514
+ function Qe(t, e) {
515
+ switch (t.kind) {
516
+ case "normal":
517
+ return Ye(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, r = e.next();
530
+ for (; r > n; )
531
+ i++, r *= 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 += Qe(t.of, e);
542
+ return n / t.count;
543
+ }
544
+ }
545
+ }
546
+ const qt = /* @__PURE__ */ new Map();
547
+ function tn(t, e, n) {
548
+ const i = `${JSON.stringify(t)}|${e}`;
549
+ let r = qt.get(i);
550
+ if (r || (r = [], qt.size > 64 && qt.clear(), qt.set(i, r)), r.length < n) {
551
+ const s = we(typeof e == "number" ? e : Kt(e)), o = [];
552
+ for (let l = 0; l < n; l++) o.push(Qe(t, s));
553
+ r.splice(0, r.length, ...o);
554
+ }
555
+ return r.slice(0, n);
556
+ }
557
+ function en(t) {
558
+ if (!t || typeof t != "object" || !Ut.includes(t.kind)) return `kind must be one of ${Ut.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 ? en(t.of) : "count must be a whole number 1..200";
575
+ }
576
+ }
577
+ function Fe(t) {
578
+ const e = Pt(t), n = It(t);
579
+ if (Jt(t)) {
580
+ const [i, r] = Dn(t), s = Math.max(i, Math.floor(e - 4 * n)), o = Math.min(r, Math.ceil(e + 4 * n));
581
+ return [s - 0.5, o + 0.5, o - s + 1];
582
+ }
583
+ return [e - 4 * n, e + 4 * n, 30];
584
+ }
585
+ function _n(t, [e, n, i], r) {
586
+ const s = (n - e) / i, o = new Array(i).fill(0);
587
+ for (const c of t) {
588
+ const d = Math.floor((c - e) / s);
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 * s,
594
+ right: e + (d + 1) * s,
595
+ count: c,
596
+ height: r === "density" ? c / (l * s) : c
597
+ }));
598
+ }
599
+ function Rn(t) {
600
+ if (t.length === 0) return { mean: 0, sd: 0 };
601
+ const e = t.reduce((i, r) => i + r, 0) / t.length, n = t.reduce((i, r) => i + (r - e) ** 2, 0) / t.length;
602
+ return { mean: e, sd: Math.sqrt(n) };
603
+ }
604
+ function nn(t, e, n) {
605
+ const i = we(typeof e == "number" ? e : Kt(e));
606
+ return Array.from({ length: Math.max(0, Math.floor(n)) }, () => {
607
+ const r = i.next();
608
+ if (t.kind === "uniform") {
609
+ const o = i.next();
610
+ return [t.x[0] + r * (t.x[1] - t.x[0]), t.y[0] + o * (t.y[1] - t.y[0])];
611
+ }
612
+ const s = t.x[0] + r * (t.x[1] - t.x[0]);
613
+ return [s, t.slope * s + t.intercept + t.noise * Ye(i)];
614
+ });
615
+ }
616
+ function rn(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 r = 0, s = 0, o = 0;
621
+ for (const [c, d] of t)
622
+ r += (c - n) * (d - i), s += (c - n) ** 2, o += (d - i) ** 2;
623
+ if (s === 0) return;
624
+ const l = r / s;
625
+ return { slope: l, intercept: i - l * n, r: o === 0 ? 0 : r / Math.sqrt(s * o) };
626
+ }
627
+ function Bn(t, e, n) {
628
+ const i = Math.min(1, Math.max(0, t)), r = i * Math.min(1, Math.max(0, e)), s = (1 - i) * Math.min(1, Math.max(0, n)), o = r + s;
629
+ return { truePositive: r, falsePositive: s, positive: o, posterior: o > 0 ? r / o : 0 };
630
+ }
631
+ function Ce(t, e, n) {
632
+ const i = we(Kt(`${t}:${e}`));
633
+ return Array.from({ length: n }, () => i.next() < 0.5);
634
+ }
635
+ const re = (t) => t.filter(Boolean).length;
636
+ function Vn(t, e) {
637
+ const n = t.length, i = Math.min(1, Math.max(0, e)) * n, r = Math.min(n - 1, Math.floor(i)), s = i - r, l = t.slice(0, r).filter(Boolean).length - r / 2, c = l + (t[r] ? 0.5 : -0.5), d = 0.18 * Math.sin(Math.PI * s);
638
+ return { x: l + (c - l) * s, depth: r + s - d };
639
+ }
640
+ const Hn = '"Latin Modern Math", "STIX Two Math", "Cambria Math", "Times New Roman", "Liberation Serif", "Noto Serif", Times, serif', Wn = '"Latin Modern Math", "STIX Two Math", "Cambria Math", "DejaVu Math TeX Gyre", "DejaVu Serif", serif', Un = (t) => /^[A-Za-z0-9\u0370-\u03ff.,;:!?()[\]'"/ ]+$/.test(t) ? Hn : Wn, sn = 0.25, Et = 0.05, qe = {
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 ue(t) {
695
+ return t.length !== 1 ? t.length * 0.5 : /[0-9]/.test(t) ? 0.5 : Object.prototype.hasOwnProperty.call(qe, t) ? qe[t] + 0.04 : "()[]".includes(t) ? 0.39 : "{}".includes(t) ? 0.5 : "|".includes(t) || ",.;:!".includes(t) || "'’‘".includes(t) ? 0.28 : "-‐".includes(t) ? 0.33 : "′″".includes(t) ? 0.3 : "+−=<>±×÷≤≥≠≈∼≡∝→←↔⇒⇔∈∉⊂⊃⊆⊇∪∩∧∨".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;
453
696
  }
454
- const jt = {
697
+ function on(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 de = {
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
+ }, he = {
491
737
  cdot: ["·", "bin"],
492
738
  times: ["×", "bin"],
493
739
  div: ["÷", "bin"],
@@ -499,6 +745,18 @@ const jt = {
499
745
  land: ["∧", "bin"],
500
746
  lor: ["∨", "bin"],
501
747
  setminus: ["∖", "bin"],
748
+ triangle: ["△", "bin"],
749
+ oplus: ["⊕", "bin"],
750
+ otimes: ["⊗", "bin"],
751
+ ominus: ["⊖", "bin"],
752
+ varnothing: ["∅", "ord"],
753
+ complement: ["∁", "ord"],
754
+ nsubseteq: ["⊈", "rel"],
755
+ ni: ["∋", "rel"],
756
+ mapsfrom: ["↤", "rel"],
757
+ gets: ["←", "rel"],
758
+ vdash: ["⊢", "rel"],
759
+ models: ["⊨", "rel"],
502
760
  le: ["≤", "rel"],
503
761
  leq: ["≤", "rel"],
504
762
  ge: ["≥", "rel"],
@@ -543,7 +801,7 @@ const jt = {
543
801
  rangle: ["⟩", "close"],
544
802
  lbrace: ["{", "open"],
545
803
  rbrace: ["}", "close"]
546
- }, _t = { sum: ["∑", !0], prod: ["∏", !0], int: ["∫", !1], oint: ["∮", !1] }, Rt = {
804
+ }, pe = { sum: ["∑", !0], prod: ["∏", !0], int: ["∫", !1], oint: ["∮", !1] }, fe = {
547
805
  sin: !1,
548
806
  cos: !1,
549
807
  tan: !1,
@@ -564,8 +822,8 @@ const jt = {
564
822
  Pr: !1,
565
823
  E: !1,
566
824
  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 {
825
+ }, ye = { ",": 3 / 18, ":": 4 / 18, ";": 5 / 18, "!": -3 / 18, quad: 1, qquad: 2 }, ze = /* @__PURE__ */ new Set(["pmatrix", "bmatrix", "vmatrix", "matrix"]);
826
+ class Gn extends Error {
569
827
  source;
570
828
  /** 0-based index into the source */
571
829
  position;
@@ -573,13 +831,14 @@ class Ke extends Error {
573
831
  super(`${e} at ${i + 1} in "${n}"`), this.name = "TexError", this.source = n, this.position = i;
574
832
  }
575
833
  }
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),
834
+ const Xn = [
835
+ ...Object.keys(de),
836
+ ...Object.keys(he),
837
+ ...Object.keys(pe),
838
+ ...Object.keys(fe),
839
+ ...Object.keys(ye).filter((t) => t.length > 1),
582
840
  "frac",
841
+ "binom",
583
842
  "sqrt",
584
843
  "vec",
585
844
  "hat",
@@ -593,13 +852,13 @@ const Qe = [
593
852
  "left",
594
853
  "right"
595
854
  ].sort();
596
- function Je(t) {
855
+ function Yn(t) {
597
856
  if (typeof t != "string") throw new TypeError("parseTex: expected a string");
598
857
  let e = 0;
599
858
  const n = () => {
600
859
  for (; e < t.length && /\s/.test(t[e]); ) e++;
601
- }, i = (u, h = e) => {
602
- throw new Ke(u, t, h);
860
+ }, i = (u, p = e) => {
861
+ throw new Gn(u, t, p);
603
862
  }, r = () => {
604
863
  const u = e;
605
864
  if (/[A-Za-z]/.test(t[e] ?? ""))
@@ -608,217 +867,164 @@ function Je(t) {
608
867
  return t.slice(u, e);
609
868
  }, s = (u) => {
610
869
  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;
870
+ const p = t.indexOf("}", e);
871
+ p < 0 && i(`Missing "}" for ${u}`);
872
+ const h = t.slice(e + 1, p);
873
+ return e = p + 1, h;
615
874
  }, o = (u) => {
616
875
  if (n(), e >= t.length && i(`Missing ${u}`), t[e] === "{") {
617
876
  e++;
618
- const d = l("}");
619
- return e++, { type: "group", body: d };
877
+ const h = l("}");
878
+ return e++, { type: "group", body: h };
620
879
  }
621
- const h = c();
622
- return h || i(`Missing ${u}`), h;
880
+ const p = c();
881
+ return p || i(`Missing ${u}`), p;
623
882
  }, l = (u) => {
624
- const h = [];
883
+ const p = [];
625
884
  for (; ; ) {
626
885
  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;
886
+ return u === "}" && i('Missing "}"'), u === "cell" && i("Missing \\end"), p;
887
+ if (u === "}" && t[e] === "}" || (t[e] === "}" && i('Unexpected "}"'), u === "cell" && (t[e] === "&" || t.startsWith("\\\\", e) || t.startsWith("\\end", e)))) return p;
629
888
  if (t[e] === "^" || t[e] === "_") {
630
- const y = e, a = t[e] === "^";
889
+ const y = e, f = t[e] === "^";
631
890
  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);
891
+ const m = o(f ? "superscript" : "subscript");
892
+ let a = p.pop() ?? { type: "group", body: [] };
893
+ a.type !== "scripts" && (a = { type: "scripts", base: a }), a.type === "scripts" && ((f && a.sup || !f && a.sub) && i(`Double ${f ? "superscript" : "subscript"}`, y), f ? a.sup = m : a.sub = m), p.push(a);
635
894
  continue;
636
895
  }
637
896
  if (t[e] === "'") {
638
897
  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 });
898
+ const y = { type: "symbol", text: "′", cls: "ord", italic: !1 }, f = p.pop() ?? { type: "group", body: [] };
899
+ p.push(f.type === "scripts" && !f.sup ? { ...f, sup: y } : { type: "scripts", base: f, sup: y });
641
900
  continue;
642
901
  }
643
- const d = c();
644
- d && h.push(d);
902
+ const h = c();
903
+ h && p.push(h);
645
904
  }
646
905
  }, c = () => {
647
906
  const u = t[e];
648
907
  if (u === "{") {
649
908
  e++;
650
- const h = l("}");
651
- return e++, { type: "group", body: h };
909
+ const p = l("}");
910
+ return e++, { type: "group", body: p };
652
911
  }
653
912
  if (u === "&" && i('"&" outside a matrix'), u === "\\") {
654
- const h = e;
913
+ const p = e;
655
914
  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 };
915
+ const h = r();
916
+ if (h === "\\" && i('"\\\\" outside a matrix', p), h in ye) return { type: "space", width: ye[h] };
917
+ if (h === "{" || h === "}") return { type: "symbol", text: h, cls: h === "{" ? "open" : "close", italic: !1 };
918
+ if (h === "|") return { type: "symbol", text: "‖", cls: "ord", italic: !1 };
919
+ if (Object.prototype.hasOwnProperty.call(de, h))
920
+ return { type: "symbol", text: de[h], cls: "ord", italic: h[0] === h[0].toLowerCase() };
921
+ if (Object.prototype.hasOwnProperty.call(he, h)) {
922
+ const [f, m] = he[h];
923
+ return { type: "symbol", text: f, cls: m, italic: !1 };
665
924
  }
666
- if (Object.prototype.hasOwnProperty.call(_t, d)) {
667
- const [a, p] = _t[d];
668
- return { type: "bigop", text: a, limits: p };
925
+ if (Object.prototype.hasOwnProperty.call(pe, h)) {
926
+ const [f, m] = pe[h];
927
+ return { type: "bigop", text: f, limits: m };
669
928
  }
670
- if (Object.prototype.hasOwnProperty.call(Rt, d)) return { type: "opname", text: d, limits: Rt[d] };
671
- switch (d) {
929
+ if (Object.prototype.hasOwnProperty.call(fe, h)) return { type: "opname", text: h, limits: fe[h] };
930
+ switch (h) {
672
931
  case "frac":
673
932
  return { type: "frac", num: o("numerator"), den: o("denominator") };
933
+ case "binom": {
934
+ const f = o("\\binom's top"), m = o("\\binom's bottom");
935
+ return {
936
+ type: "group",
937
+ body: [{ type: "symbol", text: "(", cls: "open", italic: !1 }, { type: "frac", num: f, den: m, bar: !1 }, { type: "symbol", text: ")", cls: "close", italic: !1 }]
938
+ };
939
+ }
674
940
  case "sqrt":
675
941
  return { type: "sqrt", body: o("the square root's body") };
676
942
  case "vec":
677
943
  case "hat":
678
944
  case "bar":
679
- return { type: "accent", accent: d, body: o(`\\${d}'s body`) };
945
+ return { type: "accent", accent: h, body: o(`\\${h}'s body`) };
680
946
  case "text":
681
947
  return { type: "text", text: s("\\text") };
682
948
  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") };
949
+ const f = s("\\color").trim();
950
+ 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
951
  }
686
952
  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") };
953
+ const f = s("\\id").trim();
954
+ return /^[\w.-]+$/.test(f) || i(`"${f}" is not a term id (letters, digits, _ . -)`, p), { type: "id", id: f, body: o("\\id's body") };
689
955
  }
690
956
  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]) };
957
+ const f = s("\\val").trim(), m = /^([A-Za-z_][\w.]*)(?::(\d))?$/.exec(f);
958
+ return m || i(`"${f}" is not a value name (name or name:digits)`, p), { type: "value", name: m[1], digits: m[2] === void 0 ? 2 : Number(m[2]) };
693
959
  }
694
960
  case "left":
695
961
  case "right": {
696
962
  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 };
963
+ const f = t[e] === "\\" ? (e++, r()) : t[e++];
964
+ if (f === ".") return { type: "space", width: 0 };
965
+ const a = { "(": "(", ")": ")", "[": "[", "]": "]", "|": "|", "{": "{", "}": "}", langle: "⟨", rangle: "⟩", "|.": "‖" }[f];
966
+ return a || i(`"${f}" is not a delimiter`, p), { type: "symbol", text: a, cls: h === "left" ? "open" : "close", italic: !1 };
701
967
  }
702
968
  case "begin": {
703
- const a = s("\\begin").trim();
704
- oe.has(a) || i(`Unknown environment "${a}" (use ${[...oe].join(", ")})`, h);
705
- const p = [[]];
969
+ const f = s("\\begin").trim();
970
+ ze.has(f) || i(`Unknown environment "${f}" (use ${[...ze].join(", ")})`, p);
971
+ const m = [[]];
706
972
  for (; ; ) {
707
- const m = l("cell");
708
- if (p[p.length - 1].push({ type: "group", body: m }), t[e] === "&")
973
+ const a = l("cell");
974
+ if (m[m.length - 1].push({ type: "group", body: a }), t[e] === "&")
709
975
  e++;
710
976
  else if (t.startsWith("\\\\", e))
711
- e += 2, p.push([]);
977
+ e += 2, m.push([]);
712
978
  else {
713
979
  e += 4;
714
- const b = s("\\end").trim();
715
- b !== a && i(`\\begin{${a}} ended by \\end{${b}}`);
980
+ const g = s("\\end").trim();
981
+ g !== f && i(`\\begin{${f}} ended by \\end{${g}}`);
716
982
  break;
717
983
  }
718
984
  }
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 };
985
+ return m.length > 1 && m[m.length - 1].every((a) => a.type === "group" && a.body.length === 0) && m.pop(), { type: "matrix", delimiters: f, rows: m };
720
986
  }
721
987
  case "end":
722
- return i("\\end without \\begin", h);
988
+ return i("\\end without \\begin", p);
723
989
  }
724
- const y = je(d, Qe);
725
- return i(`Unknown command "\\${d}"${y ? ` (did you mean "\\${y}"?)` : ""}`, h);
990
+ const y = En(h, Xn);
991
+ return i(`Unknown command "\\${h}"${y ? ` (did you mean "\\${y}"?)` : ""}`, p);
726
992
  }
727
993
  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
994
  };
729
995
  return { type: "group", body: l("") };
730
996
  }
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) {
997
+ const nt = [1, 1, 0.7, 0.5], Zn = (t) => t <= 1 ? 2 : 3, Kn = (t) => Math.min(3, t + 1), Me = () => ({ width: 0, height: 0, depth: 0, pieces: [] });
998
+ function et(t, e, n) {
793
999
  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 });
794
1000
  }
795
- function ct(t, e) {
1001
+ function vt(t, e) {
796
1002
  if (t.id) return t.id;
797
1003
  const n = (t.counts.get(e) ?? 0) + 1;
798
1004
  return t.counts.set(e, n), `${e}#${n}`;
799
1005
  }
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);
1006
+ function je(t, e, n, i = 1, r = t) {
1007
+ const s = nt[n.level] * i, o = ue(t) * s, { height: l, depth: c } = on(t);
802
1008
  return {
803
1009
  width: o,
804
1010
  height: l * s,
805
1011
  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) }]
1012
+ pieces: [{ kind: "glyph", text: t, x: 0, y: 0, width: o, size: s, italic: e, ...n.color ? { color: n.color } : {}, id: vt(n, r) }]
807
1013
  };
808
1014
  }
809
- function Ft(t, e, n) {
810
- const i = Zt(), r = ct(e, n), s = Y[e.level];
1015
+ function se(t, e, n) {
1016
+ const i = Me(), r = vt(e, n), s = nt[e.level];
811
1017
  for (const o of t) {
812
- const l = (o === " " ? 0.28 : /[A-Za-z]/.test(o) ? Wt(o) - 0.04 : Wt(o)) * s;
1018
+ const l = (o === " " ? 0.28 : /[A-Za-z]/.test(o) ? ue(o) - 0.04 : ue(o)) * s;
813
1019
  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);
1020
+ const { height: c, depth: d } = on(o);
1021
+ 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, d * s);
816
1022
  }
817
1023
  i.width += l;
818
1024
  }
819
1025
  return i;
820
1026
  }
821
- function Bt(t) {
1027
+ function me(t) {
822
1028
  switch (t.type) {
823
1029
  case "symbol":
824
1030
  return t.cls;
@@ -826,212 +1032,763 @@ function Bt(t) {
826
1032
  case "opname":
827
1033
  return "op";
828
1034
  case "scripts":
829
- return Bt(t.base);
1035
+ return me(t.base);
830
1036
  case "id":
831
1037
  case "color":
832
- return Bt(t.body);
1038
+ return me(t.body);
833
1039
  default:
834
1040
  return "ord";
835
1041
  }
836
1042
  }
837
- function rn(t, e) {
1043
+ function Jn(t, e) {
838
1044
  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
1045
  }
840
- function sn(t, e) {
841
- const n = Zt();
1046
+ function Qn(t, e) {
1047
+ const n = Me();
842
1048
  let i;
843
1049
  return t.forEach((r) => {
844
1050
  if (r.type === "space") {
845
- n.width += r.width * Y[e.level];
1051
+ n.width += r.width * nt[e.level];
846
1052
  return;
847
1053
  }
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;
1054
+ let s = me(r);
1055
+ 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 += Jn(i, s) / 18 * nt[e.level]);
1056
+ const o = X(r, e);
1057
+ n.pieces.push(...et(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;
852
1058
  }), n;
853
1059
  }
854
- function on(t, e) {
1060
+ function ti(t, e) {
855
1061
  if (!Number.isFinite(t)) return t > 0 ? "∞" : t < 0 ? "−∞" : "?";
856
1062
  const n = t.toFixed(e), i = n.includes(".") ? n.replace(/\.?0+$/, "") : n;
857
1063
  return (i === "-0" ? "0" : i).replace("-", "−");
858
1064
  }
859
- function R(t, e) {
860
- const n = Y[e.level];
1065
+ function X(t, e) {
1066
+ const n = nt[e.level];
861
1067
  switch (t.type) {
862
1068
  case "symbol":
863
- return le(t.text, t.italic, e);
1069
+ return je(t.text, t.italic, e);
864
1070
  case "group":
865
- return sn(t.body, e);
1071
+ return Qn(t.body, e);
866
1072
  case "space":
867
- return { ...Zt(), width: t.width * n };
1073
+ return { ...Me(), width: t.width * n };
868
1074
  case "text":
869
- return Ft(t.text, e, `text:${t.text}`);
1075
+ return se(t.text, e, `text:${t.text}`);
870
1076
  case "opname":
871
- return Ft(t.text, e, t.text);
1077
+ return se(t.text, e, t.text);
872
1078
  case "value": {
873
1079
  const i = e.values[t.name];
874
1080
  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}`);
1081
+ return se(ti(i, t.digits), { ...e, id: e.id ?? `val:${t.name}` }, `val:${t.name}`);
1082
+ }
1083
+ case "bigop":
1084
+ return je(t.text, !1, e, e.level === 0 ? 1.4 : 1.1);
1085
+ case "color":
1086
+ return X(t.body, { ...e, color: t.color });
1087
+ case "id":
1088
+ return X(t.body, { ...e, id: t.id });
1089
+ case "scripts":
1090
+ return ei(t, e);
1091
+ case "frac":
1092
+ return ni(t, e);
1093
+ case "sqrt":
1094
+ return ii(t, e);
1095
+ case "accent":
1096
+ return ri(t, e);
1097
+ case "matrix":
1098
+ return si(t, e);
1099
+ }
1100
+ }
1101
+ function ei(t, e) {
1102
+ const n = X(t.base, e), i = { ...e, level: Zn(e.level) }, r = t.sup ? X(t.sup, i) : void 0, s = t.sub ? X(t.sub, i) : void 0, o = nt[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] };
1103
+ if (l) {
1104
+ const y = Math.max(n.width, r?.width ?? 0, s?.width ?? 0), f = et(n, (y - n.width) / 2, 0);
1105
+ let m = n.height, a = n.depth;
1106
+ const g = 0.12 * o;
1107
+ if (r) {
1108
+ const b = -(n.height + g + r.depth);
1109
+ f.push(...et(r, (y - r.width) / 2, b)), m = -b + r.height;
1110
+ }
1111
+ if (s) {
1112
+ const b = n.depth + g + s.height;
1113
+ f.push(...et(s, (y - s.width) / 2, b)), a = b + s.depth;
1114
+ }
1115
+ return { width: y, height: m, depth: a, pieces: f };
1116
+ }
1117
+ let d = 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;
1118
+ if (r && s) {
1119
+ const y = d - r.depth - (s.height - u);
1120
+ y < 0.2 * o && (u += 0.2 * o - y);
1121
+ }
1122
+ const p = n.width + 0.03 * o;
1123
+ let h = n.width;
1124
+ return r ? (c.pieces.push(...et(r, p, -d)), c.height = Math.max(c.height, d + r.height), h = Math.max(h, p + r.width)) : d = 0, s && (c.pieces.push(...et(s, p, u)), c.depth = Math.max(c.depth, u + s.depth), h = Math.max(h, p + s.width)), c.width = h + 0.04 * o, c;
1125
+ }
1126
+ function ni(t, e) {
1127
+ const n = { ...e, level: Kn(e.level) }, i = X(t.num, n), r = X(t.den, n), s = nt[e.level], o = Et * s, l = sn * s, c = (e.level === 0 ? 0.16 : 0.1) * s, d = 0.1 * s, u = Math.max(i.width, r.width) + d * 2, p = -(l + o / 2 + c + i.depth), h = -l + o / 2 + c + r.height;
1128
+ return {
1129
+ width: u,
1130
+ height: -p + i.height,
1131
+ depth: h + r.depth,
1132
+ pieces: [
1133
+ ...et(i, (u - i.width) / 2, p),
1134
+ ...t.bar === !1 ? [] : [{ kind: "rule", x: 0, y: -l - o / 2, width: u, height: o, ...e.color ? { color: e.color } : {}, id: vt(e, "frac") }],
1135
+ ...et(r, (u - r.width) / 2, h)
1136
+ ]
1137
+ };
1138
+ }
1139
+ function ii(t, e) {
1140
+ const n = X(t.body, e), i = nt[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 = [
1141
+ [0.02 * i, -0.36 * i],
1142
+ [0.13 * i, -0.44 * i],
1143
+ [0.3 * i, s],
1144
+ [o - 0.04 * i, -r],
1145
+ [l, -r]
1146
+ ];
1147
+ return {
1148
+ width: l,
1149
+ height: r + Et * i,
1150
+ depth: s,
1151
+ pieces: [{ kind: "stroke", points: c, width: Et * i, ...e.color ? { color: e.color } : {}, id: vt(e, "sqrt") }, ...et(n, o, 0)]
1152
+ };
1153
+ }
1154
+ function ri(t, e) {
1155
+ const n = X(t.body, e), i = nt[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 = vt(e, t.accent);
1156
+ let d;
1157
+ if (t.accent === "vec") {
1158
+ const u = 0.12 * i;
1159
+ d = [[[s, r], [o, r]], [[o - u, r - u * 0.7], [o, r], [o - u, r + u * 0.7]]];
1160
+ } else if (t.accent === "hat") {
1161
+ const u = (s + o) / 2;
1162
+ d = [[[u - 0.16 * i, r + 0.02 * i], [u, r - 0.12 * i], [u + 0.16 * i, r + 0.02 * i]]];
1163
+ } else
1164
+ d = [[[s, r], [o, r]]];
1165
+ return {
1166
+ width: Math.max(n.width, o + 0.02 * i),
1167
+ height: -r + 0.14 * i,
1168
+ depth: n.depth,
1169
+ pieces: [...n.pieces, ...d.map((u) => ({ kind: "stroke", points: u, width: Et * i * 0.9, ...l, id: c }))]
1170
+ };
1171
+ }
1172
+ function si(t, e) {
1173
+ const n = { ...e, level: Math.max(e.level, 1) }, i = nt[n.level], r = t.rows.map((k) => k.map((M) => X(M, n))), s = Math.max(...r.map((k) => k.length)), o = Array.from({ length: s }, (k, M) => Math.max(0, ...r.map(($) => $[M]?.width ?? 0))), l = r.map((k) => Math.max(0.7 * i, ...k.map((M) => M.height))), c = r.map((k) => Math.max(0.2 * i, ...k.map((M) => M.depth))), d = 0.9 * i, u = 0.25 * i, p = t.delimiters === "matrix" ? 0 : 0.55 * i, h = o.reduce((k, M) => k + M, 0) + d * (s - 1), y = l.reduce((k, M, $) => k + M + c[$], 0) + u * (r.length - 1), f = -sn * i - y / 2, m = [];
1174
+ let a = f;
1175
+ r.forEach((k, M) => {
1176
+ a += l[M];
1177
+ let $ = p;
1178
+ k.forEach((S, A) => {
1179
+ m.push(...et(S, $ + (o[A] - S.width) / 2, a)), $ += o[A] + d;
1180
+ }), a += c[M] + u;
1181
+ });
1182
+ const g = h + p * 2, b = f + y, x = e.color ? { color: e.color } : {}, w = (k, M) => ({ kind: "stroke", points: k, width: Et * i * 1.1, ...x, id: vt(e, M) }), v = 0.08 * i;
1183
+ if (t.delimiters === "pmatrix") {
1184
+ const k = (M) => {
1185
+ const $ = M === 1 ? p * 0.75 : g - p * 0.75, S = M * p * 0.5;
1186
+ return Array.from({ length: 17 }, (A, I) => {
1187
+ const P = I / 16;
1188
+ return [$ - S * Math.sin(Math.PI * P), f - v + (y + v * 2) * P];
1189
+ });
1190
+ };
1191
+ m.push(w(k(1), "("), w(k(-1), ")"));
1192
+ } else if (t.delimiters === "bmatrix") {
1193
+ const k = p * 0.35, M = p * 0.2, $ = g - p * 0.2;
1194
+ m.push(
1195
+ w([[M + k, f - v], [M, f - v], [M, b + v], [M + k, b + v]], "["),
1196
+ w([[$ - k, f - v], [$, f - v], [$, b + v], [$ - k, b + v]], "]")
1197
+ );
1198
+ } else t.delimiters === "vmatrix" && m.push(w([[p * 0.4, f - v], [p * 0.4, b + v]], "|"), w([[g - p * 0.4, f - v], [g - p * 0.4, b + v]], "|"));
1199
+ return { width: g, height: -f + v, depth: b + v, pieces: m };
1200
+ }
1201
+ function J(t, e = {}) {
1202
+ const n = typeof t == "string" ? Yn(t) : t, i = { level: e.style === "inline" ? 1 : 0, values: e.values ?? {}, counts: /* @__PURE__ */ new Map() }, r = X(n, i);
1203
+ return { width: r.width, height: r.height, depth: r.depth, pieces: r.pieces };
1204
+ }
1205
+ const mt = 'system-ui, -apple-system, "Segoe UI", sans-serif', De = (t, e) => Math.hypot(e[0] - t[0], e[1] - t[1]);
1206
+ function B(t, e) {
1207
+ if (e >= 1) return t;
1208
+ if (e <= 0) return [];
1209
+ const n = t.map((s) => s.slice(1).reduce((o, l, c) => o + De(s[c], l), 0));
1210
+ let i = n.reduce((s, o) => s + o, 0) * e;
1211
+ const r = [];
1212
+ for (const [s, o] of t.entries()) {
1213
+ if (i <= 0) break;
1214
+ if (n[s] <= i) {
1215
+ r.push(o), i -= n[s];
1216
+ continue;
1217
+ }
1218
+ const l = [o[0]];
1219
+ for (let c = 1; c < o.length; c++) {
1220
+ const d = De(o[c - 1], o[c]);
1221
+ if (d >= i) {
1222
+ const u = d === 0 ? 0 : i / d;
1223
+ 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]);
1224
+ break;
1225
+ }
1226
+ l.push(o[c]), i -= d;
1227
+ }
1228
+ r.push(l), i = 0;
1229
+ }
1230
+ return r;
1231
+ }
1232
+ function xe(t, e) {
1233
+ 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;
1234
+ return [e.x + i * e.size, e.y + r * e.size];
1235
+ }
1236
+ function an(t, e, n) {
1237
+ const [i, r] = e, s = n.size, o = n.opacity ?? 1;
1238
+ return t.map((l) => {
1239
+ const c = l.color ?? n.color, d = o * (l.opacity ?? 1), u = `${n.idPrefix}${l.id}`;
1240
+ if (l.kind === "glyph")
1241
+ return {
1242
+ type: "text",
1243
+ id: u,
1244
+ text: l.text,
1245
+ x: i + (l.x + l.width / 2) * s,
1246
+ y: r + l.y * s,
1247
+ size: l.size * s,
1248
+ font: Un(l.text),
1249
+ italic: l.italic,
1250
+ color: c,
1251
+ align: "center",
1252
+ opacity: d
1253
+ };
1254
+ if (l.kind === "rule") {
1255
+ const p = i + l.x * s, h = r + l.y * s, y = l.width * s, f = Math.max(1, l.height * s);
1256
+ return { type: "line", id: u, points: [[p, h], [p + y, h], [p + y, h + f], [p, h + f]], closed: !0, fill: c, opacity: d };
1257
+ }
1258
+ return { type: "line", id: u, points: l.points.map(([p, h]) => [i + p * s, r + h * s]), stroke: c, width: Math.max(1, l.width * s), opacity: d };
1259
+ });
1260
+ }
1261
+ function it(t, e) {
1262
+ return an(t.pieces, xe(t, e), e);
1263
+ }
1264
+ const Gt = 480;
1265
+ function ln(t, e) {
1266
+ const n = [];
1267
+ let i = [];
1268
+ return t.forEach((r, s) => {
1269
+ const o = t[s - 1];
1270
+ (!r || o && Math.abs(r[1] - o[1]) > e * 1.5) && (i.length >= 2 && n.push(i), i = []), r && i.push(r);
1271
+ }), i.length >= 2 && n.push(i), n;
1272
+ }
1273
+ function cn(t, e) {
1274
+ const n = Math.max(e.plane.width, e.plane.height) * 20;
1275
+ if (!(!Number.isFinite(t[0]) || !Number.isFinite(t[1])))
1276
+ return [Math.max(-n, Math.min(n, t[0])), Math.max(-n, Math.min(n, t[1]))];
1277
+ }
1278
+ function un(t, e, n, i, r, s) {
1279
+ return B(e, r.draw).map((o, l) => ({ type: "line", id: `${t}.${l}`, points: o, stroke: n, width: i, opacity: r.opacity, ...s ? { dash: s } : {} }));
1280
+ }
1281
+ function Qt(t, e, n, i, r, s, o, l) {
1282
+ const c = Array.from({ length: Gt + 1 }, (d, u) => {
1283
+ const p = n + (i - n) * u / Gt;
1284
+ return cn(o.plane.toScreen([p, e(p)]), o);
1285
+ });
1286
+ return un(t, ln(c, o.plane.height), r, s, o, l);
1287
+ }
1288
+ function oi(t, e) {
1289
+ const n = t.derivative ? $e(t.expr, t.derivative) : U(t.expr, "x"), [i, r] = t.domain ?? e.plane.x, s = O(e.theme, t.color, e.theme.colors.blue), o = t.dashed ? [10 * e.plane.scale, 8 * e.plane.scale] : void 0;
1290
+ return Qt(t.id, (l) => n(l, e.scope), i, r, s, (t.width ?? 3.5) * e.plane.scale, e, o);
1291
+ }
1292
+ function ai(t, e) {
1293
+ const n = U(t.x, "t"), i = U(t.y, "t"), r = pt(e.values, t.transform), [s, o] = t.t ?? [0, Math.PI * 2], l = Array.from({ length: Gt + 1 }, (d, u) => {
1294
+ const p = s + (o - s) * u / Gt;
1295
+ return cn(e.plane.toScreen(K(r, [n(p, e.scope), i(p, e.scope)])), e);
1296
+ }), c = O(e.theme, t.color, e.theme.colors.blue);
1297
+ return un(t.id, ln(l, e.plane.height), c, (t.width ?? 3.5) * e.plane.scale, e);
1298
+ }
1299
+ const Se = (t, e, n, i, r) => [[e, n], [i, n], [i, r], [e, r]].map(t.plane.toScreen), Xt = (t) => Math.min(2e4, Math.max(0, Math.floor(t)));
1300
+ function li(t, e) {
1301
+ const n = bt(e.values, t.distribution), i = tn(n, t.seed ?? t.id, Xt(T(e.values, t.count))), r = _n(i, t.bins ?? Fe(n), t.scale ?? "density"), s = O(e.theme, t.color, e.theme.colors.blue), o = e.opacity * e.draw, l = r.flatMap(
1302
+ (c, d) => c.height > 0 ? [{ type: "line", id: `${t.id}.${d}`, points: Se(e, c.left, 0, c.right, c.height), closed: !0, fill: s, stroke: e.theme.background, width: 1 * e.plane.scale, opacity: o * (t.fillOpacity ?? 0.75) }] : []
1303
+ );
1304
+ if (t.curve && (t.scale ?? "density") === "density") {
1305
+ const [c, d] = t.bins ?? Fe(n), u = O(e.theme, "yellow", e.theme.colors.yellow);
1306
+ l.push(...Qt(`${t.id}.curve`, (p) => ct(Jt(n) ? { kind: "normal", mean: Pt(n), sd: It(n) } : n, p), c, d, u, 3 * e.plane.scale, { ...e, draw: 1 }));
1307
+ }
1308
+ return l;
1309
+ }
1310
+ function ci(t, e) {
1311
+ const n = bt(e.values, t.distribution), i = O(e.theme, t.color, e.theme.colors.blue), [r, s] = t.domain ?? e.plane.x, o = t.shade ? [T(e.values, t.shade[0]), T(e.values, t.shade[1])].sort((d, u) => d - u) : void 0, l = O(e.theme, "yellow", e.theme.colors.yellow);
1312
+ if (Jt(n)) {
1313
+ const d = [], u = Math.max(0, Math.ceil(r)), p = Math.floor(s), h = u + Math.ceil((p - u + 1) * e.draw);
1314
+ for (let y = u; y < h && y <= p; y++) {
1315
+ const f = ct(n, y);
1316
+ if (f <= 0) continue;
1317
+ const m = o && y >= o[0] && y <= o[1];
1318
+ d.push({ type: "line", id: `${t.id}.${y}`, points: Se(e, y - 0.4, 0, y + 0.4, f), closed: !0, fill: m ? l : i, opacity: e.opacity * (t.fillOpacity ?? 0.8) });
1319
+ }
1320
+ return d;
1321
+ }
1322
+ const c = [];
1323
+ if (o && e.draw >= 1) {
1324
+ const [d, u] = [Math.max(o[0], r), Math.min(o[1], s)];
1325
+ if (u > d) {
1326
+ const h = Array.from({ length: 121 }, (f, m) => {
1327
+ const a = d + (u - d) * m / 120;
1328
+ return [a, ct(n, a)];
1329
+ }), y = [[d, 0], ...h, [u, 0]].map(e.plane.toScreen);
1330
+ c.push({ type: "line", id: `${t.id}.shade`, points: y, closed: !0, fill: l, opacity: e.opacity * (t.fillOpacity ?? 0.4) });
1331
+ }
1332
+ }
1333
+ return c.push(...Qt(t.id, (d) => ct(n, d), r, s, i, (t.width ?? 3.5) * e.plane.scale, e)), c;
1334
+ }
1335
+ function ui(t, e) {
1336
+ const n = t.rows ?? 10, i = t.spacing ?? 0.5, r = t.top ?? e.plane.y[1] - i, s = i * 0.9, o = (v, k) => [v * i, r - k * s], l = O(e.theme, "grey", e.theme.colors.grey), c = O(e.theme, t.color, e.theme.colors.yellow), d = i * 0.19 * e.plane.unitX, u = [];
1337
+ for (let v = 0; v < n; v++)
1338
+ for (let k = 0; k <= v; k++) {
1339
+ const [M, $] = e.plane.toScreen(o(k - v / 2, v));
1340
+ u.push({ type: "circle", id: `${t.id}.peg.${v}.${k}`, x: M, y: $, r: d * 0.45, fill: l, opacity: e.opacity * e.draw });
1341
+ }
1342
+ const p = n + 0.3, h = Math.max(n + 2, (r - e.plane.y[0]) / s - 0.2);
1343
+ for (let v = 0; v <= n + 1; v++) {
1344
+ const k = v - (n + 1) / 2, M = B([[o(k, p), o(k, h)].map(e.plane.toScreen)], e.draw);
1345
+ for (const $ of M) u.push({ type: "line", id: `${t.id}.bin.${v}`, points: $, stroke: l, width: 1.2 * e.plane.scale, opacity: e.opacity * 0.6 });
1346
+ }
1347
+ const y = B([[o(-(n + 1) / 2, h), o((n + 1) / 2, h)].map(e.plane.toScreen)], e.draw);
1348
+ for (const v of y) u.push({ type: "line", id: `${t.id}.floor`, points: v, stroke: l, width: 1.2 * e.plane.scale, opacity: e.opacity * 0.6 });
1349
+ const f = Math.max(0, T(e.values, t.balls)), m = Math.floor(f), a = t.seed ?? t.id, g = new Array(n + 1).fill(0), b = 2 * d / e.plane.unitY / s, x = (v, k) => ({ x: v - n / 2 + (k % 2 ? 0.22 : -0.22), depth: h - b * (Math.floor(k / 2) + 0.5) });
1350
+ for (let v = 0; v < m; v++) {
1351
+ const k = re(Ce(a, v, n)), M = x(k, g[k]), [$, S] = e.plane.toScreen(o(M.x, M.depth));
1352
+ g[k]++, u.push({ type: "circle", id: `${t.id}.ball.${v}`, x: $, y: S, r: d, fill: c, opacity: e.opacity });
1353
+ }
1354
+ const w = f - m;
1355
+ if (w > 0) {
1356
+ const v = Ce(a, m, n), k = Math.min(1, w / 0.8);
1357
+ let { x: M, depth: $ } = Vn(v, k);
1358
+ if ($ -= 1, w > 0.8) {
1359
+ const I = ((w - 0.8) / 0.2) ** 2, P = re(v), z = x(P, g[P]), j = { x: re(v) - n / 2, depth: n - 1 };
1360
+ $ = j.depth + (z.depth - j.depth) * I, M = j.x + (z.x - j.x) * I;
1361
+ }
1362
+ const [S, A] = e.plane.toScreen(o(M, $));
1363
+ u.push({ type: "circle", id: `${t.id}.falling`, x: S, y: A, r: d, fill: c, opacity: e.opacity });
1364
+ }
1365
+ return u;
1366
+ }
1367
+ function di(t, e) {
1368
+ const n = dn(t, e), i = nn(n, t.seed ?? t.id, Xt(T(e.values, t.count))), r = O(e.theme, t.color, e.theme.colors.blue), s = O(e.theme, t.insideColor, e.theme.colors.yellow), o = t.inside ? dt(t.inside) : void 0, l = (t.radius ?? 3) * e.plane.scale, c = i.map(([d, u], p) => {
1369
+ const [h, y] = e.plane.toScreen([d, u]), f = o ? lt(o, { ...e.scope, x: d, y: u }) <= 0 : !1;
1370
+ return { type: "circle", id: `${t.id}.${p}`, x: h, y, r: l, fill: f ? s : r, opacity: e.opacity * e.draw * 0.85 };
1371
+ });
1372
+ if (t.fit) {
1373
+ const d = rn(i);
1374
+ if (d) {
1375
+ const [u, p] = e.plane.x;
1376
+ 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: O(e.theme, "red", e.theme.colors.red), width: 3 * e.plane.scale, opacity: e.opacity });
1377
+ }
1378
+ }
1379
+ return c;
1380
+ }
1381
+ function dn(t, e) {
1382
+ const n = t.points;
1383
+ return n.kind === "uniform" ? n : { kind: "linear", slope: T(e.values, n.slope), intercept: T(e.values, n.intercept), noise: T(e.values, n.noise), x: n.x };
1384
+ }
1385
+ function hi(t, e) {
1386
+ const n = T(e.values, t.prior), i = T(e.values, t.truePositive), r = T(e.values, t.falsePositive), s = e.plane.x[1] - e.plane.x[0], o = e.plane.y[1] - e.plane.y[0], [l, c] = t.size ?? [s * 0.8, o * 0.7], [d, u] = t.at ?? [e.plane.x[0] + s * 0.1, e.plane.y[0] + o * 0.08], p = d + l * Math.min(1, Math.max(0, n)), h = O(e.theme, t.color, e.theme.colors.yellow), y = O(e.theme, "red", e.theme.colors.red), f = O(e.theme, "grey", e.theme.colors.grey), m = e.opacity * e.draw, a = (v, k, M, $, S, A, I) => ({
1387
+ type: "line",
1388
+ id: `${t.id}.${v}`,
1389
+ points: Se(e, k, M, $, S),
1390
+ closed: !0,
1391
+ fill: A,
1392
+ stroke: e.theme.background,
1393
+ width: 2 * e.plane.scale,
1394
+ opacity: m * I
1395
+ }), g = u + c, b = g - c * Math.min(1, Math.max(0, i)), x = g - c * Math.min(1, Math.max(0, r)), w = [
1396
+ a("tp", d, b, p, g, h, 0.85),
1397
+ a("fn", d, u, p, b, f, 0.35),
1398
+ a("fp", p, x, d + l, g, y, 0.8),
1399
+ a("tn", p, u, d + l, x, f, 0.2)
1400
+ ];
1401
+ if (t.labels !== !1 && e.draw >= 1) {
1402
+ const v = 20 * e.plane.scale, k = (M, $, S, A) => {
1403
+ const [I, P] = e.plane.toScreen(S);
1404
+ w.push(...it(J($, { values: e.scope, style: "inline" }), { x: I, y: P, size: v, color: A, opacity: e.opacity, idPrefix: `${t.id}.label.${M}.` }));
1405
+ };
1406
+ 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], y), k("posterior", `P(\\text{has it} \\mid +) = \\val{${t.id}.posterior:3}`, [d + l / 2, u + c + o * 0.05], h);
1407
+ }
1408
+ return w;
1409
+ }
1410
+ const _e = ["bfs", "dfs", "dijkstra"];
1411
+ function ge(t, e, n) {
1412
+ const i = new Map(t.map((s, o) => [s, o])), r = new Map(t.map((s) => [s, []]));
1413
+ for (const s of e) {
1414
+ const o = s.weight ?? 1;
1415
+ r.get(s.from)?.push({ to: s.to, weight: o }), n || r.get(s.to)?.push({ to: s.from, weight: o });
1416
+ }
1417
+ for (const s of r.values()) s.sort((o, l) => (i.get(o.to) ?? 0) - (i.get(l.to) ?? 0));
1418
+ return r;
1419
+ }
1420
+ function pi(t, e) {
1421
+ const n = [], i = /* @__PURE__ */ new Set([t]), r = [{ node: t }];
1422
+ for (; r.length > 0; ) {
1423
+ const { node: s, parent: o } = r.shift();
1424
+ for (const { to: l } of e.get(s) ?? [])
1425
+ i.has(l) || (i.add(l), r.push({ node: l, parent: s }));
1426
+ n.push({ node: s, ...o !== void 0 ? { parent: o } : {}, frontier: r.map((l) => l.node) });
1427
+ }
1428
+ return n;
1429
+ }
1430
+ function fi(t, e) {
1431
+ const n = [], i = /* @__PURE__ */ new Set(), r = [{ node: t }];
1432
+ for (; r.length > 0; ) {
1433
+ const { node: s, parent: o } = r.pop();
1434
+ if (i.has(s)) continue;
1435
+ i.add(s);
1436
+ const l = (e.get(s) ?? []).filter(({ to: c }) => !i.has(c)).reverse();
1437
+ for (const { to: c } of l) r.push({ node: c, parent: s });
1438
+ n.push({ node: s, ...o !== void 0 ? { parent: o } : {}, frontier: [...new Set(r.map((c) => c.node).filter((c) => !i.has(c)))].reverse() });
1439
+ }
1440
+ return n;
1441
+ }
1442
+ function yi(t, e, n) {
1443
+ const i = [], r = Object.fromEntries(e.map((c) => [c, 1 / 0])), s = {}, o = new Map(e.map((c, d) => [c, d]));
1444
+ r[t] = 0;
1445
+ const l = /* @__PURE__ */ new Set();
1446
+ for (; ; ) {
1447
+ let c;
1448
+ for (const u of e)
1449
+ l.has(u) || r[u] === 1 / 0 || (c === void 0 || r[u] < r[c] || r[u] === r[c] && o.get(u) < o.get(c)) && (c = u);
1450
+ if (c === void 0) break;
1451
+ l.add(c);
1452
+ for (const { to: u, weight: p } of n.get(c) ?? [])
1453
+ l.has(u) || r[c] + p < r[u] && (r[u] = r[c] + p, s[u] = c);
1454
+ const d = e.filter((u) => !l.has(u) && r[u] < 1 / 0).sort((u, p) => r[u] - r[p]);
1455
+ i.push({ node: c, ...s[c] !== void 0 ? { parent: s[c] } : {}, frontier: d, distances: { ...r } });
1456
+ }
1457
+ return i;
1458
+ }
1459
+ const zt = /* @__PURE__ */ new Map();
1460
+ function mi(t, e, n, i, r = !1) {
1461
+ const s = JSON.stringify([t, e, n, i, r]), o = zt.get(s);
1462
+ if (o) return o;
1463
+ if (!n.includes(e)) throw new Error(`graph search: no node "${e}"`);
1464
+ const l = ge(n, i, r), c = t === "bfs" ? pi(e, l) : t === "dfs" ? fi(e, l) : yi(e, n, l);
1465
+ return zt.size > 64 && zt.clear(), zt.set(s, c), c;
1466
+ }
1467
+ function gi(t, e, n) {
1468
+ const i = ge(e, n, !0), r = ge(e, n, !1), s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([t]), l = [t];
1469
+ for (; l.length; ) {
1470
+ const y = l.shift(), f = (i.get(y)?.length ? i.get(y) : r.get(y) ?? []).map((m) => m.to).filter((m) => !o.has(m));
1471
+ f.forEach((m) => o.add(m)), s.set(y, f), l.push(...f);
1472
+ }
1473
+ const c = /* @__PURE__ */ new Map();
1474
+ let d = 0;
1475
+ const u = (y, f) => {
1476
+ const m = s.get(y) ?? [], a = m.length === 0 ? d++ : m.map((g) => u(g, f + 1)).reduce((g, b, x, w) => g + b / w.length, 0);
1477
+ return c.set(y, [a, f === 0 ? 0 : -f]), a;
1478
+ };
1479
+ u(t, 0);
1480
+ const p = [...c.values()].map(([y]) => y), h = (Math.min(...p) + Math.max(...p)) / 2;
1481
+ for (const [y, [f, m]] of c) c.set(y, [f - h, m]);
1482
+ return c;
1483
+ }
1484
+ const bi = { "∪": "|", "∩": "&", "∖": "-", "△": "^", "¬": "!", "\\": "-" };
1485
+ function hn(t) {
1486
+ const e = [...t].map((d) => bi[d] ?? d).join("");
1487
+ let n = 0;
1488
+ const i = () => {
1489
+ for (; /\s/.test(e[n] ?? ""); ) n++;
1490
+ }, r = (d) => {
1491
+ throw new Error(`set expression: ${d} at ${n + 1} in "${t}"`);
1492
+ }, s = () => {
1493
+ i();
1494
+ let d;
1495
+ if (e[n] === "!")
1496
+ n++, d = { type: "not", operand: s() };
1497
+ else if (e[n] === "(")
1498
+ n++, d = l(), i(), e[n] !== ")" && r('expected ")"'), n++;
1499
+ else {
1500
+ const u = /^[A-Za-z]\w*/.exec(e.slice(n));
1501
+ u || r(n >= e.length ? "unexpected end" : `unexpected "${e[n]}"`), n += u[0].length, d = { type: "set", name: u[0] };
1502
+ }
1503
+ for (i(); e[n] === "'"; )
1504
+ n++, d = { type: "not", operand: d }, i();
1505
+ return d;
1506
+ }, o = () => {
1507
+ let d = s();
1508
+ for (i(); e[n] === "&"; )
1509
+ n++, d = { type: "op", operator: "&", left: d, right: s() }, i();
1510
+ return d;
1511
+ }, l = () => {
1512
+ let d = o();
1513
+ for (i(); e[n] === "|" || e[n] === "-" || e[n] === "^"; )
1514
+ d = { type: "op", operator: e[n++], left: d, right: o() }, i();
1515
+ return d;
1516
+ }, c = l();
1517
+ return i(), n < e.length && r(`unexpected "${e[n]}"`), c;
1518
+ }
1519
+ function Vt(t) {
1520
+ return t.type === "set" ? [t.name] : t.type === "not" ? Vt(t.operand) : [.../* @__PURE__ */ new Set([...Vt(t.left), ...Vt(t.right)])];
1521
+ }
1522
+ function Ht(t, e) {
1523
+ switch (t.type) {
1524
+ case "set":
1525
+ return e.has(t.name);
1526
+ case "not":
1527
+ return !Ht(t.operand, e);
1528
+ case "op": {
1529
+ const n = Ht(t.left, e), i = Ht(t.right, e);
1530
+ return t.operator === "&" ? n && i : t.operator === "|" ? n || i : t.operator === "-" ? n && !i : n !== i;
876
1531
  }
877
- case "bigop":
878
- return le(t.text, !1, e, e.level === 0 ? 1.4 : 1.1);
879
- case "color":
880
- return R(t.body, { ...e, color: t.color });
881
- case "id":
882
- return R(t.body, { ...e, id: t.id });
883
- case "scripts":
884
- return an(t, e);
885
- case "frac":
886
- return ln(t, e);
887
- case "sqrt":
888
- return cn(t, e);
889
- case "accent":
890
- return un(t, e);
891
- case "matrix":
892
- return dn(t, e);
893
1532
  }
894
1533
  }
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] };
897
- 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;
1534
+ function vi(t, e) {
1535
+ const n = [];
1536
+ for (let i = 0; i < 1 << e.length; i++) {
1537
+ const r = e.filter((s, o) => i & 1 << o);
1538
+ Ht(t, new Set(r)) && n.push(r);
1539
+ }
1540
+ return n;
1541
+ }
1542
+ function pn(t, e, n, i, r = 64) {
1543
+ return Array.from({ length: r }, (s, o) => {
1544
+ const l = o / r * 2 * Math.PI;
1545
+ return [t + n * Math.cos(l), e + i * Math.sin(l)];
1546
+ });
1547
+ }
1548
+ function te(t) {
1549
+ return t.edges.map((e) => Array.isArray(e) ? { from: e[0], to: e[1], ...e[2] !== void 0 ? { weight: e[2] } : {} } : e);
1550
+ }
1551
+ function fn(t) {
1552
+ const e = /* @__PURE__ */ new Map();
1553
+ if (t.tree) {
1554
+ const [n, i] = t.tree.spacing ?? [1.2, 1.2], [r, s] = t.tree.at ?? [0, 0];
1555
+ for (const [o, [l, c]] of gi(t.tree.root, t.nodes.map((d) => d.id), te(t))) e.set(o, [r + l * n, s + c * i]);
1556
+ }
1557
+ for (const n of t.nodes) n.at && e.set(n.id, n.at);
1558
+ return e;
1559
+ }
1560
+ function yn(t, e) {
1561
+ if (!t.search) return;
1562
+ const n = mi(t.search.kind, t.search.start, t.nodes.map((s) => s.id), te(t), t.directed), i = t.step === void 0 ? n.length : Math.min(n.length, Math.max(0, T(e, t.step))), r = Math.floor(i);
1563
+ return { events: n, done: r, partial: r < n.length ? i - r : 0 };
1564
+ }
1565
+ const wi = { bfs: "queue", dfs: "stack", dijkstra: "open" };
1566
+ function ki(t, e) {
1567
+ const { plane: n, theme: i } = e, r = fn(t), s = te(t), o = yn(t, e.values), l = (t.radius ?? 18) * n.scale, c = O(i, t.color, i.ink), d = O(i, "grey", i.colors.grey), u = O(i, "yellow", i.colors.yellow), p = O(i, "blue", i.colors.blue), h = [], y = o ? o.events.slice(0, o.done) : [], f = new Set(y.map(($) => $.node)), m = new Set(y.filter(($) => $.parent !== void 0).map(($) => `${$.parent}>${$.node}`)), a = y.at(-1), g = new Set(a?.frontier ?? []), b = o && o.partial > 0 ? o.events[o.done] : void 0, x = ($, S) => m.has(`${$}>${S}`) || !t.directed && m.has(`${S}>${$}`), w = ($) => n.toScreen(r.get($) ?? [0, 0]), v = ($, S) => {
1568
+ const A = w($), I = w(S), [P, z] = St([I[0] - A[0], I[1] - A[1]]);
1569
+ return [[A[0] + P * l, A[1] + z * l], [I[0] - P * l, I[1] - z * l]];
1570
+ }, k = t.weights ?? t.search?.kind === "dijkstra";
1571
+ if (s.forEach(($, S) => {
1572
+ const [A, I] = v($.from, $.to), P = x($.from, $.to), z = P ? u : d, j = (P ? 4 : 2) * n.scale, [E] = B([[A, I]], e.draw);
1573
+ if (E && (h.push(t.directed ? { type: "arrow", id: `${t.id}.edge.${S}`, points: E, stroke: z, width: j, head: 11 * n.scale, opacity: e.opacity } : { type: "line", id: `${t.id}.edge.${S}`, points: E, stroke: z, width: j, opacity: e.opacity }), k && e.draw >= 1)) {
1574
+ const F = [(A[0] + I[0]) / 2, (A[1] + I[1]) / 2], [R, Q] = St([-(I[1] - A[1]), I[0] - A[0]]), D = 14 * n.scale;
1575
+ h.push({ type: "text", id: `${t.id}.weight.${S}`, text: String($.weight ?? 1), x: F[0] + R * D * 0.9, y: F[1] + Q * D * 0.9 + D * 0.35, size: D, font: mt, color: P ? u : d, align: "center", opacity: e.opacity });
904
1576
  }
905
- if (s) {
906
- const w = n.depth + b + s.height;
907
- a.push(...X(s, (y - s.width) / 2, w)), m = w + s.depth;
1577
+ }), b?.parent !== void 0) {
1578
+ const [$, S] = v(b.parent, b.node), [A] = B([[$, S]], b.parent ? o.partial : 1);
1579
+ A && h.push({ type: "line", id: `${t.id}.reaching`, points: A, stroke: u, width: 4 * n.scale, opacity: e.opacity });
1580
+ }
1581
+ const M = a?.distances;
1582
+ for (const $ of t.nodes) {
1583
+ const [S, A] = w($.id), I = f.has($.id), P = b?.node === $.id && o.partial >= 0.999, z = !I && g.has($.id), j = I || P ? u : z ? p : i.background;
1584
+ h.push({ type: "circle", id: `${t.id}.node.${$.id}`, x: S, y: A, r: l, fill: j, stroke: I ? u : z ? p : c, width: 2 * n.scale, opacity: e.opacity * Math.min(1, e.draw * 1.5) }), a?.node === $.id && h.push({ type: "circle", id: `${t.id}.current`, x: S, y: A, r: l * 1.35, stroke: u, width: 2 * n.scale, opacity: e.opacity * 0.8 });
1585
+ const E = I || z || P ? i.background : c;
1586
+ if (h.push(...it(J($.label ?? $.id, { style: "inline" }), { x: S, y: A, size: l * 0.95, color: E, opacity: e.opacity * e.draw, idPrefix: `${t.id}.label.${$.id}.` })), M) {
1587
+ const F = M[$.id], R = 13 * n.scale;
1588
+ h.push({ type: "text", id: `${t.id}.distance.${$.id}`, text: F === 1 / 0 ? "∞" : String(Math.round(F * 100) / 100), x: S, y: A + l + R * 1.15, size: R, font: mt, color: p, align: "center", opacity: e.opacity });
908
1589
  }
909
- return { width: y, height: p, depth: m, pieces: a };
910
1590
  }
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);
1591
+ if (t.frontier && t.search && e.draw >= 1) {
1592
+ const [$, S] = t.frontier, A = 16 * n.scale, I = wi[t.search.kind];
1593
+ h.push({ type: "text", id: `${t.id}.frontier.name`, text: `${I}:`, x: $, y: S + A * 0.35, size: A, font: mt, color: d, align: "left", opacity: e.opacity });
1594
+ const P = A * 1.9;
1595
+ [...g].forEach((z, j) => {
1596
+ const E = $ + A * 4 + j * (P + A * 0.4), F = t.nodes.find((R) => R.id === z)?.label ?? z;
1597
+ h.push({ type: "line", id: `${t.id}.frontier.box.${j}`, points: [[E, S - P / 2], [E + P, S - P / 2], [E + P, S + P / 2], [E, S + P / 2]], closed: !0, fill: p, opacity: e.opacity * 0.9 }), h.push(...it(J(F, { style: "inline" }), { x: E + P / 2, y: S, size: A * 1.05, color: i.background, opacity: e.opacity, idPrefix: `${t.id}.frontier.label.${j}.` }));
1598
+ });
915
1599
  }
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;
1600
+ return h;
919
1601
  }
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;
922
- return {
923
- width: u,
924
- height: -h + i.height,
925
- depth: d + r.depth,
926
- 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)
930
- ]
931
- };
1602
+ function $i(t) {
1603
+ return t === 2 ? [[-0.6, 0], [0.6, 0]] : [0, 1, 2].map((e) => {
1604
+ const n = Math.PI / 2 + e * 2 * Math.PI / 3;
1605
+ return [0.62 * Math.cos(n), 0.62 * Math.sin(n) - 0.1];
1606
+ });
932
1607
  }
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 = [
935
- [0.02 * i, -0.36 * i],
936
- [0.13 * i, -0.44 * i],
937
- [0.3 * i, s],
938
- [o - 0.04 * i, -r],
939
- [l, -r]
940
- ];
941
- return {
942
- 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)]
946
- };
1608
+ function Mi(t, e) {
1609
+ const { plane: n, theme: i } = e, r = t.radius ?? 1.5, [s, o] = t.at ?? [0, 0], l = $i(t.sets.length).map(([a, g]) => [s + a * r, o + g * r]), c = l.map(([a, g]) => pn(a, g, r, r, 96).map(n.toScreen)), d = l.map(([a]) => a), u = l.map(([, a]) => a), p = r * 0.35, h = [[Math.min(...d) - r - p, Math.min(...u) - r - p], [Math.max(...d) + r + p, Math.min(...u) - r - p], [Math.max(...d) + r + p, Math.max(...u) + r + p], [Math.min(...d) - r - p, Math.max(...u) + r + p]].map(n.toScreen), y = [], f = t.sets.map((a) => a.id);
1610
+ if (t.highlight) {
1611
+ const a = O(i, t.highlightColor, i.colors.yellow);
1612
+ vi(hn(t.highlight), f).forEach((g, b) => {
1613
+ y.push({
1614
+ type: "line",
1615
+ id: `${t.id}.region.${b}`,
1616
+ points: h,
1617
+ closed: !0,
1618
+ fill: a,
1619
+ opacity: e.opacity * e.draw * 0.55,
1620
+ clip: f.map((x, w) => ({ points: c[w], outside: !g.includes(x) }))
1621
+ });
1622
+ });
1623
+ }
1624
+ if (t.universe !== !1) {
1625
+ y.push({ type: "line", id: `${t.id}.universe`, points: h, closed: !0, stroke: O(i, "grey", i.colors.grey), width: 2 * n.scale, opacity: e.opacity });
1626
+ const [a, g] = h[3];
1627
+ y.push(...it(J("U", { style: "inline" }), { x: a + 16 * n.scale, y: g + 20 * n.scale, size: 22 * n.scale, color: O(i, "grey", i.colors.grey), opacity: e.opacity, idPrefix: `${t.id}.universe.` }));
1628
+ }
1629
+ const m = ["blue", "red", "green"];
1630
+ return t.sets.forEach((a, g) => {
1631
+ const b = O(i, a.color ?? m[g], i.colors.blue);
1632
+ for (const M of B([[...c[g], c[g][0]]], e.draw))
1633
+ y.push({ type: "line", id: `${t.id}.set.${a.id}`, points: M, stroke: b, width: 3 * n.scale, opacity: e.opacity });
1634
+ const [x, w] = St([l[g][0] - s || (g === 0 ? -1 : 1), l[g][1] - o]), [v, k] = n.toScreen([l[g][0] + x * r * 0.78, l[g][1] + w * r * 0.78 + (t.sets.length === 2 ? r * 0.85 : 0)]);
1635
+ y.push(...it(J(a.label ?? a.id, { style: "inline" }), { x: v, y: k, size: 26 * n.scale, color: b, opacity: e.opacity * e.draw, idPrefix: `${t.id}.label.${a.id}.` }));
1636
+ }), y;
1637
+ }
1638
+ const mn = (t, e) => (Math.round(t) % e + e) % e;
1639
+ function xi(t, e) {
1640
+ const { plane: n, theme: i } = e, r = t.modulus, [s, o] = t.at ?? [0, 0], l = t.radius ?? 2, c = T(e.values, t.value), d = O(i, t.color, i.ink), u = O(i, "yellow", i.colors.yellow), p = (f, m) => {
1641
+ const a = Math.PI / 2 - f / r * 2 * Math.PI;
1642
+ return n.toScreen([s + Math.cos(a) * l * m, o + Math.sin(a) * l * m]);
1643
+ }, h = [];
1644
+ for (const f of B([pn(s, o, l, l, 120).map(n.toScreen)], e.draw))
1645
+ h.push({ type: "line", id: `${t.id}.face`, points: f, stroke: d, width: 3 * n.scale, opacity: e.opacity });
1646
+ const y = mn(c, r);
1647
+ for (let f = 0; f < r; f++) {
1648
+ const [m, a] = p(f, 0.8), g = Math.min(26, 220 / r + 8) * n.scale;
1649
+ h.push({ type: "line", id: `${t.id}.tick.${f}`, points: [p(f, 0.95), p(f, 1)], stroke: d, width: 2 * n.scale, opacity: e.opacity * e.draw }), h.push({ type: "text", id: `${t.id}.hour.${f}`, text: String(f), x: m, y: a + g * 0.35, size: g, font: mt, color: f === y ? u : d, align: "center", opacity: e.opacity * e.draw });
1650
+ }
1651
+ if (e.draw >= 1) {
1652
+ const f = n.toScreen([s, o]);
1653
+ h.push({ type: "arrow", id: `${t.id}.hand`, points: [f, p(c, 0.62)], stroke: u, width: 5 * n.scale, head: 16 * n.scale, opacity: e.opacity }), h.push({ type: "circle", id: `${t.id}.pin`, x: f[0], y: f[1], r: 6 * n.scale, fill: u, opacity: e.opacity });
1654
+ }
1655
+ return h;
947
1656
  }
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;
951
- if (t.accent === "vec") {
952
- 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]]];
954
- } 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]]];
957
- } else
958
- f = [[[s, r], [o, r]]];
959
- return {
960
- width: Math.max(n.width, o + 0.02 * i),
961
- height: -r + 0.14 * i,
962
- depth: n.depth,
963
- pieces: [...n.pieces, ...f.map((u) => ({ kind: "stroke", points: u, width: mt * i * 0.9, ...l, id: c }))]
964
- };
1657
+ function oe(t, e, n, i = 512) {
1658
+ if (e === n) return 0;
1659
+ const r = (n - e) / i;
1660
+ let s = t(e) + t(n);
1661
+ for (let o = 1; o < i; o++) s += t(e + o * r) * (o % 2 ? 4 : 2);
1662
+ return s * r / 3;
965
1663
  }
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;
1664
+ function gn(t, e, n, i, r) {
1665
+ const s = (n - e) / i;
1666
+ return Array.from({ length: i }, (o, l) => {
1667
+ const c = e + l * s, d = c + s;
1668
+ if (r === "trapezoid") return [c, d, t(c), t(d)];
1669
+ const u = t(r === "left" ? c : r === "right" ? d : (c + d) / 2);
1670
+ return [c, d, u, u];
975
1671
  });
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;
977
- 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];
983
- });
984
- };
985
- p.push(g(v(1), "("), g(v(-1), ")"));
986
- } 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]], "]")
991
- );
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 };
994
1672
  }
995
- 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 };
1673
+ const bn = (t) => Math.min(400, Math.max(1, Math.round(t)));
1674
+ function vn(t, e, n) {
1675
+ const i = {}, r = { ...n };
1676
+ for (const s of t)
1677
+ switch (s.kind) {
1678
+ case "tangent": {
1679
+ const o = U(s.expr), l = T(e, s.at), c = s.h === void 0 ? 0 : T(e, s.h), d = Math.abs(c) > 1e-9 ? (o(l + c, r) - o(l, r)) / c : $e(s.expr, 1)(l, r);
1680
+ Object.assign(i, { [`${s.id}.slope`]: d, [`${s.id}.x`]: l, [`${s.id}.y`]: o(l, r) });
1681
+ break;
1682
+ }
1683
+ case "riemann": {
1684
+ const o = U(s.expr), l = T(e, s.from), c = T(e, s.to), d = bn(T(e, s.n)), p = gn((h) => o(h, r), l, c, d, s.rule ?? "left").reduce((h, [y, f, m, a]) => h + (m + a) / 2 * (f - y), 0);
1685
+ Object.assign(i, { [`${s.id}.sum`]: p, [`${s.id}.exact`]: oe((h) => o(h, r), l, c), [`${s.id}.n`]: d });
1686
+ break;
1687
+ }
1688
+ case "area": {
1689
+ const o = U(s.expr), l = s.lower ? U(s.lower) : () => 0;
1690
+ i[`${s.id}.value`] = oe((c) => o(c, r) - l(c, r), T(e, s.from), T(e, s.to));
1691
+ break;
1692
+ }
1693
+ case "point":
1694
+ if (s.on !== void 0 && s.x !== void 0) {
1695
+ const o = T(e, s.x);
1696
+ Object.assign(i, { [`${s.id}.x`]: o, [`${s.id}.y`]: U(s.on)(o, r) });
1697
+ }
1698
+ break;
1699
+ case "histogram": {
1700
+ const o = tn(bt(e, s.distribution), s.seed ?? s.id, Xt(T(e, s.count))), { mean: l, sd: c } = Rn(o);
1701
+ Object.assign(i, { [`${s.id}.count`]: o.length, [`${s.id}.mean`]: l, [`${s.id}.sd`]: c });
1702
+ break;
1703
+ }
1704
+ case "distribution": {
1705
+ const o = bt(e, s.distribution);
1706
+ let l = 0;
1707
+ if (s.shade) {
1708
+ const [c, d] = [T(e, s.shade[0]), T(e, s.shade[1])].sort((u, p) => u - p);
1709
+ if (Jt(o))
1710
+ for (let u = Math.max(0, Math.ceil(c)); u <= Math.floor(d) && u <= 5e3; u++) l += ct(o, u);
1711
+ else
1712
+ l = oe((u) => ct(o, u), c, d, 2048);
1713
+ }
1714
+ Object.assign(i, { [`${s.id}.p`]: l, [`${s.id}.mean`]: Pt(o), [`${s.id}.sd`]: It(o) });
1715
+ break;
1716
+ }
1717
+ case "galton":
1718
+ i[`${s.id}.landed`] = Math.max(0, Math.floor(T(e, s.balls)));
1719
+ break;
1720
+ case "scatter": {
1721
+ const o = nn(dn(s, { values: e }), s.seed ?? s.id, Xt(T(e, s.count))), l = s.inside ? dt(s.inside) : void 0, c = l ? o.filter(([u, p]) => lt(l, { ...r, x: u, y: p }) <= 0).length : 0, d = rn(o);
1722
+ Object.assign(i, {
1723
+ [`${s.id}.count`]: o.length,
1724
+ [`${s.id}.inside`]: c,
1725
+ [`${s.id}.ratio`]: o.length ? c / o.length : 0,
1726
+ [`${s.id}.slope`]: d?.slope ?? 0,
1727
+ [`${s.id}.intercept`]: d?.intercept ?? 0,
1728
+ [`${s.id}.r`]: d?.r ?? 0
1729
+ });
1730
+ break;
1731
+ }
1732
+ case "bayes": {
1733
+ const o = T(e, s.prior), l = Bn(o, T(e, s.truePositive), T(e, s.falsePositive));
1734
+ Object.assign(i, { [`${s.id}.prior`]: o, [`${s.id}.posterior`]: l.posterior, [`${s.id}.positive`]: l.positive, [`${s.id}.truePositive`]: l.truePositive, [`${s.id}.falsePositive`]: l.falsePositive });
1735
+ break;
1736
+ }
1737
+ case "graph": {
1738
+ const o = yn(s, e);
1739
+ if (o && (i[`${s.id}.visited`] = o.done, i[`${s.id}.steps`] = o.events.length, s.search?.kind === "dijkstra")) {
1740
+ const l = o.events[o.done - 1]?.distances ?? {};
1741
+ for (const c of s.nodes) i[`${s.id}.d.${c.id}`] = l[c.id] ?? 1 / 0;
1742
+ }
1743
+ break;
1744
+ }
1745
+ case "clock": {
1746
+ const o = T(e, s.value);
1747
+ Object.assign(i, { [`${s.id}.hour`]: mn(o, s.modulus), [`${s.id}.turns`]: Math.floor(Math.round(o) / s.modulus) });
1748
+ break;
1749
+ }
1750
+ case "taylor":
1751
+ i[`${s.id}.order`] = Math.min(20, Math.max(0, T(e, s.order))), i[`${s.id}.degree`] = Math.floor(i[`${s.id}.order`]);
1752
+ break;
1753
+ }
1754
+ return i;
998
1755
  }
999
- const V = (t, e, n) => t + (e - t) * n;
1000
- function ce(t, e, n) {
1756
+ const Y = (t, e, n) => t + (e - t) * n;
1757
+ function Re(t, e, n) {
1001
1758
  return t.kind === "stroke" ? { ...t, points: t.points.map(([i, r]) => [i + e, r + n]) } : { ...t, x: t.x + e, y: t.y + n };
1002
1759
  }
1003
- function hn(t, e, n) {
1760
+ function Si(t, e, n) {
1004
1761
  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) };
1762
+ return { ...e, x: Y(t.x, e.x, n), y: Y(t.y, e.y, n), width: Y(t.width, e.width, n), size: Y(t.size, e.size, n) };
1006
1763
  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) };
1764
+ return { ...e, x: Y(t.x, e.x, n), y: Y(t.y, e.y, n), width: Y(t.width, e.width, n), height: Y(t.height, e.height, n) };
1008
1765
  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)]) };
1766
+ return { ...e, width: Y(t.width, e.width, n), points: t.points.map(([i, r], s) => [Y(i, e.points[s][0], n), Y(r, e.points[s][1], n)]) };
1010
1767
  }
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));
1768
+ const Ai = (t) => t * t * (3 - 2 * t);
1769
+ function Ei(t, e, n) {
1770
+ const i = Math.min(1, Math.max(0, n)), r = t.layout.pieces.map((y) => Re(y, t.x, t.y)), s = e.layout.pieces.map((y) => Re(y, e.x, e.y));
1014
1771
  if (i === 0) return r.map((y) => ({ ...y, opacity: 1 }));
1015
1772
  if (i === 1) return s.map((y) => ({ ...y, opacity: 1 }));
1016
1773
  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);
1774
+ const f = /* @__PURE__ */ new Map();
1775
+ for (const m of y) f.set(m.id, [...f.get(m.id) ?? [], m]);
1776
+ return f;
1777
+ }, l = o(r), c = o(s), d = [], u = Ai(i), p = Math.max(0, 1 - i * 2), h = Math.max(0, i * 2 - 1);
1021
1778
  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 });
1779
+ const f = l.get(y) ?? [], m = c.get(y) ?? [], a = Math.max(f.length, m.length);
1780
+ for (let g = 0; g < a; g++) {
1781
+ const b = f[g], x = m[g], w = b && x ? Si(b, x, u) : void 0;
1782
+ if (w) {
1783
+ d.push({ ...w, opacity: 1 });
1027
1784
  continue;
1028
1785
  }
1029
- w && f.push({ ...w, opacity: h }), $ && f.push({ ...$, opacity: d });
1786
+ b && d.push({ ...b, opacity: p }), x && d.push({ ...x, opacity: h });
1030
1787
  }
1031
1788
  }
1032
- return f.filter((y) => y.opacity > 0);
1789
+ return d.filter((y) => y.opacity > 0);
1033
1790
  }
1034
- const ue = [
1791
+ const Be = [
1035
1792
  "grid",
1036
1793
  "axes",
1037
1794
  "vector",
@@ -1046,8 +1803,16 @@ const ue = [
1046
1803
  "tangent",
1047
1804
  "riemann",
1048
1805
  "area",
1049
- "taylor"
1050
- ], Ut = {
1806
+ "taylor",
1807
+ "histogram",
1808
+ "distribution",
1809
+ "galton",
1810
+ "scatter",
1811
+ "bayes",
1812
+ "graph",
1813
+ "venn",
1814
+ "clock"
1815
+ ], be = {
1051
1816
  dark: {
1052
1817
  background: "#0f1117",
1053
1818
  ink: "#f2f2f2",
@@ -1072,7 +1837,7 @@ const ue = [
1072
1837
  axes: "#eef0e6",
1073
1838
  colors: { blue: "#9fd3f0", green: "#b9e39a", red: "#f59a8f", yellow: "#f6e58d", purple: "#d0b5f2", orange: "#f7c08a", teal: "#a3e4d4", pink: "#f4b6dc", ink: "#eef0e6", grey: "#a9b0a6" }
1074
1839
  }
1075
- }, mn = /* @__PURE__ */ new Set([
1840
+ }, Ti = /* @__PURE__ */ new Set([
1076
1841
  "x",
1077
1842
  "y",
1078
1843
  "z",
@@ -1106,99 +1871,159 @@ const ue = [
1106
1871
  "clipLeft",
1107
1872
  "quaternion"
1108
1873
  ]);
1109
- function bt(t) {
1874
+ function Nt(t) {
1110
1875
  const e = (a) => {
1111
1876
  throw new Error(`math figure: ${a}`);
1112
1877
  };
1113
1878
  (!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
1879
  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`);
1880
+ const g = t[a];
1881
+ 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
1882
  }
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");
1883
+ t.theme !== void 0 && !(t.theme in be) && e(W("theme", t.theme, Object.keys(be))), Array.isArray(t.items) || e("items must be an array");
1119
1884
  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) => {
1885
+ for (const [a, g] of Object.entries(n))
1886
+ /^[A-Za-z_]\w*$/.test(a) || e(`value name "${a}" must be letters, digits and _ (starting with a letter)`), Ti.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) || at(g) || gt(g) || e(`value "${a}" must be a number, an [x, y] vector or an [a, b, c, d] matrix`);
1887
+ const i = Je(n), r = Object.keys(n).filter((a) => typeof n[a] == "number"), s = (a, g, b) => {
1888
+ b !== void 0 && (typeof b == "string" ? (b in n || e(`${a.id}.${g}: ${W("value", b, Object.keys(n))}`), at(n[b]) || e(`${a.id}.${g}: value "${b}" is not an [x, y] vector`)) : at(b) || e(`${a.id}.${g} must be [x, y] or the name of a vector value`));
1889
+ }, o = (a, g, b) => {
1890
+ b !== void 0 && (b in n || e(`${a.id}.${g}: ${W("value", b, Object.keys(n))}`), gt(n[b]) || e(`${a.id}.${g}: value "${b}" is not an [a, b, c, d] matrix`));
1891
+ }, l = (a, g, b, x) => {
1127
1892
  let w = [];
1128
1893
  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) => {
1894
+ w = Le(dt(b));
1895
+ } catch (v) {
1896
+ e(`${a.id}.${g}: ${v.message}`);
1897
+ }
1898
+ for (const v of w)
1899
+ v !== x && !(v in Wt) && !r.includes(v) && e(`${a.id}.${g}: "${v}" is neither ${x} nor a number value (${W("value", v, [x, ...r])})`);
1900
+ }, c = [], d = (a, g, b) => {
1901
+ c.push([a, g, b]);
1902
+ }, u = (a, g, b) => {
1903
+ b !== void 0 && (typeof b == "string" ? (b in n || e(`${a.id}.${g}: ${W("value", b, r)}`), typeof n[b] != "number" && e(`${a.id}.${g}: value "${b}" is not a number`)) : Number.isFinite(b) || e(`${a.id}.${g} must be a number or the name of a number value`));
1904
+ }, p = (a, g, b) => {
1905
+ (!b || typeof b != "object" || !Ut.includes(b.kind)) && e(`${a.id}.${g}: ${W("distribution", b?.kind, Ut)}`);
1906
+ for (const [w, v] of Object.entries(b))
1907
+ w !== "kind" && (w === "of" ? p(a, `${g}.of`, v) : u(a, `${g}.${w}`, v));
1908
+ const x = en(bt(n, b));
1909
+ x && e(`${a.id}.${g}: ${x}`);
1910
+ }, h = (a, g, b) => {
1911
+ let x = [];
1912
+ try {
1913
+ x = Le(dt(b));
1914
+ } catch (w) {
1915
+ e(`${a.id}.${g}: ${w.message}`);
1916
+ }
1917
+ for (const w of x)
1918
+ w !== "x" && w !== "y" && !r.includes(w) && e(`${a.id}.${g}: "${w}" is neither x, y nor a number value`);
1919
+ }, y = (a, g, b, x) => {
1140
1920
  try {
1141
- let w = At(m);
1142
- for (let $ = 0; $ < b; $++) w = G(w);
1921
+ let w = dt(b);
1922
+ for (let v = 0; v < x; v++) w = st(w);
1143
1923
  } catch (w) {
1144
- e(`${a.id}.${p}: ${w.message} (calculus needs functions with derivatives)`);
1924
+ e(`${a.id}.${g}: ${w.message} (calculus needs functions with derivatives)`);
1145
1925
  }
1146
- }, d = /* @__PURE__ */ new Set();
1926
+ }, f = /* @__PURE__ */ new Set();
1147
1927
  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) {
1928
+ switch ((!a || typeof a != "object") && e("every item must be an object"), Be.includes(a.kind) || e(W("item kind", a.kind, Be)), (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
1929
  case "grid":
1150
1930
  a.step !== void 0 && !(a.step > 0) && e(`${a.id}.step must be positive`), o(a, "transform", a.transform);
1151
1931
  break;
1152
1932
  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);
1933
+ s(a, "to", a.to), s(a, "from", a.from), o(a, "transform", a.transform), a.label && d(a, "label", a.label);
1154
1934
  break;
1155
1935
  case "basis":
1156
1936
  o(a, "transform", a.transform);
1157
1937
  break;
1158
1938
  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);
1939
+ 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 && d(a, "label", a.label);
1160
1940
  break;
1161
1941
  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));
1942
+ 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`), y(a, "expr", a.expr, a.derivative));
1163
1943
  break;
1164
1944
  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);
1945
+ l(a, "expr", a.expr, "x"), y(a, "expr", a.expr, 1), u(a, "at", a.at), u(a, "h", a.h), a.label && d(a, "label", a.label);
1166
1946
  break;
1167
1947
  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"])}`);
1948
+ 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: ${W("rule", a.rule, ["left", "right", "midpoint", "trapezoid"])}`);
1169
1949
  break;
1170
1950
  case "area":
1171
1951
  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
1952
  break;
1953
+ case "histogram":
1954
+ 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`);
1955
+ break;
1956
+ case "distribution":
1957
+ p(a, "distribution", a.distribution), a.shade && a.shade.forEach((g, b) => u(a, `shade[${b}]`, g));
1958
+ break;
1959
+ case "galton":
1960
+ 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);
1961
+ break;
1962
+ case "scatter":
1963
+ (!a.points || !["uniform", "linear"].includes(a.points.kind)) && e(`${a.id}.points: ${W("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);
1964
+ break;
1965
+ case "bayes":
1966
+ u(a, "prior", a.prior), u(a, "truePositive", a.truePositive), u(a, "falsePositive", a.falsePositive);
1967
+ break;
1968
+ case "graph": {
1969
+ (!Array.isArray(a.nodes) || a.nodes.length === 0) && e(`${a.id}.nodes needs at least one node`);
1970
+ const g = a.nodes.map((v) => v.id);
1971
+ new Set(g).size !== g.length && e(`${a.id}: two nodes share an id`);
1972
+ const b = (v, k) => {
1973
+ g.includes(k) || e(`${a.id}.${v}: ${W("node", k, g)}`);
1974
+ };
1975
+ Array.isArray(a.edges) || e(`${a.id}.edges must be an array`), te(a).forEach((v, k) => {
1976
+ b(`edges[${k}]`, v.from), b(`edges[${k}]`, v.to), v.weight !== void 0 && !(v.weight >= 0) && e(`${a.id}.edges[${k}]: weights must be ≥ 0 (shortest paths need them)`);
1977
+ }), a.tree && b("tree.root", a.tree.root);
1978
+ const x = fn(a), w = g.filter((v) => !x.has(v));
1979
+ w.length && e(`${a.id}: nodes ${w.join(", ")} have no "at" and are not reached from the tree root`), a.search && (_e.includes(a.search.kind) || e(`${a.id}.search: ${W("search", a.search.kind, _e)}`), b("search.start", a.search.start)), u(a, "step", a.step), a.nodes.forEach((v) => v.label !== void 0 && d(a, `nodes.${v.id}.label`, v.label));
1980
+ break;
1981
+ }
1982
+ case "venn": {
1983
+ (!Array.isArray(a.sets) || a.sets.length < 2 || a.sets.length > 3) && e(`${a.id}.sets: give two or three sets`);
1984
+ const g = a.sets.map((b) => b.id);
1985
+ if (g.every((b) => /^[A-Za-z]\w*$/.test(b)) || e(`${a.id}.sets: ids must be names like A, B, Evens`), a.highlight)
1986
+ try {
1987
+ for (const b of Vt(hn(a.highlight)))
1988
+ g.includes(b) || e(`${a.id}.highlight: ${W("set", b, g)}`);
1989
+ } catch (b) {
1990
+ e(`${a.id}.highlight: ${b.message}`);
1991
+ }
1992
+ a.sets.forEach((b) => b.label !== void 0 && d(a, `sets.${b.id}.label`, b.label));
1993
+ break;
1994
+ }
1995
+ case "clock":
1996
+ (!Number.isInteger(a.modulus) || a.modulus < 2 || a.modulus > 60) && e(`${a.id}.modulus must be a whole number 2..60`), u(a, "value", a.value);
1997
+ break;
1173
1998
  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);
1999
+ l(a, "expr", a.expr, "x"), y(a, "expr", a.expr, 3), u(a, "at", a.at), u(a, "order", a.order);
1175
2000
  break;
1176
2001
  case "parametric":
1177
2002
  l(a, "x", a.x, "t"), l(a, "y", a.y, "t"), o(a, "transform", a.transform);
1178
2003
  break;
1179
2004
  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);
2005
+ a.points !== void 0 && !(Array.isArray(a.points) && a.points.length >= 3 && a.points.every(at)) && 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
2006
  break;
1182
2007
  case "line":
1183
2008
  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);
1184
2009
  break;
1185
2010
  case "label":
1186
- s(a, "at", a.at), f(a, "tex", a.tex);
2011
+ s(a, "at", a.at), d(a, "tex", a.tex);
1187
2012
  break;
1188
2013
  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));
2014
+ 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((g, b) => d(a, `steps[${b}]`, g));
1190
2015
  break;
1191
2016
  }
1192
- const y = { ...i, ...Se(t.items, n, i) };
1193
- for (const [a, p, m] of c)
2017
+ const m = { ...i, ...vn(t.items, n, i) };
2018
+ for (const [a, g, b] of c)
1194
2019
  try {
1195
- ut(m, { values: y });
1196
- } catch (b) {
1197
- e(`${a.id}.${p}: ${b.message}`);
2020
+ J(b, { values: m });
2021
+ } catch (x) {
2022
+ e(`${a.id}.${g}: ${x.message}`);
1198
2023
  }
1199
2024
  return t;
1200
2025
  }
1201
- function Te(t) {
2026
+ function wn(t) {
1202
2027
  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]);
1203
2028
  return {
1204
2029
  width: e,
@@ -1212,206 +2037,112 @@ function Te(t) {
1212
2037
  toWorld: ([l, c]) => [i[0] + l / r, s[1] - c / o]
1213
2038
  };
1214
2039
  }
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;
2040
+ function Oi(t, e) {
2041
+ 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(Ot(e)) / l;
1276
2042
  return Math.min(n * 12, n / Math.max(c, 0.08)) + 1;
1277
2043
  }
1278
- function fe(t, e, n) {
1279
- const i = yn(t, e), r = Math.min(120, Math.ceil(i / n)), s = [];
2044
+ function Ve(t, e, n) {
2045
+ const i = Oi(t, e), r = Math.min(120, Math.ceil(i / n)), s = [];
1280
2046
  for (let o = -r; o <= r; o++) {
1281
2047
  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 });
2048
+ s.push({ line: [K(e, [l, -i]), K(e, [l, i])].map(t.toScreen), axis: o === 0 }), s.push({ line: [K(e, [-i, l]), K(e, [i, l])].map(t.toScreen), axis: o === 0 });
1283
2049
  }
1284
2050
  return s;
1285
2051
  }
1286
- function gn(t, e) {
2052
+ function Pi(t, e) {
1287
2053
  const { plane: n, theme: i } = e, r = t.step ?? 1, s = [], o = 1.4 * n.scale;
1288
2054
  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 });
2055
+ for (const [c, { line: d }] of Ve(n, [1, 0, 0, 1], r).entries())
2056
+ s.push({ type: "line", id: `${t.id}.ghost.${c}`, points: d, stroke: i.ghost, width: o, opacity: e.opacity });
2057
+ const l = O(i, t.color, i.grid);
2058
+ for (const [c, { line: d, axis: u }] of Ve(n, pt(e.values, t.transform), r).entries()) {
2059
+ const [p] = B([d], e.draw);
2060
+ p && s.push({ type: "line", id: `${t.id}.${c}`, points: p, stroke: u ? i.ink : l, width: u ? o * 1.6 : o, opacity: e.opacity });
1295
2061
  }
1296
2062
  return s;
1297
2063
  }
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);
2064
+ function Ii(t, e) {
2065
+ const { plane: n, theme: i } = e, r = O(i, t.color, i.axes), s = 2 * n.scale, o = e.opacity, l = B([[n.toScreen([n.x[0], 0]), n.toScreen([n.x[1], 0])]], e.draw), c = B([[n.toScreen([0, n.y[0]]), n.toScreen([0, n.y[1]])]], e.draw), d = [...l, ...c].map((m, a) => ({ type: "line", id: `${t.id}.${a ? "y" : "x"}`, points: m, stroke: r, width: s, opacity: o })), u = t.ticks ?? 1;
2066
+ if (u <= 0 || e.draw < 1) return d;
2067
+ const p = 5 * n.scale, h = 13 * n.scale, y = (m, a) => {
2068
+ const g = [];
2069
+ for (let b = Math.ceil(m / u) * u; b <= a + 1e-9; b += u) Math.abs(b) > 1e-9 && g.push(Number(b.toFixed(6)));
2070
+ return g;
2071
+ }, f = (m) => String(m).replace("-", "−");
2072
+ for (const m of y(n.x[0], n.x[1])) {
2073
+ const [a, g] = n.toScreen([m, 0]);
2074
+ d.push({ type: "line", id: `${t.id}.tick.x${m}`, points: [[a, g - p], [a, g + p]], stroke: r, width: s * 0.8, opacity: o }), t.labels !== !1 && d.push({ type: "text", id: `${t.id}.label.x${m}`, text: f(m), x: a, y: g + p + h * 1.1, size: h, font: mt, color: r, align: "center", opacity: o * 0.8 });
2075
+ }
2076
+ for (const m of y(n.y[0], n.y[1])) {
2077
+ const [a, g] = n.toScreen([0, m]);
2078
+ d.push({ type: "line", id: `${t.id}.tick.y${m}`, points: [[a - p, g], [a + p, g]], stroke: r, width: s * 0.8, opacity: o }), t.labels !== !1 && d.push({ type: "text", id: `${t.id}.label.y${m}`, text: f(m), x: a - p - h * 0.4, y: g + h * 0.35, size: h, font: mt, color: r, align: "right", opacity: o * 0.8 });
2079
+ }
2080
+ return d;
2081
+ }
2082
+ function Yt(t, e, n, i, r, s) {
2083
+ const o = 26 * s.plane.scale, [l, c] = St(n), d = J(t, { values: s.scope, style: "inline" }), u = o * (0.55 + Math.abs(l) * d.width * 0.5);
2084
+ return it(d, { x: e[0] + l * u, y: e[1] + c * u, size: o, color: i, opacity: s.opacity, idPrefix: `${r}.label.` });
2085
+ }
2086
+ function kn(t, e, n, i, r, s) {
2087
+ const o = s.plane.toScreen(e), l = s.plane.toScreen(n), [c] = B([[o, l]], s.draw);
1322
2088
  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);
2089
+ const d = Math.hypot(l[0] - o[0], l[1] - o[1]), u = Math.min(r * 3.6, d * 0.45);
1324
2090
  return [{ type: "arrow", id: t, points: c, stroke: i, width: r, head: u, opacity: s.opacity }];
1325
2091
  }
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);
2092
+ function Ni(t, e) {
2093
+ const n = pt(e.values, t.transform), i = K(n, t.from === void 0 ? [0, 0] : At(e.values, t.from)), r = K(n, At(e.values, t.to)), s = O(e.theme, t.color, e.theme.colors.yellow), o = kn(t.id, i, r, s, (t.width ?? 4) * e.plane.scale, e);
1328
2094
  if (t.label && e.draw >= 1) {
1329
- const l = e.plane.toScreen(r), c = e.plane.toScreen(i), f = Xt(l, c);
2095
+ const l = e.plane.toScreen(r), c = e.plane.toScreen(i), d = ke(l, c);
1330
2096
  if (t.labelAt === "middle") {
1331
2097
  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));
2098
+ o.push(...Yt(t.label, u, [d[1], -d[0]], s, t.id, e));
1333
2099
  } else
1334
- o.push(...Tt(t.label, l, f, s, t.id, e));
2100
+ o.push(...Yt(t.label, l, d, s, t.id, e));
1335
2101
  }
1336
2102
  return o;
1337
2103
  }
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 = [
2104
+ function Li(t, e) {
2105
+ const n = pt(e.values, t.transform), i = 4.5 * e.plane.scale, r = e.plane.toScreen([0, 0]), s = [], o = [
1340
2106
  ["i", [1, 0], e.theme.colors.green, "\\hat{i}"],
1341
2107
  ["j", [0, 1], e.theme.colors.red, "\\hat{j}"]
1342
2108
  ];
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));
2109
+ for (const [l, c, d, u] of o) {
2110
+ const p = K(n, c);
2111
+ if (s.push(...kn(`${t.id}.${l}`, [0, 0], p, d, i, e)), t.labels !== !1 && e.draw >= 1) {
2112
+ const h = e.plane.toScreen(p);
2113
+ s.push(...Yt(u, h, ke(h, r), d, `${t.id}.${l}`, e));
1348
2114
  }
1349
2115
  }
1350
2116
  return s;
1351
2117
  }
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);
2118
+ function Fi(t, e) {
2119
+ const n = t.on !== void 0 ? [e.scope[`${t.id}.x`], e.scope[`${t.id}.y`]] : At(e.values, t.at);
1354
2120
  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);
2121
+ const i = K(pt(e.values, t.transform), n), [r, s] = e.plane.toScreen(i), o = O(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 }, d = l > 0 ? [c] : [];
2122
+ return t.label && e.draw >= 1 && d.push(...Yt(t.label, [r, s], [0.7, -0.7], o, t.id, e)), d;
1385
2123
  }
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 = [
2124
+ const Ci = [[0, 0], [1, 0], [1, 1], [0, 1]];
2125
+ function qi(t, e) {
2126
+ const n = pt(e.values, t.transform), i = (t.points ?? Ci).map((l) => K(n, l)), r = i.map(e.plane.toScreen), s = O(e.theme, t.color, e.theme.colors.yellow), o = [
1396
2127
  { 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 }))
2128
+ ...B([[...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 }))
1398
2129
  ];
1399
2130
  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.` }));
2131
+ 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);
2132
+ o.push(...it(J(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
2133
  }
1403
2134
  return o;
1404
2135
  }
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;
2136
+ function zi(t, e) {
2137
+ const n = t.eigen ? Ke(pt(e.values, t.eigen)).map((o) => o.vector) : t.along !== void 0 ? [At(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 = O(e.theme, t.color, e.theme.colors.yellow), s = (t.width ?? 2.5) * e.plane.scale;
1407
2138
  return n.flatMap((o, l) => {
1408
2139
  const c = Math.hypot(o[0], o[1]);
1409
2140
  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) => ({
2141
+ const d = le(o, i / c), u = [le(d, -1), d].map(e.plane.toScreen);
2142
+ return B([u], e.draw).map((p) => ({
1412
2143
  type: "line",
1413
2144
  id: `${t.id}.${l}`,
1414
- points: h,
2145
+ points: p,
1415
2146
  stroke: r,
1416
2147
  width: s,
1417
2148
  opacity: e.opacity,
@@ -1419,12 +2150,12 @@ function En(t, e) {
1419
2150
  }));
1420
2151
  });
1421
2152
  }
1422
- function Ht(t, e, n, i) {
2153
+ function ve(t, e, n, i) {
1423
2154
  const r = n.size * 0.35;
1424
2155
  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);
2156
+ for (const d of e) {
2157
+ const [u, p] = xe(d, n);
2158
+ s = Math.min(s, u - r), l = Math.max(l, u + d.width * n.size + r), o = Math.min(o, p - d.height * n.size - r), c = Math.max(c, p + d.depth * n.size + r);
1428
2159
  }
1429
2160
  return [{
1430
2161
  type: "line",
@@ -1435,159 +2166,182 @@ function Ht(t, e, n, i) {
1435
2166
  opacity: (n.opacity ?? 1) * 0.85
1436
2167
  }];
1437
2168
  }
1438
- function Pe(t, e, n) {
1439
- const i = pt(n.values, t);
2169
+ function $n(t, e, n) {
2170
+ const i = At(n.values, t);
1440
2171
  return e ? i : n.plane.toScreen(i);
1441
2172
  }
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)];
1445
- }
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)];
1451
- }
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);
2173
+ function ji(t, e) {
2174
+ const [n, i] = $n(t.at, t.screen, e), r = (t.size ?? 28) * e.plane.scale, s = O(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 = J(t.tex, { values: e.scope });
2175
+ return [...t.backdrop ?? t.screen ?? !1 ? ve(t.id, [l], o, e) : [], ...it(l, o)];
2176
+ }
2177
+ function Di(t, e) {
2178
+ const [n, i] = $n(t.at, t.screen, e), r = (t.size ?? 36) * e.plane.scale, s = O(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: r, color: s, align: t.align, opacity: e.opacity * e.draw, idPrefix: `${t.id}.` }, p = (a) => J(t.steps[a], { values: e.scope }), h = t.backdrop ?? t.screen ?? !1;
2179
+ if (d === 0 || c >= o) {
2180
+ const a = p(c);
2181
+ return [...h ? ve(t.id, [a], u, e) : [], ...it(a, u)];
2182
+ }
2183
+ const y = (a) => {
2184
+ const [g, b] = xe(a, u);
2185
+ return { layout: a, x: g / r, y: b / r };
2186
+ }, f = p(c), m = p(c + 1);
1456
2187
  return [
1457
- ...d ? Ht(t.id, [a, p], u, e) : [],
1458
- ...Oe(pn(y(a), y(p), f), [0, 0], u)
2188
+ ...h ? ve(t.id, [f, m], u, e) : [],
2189
+ ...an(Ei(y(f), y(m), d), [0, 0], u)
1459
2190
  ];
1460
2191
  }
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`];
2192
+ function _i(t, e) {
2193
+ const n = U(t.expr), i = T(e.values, t.at), r = t.h === void 0 ? 0 : T(e.values, t.h), s = n(i, e.scope), o = e.scope[`${t.id}.slope`];
1463
2194
  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 }))
2195
+ 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]], d = O(e.theme, t.color, e.theme.colors.yellow), u = e.plane.toScreen([i, s]), p = c.map(e.plane.toScreen), h = [p[0], p[1]].flatMap(
2196
+ (y, f) => B([[u, y]], e.draw).map((m) => ({ type: "line", id: `${t.id}.${f}`, points: m, stroke: d, width: (t.width ?? 3) * e.plane.scale, opacity: e.opacity }))
1466
2197
  );
1467
2198
  if (t.points !== !1) {
1468
2199
  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 });
2200
+ if (h.push({ type: "circle", id: `${t.id}.point`, x: u[0], y: u[1], r: y, fill: d, opacity: e.opacity }), Math.abs(r) > 1e-9) {
2201
+ const [f, m] = e.plane.toScreen([i + r, n(i + r, e.scope)]);
2202
+ Number.isFinite(m) && h.push({ type: "circle", id: `${t.id}.secant`, x: f, y: m, r: y, fill: d, opacity: e.opacity });
1472
2203
  }
1473
2204
  }
1474
2205
  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.` }));
2206
+ const y = 24 * e.plane.scale, f = J(t.label, { values: e.scope, style: "inline" });
2207
+ h.push(...it(f, { x: u[0], y: u[1] - y * 1.6, size: y, color: d, opacity: e.opacity, idPrefix: `${t.id}.label.` }));
1477
2208
  }
1478
- return d;
2209
+ return h;
1479
2210
  }
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) }];
2211
+ function Ri(t, e) {
2212
+ const n = U(t.expr), i = T(e.values, t.from), r = T(e.values, t.to), s = bn(T(e.values, t.n)), o = gn((u) => n(u, e.scope), i, r, s, t.rule ?? "left"), l = O(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 / s)) * e.plane.scale;
2213
+ return o.slice(0, c).flatMap(([u, p, h, y], f) => {
2214
+ if (!Number.isFinite(h) || !Number.isFinite(y)) return [];
2215
+ const m = [[u, 0], [p, 0], [p, y], [u, h]].map(e.plane.toScreen), g = (h + y) / 2 < 0 ? O(e.theme, "red", e.theme.colors.red) : l;
2216
+ return [{ type: "line", id: `${t.id}.${f}`, points: m, closed: !0, fill: g, stroke: g, width: d, opacity: e.opacity * (t.fillOpacity ?? 0.35) }];
1486
2217
  });
1487
2218
  }
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;
2219
+ function Bi(t, e) {
2220
+ const n = U(t.expr), i = t.lower ? U(t.lower) : () => 0, r = T(e.values, t.from), s = r + (T(e.values, t.to) - r) * e.draw;
1490
2221
  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 = [];
2222
+ const o = 240, l = O(e.theme, t.color, e.theme.colors.blue), c = O(e.theme, t.negativeColor, e.theme.colors.red), d = e.opacity * (t.fillOpacity ?? 0.4), u = [];
2223
+ let p = [], h = [], y;
2224
+ const f = () => {
2225
+ p.length >= 2 && u.push({ type: "line", id: `${t.id}.${u.length}`, points: [...p, ...h.reverse()].map(e.plane.toScreen), closed: !0, fill: y ? l : c, opacity: d }), p = [], h = [];
1495
2226
  };
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;
2227
+ let m;
2228
+ for (let a = 0; a <= o; a++) {
2229
+ const g = r + (s - r) * a / o, b = n(g, e.scope), x = i(g, e.scope);
2230
+ if (!Number.isFinite(b) || !Number.isFinite(x)) {
2231
+ f(), m = void 0;
1501
2232
  continue;
1502
2233
  }
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]);
2234
+ const w = b - x >= 0;
2235
+ if (m && y !== void 0 && w !== y) {
2236
+ const v = m.fy - m.gy, k = b - x, M = v / (v - k), $ = m.x + (g - m.x) * M, S = m.gy + (x - m.gy) * M;
2237
+ p.push([$, S]), h.push([$, S]), f(), p.push([$, S]), h.push([$, S]);
1507
2238
  }
1508
- y = g, h.push([b, w]), d.push([b, $]), p = { x: b, fy: w, gy: $ };
2239
+ y = w, p.push([g, b]), h.push([g, x]), m = { x: g, fy: b, gy: x };
1509
2240
  }
1510
- return a(), u;
2241
+ return f(), u;
1511
2242
  }
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);
2243
+ const Vi = 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));
2244
+ function Hi(t, e) {
2245
+ const n = T(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 }, (p, h) => $e(t.expr, h)(n, e.scope) / Vi[h]), l = (p) => {
2246
+ let h = 0, y = 1;
2247
+ for (let f = 0; f <= r; f++)
2248
+ h += o[f] * y, y *= p - n;
2249
+ return s > 0 && r < 20 ? h + s * o[r + 1] * y : h;
2250
+ }, c = O(e.theme, t.color, e.theme.colors.yellow), [d, u] = t.domain ?? e.plane.x;
2251
+ return Qt(t.id, (p) => l(p), d, u, c, (t.width ?? 3.5) * e.plane.scale, e);
1521
2252
  }
1522
- function Cn(t, e) {
2253
+ function Wi(t, e) {
1523
2254
  switch (t.kind) {
1524
2255
  case "grid":
1525
- return gn(t, e);
2256
+ return Pi(t, e);
1526
2257
  case "axes":
1527
- return bn(t, e);
2258
+ return Ii(t, e);
1528
2259
  case "vector":
1529
- return vn(t, e);
2260
+ return Ni(t, e);
1530
2261
  case "basis":
1531
- return wn(t, e);
2262
+ return Li(t, e);
1532
2263
  case "point":
1533
- return kn(t, e);
2264
+ return Fi(t, e);
1534
2265
  case "function":
1535
- return $n(t, e);
2266
+ return oi(t, e);
1536
2267
  case "parametric":
1537
- return xn(t, e);
2268
+ return ai(t, e);
1538
2269
  case "polygon":
1539
- return Sn(t, e);
2270
+ return qi(t, e);
1540
2271
  case "line":
1541
- return En(t, e);
2272
+ return zi(t, e);
1542
2273
  case "label":
1543
- return An(t, e);
2274
+ return ji(t, e);
1544
2275
  case "equation":
1545
- return Tn(t, e);
2276
+ return Di(t, e);
1546
2277
  case "tangent":
1547
- return On(t, e);
2278
+ return _i(t, e);
1548
2279
  case "riemann":
1549
- return Ln(t, e);
2280
+ return Ri(t, e);
1550
2281
  case "area":
1551
- return Nn(t, e);
2282
+ return Bi(t, e);
1552
2283
  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 = [];
2284
+ return Hi(t, e);
2285
+ case "histogram":
2286
+ return li(t, e);
2287
+ case "distribution":
2288
+ return ci(t, e);
2289
+ case "galton":
2290
+ return ui(t, e);
2291
+ case "scatter":
2292
+ return di(t, e);
2293
+ case "bayes":
2294
+ return hi(t, e);
2295
+ case "graph":
2296
+ return ki(t, e);
2297
+ case "venn":
2298
+ return Mi(t, e);
2299
+ case "clock":
2300
+ return xi(t, e);
2301
+ }
2302
+ }
2303
+ const He = (t) => Math.min(1, Math.max(0, t));
2304
+ function ee(t, e = {}) {
2305
+ const n = be[t.theme ?? "dark"], i = wn(t), r = { ...t.values }, s = /* @__PURE__ */ new Map();
2306
+ for (const [u, p] of Object.entries(e))
2307
+ u.indexOf(".") < 0 ? typeof p != "string" && (r[u] = p) : typeof p == "number" && s.set(u, p);
2308
+ const o = Je(r), l = { ...o, ...vn(t.items, r, o) }, c = [];
1562
2309
  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 }));
2310
+ const p = (f) => s.get(`${u.id}.${f}`), h = He(p("draw") ?? u.draw ?? 1), y = He(p("opacity") ?? u.opacity ?? 1);
2311
+ h <= 0 || y <= 0 || c.push(...Wi(u, { plane: i, theme: n, values: r, scope: l, draw: h, opacity: y, prop: p }));
1565
2312
  }
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 };
2313
+ const d = t.background === "none" ? void 0 : t.background ?? n.background;
2314
+ return { width: t.width, height: t.height, ...d ? { background: d } : {}, shapes: c };
1568
2315
  }
1569
- function qe(t, e) {
2316
+ function Mn(t, e) {
1570
2317
  if (t.length < 2) return { shaft: t, head: void 0 };
1571
2318
  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);
1572
2319
  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;
2320
+ const l = r / o, c = s / o, d = Math.min(e, o), u = [n[0] - l * d, n[1] - c * d], p = d * 0.55;
1574
2321
  return {
1575
2322
  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]]
2323
+ head: [n, [u[0] - c * p, u[1] + l * p], [u[0] + c * p, u[1] - l * p]]
1577
2324
  };
1578
2325
  }
1579
- function It(t, e, n = !1) {
2326
+ function jt(t, e, n = !1) {
1580
2327
  t.beginPath(), e.forEach(([i, r], s) => s === 0 ? t.moveTo(i, r) : t.lineTo(i, r)), n && t.closePath();
1581
2328
  }
1582
- function Pn(t, e) {
2329
+ function xn(t, e) {
1583
2330
  switch (t.globalAlpha = e.opacity ?? 1, e.type) {
1584
2331
  case "line":
1585
2332
  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([]));
2333
+ if (e.clip?.length) {
2334
+ t.save();
2335
+ for (const { points: n, outside: i } of e.clip)
2336
+ jt(t, n, !0), i ? (t.rect(-1e6, -1e6, 2e6, 2e6), t.clip("evenodd")) : t.clip();
2337
+ xn(t, { ...e, clip: void 0 }), t.restore();
2338
+ return;
2339
+ }
2340
+ jt(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
2341
  return;
1588
2342
  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());
2343
+ const { shaft: n, head: i } = Mn(e.points, e.head);
2344
+ t.strokeStyle = e.stroke, t.fillStyle = e.stroke, t.lineWidth = e.width, n.length >= 2 && (jt(t, n), t.stroke()), i && (jt(t, i, !0), t.fill());
1591
2345
  return;
1592
2346
  }
1593
2347
  case "circle":
@@ -1597,41 +2351,48 @@ function Pn(t, e) {
1597
2351
  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
2352
  }
1599
2353
  }
1600
- function qn(t, e) {
2354
+ function Ui(t, e) {
1601
2355
  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);
2356
+ for (const n of e.shapes) xn(t, n);
1603
2357
  t.restore();
1604
2358
  }
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) {
2359
+ const q = (t) => String(Math.round(t * 100) / 100), Z = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), $t = (t, e = !1) => t.map(([n, i], r) => `${r ? "L" : "M"}${q(n)} ${q(i)}`).join("") + (e ? "Z" : ""), Dt = (t) => t.opacity !== void 0 && t.opacity < 1 ? ` opacity="${q(t.opacity)}"` : "";
2360
+ function Sn(t) {
1607
2361
  switch (t.type) {
1608
2362
  case "line": {
1609
2363
  if (t.points.length < 2) return "";
1610
- 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)}/>`;
2364
+ if (t.clip?.length) {
2365
+ const r = t.clip.map(({ points: o, outside: l }) => {
2366
+ const c = l ? `M-1000000 -1000000H1000000V1000000H-1000000Z${$t(o, !0)}` : $t(o, !0), d = `tfclip${Kt(`${l ? "o" : "i"}${c}`).toString(36)}`;
2367
+ return { id: d, def: `<clipPath id="${d}"><path d="${c}"${l ? ' clip-rule="evenodd"' : ""}/></clipPath>` };
2368
+ }), s = Sn({ ...t, clip: void 0 });
2369
+ return `<defs>${r.map((o) => o.def).join("")}</defs>` + r.reduceRight((o, l) => `<g clip-path="url(#${l.id})">${o}</g>`, s);
2370
+ }
2371
+ const e = t.fill ? ` fill="${Z(t.fill)}"` : ' fill="none"', n = t.stroke && (t.width ?? 1) > 0 ? ` stroke="${Z(t.stroke)}" stroke-width="${q(t.width ?? 1)}"` : "", i = t.dash?.length ? ` stroke-dasharray="${t.dash.map(q).join(" ")}"` : "";
2372
+ return `<path d="${$t(t.points, t.closed)}"${e}${n}${i}${Dt(t)}/>`;
1612
2373
  }
1613
2374
  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>`;
2375
+ const { shaft: e, head: n } = Mn(t.points, t.head), i = Z(t.stroke), r = e.length >= 2 ? `<path d="${$t(e)}" fill="none" stroke="${i}" stroke-width="${q(t.width)}"/>` : "", s = n ? `<path d="${$t(n, !0)}" fill="${i}"/>` : "";
2376
+ return `<g${Dt(t)}>${r}${s}</g>`;
1616
2377
  }
1617
2378
  case "circle": {
1618
- 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)}/>`;
2379
+ const e = t.fill ? ` fill="${Z(t.fill)}"` : ' fill="none"', n = t.stroke ? ` stroke="${Z(t.stroke)}" stroke-width="${q(t.width ?? 1)}"` : "";
2380
+ return `<circle cx="${q(t.x)}" cy="${q(t.y)}" r="${q(t.r)}"${e}${n}${Dt(t)}/>`;
1620
2381
  }
1621
2382
  case "text": {
1622
2383
  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>`;
2384
+ return `<text x="${q(t.x)}" y="${q(t.y)}" font-size="${q(t.size)}" font-family="${Z(t.font)}"${n} text-anchor="${e}" fill="${Z(t.color)}"${Dt(t)}>${Z(t.text)}</text>`;
1624
2385
  }
1625
2386
  }
1626
2387
  }
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>`;
2388
+ function Ae(t) {
2389
+ return `${t.background ? `<rect width="${q(t.width)}" height="${q(t.height)}" fill="${Z(t.background)}"/>` : ""}<g stroke-linecap="round" stroke-linejoin="round">${t.shapes.map(Sn).join("")}</g>`;
1629
2390
  }
1630
- function jn(t, e = {}) {
1631
- 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>`;
2391
+ function Gi(t, e = {}) {
2392
+ const n = e.title ? `<title>${Z(e.title)}</title>` : "", i = e.title ? ` role="img" aria-label="${Z(e.title)}"` : "";
2393
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${q(t.width)} ${q(t.height)}" width="${q(t.width)}" height="${q(t.height)}"${i}>${n}${Ae(t)}</svg>`;
1633
2394
  }
1634
- function Dn(t) {
2395
+ function Xi(t) {
1635
2396
  const e = {};
1636
2397
  for (const [n, i] of Object.entries(t.values ?? {})) {
1637
2398
  const r = typeof i == "number" ? "number" : i.length === 2 ? "[x, y] vector" : "[a, b, c, d] matrix";
@@ -1641,9 +2402,9 @@ function Dn(t) {
1641
2402
  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
2403
  return e;
1643
2404
  }
1644
- function pi(t, e = {}) {
1645
- bt(t);
1646
- const n = Dn(t), i = { ...t.values ?? {} };
2405
+ function Mr(t, e = {}) {
2406
+ Nt(t);
2407
+ const n = Xi(t), i = { ...t.values ?? {} };
1647
2408
  return {
1648
2409
  type: "custom",
1649
2410
  x: e.x ?? 0,
@@ -1653,7 +2414,7 @@ function pi(t, e = {}) {
1653
2414
  props: i,
1654
2415
  acceptsProp: (r) => Object.prototype.hasOwnProperty.call(n, r),
1655
2416
  draw(r, s) {
1656
- qn(r, Lt(t, s.props ?? {}));
2417
+ Ui(r, ee(t, s.props ?? {}));
1657
2418
  },
1658
2419
  about: {
1659
2420
  kind: "math figure",
@@ -1662,7 +2423,7 @@ function pi(t, e = {}) {
1662
2423
  }
1663
2424
  };
1664
2425
  }
1665
- function mi(t, e, n, i = {}) {
2426
+ function xr(t, e, n, i = {}) {
1666
2427
  const r = new Set(n.items.map((c) => c.id)), s = (c) => {
1667
2428
  if (!r.has(c)) throw new Error(`mathSteps: no item "${c}" (items: ${[...r].join(", ")})`);
1668
2429
  }, o = { ...n.values ?? {} };
@@ -1672,31 +2433,31 @@ function mi(t, e, n, i = {}) {
1672
2433
  s(c), o[`${c}.draw`] = 0;
1673
2434
  t.initial(e, o);
1674
2435
  const l = {
1675
- toValue(c, f, u) {
2436
+ toValue(c, d, u) {
1676
2437
  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;
2438
+ return t.to(e, { [c]: d }, { duration: 1200, ...u }), l;
1678
2439
  },
1679
- applyMatrix(c, f = {}) {
1680
- const { name: u = "M", ...h } = f;
2440
+ applyMatrix(c, d = {}) {
2441
+ const { name: u = "M", ...p } = d;
1681
2442
  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 });
2443
+ return l.toValue(u, c, { duration: 1600, ...p });
1683
2444
  },
1684
- drawOn(c, f) {
1685
- return s(c), t.to(e, { [`${c}.draw`]: 1 }, { duration: 900, ...f }), l;
2445
+ drawOn(c, d) {
2446
+ return s(c), t.to(e, { [`${c}.draw`]: 1 }, { duration: 900, ...d }), l;
1686
2447
  },
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;
2448
+ fadeIn(c, d) {
2449
+ return s(c), t.set(e, { [`${c}.draw`]: 1, [`${c}.opacity`]: 0 }), t.to(e, { [`${c}.opacity`]: 1 }, { duration: 500, ...d }), l;
1689
2450
  },
1690
- fadeOut(c, f) {
1691
- return s(c), t.to(e, { [`${c}.opacity`]: 0 }, { duration: 500, ...f }), l;
2451
+ fadeOut(c, d) {
2452
+ return s(c), t.to(e, { [`${c}.opacity`]: 0 }, { duration: 500, ...d }), l;
1692
2453
  },
1693
- showStep(c, f, u) {
1694
- return s(c), t.to(e, { [`${c}.step`]: f }, { duration: 900, ...u }), l;
2454
+ showStep(c, d, u) {
2455
+ return s(c), t.to(e, { [`${c}.step`]: d }, { duration: 900, ...u }), l;
1695
2456
  }
1696
2457
  };
1697
2458
  return l;
1698
2459
  }
1699
- class me {
2460
+ class We {
1700
2461
  media;
1701
2462
  offset;
1702
2463
  driftTolerance;
@@ -1735,7 +2496,7 @@ class me {
1735
2496
  });
1736
2497
  }
1737
2498
  }
1738
- function _n(t, e, n, i, r) {
2499
+ function Yi(t, e, n, i, r) {
1739
2500
  const s = n - r;
1740
2501
  if (s < 0) {
1741
2502
  e.paused || e.pause(), e.currentTime = 0;
@@ -1743,7 +2504,7 @@ function _n(t, e, n, i, r) {
1743
2504
  }
1744
2505
  t.update(s, i);
1745
2506
  }
1746
- class Rn {
2507
+ class Zi {
1747
2508
  container;
1748
2509
  timeline = null;
1749
2510
  adapter;
@@ -1782,7 +2543,7 @@ class Rn {
1782
2543
  this.container = i;
1783
2544
  } else
1784
2545
  this.container = e;
1785
- this.options = n, this.adapter = new re();
2546
+ this.options = n, this.adapter = new Ne();
1786
2547
  }
1787
2548
  /**
1788
2549
  * Load animation from a URL or JSON object.
@@ -1808,7 +2569,7 @@ class Rn {
1808
2569
  */
1809
2570
  useDefinition(e) {
1810
2571
  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();
2572
+ 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();
1812
2573
  }
1813
2574
  // --- scenarios: the reader chooses which timeline plays --------------------
1814
2575
  /**
@@ -1975,13 +2736,13 @@ class Rn {
1975
2736
  scanMedia() {
1976
2737
  this.mediaTargets = [], this.container.querySelectorAll("[data-tinyfly-media]").forEach((n) => {
1977
2738
  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) });
2739
+ s !== null && (i.volume = Math.max(0, Math.min(1, Number(s) || 0))), this.mediaTargets.push({ el: i, startTime: r, sync: new We(i) });
1979
2740
  });
1980
2741
  }
1981
2742
  /** Sync all discovered media targets to a timeline time. */
1982
2743
  syncAllMedia(e, n) {
1983
2744
  for (const i of this.mediaTargets)
1984
- _n(i.sync, i.el, e, n, i.startTime);
2745
+ Yi(i.sync, i.el, e, n, i.startTime);
1985
2746
  }
1986
2747
  /**
1987
2748
  * Load animation from inline JSON string.
@@ -2031,11 +2792,11 @@ class Rn {
2031
2792
  if (!r) return;
2032
2793
  const s = n.get(r);
2033
2794
  if (!s || !s.timeline.tracks?.length) return;
2034
- const o = new re();
2795
+ const o = new Ne();
2035
2796
  i.querySelectorAll("[data-tinyfly]").forEach((l) => {
2036
2797
  const c = l.getAttribute("data-tinyfly");
2037
2798
  c && o.registerTarget(c, l);
2038
- }), this.symbolInstances.push({ adapter: o, timeline: ie(s.timeline) });
2799
+ }), this.symbolInstances.push({ adapter: o, timeline: Ie(s.timeline) });
2039
2800
  });
2040
2801
  }
2041
2802
  /**
@@ -2045,7 +2806,7 @@ class Rn {
2045
2806
  * plays. Pass `{ offset }` to start the media at a timeline offset.
2046
2807
  */
2047
2808
  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));
2809
+ this.mediaSync = new We(e, n), this.timeline && (this.mediaSync.setRate(this.timeline.speed), this.mediaSync.update(this.timeline.currentTime, this.isPlaying));
2049
2810
  }
2050
2811
  /** Detach and pause the currently synced media, if any. */
2051
2812
  detachMedia() {
@@ -2152,7 +2913,7 @@ class Rn {
2152
2913
  this.playhead = i;
2153
2914
  const r = this.markers;
2154
2915
  if (r.length === 0) return;
2155
- const { crossings: s } = De(
2916
+ const { crossings: s } = Tn(
2156
2917
  r.map((o) => o.time),
2157
2918
  e,
2158
2919
  i,
@@ -2180,7 +2941,7 @@ class Rn {
2180
2941
  }
2181
2942
  }
2182
2943
  }
2183
- const Vn = {
2944
+ const Ki = {
2184
2945
  play: "Play",
2185
2946
  pause: "Pause",
2186
2947
  prev: "Previous step",
@@ -2195,7 +2956,7 @@ const Vn = {
2195
2956
  scenario: "Scenario",
2196
2957
  fullscreen: "Full screen",
2197
2958
  exitFullscreen: "Exit full screen"
2198
- }, ye = "tinyfly-controls-style", Wn = `
2959
+ }, Ue = "tinyfly-controls-style", Ji = `
2199
2960
  .tf-ctl { --tf-ctl-fg: #1d1d1f; --tf-ctl-bg: #f4f2ee; --tf-ctl-accent: #c2410c; --tf-ctl-radius: 8px;
2200
2961
  font: 14px/1.4 var(--tf-ctl-font, system-ui, sans-serif); color: var(--tf-ctl-fg); margin-top: 8px; }
2201
2962
  .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,234 +3005,234 @@ const Vn = {
2244
3005
  .tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
2245
3006
  }
2246
3007
  `;
2247
- let Bn = 0;
2248
- function Un(t) {
2249
- if (t.getElementById(ye)) return;
3008
+ let Qi = 0;
3009
+ function tr(t) {
3010
+ if (t.getElementById(Ue)) return;
2250
3011
  const e = t.createElement("style");
2251
- e.id = ye, e.textContent = Wn, t.head.appendChild(e);
3012
+ e.id = Ue, e.textContent = Ji, t.head.appendChild(e);
2252
3013
  }
2253
- function Hn(t, e, n = {}) {
3014
+ function er(t, e, n = {}) {
2254
3015
  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");
3016
+ tr(i);
3017
+ const r = { ...Ki, ...n.labels }, s = n.speeds ?? [0.5, 1, 2], o = () => t.markers.length > 0, l = () => t.markers.some((E) => E.label !== void 0 || t.caption(E.id) !== void 0), c = i.createElement("div");
2257
3018
  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, "⟲", () => {
3019
+ const d = i.createElement("div");
3020
+ d.className = "tf-ctl-bar", d.setAttribute("role", "group");
3021
+ const u = (E, F, R, Q = "") => {
3022
+ const D = i.createElement("button");
3023
+ return D.type = "button", D.className = `tf-ctl-btn ${Q}`.trim(), D.setAttribute("aria-label", E), D.title = E, D.textContent = F, D.addEventListener("click", R), D;
3024
+ }, p = u(r.restart, "⟲", () => {
2264
3025
  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 = () => {
3026
+ }), h = u(r.prev, "|◀", () => t.prev()), y = u(r.play, "▶", () => t.isPlaying ? t.pause() : m(), "tf-ctl-primary"), f = u(r.next, "▶|", () => t.next()), m = () => {
2266
3027
  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);
3028
+ }, a = i.createElement("input");
3029
+ a.type = "range", a.className = "tf-ctl-scrub", a.min = "0", a.max = "1000", a.step = "1", a.setAttribute("aria-label", r.scrub), a.addEventListener("input", () => {
3030
+ t.pause(), t.seek(Number(a.value) / 1e3 * t.duration);
2270
3031
  });
2271
- const b = i.createElement("span");
2272
- b.className = "tf-ctl-step";
2273
- 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);
2290
- const T = n.mount;
2291
- 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);
3032
+ const g = i.createElement("span");
3033
+ g.className = "tf-ctl-step";
3034
+ const b = i.createElement("select");
3035
+ b.className = "tf-ctl-speed", b.setAttribute("aria-label", r.speed);
3036
+ for (const E of s) {
3037
+ const F = i.createElement("option");
3038
+ F.value = String(E), F.textContent = `${E}×`, E === 1 && (F.selected = !0), b.appendChild(F);
3039
+ }
3040
+ b.addEventListener("change", () => t.setSpeed(Number(b.value))), d.append(p, h, y, f, a, g), s.length > 0 && d.append(b), c.append(d);
3041
+ const x = n.fullscreen ? sr(e, i, r) : void 0;
3042
+ x && d.append(x.button);
3043
+ const w = i.createElement("p");
3044
+ w.className = "tf-ctl-caption", w.setAttribute("aria-live", "polite"), n.captions !== !1 && c.append(w);
3045
+ const v = i.createElement("div");
3046
+ v.className = "tf-ctl-question", v.hidden = !0;
3047
+ const k = i.createElement("span"), M = u(r.reveal, r.reveal, () => t.play(), "tf-ctl-primary");
3048
+ v.append(k, M), c.append(v);
3049
+ const $ = nr(t, i, r.scenario, n.scenarioControl ?? "buttons");
3050
+ $ && c.append($.element);
3051
+ const S = n.mount;
3052
+ S ? S.appendChild(c) : e.insertAdjacentElement("afterend", c);
3053
+ const A = () => {
3054
+ const E = t.isPlaying;
3055
+ y.textContent = E ? "❚❚" : "▶", y.setAttribute("aria-label", E ? r.pause : r.play), y.title = E ? r.pause : r.play;
3056
+ const F = t.duration;
3057
+ i.activeElement !== a && (a.value = String(F > 0 ? Math.round(t.currentTime / F * 1e3) : 0));
3058
+ const R = t.markers;
3059
+ if (h.hidden = f.hidden = g.hidden = R.length === 0, R.length > 0) {
3060
+ const Q = t.currentMarker, D = Q ? R.indexOf(Q) + 1 : 0;
3061
+ g.textContent = r.stepFormat.replace("{index}", String(D)).replace("{total}", String(R.length)), g.setAttribute("aria-label", `${r.step} ${D} ${r.of} ${R.length}`), h.disabled = t.currentTime <= 0.5, f.disabled = t.currentTime >= F - 0.5;
3062
+ const Oe = t.caption() ?? "";
3063
+ w.textContent !== Oe && (w.textContent = Oe), w.hidden = !l();
3064
+ const Pe = !E && Q?.question !== void 0 && Math.abs(t.currentTime - Q.time) < 1;
3065
+ v.hidden = !Pe, Pe && k.textContent !== Q.question && (k.textContent = Q.question);
2305
3066
  } 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) {
3067
+ v.hidden = !0, w.hidden = !0;
3068
+ $?.update();
3069
+ }, I = t.subscribe(A);
3070
+ A();
3071
+ const P = n.keyboardScope ?? e;
3072
+ !P.hasAttribute("tabindex") && P.tabIndex < 0 && (P.tabIndex = 0);
3073
+ const z = /* @__PURE__ */ new WeakSet(), j = (E) => {
3074
+ if (z.has(E) || (z.add(E), E.defaultPrevented || E.altKey || E.ctrlKey || E.metaKey)) return;
3075
+ const F = E.target;
3076
+ if (!(F.tagName === "INPUT" || F.tagName === "SELECT") && !(E.key === " " && F.tagName === "BUTTON"))
3077
+ switch (E.key) {
2317
3078
  case " ":
2318
- S.preventDefault(), t.isPlaying ? t.pause() : p();
3079
+ E.preventDefault(), t.isPlaying ? t.pause() : m();
2319
3080
  break;
2320
3081
  case "ArrowRight":
2321
3082
  if (!o()) return;
2322
- S.preventDefault(), t.next();
3083
+ E.preventDefault(), t.next();
2323
3084
  break;
2324
3085
  case "ArrowLeft":
2325
3086
  if (!o()) return;
2326
- S.preventDefault(), t.prev();
3087
+ E.preventDefault(), t.prev();
2327
3088
  break;
2328
3089
  case "Home":
2329
- S.preventDefault(), t.pause(), t.seek(0);
3090
+ E.preventDefault(), t.pause(), t.seek(0);
2330
3091
  break;
2331
3092
  case "f":
2332
3093
  case "F":
2333
- if (!$) return;
2334
- S.preventDefault(), $.active ? $.exit() : $.enter();
3094
+ if (!x) return;
3095
+ E.preventDefault(), x.active ? x.exit() : x.enter();
2335
3096
  break;
2336
3097
  }
2337
3098
  };
2338
- return j.addEventListener("keydown", kt), c.addEventListener("keydown", kt), {
3099
+ return P.addEventListener("keydown", j), c.addEventListener("keydown", j), {
2339
3100
  element: c,
2340
- fullscreen: $ && {
3101
+ fullscreen: x && {
2341
3102
  get active() {
2342
- return $.active;
3103
+ return x.active;
2343
3104
  },
2344
- enter: $.enter,
2345
- exit: $.exit
3105
+ enter: x.enter,
3106
+ exit: x.exit
2346
3107
  },
2347
3108
  destroy() {
2348
- $?.destroy(), K(), j.removeEventListener("keydown", kt), c.removeEventListener("keydown", kt), c.remove();
3109
+ x?.destroy(), I(), P.removeEventListener("keydown", j), c.removeEventListener("keydown", j), c.remove();
2349
3110
  }
2350
3111
  };
2351
3112
  }
2352
- function Xn(t, e, n, i) {
3113
+ function nr(t, e, n, i) {
2353
3114
  const r = t.scenarios;
2354
3115
  if (r.length < 2) return;
2355
3116
  if (i === "slider") {
2356
3117
  const u = e.createElement("div");
2357
3118
  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);
3119
+ const p = e.createElement("span");
3120
+ p.textContent = n, p.setAttribute("aria-hidden", "true");
3121
+ const h = e.createElement("input");
3122
+ h.type = "range", h.min = "0", h.max = String(r.length - 1), h.step = "1", h.setAttribute("aria-label", n);
2362
3123
  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);
3124
+ return y.setAttribute("aria-hidden", "true"), h.addEventListener("input", () => {
3125
+ const m = r[Number(h.value)];
3126
+ m && t.setScenario(m.id);
3127
+ }), u.append(p, h, y), { element: u, update: () => {
3128
+ const m = Math.max(0, r.findIndex((g) => g.id === t.scenario));
3129
+ e.activeElement !== h && (h.value = String(m));
3130
+ const a = r[m].label;
3131
+ y.textContent !== a && (y.textContent = a), h.setAttribute("aria-valuetext", a);
2371
3132
  } };
2372
3133
  }
2373
3134
  const s = e.createElement("fieldset");
2374
3135
  s.className = "tf-ctl-choices";
2375
3136
  const o = e.createElement("legend");
2376
3137
  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);
3138
+ const l = `tf-ctl-scenario-${++Qi}`, c = r.map((u) => {
3139
+ const p = e.createElement("label");
3140
+ p.className = "tf-ctl-choice";
3141
+ const h = e.createElement("input");
3142
+ h.type = "radio", h.name = l, h.value = u.id, h.addEventListener("change", () => {
3143
+ h.checked && t.setScenario(u.id);
2383
3144
  });
2384
3145
  const y = e.createElement("span");
2385
- return y.textContent = u.label, h.append(d, y), s.append(h), d;
3146
+ return y.textContent = u.label, p.append(h, y), s.append(p), h;
2386
3147
  });
2387
3148
  return { element: s, update: () => {
2388
3149
  for (const u of c) {
2389
- const h = u.value === t.scenario;
2390
- u.checked !== h && (u.checked = h);
3150
+ const p = u.value === t.scenario;
3151
+ u.checked !== p && (u.checked = p);
2391
3152
  }
2392
3153
  } };
2393
3154
  }
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) {
3155
+ const ir = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>', rr = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';
3156
+ function sr(t, e, n) {
2396
3157
  const i = e, r = t, s = e.createElement("button");
2397
3158
  s.type = "button", s.className = "tf-ctl-btn tf-ctl-fullscreen";
2398
3159
  let o, l = "";
2399
3160
  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();
3161
+ const m = o !== void 0;
3162
+ s.innerHTML = m ? rr : ir;
3163
+ const a = m ? n.exitFullscreen : n.fullscreen;
3164
+ s.setAttribute("aria-label", a), s.title = a, s.setAttribute("aria-pressed", String(m)), t.classList.toggle("tf-fullscreen", m), t.classList.toggle("tf-fullscreen-overlay", o === "overlay");
3165
+ }, d = () => i.fullscreenElement ?? i.webkitFullscreenElement ?? null, u = () => {
3166
+ d() === t ? o = "native" : o === "native" && (o = void 0), c();
3167
+ }, p = (m) => {
3168
+ m.key === "Escape" && f();
3169
+ }, h = () => {
3170
+ o = "overlay", l = e.documentElement.style.overflow, e.documentElement.style.overflow = "hidden", e.addEventListener("keydown", p), c();
2410
3171
  };
2411
3172
  async function y() {
2412
3173
  if (o) return;
2413
- const p = r.requestFullscreen?.bind(r) ?? r.webkitRequestFullscreen?.bind(r), m = i.fullscreenEnabled ?? i.webkitFullscreenEnabled ?? !1;
2414
- if (p && m)
3174
+ const m = r.requestFullscreen?.bind(r) ?? r.webkitRequestFullscreen?.bind(r), a = i.fullscreenEnabled ?? i.webkitFullscreenEnabled ?? !1;
3175
+ if (m && a)
2415
3176
  try {
2416
- if (await p(), f() === t) {
3177
+ if (await m(), d() === t) {
2417
3178
  o = "native", c();
2418
3179
  return;
2419
3180
  }
2420
3181
  } catch {
2421
3182
  }
2422
- d();
3183
+ h();
2423
3184
  }
2424
- async function a() {
3185
+ async function f() {
2425
3186
  if (o === "overlay")
2426
- e.removeEventListener("keydown", h), e.documentElement.style.overflow = l, o = void 0, c();
3187
+ e.removeEventListener("keydown", p), e.documentElement.style.overflow = l, o = void 0, c();
2427
3188
  else if (o === "native") {
2428
3189
  o = void 0, c();
2429
- const p = i.exitFullscreen?.bind(i) ?? i.webkitExitFullscreen?.bind(i);
2430
- f() === t && p && await p();
3190
+ const m = i.exitFullscreen?.bind(i) ?? i.webkitExitFullscreen?.bind(i);
3191
+ d() === t && m && await m();
2431
3192
  }
2432
3193
  }
2433
3194
  return s.addEventListener("click", () => {
2434
- o ? a() : y();
3195
+ o ? f() : y();
2435
3196
  }), e.addEventListener("fullscreenchange", u), e.addEventListener("webkitfullscreenchange", u), c(), {
2436
3197
  button: s,
2437
3198
  get active() {
2438
3199
  return o !== void 0;
2439
3200
  },
2440
3201
  enter: y,
2441
- exit: a,
3202
+ exit: f,
2442
3203
  destroy() {
2443
- a(), e.removeEventListener("fullscreenchange", u), e.removeEventListener("webkitfullscreenchange", u), s.remove();
3204
+ f(), e.removeEventListener("fullscreenchange", u), e.removeEventListener("webkitfullscreenchange", u), s.remove();
2444
3205
  }
2445
3206
  };
2446
3207
  }
2447
- const ge = "tinyfly-choices-style", Kn = `
3208
+ const Ge = "tinyfly-choices-style", or = `
2448
3209
  [data-tinyfly-choose] { cursor: pointer; }
2449
3210
  [data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
2450
3211
  `;
2451
- function Qn(t) {
2452
- if (t.getElementById(ge)) return;
3212
+ function ar(t) {
3213
+ if (t.getElementById(Ge)) return;
2453
3214
  const e = t.createElement("style");
2454
- e.id = ge, e.textContent = Kn, t.head.appendChild(e);
3215
+ e.id = Ge, e.textContent = or, t.head.appendChild(e);
2455
3216
  }
2456
- function Jn(t, e) {
3217
+ function lr(t, e) {
2457
3218
  const n = Array.from(e.querySelectorAll("[data-tinyfly-choose]"));
2458
3219
  if (n.length === 0) return () => {
2459
3220
  };
2460
- Qn(e.ownerDocument);
3221
+ ar(e.ownerDocument);
2461
3222
  const i = [], r = [];
2462
3223
  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));
3224
+ const c = l.getAttribute("data-tinyfly-choose") ?? "", d = [], u = (f, m) => {
3225
+ l.hasAttribute(f) || (l.setAttribute(f, m), d.push(f));
2465
3226
  };
2466
3227
  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());
3228
+ const p = t.scenarios.find((f) => f.id === c)?.label;
3229
+ p !== void 0 && u("aria-label", p), l.setAttribute("aria-pressed", "false"), d.push("aria-pressed"), i.push({ element: l, attributes: d });
3230
+ const h = () => t.setScenario(c), y = (f) => {
3231
+ const m = f.key;
3232
+ m !== "Enter" && m !== " " || (f.preventDefault(), h());
2472
3233
  };
2473
- l.addEventListener("click", d), l.addEventListener("keydown", y), r.push(() => {
2474
- l.removeEventListener("click", d), l.removeEventListener("keydown", y);
3234
+ l.addEventListener("click", h), l.addEventListener("keydown", y), r.push(() => {
3235
+ l.removeEventListener("click", h), l.removeEventListener("keydown", y);
2475
3236
  });
2476
3237
  }
2477
3238
  const s = () => {
@@ -2481,12 +3242,12 @@ function Jn(t, e) {
2481
3242
  return s(), () => {
2482
3243
  o();
2483
3244
  for (const l of r) l();
2484
- for (const { element: l, attributes: c } of i) for (const f of c) l.removeAttribute(f);
3245
+ for (const { element: l, attributes: c } of i) for (const d of c) l.removeAttribute(d);
2485
3246
  };
2486
3247
  }
2487
- const be = /* @__PURE__ */ new WeakMap(), ti = /* @__PURE__ */ new WeakMap();
2488
- let ei = 0;
2489
- function ht(t, e, n) {
3248
+ const Xe = /* @__PURE__ */ new WeakMap(), cr = /* @__PURE__ */ new WeakMap();
3249
+ let ur = 0;
3250
+ function Mt(t, e, n) {
2490
3251
  if (t)
2491
3252
  try {
2492
3253
  return JSON.parse(t);
@@ -2495,222 +3256,222 @@ function ht(t, e, n) {
2495
3256
  return;
2496
3257
  }
2497
3258
  }
2498
- async function ni(t, e = {}) {
2499
- const n = be.get(t);
3259
+ async function dr(t, e = {}) {
3260
+ const n = Xe.get(t);
2500
3261
  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;
3262
+ const i = Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")), r = i[0], s = t.getAttribute("data-src"), o = pr(t.getAttribute("data-markers")), l = i.length > 1 || r?.hasAttribute("data-scenario") ? hr(i, o, t) : void 0;
2502
3263
  if (l && l.length === 0) return;
2503
- let c = r && !l ? ht(r.textContent, "timeline", t) : void 0;
3264
+ let c = r && !l ? Mt(r.textContent, "timeline", t) : void 0;
2504
3265
  if (!c && s && o) {
2505
3266
  const y = await fetch(s);
2506
3267
  y.ok && (c = await y.json());
2507
3268
  }
2508
- if (c && o && (c = ze(c, o)), !c && !s && !l) {
3269
+ if (c && o && (c = An(c, o)), !c && !s && !l) {
2509
3270
  console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)', t);
2510
3271
  return;
2511
3272
  }
2512
- const f = ht(t.querySelector("script[data-tinyfly-captions]")?.textContent, "captions", t), u = {
3273
+ const d = Mt(t.querySelector("script[data-tinyfly-captions]")?.textContent, "captions", t), u = {
2513
3274
  playWhenVisible: !0,
2514
3275
  ...e.player,
2515
- ...f && { captions: f },
2516
- ...ht(t.getAttribute("data-options"), "data-options", t)
3276
+ ...d && { captions: d },
3277
+ ...Mt(t.getAttribute("data-options"), "data-options", t)
2517
3278
  };
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) {
3279
+ fr(t);
3280
+ const p = new Zi(t, u), h = { element: t, player: p };
3281
+ if (Xe.set(t, h), t.setAttribute("data-tinyfly-mounted", ""), l) {
2521
3282
  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));
3283
+ await p.loadScenarios(l, { initial: l.some((f) => f.id === y) ? y : void 0 }), cr.set(t, lr(p, t));
2523
3284
  } else
2524
- await h.load(c ?? s);
3285
+ await p.load(c ?? s);
2525
3286
  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, {
3287
+ const y = Mt(t.getAttribute("data-labels"), "data-labels", t), f = t.querySelector("figcaption"), m = t.getAttribute("data-scenario-legend"), a = t.getAttribute("data-scenario-control");
3288
+ h.controls = er(p, t, {
2528
3289
  ...e.controls,
2529
3290
  ...t.getAttribute("data-fullscreen") === "true" ? { fullscreen: !0 } : {},
2530
- ...m === "slider" || m === "buttons" ? { scenarioControl: m } : {},
2531
- labels: { ...e.controls?.labels, ...y, ...p ? { scenario: p } : {} },
3291
+ ...a === "slider" || a === "buttons" ? { scenarioControl: a } : {},
3292
+ labels: { ...e.controls?.labels, ...y, ...m ? { scenario: m } : {} },
2532
3293
  // Inside the figure, before its figcaption, so the caption stays last.
2533
3294
  mount: void 0
2534
- }), a ? t.insertBefore(d.controls.element, a) : t.appendChild(d.controls.element);
3295
+ }), f ? t.insertBefore(h.controls.element, f) : t.appendChild(h.controls.element);
2535
3296
  }
2536
- return d;
3297
+ return h;
2537
3298
  }
2538
- function ii(t, e, n) {
3299
+ function hr(t, e, n) {
2539
3300
  const i = [];
2540
3301
  return t.forEach((r, s) => {
2541
- const o = ht(r.textContent, "timeline", n);
3302
+ const o = Mt(r.textContent, "timeline", n);
2542
3303
  if (!o) return;
2543
3304
  const l = r.getAttribute("data-scenario") || `scenario-${s + 1}`;
2544
- if (i.some((f) => f.id === l)) {
3305
+ if (i.some((d) => d.id === l)) {
2545
3306
  console.warn(`tinyfly: scenario id "${l}" is used more than once; the later one is skipped`, n);
2546
3307
  return;
2547
3308
  }
2548
3309
  const c = r.getAttribute("data-scenario-label") ?? void 0;
2549
- i.push({ id: l, label: c, timeline: e ? ze(o, e) : o });
3310
+ i.push({ id: l, label: c, timeline: e ? An(o, e) : o });
2550
3311
  }), i;
2551
3312
  }
2552
- function ze(t, e) {
3313
+ function An(t, e) {
2553
3314
  return t.config.markers?.length ? t : { ...t, config: { ...t.config, markers: e.map((n, i) => ({ id: `step-${i + 1}`, time: n })) } };
2554
3315
  }
2555
- function ri(t) {
3316
+ function pr(t) {
2556
3317
  if (!t) return;
2557
3318
  const e = t.split(/[\s,]+/).filter(Boolean).map(Number).filter((n) => Number.isFinite(n) && n >= 0).sort((n, i) => n - i);
2558
3319
  return e.length > 0 ? e : void 0;
2559
3320
  }
2560
- function si(t) {
3321
+ function fr(t) {
2561
3322
  const e = t.querySelector("svg");
2562
3323
  if (!e || e.hasAttribute("role") || e.hasAttribute("aria-hidden")) return;
2563
3324
  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));
3325
+ e.setAttribute("role", "img"), n ? e.setAttribute("aria-label", n) : i && (i.id ||= `tinyfly-caption-${++ur}`, e.setAttribute("aria-labelledby", i.id));
2565
3326
  }
2566
- const oi = "http://www.w3.org/2000/svg", Pt = /* @__PURE__ */ new WeakMap();
2567
- function ai(t, e) {
3327
+ const yr = "http://www.w3.org/2000/svg", ae = /* @__PURE__ */ new WeakMap();
3328
+ function mr(t, e) {
2568
3329
  const n = t?.values.get(e);
2569
3330
  return n ? Object.fromEntries(n) : {};
2570
3331
  }
2571
- async function li(t, e = {}) {
2572
- const n = Pt.get(t);
3332
+ async function gr(t, e = {}) {
3333
+ const n = ae.get(t);
2573
3334
  if (n) return n;
2574
3335
  const i = t.querySelector("script[data-tinyfly-figure]");
2575
3336
  let r;
2576
3337
  try {
2577
- r = bt(JSON.parse(i?.textContent ?? "null"));
2578
- } catch (d) {
2579
- console.warn("tinyfly: math figure is missing or invalid", t, d);
3338
+ r = Nt(JSON.parse(i?.textContent ?? "null"));
3339
+ } catch (h) {
3340
+ console.warn("tinyfly: math figure is missing or invalid", t, h);
2580
3341
  return;
2581
3342
  }
2582
3343
  const s = t.getAttribute("data-target") ?? "fig";
2583
3344
  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));
3345
+ o || (o = t.ownerDocument.createElementNS(yr, "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")));
3346
+ const l = (h) => {
3347
+ o.innerHTML = Ae(ee(r, h));
2587
3348
  };
2588
3349
  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;
3350
+ const h = { element: t, figure: r, redraw: () => l({}) };
3351
+ return ae.set(t, h), h;
2591
3352
  }
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;
3353
+ const d = await dr(t, e);
3354
+ if (!d) return;
3355
+ const u = () => l(mr(d.player.state, s));
3356
+ d.player.subscribe(u), u();
3357
+ const p = { ...d, figure: r, redraw: u };
3358
+ return ae.set(t, p), p;
2598
3359
  }
2599
- async function yi(t = document, e = {}) {
3360
+ async function Sr(t = document, e = {}) {
2600
3361
  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);
3362
+ return (await Promise.all(n.map((r) => gr(r, e)))).filter((r) => r !== void 0);
2602
3363
  }
2603
- const ci = "http://www.w3.org/2000/svg";
2604
- function gi(t, e, n = {}) {
2605
- bt(e);
3364
+ const br = "http://www.w3.org/2000/svg";
3365
+ function Ar(t, e, n = {}) {
3366
+ Nt(e);
2606
3367
  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`);
3368
+ for (const w of n.sliders ?? [])
3369
+ if (typeof i[w.value] != "number") throw new Error(`mathExplorable: slider value "${w.value}" is not a number value of the figure`);
3370
+ for (const w of n.drag ?? []) {
3371
+ if ("vector" in w && !at(i[w.vector])) throw new Error(`mathExplorable: "${w.vector}" is not a vector value of the figure`);
3372
+ if ("matrix" in w && !gt(i[w.matrix])) throw new Error(`mathExplorable: "${w.matrix}" is not a matrix value of the figure`);
2612
3373
  }
2613
- const r = Te(e), s = t.ownerDocument, o = s.createElementNS(ci, "svg");
3374
+ const r = wn(e), s = t.ownerDocument, o = s.createElementNS(br, "svg");
2614
3375
  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"/>`;
3376
+ const l = n.drag ?? [], c = (w) => {
3377
+ if ("vector" in w) return i[w.vector];
3378
+ const [v, k, M, $] = i[w.matrix];
3379
+ return w.column === 0 ? [v, M] : [k, $];
3380
+ }, d = () => {
3381
+ const w = l.map((v) => {
3382
+ const [k, M] = r.toScreen(c(v));
3383
+ return `<circle cx="${k}" cy="${M}" 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"/>`;
2623
3384
  });
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();
3385
+ o.innerHTML = Ae(ee(e, i)) + w.join(""), n.onChange?.({ ...i });
3386
+ }, u = (w, v) => {
3387
+ if (!(w in i)) throw new Error(`mathExplorable: no value "${w}"`);
3388
+ i[w] = v;
3389
+ const k = p.get(w);
3390
+ k && typeof v == "number" && (k.value = String(v), h.get(w).textContent = String(v)), d();
3391
+ }, p = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
2631
3392
  let y;
2632
3393
  if (n.sliders?.length) {
2633
3394
  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);
3395
+ for (const w of n.sliders) {
3396
+ const v = s.createElement("label");
3397
+ v.setAttribute("style", "display:flex;align-items:center;gap:6px");
3398
+ const k = s.createElement("input");
3399
+ k.type = "range", k.min = String(w.min), k.max = String(w.max), k.step = String(w.step ?? (w.max - w.min) / 100), k.value = String(i[w.value]), k.setAttribute("aria-label", w.label ?? w.value);
3400
+ const M = s.createElement("output");
3401
+ M.textContent = String(i[w.value]), k.addEventListener("input", () => u(w.value, Number(k.value))), v.append(w.label ?? w.value, k, M), y.appendChild(v), p.set(w.value, k), h.set(w.value, M);
2641
3402
  }
2642
3403
  t.appendChild(y);
2643
3404
  }
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))];
3405
+ const f = n.snap ?? 0.1, m = (w) => {
3406
+ const v = o.getBoundingClientRect(), k = (w.clientX - v.left) / (v.width || e.width) * e.width, M = (w.clientY - v.top) / (v.height || e.height) * e.height, [$, S] = r.toWorld([k, M]), A = (I) => f > 0 ? Math.round(I / f) * f : I;
3407
+ return [Number(A($).toFixed(6)), Number(A(S).toFixed(6))];
2647
3408
  };
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;
2652
- 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]);
3409
+ let a;
3410
+ const g = (w) => {
3411
+ const v = o.getBoundingClientRect(), k = e.width / (v.width || e.width), M = [(w.clientX - v.left) * k, (w.clientY - v.top) * k];
3412
+ let $;
3413
+ for (const S of l) {
3414
+ const [A, I] = r.toScreen(c(S)), P = Math.hypot(A - M[0], I - M[1]);
3415
+ P < 30 * r.scale * Math.max(1, k) && (!$ || P < $.distance) && ($ = { handle: S, distance: P });
3416
+ }
3417
+ $ && (a = $.handle, o.setPointerCapture?.(w.pointerId), w.preventDefault());
3418
+ }, b = (w) => {
3419
+ if (!a) return;
3420
+ const [v, k] = m(w);
3421
+ if ("vector" in a)
3422
+ u(a.vector, [v, k]);
2662
3423
  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]);
3424
+ const [M, $, S, A] = i[a.matrix];
3425
+ u(a.matrix, a.column === 0 ? [v, $, k, A] : [M, v, S, k]);
2665
3426
  }
2666
- }, $ = () => {
2667
- m = void 0;
3427
+ }, x = () => {
3428
+ a = void 0;
2668
3429
  };
2669
- return o.addEventListener("pointerdown", b), o.addEventListener("pointermove", w), o.addEventListener("pointerup", $), o.addEventListener("pointercancel", $), f(), {
3430
+ return o.addEventListener("pointerdown", g), o.addEventListener("pointermove", b), o.addEventListener("pointerup", x), o.addEventListener("pointercancel", x), d(), {
2670
3431
  get values() {
2671
3432
  return { ...i };
2672
3433
  },
2673
3434
  set: u,
2674
3435
  destroy() {
2675
- o.removeEventListener("pointerdown", b), o.removeEventListener("pointermove", w), o.removeEventListener("pointerup", $), o.removeEventListener("pointercancel", $), y?.remove();
3436
+ o.removeEventListener("pointerdown", g), o.removeEventListener("pointermove", b), o.removeEventListener("pointerup", x), o.removeEventListener("pointercancel", x), y?.remove();
2676
3437
  }
2677
3438
  };
2678
3439
  }
2679
- const wt = (t, e, n) => ({
3440
+ const Lt = (t, e, n) => ({
2680
3441
  width: t.width ?? 600,
2681
3442
  height: t.height ?? 600,
2682
3443
  ...t.theme ? { theme: t.theme } : {},
2683
3444
  ...t.x ? { x: t.x } : {},
2684
3445
  values: e,
2685
3446
  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 }, [
3447
+ }), Ee = "\\begin{bmatrix} \\val{M.a} & \\val{M.b} \\\\ \\val{M.c} & \\val{M.d} \\end{bmatrix}", Te = (t) => [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.1];
3448
+ function Er(t = {}) {
3449
+ return Lt(t, { M: t.matrix ?? Tt }, [
2689
3450
  { id: "grid", kind: "grid", transform: "M", ghost: !0 },
2690
3451
  { id: "square", kind: "polygon", transform: "M", color: "yellow", fillOpacity: 0.25 },
2691
3452
  { id: "basis", kind: "basis", transform: "M" },
2692
- { id: "matrix", kind: "label", tex: Qt, at: Jt(t), screen: !0, align: "left" }
3453
+ { id: "matrix", kind: "label", tex: Ee, at: Te(t), screen: !0, align: "left" }
2693
3454
  ]);
2694
3455
  }
2695
- function vi(t = {}) {
2696
- return wt(t, { M: t.matrix ?? yt }, [
3456
+ function Tr(t = {}) {
3457
+ return Lt(t, { M: t.matrix ?? Tt }, [
2697
3458
  { id: "grid", kind: "grid", transform: "M", ghost: !0 },
2698
3459
  { id: "square", kind: "polygon", transform: "M", color: "yellow", fillOpacity: 0.35, label: "\\det = \\val{M.det}" },
2699
3460
  { id: "basis", kind: "basis", transform: "M" },
2700
- { id: "matrix", kind: "label", tex: Qt, at: Jt(t), screen: !0, align: "left" }
3461
+ { id: "matrix", kind: "label", tex: Ee, at: Te(t), screen: !0, align: "left" }
2701
3462
  ]);
2702
3463
  }
2703
- function wi(t) {
2704
- return wt(t, { M: yt, A: t.matrix }, [
3464
+ function Or(t) {
3465
+ return Lt(t, { M: Tt, A: t.matrix }, [
2705
3466
  { id: "grid", kind: "grid", transform: "M", ghost: !0 },
2706
3467
  { id: "eigen", kind: "line", eigen: "A", color: "yellow", width: 3 },
2707
3468
  { id: "basis", kind: "basis", transform: "M" },
2708
- { id: "matrix", kind: "label", tex: Qt, at: Jt(t), screen: !0, align: "left" }
3469
+ { id: "matrix", kind: "label", tex: Ee, at: Te(t), screen: !0, align: "left" }
2709
3470
  ]);
2710
3471
  }
2711
- function ki(t) {
3472
+ function Pr(t) {
2712
3473
  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 }, [
3474
+ return Lt(t, { u: t.u, v: t.v, s: e }, [
2714
3475
  { id: "grid", kind: "grid", ghost: !1, color: "grey", opacity: 0.5 },
2715
3476
  { id: "axes", kind: "axes" },
2716
3477
  { id: "arrowU", kind: "vector", to: "u", color: "green", label: "\\vec{u}", labelAt: "middle" },
@@ -2718,15 +3479,15 @@ function ki(t) {
2718
3479
  { id: "sum", kind: "vector", to: "s", color: "yellow", label: "\\vec{u} + \\vec{v}" }
2719
3480
  ]);
2720
3481
  }
2721
- function $i(t) {
3482
+ function Ir(t) {
2722
3483
  const e = [
2723
3484
  { id: "axes", kind: "axes" },
2724
3485
  { id: "spanU", kind: "line", along: "u", color: "green", dashed: !0 },
2725
3486
  { id: "arrowU", kind: "vector", to: "u", color: "green", label: "\\vec{u}" }
2726
3487
  ], 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);
3488
+ 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}" })), Lt(t, n, e);
2728
3489
  }
2729
- const dt = (t, e, n) => ({
3490
+ const wt = (t, e, n) => ({
2730
3491
  width: t.width ?? 600,
2731
3492
  height: t.height ?? 600,
2732
3493
  ...t.theme ? { theme: t.theme } : {},
@@ -2735,18 +3496,18 @@ const dt = (t, e, n) => ({
2735
3496
  values: e,
2736
3497
  items: [{ id: "axes", kind: "axes" }, { id: "f", kind: "function", expr: t.expr, color: "blue" }, ...n]
2737
3498
  });
2738
- function xi(t) {
2739
- return dt(t, { a: t.at ?? 1 }, [
3499
+ function Nr(t) {
3500
+ return wt(t, { a: t.at ?? 1 }, [
2740
3501
  { id: "tangent", kind: "tangent", expr: t.expr, at: "a", color: "yellow", label: "\\text{slope} = \\val{tangent.slope}" }
2741
3502
  ]);
2742
3503
  }
2743
- function Mi(t) {
2744
- return dt(t, { a: t.at ?? 1, h: t.h ?? 2 }, [
3504
+ function Lr(t) {
3505
+ return wt(t, { a: t.at ?? 1, h: t.h ?? 2 }, [
2745
3506
  { id: "secant", kind: "tangent", expr: t.expr, at: "a", h: "h", color: "yellow", label: "\\frac{\\Delta y}{\\Delta x} = \\val{secant.slope}" }
2746
3507
  ]);
2747
3508
  }
2748
- function Si(t) {
2749
- const e = dt(t, { n: t.n ?? 4 }, [
3509
+ function Fr(t) {
3510
+ const e = wt(t, { n: t.n ?? 4 }, [
2750
3511
  { id: "sum", kind: "riemann", expr: t.expr, from: t.from, to: t.to, n: "n", rule: t.rule ?? "left", color: "teal" }
2751
3512
  ]);
2752
3513
  return e.items.push(e.items.splice(1, 1)[0]), e.items.push({
@@ -2759,8 +3520,8 @@ function Si(t) {
2759
3520
  tex: "n = \\val{sum.n:0} \\quad \\text{sum} = \\val{sum.sum:3} \\quad \\int = \\val{sum.exact:3}"
2760
3521
  }), e;
2761
3522
  }
2762
- function Ei(t) {
2763
- const e = dt(t, { b: t.to }, [
3523
+ function Cr(t) {
3524
+ const e = wt(t, { b: t.to }, [
2764
3525
  { id: "area", kind: "area", expr: t.expr, from: t.from, to: "b", color: "teal" }
2765
3526
  ]);
2766
3527
  return e.items.push(e.items.splice(1, 1)[0]), e.items.push({
@@ -2773,8 +3534,8 @@ function Ei(t) {
2773
3534
  tex: `\\int_{${t.from}}^{\\val{b:2}} f(x)\\,dx = \\val{area.value:3}`
2774
3535
  }), e;
2775
3536
  }
2776
- function Ai(t) {
2777
- const e = dt(t, { order: t.order ?? 1 }, [
3537
+ function qr(t) {
3538
+ const e = wt(t, { order: t.order ?? 1 }, [
2778
3539
  { id: "taylor", kind: "taylor", expr: t.expr, at: t.at ?? 0, order: "order", color: "yellow" },
2779
3540
  { id: "centre", kind: "point", on: t.expr, x: t.at ?? 0, color: "yellow" }
2780
3541
  ]);
@@ -2788,8 +3549,8 @@ function Ai(t) {
2788
3549
  tex: "\\text{degree } \\val{taylor.degree:0}"
2789
3550
  }), e;
2790
3551
  }
2791
- function Ti(t) {
2792
- const e = dt(t, { p: t.from ?? t.at - 2 }, [
3552
+ function zr(t) {
3553
+ const e = wt(t, { p: t.from ?? t.at - 2 }, [
2793
3554
  { id: "hole", kind: "point", at: [t.at, t.limit], hollow: !0, color: "blue", radius: 7 },
2794
3555
  { id: "moving", kind: "point", on: t.expr, x: "p", color: "yellow" }
2795
3556
  ]);
@@ -2803,62 +3564,251 @@ function Ti(t) {
2803
3564
  tex: "f(\\val{moving.x:3}) = \\val{moving.y:4}"
2804
3565
  }), e;
2805
3566
  }
2806
- function Oi(t) {
2807
- return bt(t);
3567
+ const ft = (t, e, n, i) => ({
3568
+ width: t.width ?? 600,
3569
+ height: t.height ?? 600,
3570
+ ...t.theme ? { theme: t.theme } : {},
3571
+ x: t.x ?? e.x,
3572
+ y: t.y ?? e.y,
3573
+ values: n,
3574
+ items: i
3575
+ }), kt = (t, e) => ({
3576
+ id: "readout",
3577
+ kind: "label",
3578
+ screen: !0,
3579
+ align: "left",
3580
+ size: 24,
3581
+ at: [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.08],
3582
+ tex: e
3583
+ });
3584
+ function jr(t = {}) {
3585
+ const [e, n] = t.shade ?? [-1, 1];
3586
+ return ft(t, { x: [-4, 4], y: [-0.08, 0.55] }, { mu: t.mean ?? 0, sigma: t.sd ?? 1, a: e, b: n }, [
3587
+ { id: "axes", kind: "axes", ticks: 1, labels: !0 },
3588
+ { id: "dist", kind: "distribution", distribution: { kind: "normal", mean: "mu", sd: "sigma" }, shade: ["a", "b"] },
3589
+ kt(t, "P(\\val{a:2} \\le X \\le \\val{b:2}) = \\val{dist.p:3}")
3590
+ ]);
3591
+ }
3592
+ function Dr(t = {}) {
3593
+ const e = t.n ?? 10;
3594
+ return ft(t, { x: [-1, e + 1], y: [-0.04, 0.4] }, { n: e, p: t.p ?? 0.5 }, [
3595
+ { id: "axes", kind: "axes", ticks: Math.max(1, Math.round(e / 10)) },
3596
+ { id: "dist", kind: "distribution", distribution: { kind: "binomial", n: "n", p: "p" } },
3597
+ kt(t, "n = \\val{n:0} \\quad p = \\val{p:2} \\quad \\mu = \\val{dist.mean:2}")
3598
+ ]);
3599
+ }
3600
+ function _r(t = {}) {
3601
+ return ft(t, { x: [-0.2, 3.2], y: [-0.2, 3] }, { k: t.k ?? 1, samples: t.samples ?? 2e3 }, [
3602
+ { id: "axes", kind: "axes", ticks: 1 },
3603
+ { 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" },
3604
+ kt(t, "k = \\val{k:0} \\text{ draws averaged} \\quad \\bar{x} = \\val{hist.mean:3} \\quad s = \\val{hist.sd:3}")
3605
+ ]);
3606
+ }
3607
+ function Rr(t = {}) {
3608
+ const e = t.rows ?? 10;
3609
+ return ft(t, { x: [-(e + 2) * 0.25, (e + 2) * 0.25], y: [-12, 1] }, { balls: t.balls ?? 0 }, [
3610
+ { id: "board", kind: "galton", rows: e, balls: "balls", spacing: 0.5, top: 0 },
3611
+ kt(t, "\\val{board.landed:0} \\text{ balls}")
3612
+ ]);
3613
+ }
3614
+ function Br(t = {}) {
3615
+ return ft(t, { x: [-1.3, 1.3], y: [-1.3, 1.3] }, { count: t.count ?? 0 }, [
3616
+ { id: "square", kind: "polygon", points: [[-1, -1], [1, -1], [1, 1], [-1, 1]], color: "grey", fillOpacity: 0 },
3617
+ { id: "circle", kind: "parametric", x: "cos(t)", y: "sin(t)", color: "yellow", width: 2.5 },
3618
+ { 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 },
3619
+ kt(t, "\\frac{\\text{inside}}{\\text{all}} = \\frac{\\val{pts.inside:0}}{\\val{pts.count:0}} = \\val{pts.ratio:4} \\approx \\frac{\\pi}{4}")
3620
+ ]);
3621
+ }
3622
+ function Vr(t = {}) {
3623
+ return ft(t, { x: [-1, 11], y: [-2, 10] }, { slope: t.slope ?? 0.6, intercept: t.intercept ?? 1, noise: t.noise ?? 1, count: t.count ?? 60 }, [
3624
+ { id: "axes", kind: "axes", ticks: 2 },
3625
+ { id: "pts", kind: "scatter", points: { kind: "linear", slope: "slope", intercept: "intercept", noise: "noise", x: [0, 10] }, count: "count", fit: !0, radius: 3.5 },
3626
+ kt(t, "y = \\val{pts.slope:2}\\,x + \\val{pts.intercept:2} \\quad r = \\val{pts.r:2}")
3627
+ ]);
3628
+ }
3629
+ function Hr(t = {}) {
3630
+ return ft(t, { x: [0, 1], y: [0, 1] }, { prior: t.prior ?? 0.1, sensitivity: t.sensitivity ?? 0.9, falsePositive: t.falsePositive ?? 0.1 }, [
3631
+ { id: "test", kind: "bayes", prior: "prior", truePositive: "sensitivity", falsePositive: "falsePositive", at: [0.08, 0.2], size: [0.84, 0.66] }
3632
+ ]);
3633
+ }
3634
+ const ht = (t) => ({ width: t.width ?? 600, height: t.height ?? 600, ...t.theme ? { theme: t.theme } : {} }), Ft = (t, e) => ({
3635
+ id: "readout",
3636
+ kind: "label",
3637
+ screen: !0,
3638
+ align: "left",
3639
+ size: 22,
3640
+ at: [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.07],
3641
+ tex: e
3642
+ }), Zt = {
3643
+ nodes: [
3644
+ { id: "A", at: [-3, 1.5] },
3645
+ { id: "B", at: [-1, 2.5] },
3646
+ { id: "C", at: [-1, 0.5] },
3647
+ { id: "D", at: [1, 2.5] },
3648
+ { id: "E", at: [1, 0.5] },
3649
+ { id: "F", at: [-1, -1.5] },
3650
+ { id: "G", at: [3, 1.5] },
3651
+ { id: "H", at: [1.5, -1.5] }
3652
+ ],
3653
+ edges: [["A", "B", 4], ["A", "C", 2], ["B", "D", 5], ["C", "B", 1], ["C", "E", 8], ["C", "F", 3], ["D", "G", 3], ["E", "G", 2], ["E", "D", 2], ["F", "H", 6], ["H", "E", 1]]
3654
+ };
3655
+ function Wr(t = {}) {
3656
+ const { width: e, height: n } = ht(t);
3657
+ return {
3658
+ ...ht(t),
3659
+ x: [-4.2, 4.2],
3660
+ y: [-3.6, 3.6],
3661
+ values: { step: 0 },
3662
+ items: [
3663
+ { id: "g", kind: "graph", nodes: t.nodes ?? Zt.nodes, edges: t.edges ?? Zt.edges.map(([i, r]) => [i, r]), search: { kind: t.search ?? "bfs", start: t.start ?? "A" }, step: "step", frontier: [e * 0.06, n * 0.92] },
3664
+ Ft(t, "\\text{visited } \\val{g.visited:0} \\text{ of } \\val{g.steps:0}")
3665
+ ]
3666
+ };
3667
+ }
3668
+ function Ur(t = {}) {
3669
+ const { width: e, height: n } = ht(t), i = t.target ?? "G";
3670
+ return {
3671
+ ...ht(t),
3672
+ x: [-4.2, 4.2],
3673
+ y: [-3.6, 3.6],
3674
+ values: { step: 0 },
3675
+ items: [
3676
+ { id: "g", kind: "graph", nodes: t.nodes ?? Zt.nodes, edges: t.edges ?? Zt.edges, search: { kind: "dijkstra", start: t.start ?? "A" }, step: "step", frontier: [e * 0.06, n * 0.92] },
3677
+ Ft(t, `d(${i}) = \\val{g.d.${i}:0}`)
3678
+ ]
3679
+ };
3680
+ }
3681
+ function Gr(t = {}) {
3682
+ const e = Math.min(6, Math.max(1, t.n ?? 5)), n = [], i = [], r = (l) => {
3683
+ const c = `c${n.length}`;
3684
+ return n.push({ id: c, label: `F_{${l}}` }), l >= 2 && (i.push([c, r(l - 1)]), i.push([c, r(l - 2)])), c;
3685
+ };
3686
+ r(e);
3687
+ const s = n.filter((l) => !i.some(([c]) => c === l.id)).length, o = Math.max(s * 0.75, 4);
3688
+ return {
3689
+ ...ht(t),
3690
+ x: [-o, o],
3691
+ y: [-(e + 0.2) * 1.05, 1.2],
3692
+ values: { step: 0 },
3693
+ items: [
3694
+ { id: "calls", kind: "graph", nodes: n, edges: i, directed: !0, tree: { root: "c0", spacing: [1.3, 1.05], at: [0, 0] }, search: { kind: "dfs", start: "c0" }, step: "step", radius: 17 },
3695
+ Ft(t, "\\text{calls made: } \\val{calls.visited:0} \\text{ of } \\val{calls.steps:0}")
3696
+ ]
3697
+ };
3698
+ }
3699
+ function Xr(t = {}) {
3700
+ const n = [{ id: "venn", kind: "venn", sets: (t.sets ?? ["A", "B"]).map((i) => ({ id: i })), highlight: t.highlight ?? "A & B", radius: 1.6, at: [0, -0.3] }];
3701
+ return t.label !== void 0 && n.push(Ft(t, t.label)), { ...ht(t), x: [-4, 4], y: [-4, 4], items: n };
3702
+ }
3703
+ function Yr(t = {}) {
3704
+ const e = t.modulus ?? 12;
3705
+ return {
3706
+ ...ht(t),
3707
+ x: [-3, 3],
3708
+ y: [-3, 3],
3709
+ values: { value: t.value ?? 0 },
3710
+ items: [
3711
+ { id: "clock", kind: "clock", modulus: e, value: "value", radius: 2.2, at: [0, -0.2] },
3712
+ Ft(t, `\\val{value:0} \\equiv \\val{clock.hour:0} \\pmod{${e}}`.replace("\\pmod", "\\;(\\text{mod } ").replace(`{${e}}`, `${e})`))
3713
+ ]
3714
+ };
3715
+ }
3716
+ function Zr(t) {
3717
+ return Nt(t);
2808
3718
  }
2809
- function Li(t, e = {}, n = {}) {
2810
- return jn(Lt(bt(t), e), n);
3719
+ function Kr(t, e = {}, n = {}) {
3720
+ return Gi(ee(Nt(t), e), n);
2811
3721
  }
2812
3722
  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,
2837
- 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
3723
+ Wt as CONSTANTS,
3724
+ Ut as DISTRIBUTION_KINDS,
3725
+ yt as ExpressionError,
3726
+ ce as FUNCTIONS,
3727
+ Be as ITEM_KINDS,
3728
+ Hn as MATH_FONT,
3729
+ Wn as MATH_SYMBOL_FONT,
3730
+ be as MATH_THEMES,
3731
+ Ee as MATRIX_TEX,
3732
+ Zt as SAMPLE_GRAPH,
3733
+ _e as SEARCH_KINDS,
3734
+ he as SYMBOLS,
3735
+ Xn as TEX_COMMANDS,
3736
+ Gn as TexError,
3737
+ ge as adjacency,
3738
+ Cr as areaFigure,
3739
+ Vn as ballAt,
3740
+ Ce as ballPath,
3741
+ Bn as bayesAreas,
3742
+ Hr as bayesFigure,
3743
+ re as binOf,
3744
+ _n as binSamples,
3745
+ Dr as binomialFigure,
3746
+ Yr as clockFigure,
3747
+ _r as cltFigure,
3748
+ U as compile,
3749
+ $e as compileDerivative,
3750
+ Fe as defaultBins,
3751
+ ct as density,
3752
+ Tr as determinantFigure,
3753
+ st as differentiate,
3754
+ Gi as displayListToSvg,
3755
+ Ae as displayListToSvgContent,
3756
+ en as distributionProblem,
3757
+ Ui as drawDisplayList,
3758
+ Or as eigenFigure,
3759
+ lt as evaluate,
3760
+ Le as expressionNames,
3761
+ Ct as expressionToString,
3762
+ Rr as galtonFigure,
3763
+ Wr as graphSearchFigure,
3764
+ Ht as inRegion,
3765
+ oe as integrate,
3766
+ Jt as isDiscrete,
3767
+ ee as layoutFigure,
3768
+ J as layoutTex,
3769
+ rn as leastSquares,
3770
+ zr as limitFigure,
3771
+ Er as linearMapFigure,
3772
+ $r as mat2,
3773
+ Ar as mathExplorable,
3774
+ Zr as mathFigure,
3775
+ Xi as mathFigureProps,
3776
+ Kr as mathFigureToSvg,
3777
+ xr as mathSteps,
3778
+ Mr as mathTarget,
3779
+ Pt as meanOf,
3780
+ Br as monteCarloPiFigure,
3781
+ Ei as morphEquation,
3782
+ Sr as mountAllMath,
3783
+ gr as mountMath,
3784
+ jr as normalFigure,
3785
+ jn as nthDerivative,
3786
+ dt as parseExpression,
3787
+ hn as parseSetExpression,
3788
+ Yn as parseTex,
3789
+ wn as planeOf,
3790
+ Gr as recursionTreeFigure,
3791
+ vi as regionCells,
3792
+ Vr as regressionFigure,
3793
+ Fr as riemannFigure,
3794
+ Qe as sample,
3795
+ tn as samples,
3796
+ nn as scatterPoints,
3797
+ It as sdOf,
3798
+ mi as searchEvents,
3799
+ Lr as secantFigure,
3800
+ Vt as setNames,
3801
+ Ur as shortestPathFigure,
3802
+ Ir as spanFigure,
3803
+ Rn as summary,
3804
+ Dn as supportOf,
3805
+ Nr as tangentFigure,
3806
+ qr as taylorFigure,
3807
+ it as texToShapes,
3808
+ gi as treeLayout,
3809
+ B as trimPolylines,
3810
+ Nt as validateMathFigure,
3811
+ kr as vec2,
3812
+ Pr as vectorSumFigure,
3813
+ Xr as vennFigure
2864
3814
  };