@algorisys/tinyfly 0.117.0 → 0.119.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/docs/editor-guide.md +1 -1
- package/docs/examples.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/gsap-compat.md +1 -1
- package/docs/llm-guide.md +5 -1
- package/docs/maps.md +2 -2
- package/docs/math.md +74 -9
- package/docs/teaching.md +1 -1
- package/lib/addons/characters.js +2311 -2299
- package/lib/addons/math.js +2120 -1166
- package/lib/browser/tinyfly-math.iife.js +4 -4
- package/lib/browser/tinyfly.iife.js +1 -1
- package/lib/browser/tinyfly.js +13 -1
- package/lib/browser/tinyfly.umd.js +1 -1
- package/lib/types/math/discrete/graph-search.d.ts +38 -0
- package/lib/types/math/discrete/set-expression.d.ts +33 -0
- package/lib/types/math/figure/display-list.d.ts +10 -0
- package/lib/types/math/figure/figure-spec.d.ts +168 -1
- package/lib/types/math/figure/items/discrete.d.ts +23 -0
- package/lib/types/math/figure/items/ml.d.ts +47 -0
- package/lib/types/math/figure/items/shapes.d.ts +3 -0
- package/lib/types/math/index.d.ts +11 -1
- package/lib/types/math/ml/classify.d.ts +30 -0
- package/lib/types/math/ml/colormap.d.ts +14 -0
- package/lib/types/math/ml/contours.d.ts +15 -0
- package/lib/types/math/ml/descent.d.ts +11 -0
- package/lib/types/math/ml/kmeans.d.ts +11 -0
- package/lib/types/math/ml/network.d.ts +19 -0
- package/lib/types/math/presets/discrete.d.ts +49 -0
- package/lib/types/math/presets/ml.d.ts +50 -0
- package/lib/types/math/tex/glyph-metrics.d.ts +8 -0
- package/lib/types/math/tex/tex-parser.d.ts +2 -1
- package/llms-full.txt +99 -18
- package/llms.txt +31 -31
- package/package.json +1 -1
- package/skills/tinyfly/SKILL.md +3 -1
package/lib/addons/math.js
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { randomNormal as
|
|
2
|
-
import { D as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
const e =
|
|
1
|
+
import { randomNormal as pt, createRandom as $t, hashSeed as yt, closestName as Gn, unknownName as R, deserializeTimeline as Ve, playheadCrossings as Xn } from "@algorisys/tinyfly";
|
|
2
|
+
import { D as He } from "./dom-adapter-Cphr2HZn.js";
|
|
3
|
+
const Yn = (t, e) => [t[0] + e[0], t[1] + e[1]], Ne = (t, e) => [t[0] - e[0], t[1] - e[1]], be = (t, e) => [t[0] * e, t[1] * e], Zn = (t, e) => t[0] * e[0] + t[1] * e[1], Jn = (t, e) => t[0] * e[1] - t[1] * e[0], un = (t) => Math.hypot(t[0], t[1]);
|
|
4
|
+
function Nt(t) {
|
|
5
|
+
const e = un(t);
|
|
6
6
|
return e === 0 ? [0, 0] : [t[0] / e, t[1] / e];
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
function
|
|
8
|
+
const It = (t, e, n) => [t[0] + (e[0] - t[0]) * n, t[1] + (e[1] - t[1]) * n];
|
|
9
|
+
function st(t) {
|
|
10
10
|
return Array.isArray(t) && t.length === 2 && t.every(Number.isFinite);
|
|
11
11
|
}
|
|
12
|
-
const
|
|
12
|
+
const pr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
13
13
|
__proto__: null,
|
|
14
|
-
add:
|
|
15
|
-
cross:
|
|
16
|
-
dot:
|
|
17
|
-
isVec2:
|
|
18
|
-
length:
|
|
19
|
-
lerp:
|
|
20
|
-
normalize:
|
|
21
|
-
scale:
|
|
22
|
-
sub:
|
|
23
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
24
|
-
function
|
|
25
|
-
const [n, i, s, r] = t, [
|
|
26
|
-
return [n *
|
|
27
|
-
}
|
|
28
|
-
const
|
|
29
|
-
function
|
|
30
|
-
const e =
|
|
14
|
+
add: Yn,
|
|
15
|
+
cross: Jn,
|
|
16
|
+
dot: Zn,
|
|
17
|
+
isVec2: st,
|
|
18
|
+
length: un,
|
|
19
|
+
lerp: It,
|
|
20
|
+
normalize: Nt,
|
|
21
|
+
scale: be,
|
|
22
|
+
sub: Ne
|
|
23
|
+
}, Symbol.toStringTag, { value: "Module" })), Ft = [1, 0, 0, 1], tt = ([t, e, n, i], [s, r]) => [t * s + e * r, n * s + i * r];
|
|
24
|
+
function Kn(t, e) {
|
|
25
|
+
const [n, i, s, r] = t, [a, l, c, d] = e;
|
|
26
|
+
return [n * a + i * c, n * l + i * d, s * a + r * c, s * l + r * d];
|
|
27
|
+
}
|
|
28
|
+
const Lt = ([t, e, n, i]) => t * i - e * n;
|
|
29
|
+
function Qn(t) {
|
|
30
|
+
const e = Lt(t);
|
|
31
31
|
if (Math.abs(e) < 1e-12) return;
|
|
32
32
|
const [n, i, s, r] = t;
|
|
33
33
|
return [r / e, -i / e, -s / e, n / e];
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
function
|
|
37
|
-
const [e, n, i, s] = t, r = e + s,
|
|
35
|
+
const ti = (t, e, n) => t.map((i, s) => i + (e[s] - i) * n), ei = (t) => [Math.cos(t), -Math.sin(t), Math.sin(t), Math.cos(t)];
|
|
36
|
+
function dn(t) {
|
|
37
|
+
const [e, n, i, s] = t, r = e + s, a = Lt(t), l = r * r - 4 * a, c = 1e-9;
|
|
38
38
|
if (l < -c) return [];
|
|
39
39
|
const d = Math.sqrt(Math.max(0, l)), u = d < c ? [r / 2] : [(r + d) / 2, (r - d) / 2], p = [];
|
|
40
40
|
for (const h of u) {
|
|
41
|
-
const f = [[e - h, n], [i, s - h]].reduce((
|
|
41
|
+
const f = [[e - h, n], [i, s - h]].reduce((v, x) => Math.hypot(...x) > Math.hypot(...v) ? x : v);
|
|
42
42
|
if (Math.hypot(...f) < c) {
|
|
43
43
|
p.push({ value: h, vector: [1, 0] }, { value: h, vector: [0, 1] });
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
|
-
const
|
|
47
|
-
p.push({ value: h, vector: [
|
|
46
|
+
const g = [-f[1], f[0]], o = Math.hypot(...g), m = g[0] < -c || Math.abs(g[0]) <= c && g[1] < 0 ? -1 : 1;
|
|
47
|
+
p.push({ value: h, vector: [m * g[0] / o + 0, m * g[1] / o + 0] });
|
|
48
48
|
}
|
|
49
49
|
return p;
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function vt(t) {
|
|
52
52
|
return Array.isArray(t) && t.length === 4 && t.every(Number.isFinite);
|
|
53
53
|
}
|
|
54
|
-
const
|
|
54
|
+
const fr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
55
55
|
__proto__: null,
|
|
56
|
-
IDENTITY:
|
|
57
|
-
apply:
|
|
58
|
-
determinant:
|
|
59
|
-
eigen:
|
|
60
|
-
inverse:
|
|
61
|
-
isMat2:
|
|
62
|
-
lerp:
|
|
63
|
-
multiply:
|
|
64
|
-
rotation:
|
|
65
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
56
|
+
IDENTITY: Ft,
|
|
57
|
+
apply: tt,
|
|
58
|
+
determinant: Lt,
|
|
59
|
+
eigen: dn,
|
|
60
|
+
inverse: Qn,
|
|
61
|
+
isMat2: vt,
|
|
62
|
+
lerp: ti,
|
|
63
|
+
multiply: Kn,
|
|
64
|
+
rotation: ei
|
|
65
|
+
}, Symbol.toStringTag, { value: "Module" })), ve = {
|
|
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 Yi = /* @__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
|
-
},
|
|
92
|
-
class
|
|
91
|
+
}, Kt = { pi: Math.PI, e: Math.E, tau: Math.PI * 2 };
|
|
92
|
+
class bt extends Error {
|
|
93
93
|
source;
|
|
94
94
|
/** 0-based index into the source */
|
|
95
95
|
position;
|
|
@@ -97,7 +97,7 @@ class ht 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
|
|
100
|
+
function ni(t) {
|
|
101
101
|
const e = [];
|
|
102
102
|
let n = 0;
|
|
103
103
|
for (; n < t.length; ) {
|
|
@@ -120,21 +120,21 @@ function kn(t) {
|
|
|
120
120
|
e.push({ kind: "op", value: i, at: n }), n++;
|
|
121
121
|
continue;
|
|
122
122
|
}
|
|
123
|
-
throw new
|
|
123
|
+
throw new bt(`Unexpected "${i}"`, t, n);
|
|
124
124
|
}
|
|
125
125
|
return e.push({ kind: "end", at: t.length }), e;
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function ot(t) {
|
|
128
128
|
if (typeof t != "string") throw new TypeError("parseExpression: expected a string");
|
|
129
|
-
const e =
|
|
129
|
+
const e = ni(t);
|
|
130
130
|
let n = 0;
|
|
131
131
|
const i = () => e[n], s = (h) => {
|
|
132
|
-
const
|
|
133
|
-
return
|
|
132
|
+
const y = i();
|
|
133
|
+
return y.kind === "op" && y.value === h;
|
|
134
134
|
}, r = (h) => {
|
|
135
|
-
if (!s(h)) throw new
|
|
135
|
+
if (!s(h)) throw new bt(`Expected "${h}"`, t, i().at);
|
|
136
136
|
n++;
|
|
137
|
-
},
|
|
137
|
+
}, a = () => {
|
|
138
138
|
let h = l();
|
|
139
139
|
for (; s("+") || s("-"); )
|
|
140
140
|
h = { type: "binary", operator: e[n++].value, left: h, right: l() };
|
|
@@ -157,141 +157,141 @@ function lt(t) {
|
|
|
157
157
|
return n++, { type: "number", value: h.value };
|
|
158
158
|
if (h.kind === "name") {
|
|
159
159
|
if (n++, !s("(")) return { type: "name", name: h.value };
|
|
160
|
-
const
|
|
161
|
-
if (!
|
|
160
|
+
const y = Object.prototype.hasOwnProperty.call(ve, h.value) ? ve[h.value] : void 0;
|
|
161
|
+
if (!y) throw new bt(`Unknown function "${h.value}"`, t, h.at);
|
|
162
162
|
n++;
|
|
163
163
|
const f = [];
|
|
164
164
|
if (!s(")"))
|
|
165
|
-
for (f.push(
|
|
166
|
-
n++, f.push(
|
|
167
|
-
if (r(")"), f.length !==
|
|
168
|
-
throw new
|
|
165
|
+
for (f.push(a()); s(","); )
|
|
166
|
+
n++, f.push(a());
|
|
167
|
+
if (r(")"), f.length !== y.arity)
|
|
168
|
+
throw new bt(`"${h.value}" takes ${y.arity} argument${y.arity === 1 ? "" : "s"}, got ${f.length}`, t, h.at);
|
|
169
169
|
return { type: "call", name: h.value, args: f };
|
|
170
170
|
}
|
|
171
171
|
if (s("(")) {
|
|
172
172
|
n++;
|
|
173
|
-
const
|
|
174
|
-
return r(")"),
|
|
173
|
+
const y = a();
|
|
174
|
+
return r(")"), y;
|
|
175
175
|
}
|
|
176
|
-
throw new
|
|
177
|
-
}, p =
|
|
178
|
-
if (i().kind !== "end") throw new
|
|
176
|
+
throw new bt(h.kind === "end" ? "Unexpected end" : `Unexpected "${h.value}"`, t, h.at);
|
|
177
|
+
}, p = a();
|
|
178
|
+
if (i().kind !== "end") throw new bt(`Unexpected "${i().value}"`, t, i().at);
|
|
179
179
|
return p;
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function Ue(t) {
|
|
182
182
|
const e = /* @__PURE__ */ new Set(), n = (i) => {
|
|
183
|
-
i.type === "name" && !(i.name in
|
|
183
|
+
i.type === "name" && !(i.name in Kt) ? 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
|
|
188
|
-
function
|
|
189
|
-
return
|
|
187
|
+
const F = (t) => ({ type: "number", value: t }), Ot = F(0), z = F(1), B = (t) => t.type === "number", Z = (t, e) => t.type === "number" && t.value === e;
|
|
188
|
+
function lt(t, e) {
|
|
189
|
+
return B(t) && B(e) ? F(t.value + e.value) : Z(t, 0) ? e : Z(e, 0) ? t : { type: "binary", operator: "+", left: t, right: e };
|
|
190
190
|
}
|
|
191
|
-
function
|
|
192
|
-
return
|
|
191
|
+
function it(t, e) {
|
|
192
|
+
return B(t) && B(e) ? F(t.value - e.value) : Z(e, 0) ? t : Z(t, 0) ? Gt(e) : { type: "binary", operator: "-", left: t, right: e };
|
|
193
193
|
}
|
|
194
|
-
function
|
|
195
|
-
return
|
|
194
|
+
function C(t, e) {
|
|
195
|
+
return B(t) && B(e) ? F(t.value * e.value) : Z(t, 0) || Z(e, 0) ? Ot : Z(t, 1) ? e : Z(e, 1) ? t : B(e) ? C(e, t) : B(t) && e.type === "binary" && e.operator === "*" && B(e.left) ? C(F(t.value * e.left.value), e.right) : { type: "binary", operator: "*", left: t, right: e };
|
|
196
196
|
}
|
|
197
|
-
function
|
|
198
|
-
return
|
|
197
|
+
function U(t, e) {
|
|
198
|
+
return Z(t, 0) ? Ot : Z(e, 1) ? t : B(t) && B(e) && e.value !== 0 ? F(t.value / e.value) : { type: "binary", operator: "/", left: t, right: e };
|
|
199
199
|
}
|
|
200
|
-
function
|
|
201
|
-
return
|
|
200
|
+
function ct(t, e) {
|
|
201
|
+
return Z(e, 0) ? z : Z(e, 1) ? t : B(t) && B(e) ? F(t.value ** e.value) : { type: "binary", operator: "^", left: t, right: e };
|
|
202
202
|
}
|
|
203
|
-
function
|
|
204
|
-
return
|
|
203
|
+
function Gt(t) {
|
|
204
|
+
return B(t) ? F(-t.value) : t.type === "unary" && t.operator === "-" ? t.operand : { type: "unary", operator: "-", operand: t };
|
|
205
205
|
}
|
|
206
|
-
const
|
|
207
|
-
function
|
|
206
|
+
const W = (t, ...e) => ({ type: "call", name: t, args: e });
|
|
207
|
+
function dt(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
|
|
214
|
+
return dt(t.operand, e);
|
|
215
215
|
case "binary":
|
|
216
|
-
return
|
|
216
|
+
return dt(t.left, e) && dt(t.right, e);
|
|
217
217
|
case "call":
|
|
218
|
-
return t.args.every((n) =>
|
|
218
|
+
return t.args.every((n) => dt(n, e));
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
function
|
|
222
|
-
if (
|
|
221
|
+
function X(t, e = "x") {
|
|
222
|
+
if (dt(t, e)) return Ot;
|
|
223
223
|
switch (t.type) {
|
|
224
224
|
case "number":
|
|
225
|
-
return
|
|
225
|
+
return Ot;
|
|
226
226
|
case "name":
|
|
227
|
-
return t.name === e ?
|
|
227
|
+
return t.name === e ? z : Ot;
|
|
228
228
|
case "unary":
|
|
229
|
-
return t.operator === "-" ?
|
|
229
|
+
return t.operator === "-" ? Gt(X(t.operand, e)) : X(t.operand, e);
|
|
230
230
|
case "binary": {
|
|
231
|
-
const { left: n, right: i } = t, s = () =>
|
|
231
|
+
const { left: n, right: i } = t, s = () => X(n, e), r = () => X(i, e);
|
|
232
232
|
switch (t.operator) {
|
|
233
233
|
case "+":
|
|
234
|
-
return
|
|
234
|
+
return lt(s(), r());
|
|
235
235
|
case "-":
|
|
236
|
-
return
|
|
236
|
+
return it(s(), r());
|
|
237
237
|
case "*":
|
|
238
|
-
return
|
|
238
|
+
return lt(C(s(), i), C(n, r()));
|
|
239
239
|
case "/":
|
|
240
|
-
return
|
|
240
|
+
return U(it(C(s(), i), C(n, r())), ct(i, F(2)));
|
|
241
241
|
case "^":
|
|
242
|
-
if (
|
|
243
|
-
const
|
|
244
|
-
return
|
|
242
|
+
if (dt(i, e)) {
|
|
243
|
+
const a = B(i) ? F(i.value - 1) : it(i, z);
|
|
244
|
+
return C(C(i, ct(n, a)), s());
|
|
245
245
|
}
|
|
246
|
-
return
|
|
246
|
+
return dt(n, e) ? C(C(t, W("ln", n)), r()) : C(t, lt(C(r(), W("ln", n)), U(C(i, s()), n)));
|
|
247
247
|
}
|
|
248
248
|
break;
|
|
249
249
|
}
|
|
250
250
|
case "call": {
|
|
251
|
-
const [n, i] = t.args, s = () =>
|
|
251
|
+
const [n, i] = t.args, s = () => X(n, e), r = (a) => C(a, s());
|
|
252
252
|
switch (t.name) {
|
|
253
253
|
case "sin":
|
|
254
|
-
return r(
|
|
254
|
+
return r(W("cos", n));
|
|
255
255
|
case "cos":
|
|
256
|
-
return r(
|
|
256
|
+
return r(Gt(W("sin", n)));
|
|
257
257
|
case "tan":
|
|
258
|
-
return r(
|
|
258
|
+
return r(U(z, ct(W("cos", n), F(2))));
|
|
259
259
|
case "asin":
|
|
260
|
-
return r(
|
|
260
|
+
return r(U(z, W("sqrt", it(z, ct(n, F(2))))));
|
|
261
261
|
case "acos":
|
|
262
|
-
return r(
|
|
262
|
+
return r(Gt(U(z, W("sqrt", it(z, ct(n, F(2)))))));
|
|
263
263
|
case "atan":
|
|
264
|
-
return r(
|
|
264
|
+
return r(U(z, lt(z, ct(n, F(2)))));
|
|
265
265
|
case "sinh":
|
|
266
|
-
return r(
|
|
266
|
+
return r(W("cosh", n));
|
|
267
267
|
case "cosh":
|
|
268
|
-
return r(
|
|
268
|
+
return r(W("sinh", n));
|
|
269
269
|
case "tanh":
|
|
270
|
-
return r(
|
|
270
|
+
return r(it(z, ct(W("tanh", n), F(2))));
|
|
271
271
|
case "exp":
|
|
272
272
|
return r(t);
|
|
273
273
|
case "ln":
|
|
274
|
-
return r(
|
|
274
|
+
return r(U(z, n));
|
|
275
275
|
case "log":
|
|
276
|
-
return r(
|
|
276
|
+
return r(U(z, C(n, F(Math.LN10))));
|
|
277
277
|
case "log2":
|
|
278
|
-
return r(
|
|
278
|
+
return r(U(z, C(n, F(Math.LN2))));
|
|
279
279
|
case "sqrt":
|
|
280
|
-
return r(
|
|
280
|
+
return r(U(z, C(F(2), t)));
|
|
281
281
|
case "abs":
|
|
282
|
-
return r(
|
|
282
|
+
return r(W("sign", n));
|
|
283
283
|
case "sigmoid":
|
|
284
|
-
return r(
|
|
284
|
+
return r(C(t, it(z, t)));
|
|
285
285
|
case "relu":
|
|
286
|
-
return r(
|
|
286
|
+
return r(U(lt(W("sign", n), z), F(2)));
|
|
287
287
|
case "atan2": {
|
|
288
|
-
const
|
|
289
|
-
return
|
|
288
|
+
const a = X(i, e);
|
|
289
|
+
return U(it(C(i, s()), C(n, a)), lt(ct(n, F(2)), ct(i, F(2))));
|
|
290
290
|
}
|
|
291
291
|
case "min":
|
|
292
292
|
case "max": {
|
|
293
|
-
const
|
|
294
|
-
return
|
|
293
|
+
const a = t.name === "max" ? 1 : -1, l = X(i, e), c = U(lt(z, C(F(a), W("sign", it(n, i)))), F(2));
|
|
294
|
+
return lt(C(c, s()), C(it(z, c), l));
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
throw new Error(`differentiate: "${t.name}" has no derivative rule`);
|
|
@@ -299,40 +299,40 @@ function tt(t, e = "x") {
|
|
|
299
299
|
}
|
|
300
300
|
throw new Error("differentiate: malformed expression");
|
|
301
301
|
}
|
|
302
|
-
function
|
|
302
|
+
function ii(t, e, n = "x") {
|
|
303
303
|
let i = t;
|
|
304
|
-
for (let s = 0; s < e; s++) i =
|
|
304
|
+
for (let s = 0; s < e; s++) i = X(i, n);
|
|
305
305
|
return i;
|
|
306
306
|
}
|
|
307
|
-
function
|
|
307
|
+
function Rt(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}${
|
|
314
|
+
return `(${t.operator}${Rt(t.operand)})`;
|
|
315
315
|
case "binary":
|
|
316
|
-
return `(${
|
|
316
|
+
return `(${Rt(t.left)} ${t.operator} ${Rt(t.right)})`;
|
|
317
317
|
case "call":
|
|
318
|
-
return `${t.name}(${t.args.map(
|
|
318
|
+
return `${t.name}(${t.args.map(Rt).join(", ")})`;
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
-
function
|
|
321
|
+
function et(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(
|
|
327
|
+
if (Object.prototype.hasOwnProperty.call(Kt, t.name)) return Kt[t.name];
|
|
328
328
|
throw new Error(`evaluate: unknown name "${t.name}"`);
|
|
329
329
|
}
|
|
330
330
|
case "unary": {
|
|
331
|
-
const n =
|
|
331
|
+
const n = et(t.operand, e);
|
|
332
332
|
return t.operator === "-" ? -n : n;
|
|
333
333
|
}
|
|
334
334
|
case "binary": {
|
|
335
|
-
const n =
|
|
335
|
+
const n = et(t.left, e), i = et(t.right, e);
|
|
336
336
|
switch (t.operator) {
|
|
337
337
|
case "+":
|
|
338
338
|
return n + i;
|
|
@@ -348,63 +348,63 @@ function rt(t, e = {}) {
|
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
350
|
case "call":
|
|
351
|
-
return
|
|
351
|
+
return ve[t.name].apply(...t.args.map((n) => et(n, e)));
|
|
352
352
|
}
|
|
353
353
|
throw new Error("evaluate: malformed expression");
|
|
354
354
|
}
|
|
355
|
-
const
|
|
356
|
-
function
|
|
357
|
-
let n =
|
|
358
|
-
n || (n =
|
|
355
|
+
const Xt = /* @__PURE__ */ new Map();
|
|
356
|
+
function Y(t, e = "x") {
|
|
357
|
+
let n = Xt.get(t);
|
|
358
|
+
n || (n = ot(t), Xt.size < 256 && Xt.set(t, n));
|
|
359
359
|
const i = n;
|
|
360
|
-
return (s, r = {}) =>
|
|
360
|
+
return (s, r = {}) => et(i, { ...r, [e]: s });
|
|
361
361
|
}
|
|
362
|
-
const
|
|
363
|
-
function
|
|
362
|
+
const he = /* @__PURE__ */ new Map();
|
|
363
|
+
function Pe(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 s =
|
|
366
|
+
let s = he.get(i);
|
|
367
367
|
if (!s) {
|
|
368
|
-
let
|
|
369
|
-
|
|
368
|
+
let a = Xt.get(t);
|
|
369
|
+
a || (a = ot(t)), s = ii(a, e, n), he.size < 512 && he.set(i, s);
|
|
370
370
|
}
|
|
371
371
|
const r = s;
|
|
372
|
-
return (
|
|
372
|
+
return (a, l = {}) => et(r, { ...l, [n]: a });
|
|
373
373
|
}
|
|
374
|
-
function
|
|
374
|
+
function hn(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 (
|
|
380
|
-
const [s, r,
|
|
381
|
-
Object.assign(e, { [`${n}.a`]: s, [`${n}.b`]: r, [`${n}.c`]:
|
|
382
|
-
} else
|
|
379
|
+
else if (vt(i)) {
|
|
380
|
+
const [s, r, a, l] = i;
|
|
381
|
+
Object.assign(e, { [`${n}.a`]: s, [`${n}.b`]: r, [`${n}.c`]: a, [`${n}.d`]: l, [`${n}.det`]: Lt(i) });
|
|
382
|
+
} else st(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
|
|
385
|
+
function T(t, e, n) {
|
|
386
386
|
return e ? Object.prototype.hasOwnProperty.call(t.colors, e) ? t.colors[e] : e : n;
|
|
387
387
|
}
|
|
388
|
-
function
|
|
388
|
+
function wt(t, e) {
|
|
389
389
|
if (typeof e != "string") return e;
|
|
390
390
|
const n = t[e];
|
|
391
|
-
if (!
|
|
391
|
+
if (!st(n)) throw new Error(`math figure: value "${e}" is not an [x, y] vector`);
|
|
392
392
|
return n;
|
|
393
393
|
}
|
|
394
|
-
function
|
|
395
|
-
if (e === void 0) return
|
|
394
|
+
function mt(t, e) {
|
|
395
|
+
if (e === void 0) return Ft;
|
|
396
396
|
const n = t[e];
|
|
397
|
-
if (!
|
|
397
|
+
if (!vt(n)) throw new Error(`math figure: value "${e}" is not a [a, b, c, d] matrix`);
|
|
398
398
|
return n;
|
|
399
399
|
}
|
|
400
|
-
function
|
|
400
|
+
function E(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
|
|
407
|
-
const n = (s) => s === void 0 ? void 0 :
|
|
406
|
+
function kt(t, e) {
|
|
407
|
+
const n = (s) => s === void 0 ? void 0 : E(t, s), i = (s) => s === void 0 ? void 0 : Math.round(E(t, s));
|
|
408
408
|
switch (e.kind) {
|
|
409
409
|
case "normal":
|
|
410
410
|
return { kind: "normal", mean: n(e.mean), sd: n(e.sd) };
|
|
@@ -419,11 +419,11 @@ function ft(t, e) {
|
|
|
419
419
|
case "dice":
|
|
420
420
|
return { kind: "dice", count: i(e.count), sides: i(e.sides) };
|
|
421
421
|
case "mean":
|
|
422
|
-
return { kind: "mean", of:
|
|
422
|
+
return { kind: "mean", of: kt(t, e.of), count: i(e.count) };
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
|
-
const
|
|
426
|
-
function
|
|
425
|
+
const Qt = ["normal", "uniform", "exponential", "binomial", "poisson", "dice", "mean"];
|
|
426
|
+
function si(t) {
|
|
427
427
|
switch (t.kind) {
|
|
428
428
|
case "binomial":
|
|
429
429
|
return [0, t.n];
|
|
@@ -435,17 +435,17 @@ function Mn(t) {
|
|
|
435
435
|
return [-1 / 0, 1 / 0];
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
|
-
function
|
|
438
|
+
function re(t) {
|
|
439
439
|
return t.kind === "binomial" || t.kind === "poisson" || t.kind === "dice";
|
|
440
440
|
}
|
|
441
|
-
const
|
|
441
|
+
const Yt = /* @__PURE__ */ (() => {
|
|
442
442
|
const t = [0];
|
|
443
443
|
return (e) => {
|
|
444
444
|
for (let n = t.length; n <= e; n++) t[n] = t[n - 1] + Math.log(n);
|
|
445
445
|
return t[e];
|
|
446
446
|
};
|
|
447
|
-
})(),
|
|
448
|
-
function
|
|
447
|
+
})(), pe = (t, e) => Math.exp(Yt(t) - Yt(e) - Yt(t - e));
|
|
448
|
+
function ut(t, e) {
|
|
449
449
|
switch (t.kind) {
|
|
450
450
|
case "normal": {
|
|
451
451
|
const { mean: n = 0, sd: i = 1 } = t;
|
|
@@ -460,22 +460,22 @@ function st(t, e) {
|
|
|
460
460
|
return e < 0 ? 0 : n * Math.exp(-n * e);
|
|
461
461
|
}
|
|
462
462
|
case "binomial":
|
|
463
|
-
return !Number.isInteger(e) || e < 0 || e > t.n ? 0 :
|
|
463
|
+
return !Number.isInteger(e) || e < 0 || e > t.n ? 0 : pe(t.n, e) * t.p ** e * (1 - t.p) ** (t.n - e);
|
|
464
464
|
case "poisson":
|
|
465
|
-
return !Number.isInteger(e) || e < 0 ? 0 : Math.exp(e * Math.log(t.rate) - t.rate -
|
|
465
|
+
return !Number.isInteger(e) || e < 0 ? 0 : Math.exp(e * Math.log(t.rate) - t.rate - Yt(e));
|
|
466
466
|
case "dice": {
|
|
467
467
|
const { count: n = 2, sides: i = 6 } = t;
|
|
468
468
|
if (!Number.isInteger(e) || e < n || e > n * i) return 0;
|
|
469
469
|
let s = 0;
|
|
470
470
|
for (let r = 0; r <= Math.floor((e - n) / i); r++)
|
|
471
|
-
s += (r % 2 ? -1 : 1) *
|
|
471
|
+
s += (r % 2 ? -1 : 1) * pe(n, r) * pe(e - i * r - 1, n - 1);
|
|
472
472
|
return s / i ** n;
|
|
473
473
|
}
|
|
474
474
|
case "mean":
|
|
475
|
-
return t.count === 1 ?
|
|
475
|
+
return t.count === 1 ? ut(t.of, e) : ut({ kind: "normal", mean: Ct(t.of), sd: qt(t.of) / Math.sqrt(t.count) }, e);
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
|
-
function
|
|
478
|
+
function Ct(t) {
|
|
479
479
|
switch (t.kind) {
|
|
480
480
|
case "normal":
|
|
481
481
|
return t.mean ?? 0;
|
|
@@ -490,10 +490,10 @@ function At(t) {
|
|
|
490
490
|
case "dice":
|
|
491
491
|
return (t.count ?? 2) * ((t.sides ?? 6) + 1) / 2;
|
|
492
492
|
case "mean":
|
|
493
|
-
return
|
|
493
|
+
return Ct(t.of);
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
|
-
function
|
|
496
|
+
function qt(t) {
|
|
497
497
|
switch (t.kind) {
|
|
498
498
|
case "normal":
|
|
499
499
|
return t.sd ?? 1;
|
|
@@ -508,13 +508,13 @@ function Et(t) {
|
|
|
508
508
|
case "dice":
|
|
509
509
|
return Math.sqrt((t.count ?? 2) * ((t.sides ?? 6) ** 2 - 1) / 12);
|
|
510
510
|
case "mean":
|
|
511
|
-
return
|
|
511
|
+
return qt(t.of) / Math.sqrt(t.count);
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
|
-
function
|
|
514
|
+
function pn(t, e) {
|
|
515
515
|
switch (t.kind) {
|
|
516
516
|
case "normal":
|
|
517
|
-
return
|
|
517
|
+
return pt(e, t.mean ?? 0, t.sd ?? 1);
|
|
518
518
|
case "uniform":
|
|
519
519
|
return (t.min ?? 0) + e.next() * ((t.max ?? 1) - (t.min ?? 0));
|
|
520
520
|
case "exponential":
|
|
@@ -538,24 +538,24 @@ function We(t, e) {
|
|
|
538
538
|
}
|
|
539
539
|
case "mean": {
|
|
540
540
|
let n = 0;
|
|
541
|
-
for (let i = 0; i < t.count; i++) n +=
|
|
541
|
+
for (let i = 0; i < t.count; i++) n += pn(t.of, e);
|
|
542
542
|
return n / t.count;
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
}
|
|
546
|
-
const
|
|
547
|
-
function
|
|
546
|
+
const Bt = /* @__PURE__ */ new Map();
|
|
547
|
+
function fn(t, e, n) {
|
|
548
548
|
const i = `${JSON.stringify(t)}|${e}`;
|
|
549
|
-
let s =
|
|
550
|
-
if (s || (s = [],
|
|
551
|
-
const r =
|
|
552
|
-
for (let l = 0; l < n; l++)
|
|
553
|
-
s.splice(0, s.length, ...
|
|
549
|
+
let s = Bt.get(i);
|
|
550
|
+
if (s || (s = [], Bt.size > 64 && Bt.clear(), Bt.set(i, s)), s.length < n) {
|
|
551
|
+
const r = $t(typeof e == "number" ? e : yt(e)), a = [];
|
|
552
|
+
for (let l = 0; l < n; l++) a.push(pn(t, r));
|
|
553
|
+
s.splice(0, s.length, ...a);
|
|
554
554
|
}
|
|
555
555
|
return s.slice(0, n);
|
|
556
556
|
}
|
|
557
|
-
function
|
|
558
|
-
if (!t || typeof t != "object" || !
|
|
557
|
+
function yn(t) {
|
|
558
|
+
if (!t || typeof t != "object" || !Qt.includes(t.kind)) return `kind must be one of ${Qt.join(", ")}`;
|
|
559
559
|
const e = (n, i) => n !== void 0 && !(n > 0) ? `${i} must be positive` : void 0;
|
|
560
560
|
switch (t.kind) {
|
|
561
561
|
case "normal":
|
|
@@ -571,73 +571,73 @@ function He(t) {
|
|
|
571
571
|
case "dice":
|
|
572
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
573
|
case "mean":
|
|
574
|
-
return Number.isInteger(t.count) && t.count >= 1 && t.count <= 200 ?
|
|
574
|
+
return Number.isInteger(t.count) && t.count >= 1 && t.count <= 200 ? yn(t.of) : "count must be a whole number 1..200";
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
|
-
function
|
|
578
|
-
const e =
|
|
579
|
-
if (
|
|
580
|
-
const [i, s] =
|
|
581
|
-
return [r - 0.5,
|
|
577
|
+
function We(t) {
|
|
578
|
+
const e = Ct(t), n = qt(t);
|
|
579
|
+
if (re(t)) {
|
|
580
|
+
const [i, s] = si(t), r = Math.max(i, Math.floor(e - 4 * n)), a = Math.min(s, Math.ceil(e + 4 * n));
|
|
581
|
+
return [r - 0.5, a + 0.5, a - r + 1];
|
|
582
582
|
}
|
|
583
583
|
return [e - 4 * n, e + 4 * n, 30];
|
|
584
584
|
}
|
|
585
|
-
function
|
|
586
|
-
const r = (n - e) / i,
|
|
585
|
+
function ri(t, [e, n, i], s) {
|
|
586
|
+
const r = (n - e) / i, a = new Array(i).fill(0);
|
|
587
587
|
for (const c of t) {
|
|
588
588
|
const d = Math.floor((c - e) / r);
|
|
589
|
-
d >= 0 && d < i ?
|
|
589
|
+
d >= 0 && d < i ? a[d]++ : c === n && a[i - 1]++;
|
|
590
590
|
}
|
|
591
591
|
const l = t.length || 1;
|
|
592
|
-
return
|
|
592
|
+
return a.map((c, d) => ({
|
|
593
593
|
left: e + d * r,
|
|
594
594
|
right: e + (d + 1) * r,
|
|
595
595
|
count: c,
|
|
596
596
|
height: s === "density" ? c / (l * r) : c
|
|
597
597
|
}));
|
|
598
598
|
}
|
|
599
|
-
function
|
|
599
|
+
function oi(t) {
|
|
600
600
|
if (t.length === 0) return { mean: 0, sd: 0 };
|
|
601
601
|
const e = t.reduce((i, s) => i + s, 0) / t.length, n = t.reduce((i, s) => i + (s - e) ** 2, 0) / t.length;
|
|
602
602
|
return { mean: e, sd: Math.sqrt(n) };
|
|
603
603
|
}
|
|
604
|
-
function
|
|
605
|
-
const i =
|
|
604
|
+
function mn(t, e, n) {
|
|
605
|
+
const i = $t(typeof e == "number" ? e : yt(e));
|
|
606
606
|
return Array.from({ length: Math.max(0, Math.floor(n)) }, () => {
|
|
607
607
|
const s = i.next();
|
|
608
608
|
if (t.kind === "uniform") {
|
|
609
|
-
const
|
|
610
|
-
return [t.x[0] + s * (t.x[1] - t.x[0]), t.y[0] +
|
|
609
|
+
const a = i.next();
|
|
610
|
+
return [t.x[0] + s * (t.x[1] - t.x[0]), t.y[0] + a * (t.y[1] - t.y[0])];
|
|
611
611
|
}
|
|
612
612
|
const r = t.x[0] + s * (t.x[1] - t.x[0]);
|
|
613
|
-
return [r, t.slope * r + t.intercept + t.noise *
|
|
613
|
+
return [r, t.slope * r + t.intercept + t.noise * pt(i)];
|
|
614
614
|
});
|
|
615
615
|
}
|
|
616
|
-
function
|
|
616
|
+
function gn(t) {
|
|
617
617
|
const e = t.length;
|
|
618
618
|
if (e < 2) return;
|
|
619
619
|
const n = t.reduce((c, d) => c + d[0], 0) / e, i = t.reduce((c, d) => c + d[1], 0) / e;
|
|
620
|
-
let s = 0, r = 0,
|
|
620
|
+
let s = 0, r = 0, a = 0;
|
|
621
621
|
for (const [c, d] of t)
|
|
622
|
-
s += (c - n) * (d - i), r += (c - n) ** 2,
|
|
622
|
+
s += (c - n) * (d - i), r += (c - n) ** 2, a += (d - i) ** 2;
|
|
623
623
|
if (r === 0) return;
|
|
624
624
|
const l = s / r;
|
|
625
|
-
return { slope: l, intercept: i - l * n, r:
|
|
625
|
+
return { slope: l, intercept: i - l * n, r: a === 0 ? 0 : s / Math.sqrt(r * a) };
|
|
626
626
|
}
|
|
627
|
-
function
|
|
628
|
-
const i = Math.min(1, Math.max(0, t)), s = i * Math.min(1, Math.max(0, e)), r = (1 - i) * Math.min(1, Math.max(0, n)),
|
|
629
|
-
return { truePositive: s, falsePositive: r, positive:
|
|
627
|
+
function ai(t, e, n) {
|
|
628
|
+
const i = Math.min(1, Math.max(0, t)), s = i * Math.min(1, Math.max(0, e)), r = (1 - i) * Math.min(1, Math.max(0, n)), a = s + r;
|
|
629
|
+
return { truePositive: s, falsePositive: r, positive: a, posterior: a > 0 ? s / a : 0 };
|
|
630
630
|
}
|
|
631
|
-
function
|
|
632
|
-
const i =
|
|
631
|
+
function Ge(t, e, n) {
|
|
632
|
+
const i = $t(yt(`${t}:${e}`));
|
|
633
633
|
return Array.from({ length: n }, () => i.next() < 0.5);
|
|
634
634
|
}
|
|
635
|
-
const
|
|
636
|
-
function
|
|
635
|
+
const fe = (t) => t.filter(Boolean).length;
|
|
636
|
+
function ci(t, e) {
|
|
637
637
|
const n = t.length, i = Math.min(1, Math.max(0, e)) * n, s = Math.min(n - 1, Math.floor(i)), r = i - s, l = t.slice(0, s).filter(Boolean).length - s / 2, c = l + (t[s] ? 0.5 : -0.5), d = 0.18 * Math.sin(Math.PI * r);
|
|
638
638
|
return { x: l + (c - l) * r, depth: s + r - d };
|
|
639
639
|
}
|
|
640
|
-
const
|
|
640
|
+
const li = '"Latin Modern Math", "STIX Two Math", "Cambria Math", "Times New Roman", "Liberation Serif", "Noto Serif", Times, serif', ui = '"Latin Modern Math", "STIX Two Math", "Cambria Math", "DejaVu Math TeX Gyre", "DejaVu Serif", serif', di = (t) => /^[A-Za-z0-9\u0370-\u03ff.,;:!?()[\]'"/ ]+$/.test(t) ? li : ui, bn = 0.25, Pt = 0.05, Xe = {
|
|
641
641
|
a: 0.5,
|
|
642
642
|
b: 0.56,
|
|
643
643
|
c: 0.44,
|
|
@@ -691,13 +691,13 @@ const Tn = '"Latin Modern Math", "STIX Two Math", "Cambria Math", "Times New Rom
|
|
|
691
691
|
Y: 0.75,
|
|
692
692
|
Z: 0.61
|
|
693
693
|
};
|
|
694
|
-
function
|
|
695
|
-
return t.length !== 1 ? t.length * 0.5 : /[0-9]/.test(t) ? 0.5 : Object.prototype.hasOwnProperty.call(
|
|
694
|
+
function we(t) {
|
|
695
|
+
return t.length !== 1 ? t.length * 0.5 : /[0-9]/.test(t) ? 0.5 : Object.prototype.hasOwnProperty.call(Xe, t) ? Xe[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;
|
|
696
696
|
}
|
|
697
|
-
function
|
|
697
|
+
function vn(t) {
|
|
698
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
699
|
}
|
|
700
|
-
const
|
|
700
|
+
const ke = {
|
|
701
701
|
alpha: "α",
|
|
702
702
|
beta: "β",
|
|
703
703
|
gamma: "γ",
|
|
@@ -733,7 +733,7 @@ const ee = {
|
|
|
733
733
|
Phi: "Φ",
|
|
734
734
|
Psi: "Ψ",
|
|
735
735
|
Omega: "Ω"
|
|
736
|
-
},
|
|
736
|
+
}, $e = {
|
|
737
737
|
cdot: ["·", "bin"],
|
|
738
738
|
times: ["×", "bin"],
|
|
739
739
|
div: ["÷", "bin"],
|
|
@@ -745,6 +745,18 @@ const ee = {
|
|
|
745
745
|
land: ["∧", "bin"],
|
|
746
746
|
lor: ["∨", "bin"],
|
|
747
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"],
|
|
748
760
|
le: ["≤", "rel"],
|
|
749
761
|
leq: ["≤", "rel"],
|
|
750
762
|
ge: ["≥", "rel"],
|
|
@@ -789,7 +801,7 @@ const ee = {
|
|
|
789
801
|
rangle: ["⟩", "close"],
|
|
790
802
|
lbrace: ["{", "open"],
|
|
791
803
|
rbrace: ["}", "close"]
|
|
792
|
-
},
|
|
804
|
+
}, Me = { sum: ["∑", !0], prod: ["∏", !0], int: ["∫", !1], oint: ["∮", !1] }, xe = {
|
|
793
805
|
sin: !1,
|
|
794
806
|
cos: !1,
|
|
795
807
|
tan: !1,
|
|
@@ -799,6 +811,21 @@ const ee = {
|
|
|
799
811
|
det: !1,
|
|
800
812
|
tr: !1,
|
|
801
813
|
rank: !1,
|
|
814
|
+
sinh: !1,
|
|
815
|
+
cosh: !1,
|
|
816
|
+
tanh: !1,
|
|
817
|
+
sec: !1,
|
|
818
|
+
csc: !1,
|
|
819
|
+
cot: !1,
|
|
820
|
+
arcsin: !1,
|
|
821
|
+
arccos: !1,
|
|
822
|
+
arctan: !1,
|
|
823
|
+
gcd: !1,
|
|
824
|
+
lcm: !1,
|
|
825
|
+
deg: !1,
|
|
826
|
+
dim: !1,
|
|
827
|
+
ker: !1,
|
|
828
|
+
softmax: !1,
|
|
802
829
|
lim: !0,
|
|
803
830
|
max: !0,
|
|
804
831
|
min: !0,
|
|
@@ -810,8 +837,8 @@ const ee = {
|
|
|
810
837
|
Pr: !1,
|
|
811
838
|
E: !1,
|
|
812
839
|
Var: !1
|
|
813
|
-
},
|
|
814
|
-
class
|
|
840
|
+
}, Se = { ",": 3 / 18, ":": 4 / 18, ";": 5 / 18, "!": -3 / 18, quad: 1, qquad: 2 }, Ye = /* @__PURE__ */ new Set(["pmatrix", "bmatrix", "vmatrix", "matrix"]);
|
|
841
|
+
class hi extends Error {
|
|
815
842
|
source;
|
|
816
843
|
/** 0-based index into the source */
|
|
817
844
|
position;
|
|
@@ -819,13 +846,14 @@ class On extends Error {
|
|
|
819
846
|
super(`${e} at ${i + 1} in "${n}"`), this.name = "TexError", this.source = n, this.position = i;
|
|
820
847
|
}
|
|
821
848
|
}
|
|
822
|
-
const
|
|
823
|
-
...Object.keys(
|
|
824
|
-
...Object.keys(
|
|
825
|
-
...Object.keys(
|
|
826
|
-
...Object.keys(
|
|
827
|
-
...Object.keys(
|
|
849
|
+
const pi = [
|
|
850
|
+
...Object.keys(ke),
|
|
851
|
+
...Object.keys($e),
|
|
852
|
+
...Object.keys(Me),
|
|
853
|
+
...Object.keys(xe),
|
|
854
|
+
...Object.keys(Se).filter((t) => t.length > 1),
|
|
828
855
|
"frac",
|
|
856
|
+
"binom",
|
|
829
857
|
"sqrt",
|
|
830
858
|
"vec",
|
|
831
859
|
"hat",
|
|
@@ -839,13 +867,13 @@ const Pn = [
|
|
|
839
867
|
"left",
|
|
840
868
|
"right"
|
|
841
869
|
].sort();
|
|
842
|
-
function
|
|
870
|
+
function fi(t) {
|
|
843
871
|
if (typeof t != "string") throw new TypeError("parseTex: expected a string");
|
|
844
872
|
let e = 0;
|
|
845
873
|
const n = () => {
|
|
846
874
|
for (; e < t.length && /\s/.test(t[e]); ) e++;
|
|
847
875
|
}, i = (u, p = e) => {
|
|
848
|
-
throw new
|
|
876
|
+
throw new hi(u, t, p);
|
|
849
877
|
}, s = () => {
|
|
850
878
|
const u = e;
|
|
851
879
|
if (/[A-Za-z]/.test(t[e] ?? ""))
|
|
@@ -858,7 +886,7 @@ function Nn(t) {
|
|
|
858
886
|
p < 0 && i(`Missing "}" for ${u}`);
|
|
859
887
|
const h = t.slice(e + 1, p);
|
|
860
888
|
return e = p + 1, h;
|
|
861
|
-
},
|
|
889
|
+
}, a = (u) => {
|
|
862
890
|
if (n(), e >= t.length && i(`Missing ${u}`), t[e] === "{") {
|
|
863
891
|
e++;
|
|
864
892
|
const h = l("}");
|
|
@@ -873,17 +901,17 @@ function Nn(t) {
|
|
|
873
901
|
return u === "}" && i('Missing "}"'), u === "cell" && i("Missing \\end"), p;
|
|
874
902
|
if (u === "}" && t[e] === "}" || (t[e] === "}" && i('Unexpected "}"'), u === "cell" && (t[e] === "&" || t.startsWith("\\\\", e) || t.startsWith("\\end", e)))) return p;
|
|
875
903
|
if (t[e] === "^" || t[e] === "_") {
|
|
876
|
-
const
|
|
904
|
+
const y = e, f = t[e] === "^";
|
|
877
905
|
e++;
|
|
878
|
-
const
|
|
879
|
-
let
|
|
880
|
-
|
|
906
|
+
const g = a(f ? "superscript" : "subscript");
|
|
907
|
+
let o = p.pop() ?? { type: "group", body: [] };
|
|
908
|
+
o.type !== "scripts" && (o = { type: "scripts", base: o }), o.type === "scripts" && ((f && o.sup || !f && o.sub) && i(`Double ${f ? "superscript" : "subscript"}`, y), f ? o.sup = g : o.sub = g), p.push(o);
|
|
881
909
|
continue;
|
|
882
910
|
}
|
|
883
911
|
if (t[e] === "'") {
|
|
884
912
|
e++;
|
|
885
|
-
const
|
|
886
|
-
p.push(f.type === "scripts" && !f.sup ? { ...f, sup:
|
|
913
|
+
const y = { type: "symbol", text: "′", cls: "ord", italic: !1 }, f = p.pop() ?? { type: "group", body: [] };
|
|
914
|
+
p.push(f.type === "scripts" && !f.sup ? { ...f, sup: y } : { type: "scripts", base: f, sup: y });
|
|
887
915
|
continue;
|
|
888
916
|
}
|
|
889
917
|
const h = c();
|
|
@@ -900,111 +928,118 @@ function Nn(t) {
|
|
|
900
928
|
const p = e;
|
|
901
929
|
e++;
|
|
902
930
|
const h = s();
|
|
903
|
-
if (h === "\\" && i('"\\\\" outside a matrix', p), h in
|
|
931
|
+
if (h === "\\" && i('"\\\\" outside a matrix', p), h in Se) return { type: "space", width: Se[h] };
|
|
904
932
|
if (h === "{" || h === "}") return { type: "symbol", text: h, cls: h === "{" ? "open" : "close", italic: !1 };
|
|
905
933
|
if (h === "|") return { type: "symbol", text: "‖", cls: "ord", italic: !1 };
|
|
906
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
907
|
-
return { type: "symbol", text:
|
|
908
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
909
|
-
const [f,
|
|
910
|
-
return { type: "symbol", text: f, cls:
|
|
934
|
+
if (Object.prototype.hasOwnProperty.call(ke, h))
|
|
935
|
+
return { type: "symbol", text: ke[h], cls: "ord", italic: h[0] === h[0].toLowerCase() };
|
|
936
|
+
if (Object.prototype.hasOwnProperty.call($e, h)) {
|
|
937
|
+
const [f, g] = $e[h];
|
|
938
|
+
return { type: "symbol", text: f, cls: g, italic: !1 };
|
|
911
939
|
}
|
|
912
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
913
|
-
const [f,
|
|
914
|
-
return { type: "bigop", text: f, limits:
|
|
940
|
+
if (Object.prototype.hasOwnProperty.call(Me, h)) {
|
|
941
|
+
const [f, g] = Me[h];
|
|
942
|
+
return { type: "bigop", text: f, limits: g };
|
|
915
943
|
}
|
|
916
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
944
|
+
if (Object.prototype.hasOwnProperty.call(xe, h)) return { type: "opname", text: h, limits: xe[h] };
|
|
917
945
|
switch (h) {
|
|
918
946
|
case "frac":
|
|
919
|
-
return { type: "frac", num:
|
|
947
|
+
return { type: "frac", num: a("numerator"), den: a("denominator") };
|
|
948
|
+
case "binom": {
|
|
949
|
+
const f = a("\\binom's top"), g = a("\\binom's bottom");
|
|
950
|
+
return {
|
|
951
|
+
type: "group",
|
|
952
|
+
body: [{ type: "symbol", text: "(", cls: "open", italic: !1 }, { type: "frac", num: f, den: g, bar: !1 }, { type: "symbol", text: ")", cls: "close", italic: !1 }]
|
|
953
|
+
};
|
|
954
|
+
}
|
|
920
955
|
case "sqrt":
|
|
921
|
-
return { type: "sqrt", body:
|
|
956
|
+
return { type: "sqrt", body: a("the square root's body") };
|
|
922
957
|
case "vec":
|
|
923
958
|
case "hat":
|
|
924
959
|
case "bar":
|
|
925
|
-
return { type: "accent", accent: h, body:
|
|
960
|
+
return { type: "accent", accent: h, body: a(`\\${h}'s body`) };
|
|
926
961
|
case "text":
|
|
927
962
|
return { type: "text", text: r("\\text") };
|
|
928
963
|
case "color": {
|
|
929
964
|
const f = r("\\color").trim();
|
|
930
|
-
return /^(#[0-9a-fA-F]{3,8}|[a-zA-Z]+)$/.test(f) || i(`"${f}" is not a colour name or #hex`, p), { type: "color", color: f, body:
|
|
965
|
+
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: a("\\color's body") };
|
|
931
966
|
}
|
|
932
967
|
case "id": {
|
|
933
968
|
const f = r("\\id").trim();
|
|
934
|
-
return /^[\w.-]+$/.test(f) || i(`"${f}" is not a term id (letters, digits, _ . -)`, p), { type: "id", id: f, body:
|
|
969
|
+
return /^[\w.-]+$/.test(f) || i(`"${f}" is not a term id (letters, digits, _ . -)`, p), { type: "id", id: f, body: a("\\id's body") };
|
|
935
970
|
}
|
|
936
971
|
case "val": {
|
|
937
|
-
const f = r("\\val").trim(),
|
|
938
|
-
return
|
|
972
|
+
const f = r("\\val").trim(), g = /^([A-Za-z_][\w.]*)(?::(\d))?$/.exec(f);
|
|
973
|
+
return g || i(`"${f}" is not a value name (name or name:digits)`, p), { type: "value", name: g[1], digits: g[2] === void 0 ? 2 : Number(g[2]) };
|
|
939
974
|
}
|
|
940
975
|
case "left":
|
|
941
976
|
case "right": {
|
|
942
977
|
n();
|
|
943
978
|
const f = t[e] === "\\" ? (e++, s()) : t[e++];
|
|
944
979
|
if (f === ".") return { type: "space", width: 0 };
|
|
945
|
-
const
|
|
946
|
-
return
|
|
980
|
+
const o = { "(": "(", ")": ")", "[": "[", "]": "]", "|": "|", "{": "{", "}": "}", langle: "⟨", rangle: "⟩", "|.": "‖" }[f];
|
|
981
|
+
return o || i(`"${f}" is not a delimiter`, p), { type: "symbol", text: o, cls: h === "left" ? "open" : "close", italic: !1 };
|
|
947
982
|
}
|
|
948
983
|
case "begin": {
|
|
949
984
|
const f = r("\\begin").trim();
|
|
950
|
-
|
|
951
|
-
const
|
|
985
|
+
Ye.has(f) || i(`Unknown environment "${f}" (use ${[...Ye].join(", ")})`, p);
|
|
986
|
+
const g = [[]];
|
|
952
987
|
for (; ; ) {
|
|
953
|
-
const
|
|
954
|
-
if (
|
|
988
|
+
const o = l("cell");
|
|
989
|
+
if (g[g.length - 1].push({ type: "group", body: o }), t[e] === "&")
|
|
955
990
|
e++;
|
|
956
991
|
else if (t.startsWith("\\\\", e))
|
|
957
|
-
e += 2,
|
|
992
|
+
e += 2, g.push([]);
|
|
958
993
|
else {
|
|
959
994
|
e += 4;
|
|
960
|
-
const
|
|
961
|
-
|
|
995
|
+
const m = r("\\end").trim();
|
|
996
|
+
m !== f && i(`\\begin{${f}} ended by \\end{${m}}`);
|
|
962
997
|
break;
|
|
963
998
|
}
|
|
964
999
|
}
|
|
965
|
-
return
|
|
1000
|
+
return g.length > 1 && g[g.length - 1].every((o) => o.type === "group" && o.body.length === 0) && g.pop(), { type: "matrix", delimiters: f, rows: g };
|
|
966
1001
|
}
|
|
967
1002
|
case "end":
|
|
968
1003
|
return i("\\end without \\begin", p);
|
|
969
1004
|
}
|
|
970
|
-
const
|
|
971
|
-
return i(`Unknown command "\\${h}"${
|
|
1005
|
+
const y = Gn(h, pi);
|
|
1006
|
+
return i(`Unknown command "\\${h}"${y ? ` (did you mean "\\${y}"?)` : ""}`, p);
|
|
972
1007
|
}
|
|
973
1008
|
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);
|
|
974
1009
|
};
|
|
975
1010
|
return { type: "group", body: l("") };
|
|
976
1011
|
}
|
|
977
|
-
const
|
|
978
|
-
function
|
|
1012
|
+
const at = [1, 1, 0.7, 0.5], yi = (t) => t <= 1 ? 2 : 3, mi = (t) => Math.min(3, t + 1), Ie = () => ({ width: 0, height: 0, depth: 0, pieces: [] });
|
|
1013
|
+
function rt(t, e, n) {
|
|
979
1014
|
return t.pieces.map((i) => i.kind === "stroke" ? { ...i, points: i.points.map(([s, r]) => [s + e, r + n]) } : { ...i, x: i.x + e, y: i.y + n });
|
|
980
1015
|
}
|
|
981
|
-
function
|
|
1016
|
+
function Mt(t, e) {
|
|
982
1017
|
if (t.id) return t.id;
|
|
983
1018
|
const n = (t.counts.get(e) ?? 0) + 1;
|
|
984
1019
|
return t.counts.set(e, n), `${e}#${n}`;
|
|
985
1020
|
}
|
|
986
|
-
function
|
|
987
|
-
const r =
|
|
1021
|
+
function Ze(t, e, n, i = 1, s = t) {
|
|
1022
|
+
const r = at[n.level] * i, a = we(t) * r, { height: l, depth: c } = vn(t);
|
|
988
1023
|
return {
|
|
989
|
-
width:
|
|
1024
|
+
width: a,
|
|
990
1025
|
height: l * r,
|
|
991
1026
|
depth: c * r,
|
|
992
|
-
pieces: [{ kind: "glyph", text: t, x: 0, y: 0, width:
|
|
1027
|
+
pieces: [{ kind: "glyph", text: t, x: 0, y: 0, width: a, size: r, italic: e, ...n.color ? { color: n.color } : {}, id: Mt(n, s) }]
|
|
993
1028
|
};
|
|
994
1029
|
}
|
|
995
|
-
function
|
|
996
|
-
const i =
|
|
997
|
-
for (const
|
|
998
|
-
const l = (
|
|
999
|
-
if (
|
|
1000
|
-
const { height: c, depth: d } =
|
|
1001
|
-
i.pieces.push({ kind: "glyph", text:
|
|
1030
|
+
function ye(t, e, n) {
|
|
1031
|
+
const i = Ie(), s = Mt(e, n), r = at[e.level];
|
|
1032
|
+
for (const a of t) {
|
|
1033
|
+
const l = (a === " " ? 0.28 : /[A-Za-z]/.test(a) ? we(a) - 0.04 : we(a)) * r;
|
|
1034
|
+
if (a !== " ") {
|
|
1035
|
+
const { height: c, depth: d } = vn(a);
|
|
1036
|
+
i.pieces.push({ kind: "glyph", text: a, x: i.width, y: 0, width: l, size: r, italic: !1, ...e.color ? { color: e.color } : {}, id: s }), i.height = Math.max(i.height, c * r), i.depth = Math.max(i.depth, d * r);
|
|
1002
1037
|
}
|
|
1003
1038
|
i.width += l;
|
|
1004
1039
|
}
|
|
1005
1040
|
return i;
|
|
1006
1041
|
}
|
|
1007
|
-
function
|
|
1042
|
+
function Ae(t) {
|
|
1008
1043
|
switch (t.type) {
|
|
1009
1044
|
case "symbol":
|
|
1010
1045
|
return t.cls;
|
|
@@ -1012,211 +1047,211 @@ function oe(t) {
|
|
|
1012
1047
|
case "opname":
|
|
1013
1048
|
return "op";
|
|
1014
1049
|
case "scripts":
|
|
1015
|
-
return
|
|
1050
|
+
return Ae(t.base);
|
|
1016
1051
|
case "id":
|
|
1017
1052
|
case "color":
|
|
1018
|
-
return
|
|
1053
|
+
return Ae(t.body);
|
|
1019
1054
|
default:
|
|
1020
1055
|
return "ord";
|
|
1021
1056
|
}
|
|
1022
1057
|
}
|
|
1023
|
-
function
|
|
1058
|
+
function gi(t, e) {
|
|
1024
1059
|
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;
|
|
1025
1060
|
}
|
|
1026
|
-
function
|
|
1027
|
-
const n =
|
|
1061
|
+
function bi(t, e) {
|
|
1062
|
+
const n = Ie();
|
|
1028
1063
|
let i;
|
|
1029
1064
|
return t.forEach((s) => {
|
|
1030
1065
|
if (s.type === "space") {
|
|
1031
|
-
n.width += s.width *
|
|
1066
|
+
n.width += s.width * at[e.level];
|
|
1032
1067
|
return;
|
|
1033
1068
|
}
|
|
1034
|
-
let r =
|
|
1035
|
-
r === "bin" && (i === void 0 || i === "bin" || i === "rel" || i === "open" || i === "punct" || i === "op") && (r = "ord"), i !== void 0 && e.level <= 1 && (n.width +=
|
|
1036
|
-
const
|
|
1037
|
-
n.pieces.push(...
|
|
1069
|
+
let r = Ae(s);
|
|
1070
|
+
r === "bin" && (i === void 0 || i === "bin" || i === "rel" || i === "open" || i === "punct" || i === "op") && (r = "ord"), i !== void 0 && e.level <= 1 && (n.width += gi(i, r) / 18 * at[e.level]);
|
|
1071
|
+
const a = J(s, e);
|
|
1072
|
+
n.pieces.push(...rt(a, n.width, 0)), n.width += a.width, n.height = Math.max(n.height, a.height), n.depth = Math.max(n.depth, a.depth), i = r;
|
|
1038
1073
|
}), n;
|
|
1039
1074
|
}
|
|
1040
|
-
function
|
|
1075
|
+
function vi(t, e) {
|
|
1041
1076
|
if (!Number.isFinite(t)) return t > 0 ? "∞" : t < 0 ? "−∞" : "?";
|
|
1042
1077
|
const n = t.toFixed(e), i = n.includes(".") ? n.replace(/\.?0+$/, "") : n;
|
|
1043
1078
|
return (i === "-0" ? "0" : i).replace("-", "−");
|
|
1044
1079
|
}
|
|
1045
|
-
function
|
|
1046
|
-
const n =
|
|
1080
|
+
function J(t, e) {
|
|
1081
|
+
const n = at[e.level];
|
|
1047
1082
|
switch (t.type) {
|
|
1048
1083
|
case "symbol":
|
|
1049
|
-
return
|
|
1084
|
+
return Ze(t.text, t.italic, e);
|
|
1050
1085
|
case "group":
|
|
1051
|
-
return
|
|
1086
|
+
return bi(t.body, e);
|
|
1052
1087
|
case "space":
|
|
1053
|
-
return { ...
|
|
1088
|
+
return { ...Ie(), width: t.width * n };
|
|
1054
1089
|
case "text":
|
|
1055
|
-
return
|
|
1090
|
+
return ye(t.text, e, `text:${t.text}`);
|
|
1056
1091
|
case "opname":
|
|
1057
|
-
return
|
|
1092
|
+
return ye(t.text, e, t.text);
|
|
1058
1093
|
case "value": {
|
|
1059
1094
|
const i = e.values[t.name];
|
|
1060
1095
|
if (i === void 0) throw new Error(`\\val{${t.name}}: no value named "${t.name}"`);
|
|
1061
|
-
return
|
|
1096
|
+
return ye(vi(i, t.digits), { ...e, id: e.id ?? `val:${t.name}` }, `val:${t.name}`);
|
|
1062
1097
|
}
|
|
1063
1098
|
case "bigop":
|
|
1064
|
-
return
|
|
1099
|
+
return Ze(t.text, !1, e, e.level === 0 ? 1.4 : 1.1);
|
|
1065
1100
|
case "color":
|
|
1066
|
-
return
|
|
1101
|
+
return J(t.body, { ...e, color: t.color });
|
|
1067
1102
|
case "id":
|
|
1068
|
-
return
|
|
1103
|
+
return J(t.body, { ...e, id: t.id });
|
|
1069
1104
|
case "scripts":
|
|
1070
|
-
return
|
|
1105
|
+
return wi(t, e);
|
|
1071
1106
|
case "frac":
|
|
1072
|
-
return
|
|
1107
|
+
return ki(t, e);
|
|
1073
1108
|
case "sqrt":
|
|
1074
|
-
return
|
|
1109
|
+
return $i(t, e);
|
|
1075
1110
|
case "accent":
|
|
1076
|
-
return
|
|
1111
|
+
return Mi(t, e);
|
|
1077
1112
|
case "matrix":
|
|
1078
|
-
return
|
|
1113
|
+
return xi(t, e);
|
|
1079
1114
|
}
|
|
1080
1115
|
}
|
|
1081
|
-
function
|
|
1082
|
-
const n =
|
|
1116
|
+
function wi(t, e) {
|
|
1117
|
+
const n = J(t.base, e), i = { ...e, level: yi(e.level) }, s = t.sup ? J(t.sup, i) : void 0, r = t.sub ? J(t.sub, i) : void 0, a = at[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] };
|
|
1083
1118
|
if (l) {
|
|
1084
|
-
const
|
|
1085
|
-
let
|
|
1086
|
-
const
|
|
1119
|
+
const y = Math.max(n.width, s?.width ?? 0, r?.width ?? 0), f = rt(n, (y - n.width) / 2, 0);
|
|
1120
|
+
let g = n.height, o = n.depth;
|
|
1121
|
+
const m = 0.12 * a;
|
|
1087
1122
|
if (s) {
|
|
1088
|
-
const
|
|
1089
|
-
f.push(...
|
|
1123
|
+
const v = -(n.height + m + s.depth);
|
|
1124
|
+
f.push(...rt(s, (y - s.width) / 2, v)), g = -v + s.height;
|
|
1090
1125
|
}
|
|
1091
1126
|
if (r) {
|
|
1092
|
-
const
|
|
1093
|
-
f.push(...
|
|
1127
|
+
const v = n.depth + m + r.height;
|
|
1128
|
+
f.push(...rt(r, (y - r.width) / 2, v)), o = v + r.depth;
|
|
1094
1129
|
}
|
|
1095
|
-
return { width:
|
|
1130
|
+
return { width: y, height: g, depth: o, pieces: f };
|
|
1096
1131
|
}
|
|
1097
|
-
let d = s ? Math.max(0.42 *
|
|
1132
|
+
let d = s ? Math.max(0.42 * a, n.height - 0.3 * a, s.depth + 0.25 * a) : 0, u = r ? Math.max(0.2 * a, n.depth + 0.12 * a, r.height - 0.4 * a) : 0;
|
|
1098
1133
|
if (s && r) {
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1134
|
+
const y = d - s.depth - (r.height - u);
|
|
1135
|
+
y < 0.2 * a && (u += 0.2 * a - y);
|
|
1101
1136
|
}
|
|
1102
|
-
const p = n.width + 0.03 *
|
|
1137
|
+
const p = n.width + 0.03 * a;
|
|
1103
1138
|
let h = n.width;
|
|
1104
|
-
return s ? (c.pieces.push(...
|
|
1139
|
+
return s ? (c.pieces.push(...rt(s, p, -d)), c.height = Math.max(c.height, d + s.height), h = Math.max(h, p + s.width)) : d = 0, r && (c.pieces.push(...rt(r, p, u)), c.depth = Math.max(c.depth, u + r.depth), h = Math.max(h, p + r.width)), c.width = h + 0.04 * a, c;
|
|
1105
1140
|
}
|
|
1106
|
-
function
|
|
1107
|
-
const n = { ...e, level:
|
|
1141
|
+
function ki(t, e) {
|
|
1142
|
+
const n = { ...e, level: mi(e.level) }, i = J(t.num, n), s = J(t.den, n), r = at[e.level], a = Pt * r, l = bn * r, c = (e.level === 0 ? 0.16 : 0.1) * r, d = 0.1 * r, u = Math.max(i.width, s.width) + d * 2, p = -(l + a / 2 + c + i.depth), h = -l + a / 2 + c + s.height;
|
|
1108
1143
|
return {
|
|
1109
1144
|
width: u,
|
|
1110
1145
|
height: -p + i.height,
|
|
1111
1146
|
depth: h + s.depth,
|
|
1112
1147
|
pieces: [
|
|
1113
|
-
...
|
|
1114
|
-
{ kind: "rule", x: 0, y: -l -
|
|
1115
|
-
...
|
|
1148
|
+
...rt(i, (u - i.width) / 2, p),
|
|
1149
|
+
...t.bar === !1 ? [] : [{ kind: "rule", x: 0, y: -l - a / 2, width: u, height: a, ...e.color ? { color: e.color } : {}, id: Mt(e, "frac") }],
|
|
1150
|
+
...rt(s, (u - s.width) / 2, h)
|
|
1116
1151
|
]
|
|
1117
1152
|
};
|
|
1118
1153
|
}
|
|
1119
|
-
function
|
|
1120
|
-
const n =
|
|
1154
|
+
function $i(t, e) {
|
|
1155
|
+
const n = J(t.body, e), i = at[e.level], s = Math.max(n.height, 0.7 * i) + 0.14 * i, r = Math.max(n.depth, 0.05 * i) + 0.05 * i, a = 0.56 * i, l = a + n.width + 0.08 * i, c = [
|
|
1121
1156
|
[0.02 * i, -0.36 * i],
|
|
1122
1157
|
[0.13 * i, -0.44 * i],
|
|
1123
1158
|
[0.3 * i, r],
|
|
1124
|
-
[
|
|
1159
|
+
[a - 0.04 * i, -s],
|
|
1125
1160
|
[l, -s]
|
|
1126
1161
|
];
|
|
1127
1162
|
return {
|
|
1128
1163
|
width: l,
|
|
1129
|
-
height: s +
|
|
1164
|
+
height: s + Pt * i,
|
|
1130
1165
|
depth: r,
|
|
1131
|
-
pieces: [{ kind: "stroke", points: c, width:
|
|
1166
|
+
pieces: [{ kind: "stroke", points: c, width: Pt * i, ...e.color ? { color: e.color } : {}, id: Mt(e, "sqrt") }, ...rt(n, a, 0)]
|
|
1132
1167
|
};
|
|
1133
1168
|
}
|
|
1134
|
-
function
|
|
1135
|
-
const n =
|
|
1169
|
+
function Mi(t, e) {
|
|
1170
|
+
const n = J(t.body, e), i = at[e.level], s = -(n.height + 0.12 * i), r = 0.04 * i, a = Math.max(n.width - 0.02 * i, r + 0.3 * i), l = e.color ? { color: e.color } : {}, c = Mt(e, t.accent);
|
|
1136
1171
|
let d;
|
|
1137
1172
|
if (t.accent === "vec") {
|
|
1138
1173
|
const u = 0.12 * i;
|
|
1139
|
-
d = [[[r, s], [
|
|
1174
|
+
d = [[[r, s], [a, s]], [[a - u, s - u * 0.7], [a, s], [a - u, s + u * 0.7]]];
|
|
1140
1175
|
} else if (t.accent === "hat") {
|
|
1141
|
-
const u = (r +
|
|
1176
|
+
const u = (r + a) / 2;
|
|
1142
1177
|
d = [[[u - 0.16 * i, s + 0.02 * i], [u, s - 0.12 * i], [u + 0.16 * i, s + 0.02 * i]]];
|
|
1143
1178
|
} else
|
|
1144
|
-
d = [[[r, s], [
|
|
1179
|
+
d = [[[r, s], [a, s]]];
|
|
1145
1180
|
return {
|
|
1146
|
-
width: Math.max(n.width,
|
|
1181
|
+
width: Math.max(n.width, a + 0.02 * i),
|
|
1147
1182
|
height: -s + 0.14 * i,
|
|
1148
1183
|
depth: n.depth,
|
|
1149
|
-
pieces: [...n.pieces, ...d.map((u) => ({ kind: "stroke", points: u, width:
|
|
1184
|
+
pieces: [...n.pieces, ...d.map((u) => ({ kind: "stroke", points: u, width: Pt * i * 0.9, ...l, id: c }))]
|
|
1150
1185
|
};
|
|
1151
1186
|
}
|
|
1152
|
-
function
|
|
1153
|
-
const n = { ...e, level: Math.max(e.level, 1) }, i =
|
|
1154
|
-
let
|
|
1155
|
-
s.forEach((k,
|
|
1156
|
-
|
|
1157
|
-
let
|
|
1158
|
-
k.forEach((
|
|
1159
|
-
|
|
1160
|
-
}),
|
|
1187
|
+
function xi(t, e) {
|
|
1188
|
+
const n = { ...e, level: Math.max(e.level, 1) }, i = at[n.level], s = t.rows.map((k) => k.map((M) => J(M, n))), r = Math.max(...s.map((k) => k.length)), a = Array.from({ length: r }, (k, M) => Math.max(0, ...s.map(($) => $[M]?.width ?? 0))), l = s.map((k) => Math.max(0.7 * i, ...k.map((M) => M.height))), c = s.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 = a.reduce((k, M) => k + M, 0) + d * (r - 1), y = l.reduce((k, M, $) => k + M + c[$], 0) + u * (s.length - 1), f = -bn * i - y / 2, g = [];
|
|
1189
|
+
let o = f;
|
|
1190
|
+
s.forEach((k, M) => {
|
|
1191
|
+
o += l[M];
|
|
1192
|
+
let $ = p;
|
|
1193
|
+
k.forEach((S, A) => {
|
|
1194
|
+
g.push(...rt(S, $ + (a[A] - S.width) / 2, o)), $ += a[A] + d;
|
|
1195
|
+
}), o += c[M] + u;
|
|
1161
1196
|
});
|
|
1162
|
-
const
|
|
1197
|
+
const m = h + p * 2, v = f + y, x = e.color ? { color: e.color } : {}, w = (k, M) => ({ kind: "stroke", points: k, width: Pt * i * 1.1, ...x, id: Mt(e, M) }), b = 0.08 * i;
|
|
1163
1198
|
if (t.delimiters === "pmatrix") {
|
|
1164
|
-
const k = (
|
|
1165
|
-
const
|
|
1166
|
-
return Array.from({ length: 17 }, (
|
|
1167
|
-
const
|
|
1168
|
-
return [
|
|
1199
|
+
const k = (M) => {
|
|
1200
|
+
const $ = M === 1 ? p * 0.75 : m - p * 0.75, S = M * p * 0.5;
|
|
1201
|
+
return Array.from({ length: 17 }, (A, P) => {
|
|
1202
|
+
const N = P / 16;
|
|
1203
|
+
return [$ - S * Math.sin(Math.PI * N), f - b + (y + b * 2) * N];
|
|
1169
1204
|
});
|
|
1170
1205
|
};
|
|
1171
|
-
|
|
1206
|
+
g.push(w(k(1), "("), w(k(-1), ")"));
|
|
1172
1207
|
} else if (t.delimiters === "bmatrix") {
|
|
1173
|
-
const k = p * 0.35,
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1208
|
+
const k = p * 0.35, M = p * 0.2, $ = m - p * 0.2;
|
|
1209
|
+
g.push(
|
|
1210
|
+
w([[M + k, f - b], [M, f - b], [M, v + b], [M + k, v + b]], "["),
|
|
1211
|
+
w([[$ - k, f - b], [$, f - b], [$, v + b], [$ - k, v + b]], "]")
|
|
1177
1212
|
);
|
|
1178
|
-
} else t.delimiters === "vmatrix" &&
|
|
1179
|
-
return { width:
|
|
1213
|
+
} else t.delimiters === "vmatrix" && g.push(w([[p * 0.4, f - b], [p * 0.4, v + b]], "|"), w([[m - p * 0.4, f - b], [m - p * 0.4, v + b]], "|"));
|
|
1214
|
+
return { width: m, height: -f + b, depth: v + b, pieces: g };
|
|
1180
1215
|
}
|
|
1181
|
-
function
|
|
1182
|
-
const n = typeof t == "string" ?
|
|
1216
|
+
function H(t, e = {}) {
|
|
1217
|
+
const n = typeof t == "string" ? fi(t) : t, i = { level: e.style === "inline" ? 1 : 0, values: e.values ?? {}, counts: /* @__PURE__ */ new Map() }, s = J(n, i);
|
|
1183
1218
|
return { width: s.width, height: s.height, depth: s.depth, pieces: s.pieces };
|
|
1184
1219
|
}
|
|
1185
|
-
const
|
|
1186
|
-
function
|
|
1220
|
+
const ht = 'system-ui, -apple-system, "Segoe UI", sans-serif', Je = (t, e) => Math.hypot(e[0] - t[0], e[1] - t[1]);
|
|
1221
|
+
function _(t, e) {
|
|
1187
1222
|
if (e >= 1) return t;
|
|
1188
1223
|
if (e <= 0) return [];
|
|
1189
|
-
const n = t.map((r) => r.slice(1).reduce((
|
|
1190
|
-
let i = n.reduce((r,
|
|
1224
|
+
const n = t.map((r) => r.slice(1).reduce((a, l, c) => a + Je(r[c], l), 0));
|
|
1225
|
+
let i = n.reduce((r, a) => r + a, 0) * e;
|
|
1191
1226
|
const s = [];
|
|
1192
|
-
for (const [r,
|
|
1227
|
+
for (const [r, a] of t.entries()) {
|
|
1193
1228
|
if (i <= 0) break;
|
|
1194
1229
|
if (n[r] <= i) {
|
|
1195
|
-
s.push(
|
|
1230
|
+
s.push(a), i -= n[r];
|
|
1196
1231
|
continue;
|
|
1197
1232
|
}
|
|
1198
|
-
const l = [
|
|
1199
|
-
for (let c = 1; c <
|
|
1200
|
-
const d =
|
|
1233
|
+
const l = [a[0]];
|
|
1234
|
+
for (let c = 1; c < a.length; c++) {
|
|
1235
|
+
const d = Je(a[c - 1], a[c]);
|
|
1201
1236
|
if (d >= i) {
|
|
1202
1237
|
const u = d === 0 ? 0 : i / d;
|
|
1203
|
-
l.push([
|
|
1238
|
+
l.push([a[c - 1][0] + (a[c][0] - a[c - 1][0]) * u, a[c - 1][1] + (a[c][1] - a[c - 1][1]) * u]);
|
|
1204
1239
|
break;
|
|
1205
1240
|
}
|
|
1206
|
-
l.push(
|
|
1241
|
+
l.push(a[c]), i -= d;
|
|
1207
1242
|
}
|
|
1208
1243
|
s.push(l), i = 0;
|
|
1209
1244
|
}
|
|
1210
1245
|
return s;
|
|
1211
1246
|
}
|
|
1212
|
-
function
|
|
1247
|
+
function Fe(t, e) {
|
|
1213
1248
|
const n = e.align ?? "center", i = n === "left" ? 0 : n === "right" ? -t.width : -t.width / 2, s = e.baseline === "baseline" ? 0 : (t.height - t.depth) / 2;
|
|
1214
1249
|
return [e.x + i * e.size, e.y + s * e.size];
|
|
1215
1250
|
}
|
|
1216
|
-
function
|
|
1217
|
-
const [i, s] = e, r = n.size,
|
|
1251
|
+
function wn(t, e, n) {
|
|
1252
|
+
const [i, s] = e, r = n.size, a = n.opacity ?? 1;
|
|
1218
1253
|
return t.map((l) => {
|
|
1219
|
-
const c = l.color ?? n.color, d =
|
|
1254
|
+
const c = (l.color && n.palette?.[l.color]) ?? l.color ?? n.color, d = a * (l.opacity ?? 1), u = `${n.idPrefix}${l.id}`;
|
|
1220
1255
|
if (l.kind === "glyph")
|
|
1221
1256
|
return {
|
|
1222
1257
|
type: "text",
|
|
@@ -1225,237 +1260,822 @@ function Ke(t, e, n) {
|
|
|
1225
1260
|
x: i + (l.x + l.width / 2) * r,
|
|
1226
1261
|
y: s + l.y * r,
|
|
1227
1262
|
size: l.size * r,
|
|
1228
|
-
font:
|
|
1263
|
+
font: di(l.text),
|
|
1229
1264
|
italic: l.italic,
|
|
1230
1265
|
color: c,
|
|
1231
1266
|
align: "center",
|
|
1232
1267
|
opacity: d
|
|
1233
1268
|
};
|
|
1234
1269
|
if (l.kind === "rule") {
|
|
1235
|
-
const p = i + l.x * r, h = s + l.y * r,
|
|
1236
|
-
return { type: "line", id: u, points: [[p, h], [p +
|
|
1270
|
+
const p = i + l.x * r, h = s + l.y * r, y = l.width * r, f = Math.max(1, l.height * r);
|
|
1271
|
+
return { type: "line", id: u, points: [[p, h], [p + y, h], [p + y, h + f], [p, h + f]], closed: !0, fill: c, opacity: d };
|
|
1237
1272
|
}
|
|
1238
1273
|
return { type: "line", id: u, points: l.points.map(([p, h]) => [i + p * r, s + h * r]), stroke: c, width: Math.max(1, l.width * r), opacity: d };
|
|
1239
1274
|
});
|
|
1240
1275
|
}
|
|
1241
|
-
function
|
|
1242
|
-
return
|
|
1276
|
+
function G(t, e) {
|
|
1277
|
+
return wn(t.pieces, Fe(t, e), e);
|
|
1243
1278
|
}
|
|
1244
|
-
const
|
|
1245
|
-
function
|
|
1279
|
+
const te = 480;
|
|
1280
|
+
function kn(t, e) {
|
|
1246
1281
|
const n = [];
|
|
1247
1282
|
let i = [];
|
|
1248
1283
|
return t.forEach((s, r) => {
|
|
1249
|
-
const
|
|
1250
|
-
(!s ||
|
|
1284
|
+
const a = t[r - 1];
|
|
1285
|
+
(!s || a && Math.abs(s[1] - a[1]) > e * 1.5) && (i.length >= 2 && n.push(i), i = []), s && i.push(s);
|
|
1251
1286
|
}), i.length >= 2 && n.push(i), n;
|
|
1252
1287
|
}
|
|
1253
|
-
function
|
|
1288
|
+
function $n(t, e) {
|
|
1254
1289
|
const n = Math.max(e.plane.width, e.plane.height) * 20;
|
|
1255
1290
|
if (!(!Number.isFinite(t[0]) || !Number.isFinite(t[1])))
|
|
1256
1291
|
return [Math.max(-n, Math.min(n, t[0])), Math.max(-n, Math.min(n, t[1]))];
|
|
1257
1292
|
}
|
|
1258
|
-
function
|
|
1259
|
-
return
|
|
1293
|
+
function Mn(t, e, n, i, s, r) {
|
|
1294
|
+
return _(e, s.draw).map((a, l) => ({ type: "line", id: `${t}.${l}`, points: a, stroke: n, width: i, opacity: s.opacity, ...r ? { dash: r } : {} }));
|
|
1260
1295
|
}
|
|
1261
|
-
function
|
|
1262
|
-
const c = Array.from({ length:
|
|
1263
|
-
const p = n + (i - n) * u /
|
|
1264
|
-
return
|
|
1296
|
+
function oe(t, e, n, i, s, r, a, l) {
|
|
1297
|
+
const c = Array.from({ length: te + 1 }, (d, u) => {
|
|
1298
|
+
const p = n + (i - n) * u / te;
|
|
1299
|
+
return $n(a.plane.toScreen([p, e(p)]), a);
|
|
1265
1300
|
});
|
|
1266
|
-
return
|
|
1267
|
-
}
|
|
1268
|
-
function
|
|
1269
|
-
const n = t.derivative ?
|
|
1270
|
-
return
|
|
1271
|
-
}
|
|
1272
|
-
function
|
|
1273
|
-
const n =
|
|
1274
|
-
const p = r + (
|
|
1275
|
-
return
|
|
1276
|
-
}), c =
|
|
1277
|
-
return
|
|
1278
|
-
}
|
|
1279
|
-
const
|
|
1280
|
-
function
|
|
1281
|
-
const n =
|
|
1282
|
-
(c, d) => c.height > 0 ? [{ type: "line", id: `${t.id}.${d}`, points:
|
|
1301
|
+
return Mn(t, kn(c, a.plane.height), s, r, a, l);
|
|
1302
|
+
}
|
|
1303
|
+
function Si(t, e) {
|
|
1304
|
+
const n = t.derivative ? Pe(t.expr, t.derivative) : Y(t.expr, "x"), [i, s] = t.domain ?? e.plane.x, r = T(e.theme, t.color, e.theme.colors.blue), a = t.dashed ? [10 * e.plane.scale, 8 * e.plane.scale] : void 0;
|
|
1305
|
+
return oe(t.id, (l) => n(l, e.scope), i, s, r, (t.width ?? 3.5) * e.plane.scale, e, a);
|
|
1306
|
+
}
|
|
1307
|
+
function Ai(t, e) {
|
|
1308
|
+
const n = Y(t.x, "t"), i = Y(t.y, "t"), s = mt(e.values, t.transform), [r, a] = t.t ?? [0, Math.PI * 2], l = Array.from({ length: te + 1 }, (d, u) => {
|
|
1309
|
+
const p = r + (a - r) * u / te;
|
|
1310
|
+
return $n(e.plane.toScreen(tt(s, [n(p, e.scope), i(p, e.scope)])), e);
|
|
1311
|
+
}), c = T(e.theme, t.color, e.theme.colors.blue);
|
|
1312
|
+
return Mn(t.id, kn(l, e.plane.height), c, (t.width ?? 3.5) * e.plane.scale, e);
|
|
1313
|
+
}
|
|
1314
|
+
const Le = (t, e, n, i, s) => [[e, n], [i, n], [i, s], [e, s]].map(t.plane.toScreen), ee = (t) => Math.min(2e4, Math.max(0, Math.floor(t)));
|
|
1315
|
+
function Ei(t, e) {
|
|
1316
|
+
const n = kt(e.values, t.distribution), i = fn(n, t.seed ?? t.id, ee(E(e.values, t.count))), s = ri(i, t.bins ?? We(n), t.scale ?? "density"), r = T(e.theme, t.color, e.theme.colors.blue), a = e.opacity * e.draw, l = s.flatMap(
|
|
1317
|
+
(c, d) => c.height > 0 ? [{ type: "line", id: `${t.id}.${d}`, points: Le(e, c.left, 0, c.right, c.height), closed: !0, fill: r, stroke: e.theme.background, width: 1 * e.plane.scale, opacity: a * (t.fillOpacity ?? 0.75) }] : []
|
|
1283
1318
|
);
|
|
1284
1319
|
if (t.curve && (t.scale ?? "density") === "density") {
|
|
1285
|
-
const [c, d] = t.bins ??
|
|
1286
|
-
l.push(...
|
|
1320
|
+
const [c, d] = t.bins ?? We(n), u = T(e.theme, "yellow", e.theme.colors.yellow);
|
|
1321
|
+
l.push(...oe(`${t.id}.curve`, (p) => ut(re(n) ? { kind: "normal", mean: Ct(n), sd: qt(n) } : n, p), c, d, u, 3 * e.plane.scale, { ...e, draw: 1 }));
|
|
1287
1322
|
}
|
|
1288
1323
|
return l;
|
|
1289
1324
|
}
|
|
1290
|
-
function
|
|
1291
|
-
const n =
|
|
1292
|
-
if (
|
|
1325
|
+
function Ti(t, e) {
|
|
1326
|
+
const n = kt(e.values, t.distribution), i = T(e.theme, t.color, e.theme.colors.blue), [s, r] = t.domain ?? e.plane.x, a = t.shade ? [E(e.values, t.shade[0]), E(e.values, t.shade[1])].sort((d, u) => d - u) : void 0, l = T(e.theme, "yellow", e.theme.colors.yellow);
|
|
1327
|
+
if (re(n)) {
|
|
1293
1328
|
const d = [], u = Math.max(0, Math.ceil(s)), p = Math.floor(r), h = u + Math.ceil((p - u + 1) * e.draw);
|
|
1294
|
-
for (let
|
|
1295
|
-
const f =
|
|
1329
|
+
for (let y = u; y < h && y <= p; y++) {
|
|
1330
|
+
const f = ut(n, y);
|
|
1296
1331
|
if (f <= 0) continue;
|
|
1297
|
-
const
|
|
1298
|
-
d.push({ type: "line", id: `${t.id}.${
|
|
1332
|
+
const g = a && y >= a[0] && y <= a[1];
|
|
1333
|
+
d.push({ type: "line", id: `${t.id}.${y}`, points: Le(e, y - 0.4, 0, y + 0.4, f), closed: !0, fill: g ? l : i, opacity: e.opacity * (t.fillOpacity ?? 0.8) });
|
|
1299
1334
|
}
|
|
1300
1335
|
return d;
|
|
1301
1336
|
}
|
|
1302
1337
|
const c = [];
|
|
1303
|
-
if (
|
|
1304
|
-
const [d, u] = [Math.max(
|
|
1338
|
+
if (a && e.draw >= 1) {
|
|
1339
|
+
const [d, u] = [Math.max(a[0], s), Math.min(a[1], r)];
|
|
1305
1340
|
if (u > d) {
|
|
1306
|
-
const h = Array.from({ length: 121 }, (f,
|
|
1307
|
-
const
|
|
1308
|
-
return [
|
|
1309
|
-
}),
|
|
1310
|
-
c.push({ type: "line", id: `${t.id}.shade`, points:
|
|
1341
|
+
const h = Array.from({ length: 121 }, (f, g) => {
|
|
1342
|
+
const o = d + (u - d) * g / 120;
|
|
1343
|
+
return [o, ut(n, o)];
|
|
1344
|
+
}), y = [[d, 0], ...h, [u, 0]].map(e.plane.toScreen);
|
|
1345
|
+
c.push({ type: "line", id: `${t.id}.shade`, points: y, closed: !0, fill: l, opacity: e.opacity * (t.fillOpacity ?? 0.4) });
|
|
1311
1346
|
}
|
|
1312
1347
|
}
|
|
1313
|
-
return c.push(...
|
|
1348
|
+
return c.push(...oe(t.id, (d) => ut(n, d), s, r, i, (t.width ?? 3.5) * e.plane.scale, e)), c;
|
|
1314
1349
|
}
|
|
1315
|
-
function
|
|
1316
|
-
const n = t.rows ?? 10, i = t.spacing ?? 0.5, s = t.top ?? e.plane.y[1] - i, r = i * 0.9,
|
|
1350
|
+
function Oi(t, e) {
|
|
1351
|
+
const n = t.rows ?? 10, i = t.spacing ?? 0.5, s = t.top ?? e.plane.y[1] - i, r = i * 0.9, a = (b, k) => [b * i, s - k * r], l = T(e.theme, "grey", e.theme.colors.grey), c = T(e.theme, t.color, e.theme.colors.yellow), d = i * 0.19 * e.plane.unitX, u = [];
|
|
1317
1352
|
for (let b = 0; b < n; b++)
|
|
1318
1353
|
for (let k = 0; k <= b; k++) {
|
|
1319
|
-
const [
|
|
1320
|
-
u.push({ type: "circle", id: `${t.id}.peg.${b}.${k}`, x:
|
|
1354
|
+
const [M, $] = e.plane.toScreen(a(k - b / 2, b));
|
|
1355
|
+
u.push({ type: "circle", id: `${t.id}.peg.${b}.${k}`, x: M, y: $, r: d * 0.45, fill: l, opacity: e.opacity * e.draw });
|
|
1321
1356
|
}
|
|
1322
1357
|
const p = n + 0.3, h = Math.max(n + 2, (s - e.plane.y[0]) / r - 0.2);
|
|
1323
1358
|
for (let b = 0; b <= n + 1; b++) {
|
|
1324
|
-
const k = b - (n + 1) / 2,
|
|
1325
|
-
for (const
|
|
1326
|
-
}
|
|
1327
|
-
const
|
|
1328
|
-
for (const b of
|
|
1329
|
-
const f = Math.max(0,
|
|
1330
|
-
for (let b = 0; b <
|
|
1331
|
-
const k =
|
|
1332
|
-
|
|
1333
|
-
}
|
|
1334
|
-
const
|
|
1335
|
-
if (
|
|
1336
|
-
const b =
|
|
1337
|
-
let { x:
|
|
1338
|
-
if (
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1341
|
-
}
|
|
1342
|
-
const [
|
|
1343
|
-
u.push({ type: "circle", id: `${t.id}.falling`, x:
|
|
1359
|
+
const k = b - (n + 1) / 2, M = _([[a(k, p), a(k, h)].map(e.plane.toScreen)], e.draw);
|
|
1360
|
+
for (const $ of M) u.push({ type: "line", id: `${t.id}.bin.${b}`, points: $, stroke: l, width: 1.2 * e.plane.scale, opacity: e.opacity * 0.6 });
|
|
1361
|
+
}
|
|
1362
|
+
const y = _([[a(-(n + 1) / 2, h), a((n + 1) / 2, h)].map(e.plane.toScreen)], e.draw);
|
|
1363
|
+
for (const b of y) u.push({ type: "line", id: `${t.id}.floor`, points: b, stroke: l, width: 1.2 * e.plane.scale, opacity: e.opacity * 0.6 });
|
|
1364
|
+
const f = Math.max(0, E(e.values, t.balls)), g = Math.floor(f), o = t.seed ?? t.id, m = new Array(n + 1).fill(0), v = 2 * d / e.plane.unitY / r, x = (b, k) => ({ x: b - n / 2 + (k % 2 ? 0.22 : -0.22), depth: h - v * (Math.floor(k / 2) + 0.5) });
|
|
1365
|
+
for (let b = 0; b < g; b++) {
|
|
1366
|
+
const k = fe(Ge(o, b, n)), M = x(k, m[k]), [$, S] = e.plane.toScreen(a(M.x, M.depth));
|
|
1367
|
+
m[k]++, u.push({ type: "circle", id: `${t.id}.ball.${b}`, x: $, y: S, r: d, fill: c, opacity: e.opacity });
|
|
1368
|
+
}
|
|
1369
|
+
const w = f - g;
|
|
1370
|
+
if (w > 0) {
|
|
1371
|
+
const b = Ge(o, g, n), k = Math.min(1, w / 0.8);
|
|
1372
|
+
let { x: M, depth: $ } = ci(b, k);
|
|
1373
|
+
if ($ -= 1, w > 0.8) {
|
|
1374
|
+
const P = ((w - 0.8) / 0.2) ** 2, N = fe(b), q = x(N, m[N]), L = { x: fe(b) - n / 2, depth: n - 1 };
|
|
1375
|
+
$ = L.depth + (q.depth - L.depth) * P, M = L.x + (q.x - L.x) * P;
|
|
1376
|
+
}
|
|
1377
|
+
const [S, A] = e.plane.toScreen(a(M, $));
|
|
1378
|
+
u.push({ type: "circle", id: `${t.id}.falling`, x: S, y: A, r: d, fill: c, opacity: e.opacity });
|
|
1344
1379
|
}
|
|
1345
1380
|
return u;
|
|
1346
1381
|
}
|
|
1347
|
-
function
|
|
1348
|
-
const n =
|
|
1349
|
-
const [h,
|
|
1350
|
-
return { type: "circle", id: `${t.id}.${p}`, x: h, y
|
|
1382
|
+
function Ni(t, e) {
|
|
1383
|
+
const n = xn(t, e), i = mn(n, t.seed ?? t.id, ee(E(e.values, t.count))), s = T(e.theme, t.color, e.theme.colors.blue), r = T(e.theme, t.insideColor, e.theme.colors.yellow), a = t.inside ? ot(t.inside) : void 0, l = (t.radius ?? 3) * e.plane.scale, c = i.map(([d, u], p) => {
|
|
1384
|
+
const [h, y] = e.plane.toScreen([d, u]), f = a ? et(a, { ...e.scope, x: d, y: u }) <= 0 : !1;
|
|
1385
|
+
return { type: "circle", id: `${t.id}.${p}`, x: h, y, r: l, fill: f ? r : s, opacity: e.opacity * e.draw * 0.85 };
|
|
1351
1386
|
});
|
|
1352
1387
|
if (t.fit) {
|
|
1353
|
-
const d =
|
|
1388
|
+
const d = gn(i);
|
|
1354
1389
|
if (d) {
|
|
1355
1390
|
const [u, p] = e.plane.x;
|
|
1356
|
-
c.push({ type: "line", id: `${t.id}.fit`, points: [[u, d.slope * u + d.intercept], [p, d.slope * p + d.intercept]].map(e.plane.toScreen), stroke:
|
|
1391
|
+
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: T(e.theme, "red", e.theme.colors.red), width: 3 * e.plane.scale, opacity: e.opacity });
|
|
1357
1392
|
}
|
|
1358
1393
|
}
|
|
1359
1394
|
return c;
|
|
1360
1395
|
}
|
|
1361
|
-
function
|
|
1396
|
+
function xn(t, e) {
|
|
1362
1397
|
const n = t.points;
|
|
1363
|
-
return n.kind === "uniform" ? n : { kind: "linear", slope:
|
|
1398
|
+
return n.kind === "uniform" ? n : { kind: "linear", slope: E(e.values, n.slope), intercept: E(e.values, n.intercept), noise: E(e.values, n.noise), x: n.x };
|
|
1364
1399
|
}
|
|
1365
|
-
function
|
|
1366
|
-
const n =
|
|
1400
|
+
function Pi(t, e) {
|
|
1401
|
+
const n = E(e.values, t.prior), i = E(e.values, t.truePositive), s = E(e.values, t.falsePositive), r = e.plane.x[1] - e.plane.x[0], a = e.plane.y[1] - e.plane.y[0], [l, c] = t.size ?? [r * 0.8, a * 0.7], [d, u] = t.at ?? [e.plane.x[0] + r * 0.1, e.plane.y[0] + a * 0.08], p = d + l * Math.min(1, Math.max(0, n)), h = T(e.theme, t.color, e.theme.colors.yellow), y = T(e.theme, "red", e.theme.colors.red), f = T(e.theme, "grey", e.theme.colors.grey), g = e.opacity * e.draw, o = (b, k, M, $, S, A, P) => ({
|
|
1367
1402
|
type: "line",
|
|
1368
1403
|
id: `${t.id}.${b}`,
|
|
1369
|
-
points:
|
|
1404
|
+
points: Le(e, k, M, $, S),
|
|
1370
1405
|
closed: !0,
|
|
1371
|
-
fill:
|
|
1406
|
+
fill: A,
|
|
1372
1407
|
stroke: e.theme.background,
|
|
1373
1408
|
width: 2 * e.plane.scale,
|
|
1374
|
-
opacity:
|
|
1375
|
-
}),
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1409
|
+
opacity: g * P
|
|
1410
|
+
}), m = u + c, v = m - c * Math.min(1, Math.max(0, i)), x = m - c * Math.min(1, Math.max(0, s)), w = [
|
|
1411
|
+
o("tp", d, v, p, m, h, 0.85),
|
|
1412
|
+
o("fn", d, u, p, v, f, 0.35),
|
|
1413
|
+
o("fp", p, x, d + l, m, y, 0.8),
|
|
1414
|
+
o("tn", p, u, d + l, x, f, 0.2)
|
|
1380
1415
|
];
|
|
1381
1416
|
if (t.labels !== !1 && e.draw >= 1) {
|
|
1382
|
-
const b = 20 * e.plane.scale, k = ($,
|
|
1383
|
-
const [
|
|
1384
|
-
|
|
1417
|
+
const b = 20 * e.plane.scale, k = (M, $, S, A) => {
|
|
1418
|
+
const [P, N] = e.plane.toScreen(S);
|
|
1419
|
+
w.push(...G(H($, { values: e.scope, style: "inline" }), { x: P, y: N, size: b, color: A, opacity: e.opacity, idPrefix: `${t.id}.label.${M}.` }));
|
|
1385
1420
|
};
|
|
1386
|
-
k("prior", `\\text{has it: } \\val{${t.id}.prior:3}`, [d + l / 2, u -
|
|
1421
|
+
k("prior", `\\text{has it: } \\val{${t.id}.prior:3}`, [d + l / 2, u - a * 0.04], e.theme.ink), k("tp", `\\text{has it, tests positive: } \\val{${t.id}.truePositive:3}`, [d + l / 2, u - a * 0.09], h), k("fp", `\\text{does not, tests positive: } \\val{${t.id}.falsePositive:3}`, [d + l / 2, u - a * 0.14], y), k("posterior", `P(\\text{has it} \\mid +) = \\val{${t.id}.posterior:3}`, [d + l / 2, u + c + a * 0.05], h);
|
|
1422
|
+
}
|
|
1423
|
+
return w;
|
|
1424
|
+
}
|
|
1425
|
+
const Ke = ["bfs", "dfs", "dijkstra"];
|
|
1426
|
+
function Ee(t, e, n) {
|
|
1427
|
+
const i = new Map(t.map((r, a) => [r, a])), s = new Map(t.map((r) => [r, []]));
|
|
1428
|
+
for (const r of e) {
|
|
1429
|
+
const a = r.weight ?? 1;
|
|
1430
|
+
s.get(r.from)?.push({ to: r.to, weight: a }), n || s.get(r.to)?.push({ to: r.from, weight: a });
|
|
1431
|
+
}
|
|
1432
|
+
for (const r of s.values()) r.sort((a, l) => (i.get(a.to) ?? 0) - (i.get(l.to) ?? 0));
|
|
1433
|
+
return s;
|
|
1434
|
+
}
|
|
1435
|
+
function Ii(t, e) {
|
|
1436
|
+
const n = [], i = /* @__PURE__ */ new Set([t]), s = [{ node: t }];
|
|
1437
|
+
for (; s.length > 0; ) {
|
|
1438
|
+
const { node: r, parent: a } = s.shift();
|
|
1439
|
+
for (const { to: l } of e.get(r) ?? [])
|
|
1440
|
+
i.has(l) || (i.add(l), s.push({ node: l, parent: r }));
|
|
1441
|
+
n.push({ node: r, ...a !== void 0 ? { parent: a } : {}, frontier: s.map((l) => l.node) });
|
|
1442
|
+
}
|
|
1443
|
+
return n;
|
|
1444
|
+
}
|
|
1445
|
+
function Fi(t, e) {
|
|
1446
|
+
const n = [], i = /* @__PURE__ */ new Set(), s = [{ node: t }];
|
|
1447
|
+
for (; s.length > 0; ) {
|
|
1448
|
+
const { node: r, parent: a } = s.pop();
|
|
1449
|
+
if (i.has(r)) continue;
|
|
1450
|
+
i.add(r);
|
|
1451
|
+
const l = (e.get(r) ?? []).filter(({ to: c }) => !i.has(c)).reverse();
|
|
1452
|
+
for (const { to: c } of l) s.push({ node: c, parent: r });
|
|
1453
|
+
n.push({ node: r, ...a !== void 0 ? { parent: a } : {}, frontier: [...new Set(s.map((c) => c.node).filter((c) => !i.has(c)))].reverse() });
|
|
1454
|
+
}
|
|
1455
|
+
return n;
|
|
1456
|
+
}
|
|
1457
|
+
function Li(t, e, n) {
|
|
1458
|
+
const i = [], s = Object.fromEntries(e.map((c) => [c, 1 / 0])), r = {}, a = new Map(e.map((c, d) => [c, d]));
|
|
1459
|
+
s[t] = 0;
|
|
1460
|
+
const l = /* @__PURE__ */ new Set();
|
|
1461
|
+
for (; ; ) {
|
|
1462
|
+
let c;
|
|
1463
|
+
for (const u of e)
|
|
1464
|
+
l.has(u) || s[u] === 1 / 0 || (c === void 0 || s[u] < s[c] || s[u] === s[c] && a.get(u) < a.get(c)) && (c = u);
|
|
1465
|
+
if (c === void 0) break;
|
|
1466
|
+
l.add(c);
|
|
1467
|
+
for (const { to: u, weight: p } of n.get(c) ?? [])
|
|
1468
|
+
l.has(u) || s[c] + p < s[u] && (s[u] = s[c] + p, r[u] = c);
|
|
1469
|
+
const d = e.filter((u) => !l.has(u) && s[u] < 1 / 0).sort((u, p) => s[u] - s[p]);
|
|
1470
|
+
i.push({ node: c, ...r[c] !== void 0 ? { parent: r[c] } : {}, frontier: d, distances: { ...s } });
|
|
1471
|
+
}
|
|
1472
|
+
return i;
|
|
1473
|
+
}
|
|
1474
|
+
const Vt = /* @__PURE__ */ new Map();
|
|
1475
|
+
function Ci(t, e, n, i, s = !1) {
|
|
1476
|
+
const r = JSON.stringify([t, e, n, i, s]), a = Vt.get(r);
|
|
1477
|
+
if (a) return a;
|
|
1478
|
+
if (!n.includes(e)) throw new Error(`graph search: no node "${e}"`);
|
|
1479
|
+
const l = Ee(n, i, s), c = t === "bfs" ? Ii(e, l) : t === "dfs" ? Fi(e, l) : Li(e, n, l);
|
|
1480
|
+
return Vt.size > 64 && Vt.clear(), Vt.set(r, c), c;
|
|
1481
|
+
}
|
|
1482
|
+
function qi(t, e, n) {
|
|
1483
|
+
const i = Ee(e, n, !0), s = Ee(e, n, !1), r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set([t]), l = [t];
|
|
1484
|
+
for (; l.length; ) {
|
|
1485
|
+
const y = l.shift(), f = (i.get(y)?.length ? i.get(y) : s.get(y) ?? []).map((g) => g.to).filter((g) => !a.has(g));
|
|
1486
|
+
f.forEach((g) => a.add(g)), r.set(y, f), l.push(...f);
|
|
1487
|
+
}
|
|
1488
|
+
const c = /* @__PURE__ */ new Map();
|
|
1489
|
+
let d = 0;
|
|
1490
|
+
const u = (y, f) => {
|
|
1491
|
+
const g = r.get(y) ?? [], o = g.length === 0 ? d++ : g.map((m) => u(m, f + 1)).reduce((m, v, x, w) => m + v / w.length, 0);
|
|
1492
|
+
return c.set(y, [o, f === 0 ? 0 : -f]), o;
|
|
1493
|
+
};
|
|
1494
|
+
u(t, 0);
|
|
1495
|
+
const p = [...c.values()].map(([y]) => y), h = (Math.min(...p) + Math.max(...p)) / 2;
|
|
1496
|
+
for (const [y, [f, g]] of c) c.set(y, [f - h, g]);
|
|
1497
|
+
return c;
|
|
1498
|
+
}
|
|
1499
|
+
const zi = { "∪": "|", "∩": "&", "∖": "-", "△": "^", "¬": "!", "\\": "-" };
|
|
1500
|
+
function Sn(t) {
|
|
1501
|
+
const e = [...t].map((d) => zi[d] ?? d).join("");
|
|
1502
|
+
let n = 0;
|
|
1503
|
+
const i = () => {
|
|
1504
|
+
for (; /\s/.test(e[n] ?? ""); ) n++;
|
|
1505
|
+
}, s = (d) => {
|
|
1506
|
+
throw new Error(`set expression: ${d} at ${n + 1} in "${t}"`);
|
|
1507
|
+
}, r = () => {
|
|
1508
|
+
i();
|
|
1509
|
+
let d;
|
|
1510
|
+
if (e[n] === "!")
|
|
1511
|
+
n++, d = { type: "not", operand: r() };
|
|
1512
|
+
else if (e[n] === "(")
|
|
1513
|
+
n++, d = l(), i(), e[n] !== ")" && s('expected ")"'), n++;
|
|
1514
|
+
else {
|
|
1515
|
+
const u = /^[A-Za-z]\w*/.exec(e.slice(n));
|
|
1516
|
+
u || s(n >= e.length ? "unexpected end" : `unexpected "${e[n]}"`), n += u[0].length, d = { type: "set", name: u[0] };
|
|
1517
|
+
}
|
|
1518
|
+
for (i(); e[n] === "'"; )
|
|
1519
|
+
n++, d = { type: "not", operand: d }, i();
|
|
1520
|
+
return d;
|
|
1521
|
+
}, a = () => {
|
|
1522
|
+
let d = r();
|
|
1523
|
+
for (i(); e[n] === "&"; )
|
|
1524
|
+
n++, d = { type: "op", operator: "&", left: d, right: r() }, i();
|
|
1525
|
+
return d;
|
|
1526
|
+
}, l = () => {
|
|
1527
|
+
let d = a();
|
|
1528
|
+
for (i(); e[n] === "|" || e[n] === "-" || e[n] === "^"; )
|
|
1529
|
+
d = { type: "op", operator: e[n++], left: d, right: a() }, i();
|
|
1530
|
+
return d;
|
|
1531
|
+
}, c = l();
|
|
1532
|
+
return i(), n < e.length && s(`unexpected "${e[n]}"`), c;
|
|
1533
|
+
}
|
|
1534
|
+
function Zt(t) {
|
|
1535
|
+
return t.type === "set" ? [t.name] : t.type === "not" ? Zt(t.operand) : [.../* @__PURE__ */ new Set([...Zt(t.left), ...Zt(t.right)])];
|
|
1536
|
+
}
|
|
1537
|
+
function Jt(t, e) {
|
|
1538
|
+
switch (t.type) {
|
|
1539
|
+
case "set":
|
|
1540
|
+
return e.has(t.name);
|
|
1541
|
+
case "not":
|
|
1542
|
+
return !Jt(t.operand, e);
|
|
1543
|
+
case "op": {
|
|
1544
|
+
const n = Jt(t.left, e), i = Jt(t.right, e);
|
|
1545
|
+
return t.operator === "&" ? n && i : t.operator === "|" ? n || i : t.operator === "-" ? n && !i : n !== i;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
function ji(t, e) {
|
|
1550
|
+
const n = [];
|
|
1551
|
+
for (let i = 0; i < 1 << e.length; i++) {
|
|
1552
|
+
const s = e.filter((r, a) => i & 1 << a);
|
|
1553
|
+
Jt(t, new Set(s)) && n.push(s);
|
|
1554
|
+
}
|
|
1555
|
+
return n;
|
|
1556
|
+
}
|
|
1557
|
+
function An(t, e, n, i, s = 64) {
|
|
1558
|
+
return Array.from({ length: s }, (r, a) => {
|
|
1559
|
+
const l = a / s * 2 * Math.PI;
|
|
1560
|
+
return [t + n * Math.cos(l), e + i * Math.sin(l)];
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
function ae(t) {
|
|
1564
|
+
return t.edges.map((e) => Array.isArray(e) ? { from: e[0], to: e[1], ...e[2] !== void 0 ? { weight: e[2] } : {} } : e);
|
|
1565
|
+
}
|
|
1566
|
+
function En(t) {
|
|
1567
|
+
const e = /* @__PURE__ */ new Map();
|
|
1568
|
+
if (t.tree) {
|
|
1569
|
+
const [n, i] = t.tree.spacing ?? [1.2, 1.2], [s, r] = t.tree.at ?? [0, 0];
|
|
1570
|
+
for (const [a, [l, c]] of qi(t.tree.root, t.nodes.map((d) => d.id), ae(t))) e.set(a, [s + l * n, r + c * i]);
|
|
1387
1571
|
}
|
|
1388
|
-
|
|
1572
|
+
for (const n of t.nodes) n.at && e.set(n.id, n.at);
|
|
1573
|
+
return e;
|
|
1574
|
+
}
|
|
1575
|
+
function Tn(t, e) {
|
|
1576
|
+
if (!t.search) return;
|
|
1577
|
+
const n = Ci(t.search.kind, t.search.start, t.nodes.map((r) => r.id), ae(t), t.directed), i = t.step === void 0 ? n.length : Math.min(n.length, Math.max(0, E(e, t.step))), s = Math.floor(i);
|
|
1578
|
+
return { events: n, done: s, partial: s < n.length ? i - s : 0 };
|
|
1579
|
+
}
|
|
1580
|
+
const _i = { bfs: "queue", dfs: "stack", dijkstra: "open" };
|
|
1581
|
+
function Di(t, e) {
|
|
1582
|
+
const { plane: n, theme: i } = e, s = En(t), r = ae(t), a = Tn(t, e.values), l = (t.radius ?? 18) * n.scale, c = T(i, t.color, i.ink), d = T(i, "grey", i.colors.grey), u = T(i, "yellow", i.colors.yellow), p = T(i, "blue", i.colors.blue), h = [], y = a ? a.events.slice(0, a.done) : [], f = new Set(y.map(($) => $.node)), g = new Set(y.filter(($) => $.parent !== void 0).map(($) => `${$.parent}>${$.node}`)), o = y.at(-1), m = new Set(o?.frontier ?? []), v = a && a.partial > 0 ? a.events[a.done] : void 0, x = ($, S) => g.has(`${$}>${S}`) || !t.directed && g.has(`${S}>${$}`), w = ($) => n.toScreen(s.get($) ?? [0, 0]), b = ($, S) => {
|
|
1583
|
+
const A = w($), P = w(S), [N, q] = Nt([P[0] - A[0], P[1] - A[1]]);
|
|
1584
|
+
return [[A[0] + N * l, A[1] + q * l], [P[0] - N * l, P[1] - q * l]];
|
|
1585
|
+
}, k = t.weights ?? t.search?.kind === "dijkstra";
|
|
1586
|
+
if (r.forEach(($, S) => {
|
|
1587
|
+
const [A, P] = b($.from, $.to), N = x($.from, $.to), q = N ? u : d, L = (N ? 4 : 2) * n.scale, [O] = _([[A, P]], e.draw);
|
|
1588
|
+
if (O && (h.push(t.directed ? { type: "arrow", id: `${t.id}.edge.${S}`, points: O, stroke: q, width: L, head: 11 * n.scale, opacity: e.opacity } : { type: "line", id: `${t.id}.edge.${S}`, points: O, stroke: q, width: L, opacity: e.opacity }), k && e.draw >= 1)) {
|
|
1589
|
+
const I = [(A[0] + P[0]) / 2, (A[1] + P[1]) / 2], [V, nt] = Nt([-(P[1] - A[1]), P[0] - A[0]]), D = 14 * n.scale;
|
|
1590
|
+
h.push({ type: "text", id: `${t.id}.weight.${S}`, text: String($.weight ?? 1), x: I[0] + V * D * 0.9, y: I[1] + nt * D * 0.9 + D * 0.35, size: D, font: ht, color: N ? u : d, align: "center", opacity: e.opacity });
|
|
1591
|
+
}
|
|
1592
|
+
}), v?.parent !== void 0) {
|
|
1593
|
+
const [$, S] = b(v.parent, v.node), [A] = _([[$, S]], v.parent ? a.partial : 1);
|
|
1594
|
+
A && h.push({ type: "line", id: `${t.id}.reaching`, points: A, stroke: u, width: 4 * n.scale, opacity: e.opacity });
|
|
1595
|
+
}
|
|
1596
|
+
const M = o?.distances;
|
|
1597
|
+
for (const $ of t.nodes) {
|
|
1598
|
+
const [S, A] = w($.id), P = f.has($.id), N = v?.node === $.id && a.partial >= 0.999, q = !P && m.has($.id), L = P || N ? u : q ? p : i.background;
|
|
1599
|
+
h.push({ type: "circle", id: `${t.id}.node.${$.id}`, x: S, y: A, r: l, fill: L, stroke: P ? u : q ? p : c, width: 2 * n.scale, opacity: e.opacity * Math.min(1, e.draw * 1.5) }), o?.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 });
|
|
1600
|
+
const O = P || q || N ? i.background : c;
|
|
1601
|
+
if (h.push(...G(H($.label ?? $.id, { style: "inline" }), { x: S, y: A, size: l * 0.95, color: O, opacity: e.opacity * e.draw, idPrefix: `${t.id}.label.${$.id}.` })), M) {
|
|
1602
|
+
const I = M[$.id], V = 13 * n.scale;
|
|
1603
|
+
h.push({ type: "text", id: `${t.id}.distance.${$.id}`, text: I === 1 / 0 ? "∞" : String(Math.round(I * 100) / 100), x: S, y: A + l + V * 1.15, size: V, font: ht, color: p, align: "center", opacity: e.opacity });
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
if (t.frontier && t.search && e.draw >= 1) {
|
|
1607
|
+
const [$, S] = t.frontier, A = 16 * n.scale, P = _i[t.search.kind];
|
|
1608
|
+
h.push({ type: "text", id: `${t.id}.frontier.name`, text: `${P}:`, x: $, y: S + A * 0.35, size: A, font: ht, color: d, align: "left", opacity: e.opacity });
|
|
1609
|
+
const N = A * 1.9;
|
|
1610
|
+
[...m].forEach((q, L) => {
|
|
1611
|
+
const O = $ + A * 4 + L * (N + A * 0.4), I = t.nodes.find((V) => V.id === q)?.label ?? q;
|
|
1612
|
+
h.push({ type: "line", id: `${t.id}.frontier.box.${L}`, points: [[O, S - N / 2], [O + N, S - N / 2], [O + N, S + N / 2], [O, S + N / 2]], closed: !0, fill: p, opacity: e.opacity * 0.9 }), h.push(...G(H(I, { style: "inline" }), { x: O + N / 2, y: S, size: A * 1.05, color: i.background, opacity: e.opacity, idPrefix: `${t.id}.frontier.label.${L}.` }));
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
return h;
|
|
1616
|
+
}
|
|
1617
|
+
function Ri(t) {
|
|
1618
|
+
return t === 2 ? [[-0.6, 0], [0.6, 0]] : [0, 1, 2].map((e) => {
|
|
1619
|
+
const n = Math.PI / 2 + e * 2 * Math.PI / 3;
|
|
1620
|
+
return [0.62 * Math.cos(n), 0.62 * Math.sin(n) - 0.1];
|
|
1621
|
+
});
|
|
1389
1622
|
}
|
|
1390
|
-
function
|
|
1623
|
+
function Bi(t, e) {
|
|
1624
|
+
const { plane: n, theme: i } = e, s = t.radius ?? 1.5, [r, a] = t.at ?? [0, 0], l = Ri(t.sets.length).map(([o, m]) => [r + o * s, a + m * s]), c = l.map(([o, m]) => An(o, m, s, s, 96).map(n.toScreen)), d = l.map(([o]) => o), u = l.map(([, o]) => o), p = s * 0.35, h = [[Math.min(...d) - s - p, Math.min(...u) - s - p], [Math.max(...d) + s + p, Math.min(...u) - s - p], [Math.max(...d) + s + p, Math.max(...u) + s + p], [Math.min(...d) - s - p, Math.max(...u) + s + p]].map(n.toScreen), y = [], f = t.sets.map((o) => o.id);
|
|
1625
|
+
if (t.highlight) {
|
|
1626
|
+
const o = T(i, t.highlightColor, i.colors.yellow);
|
|
1627
|
+
ji(Sn(t.highlight), f).forEach((m, v) => {
|
|
1628
|
+
y.push({
|
|
1629
|
+
type: "line",
|
|
1630
|
+
id: `${t.id}.region.${v}`,
|
|
1631
|
+
points: h,
|
|
1632
|
+
closed: !0,
|
|
1633
|
+
fill: o,
|
|
1634
|
+
opacity: e.opacity * e.draw * 0.55,
|
|
1635
|
+
clip: f.map((x, w) => ({ points: c[w], outside: !m.includes(x) }))
|
|
1636
|
+
});
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
if (t.universe !== !1) {
|
|
1640
|
+
y.push({ type: "line", id: `${t.id}.universe`, points: h, closed: !0, stroke: T(i, "grey", i.colors.grey), width: 2 * n.scale, opacity: e.opacity });
|
|
1641
|
+
const [o, m] = h[3];
|
|
1642
|
+
y.push(...G(H("U", { style: "inline" }), { x: o + 16 * n.scale, y: m + 20 * n.scale, size: 22 * n.scale, color: T(i, "grey", i.colors.grey), opacity: e.opacity, idPrefix: `${t.id}.universe.` }));
|
|
1643
|
+
}
|
|
1644
|
+
const g = ["blue", "red", "green"];
|
|
1645
|
+
return t.sets.forEach((o, m) => {
|
|
1646
|
+
const v = T(i, o.color ?? g[m], i.colors.blue);
|
|
1647
|
+
for (const M of _([[...c[m], c[m][0]]], e.draw))
|
|
1648
|
+
y.push({ type: "line", id: `${t.id}.set.${o.id}`, points: M, stroke: v, width: 3 * n.scale, opacity: e.opacity });
|
|
1649
|
+
const [x, w] = Nt([l[m][0] - r || (m === 0 ? -1 : 1), l[m][1] - a]), [b, k] = n.toScreen([l[m][0] + x * s * 0.78, l[m][1] + w * s * 0.78 + (t.sets.length === 2 ? s * 0.85 : 0)]);
|
|
1650
|
+
y.push(...G(H(o.label ?? o.id, { style: "inline" }), { x: b, y: k, size: 26 * n.scale, color: v, opacity: e.opacity * e.draw, idPrefix: `${t.id}.label.${o.id}.` }));
|
|
1651
|
+
}), y;
|
|
1652
|
+
}
|
|
1653
|
+
const On = (t, e) => (Math.round(t) % e + e) % e;
|
|
1654
|
+
function Vi(t, e) {
|
|
1655
|
+
const { plane: n, theme: i } = e, s = t.modulus, [r, a] = t.at ?? [0, 0], l = t.radius ?? 2, c = E(e.values, t.value), d = T(i, t.color, i.ink), u = T(i, "yellow", i.colors.yellow), p = (f, g) => {
|
|
1656
|
+
const o = Math.PI / 2 - f / s * 2 * Math.PI;
|
|
1657
|
+
return n.toScreen([r + Math.cos(o) * l * g, a + Math.sin(o) * l * g]);
|
|
1658
|
+
}, h = [];
|
|
1659
|
+
for (const f of _([An(r, a, l, l, 120).map(n.toScreen)], e.draw))
|
|
1660
|
+
h.push({ type: "line", id: `${t.id}.face`, points: f, stroke: d, width: 3 * n.scale, opacity: e.opacity });
|
|
1661
|
+
const y = On(c, s);
|
|
1662
|
+
for (let f = 0; f < s; f++) {
|
|
1663
|
+
const [g, o] = p(f, 0.8), m = Math.min(26, 220 / s + 8) * n.scale;
|
|
1664
|
+
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: g, y: o + m * 0.35, size: m, font: ht, color: f === y ? u : d, align: "center", opacity: e.opacity * e.draw });
|
|
1665
|
+
}
|
|
1666
|
+
if (e.draw >= 1) {
|
|
1667
|
+
const f = n.toScreen([r, a]);
|
|
1668
|
+
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 });
|
|
1669
|
+
}
|
|
1670
|
+
return h;
|
|
1671
|
+
}
|
|
1672
|
+
const Qe = ["sigmoid", "tanh", "relu"], Hi = (t, e) => t === "sigmoid" ? 1 / (1 + Math.exp(-e)) : t === "tanh" ? Math.tanh(e) : Math.max(0, e);
|
|
1673
|
+
function Ui(t, e) {
|
|
1674
|
+
const n = $t(typeof e == "number" ? e : yt(e)), i = [], s = [];
|
|
1675
|
+
for (let r = 0; r < t.length - 1; r++) {
|
|
1676
|
+
const a = 1.6 / Math.sqrt(t[r]);
|
|
1677
|
+
i.push(Array.from({ length: t[r + 1] }, () => Array.from({ length: t[r] }, () => pt(n) * a))), s.push(Array.from({ length: t[r + 1] }, () => pt(n) * 0.3));
|
|
1678
|
+
}
|
|
1679
|
+
return { layers: t, weights: i, biases: s };
|
|
1680
|
+
}
|
|
1681
|
+
function Wi(t, e, n) {
|
|
1682
|
+
const i = [e.slice(0, t.layers[0])];
|
|
1683
|
+
for (let s = 0; s < t.weights.length; s++) {
|
|
1684
|
+
const r = i[s];
|
|
1685
|
+
i.push(t.weights[s].map((a, l) => Hi(n, a.reduce((c, d, u) => c + d * (r[u] ?? 0), t.biases[s][l]))));
|
|
1686
|
+
}
|
|
1687
|
+
return i;
|
|
1688
|
+
}
|
|
1689
|
+
const Ht = ["viridis", "heat", "diverging"], Gi = {
|
|
1690
|
+
viridis: [[68, 1, 84], [59, 82, 139], [33, 145, 140], [94, 201, 98], [253, 231, 37]],
|
|
1691
|
+
heat: [[20, 12, 30], [120, 28, 60], [214, 70, 40], [250, 160, 50], [252, 240, 180]],
|
|
1692
|
+
diverging: [[49, 99, 185], [140, 180, 225], [245, 245, 245], [235, 140, 120], [190, 40, 50]]
|
|
1693
|
+
};
|
|
1694
|
+
function Ce(t, e) {
|
|
1695
|
+
const n = Gi[t], i = Math.min(1, Math.max(0, Number.isFinite(e) ? e : 0)) * (n.length - 1), s = Math.min(n.length - 2, Math.floor(i)), r = i - s, [a, l, c] = n[s].map((d, u) => Math.round(d + (n[s + 1][u] - d) * r));
|
|
1696
|
+
return `rgb(${a}, ${l}, ${c})`;
|
|
1697
|
+
}
|
|
1698
|
+
function tn(t) {
|
|
1699
|
+
const e = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());
|
|
1700
|
+
if (e) {
|
|
1701
|
+
const i = e[1].length === 3 ? [...e[1]].map((s) => s + s).join("") : e[1];
|
|
1702
|
+
return [0, 2, 4].map((s) => parseInt(i.slice(s, s + 2), 16));
|
|
1703
|
+
}
|
|
1704
|
+
const n = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i.exec(t.trim());
|
|
1705
|
+
return n ? [Number(n[1]), Number(n[2]), Number(n[3])] : void 0;
|
|
1706
|
+
}
|
|
1707
|
+
function Nn(t, e, n) {
|
|
1708
|
+
const i = tn(t), s = tn(e);
|
|
1709
|
+
if (!i || !s) return t;
|
|
1710
|
+
const r = Math.min(1, Math.max(0, n)), [a, l, c] = i.map((d, u) => Math.round(s[u] + (d - s[u]) * r));
|
|
1711
|
+
return `rgb(${a}, ${l}, ${c})`;
|
|
1712
|
+
}
|
|
1713
|
+
function Xi(t, e, n, i, s, r) {
|
|
1714
|
+
r += 1e-9 * Math.max(1, Math.abs(r));
|
|
1715
|
+
const a = [], l = t.length, c = t[0]?.length ?? 0, d = (p, h, y, f) => {
|
|
1716
|
+
(h > f || h === f && p > y) && ([p, h, y, f] = [y, f, p, h]);
|
|
1717
|
+
const g = t[h][p] - r, o = t[f][y] - r, m = g === o ? 0.5 : g / (g - o);
|
|
1718
|
+
return [e + (p + (y - p) * m) * i, n + (h + (f - h) * m) * s];
|
|
1719
|
+
};
|
|
1720
|
+
for (let p = 0; p < l - 1; p++)
|
|
1721
|
+
for (let h = 0; h < c - 1; h++) {
|
|
1722
|
+
const y = [t[p][h], t[p][h + 1], t[p + 1][h + 1], t[p + 1][h]];
|
|
1723
|
+
if (y.some((o) => !Number.isFinite(o))) continue;
|
|
1724
|
+
const f = [], g = [
|
|
1725
|
+
[0, 1, h, p, h + 1, p],
|
|
1726
|
+
[1, 2, h + 1, p, h + 1, p + 1],
|
|
1727
|
+
[2, 3, h + 1, p + 1, h, p + 1],
|
|
1728
|
+
[3, 0, h, p + 1, h, p]
|
|
1729
|
+
];
|
|
1730
|
+
for (const [o, m, v, x, w, b] of g)
|
|
1731
|
+
y[o] >= r != y[m] >= r && f.push(d(v, x, w, b));
|
|
1732
|
+
if (f.length === 2) a.push([f[0], f[1]]);
|
|
1733
|
+
else if (f.length === 4) {
|
|
1734
|
+
const o = (y[0] + y[1] + y[2] + y[3]) / 4 >= r, m = y[0] >= r;
|
|
1735
|
+
o === m ? a.push([f[0], f[1]], [f[2], f[3]]) : a.push([f[0], f[3]], [f[1], f[2]]);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
const u = 1e-6 * Math.min(Math.abs(i), Math.abs(s));
|
|
1739
|
+
return Yi(a.filter(([p, h]) => Math.hypot(h[0] - p[0], h[1] - p[1]) > u));
|
|
1740
|
+
}
|
|
1741
|
+
function Yi(t) {
|
|
1742
|
+
const e = ([a, l]) => `${Math.round(a * 1e6)},${Math.round(l * 1e6)}`, n = /* @__PURE__ */ new Map();
|
|
1743
|
+
t.forEach(([a, l], c) => {
|
|
1744
|
+
for (const d of [a, l]) n.set(e(d), [...n.get(e(d)) ?? [], c]);
|
|
1745
|
+
});
|
|
1746
|
+
const i = /* @__PURE__ */ new Set(), s = [], r = (a) => {
|
|
1747
|
+
for (; ; ) {
|
|
1748
|
+
const l = a[a.length - 1], c = (n.get(e(l)) ?? []).find((p) => !i.has(p));
|
|
1749
|
+
if (c === void 0) return;
|
|
1750
|
+
i.add(c);
|
|
1751
|
+
const [d, u] = t[c];
|
|
1752
|
+
a.push(e(d) === e(l) ? u : d);
|
|
1753
|
+
}
|
|
1754
|
+
};
|
|
1755
|
+
return t.forEach(([a, l], c) => {
|
|
1756
|
+
if (i.has(c)) return;
|
|
1757
|
+
i.add(c);
|
|
1758
|
+
const d = [a, l];
|
|
1759
|
+
r(d), d.reverse(), r(d), s.push(d);
|
|
1760
|
+
}), s;
|
|
1761
|
+
}
|
|
1762
|
+
function Zi(t, [e, n], [i, s], r) {
|
|
1763
|
+
const a = (n - e) / r, l = (s - i) / r;
|
|
1764
|
+
return { values: Array.from({ length: r + 1 }, (d, u) => Array.from({ length: r + 1 }, (p, h) => t(e + h * a, i + u * l))), x0: e, y0: i, dx: a, dy: l };
|
|
1765
|
+
}
|
|
1766
|
+
function Ji(t, e, n, i, s = 0, r = {}) {
|
|
1767
|
+
const a = ot(t), l = X(a, "x"), c = X(a, "y"), d = (h, y) => {
|
|
1768
|
+
const f = { ...r, x: h, y };
|
|
1769
|
+
return [et(l, f), et(c, f)];
|
|
1770
|
+
}, u = [e];
|
|
1771
|
+
let p = [0, 0];
|
|
1772
|
+
for (let h = 0; h < i; h++) {
|
|
1773
|
+
const [y, f] = u[u.length - 1], [g, o] = d(y, f);
|
|
1774
|
+
p = [s * p[0] - n * g, s * p[1] - n * o];
|
|
1775
|
+
const m = [y + p[0], f + p[1]];
|
|
1776
|
+
if (!Number.isFinite(m[0]) || !Number.isFinite(m[1]) || Math.abs(m[0]) > 1e6 || Math.abs(m[1]) > 1e6) break;
|
|
1777
|
+
u.push(m);
|
|
1778
|
+
}
|
|
1779
|
+
return u;
|
|
1780
|
+
}
|
|
1781
|
+
function qe(t) {
|
|
1782
|
+
const e = ot(t);
|
|
1783
|
+
return (n, i, s = {}) => et(e, { ...s, x: n, y: i });
|
|
1784
|
+
}
|
|
1785
|
+
function Pn(t, e, n, i) {
|
|
1786
|
+
const s = $t(typeof i == "number" ? i : yt(i)), r = [];
|
|
1787
|
+
for (let a = 0; a < e; a++)
|
|
1788
|
+
t.forEach(([l, c], d) => r.push({ point: [l + pt(s) * n, c + pt(s) * n], label: d }));
|
|
1789
|
+
return r;
|
|
1790
|
+
}
|
|
1791
|
+
const Ki = (t) => 1 / (1 + Math.exp(-t)), ce = (t, [e, n]) => Ki(t.w[0] * e + t.w[1] * n + t.b);
|
|
1792
|
+
function Qi(t, e, n, i = { w: [0, 0], b: 0 }) {
|
|
1793
|
+
const s = [i];
|
|
1794
|
+
for (let r = 0; r < e; r++) {
|
|
1795
|
+
const { w: a, b: l } = s[s.length - 1];
|
|
1796
|
+
let c = 0, d = 0, u = 0;
|
|
1797
|
+
for (const { point: h, label: y } of t) {
|
|
1798
|
+
const f = ce({ w: a, b: l }, h) - y;
|
|
1799
|
+
c += f * h[0], d += f * h[1], u += f;
|
|
1800
|
+
}
|
|
1801
|
+
const p = t.length || 1;
|
|
1802
|
+
s.push({ w: [a[0] - n * c / p, a[1] - n * d / p], b: l - n * u / p });
|
|
1803
|
+
}
|
|
1804
|
+
return s;
|
|
1805
|
+
}
|
|
1806
|
+
function ts(t, e) {
|
|
1807
|
+
return e.length === 0 ? 0 : e.filter(({ point: n, label: i }) => (ce(t, n) >= 0.5 ? 1 : 0) === i).length / e.length;
|
|
1808
|
+
}
|
|
1809
|
+
function es(t, e) {
|
|
1810
|
+
if (e.length === 0) return 0;
|
|
1811
|
+
const n = 1e-12;
|
|
1812
|
+
return -e.reduce((i, { point: s, label: r }) => {
|
|
1813
|
+
const a = ce(t, s);
|
|
1814
|
+
return i + Math.log(r ? a + n : 1 - a + n);
|
|
1815
|
+
}, 0) / e.length;
|
|
1816
|
+
}
|
|
1817
|
+
const ne = (t, e) => (t[0] - e[0]) ** 2 + (t[1] - e[1]) ** 2;
|
|
1818
|
+
function ze(t, e) {
|
|
1819
|
+
return t.map((n) => {
|
|
1820
|
+
let i = 0;
|
|
1821
|
+
for (let s = 1; s < e.length; s++) ne(n, e[s]) < ne(n, e[i]) && (i = s);
|
|
1822
|
+
return i;
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
function ns(t, e, n = 20, i = t.slice(0, e)) {
|
|
1826
|
+
const s = [i.map((r) => [r[0], r[1]])];
|
|
1827
|
+
for (let r = 0; r < n; r++) {
|
|
1828
|
+
const a = s[s.length - 1], l = ze(t, a), c = a.map((u, p) => {
|
|
1829
|
+
const h = t.filter((y, f) => l[f] === p);
|
|
1830
|
+
return h.length === 0 ? u : [h.reduce((y, f) => y + f[0], 0) / h.length, h.reduce((y, f) => y + f[1], 0) / h.length];
|
|
1831
|
+
}), d = c.some((u, p) => ne(u, a[p]) > 1e-12);
|
|
1832
|
+
if (s.push(c), !d) break;
|
|
1833
|
+
}
|
|
1834
|
+
return s;
|
|
1835
|
+
}
|
|
1836
|
+
function is(t, e) {
|
|
1837
|
+
const n = ze(t, e);
|
|
1838
|
+
return t.reduce((i, s, r) => i + ne(s, e[n[r]]), 0);
|
|
1839
|
+
}
|
|
1840
|
+
const le = (t, e, n) => {
|
|
1841
|
+
let i = t.get(e);
|
|
1842
|
+
return i === void 0 && (i = n(), t.size > 32 && t.clear(), t.set(e, i)), i;
|
|
1843
|
+
}, ue = (t) => Number.isFinite(t) ? t : 0, In = (t) => ({ x: t.plane.x, y: t.plane.y, w: t.plane.x[1] - t.plane.x[0], h: t.plane.y[1] - t.plane.y[0] });
|
|
1844
|
+
function Fn(t, e) {
|
|
1845
|
+
const n = Ui(t.layers, t.seed ?? t.id), i = Array.from({ length: t.layers[0] }, (a, l) => t.inputs?.[l] === void 0 ? 0.5 : E(e, t.inputs[l])), s = Wi(n, i, t.activation ?? "sigmoid"), r = t.flow === void 0 ? t.layers.length - 1 : Math.min(t.layers.length - 1, Math.max(0, ue(E(e, t.flow))));
|
|
1846
|
+
return { network: n, activations: s, flow: r };
|
|
1847
|
+
}
|
|
1848
|
+
function ss(t, e) {
|
|
1849
|
+
const { plane: n, theme: i } = e, { network: s, activations: r, flow: a } = Fn(t, e.values), l = In(e), [c, d] = t.size ?? [l.w * 0.75, l.h * 0.7], [u, p] = t.at ?? [(l.x[0] + l.x[1]) / 2, (l.y[0] + l.y[1]) / 2], h = (t.radius ?? 16) * n.scale, y = t.layers, f = (w, b) => {
|
|
1850
|
+
const k = u - c / 2 + (y.length === 1 ? c / 2 : w / (y.length - 1) * c), M = Math.min(d / Math.max(1, y[w] - 1), d * 0.3), $ = p + ((y[w] - 1) / 2 - b) * M;
|
|
1851
|
+
return n.toScreen([k, $]);
|
|
1852
|
+
}, g = T(i, "blue", i.colors.blue), o = T(i, "red", i.colors.red), m = [], v = Math.max(...s.weights.flat(2).map(Math.abs), 1e-9);
|
|
1853
|
+
s.weights.forEach((w, b) => {
|
|
1854
|
+
w.forEach((k, M) => {
|
|
1855
|
+
k.forEach(($, S) => {
|
|
1856
|
+
const A = f(b, S), P = f(b + 1, M), N = Math.min(1, Math.max(0, a - b)), q = $ >= 0 ? g : o, L = (0.6 + 3 * (Math.abs($) / v)) * n.scale;
|
|
1857
|
+
for (const O of _([[A, P]], e.draw))
|
|
1858
|
+
m.push({ type: "line", id: `${t.id}.w.${b}.${M}.${S}`, points: O, stroke: q, width: L, opacity: e.opacity * (0.18 + 0.5 * N) });
|
|
1859
|
+
if (N > 0 && N < 1) {
|
|
1860
|
+
const [O, I] = It(A, P, N);
|
|
1861
|
+
m.push({ type: "circle", id: `${t.id}.pulse.${b}.${M}.${S}`, x: O, y: I, r: h * 0.22, fill: T(i, "yellow", i.colors.yellow), opacity: e.opacity * (0.5 + 0.5 * Math.abs(r[b][S] ?? 0)) });
|
|
1862
|
+
}
|
|
1863
|
+
});
|
|
1864
|
+
});
|
|
1865
|
+
}), y.forEach((w, b) => {
|
|
1866
|
+
const k = Math.min(1, Math.max(0, a - b + 1));
|
|
1867
|
+
for (let M = 0; M < w; M++) {
|
|
1868
|
+
const [$, S] = f(b, M), A = r[b][M] ?? 0, P = t.activation === "relu" ? Math.min(1, A / 2) : t.activation === "tanh" ? (A + 1) / 2 : A;
|
|
1869
|
+
m.push({ type: "circle", id: `${t.id}.node.${b}.${M}`, x: $, y: S, r: h, fill: i.background, stroke: T(i, t.color, i.ink), width: 2 * n.scale, opacity: e.opacity * Math.min(1, e.draw * 1.5) }), k > 0 && m.push({ type: "circle", id: `${t.id}.value.${b}.${M}`, x: $, y: S, r: h * 0.86, fill: Ce("viridis", P), opacity: e.opacity * k });
|
|
1870
|
+
}
|
|
1871
|
+
});
|
|
1872
|
+
const x = (w, b, k, M) => m.push(...G(H(w, { values: e.scope, style: "inline" }), { x: b[0], y: b[1], size: 20 * n.scale, color: i.ink, align: k, opacity: e.opacity * e.draw, idPrefix: `${t.id}.${M}.` }));
|
|
1873
|
+
return t.labels?.inputs?.forEach((w, b) => {
|
|
1874
|
+
const [k, M] = f(0, b);
|
|
1875
|
+
x(w, [k - h * 1.5, M], "right", `in${b}`);
|
|
1876
|
+
}), t.labels?.outputs?.forEach((w, b) => {
|
|
1877
|
+
const [k, M] = f(y.length - 1, b);
|
|
1878
|
+
x(w, [k + h * 1.5, M], "left", `out${b}`);
|
|
1879
|
+
}), m;
|
|
1880
|
+
}
|
|
1881
|
+
const rs = (t) => {
|
|
1882
|
+
const e = Math.max(...t), n = t.map((s) => Math.exp(s - e)), i = n.reduce((s, r) => s + r, 0);
|
|
1883
|
+
return n.map((s) => s / i);
|
|
1884
|
+
};
|
|
1885
|
+
function os(t, e) {
|
|
1886
|
+
if (t.cells) {
|
|
1887
|
+
const d = In(e), [u, p] = t.size ?? [d.w * 0.7, d.h * 0.7], h = t.at ?? [(d.x[0] + d.x[1]) / 2 - u / 2, (d.y[0] + d.y[1]) / 2 - p / 2];
|
|
1888
|
+
return { cells: t.softmax ? t.cells.map(rs) : t.cells, box: [h, [h[0] + u, h[1] + p]] };
|
|
1889
|
+
}
|
|
1890
|
+
const [[n, i], [s, r]] = t.region ?? [e.plane.x, e.plane.y], a = t.resolution ?? 48, l = qe(t.expr);
|
|
1891
|
+
return { cells: Array.from({ length: a }, (d, u) => Array.from({ length: a }, (p, h) => l(n + (h + 0.5) / a * (i - n), r - (u + 0.5) / a * (r - s), e.scope))), box: [[n, s], [i, r]] };
|
|
1892
|
+
}
|
|
1893
|
+
function as(t, e) {
|
|
1894
|
+
const { plane: n, theme: i } = e, { cells: s, box: r } = os(t, e), a = s.flat().filter(Number.isFinite), [l, c] = t.range ?? [Math.min(...a), Math.max(...a)], d = s.length, u = s[0]?.length ?? 0, [[p, h], [y, f]] = r, g = (y - p) / u, o = (f - h) / d, m = [], v = t.colormap ?? "viridis", x = Math.ceil(d * e.draw);
|
|
1895
|
+
for (let b = 0; b < x; b++)
|
|
1896
|
+
for (let k = 0; k < u; k++) {
|
|
1897
|
+
const M = s[b][k];
|
|
1898
|
+
if (!Number.isFinite(M)) continue;
|
|
1899
|
+
const $ = c === l ? 0.5 : (M - l) / (c - l), S = p + k * g, A = f - b * o, P = [[S, A - o], [S + g * 1.01, A - o], [S + g * 1.01, A + o * 0.01], [S, A + o * 0.01]].map(n.toScreen);
|
|
1900
|
+
if (m.push({ type: "line", id: `${t.id}.${b}.${k}`, points: P, closed: !0, fill: Nn(Ce(v, $), i.background, e.opacity) }), t.values) {
|
|
1901
|
+
const [N, q] = n.toScreen([S + g / 2, A - o / 2]), L = Math.min(16 * n.scale, Math.abs(g * n.unitX) * 0.32);
|
|
1902
|
+
m.push({ type: "text", id: `${t.id}.v.${b}.${k}`, text: M.toFixed(2).replace(/^0/, ""), x: N, y: q + L * 0.35, size: L, font: ht, color: $ > 0.6 ? "#111" : "#eee", align: "center", opacity: e.opacity });
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
const w = Math.min(22 * n.scale, Math.abs(o * n.unitY) * 0.6);
|
|
1906
|
+
return t.rowLabels?.forEach((b, k) => {
|
|
1907
|
+
const [M, $] = n.toScreen([p, f - (k + 0.5) * o]);
|
|
1908
|
+
m.push(...G(H(b, { style: "inline" }), { x: M - w * 0.5, y: $, size: w, color: i.ink, align: "right", opacity: e.opacity * e.draw, idPrefix: `${t.id}.row.${k}.` }));
|
|
1909
|
+
}), t.colLabels?.forEach((b, k) => {
|
|
1910
|
+
const [M, $] = n.toScreen([p + (k + 0.5) * g, f]);
|
|
1911
|
+
m.push(...G(H(b, { style: "inline" }), { x: M, y: $ - w * 0.8, size: w, color: i.ink, opacity: e.opacity * e.draw, idPrefix: `${t.id}.col.${k}.` }));
|
|
1912
|
+
}), m;
|
|
1913
|
+
}
|
|
1914
|
+
const cs = /* @__PURE__ */ new Map();
|
|
1915
|
+
function ls(t, e) {
|
|
1916
|
+
const n = t.region ?? [e.plane.x, e.plane.y], i = t.resolution ?? 80, s = Object.entries(e.scope).filter(([c]) => !c.includes(".")), r = le(cs, JSON.stringify([t.expr, t.levels, n, i, s]), () => {
|
|
1917
|
+
const c = qe(t.expr), d = Zi((g, o) => c(g, o, e.scope), n[0], n[1], i), u = d.values.flat().filter(Number.isFinite), p = Math.min(...u), h = Math.max(...u), y = typeof t.levels == "number" ? t.levels : 10;
|
|
1918
|
+
return (Array.isArray(t.levels) ? t.levels : Array.from({ length: y }, (g, o) => p + (h - p) * (o + 1) / (y + 1))).map((g) => Xi(d.values, d.x0, d.y0, d.dx, d.dy, g));
|
|
1919
|
+
}), a = [], l = t.colormap ?? "viridis";
|
|
1920
|
+
return r.forEach((c, d) => {
|
|
1921
|
+
const u = t.color ? T(e.theme, t.color, e.theme.ink) : Ce(l, r.length === 1 ? 0.6 : 0.15 + 0.85 * d / (r.length - 1));
|
|
1922
|
+
_(c.map((p) => p.map(e.plane.toScreen)), e.draw).forEach((p, h) => {
|
|
1923
|
+
a.push({ type: "line", id: `${t.id}.${d}.${h}`, points: p, stroke: u, width: (t.width ?? 1.8) * e.plane.scale, opacity: e.opacity });
|
|
1924
|
+
});
|
|
1925
|
+
}), a;
|
|
1926
|
+
}
|
|
1927
|
+
const us = /* @__PURE__ */ new Map();
|
|
1928
|
+
function Ln(t, e, n) {
|
|
1929
|
+
const i = wt(e, t.start), s = E(e, t.rate), r = t.momentum === void 0 ? 0 : E(e, t.momentum), a = Math.min(500, Math.max(0, ue(E(e, t.steps)))), l = Object.entries(n).filter(([h]) => !h.includes(".")), c = le(us, JSON.stringify([t.expr, i, s, r, l]), () => Ji(t.expr, i, s, 500, r, n)), d = Math.min(c.length - 1, Math.floor(a)), u = d < c.length - 1 ? a - d : 0, p = u > 0 ? It(c[d], c[d + 1], u) : c[d];
|
|
1930
|
+
return { path: c.slice(0, d + 1), here: p, step: d, diverged: c.length < 501 && a > c.length - 1 };
|
|
1931
|
+
}
|
|
1932
|
+
function ds(t, e) {
|
|
1933
|
+
const { path: n, here: i } = Ln(t, e.values, e.scope), s = T(e.theme, t.color, e.theme.colors.red), r = [...n, i].map(e.plane.toScreen), a = [];
|
|
1934
|
+
r.length >= 2 && a.push({ type: "line", id: `${t.id}.path`, points: r, stroke: s, width: (t.width ?? 2.5) * e.plane.scale, opacity: e.opacity * 0.9 }), n.forEach((d, u) => {
|
|
1935
|
+
const [p, h] = e.plane.toScreen(d);
|
|
1936
|
+
a.push({ type: "circle", id: `${t.id}.step.${u}`, x: p, y: h, r: 3 * e.plane.scale, fill: s, opacity: e.opacity * 0.8 });
|
|
1937
|
+
});
|
|
1938
|
+
const [l, c] = e.plane.toScreen(i);
|
|
1939
|
+
return a.push({ type: "circle", id: `${t.id}.ball`, x: l, y: c, r: 8 * e.plane.scale, fill: T(e.theme, "yellow", e.theme.colors.yellow), stroke: e.theme.background, width: 2 * e.plane.scale, opacity: e.opacity }), a;
|
|
1940
|
+
}
|
|
1941
|
+
const hs = /* @__PURE__ */ new Map();
|
|
1942
|
+
function Cn(t, e) {
|
|
1943
|
+
const n = t.centres ?? [[-1.5, -1], [1.5, 1]], i = Math.min(500, Math.max(0, ue(E(e, t.epochs)))), [s, r, a] = t.start ?? [0.9, -1.1, 0.8], { data: l, models: c } = le(hs, JSON.stringify([n, t.count, t.spread, t.seed ?? t.id, t.rate, s, r, a]), () => {
|
|
1944
|
+
const f = Pn(n, t.count ?? 40, t.spread ?? 0.9, t.seed ?? t.id);
|
|
1945
|
+
return { data: f, models: Qi(f, 500, t.rate ?? 0.5, { w: [s, r], b: a }) };
|
|
1946
|
+
}), d = Math.floor(i), u = i - d, p = c[d], h = c[Math.min(c.length - 1, d + 1)], y = { w: It(p.w, h.w, u), b: p.b + (h.b - p.b) * u };
|
|
1947
|
+
return { data: l, model: y, epochs: i };
|
|
1948
|
+
}
|
|
1949
|
+
function ps(t, e) {
|
|
1950
|
+
const { plane: n, theme: i } = e, { data: s, model: r } = Cn(t, e.values), a = [], l = [T(i, "blue", i.colors.blue), T(i, "orange", i.colors.orange)];
|
|
1951
|
+
if (t.probability !== !1) {
|
|
1952
|
+
const [p, h] = n.x, [y, f] = n.y, g = (h - p) / 32, o = (f - y) / 32;
|
|
1953
|
+
for (let m = 0; m < 32; m++)
|
|
1954
|
+
for (let v = 0; v < 32; v++) {
|
|
1955
|
+
const x = ce(r, [p + (v + 0.5) * g, y + (m + 0.5) * o]), w = [[p + v * g, y + m * o], [p + (v + 1.02) * g, y + m * o], [p + (v + 1.02) * g, y + (m + 1.02) * o], [p + v * g, y + (m + 1.02) * o]].map(n.toScreen);
|
|
1956
|
+
a.push({ type: "line", id: `${t.id}.p.${m}.${v}`, points: w, closed: !0, fill: Nn(x >= 0.5 ? l[1] : l[0], i.background, e.opacity * Math.abs(x - 0.5) * 0.5) });
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
s.forEach(({ point: u, label: p }, h) => {
|
|
1960
|
+
const [y, f] = n.toScreen(u);
|
|
1961
|
+
a.push({ type: "circle", id: `${t.id}.pt.${h}`, x: y, y: f, r: 4.5 * n.scale, fill: l[p], stroke: i.background, width: 1 * n.scale, opacity: e.opacity * e.draw });
|
|
1962
|
+
});
|
|
1963
|
+
const [c, d] = r.w;
|
|
1964
|
+
if (Math.hypot(c, d) > 1e-6) {
|
|
1965
|
+
const [u, p] = n.x, [h, y] = n.y, f = Math.abs(d) > Math.abs(c) ? [[u, -(c * u + r.b) / d], [p, -(c * p + r.b) / d]] : [[-(d * h + r.b) / c, h], [-(d * y + r.b) / c, y]];
|
|
1966
|
+
a.push({ type: "line", id: `${t.id}.boundary`, points: f.map(n.toScreen), stroke: i.ink, width: 3 * n.scale, opacity: e.opacity, dash: [12 * n.scale, 8 * n.scale] });
|
|
1967
|
+
}
|
|
1968
|
+
return a;
|
|
1969
|
+
}
|
|
1970
|
+
const fs = /* @__PURE__ */ new Map();
|
|
1971
|
+
function qn(t, e) {
|
|
1972
|
+
const { points: n, history: i } = le(fs, JSON.stringify([t.centres, t.count, t.spread, t.seed ?? t.id, t.k]), () => {
|
|
1973
|
+
const c = Pn(t.centres, t.count ?? 30, t.spread ?? 0.7, t.seed ?? t.id).map((h) => h.point), d = t.k ?? t.centres.length, u = [c.reduce((h, y) => h + y[0], 0) / c.length, c.reduce((h, y) => h + y[1], 0) / c.length], p = [...c].sort((h, y) => Math.hypot(h[0] - u[0], h[1] - u[1]) - Math.hypot(y[0] - u[0], y[1] - u[1])).slice(0, d);
|
|
1974
|
+
return { points: c, history: ns(c, d, 20, p) };
|
|
1975
|
+
}), s = Math.min(i.length - 1, Math.max(0, ue(E(e, t.iteration)))), r = Math.floor(s), a = s - r, l = i[r].map((c, d) => It(c, i[Math.min(i.length - 1, r + 1)][d], a));
|
|
1976
|
+
return { points: n, history: i, centroids: l, owners: ze(n, i[r]), iteration: s, iterations: i.length - 1 };
|
|
1977
|
+
}
|
|
1978
|
+
function ys(t, e) {
|
|
1979
|
+
const { plane: n, theme: i } = e, { points: s, centroids: r, owners: a, history: l, iteration: c } = qn(t, e.values), d = ["blue", "orange", "green", "pink", "purple", "teal"].map((p) => T(i, p, i.colors.blue)), u = [];
|
|
1980
|
+
return s.forEach((p, h) => {
|
|
1981
|
+
const [y, f] = n.toScreen(p);
|
|
1982
|
+
u.push({ type: "circle", id: `${t.id}.pt.${h}`, x: y, y: f, r: 4.5 * n.scale, fill: d[a[h] % d.length], opacity: e.opacity * e.draw * 0.85 });
|
|
1983
|
+
}), r.forEach((p, h) => {
|
|
1984
|
+
const y = l.slice(0, Math.floor(c) + 1).map((m) => m[h]);
|
|
1985
|
+
y.push(p), y.length >= 2 && u.push({ type: "line", id: `${t.id}.trail.${h}`, points: y.map(n.toScreen), stroke: d[h % d.length], width: 2 * n.scale, opacity: e.opacity * 0.7, dash: [6 * n.scale, 5 * n.scale] });
|
|
1986
|
+
const [f, g] = n.toScreen(p), o = 11 * n.scale;
|
|
1987
|
+
u.push({ type: "line", id: `${t.id}.centroid.${h}`, points: [[f, g - o], [f + o, g], [f, g + o], [f - o, g]], closed: !0, fill: d[h % d.length], stroke: i.ink, width: 2.5 * n.scale, opacity: e.opacity });
|
|
1988
|
+
}), u;
|
|
1989
|
+
}
|
|
1990
|
+
function ms(t, e, n) {
|
|
1991
|
+
switch (t.kind) {
|
|
1992
|
+
case "network": {
|
|
1993
|
+
const { activations: i } = Fn(t, e);
|
|
1994
|
+
return Object.fromEntries(i[i.length - 1].map((s, r) => [`${t.id}.out${r}`, s]));
|
|
1995
|
+
}
|
|
1996
|
+
case "descent": {
|
|
1997
|
+
const { here: i, step: s } = Ln(t, e, n);
|
|
1998
|
+
return { [`${t.id}.x`]: i[0], [`${t.id}.y`]: i[1], [`${t.id}.loss`]: qe(t.expr)(i[0], i[1], n), [`${t.id}.step`]: s };
|
|
1999
|
+
}
|
|
2000
|
+
case "classifier": {
|
|
2001
|
+
const { data: i, model: s, epochs: r } = Cn(t, e);
|
|
2002
|
+
return { [`${t.id}.accuracy`]: ts(s, i), [`${t.id}.loss`]: es(s, i), [`${t.id}.epoch`]: Math.floor(r) };
|
|
2003
|
+
}
|
|
2004
|
+
case "kmeans": {
|
|
2005
|
+
const { points: i, centroids: s, iteration: r, iterations: a } = qn(t, e);
|
|
2006
|
+
return { [`${t.id}.inertia`]: is(i, s), [`${t.id}.iteration`]: Math.floor(r), [`${t.id}.iterations`]: a };
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
function me(t, e, n, i = 512) {
|
|
1391
2011
|
if (e === n) return 0;
|
|
1392
2012
|
const s = (n - e) / i;
|
|
1393
2013
|
let r = t(e) + t(n);
|
|
1394
|
-
for (let
|
|
2014
|
+
for (let a = 1; a < i; a++) r += t(e + a * s) * (a % 2 ? 4 : 2);
|
|
1395
2015
|
return r * s / 3;
|
|
1396
2016
|
}
|
|
1397
|
-
function
|
|
2017
|
+
function zn(t, e, n, i, s) {
|
|
1398
2018
|
const r = (n - e) / i;
|
|
1399
|
-
return Array.from({ length: i }, (
|
|
2019
|
+
return Array.from({ length: i }, (a, l) => {
|
|
1400
2020
|
const c = e + l * r, d = c + r;
|
|
1401
2021
|
if (s === "trapezoid") return [c, d, t(c), t(d)];
|
|
1402
2022
|
const u = t(s === "left" ? c : s === "right" ? d : (c + d) / 2);
|
|
1403
2023
|
return [c, d, u, u];
|
|
1404
2024
|
});
|
|
1405
2025
|
}
|
|
1406
|
-
const
|
|
1407
|
-
function
|
|
2026
|
+
const jn = (t) => Math.min(400, Math.max(1, Math.round(t)));
|
|
2027
|
+
function _n(t, e, n) {
|
|
1408
2028
|
const i = {}, s = { ...n };
|
|
1409
2029
|
for (const r of t)
|
|
1410
2030
|
switch (r.kind) {
|
|
1411
2031
|
case "tangent": {
|
|
1412
|
-
const
|
|
1413
|
-
Object.assign(i, { [`${r.id}.slope`]: d, [`${r.id}.x`]: l, [`${r.id}.y`]:
|
|
2032
|
+
const a = Y(r.expr), l = E(e, r.at), c = r.h === void 0 ? 0 : E(e, r.h), d = Math.abs(c) > 1e-9 ? (a(l + c, s) - a(l, s)) / c : Pe(r.expr, 1)(l, s);
|
|
2033
|
+
Object.assign(i, { [`${r.id}.slope`]: d, [`${r.id}.x`]: l, [`${r.id}.y`]: a(l, s) });
|
|
1414
2034
|
break;
|
|
1415
2035
|
}
|
|
1416
2036
|
case "riemann": {
|
|
1417
|
-
const
|
|
1418
|
-
Object.assign(i, { [`${r.id}.sum`]: p, [`${r.id}.exact`]:
|
|
2037
|
+
const a = Y(r.expr), l = E(e, r.from), c = E(e, r.to), d = jn(E(e, r.n)), p = zn((h) => a(h, s), l, c, d, r.rule ?? "left").reduce((h, [y, f, g, o]) => h + (g + o) / 2 * (f - y), 0);
|
|
2038
|
+
Object.assign(i, { [`${r.id}.sum`]: p, [`${r.id}.exact`]: me((h) => a(h, s), l, c), [`${r.id}.n`]: d });
|
|
1419
2039
|
break;
|
|
1420
2040
|
}
|
|
1421
2041
|
case "area": {
|
|
1422
|
-
const
|
|
1423
|
-
i[`${r.id}.value`] =
|
|
2042
|
+
const a = Y(r.expr), l = r.lower ? Y(r.lower) : () => 0;
|
|
2043
|
+
i[`${r.id}.value`] = me((c) => a(c, s) - l(c, s), E(e, r.from), E(e, r.to));
|
|
1424
2044
|
break;
|
|
1425
2045
|
}
|
|
1426
2046
|
case "point":
|
|
1427
2047
|
if (r.on !== void 0 && r.x !== void 0) {
|
|
1428
|
-
const
|
|
1429
|
-
Object.assign(i, { [`${r.id}.x`]:
|
|
2048
|
+
const a = E(e, r.x);
|
|
2049
|
+
Object.assign(i, { [`${r.id}.x`]: a, [`${r.id}.y`]: Y(r.on)(a, s) });
|
|
1430
2050
|
}
|
|
1431
2051
|
break;
|
|
1432
2052
|
case "histogram": {
|
|
1433
|
-
const
|
|
1434
|
-
Object.assign(i, { [`${r.id}.count`]:
|
|
2053
|
+
const a = fn(kt(e, r.distribution), r.seed ?? r.id, ee(E(e, r.count))), { mean: l, sd: c } = oi(a);
|
|
2054
|
+
Object.assign(i, { [`${r.id}.count`]: a.length, [`${r.id}.mean`]: l, [`${r.id}.sd`]: c });
|
|
1435
2055
|
break;
|
|
1436
2056
|
}
|
|
1437
2057
|
case "distribution": {
|
|
1438
|
-
const
|
|
2058
|
+
const a = kt(e, r.distribution);
|
|
1439
2059
|
let l = 0;
|
|
1440
2060
|
if (r.shade) {
|
|
1441
|
-
const [c, d] = [
|
|
1442
|
-
if (
|
|
1443
|
-
for (let u = Math.max(0, Math.ceil(c)); u <= Math.floor(d) && u <= 5e3; u++) l +=
|
|
2061
|
+
const [c, d] = [E(e, r.shade[0]), E(e, r.shade[1])].sort((u, p) => u - p);
|
|
2062
|
+
if (re(a))
|
|
2063
|
+
for (let u = Math.max(0, Math.ceil(c)); u <= Math.floor(d) && u <= 5e3; u++) l += ut(a, u);
|
|
1444
2064
|
else
|
|
1445
|
-
l =
|
|
2065
|
+
l = me((u) => ut(a, u), c, d, 2048);
|
|
1446
2066
|
}
|
|
1447
|
-
Object.assign(i, { [`${r.id}.p`]: l, [`${r.id}.mean`]:
|
|
2067
|
+
Object.assign(i, { [`${r.id}.p`]: l, [`${r.id}.mean`]: Ct(a), [`${r.id}.sd`]: qt(a) });
|
|
1448
2068
|
break;
|
|
1449
2069
|
}
|
|
1450
2070
|
case "galton":
|
|
1451
|
-
i[`${r.id}.landed`] = Math.max(0, Math.floor(
|
|
2071
|
+
i[`${r.id}.landed`] = Math.max(0, Math.floor(E(e, r.balls)));
|
|
1452
2072
|
break;
|
|
1453
2073
|
case "scatter": {
|
|
1454
|
-
const
|
|
2074
|
+
const a = mn(xn(r, { values: e }), r.seed ?? r.id, ee(E(e, r.count))), l = r.inside ? ot(r.inside) : void 0, c = l ? a.filter(([u, p]) => et(l, { ...s, x: u, y: p }) <= 0).length : 0, d = gn(a);
|
|
1455
2075
|
Object.assign(i, {
|
|
1456
|
-
[`${r.id}.count`]:
|
|
2076
|
+
[`${r.id}.count`]: a.length,
|
|
1457
2077
|
[`${r.id}.inside`]: c,
|
|
1458
|
-
[`${r.id}.ratio`]:
|
|
2078
|
+
[`${r.id}.ratio`]: a.length ? c / a.length : 0,
|
|
1459
2079
|
[`${r.id}.slope`]: d?.slope ?? 0,
|
|
1460
2080
|
[`${r.id}.intercept`]: d?.intercept ?? 0,
|
|
1461
2081
|
[`${r.id}.r`]: d?.r ?? 0
|
|
@@ -1463,52 +2083,71 @@ function sn(t, e, n) {
|
|
|
1463
2083
|
break;
|
|
1464
2084
|
}
|
|
1465
2085
|
case "bayes": {
|
|
1466
|
-
const
|
|
1467
|
-
Object.assign(i, { [`${r.id}.prior`]:
|
|
2086
|
+
const a = E(e, r.prior), l = ai(a, E(e, r.truePositive), E(e, r.falsePositive));
|
|
2087
|
+
Object.assign(i, { [`${r.id}.prior`]: a, [`${r.id}.posterior`]: l.posterior, [`${r.id}.positive`]: l.positive, [`${r.id}.truePositive`]: l.truePositive, [`${r.id}.falsePositive`]: l.falsePositive });
|
|
2088
|
+
break;
|
|
2089
|
+
}
|
|
2090
|
+
case "graph": {
|
|
2091
|
+
const a = Tn(r, e);
|
|
2092
|
+
if (a && (i[`${r.id}.visited`] = a.done, i[`${r.id}.steps`] = a.events.length, r.search?.kind === "dijkstra")) {
|
|
2093
|
+
const l = a.events[a.done - 1]?.distances ?? {};
|
|
2094
|
+
for (const c of r.nodes) i[`${r.id}.d.${c.id}`] = l[c.id] ?? 1 / 0;
|
|
2095
|
+
}
|
|
2096
|
+
break;
|
|
2097
|
+
}
|
|
2098
|
+
case "clock": {
|
|
2099
|
+
const a = E(e, r.value);
|
|
2100
|
+
Object.assign(i, { [`${r.id}.hour`]: On(a, r.modulus), [`${r.id}.turns`]: Math.floor(Math.round(a) / r.modulus) });
|
|
1468
2101
|
break;
|
|
1469
2102
|
}
|
|
2103
|
+
case "network":
|
|
2104
|
+
case "descent":
|
|
2105
|
+
case "classifier":
|
|
2106
|
+
case "kmeans":
|
|
2107
|
+
Object.assign(i, ms(r, e, s));
|
|
2108
|
+
break;
|
|
1470
2109
|
case "taylor":
|
|
1471
|
-
i[`${r.id}.order`] = Math.min(20, Math.max(0,
|
|
2110
|
+
i[`${r.id}.order`] = Math.min(20, Math.max(0, E(e, r.order))), i[`${r.id}.degree`] = Math.floor(i[`${r.id}.order`]);
|
|
1472
2111
|
break;
|
|
1473
2112
|
}
|
|
1474
2113
|
return i;
|
|
1475
2114
|
}
|
|
1476
|
-
const
|
|
1477
|
-
function
|
|
2115
|
+
const K = (t, e, n) => t + (e - t) * n;
|
|
2116
|
+
function en(t, e, n) {
|
|
1478
2117
|
return t.kind === "stroke" ? { ...t, points: t.points.map(([i, s]) => [i + e, s + n]) } : { ...t, x: t.x + e, y: t.y + n };
|
|
1479
2118
|
}
|
|
1480
|
-
function
|
|
2119
|
+
function gs(t, e, n) {
|
|
1481
2120
|
if (t.kind === "glyph" && e.kind === "glyph" && t.text === e.text)
|
|
1482
|
-
return { ...e, x:
|
|
2121
|
+
return { ...e, x: K(t.x, e.x, n), y: K(t.y, e.y, n), width: K(t.width, e.width, n), size: K(t.size, e.size, n) };
|
|
1483
2122
|
if (t.kind === "rule" && e.kind === "rule")
|
|
1484
|
-
return { ...e, x:
|
|
2123
|
+
return { ...e, x: K(t.x, e.x, n), y: K(t.y, e.y, n), width: K(t.width, e.width, n), height: K(t.height, e.height, n) };
|
|
1485
2124
|
if (t.kind === "stroke" && e.kind === "stroke" && t.points.length === e.points.length)
|
|
1486
|
-
return { ...e, width:
|
|
1487
|
-
}
|
|
1488
|
-
const
|
|
1489
|
-
function
|
|
1490
|
-
const i = Math.min(1, Math.max(0, n)), s = t.layout.pieces.map((
|
|
1491
|
-
if (i === 0) return s.map((
|
|
1492
|
-
if (i === 1) return r.map((
|
|
1493
|
-
const
|
|
2125
|
+
return { ...e, width: K(t.width, e.width, n), points: t.points.map(([i, s], r) => [K(i, e.points[r][0], n), K(s, e.points[r][1], n)]) };
|
|
2126
|
+
}
|
|
2127
|
+
const bs = (t) => t * t * (3 - 2 * t);
|
|
2128
|
+
function vs(t, e, n) {
|
|
2129
|
+
const i = Math.min(1, Math.max(0, n)), s = t.layout.pieces.map((y) => en(y, t.x, t.y)), r = e.layout.pieces.map((y) => en(y, e.x, e.y));
|
|
2130
|
+
if (i === 0) return s.map((y) => ({ ...y, opacity: 1 }));
|
|
2131
|
+
if (i === 1) return r.map((y) => ({ ...y, opacity: 1 }));
|
|
2132
|
+
const a = (y) => {
|
|
1494
2133
|
const f = /* @__PURE__ */ new Map();
|
|
1495
|
-
for (const
|
|
2134
|
+
for (const g of y) f.set(g.id, [...f.get(g.id) ?? [], g]);
|
|
1496
2135
|
return f;
|
|
1497
|
-
}, l =
|
|
1498
|
-
for (const
|
|
1499
|
-
const f = l.get(
|
|
1500
|
-
for (let
|
|
1501
|
-
const
|
|
1502
|
-
if (
|
|
1503
|
-
d.push({ ...
|
|
2136
|
+
}, l = a(s), c = a(r), d = [], u = bs(i), p = Math.max(0, 1 - i * 2), h = Math.max(0, i * 2 - 1);
|
|
2137
|
+
for (const y of /* @__PURE__ */ new Set([...l.keys(), ...c.keys()])) {
|
|
2138
|
+
const f = l.get(y) ?? [], g = c.get(y) ?? [], o = Math.max(f.length, g.length);
|
|
2139
|
+
for (let m = 0; m < o; m++) {
|
|
2140
|
+
const v = f[m], x = g[m], w = v && x ? gs(v, x, u) : void 0;
|
|
2141
|
+
if (w) {
|
|
2142
|
+
d.push({ ...w, opacity: 1 });
|
|
1504
2143
|
continue;
|
|
1505
2144
|
}
|
|
1506
|
-
|
|
2145
|
+
v && d.push({ ...v, opacity: p }), x && d.push({ ...x, opacity: h });
|
|
1507
2146
|
}
|
|
1508
2147
|
}
|
|
1509
|
-
return d.filter((
|
|
2148
|
+
return d.filter((y) => y.opacity > 0);
|
|
1510
2149
|
}
|
|
1511
|
-
const
|
|
2150
|
+
const nn = [
|
|
1512
2151
|
"grid",
|
|
1513
2152
|
"axes",
|
|
1514
2153
|
"vector",
|
|
@@ -1528,8 +2167,17 @@ const Ie = [
|
|
|
1528
2167
|
"distribution",
|
|
1529
2168
|
"galton",
|
|
1530
2169
|
"scatter",
|
|
1531
|
-
"bayes"
|
|
1532
|
-
|
|
2170
|
+
"bayes",
|
|
2171
|
+
"graph",
|
|
2172
|
+
"venn",
|
|
2173
|
+
"clock",
|
|
2174
|
+
"network",
|
|
2175
|
+
"heatmap",
|
|
2176
|
+
"contours",
|
|
2177
|
+
"descent",
|
|
2178
|
+
"classifier",
|
|
2179
|
+
"kmeans"
|
|
2180
|
+
], Te = {
|
|
1533
2181
|
dark: {
|
|
1534
2182
|
background: "#0f1117",
|
|
1535
2183
|
ink: "#f2f2f2",
|
|
@@ -1554,7 +2202,7 @@ const Ie = [
|
|
|
1554
2202
|
axes: "#eef0e6",
|
|
1555
2203
|
colors: { blue: "#9fd3f0", green: "#b9e39a", red: "#f59a8f", yellow: "#f6e58d", purple: "#d0b5f2", orange: "#f7c08a", teal: "#a3e4d4", pink: "#f4b6dc", ink: "#eef0e6", grey: "#a9b0a6" }
|
|
1556
2204
|
}
|
|
1557
|
-
},
|
|
2205
|
+
}, ws = /* @__PURE__ */ new Set([
|
|
1558
2206
|
"x",
|
|
1559
2207
|
"y",
|
|
1560
2208
|
"z",
|
|
@@ -1588,245 +2236,300 @@ const Ie = [
|
|
|
1588
2236
|
"clipLeft",
|
|
1589
2237
|
"quaternion"
|
|
1590
2238
|
]);
|
|
1591
|
-
function
|
|
1592
|
-
const e = (
|
|
1593
|
-
throw new Error(`math figure: ${
|
|
2239
|
+
function zt(t) {
|
|
2240
|
+
const e = (o) => {
|
|
2241
|
+
throw new Error(`math figure: ${o}`);
|
|
1594
2242
|
};
|
|
1595
2243
|
(!t || typeof t != "object") && e("expected a figure object"), (!(t.width > 0) || !(t.height > 0)) && e("width and height must be positive numbers (px)");
|
|
1596
|
-
for (const
|
|
1597
|
-
const
|
|
1598
|
-
|
|
2244
|
+
for (const o of ["x", "y"]) {
|
|
2245
|
+
const m = t[o];
|
|
2246
|
+
m !== void 0 && !(Array.isArray(m) && m.length === 2 && m.every(Number.isFinite) && m[0] < m[1]) && e(`${o} must be [min, max] with min < max`);
|
|
1599
2247
|
}
|
|
1600
|
-
t.theme !== void 0 && !(t.theme in
|
|
2248
|
+
t.theme !== void 0 && !(t.theme in Te) && e(R("theme", t.theme, Object.keys(Te))), Array.isArray(t.items) || e("items must be an array");
|
|
1601
2249
|
const n = t.values ?? {};
|
|
1602
|
-
for (const [
|
|
1603
|
-
/^[A-Za-z_]\w*$/.test(
|
|
1604
|
-
const i =
|
|
1605
|
-
|
|
1606
|
-
},
|
|
1607
|
-
|
|
1608
|
-
}, l = (
|
|
1609
|
-
let
|
|
2250
|
+
for (const [o, m] of Object.entries(n))
|
|
2251
|
+
/^[A-Za-z_]\w*$/.test(o) || e(`value name "${o}" must be letters, digits and _ (starting with a letter)`), ws.has(o) && e(`"${o}" cannot name a value: it is ${o === "x" || o === "t" ? "the variable of functions and curves" : "a property of the figure itself (its place, size or look)"}`), typeof m == "number" && Number.isFinite(m) || st(m) || vt(m) || e(`value "${o}" must be a number, an [x, y] vector or an [a, b, c, d] matrix`);
|
|
2252
|
+
const i = hn(n), s = Object.keys(n).filter((o) => typeof n[o] == "number"), r = (o, m, v) => {
|
|
2253
|
+
v !== void 0 && (typeof v == "string" ? (v in n || e(`${o.id}.${m}: ${R("value", v, Object.keys(n))}`), st(n[v]) || e(`${o.id}.${m}: value "${v}" is not an [x, y] vector`)) : st(v) || e(`${o.id}.${m} must be [x, y] or the name of a vector value`));
|
|
2254
|
+
}, a = (o, m, v) => {
|
|
2255
|
+
v !== void 0 && (v in n || e(`${o.id}.${m}: ${R("value", v, Object.keys(n))}`), vt(n[v]) || e(`${o.id}.${m}: value "${v}" is not an [a, b, c, d] matrix`));
|
|
2256
|
+
}, l = (o, m, v, x) => {
|
|
2257
|
+
let w = [];
|
|
1610
2258
|
try {
|
|
1611
|
-
|
|
2259
|
+
w = Ue(ot(v));
|
|
1612
2260
|
} catch (b) {
|
|
1613
|
-
e(`${
|
|
1614
|
-
}
|
|
1615
|
-
for (const b of
|
|
1616
|
-
b !==
|
|
1617
|
-
}, c = [], d = (
|
|
1618
|
-
c.push([
|
|
1619
|
-
}, u = (
|
|
1620
|
-
|
|
1621
|
-
}, p = (
|
|
1622
|
-
(!
|
|
1623
|
-
for (const [
|
|
1624
|
-
|
|
1625
|
-
const
|
|
1626
|
-
|
|
1627
|
-
}, h = (
|
|
1628
|
-
let
|
|
2261
|
+
e(`${o.id}.${m}: ${b.message}`);
|
|
2262
|
+
}
|
|
2263
|
+
for (const b of w)
|
|
2264
|
+
b !== x && !(b in Kt) && !s.includes(b) && e(`${o.id}.${m}: "${b}" is neither ${x} nor a number value (${R("value", b, [x, ...s])})`);
|
|
2265
|
+
}, c = [], d = (o, m, v) => {
|
|
2266
|
+
c.push([o, m, v]);
|
|
2267
|
+
}, u = (o, m, v) => {
|
|
2268
|
+
v !== void 0 && (typeof v == "string" ? (v in n || e(`${o.id}.${m}: ${R("value", v, s)}`), typeof n[v] != "number" && e(`${o.id}.${m}: value "${v}" is not a number`)) : Number.isFinite(v) || e(`${o.id}.${m} must be a number or the name of a number value`));
|
|
2269
|
+
}, p = (o, m, v) => {
|
|
2270
|
+
(!v || typeof v != "object" || !Qt.includes(v.kind)) && e(`${o.id}.${m}: ${R("distribution", v?.kind, Qt)}`);
|
|
2271
|
+
for (const [w, b] of Object.entries(v))
|
|
2272
|
+
w !== "kind" && (w === "of" ? p(o, `${m}.of`, b) : u(o, `${m}.${w}`, b));
|
|
2273
|
+
const x = yn(kt(n, v));
|
|
2274
|
+
x && e(`${o.id}.${m}: ${x}`);
|
|
2275
|
+
}, h = (o, m, v) => {
|
|
2276
|
+
let x = [];
|
|
1629
2277
|
try {
|
|
1630
|
-
|
|
1631
|
-
} catch (
|
|
1632
|
-
e(`${
|
|
2278
|
+
x = Ue(ot(v));
|
|
2279
|
+
} catch (w) {
|
|
2280
|
+
e(`${o.id}.${m}: ${w.message}`);
|
|
1633
2281
|
}
|
|
1634
|
-
for (const
|
|
1635
|
-
|
|
1636
|
-
},
|
|
2282
|
+
for (const w of x)
|
|
2283
|
+
w !== "x" && w !== "y" && !s.includes(w) && e(`${o.id}.${m}: "${w}" is neither x, y nor a number value`);
|
|
2284
|
+
}, y = (o, m, v, x) => {
|
|
1637
2285
|
try {
|
|
1638
|
-
let
|
|
1639
|
-
for (let b = 0; b <
|
|
1640
|
-
} catch (
|
|
1641
|
-
e(`${
|
|
2286
|
+
let w = ot(v);
|
|
2287
|
+
for (let b = 0; b < x; b++) w = X(w);
|
|
2288
|
+
} catch (w) {
|
|
2289
|
+
e(`${o.id}.${m}: ${w.message} (calculus needs functions with derivatives)`);
|
|
1642
2290
|
}
|
|
1643
2291
|
}, f = /* @__PURE__ */ new Set();
|
|
1644
|
-
for (const
|
|
1645
|
-
switch ((!
|
|
2292
|
+
for (const o of t.items)
|
|
2293
|
+
switch ((!o || typeof o != "object") && e("every item must be an object"), nn.includes(o.kind) || e(R("item kind", o.kind, nn)), (typeof o.id != "string" || !/^[A-Za-z_][\w-]*$/.test(o.id)) && e(`a ${o.kind} needs an id (letters, digits, _ and -)`), f.has(o.id) && e(`two items have the id "${o.id}"`), o.id in n && e(`"${o.id}" is both an item id and a value name`), f.add(o.id), o.kind) {
|
|
1646
2294
|
case "grid":
|
|
1647
|
-
|
|
2295
|
+
o.step !== void 0 && !(o.step > 0) && e(`${o.id}.step must be positive`), a(o, "transform", o.transform);
|
|
1648
2296
|
break;
|
|
1649
2297
|
case "vector":
|
|
1650
|
-
r(
|
|
2298
|
+
r(o, "to", o.to), r(o, "from", o.from), a(o, "transform", o.transform), o.label && d(o, "label", o.label);
|
|
1651
2299
|
break;
|
|
1652
2300
|
case "basis":
|
|
1653
|
-
o
|
|
2301
|
+
a(o, "transform", o.transform);
|
|
1654
2302
|
break;
|
|
1655
2303
|
case "point":
|
|
1656
|
-
|
|
2304
|
+
o.at === void 0 == (o.on === void 0) && e(`${o.id} needs at, or on with x (a point on a curve)`), o.on !== void 0 && (o.x === void 0 && e(`${o.id}: a point on a curve needs x`), l(o, "on", o.on, "x"), u(o, "x", o.x)), r(o, "at", o.at), a(o, "transform", o.transform), o.label && d(o, "label", o.label);
|
|
1657
2305
|
break;
|
|
1658
2306
|
case "function":
|
|
1659
|
-
l(
|
|
2307
|
+
l(o, "expr", o.expr, "x"), o.derivative !== void 0 && ((!Number.isInteger(o.derivative) || o.derivative < 0 || o.derivative > 8) && e(`${o.id}.derivative must be a whole number from 0 to 8`), y(o, "expr", o.expr, o.derivative));
|
|
1660
2308
|
break;
|
|
1661
2309
|
case "tangent":
|
|
1662
|
-
l(
|
|
2310
|
+
l(o, "expr", o.expr, "x"), y(o, "expr", o.expr, 1), u(o, "at", o.at), u(o, "h", o.h), o.label && d(o, "label", o.label);
|
|
1663
2311
|
break;
|
|
1664
2312
|
case "riemann":
|
|
1665
|
-
l(
|
|
2313
|
+
l(o, "expr", o.expr, "x"), u(o, "from", o.from), u(o, "to", o.to), u(o, "n", o.n), o.rule !== void 0 && !["left", "right", "midpoint", "trapezoid"].includes(o.rule) && e(`${o.id}.rule: ${R("rule", o.rule, ["left", "right", "midpoint", "trapezoid"])}`);
|
|
1666
2314
|
break;
|
|
1667
2315
|
case "area":
|
|
1668
|
-
l(
|
|
2316
|
+
l(o, "expr", o.expr, "x"), o.lower !== void 0 && l(o, "lower", o.lower, "x"), u(o, "from", o.from), u(o, "to", o.to);
|
|
1669
2317
|
break;
|
|
1670
2318
|
case "histogram":
|
|
1671
|
-
p(
|
|
2319
|
+
p(o, "distribution", o.distribution), u(o, "count", o.count), o.bins !== void 0 && !(Array.isArray(o.bins) && o.bins.length === 3 && o.bins[1] > o.bins[0] && Number.isInteger(o.bins[2]) && o.bins[2] >= 1 && o.bins[2] <= 500) && e(`${o.id}.bins must be [from, to, count] with from < to and a whole count 1..500`);
|
|
1672
2320
|
break;
|
|
1673
2321
|
case "distribution":
|
|
1674
|
-
p(
|
|
2322
|
+
p(o, "distribution", o.distribution), o.shade && o.shade.forEach((m, v) => u(o, `shade[${v}]`, m));
|
|
1675
2323
|
break;
|
|
1676
2324
|
case "galton":
|
|
1677
|
-
|
|
2325
|
+
o.rows !== void 0 && !(Number.isInteger(o.rows) && o.rows >= 1 && o.rows <= 30) && e(`${o.id}.rows must be a whole number 1..30`), u(o, "balls", o.balls);
|
|
1678
2326
|
break;
|
|
1679
2327
|
case "scatter":
|
|
1680
|
-
(!
|
|
2328
|
+
(!o.points || !["uniform", "linear"].includes(o.points.kind)) && e(`${o.id}.points: ${R("points kind", o.points?.kind, ["uniform", "linear"])}`), o.points.kind === "linear" && (u(o, "points.slope", o.points.slope), u(o, "points.intercept", o.points.intercept), u(o, "points.noise", o.points.noise)), u(o, "count", o.count), o.inside && h(o, "inside", o.inside);
|
|
1681
2329
|
break;
|
|
1682
2330
|
case "bayes":
|
|
1683
|
-
u(
|
|
2331
|
+
u(o, "prior", o.prior), u(o, "truePositive", o.truePositive), u(o, "falsePositive", o.falsePositive);
|
|
2332
|
+
break;
|
|
2333
|
+
case "graph": {
|
|
2334
|
+
(!Array.isArray(o.nodes) || o.nodes.length === 0) && e(`${o.id}.nodes needs at least one node`);
|
|
2335
|
+
const m = o.nodes.map((b) => b.id);
|
|
2336
|
+
new Set(m).size !== m.length && e(`${o.id}: two nodes share an id`);
|
|
2337
|
+
const v = (b, k) => {
|
|
2338
|
+
m.includes(k) || e(`${o.id}.${b}: ${R("node", k, m)}`);
|
|
2339
|
+
};
|
|
2340
|
+
Array.isArray(o.edges) || e(`${o.id}.edges must be an array`), ae(o).forEach((b, k) => {
|
|
2341
|
+
v(`edges[${k}]`, b.from), v(`edges[${k}]`, b.to), b.weight !== void 0 && !(b.weight >= 0) && e(`${o.id}.edges[${k}]: weights must be ≥ 0 (shortest paths need them)`);
|
|
2342
|
+
}), o.tree && v("tree.root", o.tree.root);
|
|
2343
|
+
const x = En(o), w = m.filter((b) => !x.has(b));
|
|
2344
|
+
w.length && e(`${o.id}: nodes ${w.join(", ")} have no "at" and are not reached from the tree root`), o.search && (Ke.includes(o.search.kind) || e(`${o.id}.search: ${R("search", o.search.kind, Ke)}`), v("search.start", o.search.start)), u(o, "step", o.step), o.nodes.forEach((b) => b.label !== void 0 && d(o, `nodes.${b.id}.label`, b.label));
|
|
2345
|
+
break;
|
|
2346
|
+
}
|
|
2347
|
+
case "venn": {
|
|
2348
|
+
(!Array.isArray(o.sets) || o.sets.length < 2 || o.sets.length > 3) && e(`${o.id}.sets: give two or three sets`);
|
|
2349
|
+
const m = o.sets.map((v) => v.id);
|
|
2350
|
+
if (m.every((v) => /^[A-Za-z]\w*$/.test(v)) || e(`${o.id}.sets: ids must be names like A, B, Evens`), o.highlight)
|
|
2351
|
+
try {
|
|
2352
|
+
for (const v of Zt(Sn(o.highlight)))
|
|
2353
|
+
m.includes(v) || e(`${o.id}.highlight: ${R("set", v, m)}`);
|
|
2354
|
+
} catch (v) {
|
|
2355
|
+
e(`${o.id}.highlight: ${v.message}`);
|
|
2356
|
+
}
|
|
2357
|
+
o.sets.forEach((v) => v.label !== void 0 && d(o, `sets.${v.id}.label`, v.label));
|
|
2358
|
+
break;
|
|
2359
|
+
}
|
|
2360
|
+
case "network":
|
|
2361
|
+
(!Array.isArray(o.layers) || o.layers.length < 2 || o.layers.length > 8 || !o.layers.every((m) => Number.isInteger(m) && m >= 1 && m <= 12)) && e(`${o.id}.layers: give 2 to 8 layers of 1 to 12 nodes, like [3, 4, 2]`), o.activation !== void 0 && !Qe.includes(o.activation) && e(`${o.id}.activation: ${R("activation", o.activation, Qe)}`), o.inputs && o.inputs.length > o.layers[0] && e(`${o.id}.inputs: more inputs than the ${o.layers[0]} input nodes`), o.inputs?.forEach((m, v) => u(o, `inputs[${v}]`, m)), u(o, "flow", o.flow), o.labels?.inputs?.forEach((m, v) => d(o, `labels.inputs[${v}]`, m)), o.labels?.outputs?.forEach((m, v) => d(o, `labels.outputs[${v}]`, m));
|
|
2362
|
+
break;
|
|
2363
|
+
case "heatmap":
|
|
2364
|
+
o.cells === void 0 == (o.expr === void 0) && e(`${o.id} needs exactly one of cells or expr`), o.cells && !(Array.isArray(o.cells) && o.cells.length >= 1 && o.cells.length <= 64 && o.cells.every((m) => Array.isArray(m) && m.length === o.cells[0].length && m.length <= 64 && m.every(Number.isFinite))) && e(`${o.id}.cells must be up to 64 equal rows of up to 64 numbers`), o.expr && h(o, "expr", o.expr), o.resolution !== void 0 && !(Number.isInteger(o.resolution) && o.resolution >= 4 && o.resolution <= 120) && e(`${o.id}.resolution must be 4..120`), o.colormap !== void 0 && !Ht.includes(o.colormap) && e(`${o.id}.colormap: ${R("colormap", o.colormap, Ht)}`), o.rowLabels?.forEach((m, v) => d(o, `rowLabels[${v}]`, m)), o.colLabels?.forEach((m, v) => d(o, `colLabels[${v}]`, m));
|
|
2365
|
+
break;
|
|
2366
|
+
case "contours":
|
|
2367
|
+
h(o, "expr", o.expr), o.colormap !== void 0 && !Ht.includes(o.colormap) && e(`${o.id}.colormap: ${R("colormap", o.colormap, Ht)}`), o.resolution !== void 0 && !(Number.isInteger(o.resolution) && o.resolution >= 8 && o.resolution <= 200) && e(`${o.id}.resolution must be 8..200`);
|
|
2368
|
+
break;
|
|
2369
|
+
case "descent":
|
|
2370
|
+
h(o, "expr", o.expr);
|
|
2371
|
+
for (const m of ["x", "y"])
|
|
2372
|
+
try {
|
|
2373
|
+
X(ot(o.expr), m);
|
|
2374
|
+
} catch (v) {
|
|
2375
|
+
e(`${o.id}.expr: ${v.message} (descent needs a gradient)`);
|
|
2376
|
+
}
|
|
2377
|
+
r(o, "start", o.start), u(o, "rate", o.rate), u(o, "steps", o.steps), u(o, "momentum", o.momentum);
|
|
2378
|
+
break;
|
|
2379
|
+
case "classifier":
|
|
2380
|
+
u(o, "epochs", o.epochs), o.count !== void 0 && !(Number.isInteger(o.count) && o.count >= 1 && o.count <= 500) && e(`${o.id}.count must be 1..500 points per cluster`), o.centres !== void 0 && !(o.centres.length === 2 && o.centres.every(st)) && e(`${o.id}.centres must be two [x, y] points`);
|
|
2381
|
+
break;
|
|
2382
|
+
case "kmeans":
|
|
2383
|
+
(!Array.isArray(o.centres) || o.centres.length < 1 || o.centres.length > 6 || !o.centres.every(st)) && e(`${o.id}.centres: give 1 to 6 [x, y] cluster centres`), o.k !== void 0 && !(Number.isInteger(o.k) && o.k >= 1 && o.k <= 6) && e(`${o.id}.k must be 1..6`), u(o, "iteration", o.iteration);
|
|
2384
|
+
break;
|
|
2385
|
+
case "clock":
|
|
2386
|
+
(!Number.isInteger(o.modulus) || o.modulus < 2 || o.modulus > 60) && e(`${o.id}.modulus must be a whole number 2..60`), u(o, "value", o.value);
|
|
1684
2387
|
break;
|
|
1685
2388
|
case "taylor":
|
|
1686
|
-
l(
|
|
2389
|
+
l(o, "expr", o.expr, "x"), y(o, "expr", o.expr, 3), u(o, "at", o.at), u(o, "order", o.order);
|
|
1687
2390
|
break;
|
|
1688
2391
|
case "parametric":
|
|
1689
|
-
l(
|
|
2392
|
+
l(o, "x", o.x, "t"), l(o, "y", o.y, "t"), a(o, "transform", o.transform);
|
|
1690
2393
|
break;
|
|
1691
2394
|
case "polygon":
|
|
1692
|
-
|
|
2395
|
+
o.points !== void 0 && !(Array.isArray(o.points) && o.points.length >= 3 && o.points.every(st)) && e(`${o.id}.points must be three or more [x, y] points`), a(o, "transform", o.transform), o.label && d(o, "label", o.label);
|
|
1693
2396
|
break;
|
|
1694
2397
|
case "line":
|
|
1695
|
-
|
|
2398
|
+
o.along === void 0 == (o.eigen === void 0) && e(`${o.id} needs exactly one of along or eigen`), r(o, "along", o.along), a(o, "eigen", o.eigen);
|
|
1696
2399
|
break;
|
|
1697
2400
|
case "label":
|
|
1698
|
-
r(
|
|
2401
|
+
r(o, "at", o.at), d(o, "tex", o.tex);
|
|
1699
2402
|
break;
|
|
1700
2403
|
case "equation":
|
|
1701
|
-
r(
|
|
2404
|
+
r(o, "at", o.at), (!Array.isArray(o.steps) || o.steps.length === 0) && e(`${o.id}.steps needs at least one TeX step`), o.steps.forEach((m, v) => d(o, `steps[${v}]`, m));
|
|
1702
2405
|
break;
|
|
1703
2406
|
}
|
|
1704
|
-
const
|
|
1705
|
-
for (const [
|
|
2407
|
+
const g = { ...i, ..._n(t.items, n, i) };
|
|
2408
|
+
for (const [o, m, v] of c)
|
|
1706
2409
|
try {
|
|
1707
|
-
|
|
1708
|
-
} catch (
|
|
1709
|
-
e(`${
|
|
2410
|
+
H(v, { values: g });
|
|
2411
|
+
} catch (x) {
|
|
2412
|
+
e(`${o.id}.${m}: ${x.message}`);
|
|
1710
2413
|
}
|
|
1711
2414
|
return t;
|
|
1712
2415
|
}
|
|
1713
|
-
function
|
|
1714
|
-
const { width: e, height: n } = t, i = t.x ?? [-5, 5], s = e / (i[1] - i[0]), r = t.y ?? [-(n / s) / 2, n / s / 2],
|
|
2416
|
+
function Dn(t) {
|
|
2417
|
+
const { width: e, height: n } = t, i = t.x ?? [-5, 5], s = e / (i[1] - i[0]), r = t.y ?? [-(n / s) / 2, n / s / 2], a = n / (r[1] - r[0]);
|
|
1715
2418
|
return {
|
|
1716
2419
|
width: e,
|
|
1717
2420
|
height: n,
|
|
1718
2421
|
x: i,
|
|
1719
2422
|
y: r,
|
|
1720
2423
|
unitX: s,
|
|
1721
|
-
unitY:
|
|
2424
|
+
unitY: a,
|
|
1722
2425
|
scale: Math.min(e, n) / 600,
|
|
1723
|
-
toScreen: ([l, c]) => [(l - i[0]) * s, (r[1] - c) *
|
|
1724
|
-
toWorld: ([l, c]) => [i[0] + l / s, r[1] - c /
|
|
2426
|
+
toScreen: ([l, c]) => [(l - i[0]) * s, (r[1] - c) * a],
|
|
2427
|
+
toWorld: ([l, c]) => [i[0] + l / s, r[1] - c / a]
|
|
1725
2428
|
};
|
|
1726
2429
|
}
|
|
1727
|
-
function
|
|
1728
|
-
const n = Math.max(Math.abs(t.x[0]), Math.abs(t.x[1]), Math.abs(t.y[0]), Math.abs(t.y[1])), [i, s, r,
|
|
2430
|
+
function ks(t, e) {
|
|
2431
|
+
const n = Math.max(Math.abs(t.x[0]), Math.abs(t.x[1]), Math.abs(t.y[0]), Math.abs(t.y[1])), [i, s, r, a] = e, l = Math.hypot(i, s, r, a), c = l === 0 ? 0 : Math.abs(Lt(e)) / l;
|
|
1729
2432
|
return Math.min(n * 12, n / Math.max(c, 0.08)) + 1;
|
|
1730
2433
|
}
|
|
1731
|
-
function
|
|
1732
|
-
const i =
|
|
1733
|
-
for (let
|
|
1734
|
-
const l =
|
|
1735
|
-
r.push({ line: [
|
|
2434
|
+
function sn(t, e, n) {
|
|
2435
|
+
const i = ks(t, e), s = Math.min(120, Math.ceil(i / n)), r = [];
|
|
2436
|
+
for (let a = -s; a <= s; a++) {
|
|
2437
|
+
const l = a * n;
|
|
2438
|
+
r.push({ line: [tt(e, [l, -i]), tt(e, [l, i])].map(t.toScreen), axis: a === 0 }), r.push({ line: [tt(e, [-i, l]), tt(e, [i, l])].map(t.toScreen), axis: a === 0 });
|
|
1736
2439
|
}
|
|
1737
2440
|
return r;
|
|
1738
2441
|
}
|
|
1739
|
-
function
|
|
1740
|
-
const { plane: n, theme: i } = e, s = t.step ?? 1, r = [],
|
|
2442
|
+
function $s(t, e) {
|
|
2443
|
+
const { plane: n, theme: i } = e, s = t.step ?? 1, r = [], a = 1.4 * n.scale;
|
|
1741
2444
|
if (t.ghost)
|
|
1742
|
-
for (const [c, { line: d }] of
|
|
1743
|
-
r.push({ type: "line", id: `${t.id}.ghost.${c}`, points: d, stroke: i.ghost, width:
|
|
1744
|
-
const l =
|
|
1745
|
-
for (const [c, { line: d, axis: u }] of
|
|
1746
|
-
const [p] =
|
|
1747
|
-
p && r.push({ type: "line", id: `${t.id}.${c}`, points: p, stroke: u ? i.ink : l, width: u ?
|
|
2445
|
+
for (const [c, { line: d }] of sn(n, [1, 0, 0, 1], s).entries())
|
|
2446
|
+
r.push({ type: "line", id: `${t.id}.ghost.${c}`, points: d, stroke: i.ghost, width: a, opacity: e.opacity });
|
|
2447
|
+
const l = T(i, t.color, i.grid);
|
|
2448
|
+
for (const [c, { line: d, axis: u }] of sn(n, mt(e.values, t.transform), s).entries()) {
|
|
2449
|
+
const [p] = _([d], e.draw);
|
|
2450
|
+
p && r.push({ type: "line", id: `${t.id}.${c}`, points: p, stroke: u ? i.ink : l, width: u ? a * 1.6 : a, opacity: e.opacity });
|
|
1748
2451
|
}
|
|
1749
2452
|
return r;
|
|
1750
2453
|
}
|
|
1751
|
-
function
|
|
1752
|
-
const { plane: n, theme: i } = e, s =
|
|
2454
|
+
function Ms(t, e) {
|
|
2455
|
+
const { plane: n, theme: i } = e, s = T(i, t.color, i.axes), r = 2 * n.scale, a = e.opacity, l = _([[n.toScreen([n.x[0], 0]), n.toScreen([n.x[1], 0])]], e.draw), c = _([[n.toScreen([0, n.y[0]]), n.toScreen([0, n.y[1]])]], e.draw), d = [...l, ...c].map((g, o) => ({ type: "line", id: `${t.id}.${o ? "y" : "x"}`, points: g, stroke: s, width: r, opacity: a })), u = t.ticks ?? 1;
|
|
1753
2456
|
if (u <= 0 || e.draw < 1) return d;
|
|
1754
|
-
const p = 5 * n.scale, h = 13 * n.scale,
|
|
1755
|
-
const
|
|
1756
|
-
for (let
|
|
1757
|
-
return
|
|
1758
|
-
}, f = (
|
|
1759
|
-
for (const
|
|
1760
|
-
const [
|
|
1761
|
-
d.push({ type: "line", id: `${t.id}.tick.x${
|
|
1762
|
-
}
|
|
1763
|
-
for (const
|
|
1764
|
-
const [
|
|
1765
|
-
d.push({ type: "line", id: `${t.id}.tick.y${
|
|
2457
|
+
const p = 5 * n.scale, h = 13 * n.scale, y = (g, o) => {
|
|
2458
|
+
const m = [];
|
|
2459
|
+
for (let v = Math.ceil(g / u) * u; v <= o + 1e-9; v += u) Math.abs(v) > 1e-9 && m.push(Number(v.toFixed(6)));
|
|
2460
|
+
return m;
|
|
2461
|
+
}, f = (g) => String(g).replace("-", "−");
|
|
2462
|
+
for (const g of y(n.x[0], n.x[1])) {
|
|
2463
|
+
const [o, m] = n.toScreen([g, 0]);
|
|
2464
|
+
d.push({ type: "line", id: `${t.id}.tick.x${g}`, points: [[o, m - p], [o, m + p]], stroke: s, width: r * 0.8, opacity: a }), t.labels !== !1 && d.push({ type: "text", id: `${t.id}.label.x${g}`, text: f(g), x: o, y: m + p + h * 1.1, size: h, font: ht, color: s, align: "center", opacity: a * 0.8 });
|
|
2465
|
+
}
|
|
2466
|
+
for (const g of y(n.y[0], n.y[1])) {
|
|
2467
|
+
const [o, m] = n.toScreen([0, g]);
|
|
2468
|
+
d.push({ type: "line", id: `${t.id}.tick.y${g}`, points: [[o - p, m], [o + p, m]], stroke: s, width: r * 0.8, opacity: a }), t.labels !== !1 && d.push({ type: "text", id: `${t.id}.label.y${g}`, text: f(g), x: o - p - h * 0.4, y: m + h * 0.35, size: h, font: ht, color: s, align: "right", opacity: a * 0.8 });
|
|
1766
2469
|
}
|
|
1767
2470
|
return d;
|
|
1768
2471
|
}
|
|
1769
|
-
function
|
|
1770
|
-
const
|
|
1771
|
-
return
|
|
2472
|
+
function ie(t, e, n, i, s, r) {
|
|
2473
|
+
const a = 26 * r.plane.scale, [l, c] = Nt(n), d = H(t, { values: r.scope, style: "inline" }), u = a * (0.55 + Math.abs(l) * d.width * 0.5);
|
|
2474
|
+
return G(d, { x: e[0] + l * u, y: e[1] + c * u, size: a, color: i, opacity: r.opacity, idPrefix: `${s}.label.` });
|
|
1772
2475
|
}
|
|
1773
|
-
function
|
|
1774
|
-
const
|
|
2476
|
+
function Rn(t, e, n, i, s, r) {
|
|
2477
|
+
const a = r.plane.toScreen(e), l = r.plane.toScreen(n), [c] = _([[a, l]], r.draw);
|
|
1775
2478
|
if (!c) return [];
|
|
1776
|
-
const d = Math.hypot(l[0] -
|
|
2479
|
+
const d = Math.hypot(l[0] - a[0], l[1] - a[1]), u = Math.min(s * 3.6, d * 0.45);
|
|
1777
2480
|
return [{ type: "arrow", id: t, points: c, stroke: i, width: s, head: u, opacity: r.opacity }];
|
|
1778
2481
|
}
|
|
1779
|
-
function
|
|
1780
|
-
const n =
|
|
2482
|
+
function xs(t, e) {
|
|
2483
|
+
const n = mt(e.values, t.transform), i = tt(n, t.from === void 0 ? [0, 0] : wt(e.values, t.from)), s = tt(n, wt(e.values, t.to)), r = T(e.theme, t.color, e.theme.colors.yellow), a = Rn(t.id, i, s, r, (t.width ?? 4) * e.plane.scale, e);
|
|
1781
2484
|
if (t.label && e.draw >= 1) {
|
|
1782
|
-
const l = e.plane.toScreen(s), c = e.plane.toScreen(i), d =
|
|
2485
|
+
const l = e.plane.toScreen(s), c = e.plane.toScreen(i), d = Ne(l, c);
|
|
1783
2486
|
if (t.labelAt === "middle") {
|
|
1784
2487
|
const u = [(l[0] + c[0]) / 2, (l[1] + c[1]) / 2];
|
|
1785
|
-
|
|
2488
|
+
a.push(...ie(t.label, u, [d[1], -d[0]], r, t.id, e));
|
|
1786
2489
|
} else
|
|
1787
|
-
|
|
2490
|
+
a.push(...ie(t.label, l, d, r, t.id, e));
|
|
1788
2491
|
}
|
|
1789
|
-
return
|
|
2492
|
+
return a;
|
|
1790
2493
|
}
|
|
1791
|
-
function
|
|
1792
|
-
const n =
|
|
2494
|
+
function Ss(t, e) {
|
|
2495
|
+
const n = mt(e.values, t.transform), i = 4.5 * e.plane.scale, s = e.plane.toScreen([0, 0]), r = [], a = [
|
|
1793
2496
|
["i", [1, 0], e.theme.colors.green, "\\hat{i}"],
|
|
1794
2497
|
["j", [0, 1], e.theme.colors.red, "\\hat{j}"]
|
|
1795
2498
|
];
|
|
1796
|
-
for (const [l, c, d, u] of
|
|
1797
|
-
const p =
|
|
1798
|
-
if (r.push(...
|
|
2499
|
+
for (const [l, c, d, u] of a) {
|
|
2500
|
+
const p = tt(n, c);
|
|
2501
|
+
if (r.push(...Rn(`${t.id}.${l}`, [0, 0], p, d, i, e)), t.labels !== !1 && e.draw >= 1) {
|
|
1799
2502
|
const h = e.plane.toScreen(p);
|
|
1800
|
-
r.push(...
|
|
2503
|
+
r.push(...ie(u, h, Ne(h, s), d, `${t.id}.${l}`, e));
|
|
1801
2504
|
}
|
|
1802
2505
|
}
|
|
1803
2506
|
return r;
|
|
1804
2507
|
}
|
|
1805
|
-
function
|
|
1806
|
-
const n = t.on !== void 0 ? [e.scope[`${t.id}.x`], e.scope[`${t.id}.y`]] :
|
|
2508
|
+
function As(t, e) {
|
|
2509
|
+
const n = t.on !== void 0 ? [e.scope[`${t.id}.x`], e.scope[`${t.id}.y`]] : wt(e.values, t.at);
|
|
1807
2510
|
if (!Number.isFinite(n[0]) || !Number.isFinite(n[1])) return [];
|
|
1808
|
-
const i =
|
|
1809
|
-
return t.label && e.draw >= 1 && d.push(...
|
|
2511
|
+
const i = tt(mt(e.values, t.transform), n), [s, r] = e.plane.toScreen(i), a = T(e.theme, t.color, e.theme.colors.yellow), l = (t.radius ?? 6) * e.plane.scale * Math.min(1, e.draw * 2), c = t.hollow ? { type: "circle", id: t.id, x: s, y: r, r: l, fill: e.theme.background, stroke: a, width: 2.5 * e.plane.scale, opacity: e.opacity } : { type: "circle", id: t.id, x: s, y: r, r: l, fill: a, opacity: e.opacity }, d = l > 0 ? [c] : [];
|
|
2512
|
+
return t.label && e.draw >= 1 && d.push(...ie(t.label, [s, r], [0.7, -0.7], a, t.id, e)), d;
|
|
1810
2513
|
}
|
|
1811
|
-
const
|
|
1812
|
-
function
|
|
1813
|
-
const n =
|
|
2514
|
+
const Es = [[0, 0], [1, 0], [1, 1], [0, 1]];
|
|
2515
|
+
function Ts(t, e) {
|
|
2516
|
+
const n = mt(e.values, t.transform), i = (t.points ?? Es).map((l) => tt(n, l)), s = i.map(e.plane.toScreen), r = T(e.theme, t.color, e.theme.colors.yellow), a = [
|
|
1814
2517
|
{ type: "line", id: `${t.id}.fill`, points: s, closed: !0, fill: r, opacity: e.opacity * (t.fillOpacity ?? 0.3) * e.draw },
|
|
1815
|
-
...
|
|
2518
|
+
..._([[...s, s[0]]], e.draw).map((l) => ({ type: "line", id: `${t.id}.outline`, points: l, stroke: r, width: 2.5 * e.plane.scale, opacity: e.opacity }))
|
|
1816
2519
|
];
|
|
1817
2520
|
if (t.label && e.draw >= 1) {
|
|
1818
2521
|
const l = i.reduce((u, p) => [u[0] + p[0] / i.length, u[1] + p[1] / i.length], [0, 0]), [c, d] = e.plane.toScreen(l);
|
|
1819
|
-
|
|
2522
|
+
a.push(...G(H(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.` }));
|
|
1820
2523
|
}
|
|
1821
|
-
return
|
|
2524
|
+
return a;
|
|
1822
2525
|
}
|
|
1823
|
-
function
|
|
1824
|
-
const n = t.eigen ?
|
|
1825
|
-
return n.flatMap((
|
|
1826
|
-
const c = Math.hypot(
|
|
2526
|
+
function Os(t, e) {
|
|
2527
|
+
const n = t.eigen ? dn(mt(e.values, t.eigen)).map((a) => a.vector) : t.along !== void 0 ? [wt(e.values, t.along)] : [], i = Math.max(Math.abs(e.plane.x[0]), Math.abs(e.plane.x[1]), Math.abs(e.plane.y[0]), Math.abs(e.plane.y[1])) * 1.5, s = T(e.theme, t.color, e.theme.colors.yellow), r = (t.width ?? 2.5) * e.plane.scale;
|
|
2528
|
+
return n.flatMap((a, l) => {
|
|
2529
|
+
const c = Math.hypot(a[0], a[1]);
|
|
1827
2530
|
if (c === 0) return [];
|
|
1828
|
-
const d =
|
|
1829
|
-
return
|
|
2531
|
+
const d = be(a, i / c), u = [be(d, -1), d].map(e.plane.toScreen);
|
|
2532
|
+
return _([u], e.draw).map((p) => ({
|
|
1830
2533
|
type: "line",
|
|
1831
2534
|
id: `${t.id}.${l}`,
|
|
1832
2535
|
points: p,
|
|
@@ -1837,185 +2540,210 @@ function ai(t, e) {
|
|
|
1837
2540
|
}));
|
|
1838
2541
|
});
|
|
1839
2542
|
}
|
|
1840
|
-
function
|
|
2543
|
+
function Oe(t, e, n, i) {
|
|
1841
2544
|
const s = n.size * 0.35;
|
|
1842
|
-
let r = 1 / 0,
|
|
2545
|
+
let r = 1 / 0, a = 1 / 0, l = -1 / 0, c = -1 / 0;
|
|
1843
2546
|
for (const d of e) {
|
|
1844
|
-
const [u, p] =
|
|
1845
|
-
r = Math.min(r, u - s), l = Math.max(l, u + d.width * n.size + s),
|
|
2547
|
+
const [u, p] = Fe(d, n);
|
|
2548
|
+
r = Math.min(r, u - s), l = Math.max(l, u + d.width * n.size + s), a = Math.min(a, p - d.height * n.size - s), c = Math.max(c, p + d.depth * n.size + s);
|
|
1846
2549
|
}
|
|
1847
2550
|
return [{
|
|
1848
2551
|
type: "line",
|
|
1849
2552
|
id: `${t}.backdrop`,
|
|
1850
|
-
points: [[r,
|
|
2553
|
+
points: [[r, a], [l, a], [l, c], [r, c]],
|
|
1851
2554
|
closed: !0,
|
|
1852
2555
|
fill: i.theme.background,
|
|
1853
2556
|
opacity: (n.opacity ?? 1) * 0.85
|
|
1854
2557
|
}];
|
|
1855
2558
|
}
|
|
1856
|
-
function
|
|
1857
|
-
const i =
|
|
2559
|
+
function Bn(t, e, n) {
|
|
2560
|
+
const i = wt(n.values, t);
|
|
1858
2561
|
return e ? i : n.plane.toScreen(i);
|
|
1859
2562
|
}
|
|
1860
|
-
function
|
|
1861
|
-
const [n, i] =
|
|
1862
|
-
return [...t.backdrop ?? t.screen ?? !1 ?
|
|
2563
|
+
function Ns(t, e) {
|
|
2564
|
+
const [n, i] = Bn(t.at, t.screen, e), s = (t.size ?? 28) * e.plane.scale, r = T(e.theme, t.color, e.theme.ink), a = { x: n, y: i, size: s, color: r, align: t.align, opacity: e.opacity * e.draw, idPrefix: `${t.id}.`, palette: e.theme.colors }, l = H(t.tex, { values: e.scope });
|
|
2565
|
+
return [...t.backdrop ?? t.screen ?? !1 ? Oe(t.id, [l], a, e) : [], ...G(l, a)];
|
|
1863
2566
|
}
|
|
1864
|
-
function
|
|
1865
|
-
const [n, i] =
|
|
1866
|
-
if (d === 0 || c >=
|
|
1867
|
-
const
|
|
1868
|
-
return [...h ?
|
|
1869
|
-
}
|
|
1870
|
-
const
|
|
1871
|
-
const [
|
|
1872
|
-
return { layout:
|
|
1873
|
-
}, f = p(c),
|
|
2567
|
+
function Ps(t, e) {
|
|
2568
|
+
const [n, i] = Bn(t.at, t.screen, e), s = (t.size ?? 36) * e.plane.scale, r = T(e.theme, t.color, e.theme.ink), a = t.steps.length - 1, l = Math.min(a, Math.max(0, e.prop("step") ?? t.step ?? 0)), c = Math.floor(l), d = l - c, u = { x: n, y: i, size: s, color: r, align: t.align, opacity: e.opacity * e.draw, idPrefix: `${t.id}.`, palette: e.theme.colors }, p = (o) => H(t.steps[o], { values: e.scope }), h = t.backdrop ?? t.screen ?? !1;
|
|
2569
|
+
if (d === 0 || c >= a) {
|
|
2570
|
+
const o = p(c);
|
|
2571
|
+
return [...h ? Oe(t.id, [o], u, e) : [], ...G(o, u)];
|
|
2572
|
+
}
|
|
2573
|
+
const y = (o) => {
|
|
2574
|
+
const [m, v] = Fe(o, u);
|
|
2575
|
+
return { layout: o, x: m / s, y: v / s };
|
|
2576
|
+
}, f = p(c), g = p(c + 1);
|
|
1874
2577
|
return [
|
|
1875
|
-
...h ?
|
|
1876
|
-
...
|
|
2578
|
+
...h ? Oe(t.id, [f, g], u, e) : [],
|
|
2579
|
+
...wn(vs(y(f), y(g), d), [0, 0], u)
|
|
1877
2580
|
];
|
|
1878
2581
|
}
|
|
1879
|
-
function
|
|
1880
|
-
const n =
|
|
1881
|
-
if (!Number.isFinite(r) || !Number.isFinite(
|
|
1882
|
-
const l = t.length !== void 0 ? t.length / 2 : Math.max(Math.abs(e.plane.x[0] - i), Math.abs(e.plane.x[1] - i)), c = [[i - l, r -
|
|
1883
|
-
(
|
|
2582
|
+
function Is(t, e) {
|
|
2583
|
+
const n = Y(t.expr), i = E(e.values, t.at), s = t.h === void 0 ? 0 : E(e.values, t.h), r = n(i, e.scope), a = e.scope[`${t.id}.slope`];
|
|
2584
|
+
if (!Number.isFinite(r) || !Number.isFinite(a)) return [];
|
|
2585
|
+
const l = t.length !== void 0 ? t.length / 2 : Math.max(Math.abs(e.plane.x[0] - i), Math.abs(e.plane.x[1] - i)), c = [[i - l, r - a * l], [i + l, r + a * l]], d = T(e.theme, t.color, e.theme.colors.yellow), u = e.plane.toScreen([i, r]), p = c.map(e.plane.toScreen), h = [p[0], p[1]].flatMap(
|
|
2586
|
+
(y, f) => _([[u, y]], e.draw).map((g) => ({ type: "line", id: `${t.id}.${f}`, points: g, stroke: d, width: (t.width ?? 3) * e.plane.scale, opacity: e.opacity }))
|
|
1884
2587
|
);
|
|
1885
2588
|
if (t.points !== !1) {
|
|
1886
|
-
const
|
|
1887
|
-
if (h.push({ type: "circle", id: `${t.id}.point`, x: u[0], y: u[1], r:
|
|
1888
|
-
const [f,
|
|
1889
|
-
Number.isFinite(
|
|
2589
|
+
const y = 6 * e.plane.scale;
|
|
2590
|
+
if (h.push({ type: "circle", id: `${t.id}.point`, x: u[0], y: u[1], r: y, fill: d, opacity: e.opacity }), Math.abs(s) > 1e-9) {
|
|
2591
|
+
const [f, g] = e.plane.toScreen([i + s, n(i + s, e.scope)]);
|
|
2592
|
+
Number.isFinite(g) && h.push({ type: "circle", id: `${t.id}.secant`, x: f, y: g, r: y, fill: d, opacity: e.opacity });
|
|
1890
2593
|
}
|
|
1891
2594
|
}
|
|
1892
2595
|
if (t.label && e.draw >= 1) {
|
|
1893
|
-
const
|
|
1894
|
-
h.push(...
|
|
2596
|
+
const y = 24 * e.plane.scale, f = H(t.label, { values: e.scope, style: "inline" });
|
|
2597
|
+
h.push(...G(f, { x: u[0], y: u[1] - y * 1.6, size: y, color: d, opacity: e.opacity, idPrefix: `${t.id}.label.` }));
|
|
1895
2598
|
}
|
|
1896
2599
|
return h;
|
|
1897
2600
|
}
|
|
1898
|
-
function
|
|
1899
|
-
const n =
|
|
1900
|
-
return
|
|
1901
|
-
if (!Number.isFinite(h) || !Number.isFinite(
|
|
1902
|
-
const
|
|
1903
|
-
return [{ type: "line", id: `${t.id}.${f}`, points:
|
|
2601
|
+
function Fs(t, e) {
|
|
2602
|
+
const n = Y(t.expr), i = E(e.values, t.from), s = E(e.values, t.to), r = jn(E(e.values, t.n)), a = zn((u) => n(u, e.scope), i, s, r, t.rule ?? "left"), l = T(e.theme, t.color, e.theme.colors.blue), c = Math.ceil(a.length * e.draw), d = Math.max(0.5, Math.min(1.5, 60 / r)) * e.plane.scale;
|
|
2603
|
+
return a.slice(0, c).flatMap(([u, p, h, y], f) => {
|
|
2604
|
+
if (!Number.isFinite(h) || !Number.isFinite(y)) return [];
|
|
2605
|
+
const g = [[u, 0], [p, 0], [p, y], [u, h]].map(e.plane.toScreen), m = (h + y) / 2 < 0 ? T(e.theme, "red", e.theme.colors.red) : l;
|
|
2606
|
+
return [{ type: "line", id: `${t.id}.${f}`, points: g, closed: !0, fill: m, stroke: m, width: d, opacity: e.opacity * (t.fillOpacity ?? 0.35) }];
|
|
1904
2607
|
});
|
|
1905
2608
|
}
|
|
1906
|
-
function
|
|
1907
|
-
const n =
|
|
2609
|
+
function Ls(t, e) {
|
|
2610
|
+
const n = Y(t.expr), i = t.lower ? Y(t.lower) : () => 0, s = E(e.values, t.from), r = s + (E(e.values, t.to) - s) * e.draw;
|
|
1908
2611
|
if (s === r) return [];
|
|
1909
|
-
const
|
|
1910
|
-
let p = [], h = [],
|
|
2612
|
+
const a = 240, l = T(e.theme, t.color, e.theme.colors.blue), c = T(e.theme, t.negativeColor, e.theme.colors.red), d = e.opacity * (t.fillOpacity ?? 0.4), u = [];
|
|
2613
|
+
let p = [], h = [], y;
|
|
1911
2614
|
const f = () => {
|
|
1912
|
-
p.length >= 2 && u.push({ type: "line", id: `${t.id}.${u.length}`, points: [...p, ...h.reverse()].map(e.plane.toScreen), closed: !0, fill:
|
|
2615
|
+
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 = [];
|
|
1913
2616
|
};
|
|
1914
|
-
let
|
|
1915
|
-
for (let
|
|
1916
|
-
const
|
|
1917
|
-
if (!Number.isFinite(
|
|
1918
|
-
f(),
|
|
2617
|
+
let g;
|
|
2618
|
+
for (let o = 0; o <= a; o++) {
|
|
2619
|
+
const m = s + (r - s) * o / a, v = n(m, e.scope), x = i(m, e.scope);
|
|
2620
|
+
if (!Number.isFinite(v) || !Number.isFinite(x)) {
|
|
2621
|
+
f(), g = void 0;
|
|
1919
2622
|
continue;
|
|
1920
2623
|
}
|
|
1921
|
-
const
|
|
1922
|
-
if (
|
|
1923
|
-
const b =
|
|
1924
|
-
p.push([
|
|
2624
|
+
const w = v - x >= 0;
|
|
2625
|
+
if (g && y !== void 0 && w !== y) {
|
|
2626
|
+
const b = g.fy - g.gy, k = v - x, M = b / (b - k), $ = g.x + (m - g.x) * M, S = g.gy + (x - g.gy) * M;
|
|
2627
|
+
p.push([$, S]), h.push([$, S]), f(), p.push([$, S]), h.push([$, S]);
|
|
1925
2628
|
}
|
|
1926
|
-
|
|
2629
|
+
y = w, p.push([m, v]), h.push([m, x]), g = { x: m, fy: v, gy: x };
|
|
1927
2630
|
}
|
|
1928
2631
|
return f(), u;
|
|
1929
2632
|
}
|
|
1930
|
-
const
|
|
1931
|
-
function
|
|
1932
|
-
const n =
|
|
1933
|
-
let h = 0,
|
|
2633
|
+
const Cs = 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));
|
|
2634
|
+
function qs(t, e) {
|
|
2635
|
+
const n = E(e.values, t.at), i = e.scope[`${t.id}.order`], s = Math.floor(i), r = i - s, a = Array.from({ length: Math.min(20, s + 1) + 1 }, (p, h) => Pe(t.expr, h)(n, e.scope) / Cs[h]), l = (p) => {
|
|
2636
|
+
let h = 0, y = 1;
|
|
1934
2637
|
for (let f = 0; f <= s; f++)
|
|
1935
|
-
h +=
|
|
1936
|
-
return r > 0 && s < 20 ? h + r *
|
|
1937
|
-
}, c =
|
|
1938
|
-
return
|
|
2638
|
+
h += a[f] * y, y *= p - n;
|
|
2639
|
+
return r > 0 && s < 20 ? h + r * a[s + 1] * y : h;
|
|
2640
|
+
}, c = T(e.theme, t.color, e.theme.colors.yellow), [d, u] = t.domain ?? e.plane.x;
|
|
2641
|
+
return oe(t.id, (p) => l(p), d, u, c, (t.width ?? 3.5) * e.plane.scale, e);
|
|
1939
2642
|
}
|
|
1940
|
-
function
|
|
2643
|
+
function zs(t, e) {
|
|
1941
2644
|
switch (t.kind) {
|
|
1942
2645
|
case "grid":
|
|
1943
|
-
return
|
|
2646
|
+
return $s(t, e);
|
|
1944
2647
|
case "axes":
|
|
1945
|
-
return
|
|
2648
|
+
return Ms(t, e);
|
|
1946
2649
|
case "vector":
|
|
1947
|
-
return
|
|
2650
|
+
return xs(t, e);
|
|
1948
2651
|
case "basis":
|
|
1949
|
-
return
|
|
2652
|
+
return Ss(t, e);
|
|
1950
2653
|
case "point":
|
|
1951
|
-
return
|
|
2654
|
+
return As(t, e);
|
|
1952
2655
|
case "function":
|
|
1953
|
-
return
|
|
2656
|
+
return Si(t, e);
|
|
1954
2657
|
case "parametric":
|
|
1955
|
-
return
|
|
2658
|
+
return Ai(t, e);
|
|
1956
2659
|
case "polygon":
|
|
1957
|
-
return
|
|
2660
|
+
return Ts(t, e);
|
|
1958
2661
|
case "line":
|
|
1959
|
-
return
|
|
2662
|
+
return Os(t, e);
|
|
1960
2663
|
case "label":
|
|
1961
|
-
return
|
|
2664
|
+
return Ns(t, e);
|
|
1962
2665
|
case "equation":
|
|
1963
|
-
return
|
|
2666
|
+
return Ps(t, e);
|
|
1964
2667
|
case "tangent":
|
|
1965
|
-
return
|
|
2668
|
+
return Is(t, e);
|
|
1966
2669
|
case "riemann":
|
|
1967
|
-
return
|
|
2670
|
+
return Fs(t, e);
|
|
1968
2671
|
case "area":
|
|
1969
|
-
return
|
|
2672
|
+
return Ls(t, e);
|
|
1970
2673
|
case "taylor":
|
|
1971
|
-
return
|
|
2674
|
+
return qs(t, e);
|
|
1972
2675
|
case "histogram":
|
|
1973
|
-
return
|
|
2676
|
+
return Ei(t, e);
|
|
1974
2677
|
case "distribution":
|
|
1975
|
-
return
|
|
2678
|
+
return Ti(t, e);
|
|
1976
2679
|
case "galton":
|
|
1977
|
-
return
|
|
2680
|
+
return Oi(t, e);
|
|
1978
2681
|
case "scatter":
|
|
1979
|
-
return
|
|
2682
|
+
return Ni(t, e);
|
|
1980
2683
|
case "bayes":
|
|
1981
|
-
return
|
|
2684
|
+
return Pi(t, e);
|
|
2685
|
+
case "graph":
|
|
2686
|
+
return Di(t, e);
|
|
2687
|
+
case "venn":
|
|
2688
|
+
return Bi(t, e);
|
|
2689
|
+
case "clock":
|
|
2690
|
+
return Vi(t, e);
|
|
2691
|
+
case "network":
|
|
2692
|
+
return ss(t, e);
|
|
2693
|
+
case "heatmap":
|
|
2694
|
+
return as(t, e);
|
|
2695
|
+
case "contours":
|
|
2696
|
+
return ls(t, e);
|
|
2697
|
+
case "descent":
|
|
2698
|
+
return ds(t, e);
|
|
2699
|
+
case "classifier":
|
|
2700
|
+
return ps(t, e);
|
|
2701
|
+
case "kmeans":
|
|
2702
|
+
return ys(t, e);
|
|
1982
2703
|
}
|
|
1983
2704
|
}
|
|
1984
|
-
const
|
|
1985
|
-
function
|
|
1986
|
-
const n =
|
|
2705
|
+
const rn = (t) => Math.min(1, Math.max(0, t));
|
|
2706
|
+
function de(t, e = {}) {
|
|
2707
|
+
const n = Te[t.theme ?? "dark"], i = Dn(t), s = { ...t.values }, r = /* @__PURE__ */ new Map();
|
|
1987
2708
|
for (const [u, p] of Object.entries(e))
|
|
1988
2709
|
u.indexOf(".") < 0 ? typeof p != "string" && (s[u] = p) : typeof p == "number" && r.set(u, p);
|
|
1989
|
-
const
|
|
2710
|
+
const a = hn(s), l = { ...a, ..._n(t.items, s, a) }, c = [];
|
|
1990
2711
|
for (const u of t.items) {
|
|
1991
|
-
const p = (f) => r.get(`${u.id}.${f}`), h =
|
|
1992
|
-
h <= 0 ||
|
|
2712
|
+
const p = (f) => r.get(`${u.id}.${f}`), h = rn(p("draw") ?? u.draw ?? 1), y = rn(p("opacity") ?? u.opacity ?? 1);
|
|
2713
|
+
h <= 0 || y <= 0 || c.push(...zs(u, { plane: i, theme: n, values: s, scope: l, draw: h, opacity: y, prop: p }));
|
|
1993
2714
|
}
|
|
1994
2715
|
const d = t.background === "none" ? void 0 : t.background ?? n.background;
|
|
1995
2716
|
return { width: t.width, height: t.height, ...d ? { background: d } : {}, shapes: c };
|
|
1996
2717
|
}
|
|
1997
|
-
function
|
|
2718
|
+
function Vn(t, e) {
|
|
1998
2719
|
if (t.length < 2) return { shaft: t, head: void 0 };
|
|
1999
|
-
const n = t[t.length - 1], i = t[t.length - 2], s = n[0] - i[0], r = n[1] - i[1],
|
|
2000
|
-
if (
|
|
2001
|
-
const l = s /
|
|
2720
|
+
const n = t[t.length - 1], i = t[t.length - 2], s = n[0] - i[0], r = n[1] - i[1], a = Math.hypot(s, r);
|
|
2721
|
+
if (a === 0 || e <= 0) return { shaft: t, head: void 0 };
|
|
2722
|
+
const l = s / a, c = r / a, d = Math.min(e, a), u = [n[0] - l * d, n[1] - c * d], p = d * 0.55;
|
|
2002
2723
|
return {
|
|
2003
2724
|
shaft: [...t.slice(0, -1), u],
|
|
2004
2725
|
head: [n, [u[0] - c * p, u[1] + l * p], [u[0] + c * p, u[1] - l * p]]
|
|
2005
2726
|
};
|
|
2006
2727
|
}
|
|
2007
|
-
function
|
|
2728
|
+
function Ut(t, e, n = !1) {
|
|
2008
2729
|
t.beginPath(), e.forEach(([i, s], r) => r === 0 ? t.moveTo(i, s) : t.lineTo(i, s)), n && t.closePath();
|
|
2009
2730
|
}
|
|
2010
|
-
function
|
|
2731
|
+
function Hn(t, e) {
|
|
2011
2732
|
switch (t.globalAlpha = e.opacity ?? 1, e.type) {
|
|
2012
2733
|
case "line":
|
|
2013
2734
|
if (e.points.length < 2) return;
|
|
2014
|
-
|
|
2735
|
+
if (e.clip?.length) {
|
|
2736
|
+
t.save();
|
|
2737
|
+
for (const { points: n, outside: i } of e.clip)
|
|
2738
|
+
Ut(t, n, !0), i ? (t.rect(-1e6, -1e6, 2e6, 2e6), t.clip("evenodd")) : t.clip();
|
|
2739
|
+
Hn(t, { ...e, clip: void 0 }), t.restore();
|
|
2740
|
+
return;
|
|
2741
|
+
}
|
|
2742
|
+
Ut(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([]));
|
|
2015
2743
|
return;
|
|
2016
2744
|
case "arrow": {
|
|
2017
|
-
const { shaft: n, head: i } =
|
|
2018
|
-
t.strokeStyle = e.stroke, t.fillStyle = e.stroke, t.lineWidth = e.width, n.length >= 2 && (
|
|
2745
|
+
const { shaft: n, head: i } = Vn(e.points, e.head);
|
|
2746
|
+
t.strokeStyle = e.stroke, t.fillStyle = e.stroke, t.lineWidth = e.width, n.length >= 2 && (Ut(t, n), t.stroke()), i && (Ut(t, i, !0), t.fill());
|
|
2019
2747
|
return;
|
|
2020
2748
|
}
|
|
2021
2749
|
case "circle":
|
|
@@ -2025,41 +2753,48 @@ function yi(t, e) {
|
|
|
2025
2753
|
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);
|
|
2026
2754
|
}
|
|
2027
2755
|
}
|
|
2028
|
-
function
|
|
2756
|
+
function js(t, e) {
|
|
2029
2757
|
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";
|
|
2030
|
-
for (const n of e.shapes)
|
|
2758
|
+
for (const n of e.shapes) Hn(t, n);
|
|
2031
2759
|
t.restore();
|
|
2032
2760
|
}
|
|
2033
|
-
const
|
|
2034
|
-
function
|
|
2761
|
+
const j = (t) => String(Math.round(t * 100) / 100), Q = (t) => t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """), Et = (t, e = !1) => t.map(([n, i], s) => `${s ? "L" : "M"}${j(n)} ${j(i)}`).join("") + (e ? "Z" : ""), Wt = (t) => t.opacity !== void 0 && t.opacity < 1 ? ` opacity="${j(t.opacity)}"` : "";
|
|
2762
|
+
function Un(t) {
|
|
2035
2763
|
switch (t.type) {
|
|
2036
2764
|
case "line": {
|
|
2037
2765
|
if (t.points.length < 2) return "";
|
|
2038
|
-
|
|
2039
|
-
|
|
2766
|
+
if (t.clip?.length) {
|
|
2767
|
+
const s = t.clip.map(({ points: a, outside: l }) => {
|
|
2768
|
+
const c = l ? `M-1000000 -1000000H1000000V1000000H-1000000Z${Et(a, !0)}` : Et(a, !0), d = `tfclip${yt(`${l ? "o" : "i"}${c}`).toString(36)}`;
|
|
2769
|
+
return { id: d, def: `<clipPath id="${d}"><path d="${c}"${l ? ' clip-rule="evenodd"' : ""}/></clipPath>` };
|
|
2770
|
+
}), r = Un({ ...t, clip: void 0 });
|
|
2771
|
+
return `<defs>${s.map((a) => a.def).join("")}</defs>` + s.reduceRight((a, l) => `<g clip-path="url(#${l.id})">${a}</g>`, r);
|
|
2772
|
+
}
|
|
2773
|
+
const e = t.fill ? ` fill="${Q(t.fill)}"` : ' fill="none"', n = t.stroke && (t.width ?? 1) > 0 ? ` stroke="${Q(t.stroke)}" stroke-width="${j(t.width ?? 1)}"` : "", i = t.dash?.length ? ` stroke-dasharray="${t.dash.map(j).join(" ")}"` : "";
|
|
2774
|
+
return `<path d="${Et(t.points, t.closed)}"${e}${n}${i}${Wt(t)}/>`;
|
|
2040
2775
|
}
|
|
2041
2776
|
case "arrow": {
|
|
2042
|
-
const { shaft: e, head: n } =
|
|
2043
|
-
return `<g${
|
|
2777
|
+
const { shaft: e, head: n } = Vn(t.points, t.head), i = Q(t.stroke), s = e.length >= 2 ? `<path d="${Et(e)}" fill="none" stroke="${i}" stroke-width="${j(t.width)}"/>` : "", r = n ? `<path d="${Et(n, !0)}" fill="${i}"/>` : "";
|
|
2778
|
+
return `<g${Wt(t)}>${s}${r}</g>`;
|
|
2044
2779
|
}
|
|
2045
2780
|
case "circle": {
|
|
2046
|
-
const e = t.fill ? ` fill="${
|
|
2047
|
-
return `<circle cx="${
|
|
2781
|
+
const e = t.fill ? ` fill="${Q(t.fill)}"` : ' fill="none"', n = t.stroke ? ` stroke="${Q(t.stroke)}" stroke-width="${j(t.width ?? 1)}"` : "";
|
|
2782
|
+
return `<circle cx="${j(t.x)}" cy="${j(t.y)}" r="${j(t.r)}"${e}${n}${Wt(t)}/>`;
|
|
2048
2783
|
}
|
|
2049
2784
|
case "text": {
|
|
2050
2785
|
const e = t.align === "center" ? "middle" : t.align === "right" ? "end" : "start", n = t.italic ? ' font-style="italic"' : "";
|
|
2051
|
-
return `<text x="${
|
|
2786
|
+
return `<text x="${j(t.x)}" y="${j(t.y)}" font-size="${j(t.size)}" font-family="${Q(t.font)}"${n} text-anchor="${e}" fill="${Q(t.color)}"${Wt(t)}>${Q(t.text)}</text>`;
|
|
2052
2787
|
}
|
|
2053
2788
|
}
|
|
2054
2789
|
}
|
|
2055
|
-
function
|
|
2056
|
-
return `${t.background ? `<rect width="${
|
|
2790
|
+
function je(t) {
|
|
2791
|
+
return `${t.background ? `<rect width="${j(t.width)}" height="${j(t.height)}" fill="${Q(t.background)}"/>` : ""}<g stroke-linecap="round" stroke-linejoin="round">${t.shapes.map(Un).join("")}</g>`;
|
|
2057
2792
|
}
|
|
2058
|
-
function
|
|
2059
|
-
const n = e.title ? `<title>${
|
|
2060
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${
|
|
2793
|
+
function _s(t, e = {}) {
|
|
2794
|
+
const n = e.title ? `<title>${Q(e.title)}</title>` : "", i = e.title ? ` role="img" aria-label="${Q(e.title)}"` : "";
|
|
2795
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${j(t.width)} ${j(t.height)}" width="${j(t.width)}" height="${j(t.height)}"${i}>${n}${je(t)}</svg>`;
|
|
2061
2796
|
}
|
|
2062
|
-
function
|
|
2797
|
+
function Ds(t) {
|
|
2063
2798
|
const e = {};
|
|
2064
2799
|
for (const [n, i] of Object.entries(t.values ?? {})) {
|
|
2065
2800
|
const s = typeof i == "number" ? "number" : i.length === 2 ? "[x, y] vector" : "[a, b, c, d] matrix";
|
|
@@ -2069,9 +2804,9 @@ function wi(t) {
|
|
|
2069
2804
|
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 });
|
|
2070
2805
|
return e;
|
|
2071
2806
|
}
|
|
2072
|
-
function
|
|
2073
|
-
|
|
2074
|
-
const n =
|
|
2807
|
+
function yr(t, e = {}) {
|
|
2808
|
+
zt(t);
|
|
2809
|
+
const n = Ds(t), i = { ...t.values ?? {} };
|
|
2075
2810
|
return {
|
|
2076
2811
|
type: "custom",
|
|
2077
2812
|
x: e.x ?? 0,
|
|
@@ -2081,7 +2816,7 @@ function Zi(t, e = {}) {
|
|
|
2081
2816
|
props: i,
|
|
2082
2817
|
acceptsProp: (s) => Object.prototype.hasOwnProperty.call(n, s),
|
|
2083
2818
|
draw(s, r) {
|
|
2084
|
-
|
|
2819
|
+
js(s, de(t, r.props ?? {}));
|
|
2085
2820
|
},
|
|
2086
2821
|
about: {
|
|
2087
2822
|
kind: "math figure",
|
|
@@ -2090,18 +2825,18 @@ function Zi(t, e = {}) {
|
|
|
2090
2825
|
}
|
|
2091
2826
|
};
|
|
2092
2827
|
}
|
|
2093
|
-
function
|
|
2828
|
+
function mr(t, e, n, i = {}) {
|
|
2094
2829
|
const s = new Set(n.items.map((c) => c.id)), r = (c) => {
|
|
2095
2830
|
if (!s.has(c)) throw new Error(`mathSteps: no item "${c}" (items: ${[...s].join(", ")})`);
|
|
2096
|
-
},
|
|
2831
|
+
}, a = { ...n.values ?? {} };
|
|
2097
2832
|
for (const c of n.items)
|
|
2098
|
-
|
|
2833
|
+
a[`${c.id}.draw`] = c.draw ?? 1, a[`${c.id}.opacity`] = c.opacity ?? 1, c.kind === "equation" && (a[`${c.id}.step`] = c.step ?? 0);
|
|
2099
2834
|
for (const c of i.hidden ?? [])
|
|
2100
|
-
r(c),
|
|
2101
|
-
t.initial(e,
|
|
2835
|
+
r(c), a[`${c}.draw`] = 0;
|
|
2836
|
+
t.initial(e, a);
|
|
2102
2837
|
const l = {
|
|
2103
2838
|
toValue(c, d, u) {
|
|
2104
|
-
if (!(c in
|
|
2839
|
+
if (!(c in a)) throw new Error(`mathSteps: no value "${c}" (values: ${Object.keys(n.values ?? {}).join(", ")})`);
|
|
2105
2840
|
return t.to(e, { [c]: d }, { duration: 1200, ...u }), l;
|
|
2106
2841
|
},
|
|
2107
2842
|
applyMatrix(c, d = {}) {
|
|
@@ -2124,7 +2859,7 @@ function Gi(t, e, n, i = {}) {
|
|
|
2124
2859
|
};
|
|
2125
2860
|
return l;
|
|
2126
2861
|
}
|
|
2127
|
-
class
|
|
2862
|
+
class on {
|
|
2128
2863
|
media;
|
|
2129
2864
|
offset;
|
|
2130
2865
|
driftTolerance;
|
|
@@ -2163,7 +2898,7 @@ class qe {
|
|
|
2163
2898
|
});
|
|
2164
2899
|
}
|
|
2165
2900
|
}
|
|
2166
|
-
function
|
|
2901
|
+
function Rs(t, e, n, i, s) {
|
|
2167
2902
|
const r = n - s;
|
|
2168
2903
|
if (r < 0) {
|
|
2169
2904
|
e.paused || e.pause(), e.currentTime = 0;
|
|
@@ -2171,7 +2906,7 @@ function ki(t, e, n, i, s) {
|
|
|
2171
2906
|
}
|
|
2172
2907
|
t.update(r, i);
|
|
2173
2908
|
}
|
|
2174
|
-
class
|
|
2909
|
+
class Bs {
|
|
2175
2910
|
container;
|
|
2176
2911
|
timeline = null;
|
|
2177
2912
|
adapter;
|
|
@@ -2210,7 +2945,7 @@ class $i {
|
|
|
2210
2945
|
this.container = i;
|
|
2211
2946
|
} else
|
|
2212
2947
|
this.container = e;
|
|
2213
|
-
this.options = n, this.adapter = new
|
|
2948
|
+
this.options = n, this.adapter = new He();
|
|
2214
2949
|
}
|
|
2215
2950
|
/**
|
|
2216
2951
|
* Load animation from a URL or JSON object.
|
|
@@ -2236,7 +2971,7 @@ class $i {
|
|
|
2236
2971
|
*/
|
|
2237
2972
|
useDefinition(e) {
|
|
2238
2973
|
const n = { ...e.config };
|
|
2239
|
-
this.options.speed !== void 0 && (n.speed = this.options.speed), this.options.loop !== void 0 && (n.loop = this.options.loop), this.options.alternate !== void 0 && (n.alternate = this.options.alternate), this.timeline =
|
|
2974
|
+
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 = Ve({ ...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();
|
|
2240
2975
|
}
|
|
2241
2976
|
// --- scenarios: the reader chooses which timeline plays --------------------
|
|
2242
2977
|
/**
|
|
@@ -2276,8 +3011,8 @@ class $i {
|
|
|
2276
3011
|
if (e === this.scenarioId) return !0;
|
|
2277
3012
|
const i = this.isPlaying, s = this.currentTime >= this.duration - 0.5, r = this.currentMarker?.id;
|
|
2278
3013
|
this.stopAnimationLoop(), this.stepping = !1, this.pausedByVisibility = !1, this.restoreAuthored(), this.scenarioId = e, this.useDefinition(n.timeline), this.lastMarkerId = null;
|
|
2279
|
-
let
|
|
2280
|
-
return this.reducedMotion || s ?
|
|
3014
|
+
let a = 0;
|
|
3015
|
+
return this.reducedMotion || s ? a = this.duration : r !== void 0 && (a = this.markers.find((l) => l.id === r)?.time ?? 0), this.seek(a), i && !this.reducedMotion ? (this.stepping = this.options.stepMode === !0, this.startPlaying()) : this.notify(), !0;
|
|
2281
3016
|
}
|
|
2282
3017
|
/** Remember how an element was authored, the first time it becomes a target. */
|
|
2283
3018
|
rememberAuthored(e) {
|
|
@@ -2329,9 +3064,9 @@ class $i {
|
|
|
2329
3064
|
* marker's own label.
|
|
2330
3065
|
*/
|
|
2331
3066
|
caption(e, n) {
|
|
2332
|
-
const i = e ? this.markers.find((
|
|
3067
|
+
const i = e ? this.markers.find((a) => a.id === e) : this.currentMarker;
|
|
2333
3068
|
if (!i) return;
|
|
2334
|
-
const s = n ?? this.language(), r = (
|
|
3069
|
+
const s = n ?? this.language(), r = (a) => a?.[s]?.[i.id] ?? a?.[s.split("-")[0]]?.[i.id];
|
|
2335
3070
|
return r(this.options.captions) ?? r(this.timeline?.captions) ?? i.label;
|
|
2336
3071
|
}
|
|
2337
3072
|
/** Move to the next marker: animated, or a jump under reduced motion. At the last marker, to the end. */
|
|
@@ -2403,13 +3138,13 @@ class $i {
|
|
|
2403
3138
|
scanMedia() {
|
|
2404
3139
|
this.mediaTargets = [], this.container.querySelectorAll("[data-tinyfly-media]").forEach((n) => {
|
|
2405
3140
|
const i = n, s = Number(i.getAttribute("data-tinyfly-start") ?? "0") || 0, r = i.getAttribute("data-volume");
|
|
2406
|
-
r !== null && (i.volume = Math.max(0, Math.min(1, Number(r) || 0))), this.mediaTargets.push({ el: i, startTime: s, sync: new
|
|
3141
|
+
r !== null && (i.volume = Math.max(0, Math.min(1, Number(r) || 0))), this.mediaTargets.push({ el: i, startTime: s, sync: new on(i) });
|
|
2407
3142
|
});
|
|
2408
3143
|
}
|
|
2409
3144
|
/** Sync all discovered media targets to a timeline time. */
|
|
2410
3145
|
syncAllMedia(e, n) {
|
|
2411
3146
|
for (const i of this.mediaTargets)
|
|
2412
|
-
|
|
3147
|
+
Rs(i.sync, i.el, e, n, i.startTime);
|
|
2413
3148
|
}
|
|
2414
3149
|
/**
|
|
2415
3150
|
* Load animation from inline JSON string.
|
|
@@ -2459,11 +3194,11 @@ class $i {
|
|
|
2459
3194
|
if (!s) return;
|
|
2460
3195
|
const r = n.get(s);
|
|
2461
3196
|
if (!r || !r.timeline.tracks?.length) return;
|
|
2462
|
-
const
|
|
3197
|
+
const a = new He();
|
|
2463
3198
|
i.querySelectorAll("[data-tinyfly]").forEach((l) => {
|
|
2464
3199
|
const c = l.getAttribute("data-tinyfly");
|
|
2465
|
-
c &&
|
|
2466
|
-
}), this.symbolInstances.push({ adapter:
|
|
3200
|
+
c && a.registerTarget(c, l);
|
|
3201
|
+
}), this.symbolInstances.push({ adapter: a, timeline: Ve(r.timeline) });
|
|
2467
3202
|
});
|
|
2468
3203
|
}
|
|
2469
3204
|
/**
|
|
@@ -2473,7 +3208,7 @@ class $i {
|
|
|
2473
3208
|
* plays. Pass `{ offset }` to start the media at a timeline offset.
|
|
2474
3209
|
*/
|
|
2475
3210
|
attachMedia(e, n) {
|
|
2476
|
-
this.mediaSync = new
|
|
3211
|
+
this.mediaSync = new on(e, n), this.timeline && (this.mediaSync.setRate(this.timeline.speed), this.mediaSync.update(this.timeline.currentTime, this.isPlaying));
|
|
2477
3212
|
}
|
|
2478
3213
|
/** Detach and pause the currently synced media, if any. */
|
|
2479
3214
|
detachMedia() {
|
|
@@ -2580,15 +3315,15 @@ class $i {
|
|
|
2580
3315
|
this.playhead = i;
|
|
2581
3316
|
const s = this.markers;
|
|
2582
3317
|
if (s.length === 0) return;
|
|
2583
|
-
const { crossings: r } =
|
|
2584
|
-
s.map((
|
|
3318
|
+
const { crossings: r } = Xn(
|
|
3319
|
+
s.map((a) => a.time),
|
|
2585
3320
|
e,
|
|
2586
3321
|
i,
|
|
2587
3322
|
{ duration: n.duration, alternate: n.config.alternate === !0, holding: n.repeatDelayRemaining > 0 }
|
|
2588
3323
|
);
|
|
2589
|
-
for (const
|
|
2590
|
-
if (
|
|
2591
|
-
const l = s[
|
|
3324
|
+
for (const a of r) {
|
|
3325
|
+
if (a.kind !== "event") continue;
|
|
3326
|
+
const l = s[a.index];
|
|
2592
3327
|
if (this.stepping || l.pause) {
|
|
2593
3328
|
this.stepping = !1, n.pause(), n.seek(l.time), this.playhead = { time: l.time, iteration: n.loopIteration, direction: n.direction };
|
|
2594
3329
|
return;
|
|
@@ -2608,7 +3343,7 @@ class $i {
|
|
|
2608
3343
|
}
|
|
2609
3344
|
}
|
|
2610
3345
|
}
|
|
2611
|
-
const
|
|
3346
|
+
const Vs = {
|
|
2612
3347
|
play: "Play",
|
|
2613
3348
|
pause: "Pause",
|
|
2614
3349
|
prev: "Previous step",
|
|
@@ -2623,7 +3358,7 @@ const Mi = {
|
|
|
2623
3358
|
scenario: "Scenario",
|
|
2624
3359
|
fullscreen: "Full screen",
|
|
2625
3360
|
exitFullscreen: "Exit full screen"
|
|
2626
|
-
},
|
|
3361
|
+
}, an = "tinyfly-controls-style", Hs = `
|
|
2627
3362
|
.tf-ctl { --tf-ctl-fg: #1d1d1f; --tf-ctl-bg: #f4f2ee; --tf-ctl-accent: #c2410c; --tf-ctl-radius: 8px;
|
|
2628
3363
|
font: 14px/1.4 var(--tf-ctl-font, system-ui, sans-serif); color: var(--tf-ctl-fg); margin-top: 8px; }
|
|
2629
3364
|
.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); }
|
|
@@ -2672,112 +3407,112 @@ const Mi = {
|
|
|
2672
3407
|
.tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
|
|
2673
3408
|
}
|
|
2674
3409
|
`;
|
|
2675
|
-
let
|
|
2676
|
-
function
|
|
2677
|
-
if (t.getElementById(
|
|
3410
|
+
let Us = 0;
|
|
3411
|
+
function Ws(t) {
|
|
3412
|
+
if (t.getElementById(an)) return;
|
|
2678
3413
|
const e = t.createElement("style");
|
|
2679
|
-
e.id =
|
|
3414
|
+
e.id = an, e.textContent = Hs, t.head.appendChild(e);
|
|
2680
3415
|
}
|
|
2681
|
-
function
|
|
3416
|
+
function Gs(t, e, n = {}) {
|
|
2682
3417
|
const i = e.ownerDocument;
|
|
2683
|
-
|
|
2684
|
-
const s = { ...
|
|
3418
|
+
Ws(i);
|
|
3419
|
+
const s = { ...Vs, ...n.labels }, r = n.speeds ?? [0.5, 1, 2], a = () => t.markers.length > 0, l = () => t.markers.some((O) => O.label !== void 0 || t.caption(O.id) !== void 0), c = i.createElement("div");
|
|
2685
3420
|
c.className = "tf-ctl";
|
|
2686
3421
|
const d = i.createElement("div");
|
|
2687
3422
|
d.className = "tf-ctl-bar", d.setAttribute("role", "group");
|
|
2688
|
-
const u = (
|
|
2689
|
-
const
|
|
2690
|
-
return
|
|
3423
|
+
const u = (O, I, V, nt = "") => {
|
|
3424
|
+
const D = i.createElement("button");
|
|
3425
|
+
return D.type = "button", D.className = `tf-ctl-btn ${nt}`.trim(), D.setAttribute("aria-label", O), D.title = O, D.textContent = I, D.addEventListener("click", V), D;
|
|
2691
3426
|
}, p = u(s.restart, "⟲", () => {
|
|
2692
3427
|
t.pause(), t.seek(0);
|
|
2693
|
-
}), h = u(s.prev, "|◀", () => t.prev()),
|
|
3428
|
+
}), h = u(s.prev, "|◀", () => t.prev()), y = u(s.play, "▶", () => t.isPlaying ? t.pause() : g(), "tf-ctl-primary"), f = u(s.next, "▶|", () => t.next()), g = () => {
|
|
2694
3429
|
t.currentTime >= t.duration - 0.5 && t.seek(0), t.play();
|
|
2695
|
-
},
|
|
2696
|
-
|
|
2697
|
-
t.pause(), t.seek(Number(
|
|
3430
|
+
}, o = i.createElement("input");
|
|
3431
|
+
o.type = "range", o.className = "tf-ctl-scrub", o.min = "0", o.max = "1000", o.step = "1", o.setAttribute("aria-label", s.scrub), o.addEventListener("input", () => {
|
|
3432
|
+
t.pause(), t.seek(Number(o.value) / 1e3 * t.duration);
|
|
2698
3433
|
});
|
|
2699
|
-
const
|
|
2700
|
-
|
|
2701
|
-
const
|
|
2702
|
-
|
|
2703
|
-
for (const
|
|
2704
|
-
const
|
|
2705
|
-
|
|
2706
|
-
}
|
|
2707
|
-
|
|
2708
|
-
const
|
|
2709
|
-
|
|
2710
|
-
const
|
|
2711
|
-
|
|
3434
|
+
const m = i.createElement("span");
|
|
3435
|
+
m.className = "tf-ctl-step";
|
|
3436
|
+
const v = i.createElement("select");
|
|
3437
|
+
v.className = "tf-ctl-speed", v.setAttribute("aria-label", s.speed);
|
|
3438
|
+
for (const O of r) {
|
|
3439
|
+
const I = i.createElement("option");
|
|
3440
|
+
I.value = String(O), I.textContent = `${O}×`, O === 1 && (I.selected = !0), v.appendChild(I);
|
|
3441
|
+
}
|
|
3442
|
+
v.addEventListener("change", () => t.setSpeed(Number(v.value))), d.append(p, h, y, f, o, m), r.length > 0 && d.append(v), c.append(d);
|
|
3443
|
+
const x = n.fullscreen ? Js(e, i, s) : void 0;
|
|
3444
|
+
x && d.append(x.button);
|
|
3445
|
+
const w = i.createElement("p");
|
|
3446
|
+
w.className = "tf-ctl-caption", w.setAttribute("aria-live", "polite"), n.captions !== !1 && c.append(w);
|
|
2712
3447
|
const b = i.createElement("div");
|
|
2713
3448
|
b.className = "tf-ctl-question", b.hidden = !0;
|
|
2714
|
-
const k = i.createElement("span"),
|
|
2715
|
-
b.append(k,
|
|
2716
|
-
const
|
|
2717
|
-
|
|
2718
|
-
const
|
|
2719
|
-
|
|
2720
|
-
const
|
|
2721
|
-
const
|
|
2722
|
-
|
|
2723
|
-
const
|
|
2724
|
-
i.activeElement !==
|
|
2725
|
-
const
|
|
2726
|
-
if (h.hidden = f.hidden =
|
|
2727
|
-
const
|
|
2728
|
-
|
|
2729
|
-
const
|
|
2730
|
-
|
|
2731
|
-
const
|
|
2732
|
-
b.hidden = !
|
|
3449
|
+
const k = i.createElement("span"), M = u(s.reveal, s.reveal, () => t.play(), "tf-ctl-primary");
|
|
3450
|
+
b.append(k, M), c.append(b);
|
|
3451
|
+
const $ = Xs(t, i, s.scenario, n.scenarioControl ?? "buttons");
|
|
3452
|
+
$ && c.append($.element);
|
|
3453
|
+
const S = n.mount;
|
|
3454
|
+
S ? S.appendChild(c) : e.insertAdjacentElement("afterend", c);
|
|
3455
|
+
const A = () => {
|
|
3456
|
+
const O = t.isPlaying;
|
|
3457
|
+
y.textContent = O ? "❚❚" : "▶", y.setAttribute("aria-label", O ? s.pause : s.play), y.title = O ? s.pause : s.play;
|
|
3458
|
+
const I = t.duration;
|
|
3459
|
+
i.activeElement !== o && (o.value = String(I > 0 ? Math.round(t.currentTime / I * 1e3) : 0));
|
|
3460
|
+
const V = t.markers;
|
|
3461
|
+
if (h.hidden = f.hidden = m.hidden = V.length === 0, V.length > 0) {
|
|
3462
|
+
const nt = t.currentMarker, D = nt ? V.indexOf(nt) + 1 : 0;
|
|
3463
|
+
m.textContent = s.stepFormat.replace("{index}", String(D)).replace("{total}", String(V.length)), m.setAttribute("aria-label", `${s.step} ${D} ${s.of} ${V.length}`), h.disabled = t.currentTime <= 0.5, f.disabled = t.currentTime >= I - 0.5;
|
|
3464
|
+
const Re = t.caption() ?? "";
|
|
3465
|
+
w.textContent !== Re && (w.textContent = Re), w.hidden = !l();
|
|
3466
|
+
const Be = !O && nt?.question !== void 0 && Math.abs(t.currentTime - nt.time) < 1;
|
|
3467
|
+
b.hidden = !Be, Be && k.textContent !== nt.question && (k.textContent = nt.question);
|
|
2733
3468
|
} else
|
|
2734
|
-
b.hidden = !0,
|
|
2735
|
-
|
|
2736
|
-
},
|
|
2737
|
-
|
|
2738
|
-
const
|
|
2739
|
-
!
|
|
2740
|
-
const
|
|
2741
|
-
if (
|
|
2742
|
-
const
|
|
2743
|
-
if (!(
|
|
2744
|
-
switch (
|
|
3469
|
+
b.hidden = !0, w.hidden = !0;
|
|
3470
|
+
$?.update();
|
|
3471
|
+
}, P = t.subscribe(A);
|
|
3472
|
+
A();
|
|
3473
|
+
const N = n.keyboardScope ?? e;
|
|
3474
|
+
!N.hasAttribute("tabindex") && N.tabIndex < 0 && (N.tabIndex = 0);
|
|
3475
|
+
const q = /* @__PURE__ */ new WeakSet(), L = (O) => {
|
|
3476
|
+
if (q.has(O) || (q.add(O), O.defaultPrevented || O.altKey || O.ctrlKey || O.metaKey)) return;
|
|
3477
|
+
const I = O.target;
|
|
3478
|
+
if (!(I.tagName === "INPUT" || I.tagName === "SELECT") && !(O.key === " " && I.tagName === "BUTTON"))
|
|
3479
|
+
switch (O.key) {
|
|
2745
3480
|
case " ":
|
|
2746
|
-
|
|
3481
|
+
O.preventDefault(), t.isPlaying ? t.pause() : g();
|
|
2747
3482
|
break;
|
|
2748
3483
|
case "ArrowRight":
|
|
2749
|
-
if (!
|
|
2750
|
-
|
|
3484
|
+
if (!a()) return;
|
|
3485
|
+
O.preventDefault(), t.next();
|
|
2751
3486
|
break;
|
|
2752
3487
|
case "ArrowLeft":
|
|
2753
|
-
if (!
|
|
2754
|
-
|
|
3488
|
+
if (!a()) return;
|
|
3489
|
+
O.preventDefault(), t.prev();
|
|
2755
3490
|
break;
|
|
2756
3491
|
case "Home":
|
|
2757
|
-
|
|
3492
|
+
O.preventDefault(), t.pause(), t.seek(0);
|
|
2758
3493
|
break;
|
|
2759
3494
|
case "f":
|
|
2760
3495
|
case "F":
|
|
2761
|
-
if (!
|
|
2762
|
-
|
|
3496
|
+
if (!x) return;
|
|
3497
|
+
O.preventDefault(), x.active ? x.exit() : x.enter();
|
|
2763
3498
|
break;
|
|
2764
3499
|
}
|
|
2765
3500
|
};
|
|
2766
|
-
return
|
|
3501
|
+
return N.addEventListener("keydown", L), c.addEventListener("keydown", L), {
|
|
2767
3502
|
element: c,
|
|
2768
|
-
fullscreen:
|
|
3503
|
+
fullscreen: x && {
|
|
2769
3504
|
get active() {
|
|
2770
|
-
return
|
|
3505
|
+
return x.active;
|
|
2771
3506
|
},
|
|
2772
|
-
enter:
|
|
2773
|
-
exit:
|
|
3507
|
+
enter: x.enter,
|
|
3508
|
+
exit: x.exit
|
|
2774
3509
|
},
|
|
2775
3510
|
destroy() {
|
|
2776
|
-
|
|
3511
|
+
x?.destroy(), P(), N.removeEventListener("keydown", L), c.removeEventListener("keydown", L), c.remove();
|
|
2777
3512
|
}
|
|
2778
3513
|
};
|
|
2779
3514
|
}
|
|
2780
|
-
function
|
|
3515
|
+
function Xs(t, e, n, i) {
|
|
2781
3516
|
const s = t.scenarios;
|
|
2782
3517
|
if (s.length < 2) return;
|
|
2783
3518
|
if (i === "slider") {
|
|
@@ -2787,30 +3522,30 @@ function Ti(t, e, n, i) {
|
|
|
2787
3522
|
p.textContent = n, p.setAttribute("aria-hidden", "true");
|
|
2788
3523
|
const h = e.createElement("input");
|
|
2789
3524
|
h.type = "range", h.min = "0", h.max = String(s.length - 1), h.step = "1", h.setAttribute("aria-label", n);
|
|
2790
|
-
const
|
|
2791
|
-
return
|
|
2792
|
-
const
|
|
2793
|
-
|
|
2794
|
-
}), u.append(p, h,
|
|
2795
|
-
const
|
|
2796
|
-
e.activeElement !== h && (h.value = String(
|
|
2797
|
-
const
|
|
2798
|
-
|
|
3525
|
+
const y = e.createElement("output");
|
|
3526
|
+
return y.setAttribute("aria-hidden", "true"), h.addEventListener("input", () => {
|
|
3527
|
+
const g = s[Number(h.value)];
|
|
3528
|
+
g && t.setScenario(g.id);
|
|
3529
|
+
}), u.append(p, h, y), { element: u, update: () => {
|
|
3530
|
+
const g = Math.max(0, s.findIndex((m) => m.id === t.scenario));
|
|
3531
|
+
e.activeElement !== h && (h.value = String(g));
|
|
3532
|
+
const o = s[g].label;
|
|
3533
|
+
y.textContent !== o && (y.textContent = o), h.setAttribute("aria-valuetext", o);
|
|
2799
3534
|
} };
|
|
2800
3535
|
}
|
|
2801
3536
|
const r = e.createElement("fieldset");
|
|
2802
3537
|
r.className = "tf-ctl-choices";
|
|
2803
|
-
const
|
|
2804
|
-
|
|
2805
|
-
const l = `tf-ctl-scenario-${++
|
|
3538
|
+
const a = e.createElement("legend");
|
|
3539
|
+
a.textContent = n, r.append(a);
|
|
3540
|
+
const l = `tf-ctl-scenario-${++Us}`, c = s.map((u) => {
|
|
2806
3541
|
const p = e.createElement("label");
|
|
2807
3542
|
p.className = "tf-ctl-choice";
|
|
2808
3543
|
const h = e.createElement("input");
|
|
2809
3544
|
h.type = "radio", h.name = l, h.value = u.id, h.addEventListener("change", () => {
|
|
2810
3545
|
h.checked && t.setScenario(u.id);
|
|
2811
3546
|
});
|
|
2812
|
-
const
|
|
2813
|
-
return
|
|
3547
|
+
const y = e.createElement("span");
|
|
3548
|
+
return y.textContent = u.label, p.append(h, y), r.append(p), h;
|
|
2814
3549
|
});
|
|
2815
3550
|
return { element: r, update: () => {
|
|
2816
3551
|
for (const u of c) {
|
|
@@ -2819,30 +3554,30 @@ function Ti(t, e, n, i) {
|
|
|
2819
3554
|
}
|
|
2820
3555
|
} };
|
|
2821
3556
|
}
|
|
2822
|
-
const
|
|
2823
|
-
function
|
|
3557
|
+
const Ys = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>', Zs = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';
|
|
3558
|
+
function Js(t, e, n) {
|
|
2824
3559
|
const i = e, s = t, r = e.createElement("button");
|
|
2825
3560
|
r.type = "button", r.className = "tf-ctl-btn tf-ctl-fullscreen";
|
|
2826
|
-
let
|
|
3561
|
+
let a, l = "";
|
|
2827
3562
|
const c = () => {
|
|
2828
|
-
const
|
|
2829
|
-
r.innerHTML =
|
|
2830
|
-
const
|
|
2831
|
-
r.setAttribute("aria-label",
|
|
3563
|
+
const g = a !== void 0;
|
|
3564
|
+
r.innerHTML = g ? Zs : Ys;
|
|
3565
|
+
const o = g ? n.exitFullscreen : n.fullscreen;
|
|
3566
|
+
r.setAttribute("aria-label", o), r.title = o, r.setAttribute("aria-pressed", String(g)), t.classList.toggle("tf-fullscreen", g), t.classList.toggle("tf-fullscreen-overlay", a === "overlay");
|
|
2832
3567
|
}, d = () => i.fullscreenElement ?? i.webkitFullscreenElement ?? null, u = () => {
|
|
2833
|
-
d() === t ?
|
|
2834
|
-
}, p = (
|
|
2835
|
-
|
|
3568
|
+
d() === t ? a = "native" : a === "native" && (a = void 0), c();
|
|
3569
|
+
}, p = (g) => {
|
|
3570
|
+
g.key === "Escape" && f();
|
|
2836
3571
|
}, h = () => {
|
|
2837
|
-
|
|
3572
|
+
a = "overlay", l = e.documentElement.style.overflow, e.documentElement.style.overflow = "hidden", e.addEventListener("keydown", p), c();
|
|
2838
3573
|
};
|
|
2839
|
-
async function
|
|
2840
|
-
if (
|
|
2841
|
-
const
|
|
2842
|
-
if (
|
|
3574
|
+
async function y() {
|
|
3575
|
+
if (a) return;
|
|
3576
|
+
const g = s.requestFullscreen?.bind(s) ?? s.webkitRequestFullscreen?.bind(s), o = i.fullscreenEnabled ?? i.webkitFullscreenEnabled ?? !1;
|
|
3577
|
+
if (g && o)
|
|
2843
3578
|
try {
|
|
2844
|
-
if (await
|
|
2845
|
-
|
|
3579
|
+
if (await g(), d() === t) {
|
|
3580
|
+
a = "native", c();
|
|
2846
3581
|
return;
|
|
2847
3582
|
}
|
|
2848
3583
|
} catch {
|
|
@@ -2850,71 +3585,71 @@ function Ni(t, e, n) {
|
|
|
2850
3585
|
h();
|
|
2851
3586
|
}
|
|
2852
3587
|
async function f() {
|
|
2853
|
-
if (
|
|
2854
|
-
e.removeEventListener("keydown", p), e.documentElement.style.overflow = l,
|
|
2855
|
-
else if (
|
|
2856
|
-
|
|
2857
|
-
const
|
|
2858
|
-
d() === t &&
|
|
3588
|
+
if (a === "overlay")
|
|
3589
|
+
e.removeEventListener("keydown", p), e.documentElement.style.overflow = l, a = void 0, c();
|
|
3590
|
+
else if (a === "native") {
|
|
3591
|
+
a = void 0, c();
|
|
3592
|
+
const g = i.exitFullscreen?.bind(i) ?? i.webkitExitFullscreen?.bind(i);
|
|
3593
|
+
d() === t && g && await g();
|
|
2859
3594
|
}
|
|
2860
3595
|
}
|
|
2861
3596
|
return r.addEventListener("click", () => {
|
|
2862
|
-
|
|
3597
|
+
a ? f() : y();
|
|
2863
3598
|
}), e.addEventListener("fullscreenchange", u), e.addEventListener("webkitfullscreenchange", u), c(), {
|
|
2864
3599
|
button: r,
|
|
2865
3600
|
get active() {
|
|
2866
|
-
return
|
|
3601
|
+
return a !== void 0;
|
|
2867
3602
|
},
|
|
2868
|
-
enter:
|
|
3603
|
+
enter: y,
|
|
2869
3604
|
exit: f,
|
|
2870
3605
|
destroy() {
|
|
2871
3606
|
f(), e.removeEventListener("fullscreenchange", u), e.removeEventListener("webkitfullscreenchange", u), r.remove();
|
|
2872
3607
|
}
|
|
2873
3608
|
};
|
|
2874
3609
|
}
|
|
2875
|
-
const
|
|
3610
|
+
const cn = "tinyfly-choices-style", Ks = `
|
|
2876
3611
|
[data-tinyfly-choose] { cursor: pointer; }
|
|
2877
3612
|
[data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
|
|
2878
3613
|
`;
|
|
2879
|
-
function
|
|
2880
|
-
if (t.getElementById(
|
|
3614
|
+
function Qs(t) {
|
|
3615
|
+
if (t.getElementById(cn)) return;
|
|
2881
3616
|
const e = t.createElement("style");
|
|
2882
|
-
e.id =
|
|
3617
|
+
e.id = cn, e.textContent = Ks, t.head.appendChild(e);
|
|
2883
3618
|
}
|
|
2884
|
-
function
|
|
3619
|
+
function tr(t, e) {
|
|
2885
3620
|
const n = Array.from(e.querySelectorAll("[data-tinyfly-choose]"));
|
|
2886
3621
|
if (n.length === 0) return () => {
|
|
2887
3622
|
};
|
|
2888
|
-
|
|
3623
|
+
Qs(e.ownerDocument);
|
|
2889
3624
|
const i = [], s = [];
|
|
2890
3625
|
for (const l of n) {
|
|
2891
|
-
const c = l.getAttribute("data-tinyfly-choose") ?? "", d = [], u = (f,
|
|
2892
|
-
l.hasAttribute(f) || (l.setAttribute(f,
|
|
3626
|
+
const c = l.getAttribute("data-tinyfly-choose") ?? "", d = [], u = (f, g) => {
|
|
3627
|
+
l.hasAttribute(f) || (l.setAttribute(f, g), d.push(f));
|
|
2893
3628
|
};
|
|
2894
3629
|
u("role", "button"), u("tabindex", "0");
|
|
2895
3630
|
const p = t.scenarios.find((f) => f.id === c)?.label;
|
|
2896
3631
|
p !== void 0 && u("aria-label", p), l.setAttribute("aria-pressed", "false"), d.push("aria-pressed"), i.push({ element: l, attributes: d });
|
|
2897
|
-
const h = () => t.setScenario(c),
|
|
2898
|
-
const
|
|
2899
|
-
|
|
3632
|
+
const h = () => t.setScenario(c), y = (f) => {
|
|
3633
|
+
const g = f.key;
|
|
3634
|
+
g !== "Enter" && g !== " " || (f.preventDefault(), h());
|
|
2900
3635
|
};
|
|
2901
|
-
l.addEventListener("click", h), l.addEventListener("keydown",
|
|
2902
|
-
l.removeEventListener("click", h), l.removeEventListener("keydown",
|
|
3636
|
+
l.addEventListener("click", h), l.addEventListener("keydown", y), s.push(() => {
|
|
3637
|
+
l.removeEventListener("click", h), l.removeEventListener("keydown", y);
|
|
2903
3638
|
});
|
|
2904
3639
|
}
|
|
2905
3640
|
const r = () => {
|
|
2906
3641
|
for (const { element: l } of i)
|
|
2907
3642
|
l.setAttribute("aria-pressed", String(l.getAttribute("data-tinyfly-choose") === t.scenario));
|
|
2908
|
-
},
|
|
3643
|
+
}, a = t.subscribe(r);
|
|
2909
3644
|
return r(), () => {
|
|
2910
|
-
|
|
3645
|
+
a();
|
|
2911
3646
|
for (const l of s) l();
|
|
2912
3647
|
for (const { element: l, attributes: c } of i) for (const d of c) l.removeAttribute(d);
|
|
2913
3648
|
};
|
|
2914
3649
|
}
|
|
2915
|
-
const
|
|
2916
|
-
let
|
|
2917
|
-
function
|
|
3650
|
+
const ln = /* @__PURE__ */ new WeakMap(), er = /* @__PURE__ */ new WeakMap();
|
|
3651
|
+
let nr = 0;
|
|
3652
|
+
function Tt(t, e, n) {
|
|
2918
3653
|
if (t)
|
|
2919
3654
|
try {
|
|
2920
3655
|
return JSON.parse(t);
|
|
@@ -2923,222 +3658,222 @@ function wt(t, e, n) {
|
|
|
2923
3658
|
return;
|
|
2924
3659
|
}
|
|
2925
3660
|
}
|
|
2926
|
-
async function
|
|
2927
|
-
const n =
|
|
3661
|
+
async function ir(t, e = {}) {
|
|
3662
|
+
const n = ln.get(t);
|
|
2928
3663
|
if (n) return n;
|
|
2929
|
-
const i = Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")), s = i[0], r = t.getAttribute("data-src"),
|
|
3664
|
+
const i = Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")), s = i[0], r = t.getAttribute("data-src"), a = rr(t.getAttribute("data-markers")), l = i.length > 1 || s?.hasAttribute("data-scenario") ? sr(i, a, t) : void 0;
|
|
2930
3665
|
if (l && l.length === 0) return;
|
|
2931
|
-
let c = s && !l ?
|
|
2932
|
-
if (!c && r &&
|
|
2933
|
-
const
|
|
2934
|
-
|
|
3666
|
+
let c = s && !l ? Tt(s.textContent, "timeline", t) : void 0;
|
|
3667
|
+
if (!c && r && a) {
|
|
3668
|
+
const y = await fetch(r);
|
|
3669
|
+
y.ok && (c = await y.json());
|
|
2935
3670
|
}
|
|
2936
|
-
if (c &&
|
|
3671
|
+
if (c && a && (c = Wn(c, a)), !c && !r && !l) {
|
|
2937
3672
|
console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)', t);
|
|
2938
3673
|
return;
|
|
2939
3674
|
}
|
|
2940
|
-
const d =
|
|
3675
|
+
const d = Tt(t.querySelector("script[data-tinyfly-captions]")?.textContent, "captions", t), u = {
|
|
2941
3676
|
playWhenVisible: !0,
|
|
2942
3677
|
...e.player,
|
|
2943
3678
|
...d && { captions: d },
|
|
2944
|
-
...
|
|
3679
|
+
...Tt(t.getAttribute("data-options"), "data-options", t)
|
|
2945
3680
|
};
|
|
2946
|
-
|
|
2947
|
-
const p = new
|
|
2948
|
-
if (
|
|
2949
|
-
const
|
|
2950
|
-
await p.loadScenarios(l, { initial: l.some((f) => f.id ===
|
|
3681
|
+
or(t);
|
|
3682
|
+
const p = new Bs(t, u), h = { element: t, player: p };
|
|
3683
|
+
if (ln.set(t, h), t.setAttribute("data-tinyfly-mounted", ""), l) {
|
|
3684
|
+
const y = t.getAttribute("data-scenario") ?? void 0;
|
|
3685
|
+
await p.loadScenarios(l, { initial: l.some((f) => f.id === y) ? y : void 0 }), er.set(t, tr(p, t));
|
|
2951
3686
|
} else
|
|
2952
3687
|
await p.load(c ?? r);
|
|
2953
3688
|
if (t.getAttribute("data-controls") !== "false") {
|
|
2954
|
-
const
|
|
2955
|
-
h.controls =
|
|
3689
|
+
const y = Tt(t.getAttribute("data-labels"), "data-labels", t), f = t.querySelector("figcaption"), g = t.getAttribute("data-scenario-legend"), o = t.getAttribute("data-scenario-control");
|
|
3690
|
+
h.controls = Gs(p, t, {
|
|
2956
3691
|
...e.controls,
|
|
2957
3692
|
...t.getAttribute("data-fullscreen") === "true" ? { fullscreen: !0 } : {},
|
|
2958
|
-
...
|
|
2959
|
-
labels: { ...e.controls?.labels, ...
|
|
3693
|
+
...o === "slider" || o === "buttons" ? { scenarioControl: o } : {},
|
|
3694
|
+
labels: { ...e.controls?.labels, ...y, ...g ? { scenario: g } : {} },
|
|
2960
3695
|
// Inside the figure, before its figcaption, so the caption stays last.
|
|
2961
3696
|
mount: void 0
|
|
2962
3697
|
}), f ? t.insertBefore(h.controls.element, f) : t.appendChild(h.controls.element);
|
|
2963
3698
|
}
|
|
2964
3699
|
return h;
|
|
2965
3700
|
}
|
|
2966
|
-
function
|
|
3701
|
+
function sr(t, e, n) {
|
|
2967
3702
|
const i = [];
|
|
2968
3703
|
return t.forEach((s, r) => {
|
|
2969
|
-
const
|
|
2970
|
-
if (!
|
|
3704
|
+
const a = Tt(s.textContent, "timeline", n);
|
|
3705
|
+
if (!a) return;
|
|
2971
3706
|
const l = s.getAttribute("data-scenario") || `scenario-${r + 1}`;
|
|
2972
3707
|
if (i.some((d) => d.id === l)) {
|
|
2973
3708
|
console.warn(`tinyfly: scenario id "${l}" is used more than once; the later one is skipped`, n);
|
|
2974
3709
|
return;
|
|
2975
3710
|
}
|
|
2976
3711
|
const c = s.getAttribute("data-scenario-label") ?? void 0;
|
|
2977
|
-
i.push({ id: l, label: c, timeline: e ?
|
|
3712
|
+
i.push({ id: l, label: c, timeline: e ? Wn(a, e) : a });
|
|
2978
3713
|
}), i;
|
|
2979
3714
|
}
|
|
2980
|
-
function
|
|
3715
|
+
function Wn(t, e) {
|
|
2981
3716
|
return t.config.markers?.length ? t : { ...t, config: { ...t.config, markers: e.map((n, i) => ({ id: `step-${i + 1}`, time: n })) } };
|
|
2982
3717
|
}
|
|
2983
|
-
function
|
|
3718
|
+
function rr(t) {
|
|
2984
3719
|
if (!t) return;
|
|
2985
3720
|
const e = t.split(/[\s,]+/).filter(Boolean).map(Number).filter((n) => Number.isFinite(n) && n >= 0).sort((n, i) => n - i);
|
|
2986
3721
|
return e.length > 0 ? e : void 0;
|
|
2987
3722
|
}
|
|
2988
|
-
function
|
|
3723
|
+
function or(t) {
|
|
2989
3724
|
const e = t.querySelector("svg");
|
|
2990
3725
|
if (!e || e.hasAttribute("role") || e.hasAttribute("aria-hidden")) return;
|
|
2991
3726
|
const n = t.getAttribute("data-alt"), i = t.querySelector("figcaption");
|
|
2992
|
-
e.setAttribute("role", "img"), n ? e.setAttribute("aria-label", n) : i && (i.id ||= `tinyfly-caption-${++
|
|
3727
|
+
e.setAttribute("role", "img"), n ? e.setAttribute("aria-label", n) : i && (i.id ||= `tinyfly-caption-${++nr}`, e.setAttribute("aria-labelledby", i.id));
|
|
2993
3728
|
}
|
|
2994
|
-
const
|
|
2995
|
-
function
|
|
3729
|
+
const ar = "http://www.w3.org/2000/svg", ge = /* @__PURE__ */ new WeakMap();
|
|
3730
|
+
function cr(t, e) {
|
|
2996
3731
|
const n = t?.values.get(e);
|
|
2997
3732
|
return n ? Object.fromEntries(n) : {};
|
|
2998
3733
|
}
|
|
2999
|
-
async function
|
|
3000
|
-
const n =
|
|
3734
|
+
async function lr(t, e = {}) {
|
|
3735
|
+
const n = ge.get(t);
|
|
3001
3736
|
if (n) return n;
|
|
3002
3737
|
const i = t.querySelector("script[data-tinyfly-figure]");
|
|
3003
3738
|
let s;
|
|
3004
3739
|
try {
|
|
3005
|
-
s =
|
|
3740
|
+
s = zt(JSON.parse(i?.textContent ?? "null"));
|
|
3006
3741
|
} catch (h) {
|
|
3007
3742
|
console.warn("tinyfly: math figure is missing or invalid", t, h);
|
|
3008
3743
|
return;
|
|
3009
3744
|
}
|
|
3010
3745
|
const r = t.getAttribute("data-target") ?? "fig";
|
|
3011
|
-
let
|
|
3012
|
-
|
|
3746
|
+
let a = t.querySelector("svg[data-tinyfly-math-svg]");
|
|
3747
|
+
a || (a = t.ownerDocument.createElementNS(ar, "svg"), a.setAttribute("data-tinyfly-math-svg", ""), a.setAttribute("viewBox", `0 0 ${s.width} ${s.height}`), a.setAttribute("style", "display:block;width:100%;height:auto"), t.insertBefore(a, t.querySelector("figcaption")));
|
|
3013
3748
|
const l = (h) => {
|
|
3014
|
-
|
|
3749
|
+
a.innerHTML = je(de(s, h));
|
|
3015
3750
|
};
|
|
3016
3751
|
if (l({}), !(t.querySelector("script[data-tinyfly-timeline]") || t.hasAttribute("data-src"))) {
|
|
3017
3752
|
const h = { element: t, figure: s, redraw: () => l({}) };
|
|
3018
|
-
return
|
|
3753
|
+
return ge.set(t, h), h;
|
|
3019
3754
|
}
|
|
3020
|
-
const d = await
|
|
3755
|
+
const d = await ir(t, e);
|
|
3021
3756
|
if (!d) return;
|
|
3022
|
-
const u = () => l(
|
|
3757
|
+
const u = () => l(cr(d.player.state, r));
|
|
3023
3758
|
d.player.subscribe(u), u();
|
|
3024
3759
|
const p = { ...d, figure: s, redraw: u };
|
|
3025
|
-
return
|
|
3760
|
+
return ge.set(t, p), p;
|
|
3026
3761
|
}
|
|
3027
|
-
async function
|
|
3762
|
+
async function gr(t = document, e = {}) {
|
|
3028
3763
|
const n = Array.from(t.querySelectorAll("[data-tinyfly-math]"));
|
|
3029
|
-
return (await Promise.all(n.map((s) =>
|
|
3764
|
+
return (await Promise.all(n.map((s) => lr(s, e)))).filter((s) => s !== void 0);
|
|
3030
3765
|
}
|
|
3031
|
-
const
|
|
3032
|
-
function
|
|
3033
|
-
|
|
3766
|
+
const ur = "http://www.w3.org/2000/svg";
|
|
3767
|
+
function br(t, e, n = {}) {
|
|
3768
|
+
zt(e);
|
|
3034
3769
|
const i = { ...e.values ?? {} };
|
|
3035
|
-
for (const
|
|
3036
|
-
if (typeof i[
|
|
3037
|
-
for (const
|
|
3038
|
-
if ("vector" in
|
|
3039
|
-
if ("matrix" in
|
|
3040
|
-
}
|
|
3041
|
-
const s =
|
|
3042
|
-
|
|
3043
|
-
const l = n.drag ?? [], c = (
|
|
3044
|
-
if ("vector" in
|
|
3045
|
-
const [b, k,
|
|
3046
|
-
return
|
|
3770
|
+
for (const w of n.sliders ?? [])
|
|
3771
|
+
if (typeof i[w.value] != "number") throw new Error(`mathExplorable: slider value "${w.value}" is not a number value of the figure`);
|
|
3772
|
+
for (const w of n.drag ?? []) {
|
|
3773
|
+
if ("vector" in w && !st(i[w.vector])) throw new Error(`mathExplorable: "${w.vector}" is not a vector value of the figure`);
|
|
3774
|
+
if ("matrix" in w && !vt(i[w.matrix])) throw new Error(`mathExplorable: "${w.matrix}" is not a matrix value of the figure`);
|
|
3775
|
+
}
|
|
3776
|
+
const s = Dn(e), r = t.ownerDocument, a = r.createElementNS(ur, "svg");
|
|
3777
|
+
a.setAttribute("viewBox", `0 0 ${e.width} ${e.height}`), a.setAttribute("style", "display:block;width:100%;height:auto;touch-action:none"), a.setAttribute("role", "img"), t.appendChild(a);
|
|
3778
|
+
const l = n.drag ?? [], c = (w) => {
|
|
3779
|
+
if ("vector" in w) return i[w.vector];
|
|
3780
|
+
const [b, k, M, $] = i[w.matrix];
|
|
3781
|
+
return w.column === 0 ? [b, M] : [k, $];
|
|
3047
3782
|
}, d = () => {
|
|
3048
|
-
const
|
|
3049
|
-
const [k,
|
|
3050
|
-
return `<circle cx="${k}" cy="${
|
|
3783
|
+
const w = l.map((b) => {
|
|
3784
|
+
const [k, M] = s.toScreen(c(b));
|
|
3785
|
+
return `<circle cx="${k}" cy="${M}" r="${14 * s.scale}" fill="rgba(255,255,255,0.08)" stroke="rgba(255,255,255,0.55)" stroke-width="${1.5 * s.scale}" style="cursor:grab"/>`;
|
|
3051
3786
|
});
|
|
3052
|
-
|
|
3053
|
-
}, u = (
|
|
3054
|
-
if (!(
|
|
3055
|
-
i[
|
|
3056
|
-
const k = p.get(
|
|
3057
|
-
k && typeof b == "number" && (k.value = String(b), h.get(
|
|
3787
|
+
a.innerHTML = je(de(e, i)) + w.join(""), n.onChange?.({ ...i });
|
|
3788
|
+
}, u = (w, b) => {
|
|
3789
|
+
if (!(w in i)) throw new Error(`mathExplorable: no value "${w}"`);
|
|
3790
|
+
i[w] = b;
|
|
3791
|
+
const k = p.get(w);
|
|
3792
|
+
k && typeof b == "number" && (k.value = String(b), h.get(w).textContent = String(b)), d();
|
|
3058
3793
|
}, p = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
|
|
3059
|
-
let
|
|
3794
|
+
let y;
|
|
3060
3795
|
if (n.sliders?.length) {
|
|
3061
|
-
|
|
3062
|
-
for (const
|
|
3796
|
+
y = r.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");
|
|
3797
|
+
for (const w of n.sliders) {
|
|
3063
3798
|
const b = r.createElement("label");
|
|
3064
3799
|
b.setAttribute("style", "display:flex;align-items:center;gap:6px");
|
|
3065
3800
|
const k = r.createElement("input");
|
|
3066
|
-
k.type = "range", k.min = String(
|
|
3067
|
-
const
|
|
3068
|
-
|
|
3801
|
+
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);
|
|
3802
|
+
const M = r.createElement("output");
|
|
3803
|
+
M.textContent = String(i[w.value]), k.addEventListener("input", () => u(w.value, Number(k.value))), b.append(w.label ?? w.value, k, M), y.appendChild(b), p.set(w.value, k), h.set(w.value, M);
|
|
3069
3804
|
}
|
|
3070
|
-
t.appendChild(
|
|
3805
|
+
t.appendChild(y);
|
|
3071
3806
|
}
|
|
3072
|
-
const f = n.snap ?? 0.1,
|
|
3073
|
-
const b =
|
|
3074
|
-
return [Number(
|
|
3807
|
+
const f = n.snap ?? 0.1, g = (w) => {
|
|
3808
|
+
const b = a.getBoundingClientRect(), k = (w.clientX - b.left) / (b.width || e.width) * e.width, M = (w.clientY - b.top) / (b.height || e.height) * e.height, [$, S] = s.toWorld([k, M]), A = (P) => f > 0 ? Math.round(P / f) * f : P;
|
|
3809
|
+
return [Number(A($).toFixed(6)), Number(A(S).toFixed(6))];
|
|
3075
3810
|
};
|
|
3076
|
-
let
|
|
3077
|
-
const
|
|
3078
|
-
const b =
|
|
3079
|
-
let
|
|
3080
|
-
for (const
|
|
3081
|
-
const [
|
|
3082
|
-
|
|
3083
|
-
}
|
|
3084
|
-
|
|
3085
|
-
},
|
|
3086
|
-
if (!
|
|
3087
|
-
const [b, k] =
|
|
3088
|
-
if ("vector" in
|
|
3089
|
-
u(
|
|
3811
|
+
let o;
|
|
3812
|
+
const m = (w) => {
|
|
3813
|
+
const b = a.getBoundingClientRect(), k = e.width / (b.width || e.width), M = [(w.clientX - b.left) * k, (w.clientY - b.top) * k];
|
|
3814
|
+
let $;
|
|
3815
|
+
for (const S of l) {
|
|
3816
|
+
const [A, P] = s.toScreen(c(S)), N = Math.hypot(A - M[0], P - M[1]);
|
|
3817
|
+
N < 30 * s.scale * Math.max(1, k) && (!$ || N < $.distance) && ($ = { handle: S, distance: N });
|
|
3818
|
+
}
|
|
3819
|
+
$ && (o = $.handle, a.setPointerCapture?.(w.pointerId), w.preventDefault());
|
|
3820
|
+
}, v = (w) => {
|
|
3821
|
+
if (!o) return;
|
|
3822
|
+
const [b, k] = g(w);
|
|
3823
|
+
if ("vector" in o)
|
|
3824
|
+
u(o.vector, [b, k]);
|
|
3090
3825
|
else {
|
|
3091
|
-
const [$,
|
|
3092
|
-
u(
|
|
3826
|
+
const [M, $, S, A] = i[o.matrix];
|
|
3827
|
+
u(o.matrix, o.column === 0 ? [b, $, k, A] : [M, b, S, k]);
|
|
3093
3828
|
}
|
|
3094
|
-
},
|
|
3095
|
-
|
|
3829
|
+
}, x = () => {
|
|
3830
|
+
o = void 0;
|
|
3096
3831
|
};
|
|
3097
|
-
return
|
|
3832
|
+
return a.addEventListener("pointerdown", m), a.addEventListener("pointermove", v), a.addEventListener("pointerup", x), a.addEventListener("pointercancel", x), d(), {
|
|
3098
3833
|
get values() {
|
|
3099
3834
|
return { ...i };
|
|
3100
3835
|
},
|
|
3101
3836
|
set: u,
|
|
3102
3837
|
destroy() {
|
|
3103
|
-
|
|
3838
|
+
a.removeEventListener("pointerdown", m), a.removeEventListener("pointermove", v), a.removeEventListener("pointerup", x), a.removeEventListener("pointercancel", x), y?.remove();
|
|
3104
3839
|
}
|
|
3105
3840
|
};
|
|
3106
3841
|
}
|
|
3107
|
-
const
|
|
3842
|
+
const jt = (t, e, n) => ({
|
|
3108
3843
|
width: t.width ?? 600,
|
|
3109
3844
|
height: t.height ?? 600,
|
|
3110
3845
|
...t.theme ? { theme: t.theme } : {},
|
|
3111
3846
|
...t.x ? { x: t.x } : {},
|
|
3112
3847
|
values: e,
|
|
3113
3848
|
items: n
|
|
3114
|
-
}),
|
|
3115
|
-
function
|
|
3116
|
-
return
|
|
3849
|
+
}), _e = "\\begin{bmatrix} \\val{M.a} & \\val{M.b} \\\\ \\val{M.c} & \\val{M.d} \\end{bmatrix}", De = (t) => [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.1];
|
|
3850
|
+
function vr(t = {}) {
|
|
3851
|
+
return jt(t, { M: t.matrix ?? Ft }, [
|
|
3117
3852
|
{ id: "grid", kind: "grid", transform: "M", ghost: !0 },
|
|
3118
3853
|
{ id: "square", kind: "polygon", transform: "M", color: "yellow", fillOpacity: 0.25 },
|
|
3119
3854
|
{ id: "basis", kind: "basis", transform: "M" },
|
|
3120
|
-
{ id: "matrix", kind: "label", tex:
|
|
3855
|
+
{ id: "matrix", kind: "label", tex: _e, at: De(t), screen: !0, align: "left" }
|
|
3121
3856
|
]);
|
|
3122
3857
|
}
|
|
3123
|
-
function
|
|
3124
|
-
return
|
|
3858
|
+
function wr(t = {}) {
|
|
3859
|
+
return jt(t, { M: t.matrix ?? Ft }, [
|
|
3125
3860
|
{ id: "grid", kind: "grid", transform: "M", ghost: !0 },
|
|
3126
3861
|
{ id: "square", kind: "polygon", transform: "M", color: "yellow", fillOpacity: 0.35, label: "\\det = \\val{M.det}" },
|
|
3127
3862
|
{ id: "basis", kind: "basis", transform: "M" },
|
|
3128
|
-
{ id: "matrix", kind: "label", tex:
|
|
3863
|
+
{ id: "matrix", kind: "label", tex: _e, at: De(t), screen: !0, align: "left" }
|
|
3129
3864
|
]);
|
|
3130
3865
|
}
|
|
3131
|
-
function
|
|
3132
|
-
return
|
|
3866
|
+
function kr(t) {
|
|
3867
|
+
return jt(t, { M: Ft, A: t.matrix }, [
|
|
3133
3868
|
{ id: "grid", kind: "grid", transform: "M", ghost: !0 },
|
|
3134
3869
|
{ id: "eigen", kind: "line", eigen: "A", color: "yellow", width: 3 },
|
|
3135
3870
|
{ id: "basis", kind: "basis", transform: "M" },
|
|
3136
|
-
{ id: "matrix", kind: "label", tex:
|
|
3871
|
+
{ id: "matrix", kind: "label", tex: _e, at: De(t), screen: !0, align: "left" }
|
|
3137
3872
|
]);
|
|
3138
3873
|
}
|
|
3139
|
-
function
|
|
3874
|
+
function $r(t) {
|
|
3140
3875
|
const e = [t.u[0] + t.v[0], t.u[1] + t.v[1]];
|
|
3141
|
-
return
|
|
3876
|
+
return jt(t, { u: t.u, v: t.v, s: e }, [
|
|
3142
3877
|
{ id: "grid", kind: "grid", ghost: !1, color: "grey", opacity: 0.5 },
|
|
3143
3878
|
{ id: "axes", kind: "axes" },
|
|
3144
3879
|
{ id: "arrowU", kind: "vector", to: "u", color: "green", label: "\\vec{u}", labelAt: "middle" },
|
|
@@ -3146,15 +3881,15 @@ function nr(t) {
|
|
|
3146
3881
|
{ id: "sum", kind: "vector", to: "s", color: "yellow", label: "\\vec{u} + \\vec{v}" }
|
|
3147
3882
|
]);
|
|
3148
3883
|
}
|
|
3149
|
-
function
|
|
3884
|
+
function Mr(t) {
|
|
3150
3885
|
const e = [
|
|
3151
3886
|
{ id: "axes", kind: "axes" },
|
|
3152
3887
|
{ id: "spanU", kind: "line", along: "u", color: "green", dashed: !0 },
|
|
3153
3888
|
{ id: "arrowU", kind: "vector", to: "u", color: "green", label: "\\vec{u}" }
|
|
3154
3889
|
], n = { u: t.u };
|
|
3155
|
-
return t.v && (n.v = t.v, e.splice(2, 0, { id: "spanV", kind: "line", along: "v", color: "red", dashed: !0 }), e.push({ id: "arrowV", kind: "vector", to: "v", color: "red", label: "\\vec{v}" })),
|
|
3890
|
+
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}" })), jt(t, n, e);
|
|
3156
3891
|
}
|
|
3157
|
-
const
|
|
3892
|
+
const xt = (t, e, n) => ({
|
|
3158
3893
|
width: t.width ?? 600,
|
|
3159
3894
|
height: t.height ?? 600,
|
|
3160
3895
|
...t.theme ? { theme: t.theme } : {},
|
|
@@ -3163,18 +3898,18 @@ const gt = (t, e, n) => ({
|
|
|
3163
3898
|
values: e,
|
|
3164
3899
|
items: [{ id: "axes", kind: "axes" }, { id: "f", kind: "function", expr: t.expr, color: "blue" }, ...n]
|
|
3165
3900
|
});
|
|
3166
|
-
function
|
|
3167
|
-
return
|
|
3901
|
+
function xr(t) {
|
|
3902
|
+
return xt(t, { a: t.at ?? 1 }, [
|
|
3168
3903
|
{ id: "tangent", kind: "tangent", expr: t.expr, at: "a", color: "yellow", label: "\\text{slope} = \\val{tangent.slope}" }
|
|
3169
3904
|
]);
|
|
3170
3905
|
}
|
|
3171
|
-
function
|
|
3172
|
-
return
|
|
3906
|
+
function Sr(t) {
|
|
3907
|
+
return xt(t, { a: t.at ?? 1, h: t.h ?? 2 }, [
|
|
3173
3908
|
{ id: "secant", kind: "tangent", expr: t.expr, at: "a", h: "h", color: "yellow", label: "\\frac{\\Delta y}{\\Delta x} = \\val{secant.slope}" }
|
|
3174
3909
|
]);
|
|
3175
3910
|
}
|
|
3176
|
-
function
|
|
3177
|
-
const e =
|
|
3911
|
+
function Ar(t) {
|
|
3912
|
+
const e = xt(t, { n: t.n ?? 4 }, [
|
|
3178
3913
|
{ id: "sum", kind: "riemann", expr: t.expr, from: t.from, to: t.to, n: "n", rule: t.rule ?? "left", color: "teal" }
|
|
3179
3914
|
]);
|
|
3180
3915
|
return e.items.push(e.items.splice(1, 1)[0]), e.items.push({
|
|
@@ -3187,8 +3922,8 @@ function or(t) {
|
|
|
3187
3922
|
tex: "n = \\val{sum.n:0} \\quad \\text{sum} = \\val{sum.sum:3} \\quad \\int = \\val{sum.exact:3}"
|
|
3188
3923
|
}), e;
|
|
3189
3924
|
}
|
|
3190
|
-
function
|
|
3191
|
-
const e =
|
|
3925
|
+
function Er(t) {
|
|
3926
|
+
const e = xt(t, { b: t.to }, [
|
|
3192
3927
|
{ id: "area", kind: "area", expr: t.expr, from: t.from, to: "b", color: "teal" }
|
|
3193
3928
|
]);
|
|
3194
3929
|
return e.items.push(e.items.splice(1, 1)[0]), e.items.push({
|
|
@@ -3201,8 +3936,8 @@ function ar(t) {
|
|
|
3201
3936
|
tex: `\\int_{${t.from}}^{\\val{b:2}} f(x)\\,dx = \\val{area.value:3}`
|
|
3202
3937
|
}), e;
|
|
3203
3938
|
}
|
|
3204
|
-
function
|
|
3205
|
-
const e =
|
|
3939
|
+
function Tr(t) {
|
|
3940
|
+
const e = xt(t, { order: t.order ?? 1 }, [
|
|
3206
3941
|
{ id: "taylor", kind: "taylor", expr: t.expr, at: t.at ?? 0, order: "order", color: "yellow" },
|
|
3207
3942
|
{ id: "centre", kind: "point", on: t.expr, x: t.at ?? 0, color: "yellow" }
|
|
3208
3943
|
]);
|
|
@@ -3216,8 +3951,8 @@ function lr(t) {
|
|
|
3216
3951
|
tex: "\\text{degree } \\val{taylor.degree:0}"
|
|
3217
3952
|
}), e;
|
|
3218
3953
|
}
|
|
3219
|
-
function
|
|
3220
|
-
const e =
|
|
3954
|
+
function Or(t) {
|
|
3955
|
+
const e = xt(t, { p: t.from ?? t.at - 2 }, [
|
|
3221
3956
|
{ id: "hole", kind: "point", at: [t.at, t.limit], hollow: !0, color: "blue", radius: 7 },
|
|
3222
3957
|
{ id: "moving", kind: "point", on: t.expr, x: "p", color: "yellow" }
|
|
3223
3958
|
]);
|
|
@@ -3231,7 +3966,7 @@ function cr(t) {
|
|
|
3231
3966
|
tex: "f(\\val{moving.x:3}) = \\val{moving.y:4}"
|
|
3232
3967
|
}), e;
|
|
3233
3968
|
}
|
|
3234
|
-
const
|
|
3969
|
+
const gt = (t, e, n, i) => ({
|
|
3235
3970
|
width: t.width ?? 600,
|
|
3236
3971
|
height: t.height ?? 600,
|
|
3237
3972
|
...t.theme ? { theme: t.theme } : {},
|
|
@@ -3239,7 +3974,7 @@ const dt = (t, e, n, i) => ({
|
|
|
3239
3974
|
y: t.y ?? e.y,
|
|
3240
3975
|
values: n,
|
|
3241
3976
|
items: i
|
|
3242
|
-
}),
|
|
3977
|
+
}), St = (t, e) => ({
|
|
3243
3978
|
id: "readout",
|
|
3244
3979
|
kind: "label",
|
|
3245
3980
|
screen: !0,
|
|
@@ -3248,137 +3983,356 @@ const dt = (t, e, n, i) => ({
|
|
|
3248
3983
|
at: [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.08],
|
|
3249
3984
|
tex: e
|
|
3250
3985
|
});
|
|
3251
|
-
function
|
|
3986
|
+
function Nr(t = {}) {
|
|
3252
3987
|
const [e, n] = t.shade ?? [-1, 1];
|
|
3253
|
-
return
|
|
3988
|
+
return gt(t, { x: [-4, 4], y: [-0.08, 0.55] }, { mu: t.mean ?? 0, sigma: t.sd ?? 1, a: e, b: n }, [
|
|
3254
3989
|
{ id: "axes", kind: "axes", ticks: 1, labels: !0 },
|
|
3255
3990
|
{ id: "dist", kind: "distribution", distribution: { kind: "normal", mean: "mu", sd: "sigma" }, shade: ["a", "b"] },
|
|
3256
|
-
|
|
3991
|
+
St(t, "P(\\val{a:2} \\le X \\le \\val{b:2}) = \\val{dist.p:3}")
|
|
3257
3992
|
]);
|
|
3258
3993
|
}
|
|
3259
|
-
function
|
|
3994
|
+
function Pr(t = {}) {
|
|
3260
3995
|
const e = t.n ?? 10;
|
|
3261
|
-
return
|
|
3996
|
+
return gt(t, { x: [-1, e + 1], y: [-0.04, 0.4] }, { n: e, p: t.p ?? 0.5 }, [
|
|
3262
3997
|
{ id: "axes", kind: "axes", ticks: Math.max(1, Math.round(e / 10)) },
|
|
3263
3998
|
{ id: "dist", kind: "distribution", distribution: { kind: "binomial", n: "n", p: "p" } },
|
|
3264
|
-
|
|
3999
|
+
St(t, "n = \\val{n:0} \\quad p = \\val{p:2} \\quad \\mu = \\val{dist.mean:2}")
|
|
3265
4000
|
]);
|
|
3266
4001
|
}
|
|
3267
|
-
function
|
|
3268
|
-
return
|
|
4002
|
+
function Ir(t = {}) {
|
|
4003
|
+
return gt(t, { x: [-0.2, 3.2], y: [-0.2, 3] }, { k: t.k ?? 1, samples: t.samples ?? 2e3 }, [
|
|
3269
4004
|
{ id: "axes", kind: "axes", ticks: 1 },
|
|
3270
4005
|
{ id: "hist", kind: "histogram", distribution: { kind: "mean", of: t.of ?? { kind: "exponential", rate: 1 }, count: "k" }, count: "samples", bins: [0, 3, 45], curve: !0, color: "teal" },
|
|
3271
|
-
|
|
4006
|
+
St(t, "k = \\val{k:0} \\text{ draws averaged} \\quad \\bar{x} = \\val{hist.mean:3} \\quad s = \\val{hist.sd:3}")
|
|
3272
4007
|
]);
|
|
3273
4008
|
}
|
|
3274
|
-
function
|
|
4009
|
+
function Fr(t = {}) {
|
|
3275
4010
|
const e = t.rows ?? 10;
|
|
3276
|
-
return
|
|
4011
|
+
return gt(t, { x: [-(e + 2) * 0.25, (e + 2) * 0.25], y: [-12, 1] }, { balls: t.balls ?? 0 }, [
|
|
3277
4012
|
{ id: "board", kind: "galton", rows: e, balls: "balls", spacing: 0.5, top: 0 },
|
|
3278
|
-
|
|
4013
|
+
St(t, "\\val{board.landed:0} \\text{ balls}")
|
|
3279
4014
|
]);
|
|
3280
4015
|
}
|
|
3281
|
-
function
|
|
3282
|
-
return
|
|
4016
|
+
function Lr(t = {}) {
|
|
4017
|
+
return gt(t, { x: [-1.3, 1.3], y: [-1.3, 1.3] }, { count: t.count ?? 0 }, [
|
|
3283
4018
|
{ id: "square", kind: "polygon", points: [[-1, -1], [1, -1], [1, 1], [-1, 1]], color: "grey", fillOpacity: 0 },
|
|
3284
4019
|
{ id: "circle", kind: "parametric", x: "cos(t)", y: "sin(t)", color: "yellow", width: 2.5 },
|
|
3285
4020
|
{ id: "pts", kind: "scatter", points: { kind: "uniform", x: [-1, 1], y: [-1, 1] }, count: "count", inside: "x^2 + y^2 - 1", color: "blue", radius: 2.2 },
|
|
3286
|
-
|
|
4021
|
+
St(t, "\\frac{\\text{inside}}{\\text{all}} = \\frac{\\val{pts.inside:0}}{\\val{pts.count:0}} = \\val{pts.ratio:4} \\approx \\frac{\\pi}{4}")
|
|
3287
4022
|
]);
|
|
3288
4023
|
}
|
|
3289
|
-
function
|
|
3290
|
-
return
|
|
4024
|
+
function Cr(t = {}) {
|
|
4025
|
+
return gt(t, { x: [-1, 11], y: [-2, 10] }, { slope: t.slope ?? 0.6, intercept: t.intercept ?? 1, noise: t.noise ?? 1, count: t.count ?? 60 }, [
|
|
3291
4026
|
{ id: "axes", kind: "axes", ticks: 2 },
|
|
3292
4027
|
{ id: "pts", kind: "scatter", points: { kind: "linear", slope: "slope", intercept: "intercept", noise: "noise", x: [0, 10] }, count: "count", fit: !0, radius: 3.5 },
|
|
3293
|
-
|
|
4028
|
+
St(t, "y = \\val{pts.slope:2}\\,x + \\val{pts.intercept:2} \\quad r = \\val{pts.r:2}")
|
|
3294
4029
|
]);
|
|
3295
4030
|
}
|
|
3296
|
-
function
|
|
3297
|
-
return
|
|
4031
|
+
function qr(t = {}) {
|
|
4032
|
+
return gt(t, { x: [0, 1], y: [0, 1] }, { prior: t.prior ?? 0.1, sensitivity: t.sensitivity ?? 0.9, falsePositive: t.falsePositive ?? 0.1 }, [
|
|
3298
4033
|
{ id: "test", kind: "bayes", prior: "prior", truePositive: "sensitivity", falsePositive: "falsePositive", at: [0.08, 0.2], size: [0.84, 0.66] }
|
|
3299
4034
|
]);
|
|
3300
4035
|
}
|
|
3301
|
-
|
|
3302
|
-
|
|
4036
|
+
const ft = (t) => ({ width: t.width ?? 600, height: t.height ?? 600, ...t.theme ? { theme: t.theme } : {} }), _t = (t, e) => ({
|
|
4037
|
+
id: "readout",
|
|
4038
|
+
kind: "label",
|
|
4039
|
+
screen: !0,
|
|
4040
|
+
align: "left",
|
|
4041
|
+
size: 22,
|
|
4042
|
+
at: [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.07],
|
|
4043
|
+
tex: e
|
|
4044
|
+
}), se = {
|
|
4045
|
+
nodes: [
|
|
4046
|
+
{ id: "A", at: [-3, 1.5] },
|
|
4047
|
+
{ id: "B", at: [-1, 2.5] },
|
|
4048
|
+
{ id: "C", at: [-1, 0.5] },
|
|
4049
|
+
{ id: "D", at: [1, 2.5] },
|
|
4050
|
+
{ id: "E", at: [1, 0.5] },
|
|
4051
|
+
{ id: "F", at: [-1, -1.5] },
|
|
4052
|
+
{ id: "G", at: [3, 1.5] },
|
|
4053
|
+
{ id: "H", at: [1.5, -1.5] }
|
|
4054
|
+
],
|
|
4055
|
+
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]]
|
|
4056
|
+
};
|
|
4057
|
+
function zr(t = {}) {
|
|
4058
|
+
const { width: e, height: n } = ft(t);
|
|
4059
|
+
return {
|
|
4060
|
+
...ft(t),
|
|
4061
|
+
x: [-4.2, 4.2],
|
|
4062
|
+
y: [-3.6, 3.6],
|
|
4063
|
+
values: { step: 0 },
|
|
4064
|
+
items: [
|
|
4065
|
+
{ id: "g", kind: "graph", nodes: t.nodes ?? se.nodes, edges: t.edges ?? se.edges.map(([i, s]) => [i, s]), search: { kind: t.search ?? "bfs", start: t.start ?? "A" }, step: "step", frontier: [e * 0.06, n * 0.92] },
|
|
4066
|
+
_t(t, "\\text{visited } \\val{g.visited:0} \\text{ of } \\val{g.steps:0}")
|
|
4067
|
+
]
|
|
4068
|
+
};
|
|
4069
|
+
}
|
|
4070
|
+
function jr(t = {}) {
|
|
4071
|
+
const { width: e, height: n } = ft(t), i = t.target ?? "G";
|
|
4072
|
+
return {
|
|
4073
|
+
...ft(t),
|
|
4074
|
+
x: [-4.2, 4.2],
|
|
4075
|
+
y: [-3.6, 3.6],
|
|
4076
|
+
values: { step: 0 },
|
|
4077
|
+
items: [
|
|
4078
|
+
{ id: "g", kind: "graph", nodes: t.nodes ?? se.nodes, edges: t.edges ?? se.edges, search: { kind: "dijkstra", start: t.start ?? "A" }, step: "step", frontier: [e * 0.06, n * 0.92] },
|
|
4079
|
+
_t(t, `d(${i}) = \\val{g.d.${i}:0}`)
|
|
4080
|
+
]
|
|
4081
|
+
};
|
|
4082
|
+
}
|
|
4083
|
+
function _r(t = {}) {
|
|
4084
|
+
const e = Math.min(6, Math.max(1, t.n ?? 5)), n = [], i = [], s = (l) => {
|
|
4085
|
+
const c = `c${n.length}`;
|
|
4086
|
+
return n.push({ id: c, label: `F_{${l}}` }), l >= 2 && (i.push([c, s(l - 1)]), i.push([c, s(l - 2)])), c;
|
|
4087
|
+
};
|
|
4088
|
+
s(e);
|
|
4089
|
+
const r = n.filter((l) => !i.some(([c]) => c === l.id)).length, a = Math.max(r * 0.75, 4);
|
|
4090
|
+
return {
|
|
4091
|
+
...ft(t),
|
|
4092
|
+
x: [-a, a],
|
|
4093
|
+
y: [-(e + 0.2) * 1.05, 1.2],
|
|
4094
|
+
values: { step: 0 },
|
|
4095
|
+
items: [
|
|
4096
|
+
{ 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 },
|
|
4097
|
+
_t(t, "\\text{calls made: } \\val{calls.visited:0} \\text{ of } \\val{calls.steps:0}")
|
|
4098
|
+
]
|
|
4099
|
+
};
|
|
4100
|
+
}
|
|
4101
|
+
function Dr(t = {}) {
|
|
4102
|
+
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] }];
|
|
4103
|
+
return t.label !== void 0 && n.push(_t(t, t.label)), { ...ft(t), x: [-4, 4], y: [-4, 4], items: n };
|
|
4104
|
+
}
|
|
4105
|
+
function Rr(t = {}) {
|
|
4106
|
+
const e = t.modulus ?? 12;
|
|
4107
|
+
return {
|
|
4108
|
+
...ft(t),
|
|
4109
|
+
x: [-3, 3],
|
|
4110
|
+
y: [-3, 3],
|
|
4111
|
+
values: { value: t.value ?? 0 },
|
|
4112
|
+
items: [
|
|
4113
|
+
{ id: "clock", kind: "clock", modulus: e, value: "value", radius: 2.2, at: [0, -0.2] },
|
|
4114
|
+
_t(t, `\\val{value:0} \\equiv \\val{clock.hour:0} \\pmod{${e}}`.replace("\\pmod", "\\;(\\text{mod } ").replace(`{${e}}`, `${e})`))
|
|
4115
|
+
]
|
|
4116
|
+
};
|
|
4117
|
+
}
|
|
4118
|
+
const At = (t) => ({ width: t.width ?? 600, height: t.height ?? 600, ...t.theme ? { theme: t.theme } : {} }), Dt = (t, e) => ({
|
|
4119
|
+
id: "readout",
|
|
4120
|
+
kind: "label",
|
|
4121
|
+
screen: !0,
|
|
4122
|
+
align: "left",
|
|
4123
|
+
size: 22,
|
|
4124
|
+
at: [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.07],
|
|
4125
|
+
tex: e
|
|
4126
|
+
});
|
|
4127
|
+
function Br(t = {}) {
|
|
4128
|
+
const e = t.layers ?? [3, 5, 4, 2], n = Array.from({ length: e[0] }, (i, s) => t.inputs?.[s] ?? [0.9, 0.2, 0.6, 0.4, 0.8][s % 5]);
|
|
4129
|
+
return {
|
|
4130
|
+
...At(t),
|
|
4131
|
+
x: [-5, 5],
|
|
4132
|
+
y: [-5, 5],
|
|
4133
|
+
values: { flow: e.length - 1, ...Object.fromEntries(n.map((i, s) => [`in${s}`, i])) },
|
|
4134
|
+
items: [
|
|
4135
|
+
{
|
|
4136
|
+
id: "net",
|
|
4137
|
+
kind: "network",
|
|
4138
|
+
layers: e,
|
|
4139
|
+
activation: t.activation ?? "sigmoid",
|
|
4140
|
+
seed: t.seed ?? "net",
|
|
4141
|
+
flow: "flow",
|
|
4142
|
+
at: [0, -0.3],
|
|
4143
|
+
size: [7, 6.5],
|
|
4144
|
+
inputs: n.map((i, s) => `in${s}`),
|
|
4145
|
+
labels: { inputs: n.map((i, s) => `x_{${s + 1}}`), outputs: Array.from({ length: e[e.length - 1] }, (i, s) => `y_{${s + 1}}`) }
|
|
4146
|
+
},
|
|
4147
|
+
Dt(t, e[e.length - 1] >= 2 ? "y_1 = \\val{net.out0:2} \\quad y_2 = \\val{net.out1:2}" : "y = \\val{net.out0:2}")
|
|
4148
|
+
]
|
|
4149
|
+
};
|
|
4150
|
+
}
|
|
4151
|
+
function Vr(t = {}) {
|
|
4152
|
+
const e = t.expr ?? "(x^2 + 8 y^2) / 4";
|
|
4153
|
+
return {
|
|
4154
|
+
...At(t),
|
|
4155
|
+
x: [-4, 4],
|
|
4156
|
+
y: [-4, 4],
|
|
4157
|
+
values: { steps: 0, rate: t.rate ?? 0.2, momentum: t.momentum ?? 0, sx: t.start?.[0] ?? -3.5, sy: t.start?.[1] ?? 2 },
|
|
4158
|
+
items: [
|
|
4159
|
+
{ id: "field", kind: "heatmap", expr: e, resolution: 40, colormap: "viridis", opacity: 0.35 },
|
|
4160
|
+
{ id: "levels", kind: "contours", expr: e, levels: 9, colormap: "viridis" },
|
|
4161
|
+
{ id: "gd", kind: "descent", expr: e, start: [t.start?.[0] ?? -3.5, t.start?.[1] ?? 2], rate: "rate", steps: "steps", momentum: "momentum" },
|
|
4162
|
+
Dt(t, "\\text{step } \\val{gd.step:0} \\quad f = \\val{gd.loss:3}")
|
|
4163
|
+
]
|
|
4164
|
+
};
|
|
4165
|
+
}
|
|
4166
|
+
function Hr(t = {}) {
|
|
4167
|
+
const e = t.tokens ?? ["The", "cat", "sat", "on", "the", "mat"], n = $t(yt(t.seed ?? "attention")), i = t.scores ?? e.map((r, a) => e.map((l, c) => (a === c ? 2.2 : 0) + (c === a - 1 ? 1.4 : 0) + pt(n) * 0.8)), s = e.map((r) => `\\text{${r}}`);
|
|
4168
|
+
return {
|
|
4169
|
+
...At(t),
|
|
4170
|
+
x: [-5, 5],
|
|
4171
|
+
y: [-5, 5],
|
|
4172
|
+
items: [
|
|
4173
|
+
{ id: "attn", kind: "heatmap", cells: i, softmax: !0, range: [0, 1], colormap: "heat", at: [-3, -4], size: [7, 7], rowLabels: s, colLabels: s, values: !0 }
|
|
4174
|
+
]
|
|
4175
|
+
};
|
|
4176
|
+
}
|
|
4177
|
+
function Ur(t = {}) {
|
|
4178
|
+
return {
|
|
4179
|
+
...At(t),
|
|
4180
|
+
x: [-4, 4],
|
|
4181
|
+
y: [-4, 4],
|
|
4182
|
+
values: { epochs: 0 },
|
|
4183
|
+
items: [
|
|
4184
|
+
{ id: "clf", kind: "classifier", epochs: "epochs", centres: [[-1.1, -0.7], [1.1, 0.9]], rate: t.rate ?? 0.3, spread: t.spread ?? 1.15 },
|
|
4185
|
+
Dt(t, "\\text{epoch } \\val{clf.epoch:0} \\quad \\text{accuracy } \\val{clf.accuracy:2} \\quad \\text{loss } \\val{clf.loss:3}")
|
|
4186
|
+
]
|
|
4187
|
+
};
|
|
4188
|
+
}
|
|
4189
|
+
function Wr(t = {}) {
|
|
4190
|
+
return {
|
|
4191
|
+
...At(t),
|
|
4192
|
+
x: [-4.5, 4.5],
|
|
4193
|
+
y: [-4.5, 4.5],
|
|
4194
|
+
values: { iteration: 0 },
|
|
4195
|
+
items: [
|
|
4196
|
+
{ id: "km", kind: "kmeans", centres: t.centres ?? [[-2.2, 1.6], [2, 2], [0.4, -2.2]], k: t.k, iteration: "iteration", spread: 0.75 },
|
|
4197
|
+
Dt(t, "\\text{iteration } \\val{km.iteration:0} \\quad \\text{inertia } \\val{km.inertia:1}")
|
|
4198
|
+
]
|
|
4199
|
+
};
|
|
4200
|
+
}
|
|
4201
|
+
function Gr(t = {}) {
|
|
4202
|
+
return {
|
|
4203
|
+
...At(t),
|
|
4204
|
+
x: [-4, 4],
|
|
4205
|
+
y: [-2, 3],
|
|
4206
|
+
items: [
|
|
4207
|
+
{ id: "axes", kind: "axes" },
|
|
4208
|
+
{ id: "sigmoid", kind: "function", expr: "sigmoid(x)", color: "blue" },
|
|
4209
|
+
{ id: "tanh", kind: "function", expr: "tanh(x)", color: "yellow" },
|
|
4210
|
+
{ id: "relu", kind: "function", expr: "relu(x)", color: "red" },
|
|
4211
|
+
Dt(t, "\\color{blue}{\\sigma(x)} \\quad \\color{yellow}{\\tanh x} \\quad \\color{red}{\\text{ReLU}(x)}")
|
|
4212
|
+
]
|
|
4213
|
+
};
|
|
4214
|
+
}
|
|
4215
|
+
function Xr(t) {
|
|
4216
|
+
return zt(t);
|
|
3303
4217
|
}
|
|
3304
|
-
function
|
|
3305
|
-
return
|
|
4218
|
+
function Yr(t, e = {}, n = {}) {
|
|
4219
|
+
return _s(de(zt(t), e), n);
|
|
3306
4220
|
}
|
|
3307
4221
|
export {
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
Qt as
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
4222
|
+
Qe as ACTIVATIONS,
|
|
4223
|
+
Ht as COLORMAPS,
|
|
4224
|
+
Kt as CONSTANTS,
|
|
4225
|
+
Qt as DISTRIBUTION_KINDS,
|
|
4226
|
+
bt as ExpressionError,
|
|
4227
|
+
ve as FUNCTIONS,
|
|
4228
|
+
nn as ITEM_KINDS,
|
|
4229
|
+
li as MATH_FONT,
|
|
4230
|
+
ui as MATH_SYMBOL_FONT,
|
|
4231
|
+
Te as MATH_THEMES,
|
|
4232
|
+
_e as MATRIX_TEX,
|
|
4233
|
+
se as SAMPLE_GRAPH,
|
|
4234
|
+
Ke as SEARCH_KINDS,
|
|
4235
|
+
$e as SYMBOLS,
|
|
4236
|
+
pi as TEX_COMMANDS,
|
|
4237
|
+
hi as TexError,
|
|
4238
|
+
ts as accuracy,
|
|
4239
|
+
Hi as activate,
|
|
4240
|
+
Gr as activationFigure,
|
|
4241
|
+
Ee as adjacency,
|
|
4242
|
+
Er as areaFigure,
|
|
4243
|
+
ze as assign,
|
|
4244
|
+
Hr as attentionFigure,
|
|
4245
|
+
ci as ballAt,
|
|
4246
|
+
Ge as ballPath,
|
|
4247
|
+
ai as bayesAreas,
|
|
4248
|
+
qr as bayesFigure,
|
|
4249
|
+
fe as binOf,
|
|
4250
|
+
ri as binSamples,
|
|
4251
|
+
Pr as binomialFigure,
|
|
4252
|
+
Nn as blendOver,
|
|
4253
|
+
Pn as blobs,
|
|
4254
|
+
Rr as clockFigure,
|
|
4255
|
+
Ir as cltFigure,
|
|
4256
|
+
Ce as colorAt,
|
|
4257
|
+
Y as compile,
|
|
4258
|
+
Pe as compileDerivative,
|
|
4259
|
+
Xi as contourLines,
|
|
4260
|
+
Ur as decisionBoundaryFigure,
|
|
4261
|
+
We as defaultBins,
|
|
4262
|
+
ut as density,
|
|
4263
|
+
Ji as descentPath,
|
|
4264
|
+
wr as determinantFigure,
|
|
4265
|
+
X as differentiate,
|
|
4266
|
+
_s as displayListToSvg,
|
|
4267
|
+
je as displayListToSvgContent,
|
|
4268
|
+
yn as distributionProblem,
|
|
4269
|
+
js as drawDisplayList,
|
|
4270
|
+
kr as eigenFigure,
|
|
4271
|
+
et as evaluate,
|
|
4272
|
+
Ue as expressionNames,
|
|
4273
|
+
Rt as expressionToString,
|
|
4274
|
+
Wi as forward,
|
|
4275
|
+
Fr as galtonFigure,
|
|
4276
|
+
Vr as gradientDescentFigure,
|
|
4277
|
+
zr as graphSearchFigure,
|
|
4278
|
+
Jt as inRegion,
|
|
4279
|
+
is as inertia,
|
|
4280
|
+
me as integrate,
|
|
4281
|
+
re as isDiscrete,
|
|
4282
|
+
Wr as kmeansFigure,
|
|
4283
|
+
ns as kmeansHistory,
|
|
4284
|
+
de as layoutFigure,
|
|
4285
|
+
H as layoutTex,
|
|
4286
|
+
gn as leastSquares,
|
|
4287
|
+
Or as limitFigure,
|
|
4288
|
+
vr as linearMapFigure,
|
|
4289
|
+
es as logLoss,
|
|
4290
|
+
fr as mat2,
|
|
4291
|
+
br as mathExplorable,
|
|
4292
|
+
Xr as mathFigure,
|
|
4293
|
+
Ds as mathFigureProps,
|
|
4294
|
+
Yr as mathFigureToSvg,
|
|
4295
|
+
mr as mathSteps,
|
|
4296
|
+
yr as mathTarget,
|
|
4297
|
+
Ct as meanOf,
|
|
4298
|
+
Lr as monteCarloPiFigure,
|
|
4299
|
+
vs as morphEquation,
|
|
4300
|
+
gr as mountAllMath,
|
|
4301
|
+
lr as mountMath,
|
|
4302
|
+
Br as neuralNetworkFigure,
|
|
4303
|
+
Nr as normalFigure,
|
|
4304
|
+
ii as nthDerivative,
|
|
4305
|
+
ot as parseExpression,
|
|
4306
|
+
Sn as parseSetExpression,
|
|
4307
|
+
fi as parseTex,
|
|
4308
|
+
Dn as planeOf,
|
|
4309
|
+
ce as predict,
|
|
4310
|
+
_r as recursionTreeFigure,
|
|
4311
|
+
ji as regionCells,
|
|
4312
|
+
Cr as regressionFigure,
|
|
4313
|
+
Ar as riemannFigure,
|
|
4314
|
+
pn as sample,
|
|
4315
|
+
Zi as sampleGrid,
|
|
4316
|
+
fn as samples,
|
|
4317
|
+
mn as scatterPoints,
|
|
4318
|
+
qt as sdOf,
|
|
4319
|
+
Ci as searchEvents,
|
|
4320
|
+
Sr as secantFigure,
|
|
4321
|
+
Ui as seededNetwork,
|
|
4322
|
+
Zt as setNames,
|
|
4323
|
+
jr as shortestPathFigure,
|
|
4324
|
+
Mr as spanFigure,
|
|
4325
|
+
oi as summary,
|
|
4326
|
+
si as supportOf,
|
|
4327
|
+
qe as surface,
|
|
4328
|
+
xr as tangentFigure,
|
|
4329
|
+
Tr as taylorFigure,
|
|
4330
|
+
G as texToShapes,
|
|
4331
|
+
Qi as trainLogistic,
|
|
4332
|
+
qi as treeLayout,
|
|
4333
|
+
_ as trimPolylines,
|
|
4334
|
+
zt as validateMathFigure,
|
|
4335
|
+
pr as vec2,
|
|
4336
|
+
$r as vectorSumFigure,
|
|
4337
|
+
Dr as vennFigure
|
|
3384
4338
|
};
|