@algorisys/tinyfly 0.120.0 → 0.122.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -6
- package/docs/character-appearance.md +62 -1
- 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 +8 -1
- package/docs/maps.md +2 -2
- package/docs/math.md +26 -4
- package/docs/teaching.md +1 -1
- package/lib/addons/characters.js +1397 -1342
- package/lib/addons/cricket-play-BRehNToP.js +5506 -0
- package/lib/addons/math.js +1349 -1275
- package/lib/addons/sports.js +1 -1
- package/lib/browser/tinyfly-math.iife.js +4 -4
- package/lib/browser/tinyfly.iife.js +12 -12
- package/lib/browser/tinyfly.js +6500 -6171
- package/lib/browser/tinyfly.umd.js +12 -12
- package/lib/types/characters/body/bean-figure.d.ts +154 -0
- package/lib/types/characters/cast.d.ts +204 -2
- package/lib/types/characters/character.d.ts +21 -5
- package/lib/types/characters/head/face.d.ts +22 -2
- package/lib/types/characters/index.d.ts +2 -1
- package/lib/types/math/index.d.ts +1 -0
- package/lib/types/math/ml/loss-surface.d.ts +118 -0
- package/llms-full.txt +110 -17
- package/llms.txt +31 -31
- package/package.json +1 -1
- package/skills/tinyfly/SKILL.md +7 -1
- package/lib/addons/cricket-play-C5CkNOc6.js +0 -5219
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 yt, createRandom as xt, hashSeed as gt, closestName as ei, unknownName as R, deserializeTimeline as Ze, playheadCrossings as ni } from "@algorisys/tinyfly";
|
|
2
|
+
import { D as Je } from "./dom-adapter-Cphr2HZn.js";
|
|
3
|
+
const ii = (t, e) => [t[0] + e[0], t[1] + e[1]], Re = (t, e) => [t[0] - e[0], t[1] - e[1]], Oe = (t, e) => [t[0] * e, t[1] * e], si = (t, e) => t[0] * e[0] + t[1] * e[1], ri = (t, e) => t[0] * e[1] - t[1] * e[0], gn = (t) => Math.hypot(t[0], t[1]);
|
|
4
|
+
function Lt(t) {
|
|
5
|
+
const e = gn(t);
|
|
6
6
|
return e === 0 ? [0, 0] : [t[0] / e, t[1] / e];
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
function
|
|
8
|
+
const qt = (t, e, n) => [t[0] + (e[0] - t[0]) * n, t[1] + (e[1] - t[1]) * n];
|
|
9
|
+
function ot(t) {
|
|
10
10
|
return Array.isArray(t) && t.length === 2 && t.every(Number.isFinite);
|
|
11
11
|
}
|
|
12
|
-
const
|
|
12
|
+
const xr = /* @__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
|
|
14
|
+
add: ii,
|
|
15
|
+
cross: ri,
|
|
16
|
+
dot: si,
|
|
17
|
+
isVec2: ot,
|
|
18
|
+
length: gn,
|
|
19
|
+
lerp: qt,
|
|
20
|
+
normalize: Lt,
|
|
21
|
+
scale: Oe,
|
|
22
|
+
sub: Re
|
|
23
|
+
}, Symbol.toStringTag, { value: "Module" })), zt = [1, 0, 0, 1], nt = ([t, e, n, i], [s, r]) => [t * s + e * r, n * s + i * r];
|
|
24
|
+
function oi(t, e) {
|
|
25
25
|
const [n, i, s, r] = t, [o, c, l, d] = e;
|
|
26
26
|
return [n * o + i * l, n * c + i * d, s * o + r * l, s * c + r * d];
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
function
|
|
30
|
-
const e =
|
|
28
|
+
const jt = ([t, e, n, i]) => t * i - e * n;
|
|
29
|
+
function ai(t) {
|
|
30
|
+
const e = jt(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, o =
|
|
35
|
+
const ci = (t, e, n) => t.map((i, s) => i + (e[s] - i) * n), li = (t) => [Math.cos(t), -Math.sin(t), Math.sin(t), Math.cos(t)];
|
|
36
|
+
function bn(t) {
|
|
37
|
+
const [e, n, i, s] = t, r = e + s, o = jt(t), c = r * r - 4 * o, l = 1e-9;
|
|
38
38
|
if (c < -l) return [];
|
|
39
|
-
const d = Math.sqrt(Math.max(0, c)), u = d < l ? [r / 2] : [(r + d) / 2, (r - d) / 2],
|
|
39
|
+
const d = Math.sqrt(Math.max(0, c)), u = d < l ? [r / 2] : [(r + d) / 2, (r - d) / 2], f = [];
|
|
40
40
|
for (const h of u) {
|
|
41
|
-
const
|
|
42
|
-
if (Math.hypot(...
|
|
43
|
-
|
|
41
|
+
const p = [[e - h, n], [i, s - h]].reduce((b, x) => Math.hypot(...x) > Math.hypot(...b) ? x : b);
|
|
42
|
+
if (Math.hypot(...p) < l) {
|
|
43
|
+
f.push({ value: h, vector: [1, 0] }, { value: h, vector: [0, 1] });
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
|
-
const y = [-
|
|
47
|
-
|
|
46
|
+
const y = [-p[1], p[0]], a = Math.hypot(...y), m = y[0] < -l || Math.abs(y[0]) <= l && y[1] < 0 ? -1 : 1;
|
|
47
|
+
f.push({ value: h, vector: [m * y[0] / a + 0, m * y[1] / a + 0] });
|
|
48
48
|
}
|
|
49
|
-
return
|
|
49
|
+
return f;
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function $t(t) {
|
|
52
52
|
return Array.isArray(t) && t.length === 4 && t.every(Number.isFinite);
|
|
53
53
|
}
|
|
54
|
-
const
|
|
54
|
+
const Sr = /* @__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: zt,
|
|
57
|
+
apply: nt,
|
|
58
|
+
determinant: jt,
|
|
59
|
+
eigen: bn,
|
|
60
|
+
inverse: ai,
|
|
61
|
+
isMat2: $t,
|
|
62
|
+
lerp: ci,
|
|
63
|
+
multiply: oi,
|
|
64
|
+
rotation: li
|
|
65
|
+
}, Symbol.toStringTag, { value: "Module" })), Ne = {
|
|
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 wr = /* @__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
|
+
}, oe = { pi: Math.PI, e: Math.E, tau: Math.PI * 2 };
|
|
92
|
+
class wt extends Error {
|
|
93
93
|
source;
|
|
94
94
|
/** 0-based index into the source */
|
|
95
95
|
position;
|
|
@@ -97,7 +97,7 @@ class bt 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 ui(t) {
|
|
101
101
|
const e = [];
|
|
102
102
|
let n = 0;
|
|
103
103
|
for (; n < t.length; ) {
|
|
@@ -120,19 +120,19 @@ function si(t) {
|
|
|
120
120
|
e.push({ kind: "op", value: i, at: n }), n++;
|
|
121
121
|
continue;
|
|
122
122
|
}
|
|
123
|
-
throw new
|
|
123
|
+
throw new wt(`Unexpected "${i}"`, t, n);
|
|
124
124
|
}
|
|
125
125
|
return e.push({ kind: "end", at: t.length }), e;
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function ct(t) {
|
|
128
128
|
if (typeof t != "string") throw new TypeError("parseExpression: expected a string");
|
|
129
|
-
const e =
|
|
129
|
+
const e = ui(t);
|
|
130
130
|
let n = 0;
|
|
131
131
|
const i = () => e[n], s = (h) => {
|
|
132
132
|
const g = i();
|
|
133
133
|
return g.kind === "op" && g.value === h;
|
|
134
134
|
}, r = (h) => {
|
|
135
|
-
if (!s(h)) throw new
|
|
135
|
+
if (!s(h)) throw new wt(`Expected "${h}"`, t, i().at);
|
|
136
136
|
n++;
|
|
137
137
|
}, o = () => {
|
|
138
138
|
let h = c();
|
|
@@ -157,141 +157,141 @@ function ot(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 g = Object.prototype.hasOwnProperty.call(
|
|
161
|
-
if (!g) throw new
|
|
160
|
+
const g = Object.prototype.hasOwnProperty.call(Ne, h.value) ? Ne[h.value] : void 0;
|
|
161
|
+
if (!g) throw new wt(`Unknown function "${h.value}"`, t, h.at);
|
|
162
162
|
n++;
|
|
163
|
-
const
|
|
163
|
+
const p = [];
|
|
164
164
|
if (!s(")"))
|
|
165
|
-
for (
|
|
166
|
-
n++,
|
|
167
|
-
if (r(")"),
|
|
168
|
-
throw new
|
|
169
|
-
return { type: "call", name: h.value, args:
|
|
165
|
+
for (p.push(o()); s(","); )
|
|
166
|
+
n++, p.push(o());
|
|
167
|
+
if (r(")"), p.length !== g.arity)
|
|
168
|
+
throw new wt(`"${h.value}" takes ${g.arity} argument${g.arity === 1 ? "" : "s"}, got ${p.length}`, t, h.at);
|
|
169
|
+
return { type: "call", name: h.value, args: p };
|
|
170
170
|
}
|
|
171
171
|
if (s("(")) {
|
|
172
172
|
n++;
|
|
173
173
|
const g = o();
|
|
174
174
|
return r(")"), g;
|
|
175
175
|
}
|
|
176
|
-
throw new
|
|
177
|
-
},
|
|
178
|
-
if (i().kind !== "end") throw new
|
|
179
|
-
return
|
|
176
|
+
throw new wt(h.kind === "end" ? "Unexpected end" : `Unexpected "${h.value}"`, t, h.at);
|
|
177
|
+
}, f = o();
|
|
178
|
+
if (i().kind !== "end") throw new wt(`Unexpected "${i().value}"`, t, i().at);
|
|
179
|
+
return f;
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function Ke(t) {
|
|
182
182
|
const e = /* @__PURE__ */ new Set(), n = (i) => {
|
|
183
|
-
i.type === "name" && !(i.name in
|
|
183
|
+
i.type === "name" && !(i.name in oe) ? 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 H(t) && H(e) ?
|
|
187
|
+
const j = (t) => ({ type: "number", value: t }), Ft = j(0), _ = j(1), H = (t) => t.type === "number", K = (t, e) => t.type === "number" && t.value === e;
|
|
188
|
+
function dt(t, e) {
|
|
189
|
+
return H(t) && H(e) ? j(t.value + e.value) : K(t, 0) ? e : K(e, 0) ? t : { type: "binary", operator: "+", left: t, right: e };
|
|
190
190
|
}
|
|
191
|
-
function
|
|
192
|
-
return H(t) && H(e) ?
|
|
191
|
+
function rt(t, e) {
|
|
192
|
+
return H(t) && H(e) ? j(t.value - e.value) : K(e, 0) ? t : K(t, 0) ? ee(e) : { type: "binary", operator: "-", left: t, right: e };
|
|
193
193
|
}
|
|
194
|
-
function
|
|
195
|
-
return H(t) && H(e) ?
|
|
194
|
+
function D(t, e) {
|
|
195
|
+
return H(t) && H(e) ? j(t.value * e.value) : K(t, 0) || K(e, 0) ? Ft : K(t, 1) ? e : K(e, 1) ? t : H(e) ? D(e, t) : H(t) && e.type === "binary" && e.operator === "*" && H(e.left) ? D(j(t.value * e.left.value), e.right) : { type: "binary", operator: "*", left: t, right: e };
|
|
196
196
|
}
|
|
197
197
|
function W(t, e) {
|
|
198
|
-
return
|
|
198
|
+
return K(t, 0) ? Ft : K(e, 1) ? t : H(t) && H(e) && e.value !== 0 ? j(t.value / e.value) : { type: "binary", operator: "/", left: t, right: e };
|
|
199
199
|
}
|
|
200
|
-
function
|
|
201
|
-
return
|
|
200
|
+
function ut(t, e) {
|
|
201
|
+
return K(e, 0) ? _ : K(e, 1) ? t : H(t) && H(e) ? j(t.value ** e.value) : { type: "binary", operator: "^", left: t, right: e };
|
|
202
202
|
}
|
|
203
|
-
function
|
|
204
|
-
return H(t) ?
|
|
203
|
+
function ee(t) {
|
|
204
|
+
return H(t) ? j(-t.value) : t.type === "unary" && t.operator === "-" ? t.operand : { type: "unary", operator: "-", operand: t };
|
|
205
205
|
}
|
|
206
206
|
const G = (t, ...e) => ({ type: "call", name: t, args: e });
|
|
207
|
-
function
|
|
207
|
+
function ft(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 ft(t.operand, e);
|
|
215
215
|
case "binary":
|
|
216
|
-
return
|
|
216
|
+
return ft(t.left, e) && ft(t.right, e);
|
|
217
217
|
case "call":
|
|
218
|
-
return t.args.every((n) =>
|
|
218
|
+
return t.args.every((n) => ft(n, e));
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
function
|
|
222
|
-
if (
|
|
221
|
+
function Z(t, e = "x") {
|
|
222
|
+
if (ft(t, e)) return Ft;
|
|
223
223
|
switch (t.type) {
|
|
224
224
|
case "number":
|
|
225
|
-
return
|
|
225
|
+
return Ft;
|
|
226
226
|
case "name":
|
|
227
|
-
return t.name === e ?
|
|
227
|
+
return t.name === e ? _ : Ft;
|
|
228
228
|
case "unary":
|
|
229
|
-
return t.operator === "-" ?
|
|
229
|
+
return t.operator === "-" ? ee(Z(t.operand, e)) : Z(t.operand, e);
|
|
230
230
|
case "binary": {
|
|
231
|
-
const { left: n, right: i } = t, s = () =>
|
|
231
|
+
const { left: n, right: i } = t, s = () => Z(n, e), r = () => Z(i, e);
|
|
232
232
|
switch (t.operator) {
|
|
233
233
|
case "+":
|
|
234
|
-
return
|
|
234
|
+
return dt(s(), r());
|
|
235
235
|
case "-":
|
|
236
|
-
return
|
|
236
|
+
return rt(s(), r());
|
|
237
237
|
case "*":
|
|
238
|
-
return
|
|
238
|
+
return dt(D(s(), i), D(n, r()));
|
|
239
239
|
case "/":
|
|
240
|
-
return W(
|
|
240
|
+
return W(rt(D(s(), i), D(n, r())), ut(i, j(2)));
|
|
241
241
|
case "^":
|
|
242
|
-
if (
|
|
243
|
-
const o = H(i) ?
|
|
244
|
-
return
|
|
242
|
+
if (ft(i, e)) {
|
|
243
|
+
const o = H(i) ? j(i.value - 1) : rt(i, _);
|
|
244
|
+
return D(D(i, ut(n, o)), s());
|
|
245
245
|
}
|
|
246
|
-
return
|
|
246
|
+
return ft(n, e) ? D(D(t, G("ln", n)), r()) : D(t, dt(D(r(), G("ln", n)), W(D(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 = () => Z(n, e), r = (o) => D(o, s());
|
|
252
252
|
switch (t.name) {
|
|
253
253
|
case "sin":
|
|
254
254
|
return r(G("cos", n));
|
|
255
255
|
case "cos":
|
|
256
|
-
return r(
|
|
256
|
+
return r(ee(G("sin", n)));
|
|
257
257
|
case "tan":
|
|
258
|
-
return r(W(
|
|
258
|
+
return r(W(_, ut(G("cos", n), j(2))));
|
|
259
259
|
case "asin":
|
|
260
|
-
return r(W(
|
|
260
|
+
return r(W(_, G("sqrt", rt(_, ut(n, j(2))))));
|
|
261
261
|
case "acos":
|
|
262
|
-
return r(
|
|
262
|
+
return r(ee(W(_, G("sqrt", rt(_, ut(n, j(2)))))));
|
|
263
263
|
case "atan":
|
|
264
|
-
return r(W(
|
|
264
|
+
return r(W(_, dt(_, ut(n, j(2)))));
|
|
265
265
|
case "sinh":
|
|
266
266
|
return r(G("cosh", n));
|
|
267
267
|
case "cosh":
|
|
268
268
|
return r(G("sinh", n));
|
|
269
269
|
case "tanh":
|
|
270
|
-
return r(
|
|
270
|
+
return r(rt(_, ut(G("tanh", n), j(2))));
|
|
271
271
|
case "exp":
|
|
272
272
|
return r(t);
|
|
273
273
|
case "ln":
|
|
274
|
-
return r(W(
|
|
274
|
+
return r(W(_, n));
|
|
275
275
|
case "log":
|
|
276
|
-
return r(W(
|
|
276
|
+
return r(W(_, D(n, j(Math.LN10))));
|
|
277
277
|
case "log2":
|
|
278
|
-
return r(W(
|
|
278
|
+
return r(W(_, D(n, j(Math.LN2))));
|
|
279
279
|
case "sqrt":
|
|
280
|
-
return r(W(
|
|
280
|
+
return r(W(_, D(j(2), t)));
|
|
281
281
|
case "abs":
|
|
282
282
|
return r(G("sign", n));
|
|
283
283
|
case "sigmoid":
|
|
284
|
-
return r(
|
|
284
|
+
return r(D(t, rt(_, t)));
|
|
285
285
|
case "relu":
|
|
286
|
-
return r(W(
|
|
286
|
+
return r(W(dt(G("sign", n), _), j(2)));
|
|
287
287
|
case "atan2": {
|
|
288
|
-
const o =
|
|
289
|
-
return W(
|
|
288
|
+
const o = Z(i, e);
|
|
289
|
+
return W(rt(D(i, s()), D(n, o)), dt(ut(n, j(2)), ut(i, j(2))));
|
|
290
290
|
}
|
|
291
291
|
case "min":
|
|
292
292
|
case "max": {
|
|
293
|
-
const o = t.name === "max" ? 1 : -1, c =
|
|
294
|
-
return
|
|
293
|
+
const o = t.name === "max" ? 1 : -1, c = Z(i, e), l = W(dt(_, D(j(o), G("sign", rt(n, i)))), j(2));
|
|
294
|
+
return dt(D(l, s()), D(rt(_, l), c));
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
throw new Error(`differentiate: "${t.name}" has no derivative rule`);
|
|
@@ -299,40 +299,40 @@ function Y(t, e = "x") {
|
|
|
299
299
|
}
|
|
300
300
|
throw new Error("differentiate: malformed expression");
|
|
301
301
|
}
|
|
302
|
-
function
|
|
302
|
+
function di(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 = Z(i, n);
|
|
305
305
|
return i;
|
|
306
306
|
}
|
|
307
|
-
function
|
|
307
|
+
function Yt(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}${Yt(t.operand)})`;
|
|
315
315
|
case "binary":
|
|
316
|
-
return `(${
|
|
316
|
+
return `(${Yt(t.left)} ${t.operator} ${Yt(t.right)})`;
|
|
317
317
|
case "call":
|
|
318
|
-
return `${t.name}(${t.args.map(
|
|
318
|
+
return `${t.name}(${t.args.map(Yt).join(", ")})`;
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
-
function
|
|
321
|
+
function it(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(oe, t.name)) return oe[t.name];
|
|
328
328
|
throw new Error(`evaluate: unknown name "${t.name}"`);
|
|
329
329
|
}
|
|
330
330
|
case "unary": {
|
|
331
|
-
const n =
|
|
331
|
+
const n = it(t.operand, e);
|
|
332
332
|
return t.operator === "-" ? -n : n;
|
|
333
333
|
}
|
|
334
334
|
case "binary": {
|
|
335
|
-
const n =
|
|
335
|
+
const n = it(t.left, e), i = it(t.right, e);
|
|
336
336
|
switch (t.operator) {
|
|
337
337
|
case "+":
|
|
338
338
|
return n + i;
|
|
@@ -348,63 +348,63 @@ function nt(t, e = {}) {
|
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
350
|
case "call":
|
|
351
|
-
return
|
|
351
|
+
return Ne[t.name].apply(...t.args.map((n) => it(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 ne = /* @__PURE__ */ new Map();
|
|
356
|
+
function J(t, e = "x") {
|
|
357
|
+
let n = ne.get(t);
|
|
358
|
+
n || (n = ct(t), ne.size < 256 && ne.set(t, n));
|
|
359
359
|
const i = n;
|
|
360
|
-
return (s, r = {}) =>
|
|
360
|
+
return (s, r = {}) => it(i, { ...r, [e]: s });
|
|
361
361
|
}
|
|
362
|
-
const
|
|
363
|
-
function
|
|
362
|
+
const ke = /* @__PURE__ */ new Map();
|
|
363
|
+
function Be(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 = ke.get(i);
|
|
367
367
|
if (!s) {
|
|
368
|
-
let o =
|
|
369
|
-
o || (o =
|
|
368
|
+
let o = ne.get(t);
|
|
369
|
+
o || (o = ct(t)), s = di(o, e, n), ke.size < 512 && ke.set(i, s);
|
|
370
370
|
}
|
|
371
371
|
const r = s;
|
|
372
|
-
return (o, c = {}) =>
|
|
372
|
+
return (o, c = {}) => it(r, { ...c, [n]: o });
|
|
373
373
|
}
|
|
374
|
-
function
|
|
374
|
+
function vn(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 (
|
|
379
|
+
else if ($t(i)) {
|
|
380
380
|
const [s, r, o, c] = i;
|
|
381
|
-
Object.assign(e, { [`${n}.a`]: s, [`${n}.b`]: r, [`${n}.c`]: o, [`${n}.d`]: c, [`${n}.det`]:
|
|
382
|
-
} else
|
|
381
|
+
Object.assign(e, { [`${n}.a`]: s, [`${n}.b`]: r, [`${n}.c`]: o, [`${n}.d`]: c, [`${n}.det`]: jt(i) });
|
|
382
|
+
} else ot(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 F(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 kt(t, e) {
|
|
389
389
|
if (typeof e != "string") return e;
|
|
390
390
|
const n = t[e];
|
|
391
|
-
if (!
|
|
391
|
+
if (!ot(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 bt(t, e) {
|
|
395
|
+
if (e === void 0) return zt;
|
|
396
396
|
const n = t[e];
|
|
397
|
-
if (
|
|
397
|
+
if (!$t(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 P(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 Mt(t, e) {
|
|
407
|
+
const n = (s) => s === void 0 ? void 0 : P(t, s), i = (s) => s === void 0 ? void 0 : Math.round(P(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 $t(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: Mt(t, e.of), count: i(e.count) };
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
|
-
const
|
|
426
|
-
function
|
|
425
|
+
const ae = ["normal", "uniform", "exponential", "binomial", "poisson", "dice", "mean"];
|
|
426
|
+
function hi(t) {
|
|
427
427
|
switch (t.kind) {
|
|
428
428
|
case "binomial":
|
|
429
429
|
return [0, t.n];
|
|
@@ -435,17 +435,17 @@ function oi(t) {
|
|
|
435
435
|
return [-1 / 0, 1 / 0];
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
|
-
function
|
|
438
|
+
function fe(t) {
|
|
439
439
|
return t.kind === "binomial" || t.kind === "poisson" || t.kind === "dice";
|
|
440
440
|
}
|
|
441
|
-
const
|
|
441
|
+
const ie = /* @__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
|
+
})(), Me = (t, e) => Math.exp(ie(t) - ie(e) - ie(t - e));
|
|
448
|
+
function ht(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 ut(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 : Me(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 - ie(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) * Me(n, r) * Me(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 ? ht(t.of, e) : ht({ kind: "normal", mean: Dt(t.of), sd: _t(t.of) / Math.sqrt(t.count) }, e);
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
|
-
function
|
|
478
|
+
function Dt(t) {
|
|
479
479
|
switch (t.kind) {
|
|
480
480
|
case "normal":
|
|
481
481
|
return t.mean ?? 0;
|
|
@@ -490,10 +490,10 @@ function zt(t) {
|
|
|
490
490
|
case "dice":
|
|
491
491
|
return (t.count ?? 2) * ((t.sides ?? 6) + 1) / 2;
|
|
492
492
|
case "mean":
|
|
493
|
-
return
|
|
493
|
+
return Dt(t.of);
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
|
-
function
|
|
496
|
+
function _t(t) {
|
|
497
497
|
switch (t.kind) {
|
|
498
498
|
case "normal":
|
|
499
499
|
return t.sd ?? 1;
|
|
@@ -508,13 +508,13 @@ function jt(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 _t(t.of) / Math.sqrt(t.count);
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
|
-
function
|
|
514
|
+
function wn(t, e) {
|
|
515
515
|
switch (t.kind) {
|
|
516
516
|
case "normal":
|
|
517
|
-
return
|
|
517
|
+
return yt(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 yn(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 += wn(t.of, e);
|
|
542
542
|
return n / t.count;
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
}
|
|
546
|
-
const
|
|
547
|
-
function
|
|
546
|
+
const Zt = /* @__PURE__ */ new Map();
|
|
547
|
+
function $n(t, e, n) {
|
|
548
548
|
const i = `${JSON.stringify(t)}|${e}`;
|
|
549
|
-
let s =
|
|
550
|
-
if (s || (s = [],
|
|
551
|
-
const r =
|
|
552
|
-
for (let c = 0; c < n; c++) o.push(
|
|
549
|
+
let s = Zt.get(i);
|
|
550
|
+
if (s || (s = [], Zt.size > 64 && Zt.clear(), Zt.set(i, s)), s.length < n) {
|
|
551
|
+
const r = xt(typeof e == "number" ? e : gt(e)), o = [];
|
|
552
|
+
for (let c = 0; c < n; c++) o.push(wn(t, r));
|
|
553
553
|
s.splice(0, s.length, ...o);
|
|
554
554
|
}
|
|
555
555
|
return s.slice(0, n);
|
|
556
556
|
}
|
|
557
|
-
function
|
|
558
|
-
if (!t || typeof t != "object" || !
|
|
557
|
+
function kn(t) {
|
|
558
|
+
if (!t || typeof t != "object" || !ae.includes(t.kind)) return `kind must be one of ${ae.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,18 +571,18 @@ function gn(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 ? kn(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] =
|
|
577
|
+
function Qe(t) {
|
|
578
|
+
const e = Dt(t), n = _t(t);
|
|
579
|
+
if (fe(t)) {
|
|
580
|
+
const [i, s] = hi(t), r = Math.max(i, Math.floor(e - 4 * n)), o = Math.min(s, Math.ceil(e + 4 * n));
|
|
581
581
|
return [r - 0.5, o + 0.5, o - r + 1];
|
|
582
582
|
}
|
|
583
583
|
return [e - 4 * n, e + 4 * n, 30];
|
|
584
584
|
}
|
|
585
|
-
function
|
|
585
|
+
function fi(t, [e, n, i], s) {
|
|
586
586
|
const r = (n - e) / i, o = new Array(i).fill(0);
|
|
587
587
|
for (const l of t) {
|
|
588
588
|
const d = Math.floor((l - e) / r);
|
|
@@ -596,13 +596,13 @@ function ai(t, [e, n, i], s) {
|
|
|
596
596
|
height: s === "density" ? l / (c * r) : l
|
|
597
597
|
}));
|
|
598
598
|
}
|
|
599
|
-
function
|
|
599
|
+
function pi(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 = xt(typeof e == "number" ? e : gt(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") {
|
|
@@ -610,10 +610,10 @@ function bn(t, e, n) {
|
|
|
610
610
|
return [t.x[0] + s * (t.x[1] - t.x[0]), t.y[0] + o * (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 * yt(i)];
|
|
614
614
|
});
|
|
615
615
|
}
|
|
616
|
-
function
|
|
616
|
+
function xn(t) {
|
|
617
617
|
const e = t.length;
|
|
618
618
|
if (e < 2) return;
|
|
619
619
|
const n = t.reduce((l, d) => l + d[0], 0) / e, i = t.reduce((l, d) => l + d[1], 0) / e;
|
|
@@ -624,20 +624,20 @@ function vn(t) {
|
|
|
624
624
|
const c = s / r;
|
|
625
625
|
return { slope: c, intercept: i - c * n, r: o === 0 ? 0 : s / Math.sqrt(r * o) };
|
|
626
626
|
}
|
|
627
|
-
function
|
|
627
|
+
function yi(t, e, n) {
|
|
628
628
|
const i = Math.min(1, Math.max(0, t)), s = i * Math.min(1, Math.max(0, e)), r = (1 - i) * Math.min(1, Math.max(0, n)), o = s + r;
|
|
629
629
|
return { truePositive: s, falsePositive: r, positive: o, posterior: o > 0 ? s / o : 0 };
|
|
630
630
|
}
|
|
631
|
-
function
|
|
632
|
-
const i =
|
|
631
|
+
function tn(t, e, n) {
|
|
632
|
+
const i = xt(gt(`${t}:${e}`));
|
|
633
633
|
return Array.from({ length: n }, () => i.next() < 0.5);
|
|
634
634
|
}
|
|
635
|
-
const
|
|
636
|
-
function
|
|
635
|
+
const xe = (t) => t.filter(Boolean).length;
|
|
636
|
+
function mi(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, c = t.slice(0, s).filter(Boolean).length - s / 2, l = c + (t[s] ? 0.5 : -0.5), d = 0.18 * Math.sin(Math.PI * r);
|
|
638
638
|
return { x: c + (l - c) * r, depth: s + r - d };
|
|
639
639
|
}
|
|
640
|
-
const
|
|
640
|
+
const gi = '"Latin Modern Math", "STIX Two Math", "Cambria Math", "Times New Roman", "Liberation Serif", "Noto Serif", Times, serif', bi = '"Latin Modern Math", "STIX Two Math", "Cambria Math", "DejaVu Math TeX Gyre", "DejaVu Serif", serif', vi = (t) => /^[A-Za-z0-9\u0370-\u03ff.,;:!?()[\]'"/ ]+$/.test(t) ? gi : bi, Sn = 0.25, Ct = 0.05, en = {
|
|
641
641
|
a: 0.5,
|
|
642
642
|
b: 0.56,
|
|
643
643
|
c: 0.44,
|
|
@@ -691,13 +691,13 @@ const di = '"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 Ie(t) {
|
|
695
|
+
return t.length !== 1 ? t.length * 0.5 : /[0-9]/.test(t) ? 0.5 : Object.prototype.hasOwnProperty.call(en, t) ? en[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 En(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 Pe = {
|
|
701
701
|
alpha: "α",
|
|
702
702
|
beta: "β",
|
|
703
703
|
gamma: "γ",
|
|
@@ -733,7 +733,7 @@ const Me = {
|
|
|
733
733
|
Phi: "Φ",
|
|
734
734
|
Psi: "Ψ",
|
|
735
735
|
Omega: "Ω"
|
|
736
|
-
},
|
|
736
|
+
}, Fe = {
|
|
737
737
|
cdot: ["·", "bin"],
|
|
738
738
|
times: ["×", "bin"],
|
|
739
739
|
div: ["÷", "bin"],
|
|
@@ -801,7 +801,7 @@ const Me = {
|
|
|
801
801
|
rangle: ["⟩", "close"],
|
|
802
802
|
lbrace: ["{", "open"],
|
|
803
803
|
rbrace: ["}", "close"]
|
|
804
|
-
},
|
|
804
|
+
}, Le = { sum: ["∑", !0], prod: ["∏", !0], int: ["∫", !1], oint: ["∮", !1] }, Ce = {
|
|
805
805
|
sin: !1,
|
|
806
806
|
cos: !1,
|
|
807
807
|
tan: !1,
|
|
@@ -837,8 +837,8 @@ const Me = {
|
|
|
837
837
|
Pr: !1,
|
|
838
838
|
E: !1,
|
|
839
839
|
Var: !1
|
|
840
|
-
},
|
|
841
|
-
class
|
|
840
|
+
}, qe = { ",": 3 / 18, ":": 4 / 18, ";": 5 / 18, "!": -3 / 18, quad: 1, qquad: 2 }, nn = /* @__PURE__ */ new Set(["pmatrix", "bmatrix", "vmatrix", "matrix"]);
|
|
841
|
+
class wi extends Error {
|
|
842
842
|
source;
|
|
843
843
|
/** 0-based index into the source */
|
|
844
844
|
position;
|
|
@@ -846,12 +846,12 @@ class fi extends Error {
|
|
|
846
846
|
super(`${e} at ${i + 1} in "${n}"`), this.name = "TexError", this.source = n, this.position = i;
|
|
847
847
|
}
|
|
848
848
|
}
|
|
849
|
-
const
|
|
850
|
-
...Object.keys(
|
|
851
|
-
...Object.keys(
|
|
852
|
-
...Object.keys(
|
|
853
|
-
...Object.keys(
|
|
854
|
-
...Object.keys(
|
|
849
|
+
const $i = [
|
|
850
|
+
...Object.keys(Pe),
|
|
851
|
+
...Object.keys(Fe),
|
|
852
|
+
...Object.keys(Le),
|
|
853
|
+
...Object.keys(Ce),
|
|
854
|
+
...Object.keys(qe).filter((t) => t.length > 1),
|
|
855
855
|
"frac",
|
|
856
856
|
"binom",
|
|
857
857
|
"sqrt",
|
|
@@ -867,13 +867,13 @@ const yi = [
|
|
|
867
867
|
"left",
|
|
868
868
|
"right"
|
|
869
869
|
].sort();
|
|
870
|
-
function
|
|
870
|
+
function ki(t) {
|
|
871
871
|
if (typeof t != "string") throw new TypeError("parseTex: expected a string");
|
|
872
872
|
let e = 0;
|
|
873
873
|
const n = () => {
|
|
874
874
|
for (; e < t.length && /\s/.test(t[e]); ) e++;
|
|
875
|
-
}, i = (u,
|
|
876
|
-
throw new
|
|
875
|
+
}, i = (u, f = e) => {
|
|
876
|
+
throw new wi(u, t, f);
|
|
877
877
|
}, s = () => {
|
|
878
878
|
const u = e;
|
|
879
879
|
if (/[A-Za-z]/.test(t[e] ?? ""))
|
|
@@ -882,74 +882,74 @@ function mi(t) {
|
|
|
882
882
|
return t.slice(u, e);
|
|
883
883
|
}, r = (u) => {
|
|
884
884
|
n(), t[e] !== "{" && i(`Expected "{" for ${u}`);
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
const h = t.slice(e + 1,
|
|
888
|
-
return e =
|
|
885
|
+
const f = t.indexOf("}", e);
|
|
886
|
+
f < 0 && i(`Missing "}" for ${u}`);
|
|
887
|
+
const h = t.slice(e + 1, f);
|
|
888
|
+
return e = f + 1, h;
|
|
889
889
|
}, o = (u) => {
|
|
890
890
|
if (n(), e >= t.length && i(`Missing ${u}`), t[e] === "{") {
|
|
891
891
|
e++;
|
|
892
892
|
const h = c("}");
|
|
893
893
|
return e++, { type: "group", body: h };
|
|
894
894
|
}
|
|
895
|
-
const
|
|
896
|
-
return
|
|
895
|
+
const f = l();
|
|
896
|
+
return f || i(`Missing ${u}`), f;
|
|
897
897
|
}, c = (u) => {
|
|
898
|
-
const
|
|
898
|
+
const f = [];
|
|
899
899
|
for (; ; ) {
|
|
900
900
|
if (n(), e >= t.length)
|
|
901
|
-
return u === "}" && i('Missing "}"'), u === "cell" && i("Missing \\end"),
|
|
902
|
-
if (u === "}" && t[e] === "}" || (t[e] === "}" && i('Unexpected "}"'), u === "cell" && (t[e] === "&" || t.startsWith("\\\\", e) || t.startsWith("\\end", e)))) return
|
|
901
|
+
return u === "}" && i('Missing "}"'), u === "cell" && i("Missing \\end"), f;
|
|
902
|
+
if (u === "}" && t[e] === "}" || (t[e] === "}" && i('Unexpected "}"'), u === "cell" && (t[e] === "&" || t.startsWith("\\\\", e) || t.startsWith("\\end", e)))) return f;
|
|
903
903
|
if (t[e] === "^" || t[e] === "_") {
|
|
904
|
-
const g = e,
|
|
904
|
+
const g = e, p = t[e] === "^";
|
|
905
905
|
e++;
|
|
906
|
-
const y = o(
|
|
907
|
-
let a =
|
|
908
|
-
a.type !== "scripts" && (a = { type: "scripts", base: a }), a.type === "scripts" && ((
|
|
906
|
+
const y = o(p ? "superscript" : "subscript");
|
|
907
|
+
let a = f.pop() ?? { type: "group", body: [] };
|
|
908
|
+
a.type !== "scripts" && (a = { type: "scripts", base: a }), a.type === "scripts" && ((p && a.sup || !p && a.sub) && i(`Double ${p ? "superscript" : "subscript"}`, g), p ? a.sup = y : a.sub = y), f.push(a);
|
|
909
909
|
continue;
|
|
910
910
|
}
|
|
911
911
|
if (t[e] === "'") {
|
|
912
912
|
e++;
|
|
913
|
-
const g = { type: "symbol", text: "′", cls: "ord", italic: !1 },
|
|
914
|
-
|
|
913
|
+
const g = { type: "symbol", text: "′", cls: "ord", italic: !1 }, p = f.pop() ?? { type: "group", body: [] };
|
|
914
|
+
f.push(p.type === "scripts" && !p.sup ? { ...p, sup: g } : { type: "scripts", base: p, sup: g });
|
|
915
915
|
continue;
|
|
916
916
|
}
|
|
917
917
|
const h = l();
|
|
918
|
-
h &&
|
|
918
|
+
h && f.push(h);
|
|
919
919
|
}
|
|
920
920
|
}, l = () => {
|
|
921
921
|
const u = t[e];
|
|
922
922
|
if (u === "{") {
|
|
923
923
|
e++;
|
|
924
|
-
const
|
|
925
|
-
return e++, { type: "group", body:
|
|
924
|
+
const f = c("}");
|
|
925
|
+
return e++, { type: "group", body: f };
|
|
926
926
|
}
|
|
927
927
|
if (u === "&" && i('"&" outside a matrix'), u === "\\") {
|
|
928
|
-
const
|
|
928
|
+
const f = e;
|
|
929
929
|
e++;
|
|
930
930
|
const h = s();
|
|
931
|
-
if (h === "\\" && i('"\\\\" outside a matrix',
|
|
931
|
+
if (h === "\\" && i('"\\\\" outside a matrix', f), h in qe) return { type: "space", width: qe[h] };
|
|
932
932
|
if (h === "{" || h === "}") return { type: "symbol", text: h, cls: h === "{" ? "open" : "close", italic: !1 };
|
|
933
933
|
if (h === "|") return { type: "symbol", text: "‖", cls: "ord", italic: !1 };
|
|
934
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
935
|
-
return { type: "symbol", text:
|
|
936
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
937
|
-
const [
|
|
938
|
-
return { type: "symbol", text:
|
|
934
|
+
if (Object.prototype.hasOwnProperty.call(Pe, h))
|
|
935
|
+
return { type: "symbol", text: Pe[h], cls: "ord", italic: h[0] === h[0].toLowerCase() };
|
|
936
|
+
if (Object.prototype.hasOwnProperty.call(Fe, h)) {
|
|
937
|
+
const [p, y] = Fe[h];
|
|
938
|
+
return { type: "symbol", text: p, cls: y, italic: !1 };
|
|
939
939
|
}
|
|
940
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
941
|
-
const [
|
|
942
|
-
return { type: "bigop", text:
|
|
940
|
+
if (Object.prototype.hasOwnProperty.call(Le, h)) {
|
|
941
|
+
const [p, y] = Le[h];
|
|
942
|
+
return { type: "bigop", text: p, limits: y };
|
|
943
943
|
}
|
|
944
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
944
|
+
if (Object.prototype.hasOwnProperty.call(Ce, h)) return { type: "opname", text: h, limits: Ce[h] };
|
|
945
945
|
switch (h) {
|
|
946
946
|
case "frac":
|
|
947
947
|
return { type: "frac", num: o("numerator"), den: o("denominator") };
|
|
948
948
|
case "binom": {
|
|
949
|
-
const
|
|
949
|
+
const p = o("\\binom's top"), y = o("\\binom's bottom");
|
|
950
950
|
return {
|
|
951
951
|
type: "group",
|
|
952
|
-
body: [{ type: "symbol", text: "(", cls: "open", italic: !1 }, { type: "frac", num:
|
|
952
|
+
body: [{ type: "symbol", text: "(", cls: "open", italic: !1 }, { type: "frac", num: p, den: y, bar: !1 }, { type: "symbol", text: ")", cls: "close", italic: !1 }]
|
|
953
953
|
};
|
|
954
954
|
}
|
|
955
955
|
case "sqrt":
|
|
@@ -961,28 +961,28 @@ function mi(t) {
|
|
|
961
961
|
case "text":
|
|
962
962
|
return { type: "text", text: r("\\text") };
|
|
963
963
|
case "color": {
|
|
964
|
-
const
|
|
965
|
-
return /^(#[0-9a-fA-F]{3,8}|[a-zA-Z]+)$/.test(
|
|
964
|
+
const p = r("\\color").trim();
|
|
965
|
+
return /^(#[0-9a-fA-F]{3,8}|[a-zA-Z]+)$/.test(p) || i(`"${p}" is not a colour name or #hex`, f), { type: "color", color: p, body: o("\\color's body") };
|
|
966
966
|
}
|
|
967
967
|
case "id": {
|
|
968
|
-
const
|
|
969
|
-
return /^[\w.-]+$/.test(
|
|
968
|
+
const p = r("\\id").trim();
|
|
969
|
+
return /^[\w.-]+$/.test(p) || i(`"${p}" is not a term id (letters, digits, _ . -)`, f), { type: "id", id: p, body: o("\\id's body") };
|
|
970
970
|
}
|
|
971
971
|
case "val": {
|
|
972
|
-
const
|
|
973
|
-
return y || i(`"${
|
|
972
|
+
const p = r("\\val").trim(), y = /^([A-Za-z_][\w.]*)(?::(\d))?$/.exec(p);
|
|
973
|
+
return y || i(`"${p}" is not a value name (name or name:digits)`, f), { type: "value", name: y[1], digits: y[2] === void 0 ? 2 : Number(y[2]) };
|
|
974
974
|
}
|
|
975
975
|
case "left":
|
|
976
976
|
case "right": {
|
|
977
977
|
n();
|
|
978
|
-
const
|
|
979
|
-
if (
|
|
980
|
-
const a = { "(": "(", ")": ")", "[": "[", "]": "]", "|": "|", "{": "{", "}": "}", langle: "⟨", rangle: "⟩", "|.": "‖" }[
|
|
981
|
-
return a || i(`"${
|
|
978
|
+
const p = t[e] === "\\" ? (e++, s()) : t[e++];
|
|
979
|
+
if (p === ".") return { type: "space", width: 0 };
|
|
980
|
+
const a = { "(": "(", ")": ")", "[": "[", "]": "]", "|": "|", "{": "{", "}": "}", langle: "⟨", rangle: "⟩", "|.": "‖" }[p];
|
|
981
|
+
return a || i(`"${p}" is not a delimiter`, f), { type: "symbol", text: a, cls: h === "left" ? "open" : "close", italic: !1 };
|
|
982
982
|
}
|
|
983
983
|
case "begin": {
|
|
984
|
-
const
|
|
985
|
-
|
|
984
|
+
const p = r("\\begin").trim();
|
|
985
|
+
nn.has(p) || i(`Unknown environment "${p}" (use ${[...nn].join(", ")})`, f);
|
|
986
986
|
const y = [[]];
|
|
987
987
|
for (; ; ) {
|
|
988
988
|
const a = c("cell");
|
|
@@ -993,53 +993,53 @@ function mi(t) {
|
|
|
993
993
|
else {
|
|
994
994
|
e += 4;
|
|
995
995
|
const m = r("\\end").trim();
|
|
996
|
-
m !==
|
|
996
|
+
m !== p && i(`\\begin{${p}} ended by \\end{${m}}`);
|
|
997
997
|
break;
|
|
998
998
|
}
|
|
999
999
|
}
|
|
1000
|
-
return y.length > 1 && y[y.length - 1].every((a) => a.type === "group" && a.body.length === 0) && y.pop(), { type: "matrix", delimiters:
|
|
1000
|
+
return y.length > 1 && y[y.length - 1].every((a) => a.type === "group" && a.body.length === 0) && y.pop(), { type: "matrix", delimiters: p, rows: y };
|
|
1001
1001
|
}
|
|
1002
1002
|
case "end":
|
|
1003
|
-
return i("\\end without \\begin",
|
|
1003
|
+
return i("\\end without \\begin", f);
|
|
1004
1004
|
}
|
|
1005
|
-
const g =
|
|
1006
|
-
return i(`Unknown command "\\${h}"${g ? ` (did you mean "\\${g}"?)` : ""}`,
|
|
1005
|
+
const g = ei(h, $i);
|
|
1006
|
+
return i(`Unknown command "\\${h}"${g ? ` (did you mean "\\${g}"?)` : ""}`, f);
|
|
1007
1007
|
}
|
|
1008
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);
|
|
1009
1009
|
};
|
|
1010
1010
|
return { type: "group", body: c("") };
|
|
1011
1011
|
}
|
|
1012
|
-
const
|
|
1013
|
-
function
|
|
1012
|
+
const lt = [1, 1, 0.7, 0.5], Mi = (t) => t <= 1 ? 2 : 3, xi = (t) => Math.min(3, t + 1), Ve = () => ({ width: 0, height: 0, depth: 0, pieces: [] });
|
|
1013
|
+
function at(t, e, n) {
|
|
1014
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 });
|
|
1015
1015
|
}
|
|
1016
|
-
function
|
|
1016
|
+
function St(t, e) {
|
|
1017
1017
|
if (t.id) return t.id;
|
|
1018
1018
|
const n = (t.counts.get(e) ?? 0) + 1;
|
|
1019
1019
|
return t.counts.set(e, n), `${e}#${n}`;
|
|
1020
1020
|
}
|
|
1021
|
-
function
|
|
1022
|
-
const r =
|
|
1021
|
+
function sn(t, e, n, i = 1, s = t) {
|
|
1022
|
+
const r = lt[n.level] * i, o = Ie(t) * r, { height: c, depth: l } = En(t);
|
|
1023
1023
|
return {
|
|
1024
1024
|
width: o,
|
|
1025
1025
|
height: c * r,
|
|
1026
1026
|
depth: l * r,
|
|
1027
|
-
pieces: [{ kind: "glyph", text: t, x: 0, y: 0, width: o, size: r, italic: e, ...n.color ? { color: n.color } : {}, id:
|
|
1027
|
+
pieces: [{ kind: "glyph", text: t, x: 0, y: 0, width: o, size: r, italic: e, ...n.color ? { color: n.color } : {}, id: St(n, s) }]
|
|
1028
1028
|
};
|
|
1029
1029
|
}
|
|
1030
|
-
function
|
|
1031
|
-
const i =
|
|
1030
|
+
function Se(t, e, n) {
|
|
1031
|
+
const i = Ve(), s = St(e, n), r = lt[e.level];
|
|
1032
1032
|
for (const o of t) {
|
|
1033
|
-
const c = (o === " " ? 0.28 : /[A-Za-z]/.test(o) ?
|
|
1033
|
+
const c = (o === " " ? 0.28 : /[A-Za-z]/.test(o) ? Ie(o) - 0.04 : Ie(o)) * r;
|
|
1034
1034
|
if (o !== " ") {
|
|
1035
|
-
const { height: l, depth: d } =
|
|
1035
|
+
const { height: l, depth: d } = En(o);
|
|
1036
1036
|
i.pieces.push({ kind: "glyph", text: o, x: i.width, y: 0, width: c, size: r, italic: !1, ...e.color ? { color: e.color } : {}, id: s }), i.height = Math.max(i.height, l * r), i.depth = Math.max(i.depth, d * r);
|
|
1037
1037
|
}
|
|
1038
1038
|
i.width += c;
|
|
1039
1039
|
}
|
|
1040
1040
|
return i;
|
|
1041
1041
|
}
|
|
1042
|
-
function
|
|
1042
|
+
function ze(t) {
|
|
1043
1043
|
switch (t.type) {
|
|
1044
1044
|
case "symbol":
|
|
1045
1045
|
return t.cls;
|
|
@@ -1047,112 +1047,112 @@ function Te(t) {
|
|
|
1047
1047
|
case "opname":
|
|
1048
1048
|
return "op";
|
|
1049
1049
|
case "scripts":
|
|
1050
|
-
return
|
|
1050
|
+
return ze(t.base);
|
|
1051
1051
|
case "id":
|
|
1052
1052
|
case "color":
|
|
1053
|
-
return
|
|
1053
|
+
return ze(t.body);
|
|
1054
1054
|
default:
|
|
1055
1055
|
return "ord";
|
|
1056
1056
|
}
|
|
1057
1057
|
}
|
|
1058
|
-
function
|
|
1058
|
+
function Si(t, e) {
|
|
1059
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;
|
|
1060
1060
|
}
|
|
1061
|
-
function
|
|
1062
|
-
const n =
|
|
1061
|
+
function Ei(t, e) {
|
|
1062
|
+
const n = Ve();
|
|
1063
1063
|
let i;
|
|
1064
1064
|
return t.forEach((s) => {
|
|
1065
1065
|
if (s.type === "space") {
|
|
1066
|
-
n.width += s.width *
|
|
1066
|
+
n.width += s.width * lt[e.level];
|
|
1067
1067
|
return;
|
|
1068
1068
|
}
|
|
1069
|
-
let r =
|
|
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 +=
|
|
1071
|
-
const o =
|
|
1072
|
-
n.pieces.push(...
|
|
1069
|
+
let r = ze(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 += Si(i, r) / 18 * lt[e.level]);
|
|
1071
|
+
const o = Q(s, e);
|
|
1072
|
+
n.pieces.push(...at(o, n.width, 0)), n.width += o.width, n.height = Math.max(n.height, o.height), n.depth = Math.max(n.depth, o.depth), i = r;
|
|
1073
1073
|
}), n;
|
|
1074
1074
|
}
|
|
1075
|
-
function
|
|
1075
|
+
function Ai(t, e) {
|
|
1076
1076
|
if (!Number.isFinite(t)) return t > 0 ? "∞" : t < 0 ? "−∞" : "?";
|
|
1077
1077
|
const n = t.toFixed(e), i = n.includes(".") ? n.replace(/\.?0+$/, "") : n;
|
|
1078
1078
|
return (i === "-0" ? "0" : i).replace("-", "−");
|
|
1079
1079
|
}
|
|
1080
|
-
function
|
|
1081
|
-
const n =
|
|
1080
|
+
function Q(t, e) {
|
|
1081
|
+
const n = lt[e.level];
|
|
1082
1082
|
switch (t.type) {
|
|
1083
1083
|
case "symbol":
|
|
1084
|
-
return
|
|
1084
|
+
return sn(t.text, t.italic, e);
|
|
1085
1085
|
case "group":
|
|
1086
|
-
return
|
|
1086
|
+
return Ei(t.body, e);
|
|
1087
1087
|
case "space":
|
|
1088
|
-
return { ...
|
|
1088
|
+
return { ...Ve(), width: t.width * n };
|
|
1089
1089
|
case "text":
|
|
1090
|
-
return
|
|
1090
|
+
return Se(t.text, e, `text:${t.text}`);
|
|
1091
1091
|
case "opname":
|
|
1092
|
-
return
|
|
1092
|
+
return Se(t.text, e, t.text);
|
|
1093
1093
|
case "value": {
|
|
1094
1094
|
const i = e.values[t.name];
|
|
1095
1095
|
if (i === void 0) throw new Error(`\\val{${t.name}}: no value named "${t.name}"`);
|
|
1096
|
-
return
|
|
1096
|
+
return Se(Ai(i, t.digits), { ...e, id: e.id ?? `val:${t.name}` }, `val:${t.name}`);
|
|
1097
1097
|
}
|
|
1098
1098
|
case "bigop":
|
|
1099
|
-
return
|
|
1099
|
+
return sn(t.text, !1, e, e.level === 0 ? 1.4 : 1.1);
|
|
1100
1100
|
case "color":
|
|
1101
|
-
return
|
|
1101
|
+
return Q(t.body, { ...e, color: t.color });
|
|
1102
1102
|
case "id":
|
|
1103
|
-
return
|
|
1103
|
+
return Q(t.body, { ...e, id: t.id });
|
|
1104
1104
|
case "scripts":
|
|
1105
|
-
return
|
|
1105
|
+
return Ti(t, e);
|
|
1106
1106
|
case "frac":
|
|
1107
|
-
return
|
|
1107
|
+
return Oi(t, e);
|
|
1108
1108
|
case "sqrt":
|
|
1109
|
-
return
|
|
1109
|
+
return Ni(t, e);
|
|
1110
1110
|
case "accent":
|
|
1111
|
-
return
|
|
1111
|
+
return Ii(t, e);
|
|
1112
1112
|
case "matrix":
|
|
1113
|
-
return
|
|
1113
|
+
return Pi(t, e);
|
|
1114
1114
|
}
|
|
1115
1115
|
}
|
|
1116
|
-
function
|
|
1117
|
-
const n =
|
|
1116
|
+
function Ti(t, e) {
|
|
1117
|
+
const n = Q(t.base, e), i = { ...e, level: Mi(e.level) }, s = t.sup ? Q(t.sup, i) : void 0, r = t.sub ? Q(t.sub, i) : void 0, o = lt[e.level], c = e.level === 0 && (t.base.type === "bigop" && t.base.limits || t.base.type === "opname" && t.base.limits), l = { ...n, pieces: [...n.pieces] };
|
|
1118
1118
|
if (c) {
|
|
1119
|
-
const g = Math.max(n.width, s?.width ?? 0, r?.width ?? 0),
|
|
1119
|
+
const g = Math.max(n.width, s?.width ?? 0, r?.width ?? 0), p = at(n, (g - n.width) / 2, 0);
|
|
1120
1120
|
let y = n.height, a = n.depth;
|
|
1121
1121
|
const m = 0.12 * o;
|
|
1122
1122
|
if (s) {
|
|
1123
1123
|
const b = -(n.height + m + s.depth);
|
|
1124
|
-
|
|
1124
|
+
p.push(...at(s, (g - s.width) / 2, b)), y = -b + s.height;
|
|
1125
1125
|
}
|
|
1126
1126
|
if (r) {
|
|
1127
1127
|
const b = n.depth + m + r.height;
|
|
1128
|
-
|
|
1128
|
+
p.push(...at(r, (g - r.width) / 2, b)), a = b + r.depth;
|
|
1129
1129
|
}
|
|
1130
|
-
return { width: g, height: y, depth: a, pieces:
|
|
1130
|
+
return { width: g, height: y, depth: a, pieces: p };
|
|
1131
1131
|
}
|
|
1132
1132
|
let d = s ? Math.max(0.42 * o, n.height - 0.3 * o, s.depth + 0.25 * o) : 0, u = r ? Math.max(0.2 * o, n.depth + 0.12 * o, r.height - 0.4 * o) : 0;
|
|
1133
1133
|
if (s && r) {
|
|
1134
1134
|
const g = d - s.depth - (r.height - u);
|
|
1135
1135
|
g < 0.2 * o && (u += 0.2 * o - g);
|
|
1136
1136
|
}
|
|
1137
|
-
const
|
|
1137
|
+
const f = n.width + 0.03 * o;
|
|
1138
1138
|
let h = n.width;
|
|
1139
|
-
return s ? (l.pieces.push(...
|
|
1139
|
+
return s ? (l.pieces.push(...at(s, f, -d)), l.height = Math.max(l.height, d + s.height), h = Math.max(h, f + s.width)) : d = 0, r && (l.pieces.push(...at(r, f, u)), l.depth = Math.max(l.depth, u + r.depth), h = Math.max(h, f + r.width)), l.width = h + 0.04 * o, l;
|
|
1140
1140
|
}
|
|
1141
|
-
function
|
|
1142
|
-
const n = { ...e, level:
|
|
1141
|
+
function Oi(t, e) {
|
|
1142
|
+
const n = { ...e, level: xi(e.level) }, i = Q(t.num, n), s = Q(t.den, n), r = lt[e.level], o = Ct * r, c = Sn * r, l = (e.level === 0 ? 0.16 : 0.1) * r, d = 0.1 * r, u = Math.max(i.width, s.width) + d * 2, f = -(c + o / 2 + l + i.depth), h = -c + o / 2 + l + s.height;
|
|
1143
1143
|
return {
|
|
1144
1144
|
width: u,
|
|
1145
|
-
height: -
|
|
1145
|
+
height: -f + i.height,
|
|
1146
1146
|
depth: h + s.depth,
|
|
1147
1147
|
pieces: [
|
|
1148
|
-
...
|
|
1149
|
-
...t.bar === !1 ? [] : [{ kind: "rule", x: 0, y: -c - o / 2, width: u, height: o, ...e.color ? { color: e.color } : {}, id:
|
|
1150
|
-
...
|
|
1148
|
+
...at(i, (u - i.width) / 2, f),
|
|
1149
|
+
...t.bar === !1 ? [] : [{ kind: "rule", x: 0, y: -c - o / 2, width: u, height: o, ...e.color ? { color: e.color } : {}, id: St(e, "frac") }],
|
|
1150
|
+
...at(s, (u - s.width) / 2, h)
|
|
1151
1151
|
]
|
|
1152
1152
|
};
|
|
1153
1153
|
}
|
|
1154
|
-
function
|
|
1155
|
-
const n =
|
|
1154
|
+
function Ni(t, e) {
|
|
1155
|
+
const n = Q(t.body, e), i = lt[e.level], s = Math.max(n.height, 0.7 * i) + 0.14 * i, r = Math.max(n.depth, 0.05 * i) + 0.05 * i, o = 0.56 * i, c = o + n.width + 0.08 * i, l = [
|
|
1156
1156
|
[0.02 * i, -0.36 * i],
|
|
1157
1157
|
[0.13 * i, -0.44 * i],
|
|
1158
1158
|
[0.3 * i, r],
|
|
@@ -1161,13 +1161,13 @@ function xi(t, e) {
|
|
|
1161
1161
|
];
|
|
1162
1162
|
return {
|
|
1163
1163
|
width: c,
|
|
1164
|
-
height: s +
|
|
1164
|
+
height: s + Ct * i,
|
|
1165
1165
|
depth: r,
|
|
1166
|
-
pieces: [{ kind: "stroke", points: l, width:
|
|
1166
|
+
pieces: [{ kind: "stroke", points: l, width: Ct * i, ...e.color ? { color: e.color } : {}, id: St(e, "sqrt") }, ...at(n, o, 0)]
|
|
1167
1167
|
};
|
|
1168
1168
|
}
|
|
1169
|
-
function
|
|
1170
|
-
const n =
|
|
1169
|
+
function Ii(t, e) {
|
|
1170
|
+
const n = Q(t.body, e), i = lt[e.level], s = -(n.height + 0.12 * i), r = 0.04 * i, o = Math.max(n.width - 0.02 * i, r + 0.3 * i), c = e.color ? { color: e.color } : {}, l = St(e, t.accent);
|
|
1171
1171
|
let d;
|
|
1172
1172
|
if (t.accent === "vec") {
|
|
1173
1173
|
const u = 0.12 * i;
|
|
@@ -1181,47 +1181,47 @@ function Si(t, e) {
|
|
|
1181
1181
|
width: Math.max(n.width, o + 0.02 * i),
|
|
1182
1182
|
height: -s + 0.14 * i,
|
|
1183
1183
|
depth: n.depth,
|
|
1184
|
-
pieces: [...n.pieces, ...d.map((u) => ({ kind: "stroke", points: u, width:
|
|
1184
|
+
pieces: [...n.pieces, ...d.map((u) => ({ kind: "stroke", points: u, width: Ct * i * 0.9, ...c, id: l }))]
|
|
1185
1185
|
};
|
|
1186
1186
|
}
|
|
1187
|
-
function
|
|
1188
|
-
const n = { ...e, level: Math.max(e.level, 1) }, i =
|
|
1189
|
-
let a =
|
|
1187
|
+
function Pi(t, e) {
|
|
1188
|
+
const n = { ...e, level: Math.max(e.level, 1) }, i = lt[n.level], s = t.rows.map(($) => $.map((M) => Q(M, n))), r = Math.max(...s.map(($) => $.length)), o = Array.from({ length: r }, ($, M) => Math.max(0, ...s.map((k) => k[M]?.width ?? 0))), c = s.map(($) => Math.max(0.7 * i, ...$.map((M) => M.height))), l = s.map(($) => Math.max(0.2 * i, ...$.map((M) => M.depth))), d = 0.9 * i, u = 0.25 * i, f = t.delimiters === "matrix" ? 0 : 0.55 * i, h = o.reduce(($, M) => $ + M, 0) + d * (r - 1), g = c.reduce(($, M, k) => $ + M + l[k], 0) + u * (s.length - 1), p = -Sn * i - g / 2, y = [];
|
|
1189
|
+
let a = p;
|
|
1190
1190
|
s.forEach(($, M) => {
|
|
1191
1191
|
a += c[M];
|
|
1192
|
-
let k =
|
|
1192
|
+
let k = f;
|
|
1193
1193
|
$.forEach((S, E) => {
|
|
1194
|
-
y.push(...
|
|
1194
|
+
y.push(...at(S, k + (o[E] - S.width) / 2, a)), k += o[E] + d;
|
|
1195
1195
|
}), a += l[M] + u;
|
|
1196
1196
|
});
|
|
1197
|
-
const m = h +
|
|
1197
|
+
const m = h + f * 2, b = p + g, x = e.color ? { color: e.color } : {}, w = ($, M) => ({ kind: "stroke", points: $, width: Ct * i * 1.1, ...x, id: St(e, M) }), v = 0.08 * i;
|
|
1198
1198
|
if (t.delimiters === "pmatrix") {
|
|
1199
1199
|
const $ = (M) => {
|
|
1200
|
-
const k = M === 1 ?
|
|
1201
|
-
return Array.from({ length: 17 }, (E,
|
|
1202
|
-
const
|
|
1203
|
-
return [k - S * Math.sin(Math.PI *
|
|
1200
|
+
const k = M === 1 ? f * 0.75 : m - f * 0.75, S = M * f * 0.5;
|
|
1201
|
+
return Array.from({ length: 17 }, (E, T) => {
|
|
1202
|
+
const O = T / 16;
|
|
1203
|
+
return [k - S * Math.sin(Math.PI * O), p - v + (g + v * 2) * O];
|
|
1204
1204
|
});
|
|
1205
1205
|
};
|
|
1206
1206
|
y.push(w($(1), "("), w($(-1), ")"));
|
|
1207
1207
|
} else if (t.delimiters === "bmatrix") {
|
|
1208
|
-
const $ =
|
|
1208
|
+
const $ = f * 0.35, M = f * 0.2, k = m - f * 0.2;
|
|
1209
1209
|
y.push(
|
|
1210
|
-
w([[M + $,
|
|
1211
|
-
w([[k - $,
|
|
1210
|
+
w([[M + $, p - v], [M, p - v], [M, b + v], [M + $, b + v]], "["),
|
|
1211
|
+
w([[k - $, p - v], [k, p - v], [k, b + v], [k - $, b + v]], "]")
|
|
1212
1212
|
);
|
|
1213
|
-
} else t.delimiters === "vmatrix" && y.push(w([[
|
|
1214
|
-
return { width: m, height: -
|
|
1213
|
+
} else t.delimiters === "vmatrix" && y.push(w([[f * 0.4, p - v], [f * 0.4, b + v]], "|"), w([[m - f * 0.4, p - v], [m - f * 0.4, b + v]], "|"));
|
|
1214
|
+
return { width: m, height: -p + v, depth: b + v, pieces: y };
|
|
1215
1215
|
}
|
|
1216
1216
|
function U(t, e = {}) {
|
|
1217
|
-
const n = typeof t == "string" ?
|
|
1217
|
+
const n = typeof t == "string" ? ki(t) : t, i = { level: e.style === "inline" ? 1 : 0, values: e.values ?? {}, counts: /* @__PURE__ */ new Map() }, s = Q(n, i);
|
|
1218
1218
|
return { width: s.width, height: s.height, depth: s.depth, pieces: s.pieces };
|
|
1219
1219
|
}
|
|
1220
|
-
const
|
|
1220
|
+
const pt = 'system-ui, -apple-system, "Segoe UI", sans-serif', rn = (t, e) => Math.hypot(e[0] - t[0], e[1] - t[1]);
|
|
1221
1221
|
function V(t, e) {
|
|
1222
1222
|
if (e >= 1) return t;
|
|
1223
1223
|
if (e <= 0) return [];
|
|
1224
|
-
const n = t.map((r) => r.slice(1).reduce((o, c, l) => o +
|
|
1224
|
+
const n = t.map((r) => r.slice(1).reduce((o, c, l) => o + rn(r[l], c), 0));
|
|
1225
1225
|
let i = n.reduce((r, o) => r + o, 0) * e;
|
|
1226
1226
|
const s = [];
|
|
1227
1227
|
for (const [r, o] of t.entries()) {
|
|
@@ -1232,7 +1232,7 @@ function V(t, e) {
|
|
|
1232
1232
|
}
|
|
1233
1233
|
const c = [o[0]];
|
|
1234
1234
|
for (let l = 1; l < o.length; l++) {
|
|
1235
|
-
const d =
|
|
1235
|
+
const d = rn(o[l - 1], o[l]);
|
|
1236
1236
|
if (d >= i) {
|
|
1237
1237
|
const u = d === 0 ? 0 : i / d;
|
|
1238
1238
|
c.push([o[l - 1][0] + (o[l][0] - o[l - 1][0]) * u, o[l - 1][1] + (o[l][1] - o[l - 1][1]) * u]);
|
|
@@ -1244,11 +1244,11 @@ function V(t, e) {
|
|
|
1244
1244
|
}
|
|
1245
1245
|
return s;
|
|
1246
1246
|
}
|
|
1247
|
-
function
|
|
1247
|
+
function He(t, e) {
|
|
1248
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;
|
|
1249
1249
|
return [e.x + i * e.size, e.y + s * e.size];
|
|
1250
1250
|
}
|
|
1251
|
-
function
|
|
1251
|
+
function An(t, e, n) {
|
|
1252
1252
|
const [i, s] = e, r = n.size, o = n.opacity ?? 1;
|
|
1253
1253
|
return t.map((c) => {
|
|
1254
1254
|
const l = (c.color && n.palette?.[c.color]) ?? c.color ?? n.color, d = o * (c.opacity ?? 1), u = `${n.idPrefix}${c.id}`;
|
|
@@ -1260,24 +1260,24 @@ function kn(t, e, n) {
|
|
|
1260
1260
|
x: i + (c.x + c.width / 2) * r,
|
|
1261
1261
|
y: s + c.y * r,
|
|
1262
1262
|
size: c.size * r,
|
|
1263
|
-
font:
|
|
1263
|
+
font: vi(c.text),
|
|
1264
1264
|
italic: c.italic,
|
|
1265
1265
|
color: l,
|
|
1266
1266
|
align: "center",
|
|
1267
1267
|
opacity: d
|
|
1268
1268
|
};
|
|
1269
1269
|
if (c.kind === "rule") {
|
|
1270
|
-
const
|
|
1271
|
-
return { type: "line", id: u, points: [[
|
|
1270
|
+
const f = i + c.x * r, h = s + c.y * r, g = c.width * r, p = Math.max(1, c.height * r);
|
|
1271
|
+
return { type: "line", id: u, points: [[f, h], [f + g, h], [f + g, h + p], [f, h + p]], closed: !0, fill: l, opacity: d };
|
|
1272
1272
|
}
|
|
1273
|
-
return { type: "line", id: u, points: c.points.map(([
|
|
1273
|
+
return { type: "line", id: u, points: c.points.map(([f, h]) => [i + f * r, s + h * r]), stroke: l, width: Math.max(1, c.width * r), opacity: d };
|
|
1274
1274
|
});
|
|
1275
1275
|
}
|
|
1276
1276
|
function X(t, e) {
|
|
1277
|
-
return
|
|
1277
|
+
return An(t.pieces, He(t, e), e);
|
|
1278
1278
|
}
|
|
1279
|
-
const
|
|
1280
|
-
function
|
|
1279
|
+
const ce = 480;
|
|
1280
|
+
function Tn(t, e) {
|
|
1281
1281
|
const n = [];
|
|
1282
1282
|
let i = [];
|
|
1283
1283
|
return t.forEach((s, r) => {
|
|
@@ -1285,52 +1285,52 @@ function Mn(t, e) {
|
|
|
1285
1285
|
(!s || o && Math.abs(s[1] - o[1]) > e * 1.5) && (i.length >= 2 && n.push(i), i = []), s && i.push(s);
|
|
1286
1286
|
}), i.length >= 2 && n.push(i), n;
|
|
1287
1287
|
}
|
|
1288
|
-
function
|
|
1288
|
+
function On(t, e) {
|
|
1289
1289
|
const n = Math.max(e.plane.width, e.plane.height) * 20;
|
|
1290
1290
|
if (!(!Number.isFinite(t[0]) || !Number.isFinite(t[1])))
|
|
1291
1291
|
return [Math.max(-n, Math.min(n, t[0])), Math.max(-n, Math.min(n, t[1]))];
|
|
1292
1292
|
}
|
|
1293
|
-
function
|
|
1293
|
+
function Nn(t, e, n, i, s, r) {
|
|
1294
1294
|
return V(e, s.draw).map((o, c) => ({ type: "line", id: `${t}.${c}`, points: o, stroke: n, width: i, opacity: s.opacity, ...r ? { dash: r } : {} }));
|
|
1295
1295
|
}
|
|
1296
|
-
function
|
|
1297
|
-
const l = Array.from({ length:
|
|
1298
|
-
const
|
|
1299
|
-
return
|
|
1296
|
+
function pe(t, e, n, i, s, r, o, c) {
|
|
1297
|
+
const l = Array.from({ length: ce + 1 }, (d, u) => {
|
|
1298
|
+
const f = n + (i - n) * u / ce;
|
|
1299
|
+
return On(o.plane.toScreen([f, e(f)]), o);
|
|
1300
1300
|
});
|
|
1301
|
-
return
|
|
1301
|
+
return Nn(t, Tn(l, o.plane.height), s, r, o, c);
|
|
1302
1302
|
}
|
|
1303
|
-
function
|
|
1304
|
-
const n = t.derivative ?
|
|
1305
|
-
return
|
|
1306
|
-
}
|
|
1307
|
-
function Ti(t, e) {
|
|
1308
|
-
const n = Z(t.x, "t"), i = Z(t.y, "t"), s = mt(e.values, t.transform), [r, o] = t.t ?? [0, Math.PI * 2], c = Array.from({ length: ne + 1 }, (d, u) => {
|
|
1309
|
-
const p = r + (o - r) * u / ne;
|
|
1310
|
-
return xn(e.plane.toScreen(et(s, [n(p, e.scope), i(p, e.scope)])), e);
|
|
1311
|
-
}), l = I(e.theme, t.color, e.theme.colors.blue);
|
|
1312
|
-
return Sn(t.id, Mn(c, e.plane.height), l, (t.width ?? 3.5) * e.plane.scale, e);
|
|
1303
|
+
function Fi(t, e) {
|
|
1304
|
+
const n = t.derivative ? Be(t.expr, t.derivative) : J(t.expr, "x"), [i, s] = t.domain ?? e.plane.x, r = F(e.theme, t.color, e.theme.colors.blue), o = t.dashed ? [10 * e.plane.scale, 8 * e.plane.scale] : void 0;
|
|
1305
|
+
return pe(t.id, (c) => n(c, e.scope), i, s, r, (t.width ?? 3.5) * e.plane.scale, e, o);
|
|
1313
1306
|
}
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
(
|
|
1307
|
+
function Li(t, e) {
|
|
1308
|
+
const n = J(t.x, "t"), i = J(t.y, "t"), s = bt(e.values, t.transform), [r, o] = t.t ?? [0, Math.PI * 2], c = Array.from({ length: ce + 1 }, (d, u) => {
|
|
1309
|
+
const f = r + (o - r) * u / ce;
|
|
1310
|
+
return On(e.plane.toScreen(nt(s, [n(f, e.scope), i(f, e.scope)])), e);
|
|
1311
|
+
}), l = F(e.theme, t.color, e.theme.colors.blue);
|
|
1312
|
+
return Nn(t.id, Tn(c, e.plane.height), l, (t.width ?? 3.5) * e.plane.scale, e);
|
|
1313
|
+
}
|
|
1314
|
+
const Ue = (t, e, n, i, s) => [[e, n], [i, n], [i, s], [e, s]].map(t.plane.toScreen), le = (t) => Math.min(2e4, Math.max(0, Math.floor(t)));
|
|
1315
|
+
function Ci(t, e) {
|
|
1316
|
+
const n = Mt(e.values, t.distribution), i = $n(n, t.seed ?? t.id, le(P(e.values, t.count))), s = fi(i, t.bins ?? Qe(n), t.scale ?? "density"), r = F(e.theme, t.color, e.theme.colors.blue), o = e.opacity * e.draw, c = s.flatMap(
|
|
1317
|
+
(l, d) => l.height > 0 ? [{ type: "line", id: `${t.id}.${d}`, points: Ue(e, l.left, 0, l.right, l.height), closed: !0, fill: r, stroke: e.theme.background, width: 1 * e.plane.scale, opacity: o * (t.fillOpacity ?? 0.75) }] : []
|
|
1318
1318
|
);
|
|
1319
1319
|
if (t.curve && (t.scale ?? "density") === "density") {
|
|
1320
|
-
const [l, d] = t.bins ??
|
|
1321
|
-
c.push(...
|
|
1320
|
+
const [l, d] = t.bins ?? Qe(n), u = F(e.theme, "yellow", e.theme.colors.yellow);
|
|
1321
|
+
c.push(...pe(`${t.id}.curve`, (f) => ht(fe(n) ? { kind: "normal", mean: Dt(n), sd: _t(n) } : n, f), l, d, u, 3 * e.plane.scale, { ...e, draw: 1 }));
|
|
1322
1322
|
}
|
|
1323
1323
|
return c;
|
|
1324
1324
|
}
|
|
1325
|
-
function
|
|
1326
|
-
const n =
|
|
1327
|
-
if (
|
|
1328
|
-
const d = [], u = Math.max(0, Math.ceil(s)),
|
|
1329
|
-
for (let g = u; g < h && g <=
|
|
1330
|
-
const
|
|
1331
|
-
if (
|
|
1325
|
+
function qi(t, e) {
|
|
1326
|
+
const n = Mt(e.values, t.distribution), i = F(e.theme, t.color, e.theme.colors.blue), [s, r] = t.domain ?? e.plane.x, o = t.shade ? [P(e.values, t.shade[0]), P(e.values, t.shade[1])].sort((d, u) => d - u) : void 0, c = F(e.theme, "yellow", e.theme.colors.yellow);
|
|
1327
|
+
if (fe(n)) {
|
|
1328
|
+
const d = [], u = Math.max(0, Math.ceil(s)), f = Math.floor(r), h = u + Math.ceil((f - u + 1) * e.draw);
|
|
1329
|
+
for (let g = u; g < h && g <= f; g++) {
|
|
1330
|
+
const p = ht(n, g);
|
|
1331
|
+
if (p <= 0) continue;
|
|
1332
1332
|
const y = o && g >= o[0] && g <= o[1];
|
|
1333
|
-
d.push({ type: "line", id: `${t.id}.${g}`, points:
|
|
1333
|
+
d.push({ type: "line", id: `${t.id}.${g}`, points: Ue(e, g - 0.4, 0, g + 0.4, p), closed: !0, fill: y ? c : i, opacity: e.opacity * (t.fillOpacity ?? 0.8) });
|
|
1334
1334
|
}
|
|
1335
1335
|
return d;
|
|
1336
1336
|
}
|
|
@@ -1338,92 +1338,92 @@ function Ni(t, e) {
|
|
|
1338
1338
|
if (o && e.draw >= 1) {
|
|
1339
1339
|
const [d, u] = [Math.max(o[0], s), Math.min(o[1], r)];
|
|
1340
1340
|
if (u > d) {
|
|
1341
|
-
const h = Array.from({ length: 121 }, (
|
|
1341
|
+
const h = Array.from({ length: 121 }, (p, y) => {
|
|
1342
1342
|
const a = d + (u - d) * y / 120;
|
|
1343
|
-
return [a,
|
|
1343
|
+
return [a, ht(n, a)];
|
|
1344
1344
|
}), g = [[d, 0], ...h, [u, 0]].map(e.plane.toScreen);
|
|
1345
1345
|
l.push({ type: "line", id: `${t.id}.shade`, points: g, closed: !0, fill: c, opacity: e.opacity * (t.fillOpacity ?? 0.4) });
|
|
1346
1346
|
}
|
|
1347
1347
|
}
|
|
1348
|
-
return l.push(...
|
|
1348
|
+
return l.push(...pe(t.id, (d) => ht(n, d), s, r, i, (t.width ?? 3.5) * e.plane.scale, e)), l;
|
|
1349
1349
|
}
|
|
1350
|
-
function
|
|
1351
|
-
const n = t.rows ?? 10, i = t.spacing ?? 0.5, s = t.top ?? e.plane.y[1] - i, r = i * 0.9, o = (v, $) => [v * i, s - $ * r], c =
|
|
1350
|
+
function zi(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, o = (v, $) => [v * i, s - $ * r], c = F(e.theme, "grey", e.theme.colors.grey), l = F(e.theme, t.color, e.theme.colors.yellow), d = i * 0.19 * e.plane.unitX, u = [];
|
|
1352
1352
|
for (let v = 0; v < n; v++)
|
|
1353
1353
|
for (let $ = 0; $ <= v; $++) {
|
|
1354
1354
|
const [M, k] = e.plane.toScreen(o($ - v / 2, v));
|
|
1355
1355
|
u.push({ type: "circle", id: `${t.id}.peg.${v}.${$}`, x: M, y: k, r: d * 0.45, fill: c, opacity: e.opacity * e.draw });
|
|
1356
1356
|
}
|
|
1357
|
-
const
|
|
1357
|
+
const f = n + 0.3, h = Math.max(n + 2, (s - e.plane.y[0]) / r - 0.2);
|
|
1358
1358
|
for (let v = 0; v <= n + 1; v++) {
|
|
1359
|
-
const $ = v - (n + 1) / 2, M = V([[o($,
|
|
1359
|
+
const $ = v - (n + 1) / 2, M = V([[o($, f), o($, h)].map(e.plane.toScreen)], e.draw);
|
|
1360
1360
|
for (const k of M) u.push({ type: "line", id: `${t.id}.bin.${v}`, points: k, stroke: c, width: 1.2 * e.plane.scale, opacity: e.opacity * 0.6 });
|
|
1361
1361
|
}
|
|
1362
1362
|
const g = V([[o(-(n + 1) / 2, h), o((n + 1) / 2, h)].map(e.plane.toScreen)], e.draw);
|
|
1363
1363
|
for (const v of g) u.push({ type: "line", id: `${t.id}.floor`, points: v, stroke: c, width: 1.2 * e.plane.scale, opacity: e.opacity * 0.6 });
|
|
1364
|
-
const
|
|
1364
|
+
const p = Math.max(0, P(e.values, t.balls)), y = Math.floor(p), a = t.seed ?? t.id, m = new Array(n + 1).fill(0), b = 2 * d / e.plane.unitY / r, x = (v, $) => ({ x: v - n / 2 + ($ % 2 ? 0.22 : -0.22), depth: h - b * (Math.floor($ / 2) + 0.5) });
|
|
1365
1365
|
for (let v = 0; v < y; v++) {
|
|
1366
|
-
const $ =
|
|
1366
|
+
const $ = xe(tn(a, v, n)), M = x($, m[$]), [k, S] = e.plane.toScreen(o(M.x, M.depth));
|
|
1367
1367
|
m[$]++, u.push({ type: "circle", id: `${t.id}.ball.${v}`, x: k, y: S, r: d, fill: l, opacity: e.opacity });
|
|
1368
1368
|
}
|
|
1369
|
-
const w =
|
|
1369
|
+
const w = p - y;
|
|
1370
1370
|
if (w > 0) {
|
|
1371
|
-
const v =
|
|
1372
|
-
let { x: M, depth: k } =
|
|
1371
|
+
const v = tn(a, y, n), $ = Math.min(1, w / 0.8);
|
|
1372
|
+
let { x: M, depth: k } = mi(v, $);
|
|
1373
1373
|
if (k -= 1, w > 0.8) {
|
|
1374
|
-
const
|
|
1375
|
-
k =
|
|
1374
|
+
const T = ((w - 0.8) / 0.2) ** 2, O = xe(v), z = x(O, m[O]), q = { x: xe(v) - n / 2, depth: n - 1 };
|
|
1375
|
+
k = q.depth + (z.depth - q.depth) * T, M = q.x + (z.x - q.x) * T;
|
|
1376
1376
|
}
|
|
1377
1377
|
const [S, E] = e.plane.toScreen(o(M, k));
|
|
1378
1378
|
u.push({ type: "circle", id: `${t.id}.falling`, x: S, y: E, r: d, fill: l, opacity: e.opacity });
|
|
1379
1379
|
}
|
|
1380
1380
|
return u;
|
|
1381
1381
|
}
|
|
1382
|
-
function
|
|
1383
|
-
const n =
|
|
1384
|
-
const [h, g] = e.plane.toScreen([d, u]),
|
|
1385
|
-
return { type: "circle", id: `${t.id}.${
|
|
1382
|
+
function ji(t, e) {
|
|
1383
|
+
const n = In(t, e), i = Mn(n, t.seed ?? t.id, le(P(e.values, t.count))), s = F(e.theme, t.color, e.theme.colors.blue), r = F(e.theme, t.insideColor, e.theme.colors.yellow), o = t.inside ? ct(t.inside) : void 0, c = (t.radius ?? 3) * e.plane.scale, l = i.map(([d, u], f) => {
|
|
1384
|
+
const [h, g] = e.plane.toScreen([d, u]), p = o ? it(o, { ...e.scope, x: d, y: u }) <= 0 : !1;
|
|
1385
|
+
return { type: "circle", id: `${t.id}.${f}`, x: h, y: g, r: c, fill: p ? r : s, opacity: e.opacity * e.draw * 0.85 };
|
|
1386
1386
|
});
|
|
1387
1387
|
if (t.fit) {
|
|
1388
|
-
const d =
|
|
1388
|
+
const d = xn(i);
|
|
1389
1389
|
if (d) {
|
|
1390
|
-
const [u,
|
|
1391
|
-
l.push({ type: "line", id: `${t.id}.fit`, points: [[u, d.slope * u + d.intercept], [
|
|
1390
|
+
const [u, f] = e.plane.x;
|
|
1391
|
+
l.push({ type: "line", id: `${t.id}.fit`, points: [[u, d.slope * u + d.intercept], [f, d.slope * f + d.intercept]].map(e.plane.toScreen), stroke: F(e.theme, "red", e.theme.colors.red), width: 3 * e.plane.scale, opacity: e.opacity });
|
|
1392
1392
|
}
|
|
1393
1393
|
}
|
|
1394
1394
|
return l;
|
|
1395
1395
|
}
|
|
1396
|
-
function
|
|
1396
|
+
function In(t, e) {
|
|
1397
1397
|
const n = t.points;
|
|
1398
|
-
return n.kind === "uniform" ? n : { kind: "linear", slope:
|
|
1398
|
+
return n.kind === "uniform" ? n : { kind: "linear", slope: P(e.values, n.slope), intercept: P(e.values, n.intercept), noise: P(e.values, n.noise), x: n.x };
|
|
1399
1399
|
}
|
|
1400
|
-
function
|
|
1401
|
-
const n =
|
|
1400
|
+
function Di(t, e) {
|
|
1401
|
+
const n = P(e.values, t.prior), i = P(e.values, t.truePositive), s = P(e.values, t.falsePositive), r = e.plane.x[1] - e.plane.x[0], o = e.plane.y[1] - e.plane.y[0], [c, l] = t.size ?? [r * 0.8, o * 0.7], [d, u] = t.at ?? [e.plane.x[0] + r * 0.1, e.plane.y[0] + o * 0.08], f = d + c * Math.min(1, Math.max(0, n)), h = F(e.theme, t.color, e.theme.colors.yellow), g = F(e.theme, "red", e.theme.colors.red), p = F(e.theme, "grey", e.theme.colors.grey), y = e.opacity * e.draw, a = (v, $, M, k, S, E, T) => ({
|
|
1402
1402
|
type: "line",
|
|
1403
1403
|
id: `${t.id}.${v}`,
|
|
1404
|
-
points:
|
|
1404
|
+
points: Ue(e, $, M, k, S),
|
|
1405
1405
|
closed: !0,
|
|
1406
1406
|
fill: E,
|
|
1407
1407
|
stroke: e.theme.background,
|
|
1408
1408
|
width: 2 * e.plane.scale,
|
|
1409
|
-
opacity: y *
|
|
1409
|
+
opacity: y * T
|
|
1410
1410
|
}), m = u + l, b = m - l * Math.min(1, Math.max(0, i)), x = m - l * Math.min(1, Math.max(0, s)), w = [
|
|
1411
|
-
a("tp", d, b,
|
|
1412
|
-
a("fn", d, u,
|
|
1413
|
-
a("fp",
|
|
1414
|
-
a("tn",
|
|
1411
|
+
a("tp", d, b, f, m, h, 0.85),
|
|
1412
|
+
a("fn", d, u, f, b, p, 0.35),
|
|
1413
|
+
a("fp", f, x, d + c, m, g, 0.8),
|
|
1414
|
+
a("tn", f, u, d + c, x, p, 0.2)
|
|
1415
1415
|
];
|
|
1416
1416
|
if (t.labels !== !1 && e.draw >= 1) {
|
|
1417
1417
|
const v = 20 * e.plane.scale, $ = (M, k, S, E) => {
|
|
1418
|
-
const [
|
|
1419
|
-
w.push(...X(U(k, { values: e.scope, style: "inline" }), { x:
|
|
1418
|
+
const [T, O] = e.plane.toScreen(S);
|
|
1419
|
+
w.push(...X(U(k, { values: e.scope, style: "inline" }), { x: T, y: O, size: v, color: E, opacity: e.opacity, idPrefix: `${t.id}.label.${M}.` }));
|
|
1420
1420
|
};
|
|
1421
1421
|
$("prior", `\\text{has it: } \\val{${t.id}.prior:3}`, [d + c / 2, u - o * 0.04], e.theme.ink), $("tp", `\\text{has it, tests positive: } \\val{${t.id}.truePositive:3}`, [d + c / 2, u - o * 0.09], h), $("fp", `\\text{does not, tests positive: } \\val{${t.id}.falsePositive:3}`, [d + c / 2, u - o * 0.14], g), $("posterior", `P(\\text{has it} \\mid +) = \\val{${t.id}.posterior:3}`, [d + c / 2, u + l + o * 0.05], h);
|
|
1422
1422
|
}
|
|
1423
1423
|
return w;
|
|
1424
1424
|
}
|
|
1425
|
-
const
|
|
1426
|
-
function
|
|
1425
|
+
const on = ["bfs", "dfs", "dijkstra"];
|
|
1426
|
+
function je(t, e, n) {
|
|
1427
1427
|
const i = new Map(t.map((r, o) => [r, o])), s = new Map(t.map((r) => [r, []]));
|
|
1428
1428
|
for (const r of e) {
|
|
1429
1429
|
const o = r.weight ?? 1;
|
|
@@ -1432,7 +1432,7 @@ function Oe(t, e, n) {
|
|
|
1432
1432
|
for (const r of s.values()) r.sort((o, c) => (i.get(o.to) ?? 0) - (i.get(c.to) ?? 0));
|
|
1433
1433
|
return s;
|
|
1434
1434
|
}
|
|
1435
|
-
function
|
|
1435
|
+
function _i(t, e) {
|
|
1436
1436
|
const n = [], i = /* @__PURE__ */ new Set([t]), s = [{ node: t }];
|
|
1437
1437
|
for (; s.length > 0; ) {
|
|
1438
1438
|
const { node: r, parent: o } = s.shift();
|
|
@@ -1442,7 +1442,7 @@ function Li(t, e) {
|
|
|
1442
1442
|
}
|
|
1443
1443
|
return n;
|
|
1444
1444
|
}
|
|
1445
|
-
function
|
|
1445
|
+
function Ri(t, e) {
|
|
1446
1446
|
const n = [], i = /* @__PURE__ */ new Set(), s = [{ node: t }];
|
|
1447
1447
|
for (; s.length > 0; ) {
|
|
1448
1448
|
const { node: r, parent: o } = s.pop();
|
|
@@ -1454,7 +1454,7 @@ function qi(t, e) {
|
|
|
1454
1454
|
}
|
|
1455
1455
|
return n;
|
|
1456
1456
|
}
|
|
1457
|
-
function
|
|
1457
|
+
function Bi(t, e, n) {
|
|
1458
1458
|
const i = [], s = Object.fromEntries(e.map((l) => [l, 1 / 0])), r = {}, o = new Map(e.map((l, d) => [l, d]));
|
|
1459
1459
|
s[t] = 0;
|
|
1460
1460
|
const c = /* @__PURE__ */ new Set();
|
|
@@ -1464,41 +1464,41 @@ function Ci(t, e, n) {
|
|
|
1464
1464
|
c.has(u) || s[u] === 1 / 0 || (l === void 0 || s[u] < s[l] || s[u] === s[l] && o.get(u) < o.get(l)) && (l = u);
|
|
1465
1465
|
if (l === void 0) break;
|
|
1466
1466
|
c.add(l);
|
|
1467
|
-
for (const { to: u, weight:
|
|
1468
|
-
c.has(u) || s[l] +
|
|
1469
|
-
const d = e.filter((u) => !c.has(u) && s[u] < 1 / 0).sort((u,
|
|
1467
|
+
for (const { to: u, weight: f } of n.get(l) ?? [])
|
|
1468
|
+
c.has(u) || s[l] + f < s[u] && (s[u] = s[l] + f, r[u] = l);
|
|
1469
|
+
const d = e.filter((u) => !c.has(u) && s[u] < 1 / 0).sort((u, f) => s[u] - s[f]);
|
|
1470
1470
|
i.push({ node: l, ...r[l] !== void 0 ? { parent: r[l] } : {}, frontier: d, distances: { ...s } });
|
|
1471
1471
|
}
|
|
1472
1472
|
return i;
|
|
1473
1473
|
}
|
|
1474
|
-
const
|
|
1475
|
-
function
|
|
1476
|
-
const r = JSON.stringify([t, e, n, i, s]), o =
|
|
1474
|
+
const Jt = /* @__PURE__ */ new Map();
|
|
1475
|
+
function Vi(t, e, n, i, s = !1) {
|
|
1476
|
+
const r = JSON.stringify([t, e, n, i, s]), o = Jt.get(r);
|
|
1477
1477
|
if (o) return o;
|
|
1478
1478
|
if (!n.includes(e)) throw new Error(`graph search: no node "${e}"`);
|
|
1479
|
-
const c =
|
|
1480
|
-
return
|
|
1479
|
+
const c = je(n, i, s), l = t === "bfs" ? _i(e, c) : t === "dfs" ? Ri(e, c) : Bi(e, n, c);
|
|
1480
|
+
return Jt.size > 64 && Jt.clear(), Jt.set(r, l), l;
|
|
1481
1481
|
}
|
|
1482
|
-
function
|
|
1483
|
-
const i =
|
|
1482
|
+
function Hi(t, e, n) {
|
|
1483
|
+
const i = je(e, n, !0), s = je(e, n, !1), r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([t]), c = [t];
|
|
1484
1484
|
for (; c.length; ) {
|
|
1485
|
-
const g = c.shift(),
|
|
1486
|
-
|
|
1485
|
+
const g = c.shift(), p = (i.get(g)?.length ? i.get(g) : s.get(g) ?? []).map((y) => y.to).filter((y) => !o.has(y));
|
|
1486
|
+
p.forEach((y) => o.add(y)), r.set(g, p), c.push(...p);
|
|
1487
1487
|
}
|
|
1488
1488
|
const l = /* @__PURE__ */ new Map();
|
|
1489
1489
|
let d = 0;
|
|
1490
|
-
const u = (g,
|
|
1491
|
-
const y = r.get(g) ?? [], a = y.length === 0 ? d++ : y.map((m) => u(m,
|
|
1492
|
-
return l.set(g, [a,
|
|
1490
|
+
const u = (g, p) => {
|
|
1491
|
+
const y = r.get(g) ?? [], a = y.length === 0 ? d++ : y.map((m) => u(m, p + 1)).reduce((m, b, x, w) => m + b / w.length, 0);
|
|
1492
|
+
return l.set(g, [a, p === 0 ? 0 : -p]), a;
|
|
1493
1493
|
};
|
|
1494
1494
|
u(t, 0);
|
|
1495
|
-
const
|
|
1496
|
-
for (const [g, [
|
|
1495
|
+
const f = [...l.values()].map(([g]) => g), h = (Math.min(...f) + Math.max(...f)) / 2;
|
|
1496
|
+
for (const [g, [p, y]] of l) l.set(g, [p - h, y]);
|
|
1497
1497
|
return l;
|
|
1498
1498
|
}
|
|
1499
|
-
const
|
|
1500
|
-
function
|
|
1501
|
-
const e = [...t].map((d) =>
|
|
1499
|
+
const Ui = { "∪": "|", "∩": "&", "∖": "-", "△": "^", "¬": "!", "\\": "-" };
|
|
1500
|
+
function Pn(t) {
|
|
1501
|
+
const e = [...t].map((d) => Ui[d] ?? d).join("");
|
|
1502
1502
|
let n = 0;
|
|
1503
1503
|
const i = () => {
|
|
1504
1504
|
for (; /\s/.test(e[n] ?? ""); ) n++;
|
|
@@ -1531,63 +1531,63 @@ function An(t) {
|
|
|
1531
1531
|
}, l = c();
|
|
1532
1532
|
return i(), n < e.length && s(`unexpected "${e[n]}"`), l;
|
|
1533
1533
|
}
|
|
1534
|
-
function
|
|
1535
|
-
return t.type === "set" ? [t.name] : t.type === "not" ?
|
|
1534
|
+
function se(t) {
|
|
1535
|
+
return t.type === "set" ? [t.name] : t.type === "not" ? se(t.operand) : [.../* @__PURE__ */ new Set([...se(t.left), ...se(t.right)])];
|
|
1536
1536
|
}
|
|
1537
|
-
function
|
|
1537
|
+
function re(t, e) {
|
|
1538
1538
|
switch (t.type) {
|
|
1539
1539
|
case "set":
|
|
1540
1540
|
return e.has(t.name);
|
|
1541
1541
|
case "not":
|
|
1542
|
-
return !
|
|
1542
|
+
return !re(t.operand, e);
|
|
1543
1543
|
case "op": {
|
|
1544
|
-
const n =
|
|
1544
|
+
const n = re(t.left, e), i = re(t.right, e);
|
|
1545
1545
|
return t.operator === "&" ? n && i : t.operator === "|" ? n || i : t.operator === "-" ? n && !i : n !== i;
|
|
1546
1546
|
}
|
|
1547
1547
|
}
|
|
1548
1548
|
}
|
|
1549
|
-
function
|
|
1549
|
+
function Wi(t, e) {
|
|
1550
1550
|
const n = [];
|
|
1551
1551
|
for (let i = 0; i < 1 << e.length; i++) {
|
|
1552
1552
|
const s = e.filter((r, o) => i & 1 << o);
|
|
1553
|
-
|
|
1553
|
+
re(t, new Set(s)) && n.push(s);
|
|
1554
1554
|
}
|
|
1555
1555
|
return n;
|
|
1556
1556
|
}
|
|
1557
|
-
function
|
|
1557
|
+
function Fn(t, e, n, i, s = 64) {
|
|
1558
1558
|
return Array.from({ length: s }, (r, o) => {
|
|
1559
1559
|
const c = o / s * 2 * Math.PI;
|
|
1560
1560
|
return [t + n * Math.cos(c), e + i * Math.sin(c)];
|
|
1561
1561
|
});
|
|
1562
1562
|
}
|
|
1563
|
-
function
|
|
1563
|
+
function ye(t) {
|
|
1564
1564
|
return t.edges.map((e) => Array.isArray(e) ? { from: e[0], to: e[1], ...e[2] !== void 0 ? { weight: e[2] } : {} } : e);
|
|
1565
1565
|
}
|
|
1566
|
-
function
|
|
1566
|
+
function Ln(t) {
|
|
1567
1567
|
const e = /* @__PURE__ */ new Map();
|
|
1568
1568
|
if (t.tree) {
|
|
1569
1569
|
const [n, i] = t.tree.spacing ?? [1.2, 1.2], [s, r] = t.tree.at ?? [0, 0];
|
|
1570
|
-
for (const [o, [c, l]] of
|
|
1570
|
+
for (const [o, [c, l]] of Hi(t.tree.root, t.nodes.map((d) => d.id), ye(t))) e.set(o, [s + c * n, r + l * i]);
|
|
1571
1571
|
}
|
|
1572
1572
|
for (const n of t.nodes) n.at && e.set(n.id, n.at);
|
|
1573
1573
|
return e;
|
|
1574
1574
|
}
|
|
1575
|
-
function
|
|
1575
|
+
function Cn(t, e) {
|
|
1576
1576
|
if (!t.search) return;
|
|
1577
|
-
const n =
|
|
1577
|
+
const n = Vi(t.search.kind, t.search.start, t.nodes.map((r) => r.id), ye(t), t.directed), i = t.step === void 0 ? n.length : Math.min(n.length, Math.max(0, P(e, t.step))), s = Math.floor(i);
|
|
1578
1578
|
return { events: n, done: s, partial: s < n.length ? i - s : 0 };
|
|
1579
1579
|
}
|
|
1580
|
-
const
|
|
1581
|
-
function
|
|
1582
|
-
const { plane: n, theme: i } = e, s =
|
|
1583
|
-
const E = w(k),
|
|
1584
|
-
return [[E[0] +
|
|
1580
|
+
const Gi = { bfs: "queue", dfs: "stack", dijkstra: "open" };
|
|
1581
|
+
function Xi(t, e) {
|
|
1582
|
+
const { plane: n, theme: i } = e, s = Ln(t), r = ye(t), o = Cn(t, e.values), c = (t.radius ?? 18) * n.scale, l = F(i, t.color, i.ink), d = F(i, "grey", i.colors.grey), u = F(i, "yellow", i.colors.yellow), f = F(i, "blue", i.colors.blue), h = [], g = o ? o.events.slice(0, o.done) : [], p = new Set(g.map((k) => k.node)), y = new Set(g.filter((k) => k.parent !== void 0).map((k) => `${k.parent}>${k.node}`)), a = g.at(-1), m = new Set(a?.frontier ?? []), b = o && o.partial > 0 ? o.events[o.done] : void 0, x = (k, S) => y.has(`${k}>${S}`) || !t.directed && y.has(`${S}>${k}`), w = (k) => n.toScreen(s.get(k) ?? [0, 0]), v = (k, S) => {
|
|
1583
|
+
const E = w(k), T = w(S), [O, z] = Lt([T[0] - E[0], T[1] - E[1]]);
|
|
1584
|
+
return [[E[0] + O * c, E[1] + z * c], [T[0] - O * c, T[1] - z * c]];
|
|
1585
1585
|
}, $ = t.weights ?? t.search?.kind === "dijkstra";
|
|
1586
1586
|
if (r.forEach((k, S) => {
|
|
1587
|
-
const [E,
|
|
1588
|
-
if (A && (h.push(t.directed ? { type: "arrow", id: `${t.id}.edge.${S}`, points: A, stroke:
|
|
1589
|
-
const
|
|
1590
|
-
h.push({ type: "text", id: `${t.id}.weight.${S}`, text: String(k.weight ?? 1), x:
|
|
1587
|
+
const [E, T] = v(k.from, k.to), O = x(k.from, k.to), z = O ? u : d, q = (O ? 4 : 2) * n.scale, [A] = V([[E, T]], e.draw);
|
|
1588
|
+
if (A && (h.push(t.directed ? { type: "arrow", id: `${t.id}.edge.${S}`, points: A, stroke: z, width: q, head: 11 * n.scale, opacity: e.opacity } : { type: "line", id: `${t.id}.edge.${S}`, points: A, stroke: z, width: q, opacity: e.opacity }), $ && e.draw >= 1)) {
|
|
1589
|
+
const N = [(E[0] + T[0]) / 2, (E[1] + T[1]) / 2], [I, L] = Lt([-(T[1] - E[1]), T[0] - E[0]]), C = 14 * n.scale;
|
|
1590
|
+
h.push({ type: "text", id: `${t.id}.weight.${S}`, text: String(k.weight ?? 1), x: N[0] + I * C * 0.9, y: N[1] + L * C * 0.9 + C * 0.35, size: C, font: pt, color: O ? u : d, align: "center", opacity: e.opacity });
|
|
1591
1591
|
}
|
|
1592
1592
|
}), b?.parent !== void 0) {
|
|
1593
1593
|
const [k, S] = v(b.parent, b.node), [E] = V([[k, S]], b.parent ? o.partial : 1);
|
|
@@ -1595,36 +1595,36 @@ function Bi(t, e) {
|
|
|
1595
1595
|
}
|
|
1596
1596
|
const M = a?.distances;
|
|
1597
1597
|
for (const k of t.nodes) {
|
|
1598
|
-
const [S, E] = w(k.id),
|
|
1599
|
-
h.push({ type: "circle", id: `${t.id}.node.${k.id}`, x: S, y: E, r: c, fill:
|
|
1600
|
-
const A =
|
|
1598
|
+
const [S, E] = w(k.id), T = p.has(k.id), O = b?.node === k.id && o.partial >= 0.999, z = !T && m.has(k.id), q = T || O ? u : z ? f : i.background;
|
|
1599
|
+
h.push({ type: "circle", id: `${t.id}.node.${k.id}`, x: S, y: E, r: c, fill: q, stroke: T ? u : z ? f : l, width: 2 * n.scale, opacity: e.opacity * Math.min(1, e.draw * 1.5) }), a?.node === k.id && h.push({ type: "circle", id: `${t.id}.current`, x: S, y: E, r: c * 1.35, stroke: u, width: 2 * n.scale, opacity: e.opacity * 0.8 });
|
|
1600
|
+
const A = T || z || O ? i.background : l;
|
|
1601
1601
|
if (h.push(...X(U(k.label ?? k.id, { style: "inline" }), { x: S, y: E, size: c * 0.95, color: A, opacity: e.opacity * e.draw, idPrefix: `${t.id}.label.${k.id}.` })), M) {
|
|
1602
|
-
const
|
|
1603
|
-
h.push({ type: "text", id: `${t.id}.distance.${k.id}`, text:
|
|
1602
|
+
const N = M[k.id], I = 13 * n.scale;
|
|
1603
|
+
h.push({ type: "text", id: `${t.id}.distance.${k.id}`, text: N === 1 / 0 ? "∞" : String(Math.round(N * 100) / 100), x: S, y: E + c + I * 1.15, size: I, font: pt, color: f, align: "center", opacity: e.opacity });
|
|
1604
1604
|
}
|
|
1605
1605
|
}
|
|
1606
1606
|
if (t.frontier && t.search && e.draw >= 1) {
|
|
1607
|
-
const [k, S] = t.frontier, E = 16 * n.scale,
|
|
1608
|
-
h.push({ type: "text", id: `${t.id}.frontier.name`, text: `${
|
|
1609
|
-
const
|
|
1610
|
-
[...m].forEach((
|
|
1611
|
-
const A = k + E * 4 +
|
|
1612
|
-
h.push({ type: "line", id: `${t.id}.frontier.box.${
|
|
1607
|
+
const [k, S] = t.frontier, E = 16 * n.scale, T = Gi[t.search.kind];
|
|
1608
|
+
h.push({ type: "text", id: `${t.id}.frontier.name`, text: `${T}:`, x: k, y: S + E * 0.35, size: E, font: pt, color: d, align: "left", opacity: e.opacity });
|
|
1609
|
+
const O = E * 1.9;
|
|
1610
|
+
[...m].forEach((z, q) => {
|
|
1611
|
+
const A = k + E * 4 + q * (O + E * 0.4), N = t.nodes.find((I) => I.id === z)?.label ?? z;
|
|
1612
|
+
h.push({ type: "line", id: `${t.id}.frontier.box.${q}`, points: [[A, S - O / 2], [A + O, S - O / 2], [A + O, S + O / 2], [A, S + O / 2]], closed: !0, fill: f, opacity: e.opacity * 0.9 }), h.push(...X(U(N, { style: "inline" }), { x: A + O / 2, y: S, size: E * 1.05, color: i.background, opacity: e.opacity, idPrefix: `${t.id}.frontier.label.${q}.` }));
|
|
1613
1613
|
});
|
|
1614
1614
|
}
|
|
1615
1615
|
return h;
|
|
1616
1616
|
}
|
|
1617
|
-
function
|
|
1617
|
+
function Yi(t) {
|
|
1618
1618
|
return t === 2 ? [[-0.6, 0], [0.6, 0]] : [0, 1, 2].map((e) => {
|
|
1619
1619
|
const n = Math.PI / 2 + e * 2 * Math.PI / 3;
|
|
1620
1620
|
return [0.62 * Math.cos(n), 0.62 * Math.sin(n) - 0.1];
|
|
1621
1621
|
});
|
|
1622
1622
|
}
|
|
1623
|
-
function
|
|
1624
|
-
const { plane: n, theme: i } = e, s = t.radius ?? 1.5, [r, o] = t.at ?? [0, 0], c =
|
|
1623
|
+
function Zi(t, e) {
|
|
1624
|
+
const { plane: n, theme: i } = e, s = t.radius ?? 1.5, [r, o] = t.at ?? [0, 0], c = Yi(t.sets.length).map(([a, m]) => [r + a * s, o + m * s]), l = c.map(([a, m]) => Fn(a, m, s, s, 96).map(n.toScreen)), d = c.map(([a]) => a), u = c.map(([, a]) => a), f = s * 0.35, h = [[Math.min(...d) - s - f, Math.min(...u) - s - f], [Math.max(...d) + s + f, Math.min(...u) - s - f], [Math.max(...d) + s + f, Math.max(...u) + s + f], [Math.min(...d) - s - f, Math.max(...u) + s + f]].map(n.toScreen), g = [], p = t.sets.map((a) => a.id);
|
|
1625
1625
|
if (t.highlight) {
|
|
1626
|
-
const a =
|
|
1627
|
-
|
|
1626
|
+
const a = F(i, t.highlightColor, i.colors.yellow);
|
|
1627
|
+
Wi(Pn(t.highlight), p).forEach((m, b) => {
|
|
1628
1628
|
g.push({
|
|
1629
1629
|
type: "line",
|
|
1630
1630
|
id: `${t.id}.region.${b}`,
|
|
@@ -1632,70 +1632,70 @@ function Hi(t, e) {
|
|
|
1632
1632
|
closed: !0,
|
|
1633
1633
|
fill: a,
|
|
1634
1634
|
opacity: e.opacity * e.draw * 0.55,
|
|
1635
|
-
clip:
|
|
1635
|
+
clip: p.map((x, w) => ({ points: l[w], outside: !m.includes(x) }))
|
|
1636
1636
|
});
|
|
1637
1637
|
});
|
|
1638
1638
|
}
|
|
1639
1639
|
if (t.universe !== !1) {
|
|
1640
|
-
g.push({ type: "line", id: `${t.id}.universe`, points: h, closed: !0, stroke:
|
|
1640
|
+
g.push({ type: "line", id: `${t.id}.universe`, points: h, closed: !0, stroke: F(i, "grey", i.colors.grey), width: 2 * n.scale, opacity: e.opacity });
|
|
1641
1641
|
const [a, m] = h[3];
|
|
1642
|
-
g.push(...X(U("U", { style: "inline" }), { x: a + 16 * n.scale, y: m + 20 * n.scale, size: 22 * n.scale, color:
|
|
1642
|
+
g.push(...X(U("U", { style: "inline" }), { x: a + 16 * n.scale, y: m + 20 * n.scale, size: 22 * n.scale, color: F(i, "grey", i.colors.grey), opacity: e.opacity, idPrefix: `${t.id}.universe.` }));
|
|
1643
1643
|
}
|
|
1644
1644
|
const y = ["blue", "red", "green"];
|
|
1645
1645
|
return t.sets.forEach((a, m) => {
|
|
1646
|
-
const b =
|
|
1646
|
+
const b = F(i, a.color ?? y[m], i.colors.blue);
|
|
1647
1647
|
for (const M of V([[...l[m], l[m][0]]], e.draw))
|
|
1648
1648
|
g.push({ type: "line", id: `${t.id}.set.${a.id}`, points: M, stroke: b, width: 3 * n.scale, opacity: e.opacity });
|
|
1649
|
-
const [x, w] =
|
|
1649
|
+
const [x, w] = Lt([c[m][0] - r || (m === 0 ? -1 : 1), c[m][1] - o]), [v, $] = n.toScreen([c[m][0] + x * s * 0.78, c[m][1] + w * s * 0.78 + (t.sets.length === 2 ? s * 0.85 : 0)]);
|
|
1650
1650
|
g.push(...X(U(a.label ?? a.id, { style: "inline" }), { x: v, y: $, size: 26 * n.scale, color: b, opacity: e.opacity * e.draw, idPrefix: `${t.id}.label.${a.id}.` }));
|
|
1651
1651
|
}), g;
|
|
1652
1652
|
}
|
|
1653
|
-
const
|
|
1654
|
-
function
|
|
1655
|
-
const { plane: n, theme: i } = e, s = t.modulus, [r, o] = t.at ?? [0, 0], c = t.radius ?? 2, l =
|
|
1656
|
-
const a = Math.PI / 2 -
|
|
1653
|
+
const qn = (t, e) => (Math.round(t) % e + e) % e;
|
|
1654
|
+
function Ji(t, e) {
|
|
1655
|
+
const { plane: n, theme: i } = e, s = t.modulus, [r, o] = t.at ?? [0, 0], c = t.radius ?? 2, l = P(e.values, t.value), d = F(i, t.color, i.ink), u = F(i, "yellow", i.colors.yellow), f = (p, y) => {
|
|
1656
|
+
const a = Math.PI / 2 - p / s * 2 * Math.PI;
|
|
1657
1657
|
return n.toScreen([r + Math.cos(a) * c * y, o + Math.sin(a) * c * y]);
|
|
1658
1658
|
}, h = [];
|
|
1659
|
-
for (const
|
|
1660
|
-
h.push({ type: "line", id: `${t.id}.face`, points:
|
|
1661
|
-
const g =
|
|
1662
|
-
for (let
|
|
1663
|
-
const [y, a] = p
|
|
1664
|
-
h.push({ type: "line", id: `${t.id}.tick.${
|
|
1659
|
+
for (const p of V([Fn(r, o, c, c, 120).map(n.toScreen)], e.draw))
|
|
1660
|
+
h.push({ type: "line", id: `${t.id}.face`, points: p, stroke: d, width: 3 * n.scale, opacity: e.opacity });
|
|
1661
|
+
const g = qn(l, s);
|
|
1662
|
+
for (let p = 0; p < s; p++) {
|
|
1663
|
+
const [y, a] = f(p, 0.8), m = Math.min(26, 220 / s + 8) * n.scale;
|
|
1664
|
+
h.push({ type: "line", id: `${t.id}.tick.${p}`, points: [f(p, 0.95), f(p, 1)], stroke: d, width: 2 * n.scale, opacity: e.opacity * e.draw }), h.push({ type: "text", id: `${t.id}.hour.${p}`, text: String(p), x: y, y: a + m * 0.35, size: m, font: pt, color: p === g ? u : d, align: "center", opacity: e.opacity * e.draw });
|
|
1665
1665
|
}
|
|
1666
1666
|
if (e.draw >= 1) {
|
|
1667
|
-
const
|
|
1668
|
-
h.push({ type: "arrow", id: `${t.id}.hand`, points: [
|
|
1667
|
+
const p = n.toScreen([r, o]);
|
|
1668
|
+
h.push({ type: "arrow", id: `${t.id}.hand`, points: [p, f(l, 0.62)], stroke: u, width: 5 * n.scale, head: 16 * n.scale, opacity: e.opacity }), h.push({ type: "circle", id: `${t.id}.pin`, x: p[0], y: p[1], r: 6 * n.scale, fill: u, opacity: e.opacity });
|
|
1669
1669
|
}
|
|
1670
1670
|
return h;
|
|
1671
1671
|
}
|
|
1672
|
-
const
|
|
1673
|
-
function
|
|
1674
|
-
const n =
|
|
1672
|
+
const an = ["sigmoid", "tanh", "relu"], Ki = (t, e) => t === "sigmoid" ? 1 / (1 + Math.exp(-e)) : t === "tanh" ? Math.tanh(e) : Math.max(0, e);
|
|
1673
|
+
function Qi(t, e) {
|
|
1674
|
+
const n = xt(typeof e == "number" ? e : gt(e)), i = [], s = [];
|
|
1675
1675
|
for (let r = 0; r < t.length - 1; r++) {
|
|
1676
1676
|
const o = 1.6 / Math.sqrt(t[r]);
|
|
1677
|
-
i.push(Array.from({ length: t[r + 1] }, () => Array.from({ length: t[r] }, () =>
|
|
1677
|
+
i.push(Array.from({ length: t[r + 1] }, () => Array.from({ length: t[r] }, () => yt(n) * o))), s.push(Array.from({ length: t[r + 1] }, () => yt(n) * 0.3));
|
|
1678
1678
|
}
|
|
1679
1679
|
return { layers: t, weights: i, biases: s };
|
|
1680
1680
|
}
|
|
1681
|
-
function
|
|
1681
|
+
function ts(t, e, n) {
|
|
1682
1682
|
const i = [e.slice(0, t.layers[0])];
|
|
1683
1683
|
for (let s = 0; s < t.weights.length; s++) {
|
|
1684
1684
|
const r = i[s];
|
|
1685
|
-
i.push(t.weights[s].map((o, c) =>
|
|
1685
|
+
i.push(t.weights[s].map((o, c) => Ki(n, o.reduce((l, d, u) => l + d * (r[u] ?? 0), t.biases[s][c]))));
|
|
1686
1686
|
}
|
|
1687
1687
|
return i;
|
|
1688
1688
|
}
|
|
1689
|
-
const
|
|
1689
|
+
const Kt = ["viridis", "heat", "diverging"], es = {
|
|
1690
1690
|
viridis: [[68, 1, 84], [59, 82, 139], [33, 145, 140], [94, 201, 98], [253, 231, 37]],
|
|
1691
1691
|
heat: [[20, 12, 30], [120, 28, 60], [214, 70, 40], [250, 160, 50], [252, 240, 180]],
|
|
1692
1692
|
diverging: [[49, 99, 185], [140, 180, 225], [245, 245, 245], [235, 140, 120], [190, 40, 50]]
|
|
1693
1693
|
};
|
|
1694
|
-
function
|
|
1695
|
-
const n =
|
|
1696
|
-
return
|
|
1694
|
+
function me(t, e) {
|
|
1695
|
+
const n = es[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;
|
|
1696
|
+
return `#${n[s].map((o, c) => Math.round(o + (n[s + 1][c] - o) * r).toString(16).padStart(2, "0")).join("")}`;
|
|
1697
1697
|
}
|
|
1698
|
-
function
|
|
1698
|
+
function cn(t) {
|
|
1699
1699
|
const e = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());
|
|
1700
1700
|
if (e) {
|
|
1701
1701
|
const i = e[1].length === 3 ? [...e[1]].map((s) => s + s).join("") : e[1];
|
|
@@ -1704,48 +1704,48 @@ function nn(t) {
|
|
|
1704
1704
|
const n = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i.exec(t.trim());
|
|
1705
1705
|
return n ? [Number(n[1]), Number(n[2]), Number(n[3])] : void 0;
|
|
1706
1706
|
}
|
|
1707
|
-
function
|
|
1708
|
-
const i =
|
|
1707
|
+
function zn(t, e, n) {
|
|
1708
|
+
const i = cn(t), s = cn(e);
|
|
1709
1709
|
if (!i || !s) return t;
|
|
1710
1710
|
const r = Math.min(1, Math.max(0, n)), [o, c, l] = i.map((d, u) => Math.round(s[u] + (d - s[u]) * r));
|
|
1711
1711
|
return `rgb(${o}, ${c}, ${l})`;
|
|
1712
1712
|
}
|
|
1713
|
-
function
|
|
1713
|
+
function ns(t, e, n, i, s, r) {
|
|
1714
1714
|
r += 1e-9 * Math.max(1, Math.abs(r));
|
|
1715
|
-
const o = [], c = t.length, l = t[0]?.length ?? 0, d = (
|
|
1716
|
-
(h >
|
|
1717
|
-
const y = t[h][
|
|
1718
|
-
return [e + (
|
|
1715
|
+
const o = [], c = t.length, l = t[0]?.length ?? 0, d = (f, h, g, p) => {
|
|
1716
|
+
(h > p || h === p && f > g) && ([f, h, g, p] = [g, p, f, h]);
|
|
1717
|
+
const y = t[h][f] - r, a = t[p][g] - r, m = y === a ? 0.5 : y / (y - a);
|
|
1718
|
+
return [e + (f + (g - f) * m) * i, n + (h + (p - h) * m) * s];
|
|
1719
1719
|
};
|
|
1720
|
-
for (let
|
|
1720
|
+
for (let f = 0; f < c - 1; f++)
|
|
1721
1721
|
for (let h = 0; h < l - 1; h++) {
|
|
1722
|
-
const g = [t[
|
|
1722
|
+
const g = [t[f][h], t[f][h + 1], t[f + 1][h + 1], t[f + 1][h]];
|
|
1723
1723
|
if (g.some((a) => !Number.isFinite(a))) continue;
|
|
1724
|
-
const
|
|
1725
|
-
[0, 1, h,
|
|
1726
|
-
[1, 2, h + 1,
|
|
1727
|
-
[2, 3, h + 1,
|
|
1728
|
-
[3, 0, h,
|
|
1724
|
+
const p = [], y = [
|
|
1725
|
+
[0, 1, h, f, h + 1, f],
|
|
1726
|
+
[1, 2, h + 1, f, h + 1, f + 1],
|
|
1727
|
+
[2, 3, h + 1, f + 1, h, f + 1],
|
|
1728
|
+
[3, 0, h, f + 1, h, f]
|
|
1729
1729
|
];
|
|
1730
1730
|
for (const [a, m, b, x, w, v] of y)
|
|
1731
|
-
g[a] >= r != g[m] >= r &&
|
|
1732
|
-
if (
|
|
1733
|
-
else if (
|
|
1731
|
+
g[a] >= r != g[m] >= r && p.push(d(b, x, w, v));
|
|
1732
|
+
if (p.length === 2) o.push([p[0], p[1]]);
|
|
1733
|
+
else if (p.length === 4) {
|
|
1734
1734
|
const a = (g[0] + g[1] + g[2] + g[3]) / 4 >= r, m = g[0] >= r;
|
|
1735
|
-
a === m ? o.push([
|
|
1735
|
+
a === m ? o.push([p[0], p[1]], [p[2], p[3]]) : o.push([p[0], p[3]], [p[1], p[2]]);
|
|
1736
1736
|
}
|
|
1737
1737
|
}
|
|
1738
1738
|
const u = 1e-6 * Math.min(Math.abs(i), Math.abs(s));
|
|
1739
|
-
return
|
|
1739
|
+
return is(o.filter(([f, h]) => Math.hypot(h[0] - f[0], h[1] - f[1]) > u));
|
|
1740
1740
|
}
|
|
1741
|
-
function
|
|
1741
|
+
function is(t) {
|
|
1742
1742
|
const e = ([o, c]) => `${Math.round(o * 1e6)},${Math.round(c * 1e6)}`, n = /* @__PURE__ */ new Map();
|
|
1743
1743
|
t.forEach(([o, c], l) => {
|
|
1744
1744
|
for (const d of [o, c]) n.set(e(d), [...n.get(e(d)) ?? [], l]);
|
|
1745
1745
|
});
|
|
1746
1746
|
const i = /* @__PURE__ */ new Set(), s = [], r = (o) => {
|
|
1747
1747
|
for (; ; ) {
|
|
1748
|
-
const c = o[o.length - 1], l = (n.get(e(c)) ?? []).find((
|
|
1748
|
+
const c = o[o.length - 1], l = (n.get(e(c)) ?? []).find((f) => !i.has(f));
|
|
1749
1749
|
if (l === void 0) return;
|
|
1750
1750
|
i.add(l);
|
|
1751
1751
|
const [d, u] = t[l];
|
|
@@ -1759,262 +1759,262 @@ function Ji(t) {
|
|
|
1759
1759
|
r(d), d.reverse(), r(d), s.push(d);
|
|
1760
1760
|
}), s;
|
|
1761
1761
|
}
|
|
1762
|
-
function
|
|
1762
|
+
function ss(t, [e, n], [i, s], r) {
|
|
1763
1763
|
const o = (n - e) / r, c = (s - i) / r;
|
|
1764
|
-
return { values: Array.from({ length: r + 1 }, (d, u) => Array.from({ length: r + 1 }, (
|
|
1764
|
+
return { values: Array.from({ length: r + 1 }, (d, u) => Array.from({ length: r + 1 }, (f, h) => t(e + h * o, i + u * c))), x0: e, y0: i, dx: o, dy: c };
|
|
1765
1765
|
}
|
|
1766
|
-
function
|
|
1767
|
-
const o =
|
|
1768
|
-
const
|
|
1769
|
-
return [
|
|
1766
|
+
function jn(t, e, n, i, s = 0, r = {}) {
|
|
1767
|
+
const o = ct(t), c = Z(o, "x"), l = Z(o, "y"), d = (h, g) => {
|
|
1768
|
+
const p = { ...r, x: h, y: g };
|
|
1769
|
+
return [it(c, p), it(l, p)];
|
|
1770
1770
|
}, u = [e];
|
|
1771
|
-
let
|
|
1771
|
+
let f = [0, 0];
|
|
1772
1772
|
for (let h = 0; h < i; h++) {
|
|
1773
|
-
const [g,
|
|
1774
|
-
|
|
1775
|
-
const m = [g +
|
|
1773
|
+
const [g, p] = u[u.length - 1], [y, a] = d(g, p);
|
|
1774
|
+
f = [s * f[0] - n * y, s * f[1] - n * a];
|
|
1775
|
+
const m = [g + f[0], p + f[1]];
|
|
1776
1776
|
if (!Number.isFinite(m[0]) || !Number.isFinite(m[1]) || Math.abs(m[0]) > 1e6 || Math.abs(m[1]) > 1e6) break;
|
|
1777
1777
|
u.push(m);
|
|
1778
1778
|
}
|
|
1779
1779
|
return u;
|
|
1780
1780
|
}
|
|
1781
|
-
function
|
|
1782
|
-
const e =
|
|
1783
|
-
return (n, i, s = {}) =>
|
|
1781
|
+
function ge(t) {
|
|
1782
|
+
const e = ct(t);
|
|
1783
|
+
return (n, i, s = {}) => it(e, { ...s, x: n, y: i });
|
|
1784
1784
|
}
|
|
1785
|
-
function
|
|
1786
|
-
const s =
|
|
1785
|
+
function Dn(t, e, n, i) {
|
|
1786
|
+
const s = xt(typeof i == "number" ? i : gt(i)), r = [];
|
|
1787
1787
|
for (let o = 0; o < e; o++)
|
|
1788
|
-
t.forEach(([c, l], d) => r.push({ point: [c +
|
|
1788
|
+
t.forEach(([c, l], d) => r.push({ point: [c + yt(s) * n, l + yt(s) * n], label: d }));
|
|
1789
1789
|
return r;
|
|
1790
1790
|
}
|
|
1791
|
-
const
|
|
1792
|
-
function
|
|
1791
|
+
const rs = (t) => 1 / (1 + Math.exp(-t)), be = (t, [e, n]) => rs(t.w[0] * e + t.w[1] * n + t.b);
|
|
1792
|
+
function os(t, e, n, i = { w: [0, 0], b: 0 }) {
|
|
1793
1793
|
const s = [i];
|
|
1794
1794
|
for (let r = 0; r < e; r++) {
|
|
1795
1795
|
const { w: o, b: c } = s[s.length - 1];
|
|
1796
1796
|
let l = 0, d = 0, u = 0;
|
|
1797
1797
|
for (const { point: h, label: g } of t) {
|
|
1798
|
-
const
|
|
1799
|
-
l +=
|
|
1798
|
+
const p = be({ w: o, b: c }, h) - g;
|
|
1799
|
+
l += p * h[0], d += p * h[1], u += p;
|
|
1800
1800
|
}
|
|
1801
|
-
const
|
|
1802
|
-
s.push({ w: [o[0] - n * l /
|
|
1801
|
+
const f = t.length || 1;
|
|
1802
|
+
s.push({ w: [o[0] - n * l / f, o[1] - n * d / f], b: c - n * u / f });
|
|
1803
1803
|
}
|
|
1804
1804
|
return s;
|
|
1805
1805
|
}
|
|
1806
|
-
function
|
|
1807
|
-
return e.length === 0 ? 0 : e.filter(({ point: n, label: i }) => (
|
|
1806
|
+
function as(t, e) {
|
|
1807
|
+
return e.length === 0 ? 0 : e.filter(({ point: n, label: i }) => (be(t, n) >= 0.5 ? 1 : 0) === i).length / e.length;
|
|
1808
1808
|
}
|
|
1809
|
-
function
|
|
1809
|
+
function cs(t, e) {
|
|
1810
1810
|
if (e.length === 0) return 0;
|
|
1811
1811
|
const n = 1e-12;
|
|
1812
1812
|
return -e.reduce((i, { point: s, label: r }) => {
|
|
1813
|
-
const o =
|
|
1813
|
+
const o = be(t, s);
|
|
1814
1814
|
return i + Math.log(r ? o + n : 1 - o + n);
|
|
1815
1815
|
}, 0) / e.length;
|
|
1816
1816
|
}
|
|
1817
|
-
const
|
|
1818
|
-
function
|
|
1817
|
+
const ue = (t, e) => (t[0] - e[0]) ** 2 + (t[1] - e[1]) ** 2;
|
|
1818
|
+
function We(t, e) {
|
|
1819
1819
|
return t.map((n) => {
|
|
1820
1820
|
let i = 0;
|
|
1821
|
-
for (let s = 1; s < e.length; s++)
|
|
1821
|
+
for (let s = 1; s < e.length; s++) ue(n, e[s]) < ue(n, e[i]) && (i = s);
|
|
1822
1822
|
return i;
|
|
1823
1823
|
});
|
|
1824
1824
|
}
|
|
1825
|
-
function
|
|
1825
|
+
function ls(t, e, n = 20, i = t.slice(0, e)) {
|
|
1826
1826
|
const s = [i.map((r) => [r[0], r[1]])];
|
|
1827
1827
|
for (let r = 0; r < n; r++) {
|
|
1828
|
-
const o = s[s.length - 1], c =
|
|
1829
|
-
const h = t.filter((g,
|
|
1830
|
-
return h.length === 0 ? u : [h.reduce((g,
|
|
1831
|
-
}), d = l.some((u,
|
|
1828
|
+
const o = s[s.length - 1], c = We(t, o), l = o.map((u, f) => {
|
|
1829
|
+
const h = t.filter((g, p) => c[p] === f);
|
|
1830
|
+
return h.length === 0 ? u : [h.reduce((g, p) => g + p[0], 0) / h.length, h.reduce((g, p) => g + p[1], 0) / h.length];
|
|
1831
|
+
}), d = l.some((u, f) => ue(u, o[f]) > 1e-12);
|
|
1832
1832
|
if (s.push(l), !d) break;
|
|
1833
1833
|
}
|
|
1834
1834
|
return s;
|
|
1835
1835
|
}
|
|
1836
|
-
function
|
|
1837
|
-
const n =
|
|
1838
|
-
return t.reduce((i, s, r) => i +
|
|
1836
|
+
function us(t, e) {
|
|
1837
|
+
const n = We(t, e);
|
|
1838
|
+
return t.reduce((i, s, r) => i + ue(s, e[n[r]]), 0);
|
|
1839
1839
|
}
|
|
1840
|
-
const
|
|
1840
|
+
const ve = (t, e, n) => {
|
|
1841
1841
|
let i = t.get(e);
|
|
1842
1842
|
return i === void 0 && (i = n(), t.size > 32 && t.clear(), t.set(e, i)), i;
|
|
1843
|
-
},
|
|
1844
|
-
function
|
|
1845
|
-
const n =
|
|
1843
|
+
}, we = (t) => Number.isFinite(t) ? t : 0, _n = (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 Rn(t, e) {
|
|
1845
|
+
const n = Qi(t.layers, t.seed ?? t.id), i = Array.from({ length: t.layers[0] }, (o, c) => t.inputs?.[c] === void 0 ? 0.5 : P(e, t.inputs[c])), s = ts(n, i, t.activation ?? "sigmoid"), r = t.flow === void 0 ? t.layers.length - 1 : Math.min(t.layers.length - 1, Math.max(0, we(P(e, t.flow))));
|
|
1846
1846
|
return { network: n, activations: s, flow: r };
|
|
1847
1847
|
}
|
|
1848
|
-
function
|
|
1849
|
-
const { plane: n, theme: i } = e, { network: s, activations: r, flow: o } =
|
|
1850
|
-
const $ = u - l / 2 + (g.length === 1 ? l / 2 : w / (g.length - 1) * l), M = Math.min(d / Math.max(1, g[w] - 1), d * 0.3), k =
|
|
1848
|
+
function ds(t, e) {
|
|
1849
|
+
const { plane: n, theme: i } = e, { network: s, activations: r, flow: o } = Rn(t, e.values), c = _n(e), [l, d] = t.size ?? [c.w * 0.75, c.h * 0.7], [u, f] = t.at ?? [(c.x[0] + c.x[1]) / 2, (c.y[0] + c.y[1]) / 2], h = (t.radius ?? 16) * n.scale, g = t.layers, p = (w, v) => {
|
|
1850
|
+
const $ = u - l / 2 + (g.length === 1 ? l / 2 : w / (g.length - 1) * l), M = Math.min(d / Math.max(1, g[w] - 1), d * 0.3), k = f + ((g[w] - 1) / 2 - v) * M;
|
|
1851
1851
|
return n.toScreen([$, k]);
|
|
1852
|
-
}, y =
|
|
1852
|
+
}, y = F(i, "blue", i.colors.blue), a = F(i, "red", i.colors.red), m = [], b = Math.max(...s.weights.flat(2).map(Math.abs), 1e-9);
|
|
1853
1853
|
s.weights.forEach((w, v) => {
|
|
1854
1854
|
w.forEach(($, M) => {
|
|
1855
1855
|
$.forEach((k, S) => {
|
|
1856
|
-
const E =
|
|
1857
|
-
for (const A of V([[E,
|
|
1858
|
-
m.push({ type: "line", id: `${t.id}.w.${v}.${M}.${S}`, points: A, stroke:
|
|
1859
|
-
if (
|
|
1860
|
-
const [A,
|
|
1861
|
-
m.push({ type: "circle", id: `${t.id}.pulse.${v}.${M}.${S}`, x: A, y:
|
|
1856
|
+
const E = p(v, S), T = p(v + 1, M), O = Math.min(1, Math.max(0, o - v)), z = k >= 0 ? y : a, q = (0.6 + 3 * (Math.abs(k) / b)) * n.scale;
|
|
1857
|
+
for (const A of V([[E, T]], e.draw))
|
|
1858
|
+
m.push({ type: "line", id: `${t.id}.w.${v}.${M}.${S}`, points: A, stroke: z, width: q, opacity: e.opacity * (0.18 + 0.5 * O) });
|
|
1859
|
+
if (O > 0 && O < 1) {
|
|
1860
|
+
const [A, N] = qt(E, T, O);
|
|
1861
|
+
m.push({ type: "circle", id: `${t.id}.pulse.${v}.${M}.${S}`, x: A, y: N, r: h * 0.22, fill: F(i, "yellow", i.colors.yellow), opacity: e.opacity * (0.5 + 0.5 * Math.abs(r[v][S] ?? 0)) });
|
|
1862
1862
|
}
|
|
1863
1863
|
});
|
|
1864
1864
|
});
|
|
1865
1865
|
}), g.forEach((w, v) => {
|
|
1866
1866
|
const $ = Math.min(1, Math.max(0, o - v + 1));
|
|
1867
1867
|
for (let M = 0; M < w; M++) {
|
|
1868
|
-
const [k, S] =
|
|
1869
|
-
m.push({ type: "circle", id: `${t.id}.node.${v}.${M}`, x: k, y: S, r: h, fill: i.background, stroke:
|
|
1868
|
+
const [k, S] = p(v, M), E = r[v][M] ?? 0, T = t.activation === "relu" ? Math.min(1, E / 2) : t.activation === "tanh" ? (E + 1) / 2 : E;
|
|
1869
|
+
m.push({ type: "circle", id: `${t.id}.node.${v}.${M}`, x: k, y: S, r: h, fill: i.background, stroke: F(i, t.color, i.ink), width: 2 * n.scale, opacity: e.opacity * Math.min(1, e.draw * 1.5) }), $ > 0 && m.push({ type: "circle", id: `${t.id}.value.${v}.${M}`, x: k, y: S, r: h * 0.86, fill: me("viridis", T), opacity: e.opacity * $ });
|
|
1870
1870
|
}
|
|
1871
1871
|
});
|
|
1872
1872
|
const x = (w, v, $, M) => m.push(...X(U(w, { values: e.scope, style: "inline" }), { x: v[0], y: v[1], size: 20 * n.scale, color: i.ink, align: $, opacity: e.opacity * e.draw, idPrefix: `${t.id}.${M}.` }));
|
|
1873
1873
|
return t.labels?.inputs?.forEach((w, v) => {
|
|
1874
|
-
const [$, M] =
|
|
1874
|
+
const [$, M] = p(0, v);
|
|
1875
1875
|
x(w, [$ - h * 1.5, M], "right", `in${v}`);
|
|
1876
1876
|
}), t.labels?.outputs?.forEach((w, v) => {
|
|
1877
|
-
const [$, M] =
|
|
1877
|
+
const [$, M] = p(g.length - 1, v);
|
|
1878
1878
|
x(w, [$ + h * 1.5, M], "left", `out${v}`);
|
|
1879
1879
|
}), m;
|
|
1880
1880
|
}
|
|
1881
|
-
const
|
|
1881
|
+
const hs = (t) => {
|
|
1882
1882
|
const e = Math.max(...t), n = t.map((s) => Math.exp(s - e)), i = n.reduce((s, r) => s + r, 0);
|
|
1883
1883
|
return n.map((s) => s / i);
|
|
1884
1884
|
};
|
|
1885
|
-
function
|
|
1885
|
+
function fs(t, e) {
|
|
1886
1886
|
if (t.cells) {
|
|
1887
|
-
const d =
|
|
1888
|
-
return { cells: t.softmax ? t.cells.map(
|
|
1887
|
+
const d = _n(e), [u, f] = 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 - f / 2];
|
|
1888
|
+
return { cells: t.softmax ? t.cells.map(hs) : t.cells, box: [h, [h[0] + u, h[1] + f]] };
|
|
1889
1889
|
}
|
|
1890
|
-
const [[n, i], [s, r]] = t.region ?? [e.plane.x, e.plane.y], o = t.resolution ?? 48, c =
|
|
1891
|
-
return { cells: Array.from({ length: o }, (d, u) => Array.from({ length: o }, (
|
|
1890
|
+
const [[n, i], [s, r]] = t.region ?? [e.plane.x, e.plane.y], o = t.resolution ?? 48, c = ge(t.expr);
|
|
1891
|
+
return { cells: Array.from({ length: o }, (d, u) => Array.from({ length: o }, (f, h) => c(n + (h + 0.5) / o * (i - n), r - (u + 0.5) / o * (r - s), e.scope))), box: [[n, s], [i, r]] };
|
|
1892
1892
|
}
|
|
1893
|
-
function
|
|
1894
|
-
const { plane: n, theme: i } = e, { cells: s, box: r } =
|
|
1893
|
+
function ps(t, e) {
|
|
1894
|
+
const { plane: n, theme: i } = e, { cells: s, box: r } = fs(t, e), o = s.flat().filter(Number.isFinite), [c, l] = t.range ?? [Math.min(...o), Math.max(...o)], d = s.length, u = s[0]?.length ?? 0, [[f, h], [g, p]] = r, y = (g - f) / u, a = (p - h) / d, m = [], b = t.colormap ?? "viridis", x = Math.ceil(d * e.draw);
|
|
1895
1895
|
for (let v = 0; v < x; v++)
|
|
1896
1896
|
for (let $ = 0; $ < u; $++) {
|
|
1897
1897
|
const M = s[v][$];
|
|
1898
1898
|
if (!Number.isFinite(M)) continue;
|
|
1899
|
-
const k = l === c ? 0.5 : (M - c) / (l - c), S =
|
|
1900
|
-
if (m.push({ type: "line", id: `${t.id}.${v}.${$}`, points:
|
|
1901
|
-
const [
|
|
1902
|
-
m.push({ type: "text", id: `${t.id}.v.${v}.${$}`, text: M.toFixed(2).replace(/^0/, ""), x:
|
|
1899
|
+
const k = l === c ? 0.5 : (M - c) / (l - c), S = f + $ * y, E = p - v * a, T = [[S, E - a], [S + y * 1.01, E - a], [S + y * 1.01, E + a * 0.01], [S, E + a * 0.01]].map(n.toScreen);
|
|
1900
|
+
if (m.push({ type: "line", id: `${t.id}.${v}.${$}`, points: T, closed: !0, fill: zn(me(b, k), i.background, e.opacity) }), t.values) {
|
|
1901
|
+
const [O, z] = n.toScreen([S + y / 2, E - a / 2]), q = Math.min(16 * n.scale, Math.abs(y * n.unitX) * 0.32);
|
|
1902
|
+
m.push({ type: "text", id: `${t.id}.v.${v}.${$}`, text: M.toFixed(2).replace(/^0/, ""), x: O, y: z + q * 0.35, size: q, font: pt, color: k > 0.6 ? "#111" : "#eee", align: "center", opacity: e.opacity });
|
|
1903
1903
|
}
|
|
1904
1904
|
}
|
|
1905
1905
|
const w = Math.min(22 * n.scale, Math.abs(a * n.unitY) * 0.6);
|
|
1906
1906
|
return t.rowLabels?.forEach((v, $) => {
|
|
1907
|
-
const [M, k] = n.toScreen([
|
|
1907
|
+
const [M, k] = n.toScreen([f, p - ($ + 0.5) * a]);
|
|
1908
1908
|
m.push(...X(U(v, { style: "inline" }), { x: M - w * 0.5, y: k, size: w, color: i.ink, align: "right", opacity: e.opacity * e.draw, idPrefix: `${t.id}.row.${$}.` }));
|
|
1909
1909
|
}), t.colLabels?.forEach((v, $) => {
|
|
1910
|
-
const [M, k] = n.toScreen([
|
|
1910
|
+
const [M, k] = n.toScreen([f + ($ + 0.5) * y, p]);
|
|
1911
1911
|
m.push(...X(U(v, { style: "inline" }), { x: M, y: k - w * 0.8, size: w, color: i.ink, opacity: e.opacity * e.draw, idPrefix: `${t.id}.col.${$}.` }));
|
|
1912
1912
|
}), m;
|
|
1913
1913
|
}
|
|
1914
|
-
const
|
|
1915
|
-
function
|
|
1916
|
-
const n = t.region ?? [e.plane.x, e.plane.y], i = t.resolution ?? 80, s = Object.entries(e.scope).filter(([l]) => !l.includes(".")), r =
|
|
1917
|
-
const l =
|
|
1918
|
-
return (Array.isArray(t.levels) ? t.levels : Array.from({ length: g }, (y, a) =>
|
|
1914
|
+
const ys = /* @__PURE__ */ new Map();
|
|
1915
|
+
function ms(t, e) {
|
|
1916
|
+
const n = t.region ?? [e.plane.x, e.plane.y], i = t.resolution ?? 80, s = Object.entries(e.scope).filter(([l]) => !l.includes(".")), r = ve(ys, JSON.stringify([t.expr, t.levels, n, i, s]), () => {
|
|
1917
|
+
const l = ge(t.expr), d = ss((y, a) => l(y, a, e.scope), n[0], n[1], i), u = d.values.flat().filter(Number.isFinite), f = Math.min(...u), h = Math.max(...u), g = typeof t.levels == "number" ? t.levels : 10;
|
|
1918
|
+
return (Array.isArray(t.levels) ? t.levels : Array.from({ length: g }, (y, a) => f + (h - f) * (a + 1) / (g + 1))).map((y) => ns(d.values, d.x0, d.y0, d.dx, d.dy, y));
|
|
1919
1919
|
}), o = [], c = t.colormap ?? "viridis";
|
|
1920
1920
|
return r.forEach((l, d) => {
|
|
1921
|
-
const u = t.color ?
|
|
1922
|
-
V(l.map((
|
|
1923
|
-
o.push({ type: "line", id: `${t.id}.${d}.${h}`, points:
|
|
1921
|
+
const u = t.color ? F(e.theme, t.color, e.theme.ink) : me(c, r.length === 1 ? 0.6 : 0.15 + 0.85 * d / (r.length - 1));
|
|
1922
|
+
V(l.map((f) => f.map(e.plane.toScreen)), e.draw).forEach((f, h) => {
|
|
1923
|
+
o.push({ type: "line", id: `${t.id}.${d}.${h}`, points: f, stroke: u, width: (t.width ?? 1.8) * e.plane.scale, opacity: e.opacity });
|
|
1924
1924
|
});
|
|
1925
1925
|
}), o;
|
|
1926
1926
|
}
|
|
1927
|
-
const
|
|
1928
|
-
function
|
|
1929
|
-
const i =
|
|
1930
|
-
return { path: l.slice(0, d + 1), here:
|
|
1927
|
+
const gs = /* @__PURE__ */ new Map();
|
|
1928
|
+
function Bn(t, e, n) {
|
|
1929
|
+
const i = kt(e, t.start), s = P(e, t.rate), r = t.momentum === void 0 ? 0 : P(e, t.momentum), o = Math.min(500, Math.max(0, we(P(e, t.steps)))), c = Object.entries(n).filter(([h]) => !h.includes(".")), l = ve(gs, JSON.stringify([t.expr, i, s, r, c]), () => jn(t.expr, i, s, 500, r, n)), d = Math.min(l.length - 1, Math.floor(o)), u = d < l.length - 1 ? o - d : 0, f = u > 0 ? qt(l[d], l[d + 1], u) : l[d];
|
|
1930
|
+
return { path: l.slice(0, d + 1), here: f, step: d, diverged: l.length < 501 && o > l.length - 1 };
|
|
1931
1931
|
}
|
|
1932
|
-
function
|
|
1933
|
-
const { path: n, here: i } =
|
|
1932
|
+
function bs(t, e) {
|
|
1933
|
+
const { path: n, here: i } = Bn(t, e.values, e.scope), s = F(e.theme, t.color, e.theme.colors.red), r = [...n, i].map(e.plane.toScreen), o = [];
|
|
1934
1934
|
r.length >= 2 && o.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 [
|
|
1936
|
-
o.push({ type: "circle", id: `${t.id}.step.${u}`, x:
|
|
1935
|
+
const [f, h] = e.plane.toScreen(d);
|
|
1936
|
+
o.push({ type: "circle", id: `${t.id}.step.${u}`, x: f, y: h, r: 3 * e.plane.scale, fill: s, opacity: e.opacity * 0.8 });
|
|
1937
1937
|
});
|
|
1938
1938
|
const [c, l] = e.plane.toScreen(i);
|
|
1939
|
-
return o.push({ type: "circle", id: `${t.id}.ball`, x: c, y: l, r: 8 * e.plane.scale, fill:
|
|
1940
|
-
}
|
|
1941
|
-
const
|
|
1942
|
-
function
|
|
1943
|
-
const n = t.centres ?? [[-1.5, -1], [1.5, 1]], i = Math.min(500, Math.max(0,
|
|
1944
|
-
const
|
|
1945
|
-
return { data:
|
|
1946
|
-
}), d = Math.floor(i), u = i - d,
|
|
1939
|
+
return o.push({ type: "circle", id: `${t.id}.ball`, x: c, y: l, r: 8 * e.plane.scale, fill: F(e.theme, "yellow", e.theme.colors.yellow), stroke: e.theme.background, width: 2 * e.plane.scale, opacity: e.opacity }), o;
|
|
1940
|
+
}
|
|
1941
|
+
const vs = /* @__PURE__ */ new Map();
|
|
1942
|
+
function Vn(t, e) {
|
|
1943
|
+
const n = t.centres ?? [[-1.5, -1], [1.5, 1]], i = Math.min(500, Math.max(0, we(P(e, t.epochs)))), [s, r, o] = t.start ?? [0.9, -1.1, 0.8], { data: c, models: l } = ve(vs, JSON.stringify([n, t.count, t.spread, t.seed ?? t.id, t.rate, s, r, o]), () => {
|
|
1944
|
+
const p = Dn(n, t.count ?? 40, t.spread ?? 0.9, t.seed ?? t.id);
|
|
1945
|
+
return { data: p, models: os(p, 500, t.rate ?? 0.5, { w: [s, r], b: o }) };
|
|
1946
|
+
}), d = Math.floor(i), u = i - d, f = l[d], h = l[Math.min(l.length - 1, d + 1)], g = { w: qt(f.w, h.w, u), b: f.b + (h.b - f.b) * u };
|
|
1947
1947
|
return { data: c, model: g, epochs: i };
|
|
1948
1948
|
}
|
|
1949
|
-
function
|
|
1950
|
-
const { plane: n, theme: i } = e, { data: s, model: r } =
|
|
1949
|
+
function ws(t, e) {
|
|
1950
|
+
const { plane: n, theme: i } = e, { data: s, model: r } = Vn(t, e.values), o = [], c = [F(i, "blue", i.colors.blue), F(i, "orange", i.colors.orange)];
|
|
1951
1951
|
if (t.probability !== !1) {
|
|
1952
|
-
const [
|
|
1952
|
+
const [f, h] = n.x, [g, p] = n.y, y = (h - f) / 32, a = (p - g) / 32;
|
|
1953
1953
|
for (let m = 0; m < 32; m++)
|
|
1954
1954
|
for (let b = 0; b < 32; b++) {
|
|
1955
|
-
const x =
|
|
1956
|
-
o.push({ type: "line", id: `${t.id}.p.${m}.${b}`, points: w, closed: !0, fill:
|
|
1955
|
+
const x = be(r, [f + (b + 0.5) * y, g + (m + 0.5) * a]), w = [[f + b * y, g + m * a], [f + (b + 1.02) * y, g + m * a], [f + (b + 1.02) * y, g + (m + 1.02) * a], [f + b * y, g + (m + 1.02) * a]].map(n.toScreen);
|
|
1956
|
+
o.push({ type: "line", id: `${t.id}.p.${m}.${b}`, points: w, closed: !0, fill: zn(x >= 0.5 ? c[1] : c[0], i.background, e.opacity * Math.abs(x - 0.5) * 0.5) });
|
|
1957
1957
|
}
|
|
1958
1958
|
}
|
|
1959
|
-
s.forEach(({ point: u, label:
|
|
1960
|
-
const [g,
|
|
1961
|
-
o.push({ type: "circle", id: `${t.id}.pt.${h}`, x: g, y:
|
|
1959
|
+
s.forEach(({ point: u, label: f }, h) => {
|
|
1960
|
+
const [g, p] = n.toScreen(u);
|
|
1961
|
+
o.push({ type: "circle", id: `${t.id}.pt.${h}`, x: g, y: p, r: 4.5 * n.scale, fill: c[f], stroke: i.background, width: 1 * n.scale, opacity: e.opacity * e.draw });
|
|
1962
1962
|
});
|
|
1963
1963
|
const [l, d] = r.w;
|
|
1964
1964
|
if (Math.hypot(l, d) > 1e-6) {
|
|
1965
|
-
const [u,
|
|
1966
|
-
o.push({ type: "line", id: `${t.id}.boundary`, points:
|
|
1965
|
+
const [u, f] = n.x, [h, g] = n.y, p = Math.abs(d) > Math.abs(l) ? [[u, -(l * u + r.b) / d], [f, -(l * f + r.b) / d]] : [[-(d * h + r.b) / l, h], [-(d * g + r.b) / l, g]];
|
|
1966
|
+
o.push({ type: "line", id: `${t.id}.boundary`, points: p.map(n.toScreen), stroke: i.ink, width: 3 * n.scale, opacity: e.opacity, dash: [12 * n.scale, 8 * n.scale] });
|
|
1967
1967
|
}
|
|
1968
1968
|
return o;
|
|
1969
1969
|
}
|
|
1970
|
-
const
|
|
1971
|
-
function
|
|
1972
|
-
const { points: n, history: i } =
|
|
1973
|
-
const l =
|
|
1974
|
-
return { points: l, history:
|
|
1975
|
-
}), s = Math.min(i.length - 1, Math.max(0,
|
|
1976
|
-
return { points: n, history: i, centroids: c, owners:
|
|
1977
|
-
}
|
|
1978
|
-
function
|
|
1979
|
-
const { plane: n, theme: i } = e, { points: s, centroids: r, owners: o, history: c, iteration: l } =
|
|
1980
|
-
return s.forEach((
|
|
1981
|
-
const [g,
|
|
1982
|
-
u.push({ type: "circle", id: `${t.id}.pt.${h}`, x: g, y:
|
|
1983
|
-
}), r.forEach((
|
|
1970
|
+
const $s = /* @__PURE__ */ new Map();
|
|
1971
|
+
function Hn(t, e) {
|
|
1972
|
+
const { points: n, history: i } = ve($s, JSON.stringify([t.centres, t.count, t.spread, t.seed ?? t.id, t.k]), () => {
|
|
1973
|
+
const l = Dn(t.centres, t.count ?? 30, t.spread ?? 0.7, t.seed ?? t.id).map((h) => h.point), d = t.k ?? t.centres.length, u = [l.reduce((h, g) => h + g[0], 0) / l.length, l.reduce((h, g) => h + g[1], 0) / l.length], f = [...l].sort((h, g) => Math.hypot(h[0] - u[0], h[1] - u[1]) - Math.hypot(g[0] - u[0], g[1] - u[1])).slice(0, d);
|
|
1974
|
+
return { points: l, history: ls(l, d, 20, f) };
|
|
1975
|
+
}), s = Math.min(i.length - 1, Math.max(0, we(P(e, t.iteration)))), r = Math.floor(s), o = s - r, c = i[r].map((l, d) => qt(l, i[Math.min(i.length - 1, r + 1)][d], o));
|
|
1976
|
+
return { points: n, history: i, centroids: c, owners: We(n, i[r]), iteration: s, iterations: i.length - 1 };
|
|
1977
|
+
}
|
|
1978
|
+
function ks(t, e) {
|
|
1979
|
+
const { plane: n, theme: i } = e, { points: s, centroids: r, owners: o, history: c, iteration: l } = Hn(t, e.values), d = ["blue", "orange", "green", "pink", "purple", "teal"].map((f) => F(i, f, i.colors.blue)), u = [];
|
|
1980
|
+
return s.forEach((f, h) => {
|
|
1981
|
+
const [g, p] = n.toScreen(f);
|
|
1982
|
+
u.push({ type: "circle", id: `${t.id}.pt.${h}`, x: g, y: p, r: 4.5 * n.scale, fill: d[o[h] % d.length], opacity: e.opacity * e.draw * 0.85 });
|
|
1983
|
+
}), r.forEach((f, h) => {
|
|
1984
1984
|
const g = c.slice(0, Math.floor(l) + 1).map((m) => m[h]);
|
|
1985
|
-
g.push(
|
|
1986
|
-
const [
|
|
1987
|
-
u.push({ type: "line", id: `${t.id}.centroid.${h}`, points: [[
|
|
1985
|
+
g.push(f), g.length >= 2 && u.push({ type: "line", id: `${t.id}.trail.${h}`, points: g.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 [p, y] = n.toScreen(f), a = 11 * n.scale;
|
|
1987
|
+
u.push({ type: "line", id: `${t.id}.centroid.${h}`, points: [[p, y - a], [p + a, y], [p, y + a], [p - a, y]], closed: !0, fill: d[h % d.length], stroke: i.ink, width: 2.5 * n.scale, opacity: e.opacity });
|
|
1988
1988
|
}), u;
|
|
1989
1989
|
}
|
|
1990
|
-
function
|
|
1990
|
+
function Ms(t, e, n) {
|
|
1991
1991
|
switch (t.kind) {
|
|
1992
1992
|
case "network": {
|
|
1993
|
-
const { activations: i } =
|
|
1993
|
+
const { activations: i } = Rn(t, e);
|
|
1994
1994
|
return Object.fromEntries(i[i.length - 1].map((s, r) => [`${t.id}.out${r}`, s]));
|
|
1995
1995
|
}
|
|
1996
1996
|
case "descent": {
|
|
1997
|
-
const { here: i, step: s } =
|
|
1998
|
-
return { [`${t.id}.x`]: i[0], [`${t.id}.y`]: i[1], [`${t.id}.loss`]:
|
|
1997
|
+
const { here: i, step: s } = Bn(t, e, n);
|
|
1998
|
+
return { [`${t.id}.x`]: i[0], [`${t.id}.y`]: i[1], [`${t.id}.loss`]: ge(t.expr)(i[0], i[1], n), [`${t.id}.step`]: s };
|
|
1999
1999
|
}
|
|
2000
2000
|
case "classifier": {
|
|
2001
|
-
const { data: i, model: s, epochs: r } =
|
|
2002
|
-
return { [`${t.id}.accuracy`]:
|
|
2001
|
+
const { data: i, model: s, epochs: r } = Vn(t, e);
|
|
2002
|
+
return { [`${t.id}.accuracy`]: as(s, i), [`${t.id}.loss`]: cs(s, i), [`${t.id}.epoch`]: Math.floor(r) };
|
|
2003
2003
|
}
|
|
2004
2004
|
case "kmeans": {
|
|
2005
|
-
const { points: i, centroids: s, iteration: r, iterations: o } =
|
|
2006
|
-
return { [`${t.id}.inertia`]:
|
|
2005
|
+
const { points: i, centroids: s, iteration: r, iterations: o } = Hn(t, e);
|
|
2006
|
+
return { [`${t.id}.inertia`]: us(i, s), [`${t.id}.iteration`]: Math.floor(r), [`${t.id}.iterations`]: o };
|
|
2007
2007
|
}
|
|
2008
2008
|
}
|
|
2009
2009
|
}
|
|
2010
|
-
function
|
|
2010
|
+
function Ee(t, e, n, i = 512) {
|
|
2011
2011
|
if (e === n) return 0;
|
|
2012
2012
|
const s = (n - e) / i;
|
|
2013
2013
|
let r = t(e) + t(n);
|
|
2014
2014
|
for (let o = 1; o < i; o++) r += t(e + o * s) * (o % 2 ? 4 : 2);
|
|
2015
2015
|
return r * s / 3;
|
|
2016
2016
|
}
|
|
2017
|
-
function
|
|
2017
|
+
function Un(t, e, n, i, s) {
|
|
2018
2018
|
const r = (n - e) / i;
|
|
2019
2019
|
return Array.from({ length: i }, (o, c) => {
|
|
2020
2020
|
const l = e + c * r, d = l + r;
|
|
@@ -2023,55 +2023,55 @@ function Dn(t, e, n, i, s) {
|
|
|
2023
2023
|
return [l, d, u, u];
|
|
2024
2024
|
});
|
|
2025
2025
|
}
|
|
2026
|
-
const
|
|
2027
|
-
function
|
|
2026
|
+
const Wn = (t) => Math.min(400, Math.max(1, Math.round(t)));
|
|
2027
|
+
function Gn(t, e, n) {
|
|
2028
2028
|
const i = {}, s = { ...n };
|
|
2029
2029
|
for (const r of t)
|
|
2030
2030
|
switch (r.kind) {
|
|
2031
2031
|
case "tangent": {
|
|
2032
|
-
const o =
|
|
2032
|
+
const o = J(r.expr), c = P(e, r.at), l = r.h === void 0 ? 0 : P(e, r.h), d = Math.abs(l) > 1e-9 ? (o(c + l, s) - o(c, s)) / l : Be(r.expr, 1)(c, s);
|
|
2033
2033
|
Object.assign(i, { [`${r.id}.slope`]: d, [`${r.id}.x`]: c, [`${r.id}.y`]: o(c, s) });
|
|
2034
2034
|
break;
|
|
2035
2035
|
}
|
|
2036
2036
|
case "riemann": {
|
|
2037
|
-
const o =
|
|
2038
|
-
Object.assign(i, { [`${r.id}.sum`]:
|
|
2037
|
+
const o = J(r.expr), c = P(e, r.from), l = P(e, r.to), d = Wn(P(e, r.n)), f = Un((h) => o(h, s), c, l, d, r.rule ?? "left").reduce((h, [g, p, y, a]) => h + (y + a) / 2 * (p - g), 0);
|
|
2038
|
+
Object.assign(i, { [`${r.id}.sum`]: f, [`${r.id}.exact`]: Ee((h) => o(h, s), c, l), [`${r.id}.n`]: d });
|
|
2039
2039
|
break;
|
|
2040
2040
|
}
|
|
2041
2041
|
case "area": {
|
|
2042
|
-
const o =
|
|
2043
|
-
i[`${r.id}.value`] =
|
|
2042
|
+
const o = J(r.expr), c = r.lower ? J(r.lower) : () => 0;
|
|
2043
|
+
i[`${r.id}.value`] = Ee((l) => o(l, s) - c(l, s), P(e, r.from), P(e, r.to));
|
|
2044
2044
|
break;
|
|
2045
2045
|
}
|
|
2046
2046
|
case "point":
|
|
2047
2047
|
if (r.on !== void 0 && r.x !== void 0) {
|
|
2048
|
-
const o =
|
|
2049
|
-
Object.assign(i, { [`${r.id}.x`]: o, [`${r.id}.y`]:
|
|
2048
|
+
const o = P(e, r.x);
|
|
2049
|
+
Object.assign(i, { [`${r.id}.x`]: o, [`${r.id}.y`]: J(r.on)(o, s) });
|
|
2050
2050
|
}
|
|
2051
2051
|
break;
|
|
2052
2052
|
case "histogram": {
|
|
2053
|
-
const o =
|
|
2053
|
+
const o = $n(Mt(e, r.distribution), r.seed ?? r.id, le(P(e, r.count))), { mean: c, sd: l } = pi(o);
|
|
2054
2054
|
Object.assign(i, { [`${r.id}.count`]: o.length, [`${r.id}.mean`]: c, [`${r.id}.sd`]: l });
|
|
2055
2055
|
break;
|
|
2056
2056
|
}
|
|
2057
2057
|
case "distribution": {
|
|
2058
|
-
const o =
|
|
2058
|
+
const o = Mt(e, r.distribution);
|
|
2059
2059
|
let c = 0;
|
|
2060
2060
|
if (r.shade) {
|
|
2061
|
-
const [l, d] = [
|
|
2062
|
-
if (
|
|
2063
|
-
for (let u = Math.max(0, Math.ceil(l)); u <= Math.floor(d) && u <= 5e3; u++) c +=
|
|
2061
|
+
const [l, d] = [P(e, r.shade[0]), P(e, r.shade[1])].sort((u, f) => u - f);
|
|
2062
|
+
if (fe(o))
|
|
2063
|
+
for (let u = Math.max(0, Math.ceil(l)); u <= Math.floor(d) && u <= 5e3; u++) c += ht(o, u);
|
|
2064
2064
|
else
|
|
2065
|
-
c =
|
|
2065
|
+
c = Ee((u) => ht(o, u), l, d, 2048);
|
|
2066
2066
|
}
|
|
2067
|
-
Object.assign(i, { [`${r.id}.p`]: c, [`${r.id}.mean`]:
|
|
2067
|
+
Object.assign(i, { [`${r.id}.p`]: c, [`${r.id}.mean`]: Dt(o), [`${r.id}.sd`]: _t(o) });
|
|
2068
2068
|
break;
|
|
2069
2069
|
}
|
|
2070
2070
|
case "galton":
|
|
2071
|
-
i[`${r.id}.landed`] = Math.max(0, Math.floor(
|
|
2071
|
+
i[`${r.id}.landed`] = Math.max(0, Math.floor(P(e, r.balls)));
|
|
2072
2072
|
break;
|
|
2073
2073
|
case "scatter": {
|
|
2074
|
-
const o =
|
|
2074
|
+
const o = Mn(In(r, { values: e }), r.seed ?? r.id, le(P(e, r.count))), c = r.inside ? ct(r.inside) : void 0, l = c ? o.filter(([u, f]) => it(c, { ...s, x: u, y: f }) <= 0).length : 0, d = xn(o);
|
|
2075
2075
|
Object.assign(i, {
|
|
2076
2076
|
[`${r.id}.count`]: o.length,
|
|
2077
2077
|
[`${r.id}.inside`]: l,
|
|
@@ -2083,12 +2083,12 @@ function Rn(t, e, n) {
|
|
|
2083
2083
|
break;
|
|
2084
2084
|
}
|
|
2085
2085
|
case "bayes": {
|
|
2086
|
-
const o =
|
|
2086
|
+
const o = P(e, r.prior), c = yi(o, P(e, r.truePositive), P(e, r.falsePositive));
|
|
2087
2087
|
Object.assign(i, { [`${r.id}.prior`]: o, [`${r.id}.posterior`]: c.posterior, [`${r.id}.positive`]: c.positive, [`${r.id}.truePositive`]: c.truePositive, [`${r.id}.falsePositive`]: c.falsePositive });
|
|
2088
2088
|
break;
|
|
2089
2089
|
}
|
|
2090
2090
|
case "graph": {
|
|
2091
|
-
const o =
|
|
2091
|
+
const o = Cn(r, e);
|
|
2092
2092
|
if (o && (i[`${r.id}.visited`] = o.done, i[`${r.id}.steps`] = o.events.length, r.search?.kind === "dijkstra")) {
|
|
2093
2093
|
const c = o.events[o.done - 1]?.distances ?? {};
|
|
2094
2094
|
for (const l of r.nodes) i[`${r.id}.d.${l.id}`] = c[l.id] ?? 1 / 0;
|
|
@@ -2096,58 +2096,131 @@ function Rn(t, e, n) {
|
|
|
2096
2096
|
break;
|
|
2097
2097
|
}
|
|
2098
2098
|
case "clock": {
|
|
2099
|
-
const o =
|
|
2100
|
-
Object.assign(i, { [`${r.id}.hour`]:
|
|
2099
|
+
const o = P(e, r.value);
|
|
2100
|
+
Object.assign(i, { [`${r.id}.hour`]: qn(o, r.modulus), [`${r.id}.turns`]: Math.floor(Math.round(o) / r.modulus) });
|
|
2101
2101
|
break;
|
|
2102
2102
|
}
|
|
2103
2103
|
case "network":
|
|
2104
2104
|
case "descent":
|
|
2105
2105
|
case "classifier":
|
|
2106
2106
|
case "kmeans":
|
|
2107
|
-
Object.assign(i,
|
|
2107
|
+
Object.assign(i, Ms(r, e, s));
|
|
2108
2108
|
break;
|
|
2109
2109
|
case "taylor":
|
|
2110
|
-
i[`${r.id}.order`] = Math.min(20, Math.max(0,
|
|
2110
|
+
i[`${r.id}.order`] = Math.min(20, Math.max(0, P(e, r.order))), i[`${r.id}.degree`] = Math.floor(i[`${r.id}.order`]);
|
|
2111
2111
|
break;
|
|
2112
2112
|
}
|
|
2113
2113
|
return i;
|
|
2114
2114
|
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2115
|
+
function Er(t) {
|
|
2116
|
+
const e = t.id ?? "loss", [[n, i], [s, r]] = t.region ?? [[-3, 3], [-3, 3]], o = Math.max(4, Math.min(120, Math.round(t.resolution ?? 36))), c = 5, l = ge(t.expr), d = t.scope ?? {}, u = (N, I) => l(N, I, d), f = Array.from({ length: o + 1 }, (N, I) => Array.from({ length: o + 1 }, (L, C) => u(n + (i - n) * C / o, s + (r - s) * I / o))), h = f.flat().filter(Number.isFinite), g = Math.min(...h), p = Math.max(...h), y = t.height ?? 1.6, a = (N) => p === g ? 0 : (Math.min(p, Math.max(g, N)) - g) / (p - g), m = (N, I, L, C = 0) => [
|
|
2117
|
+
((N - n) / (i - n) - 0.5) * c,
|
|
2118
|
+
a(L) * y + C,
|
|
2119
|
+
-((I - s) / (r - s) - 0.5) * c
|
|
2120
|
+
], b = [], x = [];
|
|
2121
|
+
for (let N = 0; N <= o; N++)
|
|
2122
|
+
for (let I = 0; I <= o; I++) {
|
|
2123
|
+
const L = f[N][I];
|
|
2124
|
+
b.push(...m(n + (i - n) * I / o, s + (r - s) * N / o, Number.isFinite(L) ? L : p)), x.push(me(t.colormap ?? "viridis", a(L)));
|
|
2125
|
+
}
|
|
2126
|
+
const w = [];
|
|
2127
|
+
for (let N = 0; N < o; N++)
|
|
2128
|
+
for (let I = 0; I < o; I++) {
|
|
2129
|
+
const L = N * (o + 1) + I, C = L + 1, Y = L + o + 1, st = Y + 1;
|
|
2130
|
+
w.push(L, C, Y, C, st, Y);
|
|
2131
|
+
}
|
|
2132
|
+
const v = Math.max(1, Math.round(t.steps ?? 40)), $ = jn(t.expr, t.start, t.rate, v, t.momentum ?? 0, d), M = $.map(([N, I]) => u(N, I)), k = 0.09, S = $.map(([N, I], L) => m(N, I, M[L], 0.06)), E = t.stepDuration ?? 250, T = 600, O = T + ($.length - 1) * E + 800, z = [
|
|
2133
|
+
{ id: "rig", kind: "group", rotation: [0, 0, 0] },
|
|
2134
|
+
{ id: "cam", kind: "camera", parent: "rig", projection: "perspective", fov: 40, near: 0.1, far: 60, position: [0, y + 3.6, 6.4], lookAt: [0, y * 0.25, 0] },
|
|
2135
|
+
{ id: "sky", kind: "light", light: "ambient", color: "#ffffff", intensity: 0.45 },
|
|
2136
|
+
{ id: "sun", kind: "light", light: "directional", color: "#ffffff", intensity: 0.85, position: [3, 6, 4] },
|
|
2137
|
+
{ id: "surface", kind: "mesh", material: "surface", geometry: { type: "mesh", positions: b, indices: w, colors: x } },
|
|
2138
|
+
// One short line per step, shown as the ball passes it.
|
|
2139
|
+
// One piece per step, shown as the ball passes it; each follows the surface between its ends
|
|
2140
|
+
// (a straight line between two points on a curved surface would dip under it).
|
|
2141
|
+
...$.slice(1).map(([N, I], L) => {
|
|
2142
|
+
const [C, Y] = $[L], st = Array.from({ length: 10 }, ($e, Ut) => {
|
|
2143
|
+
const Wt = Ut / 9, Gt = C + (N - C) * Wt, Xt = Y + (I - Y) * Wt;
|
|
2144
|
+
return m(Gt, Xt, u(Gt, Xt), 0.06);
|
|
2145
|
+
});
|
|
2146
|
+
return { id: `path${L}`, kind: "line", points: st, color: "#fc6255", width: 0.05, visible: !1 };
|
|
2147
|
+
}),
|
|
2148
|
+
{ id: "ball", kind: "mesh", material: "ball", position: [S[0][0], S[0][1] + k, S[0][2]], geometry: { type: "sphere", radius: k, segments: 16 } }
|
|
2149
|
+
], q = [
|
|
2150
|
+
{
|
|
2151
|
+
id: `${e}-ball`,
|
|
2152
|
+
target: `${e}/ball`,
|
|
2153
|
+
property: "position",
|
|
2154
|
+
// Four keys per step, on the surface, so the ball rides over bumps rather than through them.
|
|
2155
|
+
keyframes: $.flatMap(([N, I], L) => {
|
|
2156
|
+
if (L === 0) return [{ time: T, value: [S[0][0], S[0][1] + k, S[0][2]] }];
|
|
2157
|
+
const [C, Y] = $[L - 1];
|
|
2158
|
+
return [1, 2, 3, 4].map((st) => {
|
|
2159
|
+
const $e = C + (N - C) * st / 4, Ut = Y + (I - Y) * st / 4, [Wt, Gt, Xt] = m($e, Ut, u($e, Ut), 0.06);
|
|
2160
|
+
return { time: T + (L - 1 + st / 4) * E, value: [Wt, Gt + k, Xt] };
|
|
2161
|
+
});
|
|
2162
|
+
})
|
|
2163
|
+
},
|
|
2164
|
+
...S.slice(1).map((N, I) => ({
|
|
2165
|
+
id: `${e}-path${I}`,
|
|
2166
|
+
target: `${e}/path${I}`,
|
|
2167
|
+
property: "visible",
|
|
2168
|
+
keyframes: [{ time: 0, value: 0 }, { time: T + (I + 1) * E - 1, value: 0 }, { time: T + (I + 1) * E, value: 1 }]
|
|
2169
|
+
}))
|
|
2170
|
+
], A = t.orbit ?? 50;
|
|
2171
|
+
return A !== 0 && q.push({ id: `${e}-orbit`, target: `${e}/rig`, property: "rotateY", keyframes: [{ time: 0, value: -A / 2 }, { time: O, value: A / 2, easing: "ease-in-out" }] }), {
|
|
2172
|
+
scene: {
|
|
2173
|
+
id: e,
|
|
2174
|
+
camera: "cam",
|
|
2175
|
+
background: t.background ?? "#0f1117",
|
|
2176
|
+
materials: {
|
|
2177
|
+
surface: { color: "#ffffff", shading: "lambert", doubleSided: !0, creases: !1 },
|
|
2178
|
+
ball: { color: "#ffd75e", shading: "toon", outline: { width: 2, color: "#0f1117" } }
|
|
2179
|
+
},
|
|
2180
|
+
objects: z
|
|
2181
|
+
},
|
|
2182
|
+
tracks: q,
|
|
2183
|
+
duration: O,
|
|
2184
|
+
path: $,
|
|
2185
|
+
losses: M
|
|
2186
|
+
};
|
|
2187
|
+
}
|
|
2188
|
+
const tt = (t, e, n) => t + (e - t) * n;
|
|
2189
|
+
function ln(t, e, n) {
|
|
2117
2190
|
return t.kind === "stroke" ? { ...t, points: t.points.map(([i, s]) => [i + e, s + n]) } : { ...t, x: t.x + e, y: t.y + n };
|
|
2118
2191
|
}
|
|
2119
|
-
function
|
|
2192
|
+
function xs(t, e, n) {
|
|
2120
2193
|
if (t.kind === "glyph" && e.kind === "glyph" && t.text === e.text)
|
|
2121
|
-
return { ...e, x:
|
|
2194
|
+
return { ...e, x: tt(t.x, e.x, n), y: tt(t.y, e.y, n), width: tt(t.width, e.width, n), size: tt(t.size, e.size, n) };
|
|
2122
2195
|
if (t.kind === "rule" && e.kind === "rule")
|
|
2123
|
-
return { ...e, x:
|
|
2196
|
+
return { ...e, x: tt(t.x, e.x, n), y: tt(t.y, e.y, n), width: tt(t.width, e.width, n), height: tt(t.height, e.height, n) };
|
|
2124
2197
|
if (t.kind === "stroke" && e.kind === "stroke" && t.points.length === e.points.length)
|
|
2125
|
-
return { ...e, width:
|
|
2198
|
+
return { ...e, width: tt(t.width, e.width, n), points: t.points.map(([i, s], r) => [tt(i, e.points[r][0], n), tt(s, e.points[r][1], n)]) };
|
|
2126
2199
|
}
|
|
2127
|
-
const
|
|
2128
|
-
function
|
|
2129
|
-
const i = Math.min(1, Math.max(0, n)), s = t.layout.pieces.map((g) =>
|
|
2200
|
+
const Ss = (t) => t * t * (3 - 2 * t);
|
|
2201
|
+
function Es(t, e, n) {
|
|
2202
|
+
const i = Math.min(1, Math.max(0, n)), s = t.layout.pieces.map((g) => ln(g, t.x, t.y)), r = e.layout.pieces.map((g) => ln(g, e.x, e.y));
|
|
2130
2203
|
if (i === 0) return s.map((g) => ({ ...g, opacity: 1 }));
|
|
2131
2204
|
if (i === 1) return r.map((g) => ({ ...g, opacity: 1 }));
|
|
2132
2205
|
const o = (g) => {
|
|
2133
|
-
const
|
|
2134
|
-
for (const y of g)
|
|
2135
|
-
return
|
|
2136
|
-
}, c = o(s), l = o(r), d = [], u =
|
|
2206
|
+
const p = /* @__PURE__ */ new Map();
|
|
2207
|
+
for (const y of g) p.set(y.id, [...p.get(y.id) ?? [], y]);
|
|
2208
|
+
return p;
|
|
2209
|
+
}, c = o(s), l = o(r), d = [], u = Ss(i), f = Math.max(0, 1 - i * 2), h = Math.max(0, i * 2 - 1);
|
|
2137
2210
|
for (const g of /* @__PURE__ */ new Set([...c.keys(), ...l.keys()])) {
|
|
2138
|
-
const
|
|
2211
|
+
const p = c.get(g) ?? [], y = l.get(g) ?? [], a = Math.max(p.length, y.length);
|
|
2139
2212
|
for (let m = 0; m < a; m++) {
|
|
2140
|
-
const b =
|
|
2213
|
+
const b = p[m], x = y[m], w = b && x ? xs(b, x, u) : void 0;
|
|
2141
2214
|
if (w) {
|
|
2142
2215
|
d.push({ ...w, opacity: 1 });
|
|
2143
2216
|
continue;
|
|
2144
2217
|
}
|
|
2145
|
-
b && d.push({ ...b, opacity:
|
|
2218
|
+
b && d.push({ ...b, opacity: f }), x && d.push({ ...x, opacity: h });
|
|
2146
2219
|
}
|
|
2147
2220
|
}
|
|
2148
2221
|
return d.filter((g) => g.opacity > 0);
|
|
2149
2222
|
}
|
|
2150
|
-
const
|
|
2223
|
+
const un = [
|
|
2151
2224
|
"grid",
|
|
2152
2225
|
"axes",
|
|
2153
2226
|
"vector",
|
|
@@ -2177,7 +2250,7 @@ const rn = [
|
|
|
2177
2250
|
"descent",
|
|
2178
2251
|
"classifier",
|
|
2179
2252
|
"kmeans"
|
|
2180
|
-
],
|
|
2253
|
+
], De = {
|
|
2181
2254
|
dark: {
|
|
2182
2255
|
background: "#0f1117",
|
|
2183
2256
|
ink: "#f2f2f2",
|
|
@@ -2202,7 +2275,7 @@ const rn = [
|
|
|
2202
2275
|
axes: "#eef0e6",
|
|
2203
2276
|
colors: { blue: "#9fd3f0", green: "#b9e39a", red: "#f59a8f", yellow: "#f6e58d", purple: "#d0b5f2", orange: "#f7c08a", teal: "#a3e4d4", pink: "#f4b6dc", ink: "#eef0e6", grey: "#a9b0a6" }
|
|
2204
2277
|
}
|
|
2205
|
-
},
|
|
2278
|
+
}, As = /* @__PURE__ */ new Set([
|
|
2206
2279
|
"x",
|
|
2207
2280
|
"y",
|
|
2208
2281
|
"z",
|
|
@@ -2236,7 +2309,7 @@ const rn = [
|
|
|
2236
2309
|
"clipLeft",
|
|
2237
2310
|
"quaternion"
|
|
2238
2311
|
]);
|
|
2239
|
-
function
|
|
2312
|
+
function Et(t) {
|
|
2240
2313
|
const e = (a) => {
|
|
2241
2314
|
throw new Error(`math figure: ${a}`);
|
|
2242
2315
|
};
|
|
@@ -2245,37 +2318,37 @@ function xt(t) {
|
|
|
2245
2318
|
const m = t[a];
|
|
2246
2319
|
m !== void 0 && !(Array.isArray(m) && m.length === 2 && m.every(Number.isFinite) && m[0] < m[1]) && e(`${a} must be [min, max] with min < max`);
|
|
2247
2320
|
}
|
|
2248
|
-
t.theme !== void 0 && !(t.theme in
|
|
2321
|
+
t.theme !== void 0 && !(t.theme in De) && e(R("theme", t.theme, Object.keys(De))), Array.isArray(t.items) || e("items must be an array");
|
|
2249
2322
|
const n = t.values ?? {};
|
|
2250
2323
|
for (const [a, m] of Object.entries(n))
|
|
2251
|
-
/^[A-Za-z_]\w*$/.test(a) || e(`value name "${a}" must be letters, digits and _ (starting with a letter)`),
|
|
2252
|
-
const i =
|
|
2253
|
-
b !== void 0 && (typeof b == "string" ? (b in n || e(`${a.id}.${m}: ${
|
|
2324
|
+
/^[A-Za-z_]\w*$/.test(a) || e(`value name "${a}" must be letters, digits and _ (starting with a letter)`), As.has(a) && e(`"${a}" cannot name a value: it is ${a === "x" || a === "t" ? "the variable of functions and curves" : "a property of the figure itself (its place, size or look)"}`), typeof m == "number" && Number.isFinite(m) || ot(m) || $t(m) || e(`value "${a}" must be a number, an [x, y] vector or an [a, b, c, d] matrix`);
|
|
2325
|
+
const i = vn(n), s = Object.keys(n).filter((a) => typeof n[a] == "number"), r = (a, m, b) => {
|
|
2326
|
+
b !== void 0 && (typeof b == "string" ? (b in n || e(`${a.id}.${m}: ${R("value", b, Object.keys(n))}`), ot(n[b]) || e(`${a.id}.${m}: value "${b}" is not an [x, y] vector`)) : ot(b) || e(`${a.id}.${m} must be [x, y] or the name of a vector value`));
|
|
2254
2327
|
}, o = (a, m, b) => {
|
|
2255
|
-
b !== void 0 && (b in n || e(`${a.id}.${m}: ${
|
|
2328
|
+
b !== void 0 && (b in n || e(`${a.id}.${m}: ${R("value", b, Object.keys(n))}`), $t(n[b]) || e(`${a.id}.${m}: value "${b}" is not an [a, b, c, d] matrix`));
|
|
2256
2329
|
}, c = (a, m, b, x) => {
|
|
2257
2330
|
let w = [];
|
|
2258
2331
|
try {
|
|
2259
|
-
w =
|
|
2332
|
+
w = Ke(ct(b));
|
|
2260
2333
|
} catch (v) {
|
|
2261
2334
|
e(`${a.id}.${m}: ${v.message}`);
|
|
2262
2335
|
}
|
|
2263
2336
|
for (const v of w)
|
|
2264
|
-
v !== x && !(v in
|
|
2337
|
+
v !== x && !(v in oe) && !s.includes(v) && e(`${a.id}.${m}: "${v}" is neither ${x} nor a number value (${R("value", v, [x, ...s])})`);
|
|
2265
2338
|
}, l = [], d = (a, m, b) => {
|
|
2266
2339
|
l.push([a, m, b]);
|
|
2267
2340
|
}, u = (a, m, b) => {
|
|
2268
|
-
b !== void 0 && (typeof b == "string" ? (b in n || e(`${a.id}.${m}: ${
|
|
2269
|
-
},
|
|
2270
|
-
(!b || typeof b != "object" || !
|
|
2341
|
+
b !== void 0 && (typeof b == "string" ? (b in n || e(`${a.id}.${m}: ${R("value", b, s)}`), typeof n[b] != "number" && e(`${a.id}.${m}: value "${b}" is not a number`)) : Number.isFinite(b) || e(`${a.id}.${m} must be a number or the name of a number value`));
|
|
2342
|
+
}, f = (a, m, b) => {
|
|
2343
|
+
(!b || typeof b != "object" || !ae.includes(b.kind)) && e(`${a.id}.${m}: ${R("distribution", b?.kind, ae)}`);
|
|
2271
2344
|
for (const [w, v] of Object.entries(b))
|
|
2272
|
-
w !== "kind" && (w === "of" ?
|
|
2273
|
-
const x =
|
|
2345
|
+
w !== "kind" && (w === "of" ? f(a, `${m}.of`, v) : u(a, `${m}.${w}`, v));
|
|
2346
|
+
const x = kn(Mt(n, b));
|
|
2274
2347
|
x && e(`${a.id}.${m}: ${x}`);
|
|
2275
2348
|
}, h = (a, m, b) => {
|
|
2276
2349
|
let x = [];
|
|
2277
2350
|
try {
|
|
2278
|
-
x =
|
|
2351
|
+
x = Ke(ct(b));
|
|
2279
2352
|
} catch (w) {
|
|
2280
2353
|
e(`${a.id}.${m}: ${w.message}`);
|
|
2281
2354
|
}
|
|
@@ -2283,14 +2356,14 @@ function xt(t) {
|
|
|
2283
2356
|
w !== "x" && w !== "y" && !s.includes(w) && e(`${a.id}.${m}: "${w}" is neither x, y nor a number value`);
|
|
2284
2357
|
}, g = (a, m, b, x) => {
|
|
2285
2358
|
try {
|
|
2286
|
-
let w =
|
|
2287
|
-
for (let v = 0; v < x; v++) w =
|
|
2359
|
+
let w = ct(b);
|
|
2360
|
+
for (let v = 0; v < x; v++) w = Z(w);
|
|
2288
2361
|
} catch (w) {
|
|
2289
2362
|
e(`${a.id}.${m}: ${w.message} (calculus needs functions with derivatives)`);
|
|
2290
2363
|
}
|
|
2291
|
-
},
|
|
2364
|
+
}, p = /* @__PURE__ */ new Set();
|
|
2292
2365
|
for (const a of t.items)
|
|
2293
|
-
switch ((!a || typeof a != "object") && e("every item must be an object"),
|
|
2366
|
+
switch ((!a || typeof a != "object") && e("every item must be an object"), un.includes(a.kind) || e(R("item kind", a.kind, un)), (typeof a.id != "string" || !/^[A-Za-z_][\w-]*$/.test(a.id)) && e(`a ${a.kind} needs an id (letters, digits, _ and -)`), p.has(a.id) && e(`two items have the id "${a.id}"`), a.id in n && e(`"${a.id}" is both an item id and a value name`), p.add(a.id), a.kind) {
|
|
2294
2367
|
case "grid":
|
|
2295
2368
|
a.step !== void 0 && !(a.step > 0) && e(`${a.id}.step must be positive`), o(a, "transform", a.transform);
|
|
2296
2369
|
break;
|
|
@@ -2310,22 +2383,22 @@ function xt(t) {
|
|
|
2310
2383
|
c(a, "expr", a.expr, "x"), g(a, "expr", a.expr, 1), u(a, "at", a.at), u(a, "h", a.h), a.label && d(a, "label", a.label);
|
|
2311
2384
|
break;
|
|
2312
2385
|
case "riemann":
|
|
2313
|
-
c(a, "expr", a.expr, "x"), u(a, "from", a.from), u(a, "to", a.to), u(a, "n", a.n), a.rule !== void 0 && !["left", "right", "midpoint", "trapezoid"].includes(a.rule) && e(`${a.id}.rule: ${
|
|
2386
|
+
c(a, "expr", a.expr, "x"), u(a, "from", a.from), u(a, "to", a.to), u(a, "n", a.n), a.rule !== void 0 && !["left", "right", "midpoint", "trapezoid"].includes(a.rule) && e(`${a.id}.rule: ${R("rule", a.rule, ["left", "right", "midpoint", "trapezoid"])}`);
|
|
2314
2387
|
break;
|
|
2315
2388
|
case "area":
|
|
2316
2389
|
c(a, "expr", a.expr, "x"), a.lower !== void 0 && c(a, "lower", a.lower, "x"), u(a, "from", a.from), u(a, "to", a.to);
|
|
2317
2390
|
break;
|
|
2318
2391
|
case "histogram":
|
|
2319
|
-
|
|
2392
|
+
f(a, "distribution", a.distribution), u(a, "count", a.count), a.bins !== void 0 && !(Array.isArray(a.bins) && a.bins.length === 3 && a.bins[1] > a.bins[0] && Number.isInteger(a.bins[2]) && a.bins[2] >= 1 && a.bins[2] <= 500) && e(`${a.id}.bins must be [from, to, count] with from < to and a whole count 1..500`);
|
|
2320
2393
|
break;
|
|
2321
2394
|
case "distribution":
|
|
2322
|
-
|
|
2395
|
+
f(a, "distribution", a.distribution), a.shade && a.shade.forEach((m, b) => u(a, `shade[${b}]`, m));
|
|
2323
2396
|
break;
|
|
2324
2397
|
case "galton":
|
|
2325
2398
|
a.rows !== void 0 && !(Number.isInteger(a.rows) && a.rows >= 1 && a.rows <= 30) && e(`${a.id}.rows must be a whole number 1..30`), u(a, "balls", a.balls);
|
|
2326
2399
|
break;
|
|
2327
2400
|
case "scatter":
|
|
2328
|
-
(!a.points || !["uniform", "linear"].includes(a.points.kind)) && e(`${a.id}.points: ${
|
|
2401
|
+
(!a.points || !["uniform", "linear"].includes(a.points.kind)) && e(`${a.id}.points: ${R("points kind", a.points?.kind, ["uniform", "linear"])}`), a.points.kind === "linear" && (u(a, "points.slope", a.points.slope), u(a, "points.intercept", a.points.intercept), u(a, "points.noise", a.points.noise)), u(a, "count", a.count), a.inside && h(a, "inside", a.inside);
|
|
2329
2402
|
break;
|
|
2330
2403
|
case "bayes":
|
|
2331
2404
|
u(a, "prior", a.prior), u(a, "truePositive", a.truePositive), u(a, "falsePositive", a.falsePositive);
|
|
@@ -2335,13 +2408,13 @@ function xt(t) {
|
|
|
2335
2408
|
const m = a.nodes.map((v) => v.id);
|
|
2336
2409
|
new Set(m).size !== m.length && e(`${a.id}: two nodes share an id`);
|
|
2337
2410
|
const b = (v, $) => {
|
|
2338
|
-
m.includes($) || e(`${a.id}.${v}: ${
|
|
2411
|
+
m.includes($) || e(`${a.id}.${v}: ${R("node", $, m)}`);
|
|
2339
2412
|
};
|
|
2340
|
-
Array.isArray(a.edges) || e(`${a.id}.edges must be an array`),
|
|
2413
|
+
Array.isArray(a.edges) || e(`${a.id}.edges must be an array`), ye(a).forEach((v, $) => {
|
|
2341
2414
|
b(`edges[${$}]`, v.from), b(`edges[${$}]`, v.to), v.weight !== void 0 && !(v.weight >= 0) && e(`${a.id}.edges[${$}]: weights must be ≥ 0 (shortest paths need them)`);
|
|
2342
2415
|
}), a.tree && b("tree.root", a.tree.root);
|
|
2343
|
-
const x =
|
|
2344
|
-
w.length && e(`${a.id}: nodes ${w.join(", ")} have no "at" and are not reached from the tree root`), a.search && (
|
|
2416
|
+
const x = Ln(a), w = m.filter((v) => !x.has(v));
|
|
2417
|
+
w.length && e(`${a.id}: nodes ${w.join(", ")} have no "at" and are not reached from the tree root`), a.search && (on.includes(a.search.kind) || e(`${a.id}.search: ${R("search", a.search.kind, on)}`), b("search.start", a.search.start)), u(a, "step", a.step), a.nodes.forEach((v) => v.label !== void 0 && d(a, `nodes.${v.id}.label`, v.label));
|
|
2345
2418
|
break;
|
|
2346
2419
|
}
|
|
2347
2420
|
case "venn": {
|
|
@@ -2349,8 +2422,8 @@ function xt(t) {
|
|
|
2349
2422
|
const m = a.sets.map((b) => b.id);
|
|
2350
2423
|
if (m.every((b) => /^[A-Za-z]\w*$/.test(b)) || e(`${a.id}.sets: ids must be names like A, B, Evens`), a.highlight)
|
|
2351
2424
|
try {
|
|
2352
|
-
for (const b of
|
|
2353
|
-
m.includes(b) || e(`${a.id}.highlight: ${
|
|
2425
|
+
for (const b of se(Pn(a.highlight)))
|
|
2426
|
+
m.includes(b) || e(`${a.id}.highlight: ${R("set", b, m)}`);
|
|
2354
2427
|
} catch (b) {
|
|
2355
2428
|
e(`${a.id}.highlight: ${b.message}`);
|
|
2356
2429
|
}
|
|
@@ -2358,29 +2431,29 @@ function xt(t) {
|
|
|
2358
2431
|
break;
|
|
2359
2432
|
}
|
|
2360
2433
|
case "network":
|
|
2361
|
-
(!Array.isArray(a.layers) || a.layers.length < 2 || a.layers.length > 8 || !a.layers.every((m) => Number.isInteger(m) && m >= 1 && m <= 12)) && e(`${a.id}.layers: give 2 to 8 layers of 1 to 12 nodes, like [3, 4, 2]`), a.activation !== void 0 && !
|
|
2434
|
+
(!Array.isArray(a.layers) || a.layers.length < 2 || a.layers.length > 8 || !a.layers.every((m) => Number.isInteger(m) && m >= 1 && m <= 12)) && e(`${a.id}.layers: give 2 to 8 layers of 1 to 12 nodes, like [3, 4, 2]`), a.activation !== void 0 && !an.includes(a.activation) && e(`${a.id}.activation: ${R("activation", a.activation, an)}`), a.inputs && a.inputs.length > a.layers[0] && e(`${a.id}.inputs: more inputs than the ${a.layers[0]} input nodes`), a.inputs?.forEach((m, b) => u(a, `inputs[${b}]`, m)), u(a, "flow", a.flow), a.labels?.inputs?.forEach((m, b) => d(a, `labels.inputs[${b}]`, m)), a.labels?.outputs?.forEach((m, b) => d(a, `labels.outputs[${b}]`, m));
|
|
2362
2435
|
break;
|
|
2363
2436
|
case "heatmap":
|
|
2364
|
-
a.cells === void 0 == (a.expr === void 0) && e(`${a.id} needs exactly one of cells or expr`), a.cells && !(Array.isArray(a.cells) && a.cells.length >= 1 && a.cells.length <= 64 && a.cells.every((m) => Array.isArray(m) && m.length === a.cells[0].length && m.length <= 64 && m.every(Number.isFinite))) && e(`${a.id}.cells must be up to 64 equal rows of up to 64 numbers`), a.expr && h(a, "expr", a.expr), a.resolution !== void 0 && !(Number.isInteger(a.resolution) && a.resolution >= 4 && a.resolution <= 120) && e(`${a.id}.resolution must be 4..120`), a.colormap !== void 0 && !
|
|
2437
|
+
a.cells === void 0 == (a.expr === void 0) && e(`${a.id} needs exactly one of cells or expr`), a.cells && !(Array.isArray(a.cells) && a.cells.length >= 1 && a.cells.length <= 64 && a.cells.every((m) => Array.isArray(m) && m.length === a.cells[0].length && m.length <= 64 && m.every(Number.isFinite))) && e(`${a.id}.cells must be up to 64 equal rows of up to 64 numbers`), a.expr && h(a, "expr", a.expr), a.resolution !== void 0 && !(Number.isInteger(a.resolution) && a.resolution >= 4 && a.resolution <= 120) && e(`${a.id}.resolution must be 4..120`), a.colormap !== void 0 && !Kt.includes(a.colormap) && e(`${a.id}.colormap: ${R("colormap", a.colormap, Kt)}`), a.rowLabels?.forEach((m, b) => d(a, `rowLabels[${b}]`, m)), a.colLabels?.forEach((m, b) => d(a, `colLabels[${b}]`, m));
|
|
2365
2438
|
break;
|
|
2366
2439
|
case "contours":
|
|
2367
|
-
h(a, "expr", a.expr), a.colormap !== void 0 && !
|
|
2440
|
+
h(a, "expr", a.expr), a.colormap !== void 0 && !Kt.includes(a.colormap) && e(`${a.id}.colormap: ${R("colormap", a.colormap, Kt)}`), a.resolution !== void 0 && !(Number.isInteger(a.resolution) && a.resolution >= 8 && a.resolution <= 200) && e(`${a.id}.resolution must be 8..200`);
|
|
2368
2441
|
break;
|
|
2369
2442
|
case "descent":
|
|
2370
2443
|
h(a, "expr", a.expr);
|
|
2371
2444
|
for (const m of ["x", "y"])
|
|
2372
2445
|
try {
|
|
2373
|
-
|
|
2446
|
+
Z(ct(a.expr), m);
|
|
2374
2447
|
} catch (b) {
|
|
2375
2448
|
e(`${a.id}.expr: ${b.message} (descent needs a gradient)`);
|
|
2376
2449
|
}
|
|
2377
2450
|
r(a, "start", a.start), u(a, "rate", a.rate), u(a, "steps", a.steps), u(a, "momentum", a.momentum);
|
|
2378
2451
|
break;
|
|
2379
2452
|
case "classifier":
|
|
2380
|
-
u(a, "epochs", a.epochs), a.count !== void 0 && !(Number.isInteger(a.count) && a.count >= 1 && a.count <= 500) && e(`${a.id}.count must be 1..500 points per cluster`), a.centres !== void 0 && !(a.centres.length === 2 && a.centres.every(
|
|
2453
|
+
u(a, "epochs", a.epochs), a.count !== void 0 && !(Number.isInteger(a.count) && a.count >= 1 && a.count <= 500) && e(`${a.id}.count must be 1..500 points per cluster`), a.centres !== void 0 && !(a.centres.length === 2 && a.centres.every(ot)) && e(`${a.id}.centres must be two [x, y] points`);
|
|
2381
2454
|
break;
|
|
2382
2455
|
case "kmeans":
|
|
2383
|
-
(!Array.isArray(a.centres) || a.centres.length < 1 || a.centres.length > 6 || !a.centres.every(
|
|
2456
|
+
(!Array.isArray(a.centres) || a.centres.length < 1 || a.centres.length > 6 || !a.centres.every(ot)) && e(`${a.id}.centres: give 1 to 6 [x, y] cluster centres`), a.k !== void 0 && !(Number.isInteger(a.k) && a.k >= 1 && a.k <= 6) && e(`${a.id}.k must be 1..6`), u(a, "iteration", a.iteration);
|
|
2384
2457
|
break;
|
|
2385
2458
|
case "clock":
|
|
2386
2459
|
(!Number.isInteger(a.modulus) || a.modulus < 2 || a.modulus > 60) && e(`${a.id}.modulus must be a whole number 2..60`), u(a, "value", a.value);
|
|
@@ -2392,7 +2465,7 @@ function xt(t) {
|
|
|
2392
2465
|
c(a, "x", a.x, "t"), c(a, "y", a.y, "t"), o(a, "transform", a.transform);
|
|
2393
2466
|
break;
|
|
2394
2467
|
case "polygon":
|
|
2395
|
-
a.points !== void 0 && !(Array.isArray(a.points) && a.points.length >= 3 && a.points.every(
|
|
2468
|
+
a.points !== void 0 && !(Array.isArray(a.points) && a.points.length >= 3 && a.points.every(ot)) && e(`${a.id}.points must be three or more [x, y] points`), o(a, "transform", a.transform), a.label && d(a, "label", a.label);
|
|
2396
2469
|
break;
|
|
2397
2470
|
case "line":
|
|
2398
2471
|
a.along === void 0 == (a.eigen === void 0) && e(`${a.id} needs exactly one of along or eigen`), r(a, "along", a.along), o(a, "eigen", a.eigen);
|
|
@@ -2404,7 +2477,7 @@ function xt(t) {
|
|
|
2404
2477
|
r(a, "at", a.at), (!Array.isArray(a.steps) || a.steps.length === 0) && e(`${a.id}.steps needs at least one TeX step`), a.steps.forEach((m, b) => d(a, `steps[${b}]`, m));
|
|
2405
2478
|
break;
|
|
2406
2479
|
}
|
|
2407
|
-
const y = { ...i, ...
|
|
2480
|
+
const y = { ...i, ...Gn(t.items, n, i) };
|
|
2408
2481
|
for (const [a, m, b] of l)
|
|
2409
2482
|
try {
|
|
2410
2483
|
U(b, { values: y });
|
|
@@ -2413,7 +2486,7 @@ function xt(t) {
|
|
|
2413
2486
|
}
|
|
2414
2487
|
return t;
|
|
2415
2488
|
}
|
|
2416
|
-
function
|
|
2489
|
+
function Xn(t) {
|
|
2417
2490
|
const { width: e, height: n } = t, i = t.x ?? [-5, 5], s = e / (i[1] - i[0]), r = t.y ?? [-(n / s) / 2, n / s / 2], o = n / (r[1] - r[0]);
|
|
2418
2491
|
return {
|
|
2419
2492
|
width: e,
|
|
@@ -2427,112 +2500,112 @@ function Bn(t) {
|
|
|
2427
2500
|
toWorld: ([c, l]) => [i[0] + c / s, r[1] - l / o]
|
|
2428
2501
|
};
|
|
2429
2502
|
}
|
|
2430
|
-
function
|
|
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, o] = e, c = Math.hypot(i, s, r, o), l = c === 0 ? 0 : Math.abs(
|
|
2503
|
+
function Ts(t, e) {
|
|
2504
|
+
const n = Math.max(Math.abs(t.x[0]), Math.abs(t.x[1]), Math.abs(t.y[0]), Math.abs(t.y[1])), [i, s, r, o] = e, c = Math.hypot(i, s, r, o), l = c === 0 ? 0 : Math.abs(jt(e)) / c;
|
|
2432
2505
|
return Math.min(n * 12, n / Math.max(l, 0.08)) + 1;
|
|
2433
2506
|
}
|
|
2434
|
-
function
|
|
2435
|
-
const i =
|
|
2507
|
+
function dn(t, e, n) {
|
|
2508
|
+
const i = Ts(t, e), s = Math.min(120, Math.ceil(i / n)), r = [];
|
|
2436
2509
|
for (let o = -s; o <= s; o++) {
|
|
2437
2510
|
const c = o * n;
|
|
2438
|
-
r.push({ line: [
|
|
2511
|
+
r.push({ line: [nt(e, [c, -i]), nt(e, [c, i])].map(t.toScreen), axis: o === 0 }), r.push({ line: [nt(e, [-i, c]), nt(e, [i, c])].map(t.toScreen), axis: o === 0 });
|
|
2439
2512
|
}
|
|
2440
2513
|
return r;
|
|
2441
2514
|
}
|
|
2442
|
-
function
|
|
2515
|
+
function Os(t, e) {
|
|
2443
2516
|
const { plane: n, theme: i } = e, s = t.step ?? 1, r = [], o = 1.4 * n.scale;
|
|
2444
2517
|
if (t.ghost)
|
|
2445
|
-
for (const [l, { line: d }] of
|
|
2518
|
+
for (const [l, { line: d }] of dn(n, [1, 0, 0, 1], s).entries())
|
|
2446
2519
|
r.push({ type: "line", id: `${t.id}.ghost.${l}`, points: d, stroke: i.ghost, width: o, opacity: e.opacity });
|
|
2447
|
-
const c =
|
|
2448
|
-
for (const [l, { line: d, axis: u }] of
|
|
2449
|
-
const [
|
|
2450
|
-
|
|
2520
|
+
const c = F(i, t.color, i.grid);
|
|
2521
|
+
for (const [l, { line: d, axis: u }] of dn(n, bt(e.values, t.transform), s).entries()) {
|
|
2522
|
+
const [f] = V([d], e.draw);
|
|
2523
|
+
f && r.push({ type: "line", id: `${t.id}.${l}`, points: f, stroke: u ? i.ink : c, width: u ? o * 1.6 : o, opacity: e.opacity });
|
|
2451
2524
|
}
|
|
2452
2525
|
return r;
|
|
2453
2526
|
}
|
|
2454
|
-
function
|
|
2455
|
-
const { plane: n, theme: i } = e, s =
|
|
2527
|
+
function Ns(t, e) {
|
|
2528
|
+
const { plane: n, theme: i } = e, s = F(i, t.color, i.axes), r = 2 * n.scale, o = e.opacity, c = V([[n.toScreen([n.x[0], 0]), n.toScreen([n.x[1], 0])]], e.draw), l = V([[n.toScreen([0, n.y[0]]), n.toScreen([0, n.y[1]])]], e.draw), d = [...c, ...l].map((y, a) => ({ type: "line", id: `${t.id}.${a ? "y" : "x"}`, points: y, stroke: s, width: r, opacity: o })), u = t.ticks ?? 1;
|
|
2456
2529
|
if (u <= 0 || e.draw < 1) return d;
|
|
2457
|
-
const
|
|
2530
|
+
const f = 5 * n.scale, h = 13 * n.scale, g = (y, a) => {
|
|
2458
2531
|
const m = [];
|
|
2459
2532
|
for (let b = Math.ceil(y / u) * u; b <= a + 1e-9; b += u) Math.abs(b) > 1e-9 && m.push(Number(b.toFixed(6)));
|
|
2460
2533
|
return m;
|
|
2461
|
-
},
|
|
2534
|
+
}, p = (y) => String(y).replace("-", "−");
|
|
2462
2535
|
for (const y of g(n.x[0], n.x[1])) {
|
|
2463
2536
|
const [a, m] = n.toScreen([y, 0]);
|
|
2464
|
-
d.push({ type: "line", id: `${t.id}.tick.x${y}`, points: [[a, m -
|
|
2537
|
+
d.push({ type: "line", id: `${t.id}.tick.x${y}`, points: [[a, m - f], [a, m + f]], stroke: s, width: r * 0.8, opacity: o }), t.labels !== !1 && d.push({ type: "text", id: `${t.id}.label.x${y}`, text: p(y), x: a, y: m + f + h * 1.1, size: h, font: pt, color: s, align: "center", opacity: o * 0.8 });
|
|
2465
2538
|
}
|
|
2466
2539
|
for (const y of g(n.y[0], n.y[1])) {
|
|
2467
2540
|
const [a, m] = n.toScreen([0, y]);
|
|
2468
|
-
d.push({ type: "line", id: `${t.id}.tick.y${y}`, points: [[a -
|
|
2541
|
+
d.push({ type: "line", id: `${t.id}.tick.y${y}`, points: [[a - f, m], [a + f, m]], stroke: s, width: r * 0.8, opacity: o }), t.labels !== !1 && d.push({ type: "text", id: `${t.id}.label.y${y}`, text: p(y), x: a - f - h * 0.4, y: m + h * 0.35, size: h, font: pt, color: s, align: "right", opacity: o * 0.8 });
|
|
2469
2542
|
}
|
|
2470
2543
|
return d;
|
|
2471
2544
|
}
|
|
2472
|
-
function
|
|
2473
|
-
const o = 26 * r.plane.scale, [c, l] =
|
|
2545
|
+
function de(t, e, n, i, s, r) {
|
|
2546
|
+
const o = 26 * r.plane.scale, [c, l] = Lt(n), d = U(t, { values: r.scope, style: "inline" }), u = o * (0.55 + Math.abs(c) * d.width * 0.5);
|
|
2474
2547
|
return X(d, { x: e[0] + c * u, y: e[1] + l * u, size: o, color: i, opacity: r.opacity, idPrefix: `${s}.label.` });
|
|
2475
2548
|
}
|
|
2476
|
-
function
|
|
2549
|
+
function Yn(t, e, n, i, s, r) {
|
|
2477
2550
|
const o = r.plane.toScreen(e), c = r.plane.toScreen(n), [l] = V([[o, c]], r.draw);
|
|
2478
2551
|
if (!l) return [];
|
|
2479
2552
|
const d = Math.hypot(c[0] - o[0], c[1] - o[1]), u = Math.min(s * 3.6, d * 0.45);
|
|
2480
2553
|
return [{ type: "arrow", id: t, points: l, stroke: i, width: s, head: u, opacity: r.opacity }];
|
|
2481
2554
|
}
|
|
2482
|
-
function
|
|
2483
|
-
const n =
|
|
2555
|
+
function Is(t, e) {
|
|
2556
|
+
const n = bt(e.values, t.transform), i = nt(n, t.from === void 0 ? [0, 0] : kt(e.values, t.from)), s = nt(n, kt(e.values, t.to)), r = F(e.theme, t.color, e.theme.colors.yellow), o = Yn(t.id, i, s, r, (t.width ?? 4) * e.plane.scale, e);
|
|
2484
2557
|
if (t.label && e.draw >= 1) {
|
|
2485
|
-
const c = e.plane.toScreen(s), l = e.plane.toScreen(i), d =
|
|
2558
|
+
const c = e.plane.toScreen(s), l = e.plane.toScreen(i), d = Re(c, l);
|
|
2486
2559
|
if (t.labelAt === "middle") {
|
|
2487
2560
|
const u = [(c[0] + l[0]) / 2, (c[1] + l[1]) / 2];
|
|
2488
|
-
o.push(...
|
|
2561
|
+
o.push(...de(t.label, u, [d[1], -d[0]], r, t.id, e));
|
|
2489
2562
|
} else
|
|
2490
|
-
o.push(...
|
|
2563
|
+
o.push(...de(t.label, c, d, r, t.id, e));
|
|
2491
2564
|
}
|
|
2492
2565
|
return o;
|
|
2493
2566
|
}
|
|
2494
|
-
function
|
|
2495
|
-
const n =
|
|
2567
|
+
function Ps(t, e) {
|
|
2568
|
+
const n = bt(e.values, t.transform), i = 4.5 * e.plane.scale, s = e.plane.toScreen([0, 0]), r = [], o = [
|
|
2496
2569
|
["i", [1, 0], e.theme.colors.green, "\\hat{i}"],
|
|
2497
2570
|
["j", [0, 1], e.theme.colors.red, "\\hat{j}"]
|
|
2498
2571
|
];
|
|
2499
2572
|
for (const [c, l, d, u] of o) {
|
|
2500
|
-
const
|
|
2501
|
-
if (r.push(...
|
|
2502
|
-
const h = e.plane.toScreen(
|
|
2503
|
-
r.push(...
|
|
2573
|
+
const f = nt(n, l);
|
|
2574
|
+
if (r.push(...Yn(`${t.id}.${c}`, [0, 0], f, d, i, e)), t.labels !== !1 && e.draw >= 1) {
|
|
2575
|
+
const h = e.plane.toScreen(f);
|
|
2576
|
+
r.push(...de(u, h, Re(h, s), d, `${t.id}.${c}`, e));
|
|
2504
2577
|
}
|
|
2505
2578
|
}
|
|
2506
2579
|
return r;
|
|
2507
2580
|
}
|
|
2508
|
-
function
|
|
2509
|
-
const n = t.on !== void 0 ? [e.scope[`${t.id}.x`], e.scope[`${t.id}.y`]] :
|
|
2581
|
+
function Fs(t, e) {
|
|
2582
|
+
const n = t.on !== void 0 ? [e.scope[`${t.id}.x`], e.scope[`${t.id}.y`]] : kt(e.values, t.at);
|
|
2510
2583
|
if (!Number.isFinite(n[0]) || !Number.isFinite(n[1])) return [];
|
|
2511
|
-
const i =
|
|
2512
|
-
return t.label && e.draw >= 1 && d.push(...
|
|
2584
|
+
const i = nt(bt(e.values, t.transform), n), [s, r] = e.plane.toScreen(i), o = F(e.theme, t.color, e.theme.colors.yellow), c = (t.radius ?? 6) * e.plane.scale * Math.min(1, e.draw * 2), l = t.hollow ? { type: "circle", id: t.id, x: s, y: r, r: c, fill: e.theme.background, stroke: o, width: 2.5 * e.plane.scale, opacity: e.opacity } : { type: "circle", id: t.id, x: s, y: r, r: c, fill: o, opacity: e.opacity }, d = c > 0 ? [l] : [];
|
|
2585
|
+
return t.label && e.draw >= 1 && d.push(...de(t.label, [s, r], [0.7, -0.7], o, t.id, e)), d;
|
|
2513
2586
|
}
|
|
2514
|
-
const
|
|
2515
|
-
function
|
|
2516
|
-
const n =
|
|
2587
|
+
const Ls = [[0, 0], [1, 0], [1, 1], [0, 1]];
|
|
2588
|
+
function Cs(t, e) {
|
|
2589
|
+
const n = bt(e.values, t.transform), i = (t.points ?? Ls).map((c) => nt(n, c)), s = i.map(e.plane.toScreen), r = F(e.theme, t.color, e.theme.colors.yellow), o = [
|
|
2517
2590
|
{ type: "line", id: `${t.id}.fill`, points: s, closed: !0, fill: r, opacity: e.opacity * (t.fillOpacity ?? 0.3) * e.draw },
|
|
2518
2591
|
...V([[...s, s[0]]], e.draw).map((c) => ({ type: "line", id: `${t.id}.outline`, points: c, stroke: r, width: 2.5 * e.plane.scale, opacity: e.opacity }))
|
|
2519
2592
|
];
|
|
2520
2593
|
if (t.label && e.draw >= 1) {
|
|
2521
|
-
const c = i.reduce((u,
|
|
2594
|
+
const c = i.reduce((u, f) => [u[0] + f[0] / i.length, u[1] + f[1] / i.length], [0, 0]), [l, d] = e.plane.toScreen(c);
|
|
2522
2595
|
o.push(...X(U(t.label, { values: e.scope, style: "inline" }), { x: l, y: d, size: 24 * e.plane.scale, color: e.theme.ink, opacity: e.opacity, idPrefix: `${t.id}.label.` }));
|
|
2523
2596
|
}
|
|
2524
2597
|
return o;
|
|
2525
2598
|
}
|
|
2526
|
-
function
|
|
2527
|
-
const n = t.eigen ?
|
|
2599
|
+
function qs(t, e) {
|
|
2600
|
+
const n = t.eigen ? bn(bt(e.values, t.eigen)).map((o) => o.vector) : t.along !== void 0 ? [kt(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 = F(e.theme, t.color, e.theme.colors.yellow), r = (t.width ?? 2.5) * e.plane.scale;
|
|
2528
2601
|
return n.flatMap((o, c) => {
|
|
2529
2602
|
const l = Math.hypot(o[0], o[1]);
|
|
2530
2603
|
if (l === 0) return [];
|
|
2531
|
-
const d =
|
|
2532
|
-
return V([u], e.draw).map((
|
|
2604
|
+
const d = Oe(o, i / l), u = [Oe(d, -1), d].map(e.plane.toScreen);
|
|
2605
|
+
return V([u], e.draw).map((f) => ({
|
|
2533
2606
|
type: "line",
|
|
2534
2607
|
id: `${t.id}.${c}`,
|
|
2535
|
-
points:
|
|
2608
|
+
points: f,
|
|
2536
2609
|
stroke: s,
|
|
2537
2610
|
width: r,
|
|
2538
2611
|
opacity: e.opacity,
|
|
@@ -2540,12 +2613,12 @@ function Is(t, e) {
|
|
|
2540
2613
|
}));
|
|
2541
2614
|
});
|
|
2542
2615
|
}
|
|
2543
|
-
function
|
|
2616
|
+
function _e(t, e, n, i) {
|
|
2544
2617
|
const s = n.size * 0.35;
|
|
2545
2618
|
let r = 1 / 0, o = 1 / 0, c = -1 / 0, l = -1 / 0;
|
|
2546
2619
|
for (const d of e) {
|
|
2547
|
-
const [u,
|
|
2548
|
-
r = Math.min(r, u - s), c = Math.max(c, u + d.width * n.size + s), o = Math.min(o,
|
|
2620
|
+
const [u, f] = He(d, n);
|
|
2621
|
+
r = Math.min(r, u - s), c = Math.max(c, u + d.width * n.size + s), o = Math.min(o, f - d.height * n.size - s), l = Math.max(l, f + d.depth * n.size + s);
|
|
2549
2622
|
}
|
|
2550
2623
|
return [{
|
|
2551
2624
|
type: "line",
|
|
@@ -2556,194 +2629,194 @@ function Ie(t, e, n, i) {
|
|
|
2556
2629
|
opacity: (n.opacity ?? 1) * 0.85
|
|
2557
2630
|
}];
|
|
2558
2631
|
}
|
|
2559
|
-
function
|
|
2560
|
-
const i =
|
|
2632
|
+
function Zn(t, e, n) {
|
|
2633
|
+
const i = kt(n.values, t);
|
|
2561
2634
|
return e ? i : n.plane.toScreen(i);
|
|
2562
2635
|
}
|
|
2563
|
-
function
|
|
2564
|
-
const [n, i] =
|
|
2565
|
-
return [...t.backdrop ?? t.screen ?? !1 ?
|
|
2636
|
+
function zs(t, e) {
|
|
2637
|
+
const [n, i] = Zn(t.at, t.screen, e), s = (t.size ?? 28) * e.plane.scale, r = F(e.theme, t.color, e.theme.ink), o = { x: n, y: i, size: s, color: r, align: t.align, opacity: e.opacity * e.draw, idPrefix: `${t.id}.`, palette: e.theme.colors }, c = U(t.tex, { values: e.scope });
|
|
2638
|
+
return [...t.backdrop ?? t.screen ?? !1 ? _e(t.id, [c], o, e) : [], ...X(c, o)];
|
|
2566
2639
|
}
|
|
2567
|
-
function
|
|
2568
|
-
const [n, i] =
|
|
2640
|
+
function js(t, e) {
|
|
2641
|
+
const [n, i] = Zn(t.at, t.screen, e), s = (t.size ?? 36) * e.plane.scale, r = F(e.theme, t.color, e.theme.ink), o = t.steps.length - 1, c = Math.min(o, Math.max(0, e.prop("step") ?? t.step ?? 0)), l = Math.floor(c), d = c - l, u = { x: n, y: i, size: s, color: r, align: t.align, opacity: e.opacity * e.draw, idPrefix: `${t.id}.`, palette: e.theme.colors }, f = (a) => U(t.steps[a], { values: e.scope }), h = t.backdrop ?? t.screen ?? !1;
|
|
2569
2642
|
if (d === 0 || l >= o) {
|
|
2570
|
-
const a =
|
|
2571
|
-
return [...h ?
|
|
2643
|
+
const a = f(l);
|
|
2644
|
+
return [...h ? _e(t.id, [a], u, e) : [], ...X(a, u)];
|
|
2572
2645
|
}
|
|
2573
2646
|
const g = (a) => {
|
|
2574
|
-
const [m, b] =
|
|
2647
|
+
const [m, b] = He(a, u);
|
|
2575
2648
|
return { layout: a, x: m / s, y: b / s };
|
|
2576
|
-
},
|
|
2649
|
+
}, p = f(l), y = f(l + 1);
|
|
2577
2650
|
return [
|
|
2578
|
-
...h ?
|
|
2579
|
-
...
|
|
2651
|
+
...h ? _e(t.id, [p, y], u, e) : [],
|
|
2652
|
+
...An(Es(g(p), g(y), d), [0, 0], u)
|
|
2580
2653
|
];
|
|
2581
2654
|
}
|
|
2582
|
-
function
|
|
2583
|
-
const n =
|
|
2655
|
+
function Ds(t, e) {
|
|
2656
|
+
const n = J(t.expr), i = P(e.values, t.at), s = t.h === void 0 ? 0 : P(e.values, t.h), r = n(i, e.scope), o = e.scope[`${t.id}.slope`];
|
|
2584
2657
|
if (!Number.isFinite(r) || !Number.isFinite(o)) return [];
|
|
2585
|
-
const c = t.length !== void 0 ? t.length / 2 : Math.max(Math.abs(e.plane.x[0] - i), Math.abs(e.plane.x[1] - i)), l = [[i - c, r - o * c], [i + c, r + o * c]], d =
|
|
2586
|
-
(g,
|
|
2658
|
+
const c = t.length !== void 0 ? t.length / 2 : Math.max(Math.abs(e.plane.x[0] - i), Math.abs(e.plane.x[1] - i)), l = [[i - c, r - o * c], [i + c, r + o * c]], d = F(e.theme, t.color, e.theme.colors.yellow), u = e.plane.toScreen([i, r]), f = l.map(e.plane.toScreen), h = [f[0], f[1]].flatMap(
|
|
2659
|
+
(g, p) => V([[u, g]], e.draw).map((y) => ({ type: "line", id: `${t.id}.${p}`, points: y, stroke: d, width: (t.width ?? 3) * e.plane.scale, opacity: e.opacity }))
|
|
2587
2660
|
);
|
|
2588
2661
|
if (t.points !== !1) {
|
|
2589
2662
|
const g = 6 * e.plane.scale;
|
|
2590
2663
|
if (h.push({ type: "circle", id: `${t.id}.point`, x: u[0], y: u[1], r: g, fill: d, opacity: e.opacity }), Math.abs(s) > 1e-9) {
|
|
2591
|
-
const [
|
|
2592
|
-
Number.isFinite(y) && h.push({ type: "circle", id: `${t.id}.secant`, x:
|
|
2664
|
+
const [p, y] = e.plane.toScreen([i + s, n(i + s, e.scope)]);
|
|
2665
|
+
Number.isFinite(y) && h.push({ type: "circle", id: `${t.id}.secant`, x: p, y, r: g, fill: d, opacity: e.opacity });
|
|
2593
2666
|
}
|
|
2594
2667
|
}
|
|
2595
2668
|
if (t.label && e.draw >= 1) {
|
|
2596
|
-
const g = 24 * e.plane.scale,
|
|
2597
|
-
h.push(...X(
|
|
2669
|
+
const g = 24 * e.plane.scale, p = U(t.label, { values: e.scope, style: "inline" });
|
|
2670
|
+
h.push(...X(p, { x: u[0], y: u[1] - g * 1.6, size: g, color: d, opacity: e.opacity, idPrefix: `${t.id}.label.` }));
|
|
2598
2671
|
}
|
|
2599
2672
|
return h;
|
|
2600
2673
|
}
|
|
2601
|
-
function
|
|
2602
|
-
const n =
|
|
2603
|
-
return o.slice(0, l).flatMap(([u,
|
|
2674
|
+
function _s(t, e) {
|
|
2675
|
+
const n = J(t.expr), i = P(e.values, t.from), s = P(e.values, t.to), r = Wn(P(e.values, t.n)), o = Un((u) => n(u, e.scope), i, s, r, t.rule ?? "left"), c = F(e.theme, t.color, e.theme.colors.blue), l = Math.ceil(o.length * e.draw), d = Math.max(0.5, Math.min(1.5, 60 / r)) * e.plane.scale;
|
|
2676
|
+
return o.slice(0, l).flatMap(([u, f, h, g], p) => {
|
|
2604
2677
|
if (!Number.isFinite(h) || !Number.isFinite(g)) return [];
|
|
2605
|
-
const y = [[u, 0], [
|
|
2606
|
-
return [{ type: "line", id: `${t.id}.${
|
|
2678
|
+
const y = [[u, 0], [f, 0], [f, g], [u, h]].map(e.plane.toScreen), m = (h + g) / 2 < 0 ? F(e.theme, "red", e.theme.colors.red) : c;
|
|
2679
|
+
return [{ type: "line", id: `${t.id}.${p}`, points: y, closed: !0, fill: m, stroke: m, width: d, opacity: e.opacity * (t.fillOpacity ?? 0.35) }];
|
|
2607
2680
|
});
|
|
2608
2681
|
}
|
|
2609
|
-
function
|
|
2610
|
-
const n =
|
|
2682
|
+
function Rs(t, e) {
|
|
2683
|
+
const n = J(t.expr), i = t.lower ? J(t.lower) : () => 0, s = P(e.values, t.from), r = s + (P(e.values, t.to) - s) * e.draw;
|
|
2611
2684
|
if (s === r) return [];
|
|
2612
|
-
const o = 240, c =
|
|
2613
|
-
let
|
|
2614
|
-
const
|
|
2615
|
-
|
|
2685
|
+
const o = 240, c = F(e.theme, t.color, e.theme.colors.blue), l = F(e.theme, t.negativeColor, e.theme.colors.red), d = e.opacity * (t.fillOpacity ?? 0.4), u = [];
|
|
2686
|
+
let f = [], h = [], g;
|
|
2687
|
+
const p = () => {
|
|
2688
|
+
f.length >= 2 && u.push({ type: "line", id: `${t.id}.${u.length}`, points: [...f, ...h.reverse()].map(e.plane.toScreen), closed: !0, fill: g ? c : l, opacity: d }), f = [], h = [];
|
|
2616
2689
|
};
|
|
2617
2690
|
let y;
|
|
2618
2691
|
for (let a = 0; a <= o; a++) {
|
|
2619
2692
|
const m = s + (r - s) * a / o, b = n(m, e.scope), x = i(m, e.scope);
|
|
2620
2693
|
if (!Number.isFinite(b) || !Number.isFinite(x)) {
|
|
2621
|
-
|
|
2694
|
+
p(), y = void 0;
|
|
2622
2695
|
continue;
|
|
2623
2696
|
}
|
|
2624
2697
|
const w = b - x >= 0;
|
|
2625
2698
|
if (y && g !== void 0 && w !== g) {
|
|
2626
2699
|
const v = y.fy - y.gy, $ = b - x, M = v / (v - $), k = y.x + (m - y.x) * M, S = y.gy + (x - y.gy) * M;
|
|
2627
|
-
|
|
2700
|
+
f.push([k, S]), h.push([k, S]), p(), f.push([k, S]), h.push([k, S]);
|
|
2628
2701
|
}
|
|
2629
|
-
g = w,
|
|
2702
|
+
g = w, f.push([m, b]), h.push([m, x]), y = { x: m, fy: b, gy: x };
|
|
2630
2703
|
}
|
|
2631
|
-
return
|
|
2704
|
+
return p(), u;
|
|
2632
2705
|
}
|
|
2633
|
-
const
|
|
2634
|
-
function
|
|
2635
|
-
const n =
|
|
2706
|
+
const Bs = 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));
|
|
2707
|
+
function Vs(t, e) {
|
|
2708
|
+
const n = P(e.values, t.at), i = e.scope[`${t.id}.order`], s = Math.floor(i), r = i - s, o = Array.from({ length: Math.min(20, s + 1) + 1 }, (f, h) => Be(t.expr, h)(n, e.scope) / Bs[h]), c = (f) => {
|
|
2636
2709
|
let h = 0, g = 1;
|
|
2637
|
-
for (let
|
|
2638
|
-
h += o[
|
|
2710
|
+
for (let p = 0; p <= s; p++)
|
|
2711
|
+
h += o[p] * g, g *= f - n;
|
|
2639
2712
|
return r > 0 && s < 20 ? h + r * o[s + 1] * g : h;
|
|
2640
|
-
}, l =
|
|
2641
|
-
return
|
|
2713
|
+
}, l = F(e.theme, t.color, e.theme.colors.yellow), [d, u] = t.domain ?? e.plane.x;
|
|
2714
|
+
return pe(t.id, (f) => c(f), d, u, l, (t.width ?? 3.5) * e.plane.scale, e);
|
|
2642
2715
|
}
|
|
2643
|
-
function
|
|
2716
|
+
function Hs(t, e) {
|
|
2644
2717
|
switch (t.kind) {
|
|
2645
2718
|
case "grid":
|
|
2646
|
-
return
|
|
2719
|
+
return Os(t, e);
|
|
2647
2720
|
case "axes":
|
|
2648
|
-
return
|
|
2721
|
+
return Ns(t, e);
|
|
2649
2722
|
case "vector":
|
|
2650
|
-
return
|
|
2723
|
+
return Is(t, e);
|
|
2651
2724
|
case "basis":
|
|
2652
|
-
return
|
|
2725
|
+
return Ps(t, e);
|
|
2653
2726
|
case "point":
|
|
2654
|
-
return
|
|
2727
|
+
return Fs(t, e);
|
|
2655
2728
|
case "function":
|
|
2656
|
-
return
|
|
2729
|
+
return Fi(t, e);
|
|
2657
2730
|
case "parametric":
|
|
2658
|
-
return
|
|
2731
|
+
return Li(t, e);
|
|
2659
2732
|
case "polygon":
|
|
2660
|
-
return
|
|
2733
|
+
return Cs(t, e);
|
|
2661
2734
|
case "line":
|
|
2662
|
-
return
|
|
2735
|
+
return qs(t, e);
|
|
2663
2736
|
case "label":
|
|
2664
|
-
return
|
|
2737
|
+
return zs(t, e);
|
|
2665
2738
|
case "equation":
|
|
2666
|
-
return
|
|
2739
|
+
return js(t, e);
|
|
2667
2740
|
case "tangent":
|
|
2668
|
-
return
|
|
2741
|
+
return Ds(t, e);
|
|
2669
2742
|
case "riemann":
|
|
2670
|
-
return
|
|
2743
|
+
return _s(t, e);
|
|
2671
2744
|
case "area":
|
|
2672
|
-
return
|
|
2745
|
+
return Rs(t, e);
|
|
2673
2746
|
case "taylor":
|
|
2674
|
-
return
|
|
2747
|
+
return Vs(t, e);
|
|
2675
2748
|
case "histogram":
|
|
2676
|
-
return
|
|
2749
|
+
return Ci(t, e);
|
|
2677
2750
|
case "distribution":
|
|
2678
|
-
return
|
|
2751
|
+
return qi(t, e);
|
|
2679
2752
|
case "galton":
|
|
2680
|
-
return
|
|
2753
|
+
return zi(t, e);
|
|
2681
2754
|
case "scatter":
|
|
2682
|
-
return
|
|
2755
|
+
return ji(t, e);
|
|
2683
2756
|
case "bayes":
|
|
2684
|
-
return
|
|
2757
|
+
return Di(t, e);
|
|
2685
2758
|
case "graph":
|
|
2686
|
-
return
|
|
2759
|
+
return Xi(t, e);
|
|
2687
2760
|
case "venn":
|
|
2688
|
-
return
|
|
2761
|
+
return Zi(t, e);
|
|
2689
2762
|
case "clock":
|
|
2690
|
-
return
|
|
2763
|
+
return Ji(t, e);
|
|
2691
2764
|
case "network":
|
|
2692
|
-
return
|
|
2765
|
+
return ds(t, e);
|
|
2693
2766
|
case "heatmap":
|
|
2694
|
-
return
|
|
2767
|
+
return ps(t, e);
|
|
2695
2768
|
case "contours":
|
|
2696
|
-
return
|
|
2769
|
+
return ms(t, e);
|
|
2697
2770
|
case "descent":
|
|
2698
|
-
return
|
|
2771
|
+
return bs(t, e);
|
|
2699
2772
|
case "classifier":
|
|
2700
|
-
return
|
|
2773
|
+
return ws(t, e);
|
|
2701
2774
|
case "kmeans":
|
|
2702
|
-
return
|
|
2775
|
+
return ks(t, e);
|
|
2703
2776
|
}
|
|
2704
2777
|
}
|
|
2705
|
-
const
|
|
2706
|
-
function
|
|
2707
|
-
const n =
|
|
2708
|
-
for (const [u,
|
|
2709
|
-
u.indexOf(".") < 0 ? typeof
|
|
2710
|
-
const o =
|
|
2778
|
+
const hn = (t) => Math.min(1, Math.max(0, t));
|
|
2779
|
+
function Rt(t, e = {}) {
|
|
2780
|
+
const n = De[t.theme ?? "dark"], i = Xn(t), s = { ...t.values }, r = /* @__PURE__ */ new Map();
|
|
2781
|
+
for (const [u, f] of Object.entries(e))
|
|
2782
|
+
u.indexOf(".") < 0 ? typeof f != "string" && (s[u] = f) : typeof f == "number" && r.set(u, f);
|
|
2783
|
+
const o = vn(s), c = { ...o, ...Gn(t.items, s, o) }, l = [];
|
|
2711
2784
|
for (const u of t.items) {
|
|
2712
|
-
const
|
|
2713
|
-
h <= 0 || g <= 0 || l.push(...
|
|
2785
|
+
const f = (p) => r.get(`${u.id}.${p}`), h = hn(f("draw") ?? u.draw ?? 1), g = hn(f("opacity") ?? u.opacity ?? 1);
|
|
2786
|
+
h <= 0 || g <= 0 || l.push(...Hs(u, { plane: i, theme: n, values: s, scope: c, draw: h, opacity: g, prop: f }));
|
|
2714
2787
|
}
|
|
2715
2788
|
const d = t.background === "none" ? void 0 : t.background ?? n.background;
|
|
2716
2789
|
return { width: t.width, height: t.height, ...d ? { background: d } : {}, shapes: l };
|
|
2717
2790
|
}
|
|
2718
|
-
function
|
|
2791
|
+
function Jn(t, e) {
|
|
2719
2792
|
if (t.length < 2) return { shaft: t, head: void 0 };
|
|
2720
2793
|
const n = t[t.length - 1], i = t[t.length - 2], s = n[0] - i[0], r = n[1] - i[1], o = Math.hypot(s, r);
|
|
2721
2794
|
if (o === 0 || e <= 0) return { shaft: t, head: void 0 };
|
|
2722
|
-
const c = s / o, l = r / o, d = Math.min(e, o), u = [n[0] - c * d, n[1] - l * d],
|
|
2795
|
+
const c = s / o, l = r / o, d = Math.min(e, o), u = [n[0] - c * d, n[1] - l * d], f = d * 0.55;
|
|
2723
2796
|
return {
|
|
2724
2797
|
shaft: [...t.slice(0, -1), u],
|
|
2725
|
-
head: [n, [u[0] - l *
|
|
2798
|
+
head: [n, [u[0] - l * f, u[1] + c * f], [u[0] + l * f, u[1] - c * f]]
|
|
2726
2799
|
};
|
|
2727
2800
|
}
|
|
2728
|
-
function
|
|
2801
|
+
function Qt(t, e, n = !1) {
|
|
2729
2802
|
t.beginPath(), e.forEach(([i, s], r) => r === 0 ? t.moveTo(i, s) : t.lineTo(i, s)), n && t.closePath();
|
|
2730
2803
|
}
|
|
2731
|
-
function
|
|
2804
|
+
function Kn(t, e) {
|
|
2732
2805
|
switch (t.globalAlpha = e.opacity ?? 1, e.type) {
|
|
2733
2806
|
case "line":
|
|
2734
2807
|
if (e.points.length < 2) return;
|
|
2735
2808
|
if (e.clip?.length) {
|
|
2736
2809
|
t.save();
|
|
2737
2810
|
for (const { points: n, outside: i } of e.clip)
|
|
2738
|
-
|
|
2739
|
-
|
|
2811
|
+
Qt(t, n, !0), i ? (t.rect(-1e6, -1e6, 2e6, 2e6), t.clip("evenodd")) : t.clip();
|
|
2812
|
+
Kn(t, { ...e, clip: void 0 }), t.restore();
|
|
2740
2813
|
return;
|
|
2741
2814
|
}
|
|
2742
|
-
|
|
2815
|
+
Qt(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([]));
|
|
2743
2816
|
return;
|
|
2744
2817
|
case "arrow": {
|
|
2745
|
-
const { shaft: n, head: i } =
|
|
2746
|
-
t.strokeStyle = e.stroke, t.fillStyle = e.stroke, t.lineWidth = e.width, n.length >= 2 && (
|
|
2818
|
+
const { shaft: n, head: i } = Jn(e.points, e.head);
|
|
2819
|
+
t.strokeStyle = e.stroke, t.fillStyle = e.stroke, t.lineWidth = e.width, n.length >= 2 && (Qt(t, n), t.stroke()), i && (Qt(t, i, !0), t.fill());
|
|
2747
2820
|
return;
|
|
2748
2821
|
}
|
|
2749
2822
|
case "circle":
|
|
@@ -2753,48 +2826,48 @@ function Wn(t, e) {
|
|
|
2753
2826
|
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);
|
|
2754
2827
|
}
|
|
2755
2828
|
}
|
|
2756
|
-
function
|
|
2829
|
+
function Us(t, e) {
|
|
2757
2830
|
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";
|
|
2758
|
-
for (const n of e.shapes)
|
|
2831
|
+
for (const n of e.shapes) Kn(t, n);
|
|
2759
2832
|
t.restore();
|
|
2760
2833
|
}
|
|
2761
|
-
const
|
|
2762
|
-
function
|
|
2834
|
+
const B = (t) => String(Math.round(t * 100) / 100), et = (t) => t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """), Nt = (t, e = !1) => t.map(([n, i], s) => `${s ? "L" : "M"}${B(n)} ${B(i)}`).join("") + (e ? "Z" : ""), te = (t) => t.opacity !== void 0 && t.opacity < 1 ? ` opacity="${B(t.opacity)}"` : "";
|
|
2835
|
+
function Qn(t) {
|
|
2763
2836
|
switch (t.type) {
|
|
2764
2837
|
case "line": {
|
|
2765
2838
|
if (t.points.length < 2) return "";
|
|
2766
2839
|
if (t.clip?.length) {
|
|
2767
2840
|
const s = t.clip.map(({ points: o, outside: c }) => {
|
|
2768
|
-
const l = c ? `M-1000000 -1000000H1000000V1000000H-1000000Z${
|
|
2841
|
+
const l = c ? `M-1000000 -1000000H1000000V1000000H-1000000Z${Nt(o, !0)}` : Nt(o, !0), d = `tfclip${gt(`${c ? "o" : "i"}${l}`).toString(36)}`;
|
|
2769
2842
|
return { id: d, def: `<clipPath id="${d}"><path d="${l}"${c ? ' clip-rule="evenodd"' : ""}/></clipPath>` };
|
|
2770
|
-
}), r =
|
|
2843
|
+
}), r = Qn({ ...t, clip: void 0 });
|
|
2771
2844
|
return `<defs>${s.map((o) => o.def).join("")}</defs>` + s.reduceRight((o, c) => `<g clip-path="url(#${c.id})">${o}</g>`, r);
|
|
2772
2845
|
}
|
|
2773
|
-
const e = t.fill ? ` fill="${
|
|
2774
|
-
return `<path d="${
|
|
2846
|
+
const e = t.fill ? ` fill="${et(t.fill)}"` : ' fill="none"', n = t.stroke && (t.width ?? 1) > 0 ? ` stroke="${et(t.stroke)}" stroke-width="${B(t.width ?? 1)}"` : "", i = t.dash?.length ? ` stroke-dasharray="${t.dash.map(B).join(" ")}"` : "";
|
|
2847
|
+
return `<path d="${Nt(t.points, t.closed)}"${e}${n}${i}${te(t)}/>`;
|
|
2775
2848
|
}
|
|
2776
2849
|
case "arrow": {
|
|
2777
|
-
const { shaft: e, head: n } =
|
|
2778
|
-
return `<g${
|
|
2850
|
+
const { shaft: e, head: n } = Jn(t.points, t.head), i = et(t.stroke), s = e.length >= 2 ? `<path d="${Nt(e)}" fill="none" stroke="${i}" stroke-width="${B(t.width)}"/>` : "", r = n ? `<path d="${Nt(n, !0)}" fill="${i}"/>` : "";
|
|
2851
|
+
return `<g${te(t)}>${s}${r}</g>`;
|
|
2779
2852
|
}
|
|
2780
2853
|
case "circle": {
|
|
2781
|
-
const e = t.fill ? ` fill="${
|
|
2782
|
-
return `<circle cx="${
|
|
2854
|
+
const e = t.fill ? ` fill="${et(t.fill)}"` : ' fill="none"', n = t.stroke ? ` stroke="${et(t.stroke)}" stroke-width="${B(t.width ?? 1)}"` : "";
|
|
2855
|
+
return `<circle cx="${B(t.x)}" cy="${B(t.y)}" r="${B(t.r)}"${e}${n}${te(t)}/>`;
|
|
2783
2856
|
}
|
|
2784
2857
|
case "text": {
|
|
2785
2858
|
const e = t.align === "center" ? "middle" : t.align === "right" ? "end" : "start", n = t.italic ? ' font-style="italic"' : "";
|
|
2786
|
-
return `<text x="${
|
|
2859
|
+
return `<text x="${B(t.x)}" y="${B(t.y)}" font-size="${B(t.size)}" font-family="${et(t.font)}"${n} text-anchor="${e}" fill="${et(t.color)}"${te(t)}>${et(t.text)}</text>`;
|
|
2787
2860
|
}
|
|
2788
2861
|
}
|
|
2789
2862
|
}
|
|
2790
|
-
function
|
|
2791
|
-
return `${t.background ? `<rect width="${
|
|
2863
|
+
function Ge(t) {
|
|
2864
|
+
return `${t.background ? `<rect width="${B(t.width)}" height="${B(t.height)}" fill="${et(t.background)}"/>` : ""}<g stroke-linecap="round" stroke-linejoin="round">${t.shapes.map(Qn).join("")}</g>`;
|
|
2792
2865
|
}
|
|
2793
|
-
function
|
|
2794
|
-
const n = e.title ? `<title>${
|
|
2795
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${
|
|
2866
|
+
function Ws(t, e = {}) {
|
|
2867
|
+
const n = e.title ? `<title>${et(e.title)}</title>` : "", i = e.title ? ` role="img" aria-label="${et(e.title)}"` : "";
|
|
2868
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${B(t.width)} ${B(t.height)}" width="${B(t.width)}" height="${B(t.height)}"${i}>${n}${Ge(t)}</svg>`;
|
|
2796
2869
|
}
|
|
2797
|
-
function
|
|
2870
|
+
function Gs(t) {
|
|
2798
2871
|
const e = {};
|
|
2799
2872
|
for (const [n, i] of Object.entries(t.values ?? {})) {
|
|
2800
2873
|
const s = typeof i == "number" ? "number" : i.length === 2 ? "[x, y] vector" : "[a, b, c, d] matrix";
|
|
@@ -2804,9 +2877,9 @@ function Bs(t) {
|
|
|
2804
2877
|
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 });
|
|
2805
2878
|
return e;
|
|
2806
2879
|
}
|
|
2807
|
-
function
|
|
2808
|
-
|
|
2809
|
-
const n =
|
|
2880
|
+
function Xs(t, e = {}) {
|
|
2881
|
+
Et(t);
|
|
2882
|
+
const n = Gs(t), i = { ...t.values ?? {} };
|
|
2810
2883
|
return {
|
|
2811
2884
|
type: "custom",
|
|
2812
2885
|
x: e.x ?? 0,
|
|
@@ -2816,7 +2889,7 @@ function Vs(t, e = {}) {
|
|
|
2816
2889
|
props: i,
|
|
2817
2890
|
acceptsProp: (s) => Object.prototype.hasOwnProperty.call(n, s),
|
|
2818
2891
|
draw(s, r) {
|
|
2819
|
-
|
|
2892
|
+
Us(s, Rt(t, r.props ?? {}));
|
|
2820
2893
|
},
|
|
2821
2894
|
about: {
|
|
2822
2895
|
kind: "math figure",
|
|
@@ -2825,7 +2898,7 @@ function Vs(t, e = {}) {
|
|
|
2825
2898
|
}
|
|
2826
2899
|
};
|
|
2827
2900
|
}
|
|
2828
|
-
function
|
|
2901
|
+
function Ar(t, e, n, i = {}) {
|
|
2829
2902
|
const s = new Set(n.items.map((l) => l.id)), r = (l) => {
|
|
2830
2903
|
if (!s.has(l)) throw new Error(`mathSteps: no item "${l}" (items: ${[...s].join(", ")})`);
|
|
2831
2904
|
}, o = { ...n.values ?? {} };
|
|
@@ -2840,9 +2913,9 @@ function $r(t, e, n, i = {}) {
|
|
|
2840
2913
|
return t.to(e, { [l]: d }, { duration: 1200, ...u }), c;
|
|
2841
2914
|
},
|
|
2842
2915
|
applyMatrix(l, d = {}) {
|
|
2843
|
-
const { name: u = "M", ...
|
|
2916
|
+
const { name: u = "M", ...f } = d;
|
|
2844
2917
|
if (l.length !== 4 || !l.every(Number.isFinite)) throw new Error("mathSteps.applyMatrix: expected [a, b, c, d]");
|
|
2845
|
-
return c.toValue(u, l, { duration: 1600, ...
|
|
2918
|
+
return c.toValue(u, l, { duration: 1600, ...f });
|
|
2846
2919
|
},
|
|
2847
2920
|
drawOn(l, d) {
|
|
2848
2921
|
return r(l), t.to(e, { [`${l}.draw`]: 1 }, { duration: 900, ...d }), c;
|
|
@@ -2859,7 +2932,7 @@ function $r(t, e, n, i = {}) {
|
|
|
2859
2932
|
};
|
|
2860
2933
|
return c;
|
|
2861
2934
|
}
|
|
2862
|
-
class
|
|
2935
|
+
class fn {
|
|
2863
2936
|
media;
|
|
2864
2937
|
offset;
|
|
2865
2938
|
driftTolerance;
|
|
@@ -2898,7 +2971,7 @@ class cn {
|
|
|
2898
2971
|
});
|
|
2899
2972
|
}
|
|
2900
2973
|
}
|
|
2901
|
-
function
|
|
2974
|
+
function Ys(t, e, n, i, s) {
|
|
2902
2975
|
const r = n - s;
|
|
2903
2976
|
if (r < 0) {
|
|
2904
2977
|
e.paused || e.pause(), e.currentTime = 0;
|
|
@@ -2906,7 +2979,7 @@ function Hs(t, e, n, i, s) {
|
|
|
2906
2979
|
}
|
|
2907
2980
|
t.update(r, i);
|
|
2908
2981
|
}
|
|
2909
|
-
class
|
|
2982
|
+
class Zs {
|
|
2910
2983
|
container;
|
|
2911
2984
|
timeline = null;
|
|
2912
2985
|
adapter;
|
|
@@ -2945,7 +3018,7 @@ class Us {
|
|
|
2945
3018
|
this.container = i;
|
|
2946
3019
|
} else
|
|
2947
3020
|
this.container = e;
|
|
2948
|
-
this.options = n, this.adapter = new
|
|
3021
|
+
this.options = n, this.adapter = new Je();
|
|
2949
3022
|
}
|
|
2950
3023
|
/**
|
|
2951
3024
|
* Load animation from a URL or JSON object.
|
|
@@ -2971,7 +3044,7 @@ class Us {
|
|
|
2971
3044
|
*/
|
|
2972
3045
|
useDefinition(e) {
|
|
2973
3046
|
const n = { ...e.config };
|
|
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 =
|
|
3047
|
+
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 = Ze({ ...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();
|
|
2975
3048
|
}
|
|
2976
3049
|
// --- scenarios: the reader chooses which timeline plays --------------------
|
|
2977
3050
|
/**
|
|
@@ -3138,13 +3211,13 @@ class Us {
|
|
|
3138
3211
|
scanMedia() {
|
|
3139
3212
|
this.mediaTargets = [], this.container.querySelectorAll("[data-tinyfly-media]").forEach((n) => {
|
|
3140
3213
|
const i = n, s = Number(i.getAttribute("data-tinyfly-start") ?? "0") || 0, r = i.getAttribute("data-volume");
|
|
3141
|
-
r !== null && (i.volume = Math.max(0, Math.min(1, Number(r) || 0))), this.mediaTargets.push({ el: i, startTime: s, sync: new
|
|
3214
|
+
r !== null && (i.volume = Math.max(0, Math.min(1, Number(r) || 0))), this.mediaTargets.push({ el: i, startTime: s, sync: new fn(i) });
|
|
3142
3215
|
});
|
|
3143
3216
|
}
|
|
3144
3217
|
/** Sync all discovered media targets to a timeline time. */
|
|
3145
3218
|
syncAllMedia(e, n) {
|
|
3146
3219
|
for (const i of this.mediaTargets)
|
|
3147
|
-
|
|
3220
|
+
Ys(i.sync, i.el, e, n, i.startTime);
|
|
3148
3221
|
}
|
|
3149
3222
|
/**
|
|
3150
3223
|
* Load animation from inline JSON string.
|
|
@@ -3194,11 +3267,11 @@ class Us {
|
|
|
3194
3267
|
if (!s) return;
|
|
3195
3268
|
const r = n.get(s);
|
|
3196
3269
|
if (!r || !r.timeline.tracks?.length) return;
|
|
3197
|
-
const o = new
|
|
3270
|
+
const o = new Je();
|
|
3198
3271
|
i.querySelectorAll("[data-tinyfly]").forEach((c) => {
|
|
3199
3272
|
const l = c.getAttribute("data-tinyfly");
|
|
3200
3273
|
l && o.registerTarget(l, c);
|
|
3201
|
-
}), this.symbolInstances.push({ adapter: o, timeline:
|
|
3274
|
+
}), this.symbolInstances.push({ adapter: o, timeline: Ze(r.timeline) });
|
|
3202
3275
|
});
|
|
3203
3276
|
}
|
|
3204
3277
|
/**
|
|
@@ -3208,7 +3281,7 @@ class Us {
|
|
|
3208
3281
|
* plays. Pass `{ offset }` to start the media at a timeline offset.
|
|
3209
3282
|
*/
|
|
3210
3283
|
attachMedia(e, n) {
|
|
3211
|
-
this.mediaSync = new
|
|
3284
|
+
this.mediaSync = new fn(e, n), this.timeline && (this.mediaSync.setRate(this.timeline.speed), this.mediaSync.update(this.timeline.currentTime, this.isPlaying));
|
|
3212
3285
|
}
|
|
3213
3286
|
/** Detach and pause the currently synced media, if any. */
|
|
3214
3287
|
detachMedia() {
|
|
@@ -3315,7 +3388,7 @@ class Us {
|
|
|
3315
3388
|
this.playhead = i;
|
|
3316
3389
|
const s = this.markers;
|
|
3317
3390
|
if (s.length === 0) return;
|
|
3318
|
-
const { crossings: r } =
|
|
3391
|
+
const { crossings: r } = ni(
|
|
3319
3392
|
s.map((o) => o.time),
|
|
3320
3393
|
e,
|
|
3321
3394
|
i,
|
|
@@ -3343,7 +3416,7 @@ class Us {
|
|
|
3343
3416
|
}
|
|
3344
3417
|
}
|
|
3345
3418
|
}
|
|
3346
|
-
const
|
|
3419
|
+
const Js = {
|
|
3347
3420
|
play: "Play",
|
|
3348
3421
|
pause: "Pause",
|
|
3349
3422
|
prev: "Previous step",
|
|
@@ -3358,7 +3431,7 @@ const Ws = {
|
|
|
3358
3431
|
scenario: "Scenario",
|
|
3359
3432
|
fullscreen: "Full screen",
|
|
3360
3433
|
exitFullscreen: "Exit full screen"
|
|
3361
|
-
},
|
|
3434
|
+
}, pn = "tinyfly-controls-style", Ks = `
|
|
3362
3435
|
.tf-ctl { --tf-ctl-fg: #1d1d1f; --tf-ctl-bg: #f4f2ee; --tf-ctl-accent: #c2410c; --tf-ctl-radius: 8px;
|
|
3363
3436
|
font: 14px/1.4 var(--tf-ctl-font, system-ui, sans-serif); color: var(--tf-ctl-fg); margin-top: 8px; }
|
|
3364
3437
|
.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); }
|
|
@@ -3407,25 +3480,25 @@ const Ws = {
|
|
|
3407
3480
|
.tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
|
|
3408
3481
|
}
|
|
3409
3482
|
`;
|
|
3410
|
-
let
|
|
3411
|
-
function
|
|
3412
|
-
if (t.getElementById(
|
|
3483
|
+
let Qs = 0;
|
|
3484
|
+
function tr(t) {
|
|
3485
|
+
if (t.getElementById(pn)) return;
|
|
3413
3486
|
const e = t.createElement("style");
|
|
3414
|
-
e.id =
|
|
3487
|
+
e.id = pn, e.textContent = Ks, t.head.appendChild(e);
|
|
3415
3488
|
}
|
|
3416
|
-
function
|
|
3489
|
+
function er(t, e, n = {}) {
|
|
3417
3490
|
const i = e.ownerDocument;
|
|
3418
|
-
|
|
3419
|
-
const s = { ...
|
|
3491
|
+
tr(i);
|
|
3492
|
+
const s = { ...Js, ...n.labels }, r = n.speeds ?? [0.5, 1, 2], o = () => t.markers.length > 0, c = () => t.markers.some((A) => A.label !== void 0 || t.caption(A.id) !== void 0), l = i.createElement("div");
|
|
3420
3493
|
l.className = "tf-ctl";
|
|
3421
3494
|
const d = i.createElement("div");
|
|
3422
3495
|
d.className = "tf-ctl-bar", d.setAttribute("role", "group");
|
|
3423
|
-
const u = (A,
|
|
3424
|
-
const
|
|
3425
|
-
return
|
|
3426
|
-
},
|
|
3496
|
+
const u = (A, N, I, L = "") => {
|
|
3497
|
+
const C = i.createElement("button");
|
|
3498
|
+
return C.type = "button", C.className = `tf-ctl-btn ${L}`.trim(), C.setAttribute("aria-label", A), C.title = A, C.textContent = N, C.addEventListener("click", I), C;
|
|
3499
|
+
}, f = u(s.restart, "⟲", () => {
|
|
3427
3500
|
t.pause(), t.seek(0);
|
|
3428
|
-
}), h = u(s.prev, "|◀", () => t.prev()), g = u(s.play, "▶", () => t.isPlaying ? t.pause() : y(), "tf-ctl-primary"),
|
|
3501
|
+
}), h = u(s.prev, "|◀", () => t.prev()), g = u(s.play, "▶", () => t.isPlaying ? t.pause() : y(), "tf-ctl-primary"), p = u(s.next, "▶|", () => t.next()), y = () => {
|
|
3429
3502
|
t.currentTime >= t.duration - 0.5 && t.seek(0), t.play();
|
|
3430
3503
|
}, a = i.createElement("input");
|
|
3431
3504
|
a.type = "range", a.className = "tf-ctl-scrub", a.min = "0", a.max = "1000", a.step = "1", a.setAttribute("aria-label", s.scrub), a.addEventListener("input", () => {
|
|
@@ -3436,11 +3509,11 @@ function Zs(t, e, n = {}) {
|
|
|
3436
3509
|
const b = i.createElement("select");
|
|
3437
3510
|
b.className = "tf-ctl-speed", b.setAttribute("aria-label", s.speed);
|
|
3438
3511
|
for (const A of r) {
|
|
3439
|
-
const
|
|
3440
|
-
|
|
3512
|
+
const N = i.createElement("option");
|
|
3513
|
+
N.value = String(A), N.textContent = `${A}×`, A === 1 && (N.selected = !0), b.appendChild(N);
|
|
3441
3514
|
}
|
|
3442
|
-
b.addEventListener("change", () => t.setSpeed(Number(b.value))), d.append(
|
|
3443
|
-
const x = n.fullscreen ?
|
|
3515
|
+
b.addEventListener("change", () => t.setSpeed(Number(b.value))), d.append(f, h, g, p, a, m), r.length > 0 && d.append(b), l.append(d);
|
|
3516
|
+
const x = n.fullscreen ? rr(e, i, s) : void 0;
|
|
3444
3517
|
x && d.append(x.button);
|
|
3445
3518
|
const w = i.createElement("p");
|
|
3446
3519
|
w.className = "tf-ctl-caption", w.setAttribute("aria-live", "polite"), n.captions !== !1 && l.append(w);
|
|
@@ -3448,34 +3521,34 @@ function Zs(t, e, n = {}) {
|
|
|
3448
3521
|
v.className = "tf-ctl-question", v.hidden = !0;
|
|
3449
3522
|
const $ = i.createElement("span"), M = u(s.reveal, s.reveal, () => t.play(), "tf-ctl-primary");
|
|
3450
3523
|
v.append($, M), l.append(v);
|
|
3451
|
-
const k =
|
|
3524
|
+
const k = nr(t, i, s.scenario, n.scenarioControl ?? "buttons");
|
|
3452
3525
|
k && l.append(k.element);
|
|
3453
3526
|
const S = n.mount;
|
|
3454
3527
|
S ? S.appendChild(l) : e.insertAdjacentElement("afterend", l);
|
|
3455
3528
|
const E = () => {
|
|
3456
3529
|
const A = t.isPlaying;
|
|
3457
3530
|
g.textContent = A ? "❚❚" : "▶", g.setAttribute("aria-label", A ? s.pause : s.play), g.title = A ? s.pause : s.play;
|
|
3458
|
-
const
|
|
3459
|
-
i.activeElement !== a && (a.value = String(
|
|
3460
|
-
const
|
|
3461
|
-
if (h.hidden =
|
|
3462
|
-
const
|
|
3463
|
-
m.textContent = s.stepFormat.replace("{index}", String(
|
|
3464
|
-
const
|
|
3465
|
-
w.textContent !==
|
|
3466
|
-
const
|
|
3467
|
-
v.hidden = !
|
|
3531
|
+
const N = t.duration;
|
|
3532
|
+
i.activeElement !== a && (a.value = String(N > 0 ? Math.round(t.currentTime / N * 1e3) : 0));
|
|
3533
|
+
const I = t.markers;
|
|
3534
|
+
if (h.hidden = p.hidden = m.hidden = I.length === 0, I.length > 0) {
|
|
3535
|
+
const L = t.currentMarker, C = L ? I.indexOf(L) + 1 : 0;
|
|
3536
|
+
m.textContent = s.stepFormat.replace("{index}", String(C)).replace("{total}", String(I.length)), m.setAttribute("aria-label", `${s.step} ${C} ${s.of} ${I.length}`), h.disabled = t.currentTime <= 0.5, p.disabled = t.currentTime >= N - 0.5;
|
|
3537
|
+
const Y = t.caption() ?? "";
|
|
3538
|
+
w.textContent !== Y && (w.textContent = Y), w.hidden = !c();
|
|
3539
|
+
const st = !A && L?.question !== void 0 && Math.abs(t.currentTime - L.time) < 1;
|
|
3540
|
+
v.hidden = !st, st && $.textContent !== L.question && ($.textContent = L.question);
|
|
3468
3541
|
} else
|
|
3469
3542
|
v.hidden = !0, w.hidden = !0;
|
|
3470
3543
|
k?.update();
|
|
3471
|
-
},
|
|
3544
|
+
}, T = t.subscribe(E);
|
|
3472
3545
|
E();
|
|
3473
|
-
const
|
|
3474
|
-
!
|
|
3475
|
-
const
|
|
3476
|
-
if (
|
|
3477
|
-
const
|
|
3478
|
-
if (!(
|
|
3546
|
+
const O = n.keyboardScope ?? e;
|
|
3547
|
+
!O.hasAttribute("tabindex") && O.tabIndex < 0 && (O.tabIndex = 0);
|
|
3548
|
+
const z = /* @__PURE__ */ new WeakSet(), q = (A) => {
|
|
3549
|
+
if (z.has(A) || (z.add(A), A.defaultPrevented || A.altKey || A.ctrlKey || A.metaKey)) return;
|
|
3550
|
+
const N = A.target;
|
|
3551
|
+
if (!(N.tagName === "INPUT" || N.tagName === "SELECT") && !(A.key === " " && N.tagName === "BUTTON"))
|
|
3479
3552
|
switch (A.key) {
|
|
3480
3553
|
case " ":
|
|
3481
3554
|
A.preventDefault(), t.isPlaying ? t.pause() : y();
|
|
@@ -3498,7 +3571,7 @@ function Zs(t, e, n = {}) {
|
|
|
3498
3571
|
break;
|
|
3499
3572
|
}
|
|
3500
3573
|
};
|
|
3501
|
-
return
|
|
3574
|
+
return O.addEventListener("keydown", q), l.addEventListener("keydown", q), {
|
|
3502
3575
|
element: l,
|
|
3503
3576
|
fullscreen: x && {
|
|
3504
3577
|
get active() {
|
|
@@ -3508,25 +3581,25 @@ function Zs(t, e, n = {}) {
|
|
|
3508
3581
|
exit: x.exit
|
|
3509
3582
|
},
|
|
3510
3583
|
destroy() {
|
|
3511
|
-
x?.destroy(),
|
|
3584
|
+
x?.destroy(), T(), O.removeEventListener("keydown", q), l.removeEventListener("keydown", q), l.remove();
|
|
3512
3585
|
}
|
|
3513
3586
|
};
|
|
3514
3587
|
}
|
|
3515
|
-
function
|
|
3588
|
+
function nr(t, e, n, i) {
|
|
3516
3589
|
const s = t.scenarios;
|
|
3517
3590
|
if (s.length < 2) return;
|
|
3518
3591
|
if (i === "slider") {
|
|
3519
3592
|
const u = e.createElement("div");
|
|
3520
3593
|
u.className = "tf-ctl-choice-slider";
|
|
3521
|
-
const
|
|
3522
|
-
|
|
3594
|
+
const f = e.createElement("span");
|
|
3595
|
+
f.textContent = n, f.setAttribute("aria-hidden", "true");
|
|
3523
3596
|
const h = e.createElement("input");
|
|
3524
3597
|
h.type = "range", h.min = "0", h.max = String(s.length - 1), h.step = "1", h.setAttribute("aria-label", n);
|
|
3525
3598
|
const g = e.createElement("output");
|
|
3526
3599
|
return g.setAttribute("aria-hidden", "true"), h.addEventListener("input", () => {
|
|
3527
3600
|
const y = s[Number(h.value)];
|
|
3528
3601
|
y && t.setScenario(y.id);
|
|
3529
|
-
}), u.append(
|
|
3602
|
+
}), u.append(f, h, g), { element: u, update: () => {
|
|
3530
3603
|
const y = Math.max(0, s.findIndex((m) => m.id === t.scenario));
|
|
3531
3604
|
e.activeElement !== h && (h.value = String(y));
|
|
3532
3605
|
const a = s[y].label;
|
|
@@ -3537,39 +3610,39 @@ function Js(t, e, n, i) {
|
|
|
3537
3610
|
r.className = "tf-ctl-choices";
|
|
3538
3611
|
const o = e.createElement("legend");
|
|
3539
3612
|
o.textContent = n, r.append(o);
|
|
3540
|
-
const c = `tf-ctl-scenario-${++
|
|
3541
|
-
const
|
|
3542
|
-
|
|
3613
|
+
const c = `tf-ctl-scenario-${++Qs}`, l = s.map((u) => {
|
|
3614
|
+
const f = e.createElement("label");
|
|
3615
|
+
f.className = "tf-ctl-choice";
|
|
3543
3616
|
const h = e.createElement("input");
|
|
3544
3617
|
h.type = "radio", h.name = c, h.value = u.id, h.addEventListener("change", () => {
|
|
3545
3618
|
h.checked && t.setScenario(u.id);
|
|
3546
3619
|
});
|
|
3547
3620
|
const g = e.createElement("span");
|
|
3548
|
-
return g.textContent = u.label,
|
|
3621
|
+
return g.textContent = u.label, f.append(h, g), r.append(f), h;
|
|
3549
3622
|
});
|
|
3550
3623
|
return { element: r, update: () => {
|
|
3551
3624
|
for (const u of l) {
|
|
3552
|
-
const
|
|
3553
|
-
u.checked !==
|
|
3625
|
+
const f = u.value === t.scenario;
|
|
3626
|
+
u.checked !== f && (u.checked = f);
|
|
3554
3627
|
}
|
|
3555
3628
|
} };
|
|
3556
3629
|
}
|
|
3557
|
-
const
|
|
3558
|
-
function
|
|
3630
|
+
const ir = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>', sr = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';
|
|
3631
|
+
function rr(t, e, n) {
|
|
3559
3632
|
const i = e, s = t, r = e.createElement("button");
|
|
3560
3633
|
r.type = "button", r.className = "tf-ctl-btn tf-ctl-fullscreen";
|
|
3561
3634
|
let o, c = "";
|
|
3562
3635
|
const l = () => {
|
|
3563
3636
|
const y = o !== void 0;
|
|
3564
|
-
r.innerHTML = y ?
|
|
3637
|
+
r.innerHTML = y ? sr : ir;
|
|
3565
3638
|
const a = y ? n.exitFullscreen : n.fullscreen;
|
|
3566
3639
|
r.setAttribute("aria-label", a), r.title = a, r.setAttribute("aria-pressed", String(y)), t.classList.toggle("tf-fullscreen", y), t.classList.toggle("tf-fullscreen-overlay", o === "overlay");
|
|
3567
3640
|
}, d = () => i.fullscreenElement ?? i.webkitFullscreenElement ?? null, u = () => {
|
|
3568
3641
|
d() === t ? o = "native" : o === "native" && (o = void 0), l();
|
|
3569
|
-
},
|
|
3570
|
-
y.key === "Escape" &&
|
|
3642
|
+
}, f = (y) => {
|
|
3643
|
+
y.key === "Escape" && p();
|
|
3571
3644
|
}, h = () => {
|
|
3572
|
-
o = "overlay", c = e.documentElement.style.overflow, e.documentElement.style.overflow = "hidden", e.addEventListener("keydown",
|
|
3645
|
+
o = "overlay", c = e.documentElement.style.overflow, e.documentElement.style.overflow = "hidden", e.addEventListener("keydown", f), l();
|
|
3573
3646
|
};
|
|
3574
3647
|
async function g() {
|
|
3575
3648
|
if (o) return;
|
|
@@ -3584,9 +3657,9 @@ function tr(t, e, n) {
|
|
|
3584
3657
|
}
|
|
3585
3658
|
h();
|
|
3586
3659
|
}
|
|
3587
|
-
async function
|
|
3660
|
+
async function p() {
|
|
3588
3661
|
if (o === "overlay")
|
|
3589
|
-
e.removeEventListener("keydown",
|
|
3662
|
+
e.removeEventListener("keydown", f), e.documentElement.style.overflow = c, o = void 0, l();
|
|
3590
3663
|
else if (o === "native") {
|
|
3591
3664
|
o = void 0, l();
|
|
3592
3665
|
const y = i.exitFullscreen?.bind(i) ?? i.webkitExitFullscreen?.bind(i);
|
|
@@ -3594,44 +3667,44 @@ function tr(t, e, n) {
|
|
|
3594
3667
|
}
|
|
3595
3668
|
}
|
|
3596
3669
|
return r.addEventListener("click", () => {
|
|
3597
|
-
o ?
|
|
3670
|
+
o ? p() : g();
|
|
3598
3671
|
}), e.addEventListener("fullscreenchange", u), e.addEventListener("webkitfullscreenchange", u), l(), {
|
|
3599
3672
|
button: r,
|
|
3600
3673
|
get active() {
|
|
3601
3674
|
return o !== void 0;
|
|
3602
3675
|
},
|
|
3603
3676
|
enter: g,
|
|
3604
|
-
exit:
|
|
3677
|
+
exit: p,
|
|
3605
3678
|
destroy() {
|
|
3606
|
-
|
|
3679
|
+
p(), e.removeEventListener("fullscreenchange", u), e.removeEventListener("webkitfullscreenchange", u), r.remove();
|
|
3607
3680
|
}
|
|
3608
3681
|
};
|
|
3609
3682
|
}
|
|
3610
|
-
const
|
|
3683
|
+
const yn = "tinyfly-choices-style", or = `
|
|
3611
3684
|
[data-tinyfly-choose] { cursor: pointer; }
|
|
3612
3685
|
[data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
|
|
3613
3686
|
`;
|
|
3614
|
-
function
|
|
3615
|
-
if (t.getElementById(
|
|
3687
|
+
function ar(t) {
|
|
3688
|
+
if (t.getElementById(yn)) return;
|
|
3616
3689
|
const e = t.createElement("style");
|
|
3617
|
-
e.id =
|
|
3690
|
+
e.id = yn, e.textContent = or, t.head.appendChild(e);
|
|
3618
3691
|
}
|
|
3619
|
-
function
|
|
3692
|
+
function cr(t, e) {
|
|
3620
3693
|
const n = Array.from(e.querySelectorAll("[data-tinyfly-choose]"));
|
|
3621
3694
|
if (n.length === 0) return () => {
|
|
3622
3695
|
};
|
|
3623
|
-
|
|
3696
|
+
ar(e.ownerDocument);
|
|
3624
3697
|
const i = [], s = [];
|
|
3625
3698
|
for (const c of n) {
|
|
3626
|
-
const l = c.getAttribute("data-tinyfly-choose") ?? "", d = [], u = (
|
|
3627
|
-
c.hasAttribute(
|
|
3699
|
+
const l = c.getAttribute("data-tinyfly-choose") ?? "", d = [], u = (p, y) => {
|
|
3700
|
+
c.hasAttribute(p) || (c.setAttribute(p, y), d.push(p));
|
|
3628
3701
|
};
|
|
3629
3702
|
u("role", "button"), u("tabindex", "0");
|
|
3630
|
-
const
|
|
3631
|
-
|
|
3632
|
-
const h = () => t.setScenario(l), g = (
|
|
3633
|
-
const y =
|
|
3634
|
-
y !== "Enter" && y !== " " || (
|
|
3703
|
+
const f = t.scenarios.find((p) => p.id === l)?.label;
|
|
3704
|
+
f !== void 0 && u("aria-label", f), c.setAttribute("aria-pressed", "false"), d.push("aria-pressed"), i.push({ element: c, attributes: d });
|
|
3705
|
+
const h = () => t.setScenario(l), g = (p) => {
|
|
3706
|
+
const y = p.key;
|
|
3707
|
+
y !== "Enter" && y !== " " || (p.preventDefault(), h());
|
|
3635
3708
|
};
|
|
3636
3709
|
c.addEventListener("click", h), c.addEventListener("keydown", g), s.push(() => {
|
|
3637
3710
|
c.removeEventListener("click", h), c.removeEventListener("keydown", g);
|
|
@@ -3647,9 +3720,9 @@ function ir(t, e) {
|
|
|
3647
3720
|
for (const { element: c, attributes: l } of i) for (const d of l) c.removeAttribute(d);
|
|
3648
3721
|
};
|
|
3649
3722
|
}
|
|
3650
|
-
const
|
|
3651
|
-
let
|
|
3652
|
-
function
|
|
3723
|
+
const mn = /* @__PURE__ */ new WeakMap(), lr = /* @__PURE__ */ new WeakMap();
|
|
3724
|
+
let ur = 0;
|
|
3725
|
+
function Pt(t, e, n) {
|
|
3653
3726
|
if (t)
|
|
3654
3727
|
try {
|
|
3655
3728
|
return JSON.parse(t);
|
|
@@ -3658,50 +3731,50 @@ function Nt(t, e, n) {
|
|
|
3658
3731
|
return;
|
|
3659
3732
|
}
|
|
3660
3733
|
}
|
|
3661
|
-
async function
|
|
3662
|
-
const n =
|
|
3734
|
+
async function dr(t, e = {}) {
|
|
3735
|
+
const n = mn.get(t);
|
|
3663
3736
|
if (n) return n;
|
|
3664
|
-
const i = Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")), s = i[0], r = t.getAttribute("data-src"), o =
|
|
3737
|
+
const i = Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")), s = i[0], r = t.getAttribute("data-src"), o = fr(t.getAttribute("data-markers")), c = i.length > 1 || s?.hasAttribute("data-scenario") ? hr(i, o, t) : void 0;
|
|
3665
3738
|
if (c && c.length === 0) return;
|
|
3666
|
-
let l = s && !c ?
|
|
3739
|
+
let l = s && !c ? Pt(s.textContent, "timeline", t) : void 0;
|
|
3667
3740
|
if (!l && r && o) {
|
|
3668
3741
|
const g = await fetch(r);
|
|
3669
3742
|
g.ok && (l = await g.json());
|
|
3670
3743
|
}
|
|
3671
|
-
if (l && o && (l =
|
|
3744
|
+
if (l && o && (l = ti(l, o)), !l && !r && !c) {
|
|
3672
3745
|
console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)', t);
|
|
3673
3746
|
return;
|
|
3674
3747
|
}
|
|
3675
|
-
const d =
|
|
3748
|
+
const d = Pt(t.querySelector("script[data-tinyfly-captions]")?.textContent, "captions", t), u = {
|
|
3676
3749
|
playWhenVisible: !0,
|
|
3677
3750
|
...e.player,
|
|
3678
3751
|
...d && { captions: d },
|
|
3679
|
-
...
|
|
3752
|
+
...Pt(t.getAttribute("data-options"), "data-options", t)
|
|
3680
3753
|
};
|
|
3681
|
-
|
|
3682
|
-
const
|
|
3683
|
-
if (
|
|
3754
|
+
pr(t);
|
|
3755
|
+
const f = new Zs(t, u), h = { element: t, player: f };
|
|
3756
|
+
if (mn.set(t, h), t.setAttribute("data-tinyfly-mounted", ""), c) {
|
|
3684
3757
|
const g = t.getAttribute("data-scenario") ?? void 0;
|
|
3685
|
-
await
|
|
3758
|
+
await f.loadScenarios(c, { initial: c.some((p) => p.id === g) ? g : void 0 }), lr.set(t, cr(f, t));
|
|
3686
3759
|
} else
|
|
3687
|
-
await
|
|
3760
|
+
await f.load(l ?? r);
|
|
3688
3761
|
if (t.getAttribute("data-controls") !== "false") {
|
|
3689
|
-
const g =
|
|
3690
|
-
h.controls =
|
|
3762
|
+
const g = Pt(t.getAttribute("data-labels"), "data-labels", t), p = t.querySelector("figcaption"), y = t.getAttribute("data-scenario-legend"), a = t.getAttribute("data-scenario-control");
|
|
3763
|
+
h.controls = er(f, t, {
|
|
3691
3764
|
...e.controls,
|
|
3692
3765
|
...t.getAttribute("data-fullscreen") === "true" ? { fullscreen: !0 } : {},
|
|
3693
3766
|
...a === "slider" || a === "buttons" ? { scenarioControl: a } : {},
|
|
3694
3767
|
labels: { ...e.controls?.labels, ...g, ...y ? { scenario: y } : {} },
|
|
3695
3768
|
// Inside the figure, before its figcaption, so the caption stays last.
|
|
3696
3769
|
mount: void 0
|
|
3697
|
-
}),
|
|
3770
|
+
}), p ? t.insertBefore(h.controls.element, p) : t.appendChild(h.controls.element);
|
|
3698
3771
|
}
|
|
3699
3772
|
return h;
|
|
3700
3773
|
}
|
|
3701
|
-
function
|
|
3774
|
+
function hr(t, e, n) {
|
|
3702
3775
|
const i = [];
|
|
3703
3776
|
return t.forEach((s, r) => {
|
|
3704
|
-
const o =
|
|
3777
|
+
const o = Pt(s.textContent, "timeline", n);
|
|
3705
3778
|
if (!o) return;
|
|
3706
3779
|
const c = s.getAttribute("data-scenario") || `scenario-${r + 1}`;
|
|
3707
3780
|
if (i.some((d) => d.id === c)) {
|
|
@@ -3709,61 +3782,61 @@ function ar(t, e, n) {
|
|
|
3709
3782
|
return;
|
|
3710
3783
|
}
|
|
3711
3784
|
const l = s.getAttribute("data-scenario-label") ?? void 0;
|
|
3712
|
-
i.push({ id: c, label: l, timeline: e ?
|
|
3785
|
+
i.push({ id: c, label: l, timeline: e ? ti(o, e) : o });
|
|
3713
3786
|
}), i;
|
|
3714
3787
|
}
|
|
3715
|
-
function
|
|
3788
|
+
function ti(t, e) {
|
|
3716
3789
|
return t.config.markers?.length ? t : { ...t, config: { ...t.config, markers: e.map((n, i) => ({ id: `step-${i + 1}`, time: n })) } };
|
|
3717
3790
|
}
|
|
3718
|
-
function
|
|
3791
|
+
function fr(t) {
|
|
3719
3792
|
if (!t) return;
|
|
3720
3793
|
const e = t.split(/[\s,]+/).filter(Boolean).map(Number).filter((n) => Number.isFinite(n) && n >= 0).sort((n, i) => n - i);
|
|
3721
3794
|
return e.length > 0 ? e : void 0;
|
|
3722
3795
|
}
|
|
3723
|
-
function
|
|
3796
|
+
function pr(t) {
|
|
3724
3797
|
const e = t.querySelector("svg");
|
|
3725
3798
|
if (!e || e.hasAttribute("role") || e.hasAttribute("aria-hidden")) return;
|
|
3726
3799
|
const n = t.getAttribute("data-alt"), i = t.querySelector("figcaption");
|
|
3727
|
-
e.setAttribute("role", "img"), n ? e.setAttribute("aria-label", n) : i && (i.id ||= `tinyfly-caption-${++
|
|
3800
|
+
e.setAttribute("role", "img"), n ? e.setAttribute("aria-label", n) : i && (i.id ||= `tinyfly-caption-${++ur}`, e.setAttribute("aria-labelledby", i.id));
|
|
3728
3801
|
}
|
|
3729
|
-
const
|
|
3730
|
-
function
|
|
3802
|
+
const yr = "http://www.w3.org/2000/svg", Ae = /* @__PURE__ */ new WeakMap();
|
|
3803
|
+
function mr(t, e) {
|
|
3731
3804
|
const n = t?.values.get(e);
|
|
3732
3805
|
return n ? Object.fromEntries(n) : {};
|
|
3733
3806
|
}
|
|
3734
|
-
async function
|
|
3735
|
-
const n =
|
|
3807
|
+
async function gr(t, e = {}) {
|
|
3808
|
+
const n = Ae.get(t);
|
|
3736
3809
|
if (n) return n;
|
|
3737
3810
|
const i = t.querySelector("script[data-tinyfly-figure]");
|
|
3738
3811
|
let s;
|
|
3739
3812
|
try {
|
|
3740
|
-
s =
|
|
3813
|
+
s = Et(JSON.parse(i?.textContent ?? "null"));
|
|
3741
3814
|
} catch (h) {
|
|
3742
3815
|
console.warn("tinyfly: math figure is missing or invalid", t, h);
|
|
3743
3816
|
return;
|
|
3744
3817
|
}
|
|
3745
3818
|
const r = t.getAttribute("data-target") ?? "fig";
|
|
3746
3819
|
let o = t.querySelector("svg[data-tinyfly-math-svg]");
|
|
3747
|
-
o || (o = t.ownerDocument.createElementNS(
|
|
3820
|
+
o || (o = t.ownerDocument.createElementNS(yr, "svg"), o.setAttribute("data-tinyfly-math-svg", ""), o.setAttribute("viewBox", `0 0 ${s.width} ${s.height}`), o.setAttribute("style", "display:block;width:100%;height:auto"), t.insertBefore(o, t.querySelector("figcaption")));
|
|
3748
3821
|
const c = (h) => {
|
|
3749
|
-
o.innerHTML =
|
|
3822
|
+
o.innerHTML = Ge(Rt(s, h));
|
|
3750
3823
|
};
|
|
3751
3824
|
if (c({}), !(t.querySelector("script[data-tinyfly-timeline]") || t.hasAttribute("data-src"))) {
|
|
3752
3825
|
const h = { element: t, figure: s, redraw: () => c({}) };
|
|
3753
|
-
return
|
|
3826
|
+
return Ae.set(t, h), h;
|
|
3754
3827
|
}
|
|
3755
|
-
const d = await
|
|
3828
|
+
const d = await dr(t, e);
|
|
3756
3829
|
if (!d) return;
|
|
3757
|
-
const u = () => c(
|
|
3830
|
+
const u = () => c(mr(d.player.state, r));
|
|
3758
3831
|
d.player.subscribe(u), u();
|
|
3759
|
-
const
|
|
3760
|
-
return
|
|
3832
|
+
const f = { ...d, figure: s, redraw: u };
|
|
3833
|
+
return Ae.set(t, f), f;
|
|
3761
3834
|
}
|
|
3762
|
-
async function
|
|
3835
|
+
async function Tr(t = document, e = {}) {
|
|
3763
3836
|
const n = Array.from(t.querySelectorAll("[data-tinyfly-math]"));
|
|
3764
|
-
return (await Promise.all(n.map((s) =>
|
|
3837
|
+
return (await Promise.all(n.map((s) => gr(s, e)))).filter((s) => s !== void 0);
|
|
3765
3838
|
}
|
|
3766
|
-
const
|
|
3839
|
+
const It = {
|
|
3767
3840
|
kind: "math",
|
|
3768
3841
|
create: "mathSurface(figure, { x, y })",
|
|
3769
3842
|
anchors: {
|
|
@@ -3783,18 +3856,18 @@ const Ot = {
|
|
|
3783
3856
|
step: "item:ID of an equation, { to } — moves to that step, terms gliding (default 900 ms)",
|
|
3784
3857
|
set: "value:NAME, { value } — tweens a value: a number, [x, y] or [a, b, c, d] (default 1200 ms)"
|
|
3785
3858
|
}
|
|
3786
|
-
},
|
|
3787
|
-
function
|
|
3859
|
+
}, br = (t, e, n) => typeof t == "number" && typeof e == "number" ? t + (e - t) * n : Array.isArray(t) && Array.isArray(e) ? t.map((i, s) => i + ((e[s] ?? i) - i) * n) : n < 1 ? t : e;
|
|
3860
|
+
function vr(t, e) {
|
|
3788
3861
|
const n = [...t].sort((i, s) => i.time - s.time);
|
|
3789
3862
|
if (e <= n[0].time) return n[0].value;
|
|
3790
3863
|
for (let i = 1; i < n.length; i++)
|
|
3791
3864
|
if (e <= n[i].time) {
|
|
3792
3865
|
const s = n[i - 1], r = n[i];
|
|
3793
|
-
return r.time === s.time ? r.value :
|
|
3866
|
+
return r.time === s.time ? r.value : br(s.value, r.value, (e - s.time) / (r.time - s.time));
|
|
3794
3867
|
}
|
|
3795
3868
|
return n[n.length - 1].value;
|
|
3796
3869
|
}
|
|
3797
|
-
function
|
|
3870
|
+
function wr(t) {
|
|
3798
3871
|
let e = 1 / 0, n = 1 / 0, i = -1 / 0, s = -1 / 0;
|
|
3799
3872
|
const r = (o, c) => {
|
|
3800
3873
|
e = Math.min(e, o), i = Math.max(i, o), n = Math.min(n, c), s = Math.max(s, c);
|
|
@@ -3809,10 +3882,10 @@ function yr(t) {
|
|
|
3809
3882
|
}
|
|
3810
3883
|
return Number.isFinite(e) ? { left: e, top: n, right: i, bottom: s } : void 0;
|
|
3811
3884
|
}
|
|
3812
|
-
const
|
|
3813
|
-
function
|
|
3814
|
-
|
|
3815
|
-
const n = e.x ?? 0, i = e.y ?? 0, s =
|
|
3885
|
+
const Te = (t) => t.replace(/\s+/g, "").replace(/-/g, "−").replace(/\*/g, "∗");
|
|
3886
|
+
function Or(t, e = {}) {
|
|
3887
|
+
Et(t);
|
|
3888
|
+
const n = e.x ?? 0, i = e.y ?? 0, s = Xs(t, { x: n, y: i }), r = /* @__PURE__ */ new Map(), o = t.items.map((y) => y.id), c = (y) => ({
|
|
3816
3889
|
left: n + y.left,
|
|
3817
3890
|
top: i + y.top,
|
|
3818
3891
|
right: n + y.right,
|
|
@@ -3824,15 +3897,15 @@ function Mr(t, e = {}) {
|
|
|
3824
3897
|
}), l = c({ left: 0, top: 0, right: t.width, bottom: t.height }), d = (y) => {
|
|
3825
3898
|
if (!y.includes(".")) {
|
|
3826
3899
|
const x = t.values?.[y];
|
|
3827
|
-
if (x === void 0) throw new Error(`mathSurface: ${
|
|
3900
|
+
if (x === void 0) throw new Error(`mathSurface: ${R("value", y, Object.keys(t.values ?? {}))}`);
|
|
3828
3901
|
return x;
|
|
3829
3902
|
}
|
|
3830
3903
|
const [a, m] = y.split("."), b = t.items.find((x) => x.id === a);
|
|
3831
3904
|
return m === "step" ? b.kind === "equation" ? b.step ?? 0 : 0 : b[m] ?? 1;
|
|
3832
3905
|
}, u = (y, a) => {
|
|
3833
3906
|
const m = r.get(y);
|
|
3834
|
-
return m?.length ?
|
|
3835
|
-
},
|
|
3907
|
+
return m?.length ? vr(m, a) : d(y);
|
|
3908
|
+
}, f = (y, a, m, b) => {
|
|
3836
3909
|
const x = u(y, m.at);
|
|
3837
3910
|
r.set(y, [...r.get(y) ?? [], { time: m.at, value: x }, { time: m.at + (m.duration ?? b), value: a, ...m.easing ? { easing: m.easing } : {} }]);
|
|
3838
3911
|
}, h = (y) => {
|
|
@@ -3841,27 +3914,27 @@ function Mr(t, e = {}) {
|
|
|
3841
3914
|
return a;
|
|
3842
3915
|
}, g = (y, a) => {
|
|
3843
3916
|
const m = a.split(":")[0].split("#")[0].split(".")[0];
|
|
3844
|
-
if (!o.includes(m)) throw new Error(`mathSurface: ${y}: ${
|
|
3917
|
+
if (!o.includes(m)) throw new Error(`mathSurface: ${y}: ${R("item", m, o)}`);
|
|
3845
3918
|
return m;
|
|
3846
|
-
},
|
|
3919
|
+
}, p = {
|
|
3847
3920
|
kind: "math",
|
|
3848
3921
|
target: s,
|
|
3849
3922
|
box: l,
|
|
3850
|
-
about:
|
|
3923
|
+
about: It,
|
|
3851
3924
|
anchor(y, a = 1 / 0) {
|
|
3852
3925
|
const m = y.indexOf(":"), b = m < 0 ? y : y.slice(0, m), x = m < 0 ? "" : y.slice(m + 1);
|
|
3853
3926
|
if (b === "box" || b === "value") return l;
|
|
3854
3927
|
if (!["item", "tip", "point", "node", "term"].includes(b))
|
|
3855
|
-
throw new Error(`mathSurface: ${
|
|
3856
|
-
const w =
|
|
3928
|
+
throw new Error(`mathSurface: ${R("anchor", b, Object.keys(It.anchors).map((k) => k.split(":")[0]))}`);
|
|
3929
|
+
const w = Rt(t, h(a)).shapes, v = (k) => w.filter((S) => S.id === k || S.id.startsWith(`${k}.`));
|
|
3857
3930
|
let $ = [];
|
|
3858
3931
|
if (b === "item") $ = v(g(y, x));
|
|
3859
3932
|
else if (b === "tip") {
|
|
3860
3933
|
g(y, x);
|
|
3861
|
-
const k = w.find((
|
|
3934
|
+
const k = w.find((O) => O.type === "arrow" && (O.id === x || O.id === `${x}.0`));
|
|
3862
3935
|
if (!k || k.type !== "arrow") throw new Error(`mathSurface: no vector at "${y}" (a vector item id, or basis.i / basis.j)`);
|
|
3863
|
-
const [S, E] = k.points[k.points.length - 1],
|
|
3864
|
-
return c({ left: S -
|
|
3936
|
+
const [S, E] = k.points[k.points.length - 1], T = k.width * 2.5;
|
|
3937
|
+
return c({ left: S - T, top: E - T, right: S + T, bottom: E + T });
|
|
3865
3938
|
} else if (b === "point") $ = w.filter((k) => k.id === g(y, x) && k.type === "circle");
|
|
3866
3939
|
else if (b === "node") {
|
|
3867
3940
|
const [k, S] = x.split(":");
|
|
@@ -3869,48 +3942,48 @@ function Mr(t, e = {}) {
|
|
|
3869
3942
|
} else {
|
|
3870
3943
|
const k = /^([^:#]+)(?:#(\d+))?:(.+)$/.exec(x);
|
|
3871
3944
|
if (!k) throw new Error(`mathSurface: "${y}" should be term:ID:TEXT`);
|
|
3872
|
-
const [, S, E,
|
|
3945
|
+
const [, S, E, T] = k;
|
|
3873
3946
|
g(y, S);
|
|
3874
|
-
const
|
|
3947
|
+
const O = v(S).filter((I) => I.type === "text" && !I.id.includes(".backdrop")), z = Te(T), q = O.map((I) => Te(I.text)).join("");
|
|
3875
3948
|
let A = -1;
|
|
3876
|
-
for (let
|
|
3949
|
+
for (let I = 0, L = 0; I < Number(E ?? 1) && (A = q.indexOf(z, L), !(A < 0)); I++, L = A + 1)
|
|
3877
3950
|
;
|
|
3878
|
-
if (A < 0) throw new Error(`mathSurface: no "${
|
|
3879
|
-
let
|
|
3880
|
-
$ =
|
|
3881
|
-
const
|
|
3882
|
-
return
|
|
3951
|
+
if (A < 0) throw new Error(`mathSurface: no "${T}" in ${S} (it reads "${q}")`);
|
|
3952
|
+
let N = 0;
|
|
3953
|
+
$ = O.filter((I) => {
|
|
3954
|
+
const L = Te(I.text).length, C = N < A + z.length && N + L > A;
|
|
3955
|
+
return N += L, C;
|
|
3883
3956
|
});
|
|
3884
3957
|
}
|
|
3885
|
-
const M =
|
|
3958
|
+
const M = wr($);
|
|
3886
3959
|
if (!M) throw new Error(`mathSurface: "${y}" is not drawn at ${a === 1 / 0 ? "the end" : `${a} ms`}`);
|
|
3887
3960
|
return c(M);
|
|
3888
3961
|
},
|
|
3889
3962
|
edit(y, a, m) {
|
|
3890
|
-
if (!(y in
|
|
3963
|
+
if (!(y in It.edits)) throw new Error(`mathSurface.edit: ${R("edit", y, Object.keys(It.edits))}`);
|
|
3891
3964
|
for (const b of Array.isArray(a) ? a : [a]) {
|
|
3892
3965
|
const [x, w = ""] = [b.slice(0, b.indexOf(":")), b.slice(b.indexOf(":") + 1)];
|
|
3893
3966
|
if (y === "set") {
|
|
3894
3967
|
if (x !== "value") throw new Error(`mathSurface.edit: set takes value:NAME, not "${b}"`);
|
|
3895
3968
|
if (m.value === void 0) throw new Error("mathSurface.edit: set needs `value`");
|
|
3896
|
-
d(w),
|
|
3969
|
+
d(w), f(w, m.value, m, 1200);
|
|
3897
3970
|
continue;
|
|
3898
3971
|
}
|
|
3899
3972
|
if (x !== "item") throw new Error(`mathSurface.edit: ${y} takes item:ID, not "${b}"`);
|
|
3900
3973
|
const v = g(b, w);
|
|
3901
|
-
if (y === "drawOn")
|
|
3902
|
-
else if (y === "erase")
|
|
3903
|
-
else if (y === "show")
|
|
3904
|
-
else if (y === "hide")
|
|
3974
|
+
if (y === "drawOn") f(`${v}.draw`, 1, m, 900);
|
|
3975
|
+
else if (y === "erase") f(`${v}.draw`, 0, m, 600);
|
|
3976
|
+
else if (y === "show") f(`${v}.opacity`, 1, m, 500);
|
|
3977
|
+
else if (y === "hide") f(`${v}.opacity`, 0, m, 500);
|
|
3905
3978
|
else {
|
|
3906
3979
|
if (typeof m.to != "number") throw new Error("mathSurface.edit: step needs `to`, the step number");
|
|
3907
|
-
|
|
3980
|
+
f(`${v}.step`, m.to, m, 900);
|
|
3908
3981
|
}
|
|
3909
3982
|
}
|
|
3910
|
-
return
|
|
3983
|
+
return p;
|
|
3911
3984
|
},
|
|
3912
3985
|
piece(y) {
|
|
3913
|
-
throw new Error(`mathSurface: parts of a figure do not come loose ("${y}"); change it with edits (${Object.keys(
|
|
3986
|
+
throw new Error(`mathSurface: parts of a figure do not come loose ("${y}"); change it with edits (${Object.keys(It.edits).join(", ")})`);
|
|
3914
3987
|
},
|
|
3915
3988
|
follow() {
|
|
3916
3989
|
throw new Error("mathSurface: parts of a figure do not come loose; use edits instead");
|
|
@@ -3931,19 +4004,19 @@ function Mr(t, e = {}) {
|
|
|
3931
4004
|
}));
|
|
3932
4005
|
}
|
|
3933
4006
|
};
|
|
3934
|
-
return
|
|
4007
|
+
return p;
|
|
3935
4008
|
}
|
|
3936
|
-
const
|
|
3937
|
-
function
|
|
3938
|
-
|
|
4009
|
+
const $r = "http://www.w3.org/2000/svg";
|
|
4010
|
+
function Nr(t, e, n = {}) {
|
|
4011
|
+
Et(e);
|
|
3939
4012
|
const i = { ...e.values ?? {} };
|
|
3940
4013
|
for (const w of n.sliders ?? [])
|
|
3941
4014
|
if (typeof i[w.value] != "number") throw new Error(`mathExplorable: slider value "${w.value}" is not a number value of the figure`);
|
|
3942
4015
|
for (const w of n.drag ?? []) {
|
|
3943
|
-
if ("vector" in w && !
|
|
3944
|
-
if ("matrix" in w &&
|
|
4016
|
+
if ("vector" in w && !ot(i[w.vector])) throw new Error(`mathExplorable: "${w.vector}" is not a vector value of the figure`);
|
|
4017
|
+
if ("matrix" in w && !$t(i[w.matrix])) throw new Error(`mathExplorable: "${w.matrix}" is not a matrix value of the figure`);
|
|
3945
4018
|
}
|
|
3946
|
-
const s =
|
|
4019
|
+
const s = Xn(e), r = t.ownerDocument, o = r.createElementNS($r, "svg");
|
|
3947
4020
|
o.setAttribute("viewBox", `0 0 ${e.width} ${e.height}`), o.setAttribute("style", "display:block;width:100%;height:auto;touch-action:none"), o.setAttribute("role", "img"), t.appendChild(o);
|
|
3948
4021
|
const c = n.drag ?? [], l = (w) => {
|
|
3949
4022
|
if ("vector" in w) return i[w.vector];
|
|
@@ -3954,13 +4027,13 @@ function xr(t, e, n = {}) {
|
|
|
3954
4027
|
const [$, M] = s.toScreen(l(v));
|
|
3955
4028
|
return `<circle cx="${$}" 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"/>`;
|
|
3956
4029
|
});
|
|
3957
|
-
o.innerHTML =
|
|
4030
|
+
o.innerHTML = Ge(Rt(e, i)) + w.join(""), n.onChange?.({ ...i });
|
|
3958
4031
|
}, u = (w, v) => {
|
|
3959
4032
|
if (!(w in i)) throw new Error(`mathExplorable: no value "${w}"`);
|
|
3960
4033
|
i[w] = v;
|
|
3961
|
-
const $ =
|
|
4034
|
+
const $ = f.get(w);
|
|
3962
4035
|
$ && typeof v == "number" && ($.value = String(v), h.get(w).textContent = String(v)), d();
|
|
3963
|
-
},
|
|
4036
|
+
}, f = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
|
|
3964
4037
|
let g;
|
|
3965
4038
|
if (n.sliders?.length) {
|
|
3966
4039
|
g = r.createElement("div"), g.setAttribute("style", "display:flex;flex-wrap:wrap;gap:8px 18px;align-items:center;padding:8px 0;font:14px system-ui,sans-serif");
|
|
@@ -3970,12 +4043,12 @@ function xr(t, e, n = {}) {
|
|
|
3970
4043
|
const $ = r.createElement("input");
|
|
3971
4044
|
$.type = "range", $.min = String(w.min), $.max = String(w.max), $.step = String(w.step ?? (w.max - w.min) / 100), $.value = String(i[w.value]), $.setAttribute("aria-label", w.label ?? w.value);
|
|
3972
4045
|
const M = r.createElement("output");
|
|
3973
|
-
M.textContent = String(i[w.value]), $.addEventListener("input", () => u(w.value, Number($.value))), v.append(w.label ?? w.value, $, M), g.appendChild(v),
|
|
4046
|
+
M.textContent = String(i[w.value]), $.addEventListener("input", () => u(w.value, Number($.value))), v.append(w.label ?? w.value, $, M), g.appendChild(v), f.set(w.value, $), h.set(w.value, M);
|
|
3974
4047
|
}
|
|
3975
4048
|
t.appendChild(g);
|
|
3976
4049
|
}
|
|
3977
|
-
const
|
|
3978
|
-
const v = o.getBoundingClientRect(), $ = (w.clientX - v.left) / (v.width || e.width) * e.width, M = (w.clientY - v.top) / (v.height || e.height) * e.height, [k, S] = s.toWorld([$, M]), E = (
|
|
4050
|
+
const p = n.snap ?? 0.1, y = (w) => {
|
|
4051
|
+
const v = o.getBoundingClientRect(), $ = (w.clientX - v.left) / (v.width || e.width) * e.width, M = (w.clientY - v.top) / (v.height || e.height) * e.height, [k, S] = s.toWorld([$, M]), E = (T) => p > 0 ? Math.round(T / p) * p : T;
|
|
3979
4052
|
return [Number(E(k).toFixed(6)), Number(E(S).toFixed(6))];
|
|
3980
4053
|
};
|
|
3981
4054
|
let a;
|
|
@@ -3983,8 +4056,8 @@ function xr(t, e, n = {}) {
|
|
|
3983
4056
|
const v = o.getBoundingClientRect(), $ = e.width / (v.width || e.width), M = [(w.clientX - v.left) * $, (w.clientY - v.top) * $];
|
|
3984
4057
|
let k;
|
|
3985
4058
|
for (const S of c) {
|
|
3986
|
-
const [E,
|
|
3987
|
-
|
|
4059
|
+
const [E, T] = s.toScreen(l(S)), O = Math.hypot(E - M[0], T - M[1]);
|
|
4060
|
+
O < 30 * s.scale * Math.max(1, $) && (!k || O < k.distance) && (k = { handle: S, distance: O });
|
|
3988
4061
|
}
|
|
3989
4062
|
k && (a = k.handle, o.setPointerCapture?.(w.pointerId), w.preventDefault());
|
|
3990
4063
|
}, b = (w) => {
|
|
@@ -4009,41 +4082,41 @@ function xr(t, e, n = {}) {
|
|
|
4009
4082
|
}
|
|
4010
4083
|
};
|
|
4011
4084
|
}
|
|
4012
|
-
const
|
|
4085
|
+
const Bt = (t, e, n) => ({
|
|
4013
4086
|
width: t.width ?? 600,
|
|
4014
4087
|
height: t.height ?? 600,
|
|
4015
4088
|
...t.theme ? { theme: t.theme } : {},
|
|
4016
4089
|
...t.x ? { x: t.x } : {},
|
|
4017
4090
|
values: e,
|
|
4018
4091
|
items: n
|
|
4019
|
-
}),
|
|
4020
|
-
function
|
|
4021
|
-
return
|
|
4092
|
+
}), Xe = "\\begin{bmatrix} \\val{M.a} & \\val{M.b} \\\\ \\val{M.c} & \\val{M.d} \\end{bmatrix}", Ye = (t) => [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.1];
|
|
4093
|
+
function Ir(t = {}) {
|
|
4094
|
+
return Bt(t, { M: t.matrix ?? zt }, [
|
|
4022
4095
|
{ id: "grid", kind: "grid", transform: "M", ghost: !0 },
|
|
4023
4096
|
{ id: "square", kind: "polygon", transform: "M", color: "yellow", fillOpacity: 0.25 },
|
|
4024
4097
|
{ id: "basis", kind: "basis", transform: "M" },
|
|
4025
|
-
{ id: "matrix", kind: "label", tex:
|
|
4098
|
+
{ id: "matrix", kind: "label", tex: Xe, at: Ye(t), screen: !0, align: "left" }
|
|
4026
4099
|
]);
|
|
4027
4100
|
}
|
|
4028
|
-
function
|
|
4029
|
-
return
|
|
4101
|
+
function Pr(t = {}) {
|
|
4102
|
+
return Bt(t, { M: t.matrix ?? zt }, [
|
|
4030
4103
|
{ id: "grid", kind: "grid", transform: "M", ghost: !0 },
|
|
4031
4104
|
{ id: "square", kind: "polygon", transform: "M", color: "yellow", fillOpacity: 0.35, label: "\\det = \\val{M.det}" },
|
|
4032
4105
|
{ id: "basis", kind: "basis", transform: "M" },
|
|
4033
|
-
{ id: "matrix", kind: "label", tex:
|
|
4106
|
+
{ id: "matrix", kind: "label", tex: Xe, at: Ye(t), screen: !0, align: "left" }
|
|
4034
4107
|
]);
|
|
4035
4108
|
}
|
|
4036
|
-
function
|
|
4037
|
-
return
|
|
4109
|
+
function Fr(t) {
|
|
4110
|
+
return Bt(t, { M: zt, A: t.matrix }, [
|
|
4038
4111
|
{ id: "grid", kind: "grid", transform: "M", ghost: !0 },
|
|
4039
4112
|
{ id: "eigen", kind: "line", eigen: "A", color: "yellow", width: 3 },
|
|
4040
4113
|
{ id: "basis", kind: "basis", transform: "M" },
|
|
4041
|
-
{ id: "matrix", kind: "label", tex:
|
|
4114
|
+
{ id: "matrix", kind: "label", tex: Xe, at: Ye(t), screen: !0, align: "left" }
|
|
4042
4115
|
]);
|
|
4043
4116
|
}
|
|
4044
|
-
function
|
|
4117
|
+
function Lr(t) {
|
|
4045
4118
|
const e = [t.u[0] + t.v[0], t.u[1] + t.v[1]];
|
|
4046
|
-
return
|
|
4119
|
+
return Bt(t, { u: t.u, v: t.v, s: e }, [
|
|
4047
4120
|
{ id: "grid", kind: "grid", ghost: !1, color: "grey", opacity: 0.5 },
|
|
4048
4121
|
{ id: "axes", kind: "axes" },
|
|
4049
4122
|
{ id: "arrowU", kind: "vector", to: "u", color: "green", label: "\\vec{u}", labelAt: "middle" },
|
|
@@ -4051,15 +4124,15 @@ function Tr(t) {
|
|
|
4051
4124
|
{ id: "sum", kind: "vector", to: "s", color: "yellow", label: "\\vec{u} + \\vec{v}" }
|
|
4052
4125
|
]);
|
|
4053
4126
|
}
|
|
4054
|
-
function
|
|
4127
|
+
function Cr(t) {
|
|
4055
4128
|
const e = [
|
|
4056
4129
|
{ id: "axes", kind: "axes" },
|
|
4057
4130
|
{ id: "spanU", kind: "line", along: "u", color: "green", dashed: !0 },
|
|
4058
4131
|
{ id: "arrowU", kind: "vector", to: "u", color: "green", label: "\\vec{u}" }
|
|
4059
4132
|
], n = { u: t.u };
|
|
4060
|
-
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}" })),
|
|
4133
|
+
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}" })), Bt(t, n, e);
|
|
4061
4134
|
}
|
|
4062
|
-
const
|
|
4135
|
+
const At = (t, e, n) => ({
|
|
4063
4136
|
width: t.width ?? 600,
|
|
4064
4137
|
height: t.height ?? 600,
|
|
4065
4138
|
...t.theme ? { theme: t.theme } : {},
|
|
@@ -4068,18 +4141,18 @@ const St = (t, e, n) => ({
|
|
|
4068
4141
|
values: e,
|
|
4069
4142
|
items: [{ id: "axes", kind: "axes" }, { id: "f", kind: "function", expr: t.expr, color: "blue" }, ...n]
|
|
4070
4143
|
});
|
|
4071
|
-
function
|
|
4072
|
-
return
|
|
4144
|
+
function qr(t) {
|
|
4145
|
+
return At(t, { a: t.at ?? 1 }, [
|
|
4073
4146
|
{ id: "tangent", kind: "tangent", expr: t.expr, at: "a", color: "yellow", label: "\\text{slope} = \\val{tangent.slope}" }
|
|
4074
4147
|
]);
|
|
4075
4148
|
}
|
|
4076
|
-
function
|
|
4077
|
-
return
|
|
4149
|
+
function zr(t) {
|
|
4150
|
+
return At(t, { a: t.at ?? 1, h: t.h ?? 2 }, [
|
|
4078
4151
|
{ id: "secant", kind: "tangent", expr: t.expr, at: "a", h: "h", color: "yellow", label: "\\frac{\\Delta y}{\\Delta x} = \\val{secant.slope}" }
|
|
4079
4152
|
]);
|
|
4080
4153
|
}
|
|
4081
|
-
function
|
|
4082
|
-
const e =
|
|
4154
|
+
function jr(t) {
|
|
4155
|
+
const e = At(t, { n: t.n ?? 4 }, [
|
|
4083
4156
|
{ id: "sum", kind: "riemann", expr: t.expr, from: t.from, to: t.to, n: "n", rule: t.rule ?? "left", color: "teal" }
|
|
4084
4157
|
]);
|
|
4085
4158
|
return e.items.push(e.items.splice(1, 1)[0]), e.items.push({
|
|
@@ -4092,8 +4165,8 @@ function Pr(t) {
|
|
|
4092
4165
|
tex: "n = \\val{sum.n:0} \\quad \\text{sum} = \\val{sum.sum:3} \\quad \\int = \\val{sum.exact:3}"
|
|
4093
4166
|
}), e;
|
|
4094
4167
|
}
|
|
4095
|
-
function
|
|
4096
|
-
const e =
|
|
4168
|
+
function Dr(t) {
|
|
4169
|
+
const e = At(t, { b: t.to }, [
|
|
4097
4170
|
{ id: "area", kind: "area", expr: t.expr, from: t.from, to: "b", color: "teal" }
|
|
4098
4171
|
]);
|
|
4099
4172
|
return e.items.push(e.items.splice(1, 1)[0]), e.items.push({
|
|
@@ -4106,8 +4179,8 @@ function Fr(t) {
|
|
|
4106
4179
|
tex: `\\int_{${t.from}}^{\\val{b:2}} f(x)\\,dx = \\val{area.value:3}`
|
|
4107
4180
|
}), e;
|
|
4108
4181
|
}
|
|
4109
|
-
function
|
|
4110
|
-
const e =
|
|
4182
|
+
function _r(t) {
|
|
4183
|
+
const e = At(t, { order: t.order ?? 1 }, [
|
|
4111
4184
|
{ id: "taylor", kind: "taylor", expr: t.expr, at: t.at ?? 0, order: "order", color: "yellow" },
|
|
4112
4185
|
{ id: "centre", kind: "point", on: t.expr, x: t.at ?? 0, color: "yellow" }
|
|
4113
4186
|
]);
|
|
@@ -4121,8 +4194,8 @@ function Lr(t) {
|
|
|
4121
4194
|
tex: "\\text{degree } \\val{taylor.degree:0}"
|
|
4122
4195
|
}), e;
|
|
4123
4196
|
}
|
|
4124
|
-
function
|
|
4125
|
-
const e =
|
|
4197
|
+
function Rr(t) {
|
|
4198
|
+
const e = At(t, { p: t.from ?? t.at - 2 }, [
|
|
4126
4199
|
{ id: "hole", kind: "point", at: [t.at, t.limit], hollow: !0, color: "blue", radius: 7 },
|
|
4127
4200
|
{ id: "moving", kind: "point", on: t.expr, x: "p", color: "yellow" }
|
|
4128
4201
|
]);
|
|
@@ -4136,7 +4209,7 @@ function qr(t) {
|
|
|
4136
4209
|
tex: "f(\\val{moving.x:3}) = \\val{moving.y:4}"
|
|
4137
4210
|
}), e;
|
|
4138
4211
|
}
|
|
4139
|
-
const
|
|
4212
|
+
const vt = (t, e, n, i) => ({
|
|
4140
4213
|
width: t.width ?? 600,
|
|
4141
4214
|
height: t.height ?? 600,
|
|
4142
4215
|
...t.theme ? { theme: t.theme } : {},
|
|
@@ -4144,7 +4217,7 @@ const gt = (t, e, n, i) => ({
|
|
|
4144
4217
|
y: t.y ?? e.y,
|
|
4145
4218
|
values: n,
|
|
4146
4219
|
items: i
|
|
4147
|
-
}),
|
|
4220
|
+
}), Tt = (t, e) => ({
|
|
4148
4221
|
id: "readout",
|
|
4149
4222
|
kind: "label",
|
|
4150
4223
|
screen: !0,
|
|
@@ -4153,57 +4226,57 @@ const gt = (t, e, n, i) => ({
|
|
|
4153
4226
|
at: [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.08],
|
|
4154
4227
|
tex: e
|
|
4155
4228
|
});
|
|
4156
|
-
function
|
|
4229
|
+
function Br(t = {}) {
|
|
4157
4230
|
const [e, n] = t.shade ?? [-1, 1];
|
|
4158
|
-
return
|
|
4231
|
+
return vt(t, { x: [-4, 4], y: [-0.08, 0.55] }, { mu: t.mean ?? 0, sigma: t.sd ?? 1, a: e, b: n }, [
|
|
4159
4232
|
{ id: "axes", kind: "axes", ticks: 1, labels: !0 },
|
|
4160
4233
|
{ id: "dist", kind: "distribution", distribution: { kind: "normal", mean: "mu", sd: "sigma" }, shade: ["a", "b"] },
|
|
4161
|
-
|
|
4234
|
+
Tt(t, "P(\\val{a:2} \\le X \\le \\val{b:2}) = \\val{dist.p:3}")
|
|
4162
4235
|
]);
|
|
4163
4236
|
}
|
|
4164
|
-
function
|
|
4237
|
+
function Vr(t = {}) {
|
|
4165
4238
|
const e = t.n ?? 10;
|
|
4166
|
-
return
|
|
4239
|
+
return vt(t, { x: [-1, e + 1], y: [-0.04, 0.4] }, { n: e, p: t.p ?? 0.5 }, [
|
|
4167
4240
|
{ id: "axes", kind: "axes", ticks: Math.max(1, Math.round(e / 10)) },
|
|
4168
4241
|
{ id: "dist", kind: "distribution", distribution: { kind: "binomial", n: "n", p: "p" } },
|
|
4169
|
-
|
|
4242
|
+
Tt(t, "n = \\val{n:0} \\quad p = \\val{p:2} \\quad \\mu = \\val{dist.mean:2}")
|
|
4170
4243
|
]);
|
|
4171
4244
|
}
|
|
4172
|
-
function
|
|
4173
|
-
return
|
|
4245
|
+
function Hr(t = {}) {
|
|
4246
|
+
return vt(t, { x: [-0.2, 3.2], y: [-0.2, 3] }, { k: t.k ?? 1, samples: t.samples ?? 2e3 }, [
|
|
4174
4247
|
{ id: "axes", kind: "axes", ticks: 1 },
|
|
4175
4248
|
{ 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" },
|
|
4176
|
-
|
|
4249
|
+
Tt(t, "k = \\val{k:0} \\text{ draws averaged} \\quad \\bar{x} = \\val{hist.mean:3} \\quad s = \\val{hist.sd:3}")
|
|
4177
4250
|
]);
|
|
4178
4251
|
}
|
|
4179
|
-
function
|
|
4252
|
+
function Ur(t = {}) {
|
|
4180
4253
|
const e = t.rows ?? 10;
|
|
4181
|
-
return
|
|
4254
|
+
return vt(t, { x: [-(e + 2) * 0.25, (e + 2) * 0.25], y: [-12, 1] }, { balls: t.balls ?? 0 }, [
|
|
4182
4255
|
{ id: "board", kind: "galton", rows: e, balls: "balls", spacing: 0.5, top: 0 },
|
|
4183
|
-
|
|
4256
|
+
Tt(t, "\\val{board.landed:0} \\text{ balls}")
|
|
4184
4257
|
]);
|
|
4185
4258
|
}
|
|
4186
|
-
function
|
|
4187
|
-
return
|
|
4259
|
+
function Wr(t = {}) {
|
|
4260
|
+
return vt(t, { x: [-1.3, 1.3], y: [-1.3, 1.3] }, { count: t.count ?? 0 }, [
|
|
4188
4261
|
{ id: "square", kind: "polygon", points: [[-1, -1], [1, -1], [1, 1], [-1, 1]], color: "grey", fillOpacity: 0 },
|
|
4189
4262
|
{ id: "circle", kind: "parametric", x: "cos(t)", y: "sin(t)", color: "yellow", width: 2.5 },
|
|
4190
4263
|
{ 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 },
|
|
4191
|
-
|
|
4264
|
+
Tt(t, "\\frac{\\text{inside}}{\\text{all}} = \\frac{\\val{pts.inside:0}}{\\val{pts.count:0}} = \\val{pts.ratio:4} \\approx \\frac{\\pi}{4}")
|
|
4192
4265
|
]);
|
|
4193
4266
|
}
|
|
4194
|
-
function
|
|
4195
|
-
return
|
|
4267
|
+
function Gr(t = {}) {
|
|
4268
|
+
return vt(t, { x: [-1, 11], y: [-2, 10] }, { slope: t.slope ?? 0.6, intercept: t.intercept ?? 1, noise: t.noise ?? 1, count: t.count ?? 60 }, [
|
|
4196
4269
|
{ id: "axes", kind: "axes", ticks: 2 },
|
|
4197
4270
|
{ id: "pts", kind: "scatter", points: { kind: "linear", slope: "slope", intercept: "intercept", noise: "noise", x: [0, 10] }, count: "count", fit: !0, radius: 3.5 },
|
|
4198
|
-
|
|
4271
|
+
Tt(t, "y = \\val{pts.slope:2}\\,x + \\val{pts.intercept:2} \\quad r = \\val{pts.r:2}")
|
|
4199
4272
|
]);
|
|
4200
4273
|
}
|
|
4201
|
-
function
|
|
4202
|
-
return
|
|
4274
|
+
function Xr(t = {}) {
|
|
4275
|
+
return vt(t, { x: [0, 1], y: [0, 1] }, { prior: t.prior ?? 0.1, sensitivity: t.sensitivity ?? 0.9, falsePositive: t.falsePositive ?? 0.1 }, [
|
|
4203
4276
|
{ id: "test", kind: "bayes", prior: "prior", truePositive: "sensitivity", falsePositive: "falsePositive", at: [0.08, 0.2], size: [0.84, 0.66] }
|
|
4204
4277
|
]);
|
|
4205
4278
|
}
|
|
4206
|
-
const
|
|
4279
|
+
const mt = (t) => ({ width: t.width ?? 600, height: t.height ?? 600, ...t.theme ? { theme: t.theme } : {} }), Vt = (t, e) => ({
|
|
4207
4280
|
id: "readout",
|
|
4208
4281
|
kind: "label",
|
|
4209
4282
|
screen: !0,
|
|
@@ -4211,7 +4284,7 @@ const ft = (t) => ({ width: t.width ?? 600, height: t.height ?? 600, ...t.theme
|
|
|
4211
4284
|
size: 22,
|
|
4212
4285
|
at: [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.07],
|
|
4213
4286
|
tex: e
|
|
4214
|
-
}),
|
|
4287
|
+
}), he = {
|
|
4215
4288
|
nodes: [
|
|
4216
4289
|
{ id: "A", at: [-3, 1.5] },
|
|
4217
4290
|
{ id: "B", at: [-1, 2.5] },
|
|
@@ -4224,33 +4297,33 @@ const ft = (t) => ({ width: t.width ?? 600, height: t.height ?? 600, ...t.theme
|
|
|
4224
4297
|
],
|
|
4225
4298
|
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]]
|
|
4226
4299
|
};
|
|
4227
|
-
function
|
|
4228
|
-
const { width: e, height: n } =
|
|
4300
|
+
function Yr(t = {}) {
|
|
4301
|
+
const { width: e, height: n } = mt(t);
|
|
4229
4302
|
return {
|
|
4230
|
-
...
|
|
4303
|
+
...mt(t),
|
|
4231
4304
|
x: [-4.2, 4.2],
|
|
4232
4305
|
y: [-3.6, 3.6],
|
|
4233
4306
|
values: { step: 0 },
|
|
4234
4307
|
items: [
|
|
4235
|
-
{ id: "g", kind: "graph", nodes: t.nodes ??
|
|
4236
|
-
|
|
4308
|
+
{ id: "g", kind: "graph", nodes: t.nodes ?? he.nodes, edges: t.edges ?? he.edges.map(([i, s]) => [i, s]), search: { kind: t.search ?? "bfs", start: t.start ?? "A" }, step: "step", frontier: [e * 0.06, n * 0.92] },
|
|
4309
|
+
Vt(t, "\\text{visited } \\val{g.visited:0} \\text{ of } \\val{g.steps:0}")
|
|
4237
4310
|
]
|
|
4238
4311
|
};
|
|
4239
4312
|
}
|
|
4240
|
-
function
|
|
4241
|
-
const { width: e, height: n } =
|
|
4313
|
+
function Zr(t = {}) {
|
|
4314
|
+
const { width: e, height: n } = mt(t), i = t.target ?? "G";
|
|
4242
4315
|
return {
|
|
4243
|
-
...
|
|
4316
|
+
...mt(t),
|
|
4244
4317
|
x: [-4.2, 4.2],
|
|
4245
4318
|
y: [-3.6, 3.6],
|
|
4246
4319
|
values: { step: 0 },
|
|
4247
4320
|
items: [
|
|
4248
|
-
{ id: "g", kind: "graph", nodes: t.nodes ??
|
|
4249
|
-
|
|
4321
|
+
{ id: "g", kind: "graph", nodes: t.nodes ?? he.nodes, edges: t.edges ?? he.edges, search: { kind: "dijkstra", start: t.start ?? "A" }, step: "step", frontier: [e * 0.06, n * 0.92] },
|
|
4322
|
+
Vt(t, `d(${i}) = \\val{g.d.${i}:0}`)
|
|
4250
4323
|
]
|
|
4251
4324
|
};
|
|
4252
4325
|
}
|
|
4253
|
-
function
|
|
4326
|
+
function Jr(t = {}) {
|
|
4254
4327
|
const e = Math.min(6, Math.max(1, t.n ?? 5)), n = [], i = [], s = (c) => {
|
|
4255
4328
|
const l = `c${n.length}`;
|
|
4256
4329
|
return n.push({ id: l, label: `F_{${c}}` }), c >= 2 && (i.push([l, s(c - 1)]), i.push([l, s(c - 2)])), l;
|
|
@@ -4258,34 +4331,34 @@ function Ur(t = {}) {
|
|
|
4258
4331
|
s(e);
|
|
4259
4332
|
const r = n.filter((c) => !i.some(([l]) => l === c.id)).length, o = Math.max(r * 0.75, 4);
|
|
4260
4333
|
return {
|
|
4261
|
-
...
|
|
4334
|
+
...mt(t),
|
|
4262
4335
|
x: [-o, o],
|
|
4263
4336
|
y: [-(e + 0.2) * 1.05, 1.2],
|
|
4264
4337
|
values: { step: 0 },
|
|
4265
4338
|
items: [
|
|
4266
4339
|
{ 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 },
|
|
4267
|
-
|
|
4340
|
+
Vt(t, "\\text{calls made: } \\val{calls.visited:0} \\text{ of } \\val{calls.steps:0}")
|
|
4268
4341
|
]
|
|
4269
4342
|
};
|
|
4270
4343
|
}
|
|
4271
|
-
function
|
|
4344
|
+
function Kr(t = {}) {
|
|
4272
4345
|
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] }];
|
|
4273
|
-
return t.label !== void 0 && n.push(
|
|
4346
|
+
return t.label !== void 0 && n.push(Vt(t, t.label)), { ...mt(t), x: [-4, 4], y: [-4, 4], items: n };
|
|
4274
4347
|
}
|
|
4275
|
-
function
|
|
4348
|
+
function Qr(t = {}) {
|
|
4276
4349
|
const e = t.modulus ?? 12;
|
|
4277
4350
|
return {
|
|
4278
|
-
...
|
|
4351
|
+
...mt(t),
|
|
4279
4352
|
x: [-3, 3],
|
|
4280
4353
|
y: [-3, 3],
|
|
4281
4354
|
values: { value: t.value ?? 0 },
|
|
4282
4355
|
items: [
|
|
4283
4356
|
{ id: "clock", kind: "clock", modulus: e, value: "value", radius: 2.2, at: [0, -0.2] },
|
|
4284
|
-
|
|
4357
|
+
Vt(t, `\\val{value:0} \\equiv \\val{clock.hour:0} \\pmod{${e}}`.replace("\\pmod", "\\;(\\text{mod } ").replace(`{${e}}`, `${e})`))
|
|
4285
4358
|
]
|
|
4286
4359
|
};
|
|
4287
4360
|
}
|
|
4288
|
-
const
|
|
4361
|
+
const Ot = (t) => ({ width: t.width ?? 600, height: t.height ?? 600, ...t.theme ? { theme: t.theme } : {} }), Ht = (t, e) => ({
|
|
4289
4362
|
id: "readout",
|
|
4290
4363
|
kind: "label",
|
|
4291
4364
|
screen: !0,
|
|
@@ -4294,10 +4367,10 @@ const At = (t) => ({ width: t.width ?? 600, height: t.height ?? 600, ...t.theme
|
|
|
4294
4367
|
at: [(t.width ?? 600) * 0.05, (t.height ?? 600) * 0.07],
|
|
4295
4368
|
tex: e
|
|
4296
4369
|
});
|
|
4297
|
-
function
|
|
4370
|
+
function to(t = {}) {
|
|
4298
4371
|
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]);
|
|
4299
4372
|
return {
|
|
4300
|
-
...
|
|
4373
|
+
...Ot(t),
|
|
4301
4374
|
x: [-5, 5],
|
|
4302
4375
|
y: [-5, 5],
|
|
4303
4376
|
values: { flow: e.length - 1, ...Object.fromEntries(n.map((i, s) => [`in${s}`, i])) },
|
|
@@ -4314,14 +4387,14 @@ function Xr(t = {}) {
|
|
|
4314
4387
|
inputs: n.map((i, s) => `in${s}`),
|
|
4315
4388
|
labels: { inputs: n.map((i, s) => `x_{${s + 1}}`), outputs: Array.from({ length: e[e.length - 1] }, (i, s) => `y_{${s + 1}}`) }
|
|
4316
4389
|
},
|
|
4317
|
-
|
|
4390
|
+
Ht(t, e[e.length - 1] >= 2 ? "y_1 = \\val{net.out0:2} \\quad y_2 = \\val{net.out1:2}" : "y = \\val{net.out0:2}")
|
|
4318
4391
|
]
|
|
4319
4392
|
};
|
|
4320
4393
|
}
|
|
4321
|
-
function
|
|
4394
|
+
function eo(t = {}) {
|
|
4322
4395
|
const e = t.expr ?? "(x^2 + 8 y^2) / 4";
|
|
4323
4396
|
return {
|
|
4324
|
-
...
|
|
4397
|
+
...Ot(t),
|
|
4325
4398
|
x: [-4, 4],
|
|
4326
4399
|
y: [-4, 4],
|
|
4327
4400
|
values: { steps: 0, rate: t.rate ?? 0.2, momentum: t.momentum ?? 0, sx: t.start?.[0] ?? -3.5, sy: t.start?.[1] ?? 2 },
|
|
@@ -4329,14 +4402,14 @@ function Yr(t = {}) {
|
|
|
4329
4402
|
{ id: "field", kind: "heatmap", expr: e, resolution: 40, colormap: "viridis", opacity: 0.35 },
|
|
4330
4403
|
{ id: "levels", kind: "contours", expr: e, levels: 9, colormap: "viridis" },
|
|
4331
4404
|
{ id: "gd", kind: "descent", expr: e, start: [t.start?.[0] ?? -3.5, t.start?.[1] ?? 2], rate: "rate", steps: "steps", momentum: "momentum" },
|
|
4332
|
-
|
|
4405
|
+
Ht(t, "\\text{step } \\val{gd.step:0} \\quad f = \\val{gd.loss:3}")
|
|
4333
4406
|
]
|
|
4334
4407
|
};
|
|
4335
4408
|
}
|
|
4336
|
-
function
|
|
4337
|
-
const e = t.tokens ?? ["The", "cat", "sat", "on", "the", "mat"], n =
|
|
4409
|
+
function no(t = {}) {
|
|
4410
|
+
const e = t.tokens ?? ["The", "cat", "sat", "on", "the", "mat"], n = xt(gt(t.seed ?? "attention")), i = t.scores ?? e.map((r, o) => e.map((c, l) => (o === l ? 2.2 : 0) + (l === o - 1 ? 1.4 : 0) + yt(n) * 0.8)), s = e.map((r) => `\\text{${r}}`);
|
|
4338
4411
|
return {
|
|
4339
|
-
...
|
|
4412
|
+
...Ot(t),
|
|
4340
4413
|
x: [-5, 5],
|
|
4341
4414
|
y: [-5, 5],
|
|
4342
4415
|
items: [
|
|
@@ -4344,33 +4417,33 @@ function Zr(t = {}) {
|
|
|
4344
4417
|
]
|
|
4345
4418
|
};
|
|
4346
4419
|
}
|
|
4347
|
-
function
|
|
4420
|
+
function io(t = {}) {
|
|
4348
4421
|
return {
|
|
4349
|
-
...
|
|
4422
|
+
...Ot(t),
|
|
4350
4423
|
x: [-4, 4],
|
|
4351
4424
|
y: [-4, 4],
|
|
4352
4425
|
values: { epochs: 0 },
|
|
4353
4426
|
items: [
|
|
4354
4427
|
{ 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 },
|
|
4355
|
-
|
|
4428
|
+
Ht(t, "\\text{epoch } \\val{clf.epoch:0} \\quad \\text{accuracy } \\val{clf.accuracy:2} \\quad \\text{loss } \\val{clf.loss:3}")
|
|
4356
4429
|
]
|
|
4357
4430
|
};
|
|
4358
4431
|
}
|
|
4359
|
-
function
|
|
4432
|
+
function so(t = {}) {
|
|
4360
4433
|
return {
|
|
4361
|
-
...
|
|
4434
|
+
...Ot(t),
|
|
4362
4435
|
x: [-4.5, 4.5],
|
|
4363
4436
|
y: [-4.5, 4.5],
|
|
4364
4437
|
values: { iteration: 0 },
|
|
4365
4438
|
items: [
|
|
4366
4439
|
{ 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 },
|
|
4367
|
-
|
|
4440
|
+
Ht(t, "\\text{iteration } \\val{km.iteration:0} \\quad \\text{inertia } \\val{km.inertia:1}")
|
|
4368
4441
|
]
|
|
4369
4442
|
};
|
|
4370
4443
|
}
|
|
4371
|
-
function
|
|
4444
|
+
function ro(t = {}) {
|
|
4372
4445
|
return {
|
|
4373
|
-
...
|
|
4446
|
+
...Ot(t),
|
|
4374
4447
|
x: [-4, 4],
|
|
4375
4448
|
y: [-2, 3],
|
|
4376
4449
|
items: [
|
|
@@ -4378,133 +4451,134 @@ function Qr(t = {}) {
|
|
|
4378
4451
|
{ id: "sigmoid", kind: "function", expr: "sigmoid(x)", color: "blue" },
|
|
4379
4452
|
{ id: "tanh", kind: "function", expr: "tanh(x)", color: "yellow" },
|
|
4380
4453
|
{ id: "relu", kind: "function", expr: "relu(x)", color: "red" },
|
|
4381
|
-
|
|
4454
|
+
Ht(t, "\\color{blue}{\\sigma(x)} \\quad \\color{yellow}{\\tanh x} \\quad \\color{red}{\\text{ReLU}(x)}")
|
|
4382
4455
|
]
|
|
4383
4456
|
};
|
|
4384
4457
|
}
|
|
4385
|
-
function
|
|
4386
|
-
return
|
|
4458
|
+
function oo(t) {
|
|
4459
|
+
return Et(t);
|
|
4387
4460
|
}
|
|
4388
|
-
function
|
|
4389
|
-
return
|
|
4461
|
+
function ao(t, e = {}, n = {}) {
|
|
4462
|
+
return Ws(Rt(Et(t), e), n);
|
|
4390
4463
|
}
|
|
4391
4464
|
export {
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4465
|
+
an as ACTIVATIONS,
|
|
4466
|
+
Kt as COLORMAPS,
|
|
4467
|
+
oe as CONSTANTS,
|
|
4468
|
+
ae as DISTRIBUTION_KINDS,
|
|
4469
|
+
wt as ExpressionError,
|
|
4470
|
+
Ne as FUNCTIONS,
|
|
4471
|
+
un as ITEM_KINDS,
|
|
4472
|
+
gi as MATH_FONT,
|
|
4473
|
+
It as MATH_SURFACE,
|
|
4474
|
+
bi as MATH_SYMBOL_FONT,
|
|
4475
|
+
De as MATH_THEMES,
|
|
4476
|
+
Xe as MATRIX_TEX,
|
|
4477
|
+
he as SAMPLE_GRAPH,
|
|
4478
|
+
on as SEARCH_KINDS,
|
|
4479
|
+
Fe as SYMBOLS,
|
|
4480
|
+
$i as TEX_COMMANDS,
|
|
4481
|
+
wi as TexError,
|
|
4482
|
+
as as accuracy,
|
|
4483
|
+
Ki as activate,
|
|
4484
|
+
ro as activationFigure,
|
|
4485
|
+
je as adjacency,
|
|
4486
|
+
Dr as areaFigure,
|
|
4487
|
+
We as assign,
|
|
4488
|
+
no as attentionFigure,
|
|
4489
|
+
mi as ballAt,
|
|
4490
|
+
tn as ballPath,
|
|
4491
|
+
yi as bayesAreas,
|
|
4492
|
+
Xr as bayesFigure,
|
|
4493
|
+
xe as binOf,
|
|
4494
|
+
fi as binSamples,
|
|
4495
|
+
Vr as binomialFigure,
|
|
4496
|
+
zn as blendOver,
|
|
4497
|
+
Dn as blobs,
|
|
4498
|
+
Qr as clockFigure,
|
|
4499
|
+
Hr as cltFigure,
|
|
4500
|
+
me as colorAt,
|
|
4501
|
+
J as compile,
|
|
4502
|
+
Be as compileDerivative,
|
|
4503
|
+
ns as contourLines,
|
|
4504
|
+
io as decisionBoundaryFigure,
|
|
4505
|
+
Qe as defaultBins,
|
|
4506
|
+
ht as density,
|
|
4507
|
+
jn as descentPath,
|
|
4508
|
+
Pr as determinantFigure,
|
|
4509
|
+
Z as differentiate,
|
|
4510
|
+
Ws as displayListToSvg,
|
|
4511
|
+
Ge as displayListToSvgContent,
|
|
4512
|
+
kn as distributionProblem,
|
|
4513
|
+
Us as drawDisplayList,
|
|
4514
|
+
Fr as eigenFigure,
|
|
4515
|
+
it as evaluate,
|
|
4516
|
+
Ke as expressionNames,
|
|
4517
|
+
Yt as expressionToString,
|
|
4518
|
+
ts as forward,
|
|
4519
|
+
Ur as galtonFigure,
|
|
4520
|
+
eo as gradientDescentFigure,
|
|
4521
|
+
Yr as graphSearchFigure,
|
|
4522
|
+
re as inRegion,
|
|
4523
|
+
us as inertia,
|
|
4524
|
+
Ee as integrate,
|
|
4525
|
+
fe as isDiscrete,
|
|
4526
|
+
so as kmeansFigure,
|
|
4527
|
+
ls as kmeansHistory,
|
|
4528
|
+
Rt as layoutFigure,
|
|
4456
4529
|
U as layoutTex,
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4530
|
+
xn as leastSquares,
|
|
4531
|
+
Rr as limitFigure,
|
|
4532
|
+
Ir as linearMapFigure,
|
|
4533
|
+
cs as logLoss,
|
|
4534
|
+
Er as lossSurface3D,
|
|
4535
|
+
Sr as mat2,
|
|
4536
|
+
Nr as mathExplorable,
|
|
4537
|
+
oo as mathFigure,
|
|
4538
|
+
Gs as mathFigureProps,
|
|
4539
|
+
ao as mathFigureToSvg,
|
|
4540
|
+
Ar as mathSteps,
|
|
4541
|
+
Or as mathSurface,
|
|
4542
|
+
Xs as mathTarget,
|
|
4543
|
+
Dt as meanOf,
|
|
4544
|
+
Wr as monteCarloPiFigure,
|
|
4545
|
+
Es as morphEquation,
|
|
4546
|
+
Tr as mountAllMath,
|
|
4547
|
+
gr as mountMath,
|
|
4548
|
+
to as neuralNetworkFigure,
|
|
4549
|
+
Br as normalFigure,
|
|
4550
|
+
di as nthDerivative,
|
|
4551
|
+
ct as parseExpression,
|
|
4552
|
+
Pn as parseSetExpression,
|
|
4553
|
+
ki as parseTex,
|
|
4554
|
+
Xn as planeOf,
|
|
4555
|
+
be as predict,
|
|
4556
|
+
Jr as recursionTreeFigure,
|
|
4557
|
+
Wi as regionCells,
|
|
4558
|
+
Gr as regressionFigure,
|
|
4559
|
+
jr as riemannFigure,
|
|
4560
|
+
wn as sample,
|
|
4561
|
+
ss as sampleGrid,
|
|
4562
|
+
$n as samples,
|
|
4563
|
+
Mn as scatterPoints,
|
|
4564
|
+
_t as sdOf,
|
|
4565
|
+
Vi as searchEvents,
|
|
4566
|
+
zr as secantFigure,
|
|
4567
|
+
Qi as seededNetwork,
|
|
4568
|
+
se as setNames,
|
|
4569
|
+
Zr as shortestPathFigure,
|
|
4570
|
+
Cr as spanFigure,
|
|
4571
|
+
pi as summary,
|
|
4572
|
+
hi as supportOf,
|
|
4573
|
+
ge as surface,
|
|
4574
|
+
qr as tangentFigure,
|
|
4575
|
+
_r as taylorFigure,
|
|
4502
4576
|
X as texToShapes,
|
|
4503
|
-
|
|
4504
|
-
|
|
4577
|
+
os as trainLogistic,
|
|
4578
|
+
Hi as treeLayout,
|
|
4505
4579
|
V as trimPolylines,
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4580
|
+
Et as validateMathFigure,
|
|
4581
|
+
xr as vec2,
|
|
4582
|
+
Lr as vectorSumFigure,
|
|
4583
|
+
Kr as vennFigure
|
|
4510
4584
|
};
|