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