@mathzetta/inlinemath 0.2.0 → 0.3.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 +37 -33
- package/dist/cas.external.js +2 -2
- package/dist/cas.js +2 -2
- package/dist/chunks/calculate-BGMEvf3f.js +2 -0
- package/dist/chunks/draw-q86mDDWm.js +2 -0
- package/dist/chunks/edit-CTMRUElt.js +2 -0
- package/dist/chunks/edit-D2RO7fg0.js +2 -0
- package/dist/chunks/html-1wCO6EpZ.js +2 -0
- package/dist/chunks/html-D5QiXGXD.js +2 -0
- package/dist/chunks/lite-Bo8THzyq.js +2 -0
- package/dist/fonts/README-inlinemath-greek.txt +15 -0
- package/dist/fonts/fonts.css +19 -1
- package/dist/fonts/inlinemath-greek-italic.woff2 +0 -0
- package/dist/fonts/inlinemath-greek-regular.woff2 +0 -0
- package/dist/inlinemath-cas.external.global.min.js +2 -2
- package/dist/inlinemath-cas.global.min.js +2 -2
- package/dist/inlinemath-lite-calc.global.min.js +2 -2
- package/dist/inlinemath-lite.external.global.min.js +2 -2
- package/dist/inlinemath-lite.global.min.js +2 -2
- package/dist/inlinemath.css +17 -7
- package/dist/inlinemath.external.global.min.js +2 -2
- package/dist/inlinemath.external.js +2 -2
- package/dist/inlinemath.global.min.js +2 -2
- package/dist/inlinemath.js +2 -2
- package/dist/lite-calc.js +2 -2
- package/dist/lite.external.js +2 -2
- package/dist/lite.js +2 -2
- package/dist/markdown.external.js +2 -2
- package/dist/markdown.js +2 -2
- package/fonts/README-inlinemath-greek.txt +15 -0
- package/fonts/fonts.css +19 -1
- package/fonts/inlinemath-greek-italic.woff2 +0 -0
- package/fonts/inlinemath-greek-regular.woff2 +0 -0
- package/inlinemath.css +17 -7
- package/package.json +6 -6
- package/src/cas.d.ts +1 -1
- package/src/cas.js +15 -4
- package/src/draw.js +13 -9
- package/src/edit.js +11 -4
- package/src/html.js +1 -1
- package/src/index.js +1 -1
- package/src/layout.js +89 -32
- package/src/lite.js +1 -1
- package/src/markdown.d.ts +1 -1
- package/src/markdown.js +139 -57
- package/src/mathzetta.js +2 -2
- package/src/select.js +7 -0
- package/src/types.d.ts +12 -10
- package/src/variables.js +44 -10
- package/src/view.js +69 -18
- package/dist/chunks/calculate-Cz87Lt0N.js +0 -2
- package/dist/chunks/draw-Bev17BJJ.js +0 -2
- package/dist/chunks/edit-C65xXzo8.js +0 -2
- package/dist/chunks/edit-M68aRA5o.js +0 -2
- package/dist/chunks/html-BimAqn7x.js +0 -2
- package/dist/chunks/html-CupluJSh.js +0 -2
- package/dist/chunks/lite-3Fb-OHbt.js +0 -2
package/src/view.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Once something listens for 'click', the drawing works from the keyboard too:
|
|
14
14
|
* Tab to it, arrow keys walk its parts (Down into a part, Up out of it,
|
|
15
|
-
* Left/Right between
|
|
15
|
+
* Left/Right between neighbors, Home or Escape back to the whole), Enter or
|
|
16
16
|
* Space fires the click handlers for the current part, and each part is spoken.
|
|
17
17
|
*
|
|
18
18
|
* view.editable({ toText }) (toText from 'mathzetta/text') lets the reader change it: double-click
|
|
@@ -55,10 +55,19 @@ export class View {
|
|
|
55
55
|
* point is the motion, started by the reader).
|
|
56
56
|
*/
|
|
57
57
|
set(input, { animate = false, duration = 600, easing = 'ease-in-out' } = {}) {
|
|
58
|
+
// read and drawn before anything changes: an expression that can't be drawn leaves the view as it was
|
|
59
|
+
const tree = treeOf(input, this.options);
|
|
60
|
+
const { html } = layout(tree, layoutOptions(tree, this.options));
|
|
61
|
+
// an editor still open over the old expression would put its text at the old one's path
|
|
62
|
+
if (this.editor) {
|
|
63
|
+
const open = this.editor;
|
|
64
|
+
this.editor = null;
|
|
65
|
+
open.cancelEdit?.();
|
|
66
|
+
}
|
|
58
67
|
const before = shouldAnimate(animate) && this.tree ? this.snapshot() : null;
|
|
59
68
|
const isStep = this.tree !== undefined;
|
|
60
|
-
this.tree =
|
|
61
|
-
this.element.innerHTML =
|
|
69
|
+
this.tree = tree;
|
|
70
|
+
this.element.innerHTML = html;
|
|
62
71
|
this.root = this.element.firstElementChild;
|
|
63
72
|
if (this.handlers.length) this.root.classList.add(`${this.p}-clickable`);
|
|
64
73
|
if (this.editing) this.root.classList.add(`${this.p}-editable`);
|
|
@@ -121,9 +130,9 @@ export class View {
|
|
|
121
130
|
return this;
|
|
122
131
|
}
|
|
123
132
|
|
|
124
|
-
/**
|
|
125
|
-
color(target,
|
|
126
|
-
this.elements(target).forEach((e) => { e.style.color =
|
|
133
|
+
/** Color parts; pass null to clear. */
|
|
134
|
+
color(target, color) {
|
|
135
|
+
this.elements(target).forEach((e) => { e.style.color = color || ''; });
|
|
127
136
|
return this;
|
|
128
137
|
}
|
|
129
138
|
|
|
@@ -140,15 +149,37 @@ export class View {
|
|
|
140
149
|
fn({ node, id, path: pathOf(this.tree, id), element, event });
|
|
141
150
|
};
|
|
142
151
|
this.element.addEventListener(type, listener);
|
|
143
|
-
|
|
152
|
+
const entry = [type, listener];
|
|
153
|
+
this.handlers.push(entry);
|
|
144
154
|
this.root.classList.add(`${this.p}-clickable`);
|
|
145
155
|
if (type === 'click') { this.clicks.push(fn); this.keyboard(); }
|
|
146
156
|
return () => {
|
|
147
157
|
this.element.removeEventListener(type, listener);
|
|
148
158
|
this.clicks = this.clicks.filter((f) => f !== fn);
|
|
159
|
+
this.handlers = this.handlers.filter((h) => h !== entry); // or every set() would mark it clickable again
|
|
160
|
+
if (!this.handlers.length && this.root) this.root.classList.remove(`${this.p}-clickable`);
|
|
149
161
|
};
|
|
150
162
|
}
|
|
151
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Stop listening: every handler from on(), the keys, double-click editing; any editor open is closed and
|
|
166
|
+
* the live regions this view added are removed. The drawing stays. Call it before dropping a view whose
|
|
167
|
+
* element lives on (a page that draws a new View into the same element).
|
|
168
|
+
*/
|
|
169
|
+
destroy() {
|
|
170
|
+
if (this.editor) { const open = this.editor; this.editor = null; open.cancelEdit?.(); }
|
|
171
|
+
for (const [type, listener] of this.handlers) this.element.removeEventListener(type, listener);
|
|
172
|
+
this.handlers = [];
|
|
173
|
+
this.clicks = [];
|
|
174
|
+
if (this.keyListener) this.element.removeEventListener('keydown', this.keyListener);
|
|
175
|
+
if (this.editListener) this.element.removeEventListener('dblclick', this.editListener);
|
|
176
|
+
this.keyListener = this.editListener = null;
|
|
177
|
+
this.keysOn = this.editOn = false;
|
|
178
|
+
for (const live of new Set([this.live, this.partsLive])) if (live && live.dataset?.mvMadeBy === 'view') live.remove();
|
|
179
|
+
this.live = this.partsLive = null;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
152
183
|
// ---- editing a part in place ---------------------------------------------------
|
|
153
184
|
|
|
154
185
|
/**
|
|
@@ -165,12 +196,13 @@ export class View {
|
|
|
165
196
|
this.keyboard();
|
|
166
197
|
if (!this.editOn && this.element.addEventListener) {
|
|
167
198
|
this.editOn = true;
|
|
168
|
-
this.
|
|
199
|
+
this.editListener = (event) => {
|
|
169
200
|
const element = event.target.closest?.('[data-node]');
|
|
170
201
|
if (!element || !this.root.contains(element)) return;
|
|
171
202
|
event.preventDefault();
|
|
172
203
|
this.edit(select(this.tree, Number(element.dataset.node))[0]);
|
|
173
|
-
}
|
|
204
|
+
};
|
|
205
|
+
this.element.addEventListener('dblclick', this.editListener);
|
|
174
206
|
}
|
|
175
207
|
return this;
|
|
176
208
|
}
|
|
@@ -185,8 +217,9 @@ export class View {
|
|
|
185
217
|
let label = 'Edit';
|
|
186
218
|
try { label = `Edit ${toAudioSpeech(node)}`; } catch { /* the plain name will do */ }
|
|
187
219
|
const back = () => { if (returnFocus && this.root.focus) this.root.focus(); };
|
|
188
|
-
|
|
220
|
+
this.editor = openEditor(element, this.editing.toText(node), {
|
|
189
221
|
label,
|
|
222
|
+
prefix: this.p,
|
|
190
223
|
parse: (text) => treeOf(text, this.options),
|
|
191
224
|
commit: (part, typed) => {
|
|
192
225
|
this.set(replaceAt(this.tree, path, part), { animate: true });
|
|
@@ -197,6 +230,7 @@ export class View {
|
|
|
197
230
|
},
|
|
198
231
|
cancel: back,
|
|
199
232
|
});
|
|
233
|
+
return this.editor;
|
|
200
234
|
}
|
|
201
235
|
|
|
202
236
|
// ---- the keyboard: what a click does, without a pointer -----------------------
|
|
@@ -218,7 +252,8 @@ export class View {
|
|
|
218
252
|
if (this.keysOn || !this.element.addEventListener) return;
|
|
219
253
|
this.keysOn = true;
|
|
220
254
|
this.partsLive = this.live || liveRegionFor(this.element, true, this.p);
|
|
221
|
-
this.
|
|
255
|
+
this.keyListener = (event) => this.key(event);
|
|
256
|
+
this.element.addEventListener('keydown', this.keyListener);
|
|
222
257
|
}
|
|
223
258
|
|
|
224
259
|
key(event) {
|
|
@@ -228,8 +263,8 @@ export class View {
|
|
|
228
263
|
switch (event.key) {
|
|
229
264
|
case 'ArrowDown': next = at ? this.partsOf(at)[0] : this.partsOf(this.tree)[0]; break;
|
|
230
265
|
case 'ArrowUp': next = at ? this.outerOf(at) : undefined; break;
|
|
231
|
-
case 'ArrowRight': next = at ? this.
|
|
232
|
-
case 'ArrowLeft': next = at ? this.
|
|
266
|
+
case 'ArrowRight': next = at ? this.neighbor(at, 1) : this.partsOf(this.tree)[0]; break;
|
|
267
|
+
case 'ArrowLeft': next = at ? this.neighbor(at, -1) : undefined; break;
|
|
233
268
|
case 'Home': case 'Escape': next = null; break;
|
|
234
269
|
case 'F2':
|
|
235
270
|
if (!this.editing) return;
|
|
@@ -283,7 +318,7 @@ export class View {
|
|
|
283
318
|
}
|
|
284
319
|
|
|
285
320
|
/** The part beside this one (dir 1 next, -1 previous), or undefined at the end. */
|
|
286
|
-
|
|
321
|
+
neighbor(node, dir) {
|
|
287
322
|
const siblings = this.partsOf(this.outerOf(node) || this.tree);
|
|
288
323
|
const i = siblings.indexOf(node);
|
|
289
324
|
return i < 0 ? undefined : siblings[i + dir];
|
|
@@ -303,7 +338,7 @@ export class View {
|
|
|
303
338
|
|
|
304
339
|
// ---- animation between steps --------------------------------------------
|
|
305
340
|
|
|
306
|
-
/** Where each drawn part is now, grouped by what it looks like. */
|
|
341
|
+
/** Where each drawn part is now, grouped by what it looks like; each entry knows the old node it was. */
|
|
307
342
|
snapshot() {
|
|
308
343
|
const bySignature = new Map();
|
|
309
344
|
const visit = (n) => {
|
|
@@ -311,7 +346,7 @@ export class View {
|
|
|
311
346
|
if (e) {
|
|
312
347
|
const sig = signature(n);
|
|
313
348
|
if (!bySignature.has(sig)) bySignature.set(sig, []);
|
|
314
|
-
bySignature.get(sig).push(e.getBoundingClientRect());
|
|
349
|
+
bySignature.get(sig).push({ rect: e.getBoundingClientRect(), node: n, sig });
|
|
315
350
|
}
|
|
316
351
|
if (n.type === 'op') n.args.forEach(visit);
|
|
317
352
|
};
|
|
@@ -325,11 +360,23 @@ export class View {
|
|
|
325
360
|
*/
|
|
326
361
|
morph(before, { duration, easing }) {
|
|
327
362
|
if (typeof Element === 'undefined' || !Element.prototype.animate) return;
|
|
363
|
+
// a part that moves as a whole takes its old parts with it: they are no source for another (x² + x → x² − x:
|
|
364
|
+
// the lone x comes from the old lone x, not from inside x²)
|
|
365
|
+
const consume = (oldNode) => {
|
|
366
|
+
if (oldNode.type !== 'op') return;
|
|
367
|
+
for (const child of oldNode.args) {
|
|
368
|
+
const list = before.get(signature(child));
|
|
369
|
+
const at = list ? list.findIndex((entry) => entry.node === child) : -1;
|
|
370
|
+
if (at > -1) list.splice(at, 1);
|
|
371
|
+
consume(child);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
328
374
|
const visit = (n) => {
|
|
329
375
|
const e = this.elementOf(n);
|
|
330
376
|
const old = e && before.get(signature(n));
|
|
331
377
|
if (old && old.length) {
|
|
332
|
-
const from = old.shift();
|
|
378
|
+
const { rect: from, node: was } = old.shift();
|
|
379
|
+
consume(was);
|
|
333
380
|
const to = e.getBoundingClientRect();
|
|
334
381
|
const dx = from.left - to.left;
|
|
335
382
|
const dy = from.top - to.top;
|
|
@@ -358,7 +405,11 @@ function liveRegionFor(element, announce, prefix) {
|
|
|
358
405
|
if (!announce) return null;
|
|
359
406
|
if (typeof announce === 'object' && announce.nodeType === 1) return announce;
|
|
360
407
|
if (typeof document === 'undefined' || !element.insertAdjacentElement) return null;
|
|
408
|
+
// one region per element: drawing a new view into the same element reuses the last one's
|
|
409
|
+
const next = element.nextElementSibling;
|
|
410
|
+
if (next && next.dataset?.mvMadeBy === 'view' && next.classList.contains(`${prefix}-sr-only`)) return next;
|
|
361
411
|
const live = document.createElement('span');
|
|
412
|
+
live.dataset.mvMadeBy = 'view';
|
|
362
413
|
live.className = `${prefix}-sr-only`;
|
|
363
414
|
live.setAttribute('aria-live', 'polite');
|
|
364
415
|
live.setAttribute('aria-atomic', 'true');
|
|
@@ -367,7 +418,7 @@ function liveRegionFor(element, announce, prefix) {
|
|
|
367
418
|
}
|
|
368
419
|
|
|
369
420
|
/**
|
|
370
|
-
* Should a step animate? true
|
|
421
|
+
* Should a step animate? true honors prefers-reduced-motion (no motion for a reader who asked
|
|
371
422
|
* for none), 'always' does not, false never animates.
|
|
372
423
|
*/
|
|
373
424
|
export function shouldAnimate(animate) {
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/* Inline Math 0.2.0 — MIT licence; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
-
import{h as t,i as n,j as e,k as r,m as o,o as i}from"./lite-3Fb-OHbt.js";function a(t){return Array.isArray(t)&&t.length>0&&t.every(n=>Array.isArray(n)&&n.length>0&&n.length===t[0].length&&!n.some(Array.isArray))}const s=t=>Array.isArray(t)&&t.length>0&&!t.some(Array.isArray);function u(t){const n=t,e=n.make??(t=>t),r=n.size??(()=>1),o=t=>`${t.length} by ${t[0].length}`,i=(t,r)=>e(Array.from({length:t},(e,r)=>Array.from({length:t},(t,e)=>r===e?n.one():n.zero())),r);function s(t,r){return t[0].length!==r.length&&n.fail(`a ${o(t)} matrix times a ${o(r)} one`),e(t.map(t=>r[0].map((e,o)=>t.reduce((t,e,i)=>n.add(t,n.mul(e,r[i][o])),n.zero()))),t)}function u(t){const e=t.map(t=>t.slice()),o=e.length,i=e[0].length;let a=n.one(),s=0;for(let t=0;t<i&&s<o;t++){let i=-1;for(let a=s;a<o;a++)n.isZero(e[a][t])||(i<0||r(e[a][t])>r(e[i][t]))&&(i=a);if(i<0){a=n.zero();continue}i!==s&&([e[i],e[s]]=[e[s],e[i]],a=n.sub(n.zero(),a));const u=e[s][t];a=n.mul(a,u),e[s]=e[s].map(t=>n.div(t,u));for(let r=0;r<o;r++){if(r===s||n.isZero(e[r][t]))continue;const o=e[r][t];e[r]=e[r].map((t,r)=>n.sub(t,n.mul(o,e[s][r])))}s++}return s<o&&(a=n.zero()),{M:e,det:a,rank:s}}function c(t){const r=t.length;r!==t[0].length&&n.fail(`a ${o(t)} matrix has no inverse`);const a=i(r),{M:s,rank:c}=u(t.map((t,n)=>[...t,...a[n]]));return(c<r||s.some((t,e)=>n.isZero(t[e])))&&n.fail("the matrix has no inverse (its determinant is 0)"),e(s.map(t=>t.slice(r)),t)}return{identity:i,transpose:t=>e(t[0].map((n,e)=>t.map(t=>t[e])),t),times:s,det:function(t){return t.length!==t[0].length&&n.fail(`a ${o(t)} matrix has no determinant`),u(t).det},inverse:c,power:function(t,e){t.length!==t[0].length&&n.fail(`a ${o(t)} matrix has no powers`);let r=e<0n?c(t):t,a=e<0n?-e:e,u=i(t.length,t);for(;a>0n;)1n&a&&(u=s(u,r)),r=s(r,r),a>>=1n;return u},trace:t=>(t.length!==t[0].length&&n.fail(`a ${o(t)} matrix has no trace`),t.reduce((t,e,r)=>n.add(t,e[r]),n.zero())),dot:(t,e)=>(t.length!==e.length&&n.fail("vectors of different lengths"),t.reduce((t,r,o)=>n.add(t,n.mul(r,e[o])),n.zero())),cross:(t,e)=>(3===t.length&&3===e.length||n.fail("the cross product is for vectors of 3 numbers"),[n.sub(n.mul(t[1],e[2]),n.mul(t[2],e[1])),n.sub(n.mul(t[2],e[0]),n.mul(t[0],e[2])),n.sub(n.mul(t[0],e[1]),n.mul(t[1],e[0]))]),solve:function(t,n){return a(n)?s(c(t),n):s(c(t),n.map(t=>[t])).map(t=>t[0])},rank:t=>u(t).rank,rref:t=>e(u(t).M,t),timesVector:(t,n)=>s(t,n.map(t=>[t])).map(t=>t[0]),vectorTimes:(t,n)=>s([t],n)[0]}}const c=u({add:(t,n)=>t+n,sub:(t,n)=>t-n,mul:(t,n)=>t*n,div:(t,n)=>t/n,isZero:t=>Math.abs(t)<1e-12,zero:()=>0,one:()=>1,size:Math.abs,fail:t=>{throw new Error(t)}}),l=t=>a(t)&&(t.length>1||t[0].length>1),f=t=>s(t)&&!l(t),h=t=>{const n=(e,r)=>{if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)throw new Error("Lists of different lengths");return e.map((t,e)=>n(t,r[e]))}return Array.isArray(e)?e.map(t=>n(t,r)):Array.isArray(r)?r.map(t=>n(e,t)):t(e,r)};return n},m=(t,n)=>l(t)&&l(n)?c.times(t,n):l(t)&&f(n)?c.timesVector(t,n):f(t)&&l(n)?c.vectorTimes(t,n):h((t,n)=>t*n)(t,n),g=t=>n=>t(n.length>1&&n.every(f)?n:n[0]),p={det:g(c.det),inv:g(c.inverse),inverse:g(c.inverse),transpose:g(c.transpose),trace:g(c.trace),tr:g(c.trace),rank:g(c.rank),rref:g(c.rref),identity:([t])=>c.identity(t),dot:([t,n])=>c.dot(t,n),cross:([t,n])=>c.cross(t,n),linsolve:([t,n])=>c.solve(t,n)},d=(t,n)=>t.args.map(t=>"op"===t.type&&"[]"===t.op?t.args.map(t=>A(t,n)):[A(t,n)]),b={pi:Math.PI,"π":Math.PI,e:Math.E,tau:2*Math.PI,"τ":2*Math.PI,"∞":1/0,"-∞":-1/0,true:!0,false:!1},w=(t,n)=>n?w(n,t%n):Math.abs(t),M={neg:t=>-t,pm:t=>[t,-t],"!":t=>{if(!Number.isInteger(t)||t<0)return NaN;if(t>170)return 1/0;let n=1;for(let e=2;e<=t;e++)n*=e;return n},"\\not":t=>!t,sqrt:Math.sqrt,abs:Math.abs,floor:Math.floor,ceil:Math.ceil,det:t=>c.det(t),ln:Math.log,loglog:t=>Math.log(Math.log(t)),logloglog:t=>Math.log(Math.log(Math.log(t))),expm1:Math.expm1,sin:Math.sin,cos:Math.cos,tan:Math.tan,csc:t=>1/Math.sin(t),sec:t=>1/Math.cos(t),cot:t=>1/Math.tan(t),sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan,arcsinh:Math.asinh,arccosh:Math.acosh,arctanh:Math.atanh},y={"+":(t,n)=>Array.isArray(t)||Array.isArray(n)?h((t,n)=>t+n)(t,n):t+n,"-":(t,n)=>Array.isArray(t)||Array.isArray(n)?h((t,n)=>t-n)(t,n):t-n,"*":m,"/":(t,n)=>l(n)?m(t,c.inverse(n)):Array.isArray(t)||Array.isArray(n)?h((t,n)=>t/n)(t,n):t/n,"^":(t,n)=>{if(!l(t))return Array.isArray(t)?h((t,n)=>t**n)(t,n):t**n;if(!Number.isInteger(n))throw new Error("A matrix to a power that is not a whole number");return c.power(t,BigInt(n))},mod:(t,n)=>t%n,log:(t,n)=>Math.log(n)/Math.log(t),root:(t,n)=>n**(1/t),atan2:Math.atan2,round:(t,n)=>Math.round(t*10**n)/10**n,"±":(t,n)=>[t+n,t-n],fixed:(t,n)=>Number(t).toFixed(n),perm:(t,n)=>{if(!Number.isInteger(t)||!Number.isInteger(n)||n<0||n>t)return NaN;let e=1;for(let r=t-n+1;r<=t&&e!==1/0;r++)e*=r;return e},comb:(t,n)=>{if(!Number.isInteger(t)||!Number.isInteger(n)||n<0||n>t)return NaN;n=Math.min(n,t-n);let e=1;for(let r=1;r<=n&&e!==1/0;r++)e=e*(t-n+r)/r;return Math.round(e)},"=":(t,n)=>t==n,"===":(t,n)=>t===n,"≠":(t,n)=>t!=n,"≠=":(t,n)=>t!==n,"≈":(t,n)=>Math.abs(t-n)<1e-9,"≡":(t,n)=>t===n,"∪":(t,n)=>[...new Set([...[].concat(t),...[].concat(n)])],"∩":(t,n)=>[].concat(t).filter(t=>[].concat(n).includes(t)),"<":(t,n)=>t<n,">":(t,n)=>t>n,"≤":(t,n)=>t<=n,"≥":(t,n)=>t>=n,"&":(t,n)=>t&&n,"|":(t,n)=>t||n,"\\xor":(t,n)=>Boolean(t)!==Boolean(n),"\\nor":(t,n)=>!(t||n),"\\nand":(t,n)=>!(t&&n)},v={max:t=>Math.max(...t),min:t=>Math.min(...t),sum:t=>t.reduce((t,n)=>t+n,0),prod:t=>t.reduce((t,n)=>t*n,1),mean:t=>t.reduce((t,n)=>t+n,0)/t.length,gcd:t=>t.reduce(w),"()":t=>t,"[]":t=>t,"{}":t=>t};const x=5e6;let N=0,I=0;function A(t,e){if(++N>x)throw new Error("Too much to work out");switch(t.type){case"number":return Number(t.value);case"string":return t.value.slice(1,-1);case"symbol":if(Object.prototype.hasOwnProperty.call(e,t.value))return e[t.value];if(Object.prototype.hasOwnProperty.call(b,t.value))return b[t.value];throw new Error(`No value for '${t.value}'`)}const r=n(t);if(r)return A(r,e);const{op:o,args:i}=t;if("?:"===o)return A(i[0],e)?A(i[1],e):A(i[2],e);if("∈"===o||"∉"===o)return function(t,n){const[e,r]=t.args,o=A(e,n);let i;if("symbol"===r.type&&$[r.value])return i=$[r.value](o),"∈"===t.op?i:!i;if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[t,e]=r.args.map(t=>A(t,n)),a="["===r.op[0]?o>=t:o>t,s="]"===r.op[1]?o<=e:o<e;i=a&&s}else{const t=A(r,n);i=Array.isArray(t)&&t.includes(o)}return"∈"===t.op?i:!i}(t,e);if("random"===o)return Math.random();if(("\\sumidx"===o||"\\prodidx"===o)&&3===i.length&&"op"===i[1].type&&"="===i[1].op&&"symbol"===i[1].args[0].type){const[t,n,r]=[i[0],i[1].args[1],i[2]],a=i[1].args[0].value,s=A(n,e),u=A(r,e);if(!Number.isFinite(s)||!Number.isFinite(u)||u-s>1e6)throw new Error(`Can't evaluate '${o}' over that range`);let c="\\sumidx"===o?0:1;for(let n=s;n<=u;n++){const r=A(t,{...e,[a]:n});c="\\sumidx"===o?c+r:c*r}return c}if("pmod"===o){const[t,n]=i,r=A(n,e);if("op"===t.type&&["≡","="].includes(t.op)){const[n,o]=t.args.map(t=>A(t,e));return(n-o)%r===0}return A(t,e)%r}if("pmatrix"===o||"bmatrix"===o)return d(t,e);if("vmatrix"===o)return c.det(d(t,e));if("^"===o&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(e,"T")){const t=A(i[0],e);if(l(t))return c.transpose(t)}const a=i.map(t=>A(t,e));if(o.startsWith("\\:")&&Object.prototype.hasOwnProperty.call(p,o.slice(2)))return p[o.slice(2)](a);if(M[o]&&1===a.length)return M[o](a[0]);if(y[o]&&2===a.length)return y[o](a[0],a[1]);if(v[o])return v[o](a);throw new Error(`Can't evaluate '${o}'`)}const $={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":t=>Number.isInteger(t)&&t>0,"ℚ":Number.isFinite,"ℂ":t=>"number"==typeof t&&!Number.isNaN(t)};for(const t of[b,M,y,v,$,p])Object.setPrototypeOf(t,null);class B extends Error{}class F extends Error{}const O={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6};let k=0,j=0;const P=t=>t<0n?-t:t,S=t=>0n===t?0:P(t).toString(2).length;function z(t,n){for(t=P(t),n=P(n);n;)[t,n]=[n,t%n];return t}function E(t,n=1n){if(0n===n)throw new B("division by zero");n<0n&&(t=-t,n=-n);const e=z(t,n)||1n;return{n:t/e,d:n/e}}const T=E(0n),W=E(1n),Z=(t,n)=>E(t.n*n.d+n.n*t.d,t.d*n.d),q=(t,n)=>E(t.n*n.n,t.d*n.d),D=(t,n)=>E(t.n*n.d,t.d*n.n),_=t=>({n:-t.n,d:t.d}),C=(t,n)=>{const e=t.n*n.d-n.n*t.d;return e<0n?-1:e>0n?1:0},V=t=>{const n=t.n/t.d;return t.n<0n&&n*t.d!==t.n?n-1n:n};function L(t){const n=S(t.n),e=S(t.d);if(n<1e3&&e<1e3)return Number(t.n)/Number(t.d);const r=BigInt(Math.max(n,e)-1e3),o=t.d>>r;return 0n===o?t.n<0n?-1/0:1/0:Number(t.n>>r)/Number(o)}function G(t){let n=String(t).trim(),e=1n;n.startsWith("-")&&(e=-1n,n=n.slice(1));const r=n.endsWith("..");r&&(n=n.slice(0,-2));let o=0;const i=n.search(/e/i);i>=0&&(o=Number(n.slice(i+1)),n=n.slice(0,i));const[a="",s=""]=n.split(".");if(!(/^\d*$/.test(a)&&/^\d*$/.test(s)&&a+s))throw new F(`'${t}' is not a number`);let u;if(r&&s){let t=1;for(let n=1;2*n<=s.length;n++)if(s.slice(-n)===s.slice(-2*n,-n)){t=n;break}const n=s.slice(-t);let e=s;for(;e.endsWith(n);)e=e.slice(0,-t);const r=BigInt(e||"0"),o=BigInt(e+n);u=Z(E(BigInt(a||"0")),E(o-r,(10n**BigInt(t)-1n)*10n**BigInt(e.length)))}else u=E(BigInt(a+s||"0"),10n**BigInt(s.length));return o&&(u=o>0?q(u,E(10n**BigInt(o))):D(u,E(10n**BigInt(-o)))),e<0n?_(u):u}function J(t,n=0,e=0,r=null){return 0n===t.n?{kind:"x",c:T,pi:0,e:0,root:null}:{kind:"x",c:t,pi:n,e:e,root:r}}const R=(t,n=1n)=>J(E(BigInt(t),BigInt(n))),X=J(W,1),H=J(W,0,1),K=t=>null!==t&&"object"==typeof t&&"x"===t.kind,Q=t=>K(t)&&!t.pi&&!t.e&&!t.root,U=t=>K(t)?0n===t.c.n:0===t,Y=t=>Q(t)&&1n===t.c.d?t.c.n:null,tt=(t,n)=>Object.assign(t,{group:n}),nt=t=>({kind:"s",text:t});function et(t,n){return t&&n?t.n===n.n&&t.r===n.r:t===n}const rt=(t,n)=>0===C(t.c,n.c)&&t.pi===n.pi&&t.e===n.e&&et(t.root,n.root);function ot(t){if("number"==typeof t)return t;if(K(t)){let n=L(t.c);return t.pi&&(n*=Math.PI**t.pi),t.e&&(n*=Math.E**t.e),t.root&&(n*=L(E(t.root.r))**(1/t.root.n)),n}if("boolean"==typeof t)return t?1:0;throw new F("not a number")}function it(t,...n){if(Number.isNaN(t))throw new B("undefined");if(!Number.isFinite(t)&&n.every(Number.isFinite))throw new F("too large to calculate");return t}const at=t=>"boolean"==typeof t?t:K(t)?0n!==t.c.n:"number"==typeof t?0!==t:Boolean(t);function st(t){if("bigint"==typeof t)return J(E(t));if("number"==typeof t)return Number.isFinite(t)?J(Number.isInteger(t)&&Math.abs(t)<=Number.MAX_SAFE_INTEGER?E(BigInt(t)):G(String(t))):t;if("boolean"==typeof t)return t;if("string"==typeof t)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(t.trim())?J(G(t)):Yt(e(t),{});if(Array.isArray(t))return!t.group&&a(t)?tt(t.map(t=>tt(t.map(st),"[]")),"[]"):tt(t.map(st),t.group||"()");if(K(t)||"function"==typeof t)return t;throw new F(`can't use ${typeof t} as a value`)}function ut(t){return Array.isArray(t)?t.map(ut):t&&"s"===t.kind?t.text:"boolean"==typeof t?t:ot(t)}function ct(t,n){if(t<2n)return t;const e=BigInt(n);let r=1n<<BigInt(Math.ceil(S(t)/n));for(;;){const n=((e-1n)*r+t/r**(e-1n))/e;if(n>=r)return r;r=n}}function lt(t,n,e,r=0,o=0){if(0n===e)return J(T);const{coef:i,root:a}=function(t,n){let e=1n,r=n;const o=BigInt(t),i=r<10n**24n?1000000n:10000n;for(let t=2n;t<=i&&t*t<=r;t+=2n===t?1n:2n){const n=t**o;for(;r%n===0n;)r/=n,e*=t}const a=ct(r,t);if(a**o===r&&(e*=a,r=1n),1n===r)return{coef:e,root:null};for(let n=t;n>=2;n--){if(t%n!==0)continue;const o=ct(r,n);if(o**BigInt(n)===r)return{coef:e,root:{n:t/n,r:o}}}return{coef:e,root:{n:t,r:r}}}(n,e);return a&&1===a.n?J(q(t,E(i*a.r)),r,o):J(q(t,E(i)),r,o,a)}function ft(t,n){const e=q(t.c,n.c);if(S(e.n)+S(e.d)>O.bits)return null;const r=t.pi+n.pi,o=t.e+n.e;if(!t.root||!n.root)return J(e,r,o,t.root||n.root);const i=Wt(t.root.n,n.root.n);if(i>O.rootIndex)return null;const a=t.root.r**BigInt(i/t.root.n)*n.root.r**BigInt(i/n.root.n);return S(a)>4e3?null:lt(e,i,a,r,o)}function ht(t){if(0n===t.c.n)throw new B("division by zero");const n=J(D(W,t.c),-t.pi,-t.e);if(!t.root)return n;const{n:e,r:r}=t.root;return ft(n,lt(E(1n,r),e,r**BigInt(e-1)))}function mt(t,n){if(0n===n){if(0n===t.c.n)throw new B("0^0 is undefined");return J(W)}if(n<0n){const e=ht(t);return e&&mt(e,-n)}if((S(t.c.n)+S(t.c.d)+(t.root?S(t.root.r):0))*Number(n)>O.bits||n>100000n)return null;const e=E(t.c.n**n,t.c.d**n),r=Number(n);if(!t.root)return J(e,t.pi*r,t.e*r);const{n:o,r:i}=t.root,a=i**(n/BigInt(o));return lt(q(e,E(a)),o,i**(n%BigInt(o))||1n,t.pi*r,t.e*r)}function gt(t,n,e){if(!Q(t)||e>1000n)return null;const r=mt(t,n);if(!r)return null;let{n:o,d:i}=r.c,a=!1;if(o<0n){if(e%2n==0n)throw new B("not a real number");a=!0,o=-o}const s=function(t,n){const e=t.n*t.d**BigInt(n-1);return S(e)>4e3?null:lt(E(1n,t.d),n,e)}({n:o,d:i},Number(e));return s?a?J(_(s.c),s.pi,s.e,s.root):s:null}function pt(t){return n=>Array.isArray(n)?tt(n.map(n=>pt(t)(n)),n.group):t(n)}function dt(t){const n=(e,r)=>{const o=Array.isArray(e),i=Array.isArray(r);if(o&&i){if(e.length!==r.length)throw new B("lists of different lengths");return tt(e.map((t,e)=>n(t,r[e])),e.group)}return o?tt(e.map(t=>n(t,r)),e.group):i?tt(r.map(t=>n(e,t)),r.group):t(e,r)};return n}const bt=dt((t,n)=>K(t)&&K(n)&&function(t,n){if(0n===t.c.n)return n;if(0n===n.c.n)return t;if(t.pi!==n.pi||t.e!==n.e||!et(t.root,n.root))return null;const e=Z(t.c,n.c);return S(e.n)+S(e.d)>O.bits?null:J(e,t.pi,t.e,t.root)}(t,n)||it(ot(t)+ot(n),ot(t),ot(n))),wt=pt(t=>K(t)?J(_(t.c),t.pi,t.e,t.root):-ot(t)),Mt=(t,n)=>bt(t,wt(n)),yt=dt((t,n)=>K(t)&&K(n)&&ft(t,n)||it(ot(t)*ot(n),ot(t),ot(n))),vt=dt((t,n)=>{if(U(n))throw new B("division by zero");if(K(t)&&K(n)){const e=ht(n),r=e&&ft(t,e);if(r)return r}return it(ot(t)/ot(n),ot(t),ot(n))}),xt=dt((t,n)=>{if(K(t)&&Q(n)){const{n:e,d:r}=n.c,o=1n===r?mt(t,e):gt(t,e,r);if(o)return o}const e=ot(t),r=ot(n);if(0===e&&0===r)throw new B("0^0 is undefined");if(0===e&&r<0)throw new B("division by zero");if(e<0&&!Number.isInteger(r))throw new B("not a real number");return it(e**r,e,r)});function Nt(t,n){if(Q(t)&&Q(n))return C(t.c,n.c);if(K(t)&&K(n)&&rt(t,n))return 0;const e=ot(t),r=ot(n);return e===r||Number.isFinite(e)&&Number.isFinite(r)&&Math.abs(e-r)<=1e-12*Math.max(1,Math.abs(e),Math.abs(r))?0:e<r?-1:1}function It(t,n){return Array.isArray(t)||Array.isArray(n)?Array.isArray(t)&&Array.isArray(n)&&t.length===n.length&&t.every((t,e)=>It(t,n[e])):t&&"s"===t.kind?Boolean(n&&"s"===n.kind&&t.text===n.text):"boolean"==typeof t||"boolean"==typeof n?t===n:0===Nt(t,n)}const At={0:()=>R(0),2:()=>R(1,2),3:()=>lt(E(1n,2n),2,2n),4:()=>lt(E(1n,2n),2,3n),6:()=>R(1)};function $t(t){t=(t%24+24)%24;const[n,e]=t<=6?[t,1]:t<=12?[12-t,1]:t<=18?[t-12,-1]:[24-t,-1],r=At[n];return r?e<0?wt(r()):r():null}const Bt=t=>$t(t+6),Ft=(t,n)=>Math.abs(t)<1e-15&&Math.abs(n)>1e-6?0:t;function Ot(t,n){const e=function(t){if(U(t))return 0;if(!K(t)||1!==t.pi||t.e||t.root)return null;const n=q(t.c,E(12n));return 1n!==n.d?null:Number((n.n%24n+24n)%24n)}(n);if(null!==e){const n=$t(e),r=Bt(e);if(n&&r)switch(t){case"sin":return n;case"cos":return r;case"tan":return vt(n,r);case"cot":return vt(r,n);case"sec":return vt(R(1),r);case"csc":return vt(R(1),n)}}const r=ot(n),o=Ft(Math.sin(r),r),i=Ft(Math.cos(r),r),a={sin:o,cos:i,tan:o/i,cot:i/o,sec:1/i,csc:1/o}[t];if(!Number.isFinite(a)&&Number.isFinite(r))throw new B("undefined");return it(a)}function kt(t,n){const e={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[t],r=n=>"arcsin"===t?$t(n):"arccos"===t?Bt(n):Bt(n)&&!U(Bt(n))?vt($t(n),Bt(n)):null;if(K(n))for(let t=e[0];t<=e[1];t++){const e=r(t);if(e&&K(e)&&rt(e,n))return J(E(BigInt(t),12n),1)}const o=ot(n);if("arctan"!==t&&Math.abs(o)>1)throw new B("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[t](o)}function jt(t){if(K(t)){if(0n===t.c.n)throw new B("ln 0 is undefined");if(t.c.n<0n)throw new B("not a real number");if(1n===t.c.n&&1n===t.c.d&&!t.pi&&!t.root)return R(t.e)}const n=ot(t);if(n<=0)throw new B(0===n?"ln 0 is undefined":"not a real number");return Math.log(n)}function Pt(t){if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*Pt(1-t));const n=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];let e=n[0];const r=(t-=1)+7+.5;for(let r=1;r<9;r++)e+=n[r]/(t+r);return Math.sqrt(2*Math.PI)*r**(t+.5)*Math.exp(-r)*e}function St(t,n){const e=Y(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null===e)throw new B(`${n} needs whole numbers`);return e}const zt=pt(t=>Q(t)?J(E(V(t.c))):st(Math.floor(ot(t)))),Et=pt(t=>Q(t)?J(E(-V(_(t.c)))):st(Math.ceil(ot(t))));function Tt(t,n){const e=Number(St(n,"round"));if(Q(t)){const n=E(10n**BigInt(Math.abs(e))),r=e>=0?q(t.c,n):D(t.c,n),o=V(Z(q(E(2n),E(P(r.n),r.d)),W))/2n,i=E(r.n<0n?-o:o);return J(e>=0?D(i,n):q(i,n))}const r=10**e;return Math.sign(ot(t))*Math.round(Math.abs(ot(t))*r)/r}const Wt=(t,n)=>t/Zt(t,n)*n,Zt=(t,n)=>n?Zt(n,t%n):t,qt={pi:()=>X,"π":()=>X,tau:()=>J(E(2n),1),"τ":()=>J(E(2n),1),e:()=>H,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1},Dt={abs:t=>K(t)?J(E(P(t.c.n),t.c.d),t.pi,t.e,t.root):Math.abs(ot(t)),floor:zt,ceil:Et,sqrt:t=>xt(t,R(1,2)),ln:pt(jt),loglog:pt(t=>jt(jt(t))),logloglog:pt(t=>jt(jt(jt(t)))),expm1:pt(t=>U(t)?R(0):Math.expm1(ot(t))),sinh:pt(t=>U(t)?R(0):Math.sinh(ot(t))),cosh:pt(t=>U(t)?R(1):Math.cosh(ot(t))),tanh:pt(t=>U(t)?R(0):Math.tanh(ot(t))),arcsinh:pt(t=>U(t)?R(0):Math.asinh(ot(t))),arccosh:pt(t=>{const n=ot(t);if(n<1)throw new B("not a real number");return 1===n?R(0):Math.acosh(n)}),arctanh:pt(t=>{const n=ot(t);if(Math.abs(n)>=1)throw new B("undefined");return U(t)?R(0):Math.atanh(n)}),"!":pt(function(t){const n=Y(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null!==n){if(n<0n)throw new B("factorial of a negative number");if(n>BigInt(O.factorial))throw new F("too large to calculate");let t=1n;for(let e=2n;e<=n;e++)t*=e;return J(E(t))}const e=ot(t);if(e<0&&Number.isInteger(e))throw new B("factorial of a negative number");return it(Pt(e+1),e)}),neg:wt,pm:t=>tt([t,wt(t)],"pm"),"\\not":t=>!at(t),det:t=>Xt.det(t)};for(const t of["sin","cos","tan","csc","sec","cot"])Dt[t]=pt(n=>Ot(t,n));for(const t of["arcsin","arccos","arctan"])Dt[t]=pt(n=>kt(t,n));const _t=new Set(["pmatrix","bmatrix"]),Ct=t=>a(t)&&(_t.has(t.group)||"[]"===t.group&&t.every(t=>"[]"===t.group)&&(t.length>1||t[0].length>1)),Vt=t=>s(t)&&!Ct(t)&&"pm"!==t.group,Lt=u({add:bt,sub:Mt,mul:yt,div:vt,isZero:t=>K(t)?0n===t.c.n:Math.abs(ot(t))<1e-12,zero:()=>R(0),one:()=>R(1),size:t=>Math.abs(ot(t)),fail:t=>{throw new B(t)},make:(t,n)=>tt(t.map(t=>tt(t,"[]")),n&&n.group?n.group:"bmatrix")}),Gt=(t,n)=>tt(t,n&&n.group?n.group:"[]"),Jt=(t,n)=>(...e)=>{const r=e.length>1&&e.every(Vt)?tt(e.map(t=>tt(t,"[]")),"[]"):e[0];if(e.length>1&&r===e[0])throw new F(`${t} of more than one thing`);if(!Ct(r))throw new F(`${t} of something that isn't a matrix`);return n(r)};function Rt(t,n){return Ct(t)&&Ct(n)?Lt.times(t,n):Ct(t)&&Vt(n)?Gt(Lt.timesVector(t,n),n):Vt(t)&&Ct(n)?Gt(Lt.vectorTimes(t,n),t):yt(t,n)}const Xt={det:Jt("det",Lt.det),inv:Jt("inv",Lt.inverse),inverse:Jt("inverse",Lt.inverse),transpose:Jt("transpose",Lt.transpose),trace:Jt("trace",Lt.trace),tr:Jt("tr",Lt.trace),rank:Jt("rank",t=>R(Lt.rank(t))),rref:Jt("rref",Lt.rref),identity:t=>{const n=Y(t);if(null===n||n<1n||n>100n)throw new F("identity(n) needs a whole number n");return Lt.identity(Number(n))},dot:(t,n)=>{if(!Vt(t)||!Vt(n))throw new F("dot of something that isn't a vector");return Lt.dot(t,n)},cross:(t,n)=>{if(!Vt(t)||!Vt(n))throw new F("cross of something that isn't a vector");return Gt(Lt.cross(t,n),t)},linsolve:(t,n)=>{if(!Ct(t)||!Ct(n)&&!Vt(n))throw new F("linsolve(A, b) needs a matrix and a vector");return Ct(n)?Lt.solve(t,n):Gt(Lt.solve(t,n),n)}};function Ht(t,n){const e=t.args.map(t=>tt("op"===t.type&&"[]"===t.op?t.args.map(n):[n(t)],"[]"));if(e.some(t=>t.length!==e[0].length))throw new B("rows of different lengths");return tt(e,"vmatrix"===t.op?"bmatrix":t.op)}const Kt={"+":bt,"-":Mt,"*":Rt,"/":(t,n)=>Ct(n)?Rt(t,Lt.inverse(n)):vt(t,n),"^":function(t,n){if(!Ct(t))return xt(t,n);const e=Y(n);if(null===e)throw new F("a matrix to a power that is not a whole number");return Lt.power(t,e)},"±":(t,n)=>tt([bt(t,n),Mt(t,n)],"pm"),mod:dt(function(t,n){if(U(n))throw new B("division by zero");if(Q(t)&&Q(n))return J(Z(t.c,_(q(n.c,E(V(D(t.c,n.c)))))));const e=ot(t),r=ot(n);return it((e%r+r)%r)}),log:dt(function(t,n){if(K(t)&&rt(t,H))return jt(n);const e=ot(t),r=ot(n);if(e<=0||1===e)throw new B("not a valid base");if(r<=0)throw new B(0===r?"log 0 is undefined":"not a real number");const o=Math.log(r)/Math.log(e);if(Q(t)&&Q(n))for(let e=1n;e<=12n;e++){const r=Math.round(o*Number(e));if(Math.abs(o*Number(e)-r)>1e-9)continue;const i=mt(t,BigInt(r)),a=mt(n,e);if(i&&a&&rt(i,a))return J(E(BigInt(r),e))}return o}),root:dt((t,n)=>xt(n,vt(R(1),t))),atan2:(t,n)=>Math.atan2(ot(t),ot(n)),round:Tt,fixed:function(t,n){const e=Number(St(n,"fixed"));if(e<0)throw new B("fixed needs 0 or more decimal places");const r=Tt(t,n);if(Q(r)){const t=r.c.n*10n**BigInt(e)/r.c.d,n=(t<0n?-t:t).toString().padStart(e+1,"0");return nt(`${t<0n?"-":""}${n.slice(0,n.length-e)}${e?"."+n.slice(-e):""}`)}return nt(Number(ot(r)).toFixed(e))},perm:function(t,n){const e=St(t,"permutations"),r=St(n,"permutations");if(r<0n||r>e)throw new B("undefined");if(r>BigInt(O.terms))throw new F("too large to calculate");let o=1n;for(let t=e-r+1n;t<=e;t++)o*=t;return J(E(o))},comb:function(t,n){const e=St(t,"combinations");let r=St(n,"combinations");if(r<0n||r>e)throw new B("undefined");if(e-r<r&&(r=e-r),r>BigInt(O.terms))throw new F("too large to calculate");let o=1n;for(let t=1n;t<=r;t++)o=o*(e-r+t)/t;return J(E(o))},"=":(t,n)=>It(t,n),"===":(t,n)=>It(t,n),"≠":(t,n)=>!It(t,n),"≠=":(t,n)=>!It(t,n),"≈":(t,n)=>Math.abs(ot(t)-ot(n))<=1e-9*Math.max(1,Math.abs(ot(t)),Math.abs(ot(n))),"<":(t,n)=>Nt(t,n)<0,">":(t,n)=>Nt(t,n)>0,"≤":(t,n)=>Nt(t,n)<=0,"≥":(t,n)=>Nt(t,n)>=0,"&":(t,n)=>at(t)&&at(n),"|":(t,n)=>at(t)||at(n),"\\xor":(t,n)=>at(t)!==at(n),"\\nor":(t,n)=>!(at(t)||at(n)),"\\nand":(t,n)=>!(at(t)&&at(n))},Qt={sum:t=>t.reduce((t,n)=>bt(t,n),R(0)),prod:t=>t.reduce((t,n)=>yt(t,n),R(1)),max:t=>t.reduce((t,n)=>Nt(n,t)>0?n:t),min:t=>t.reduce((t,n)=>Nt(n,t)<0?n:t),mean:t=>vt(Qt.sum(t),R(t.length)),gcd:t=>J(E(t.map(t=>St(t,"gcd")).reduce(z)))},Ut=["∈","∉","∪","∩","pmod","random","(]","[)"];function Yt(e,r){if(++k>O.steps)throw new F("too much to work out");switch(e.type){case"number":return J(G(e.value));case"string":return nt(e.value.slice(1,-1));case"symbol":return tn(e.value,r)}const i=n(e);if(i)return Yt(i,r);const{op:a,args:s}=e,u=t=>Yt(t,r);if("?:"===a)return at(u(s[0]))?u(s[1]):u(s[2]);if("_"===a){if(s.every(t=>"op"!==t.type))return tn(`${s[0].value}_${s[1].value}`,r);throw new F("subscript")}if("der"===a)return function(t,n){const[e,r]=t.args,o=en(r);if(!o||!Object.prototype.hasOwnProperty.call(n,o))throw new F(`a derivative needs a value for ${o||"its variable"}`);const i=ot(n[o]),a=nn(e,o,n);if(!Number.isFinite(a(i)))throw new B("undefined");const s=1e-6*Math.max(1,Math.abs(i)),u=(a(i+s)-a(i))/s,c=(a(i)-a(i-s))/s;if(!Number.isFinite(u)||!Number.isFinite(c)||Math.abs(u-c)>.001*Math.max(1,Math.abs(u)))throw new B("not differentiable here");let l=.1*Math.max(1,Math.abs(i));const f=1.4,h=[[(a(i+l)-a(i-l))/(2*l)]];let m=h[0][0],g=1/0;for(let t=1;t<12;t++){l/=f,h[t]=[(a(i+l)-a(i-l))/(2*l)];let n=f*f;for(let e=1;e<=t;e++){h[t][e]=(h[t][e-1]*n-h[t-1][e-1])/(n-1),n*=f*f;const r=Math.max(Math.abs(h[t][e]-h[t][e-1]),Math.abs(h[t][e]-h[t-1][e-1]));r<=g&&(g=r,m=h[t][e])}if(Math.abs(h[t][t]-h[t-1][t-1])>=2*g)break}if(!Number.isFinite(m))throw new B("not differentiable here");return sn(m,g)}(e,r);if("int"===a)return function(t,n){const[e,r,i,a]=t,s=t=>t&&"symbol"===t.type&&/^[a-zA-Zʹ-Ͽ]$/.test(t.value);let u,c,l;if(4===t.length)[u,c,l]=[en(r),i,a];else{if(3!==t.length||s(r))throw new F("an integral needs limits to be calculated");[u,c,l]=[o(e)||"x",r,i]}let f=ot(Yt(c,n)),h=ot(Yt(l,n));if(f===h)return R(0);let m=1;f>h&&([f,h]=[h,f],m=-1);const g=nn(e,u,n),{value:p,error:d}=rn(g,f,h);return sn(m*p,d)}(s,r);if("lim"===a)return function(t,n){const[e,r,i,a]=t;let s,u,c=0;if(2===t.length&&"op"===r.type&&"→"===r.op)[s,u]=[en(r.args[0]),r.args[1]];else if(2===t.length)[s,u]=[o(e),r];else{if(!(t.length>=3))throw new F("a limit needs a point");[s,u]=[en(r),i]}if(4===t.length){const t="op"===a.type?"":String(a.value).toLowerCase();c=t.startsWith("r")||"+"===t?1:-1}if(!s)throw new F("a limit needs a variable");const l=Yt(u,n),f=ot(l),h=nn(e,s,n);let m,g;if(Number.isFinite(f))if(c)({value:m,error:g}=an(t=>h(f+c*t*Math.max(1,Math.abs(f)))));else{const t=an(t=>h(f+t*Math.max(1,Math.abs(f)))),r=an(t=>h(f-t*Math.max(1,Math.abs(f))));if(t.value===r.value)({value:m,error:g}=t);else{if(!(Number.isFinite(t.value)&&Number.isFinite(r.value)&&Math.abs(t.value-r.value)<=1e-6*Math.max(1,Math.abs(t.value))))throw new B("the limit does not exist");m=(t.value+r.value)/2,g=Math.max(t.error,r.error,Math.abs(t.value-r.value))}try{const t=Yt(e,{...n,[s]:l});if(Math.abs(ot(t)-m)<=1e-6*Math.max(1,Math.abs(m)))return t}catch(t){if(!(t instanceof B))throw t}}else({value:m,error:g}=an(t=>h(Math.sign(f)/t)));return Number.isFinite(m)?sn(m,g):m}(s,r);if("\\sumidx"===a||"\\prodidx"===a)return function(t,n,e){const[r,i,a]=n;if(n.length<3)throw new F("a sum needs its limits");let s,u=i;"op"===i.type&&"="===i.op&&"symbol"===i.args[0].type?[s,u]=[i.args[0].value,i.args[1]]:s=o(r)||"n";const c=St(Yt(u,e),"a sum"),l=Yt(a,e),f=t?bt:yt;if(l===1/0){if(!t)throw new F("an infinite product");return function(t,n){const e=[],r=[];let o=0,i=n;for(let a=4;a<=17;a++){const s=2**a;for(;i<n+s;i++){const n=t(i);if(!Number.isFinite(n))throw new B("undefined");o+=n}if(e.push(s),r.push(o),a>=6&&r[r.length-1]===r[r.length-2])return sn(o,0)}const a=r[r.length-1]-r[r.length-2],s=r[r.length-2]-r[r.length-3];if(Math.abs(a)>=.9*Math.abs(s)&&Math.abs(a)>1e-12)throw new B("the series diverges");const u=e.slice(-7).map(t=>1/t),c=r.slice(-7),l=r.slice(-8,-1),f=(t,n)=>{const e=n.slice();for(let n=1;n<t.length;n++)for(let r=0;r<t.length-n;r++)e[r]=(t[r+n]*e[r]-t[r]*e[r+1])/(t[r+n]-t[r]);return e[0]},h=f(u,c),m=f(e.slice(-8,-1).map(t=>1/t),l);return sn(h,Math.abs(h-m))}(nn(r,s,e),Number(c))}const h=St(l,"a sum");if(h-c+1n>BigInt(O.terms))throw new F("too many terms to add one by one");let m=R(t?0:1);for(let t=c;t<=h;t++)m=f(m,Yt(r,{...e,[s]:J(E(t))}));return m}("\\sumidx"===a,s,r);if(["()","[]","{}"].includes(a))return tt(s.map(u),a);if("pmatrix"===a||"bmatrix"===a)return Ht(e,u);if("vmatrix"===a)return Lt.det(Ht(e,u));if("^"===a&&"symbol"===s[1].type&&"T"===s[1].value&&!Object.prototype.hasOwnProperty.call(r,"T")){const t=u(s[0]);if(Ct(t))return Lt.transpose(t)}if(Ut.includes(a))return function(n,e){const r={};for(const[t,n]of Object.entries(e))"function"!=typeof n&&(r[t]=ut(n));try{return st(function(n,e={}){0===I&&(N=0),I++;try{return A(t(n),e)}finally{I--}}(n,r))}catch(t){throw new F(t.message)}}(e,r);if(a.startsWith("\\:")){const t=a.slice(2);if("function"!=typeof r[t]&&Object.prototype.hasOwnProperty.call(Xt,t))return Xt[t](...s.map(u));const n=r[t];if("function"!=typeof n)throw new F(`no function ${a.slice(2)}`);return st(n(...s.map(t=>ut(u(t)))))}if(Dt[a]&&1===s.length)return Dt[a](u(s[0]));if(Kt[a]&&2===s.length)return Kt[a](u(s[0]),u(s[1]));if(Qt[a])return Qt[a](s.map(u));throw new F(`can't calculate '${a}'`)}function tn(t,n){if(Object.prototype.hasOwnProperty.call(n,t))return n[t];if(Object.prototype.hasOwnProperty.call(qt,t))return qt[t]();throw new F(`no value for '${t}'`)}function nn(t,n,e){return r=>{try{return ot(Yt(t,{...e,[n]:r}))}catch(t){if(t instanceof B)return NaN;throw t}}}const en=t=>"symbol"===t.type?t.value:null;function rn(t,n,e){if(n===-1/0&&e===1/0){const n=rn(t,-1/0,0),e=rn(t,0,1/0);return{value:n.value+e.value,error:n.error+e.error}}return e===1/0?on(e=>t(n+e/(1-e))/((1-e)*(1-e)),0,1):n===-1/0?on(n=>t(e-n/(1-n))/((1-n)*(1-n)),0,1):on(t,n,e)}function on(t,n,e){const r=(e-n)/2;let o=1,i=0,a=NaN,s=NaN,u=0;const c=o=>{const i=Math.PI/2*Math.sinh(Math.abs(o)),a=Math.exp(-2*i),s=2*r*a/(1+a),c=r*(Math.PI/2)*Math.cosh(o)*(4*a)/((1+a)*(1+a));if(0===s||0===c)return 0;const l=o>0?e-s:n+s;if(0!==o&&(l<=n||l>=e))return 0;const f=t(0===o?(n+e)/2:l);if(!Number.isFinite(f)){if(s<1e-6*r)return 0;throw new B("the integral diverges")}return Math.abs(o)>3.5&&(u=Math.max(u,Math.abs(c*f))),c*f};i=c(0);for(let t=o;t<=4;t+=o)i+=c(t)+c(-t);a=o*i;for(let t=1;t<=8;t++){o/=2;for(let t=o;t<=4;t+=2*o)i+=c(t)+c(-t);s=a,a=o*i;const n=Math.max(1,Math.abs(a));if(u>1e-8*n)throw new B("the integral diverges");if(t>=3&&Math.abs(a-s)<=1e-13*n)break}const l=Math.abs(a-s);if(!Number.isFinite(a)||l>1e-6*Math.max(1,Math.abs(a)))throw new B("the integral does not converge");return{value:a,error:l}}function an(t){const n=[],e=[];for(let r=0;r<30;r++){const o=.1/2**r,i=t(o);Number.isFinite(i)&&(n.push(o),e.push(i))}if(e.length<6)throw new B("undefined");const r=e.slice(1).map((t,n)=>t-e[n]).slice(-6);if(r.every(t=>Math.sign(t)===Math.sign(r[0])&&0!==t)&&Math.abs(r[5])>=.95*Math.abs(r[0])&&Math.abs(e[e.length-1])>10)return{value:Math.sign(r[0])*(1/0),error:0};const o=t=>{const r=n.slice(t,t+8),o=e.slice(t,t+8);for(let t=1;t<r.length;t++)for(let n=0;n<r.length-t;n++)o[n]=(r[n+t]*o[n]-r[n]*o[n+1])/(r[n+t]-r[n]);return o[0]};let i=null;for(let t=0;t+9<=e.length;t++){const n=o(t),e=o(t+1),r=Math.abs(n-e);Number.isFinite(n)&&(!i||r<i.error)&&(i={value:n,error:r})}const a=e[e.length-1],s=Math.abs(a-e[e.length-2]);if(!i||i.error>Math.max(s,1e-6*Math.max(1,Math.abs(a)))){if(s<=1e-6*Math.max(1,Math.abs(a)))return{value:a,error:10*s};throw new B("the limit could not be found")}return i}function sn(t,n=0){if(!Number.isFinite(t))return t;const e=Math.max(1e-10,4*n)*Math.max(1,Math.abs(t));if(e>1e-6*Math.max(1,Math.abs(t)))return t;if(Math.abs(t)<e)return R(0);const r=[[R(1),1e3],[X,100],[J(W,2),100],[H,100],...[2n,3n,5n,6n,7n].map(t=>[J(W,0,0,{n:2,r:t}),100])];for(const[n,o]of r){const r=t/ot(n),i=un(r,o);if(i&&Math.abs(Number(i.n)/Number(i.d)-r)*ot(n)<=e)return ft(J(i),n)}return t}function un(t,n){if(!Number.isFinite(t)||Math.abs(t)>1e12)return null;let[e,r,o,i]=[0,1,1,0],a=t;for(let t=0;t<40;t++){const t=Math.floor(a),s=t*r+e,u=t*i+o;if(u>n)break;if([e,r,o,i]=[r,s,i,u],Math.abs(a-t)<1e-15)break;a=1/(a-t)}return i?E(BigInt(r),BigInt(i)):null}function cn(t,n){if("boolean"==typeof t)return String(t);if(t&&"s"===t.kind)return JSON.stringify(t.text);if(Array.isArray(t)){if("pm"===t.group&&2===t.length&&It(t[1],wt(t[0])))return`±${ln(t[0],n)}`;if(_t.has(t.group)&&a(t))return`${t.group}(${t.map(t=>`[${t.map(t=>cn(t,n)).join(", ")}]`).join(", ")})`;const[e,r]={"()":"()","[]":"[]","{}":"{}"}[t.group]||"{}";return e+t.map(t=>cn(t,n)).join(", ")+r}return"number"==typeof t?fn(t,n):n.decimal||null!==n.places?function(t,n){if(Q(t)&&null===n.places){let e=t.c.d,r=0,o=0;for(;e%2n==0n;)e/=2n,r++;for(;e%5n==0n;)e/=5n,o++;const i=Math.max(r,o);if(1n===e&&i<=n.digits){const e=t.c.n*10n**BigInt(i)/t.c.d,r=e<0n,o=P(e).toString().padStart(i+1,"0"),a=i?`${o.slice(0,-i)}.${o.slice(-i)}`:o;if(o.length<=n.maxDigits)return(r?"-":"")+hn(a)}}return Q(t)&&null!==n.places?cn(Tt(t,R(n.places)),{...n,places:null,decimal:!0}):fn(ot(t),n)}(t,n):function(t,n){const{c:e}=t,r=P(e.n);if(r.toString().length>n.maxDigits||e.d.toString().length>n.maxDigits)return function(t,n){if(!Q(t)||1n!==t.c.d)return fn(ot(t),n);const e=P(t.c.n).toString(),r=BigInt(e.slice(0,n.digits+1)),o=((r+5n)/10n).toString(),i=e.length-1+(o.length>n.digits?1:0),a=hn(`${o[0]}.${o.slice(1,n.digits)}`);return`${t.c.n<0n?"-":""}${a}*10^(${i})`}(t,n);const o=(t,n)=>1===n?t:`${t}^${n}`,i=[],a=[];t.pi>0&&i.push(o("pi",t.pi));t.pi<0&&a.push(o("pi",-t.pi));t.e>0&&i.push(o("e",t.e));t.e<0&&a.push(o("e",-t.e));t.root&&i.push(2===t.root.n?`sqrt(${t.root.r})`:`root(${t.root.n}, ${t.root.r})`);1n===r&&i.length||i.unshift(r.toString());1n!==e.d&&a.unshift(e.d.toString());const s=t=>t.length>1?`(${t.join("*")})`:t[0],u=a.length?`${s(i)}/${s(a)}`:i.join("*");return(e.n<0n?"-":"")+u}(t,n)}const ln=(t,n)=>{const e=cn(t,n);return/^[\d.]+$|^[a-zπ]+$/i.test(e)?e:`(${e})`};function fn(t,n){if(t===1/0)return"∞";if(t===-1/0)return"-∞";if(Object.is(t,-0)||0===t)return"0";if(null!==n.places&&Math.abs(t)<1e21)return t.toFixed(n.places);const e=Math.abs(t);if(e>=1e15||e<1e-6){const[e,r]=t.toExponential(n.digits-1).split("e");return`${hn(e)}*10^(${Number(r)})`}return String(Number(t.toPrecision(n.digits)))}const hn=t=>t.includes(".")?t.replace(/\.?0+$/,""):t;function mn(t,n={},o={}){const i="string"==typeof t?e(t):r(t),a={};for(const[t,e]of Object.entries(n))a[t]=st(e);let s;0===j&&(k=0),j++;try{s=Yt(i,a)}finally{j--}const u={decimal:!1,places:null,digits:12,maxDigits:50,...o};void 0===u.places&&(u.places=null);const c=t=>Array.isArray(t)?t.every(c):"number"!=typeof t;return{value:ut(s),text:cn(s,u),exact:c(s)}}function gn(t,n={}){let e=t.trim();const r={},o=/^(~|≈)\s*(\d+)?/.exec(e);o&&(r.decimal=!0,void 0!==o[2]&&(r.places=Number(o[2])),e=e.slice(o[0].length)),/\d\.\d|\.\d/.test(e)&&(r.decimal=!0);try{const{text:t}=mn(e,n,r);return t.startsWith('"')||/^\d+(\.\d+)?$/.test(t)?t:`(${t})`}catch(t){if(t instanceof B)return'"undefined"';if(t instanceof F)return`(${e})`;throw t}}i(gn);for(const t of[O,At,qt,Dt,Kt,Qt])Object.setPrototypeOf(t,null);Object.setPrototypeOf(Xt,null);export{mn as a,gn as c};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/* Inline Math 0.2.0 — MIT licence; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate with an import map */
|
|
2
|
-
import{GREEK as t,isCustomFunction as e,matrixRows as r,unaryNeedsBrackets as s,isMinusOneTimes as i,bracketedSides as n,isImplicitProduct as a,customName as l,needsBrackets as h,derivativeOrder as o,bracketOp as c,precedenceOf as u,isVariable as d,firstLeaf as p,firstVariable as m,MATRICES as f,walk as g,toPostfix as b,operator as $,VARIADIC as x,parseTree as v,fromPostfix as y}from"mathzetta";import{toAudioSpeech as w}from"mathzetta/speech";const L={"(":{fill:"M0.92,0 C0.1,0.2 0.1,0.8 0.92,1 L1,0.975 C0.48,0.75 0.48,0.25 1,0.025 Z"},")":{fill:"M0.08,0 C0.9,0.2 0.9,0.8 0.08,1 L0,0.975 C0.52,0.75 0.52,0.25 0,0.025 Z"},"{":{fill:"M1,0 C0.45,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.35,0.49 0.05,0.5 C0.35,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.45,1 1,1 L1,0.985 C0.68,0.985 0.64,0.95 0.64,0.8 L0.64,0.62 C0.64,0.53 0.55,0.505 0.3,0.5 C0.55,0.495 0.64,0.47 0.64,0.38 L0.64,0.2 C0.64,0.05 0.68,0.015 1,0.015 Z"},"}":{fill:"M0,0 C0.55,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.65,0.49 0.95,0.5 C0.65,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.55,1 0,1 L0,0.985 C0.32,0.985 0.36,0.95 0.36,0.8 L0.36,0.62 C0.36,0.53 0.45,0.505 0.7,0.5 C0.45,0.495 0.36,0.47 0.36,0.38 L0.36,0.2 C0.36,0.05 0.32,0.015 0,0.015 Z"},sqrt:{stroke:"M0,0.62 L0.18,0.55 L0.45,0.97 L0.98,0.015"},cancel:{stroke:"M0,1 L1,0"},int:{stroke:"M0.95,0.09 C0.9,0.01 0.72,0 0.66,0.12 C0.6,0.25 0.42,0.75 0.34,0.88 C0.28,0.99 0.1,0.99 0.05,0.91"},sum:{fill:"M0.04,0 L0.94,0 L0.98,0.24 L0.94,0.24 C0.9,0.1 0.8,0.07 0.62,0.07 L0.24,0.07 L0.58,0.5 L0.2,0.93 L0.64,0.93 C0.82,0.93 0.92,0.9 0.95,0.76 L0.99,0.76 L0.94,1 L0.02,1 L0.47,0.47 Z"},prod:{fill:"M0,0 L1,0 L1,0.04 L0.88,0.05 L0.88,0.95 L1,0.96 L1,1 L0.62,1 L0.62,0.96 L0.74,0.95 L0.74,0.06 L0.26,0.06 L0.26,0.95 L0.38,0.96 L0.38,1 L0,1 L0,0.96 L0.12,0.95 L0.12,0.05 L0,0.04 Z"}};function M(t,e,r=""){const s=L[t];return`<svg class="${e}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${r?` style="${r}"`:""}>${s.fill?`<path d="${s.fill}" fill="currentColor"/>`:`<path d="${s.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const k=.8,C=.2,z=.25,P=.7,j="−",A={"+":"add","-":"sub","*":"mul","/":"frac","^":"pow",_:"subscript",neg:"neg",pm:"pm","!":"factorial","=":"eq","===":"eq","≠":"neq","≠=":"neq","<":"lt",">":"gt","≤":"le","≥":"ge","≈":"approx","≡":"equiv","∈":"in","∉":"notin","∪":"union","∩":"intersect","→":"to","±":"pm","&":"and","|":"or","\\not":"not","\\xor":"xor","\\nand":"nand","\\nor":"nor","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod",pmatrix:"matrix",bmatrix:"matrix",vmatrix:"matrix"},Z={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},q={"±":"±","∪":"∪","∩":"∩",mod:"mod"},B=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],F={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},O=[...B,...Object.keys(F),"ln","det"],S={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},W={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},E={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},_={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},I=["boxed","overline","bar","underline","cancel",...Object.keys(_)],N={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},T=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),D=t=>+t.toFixed(3)+"em",R=(t,e=k,r=C)=>({html:t,h:e,d:r});function G(...t){const e=t.flat().filter(Boolean);return{html:e.map(t=>t.html).join(""),h:Math.max(k,...e.map(t=>t.h)),d:Math.max(C,...e.map(t=>t.d))}}function H(t,e={}){const r=new J({...N,...e}),s=r.render(t,{level:0}),i=`${r.p}${r.o.display?` ${r.p}-display`:""}`,n="function"==typeof r.o.mathml?function(t,e,r,s){try{return String(t(e)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${r}-sr-math"${s?' display="block"':""}>`)}catch{return""}}(r.o.mathml,t,r.p,r.o.display):"",a=n?null:function(t,e){if(!1===e||null===e)return null;if("string"==typeof e)return e;try{return"function"==typeof e?e(t):w(t)}catch{return null}}(t,r.o.label),l=null!==a||n?s.html.replace(/^<span /,'<span aria-hidden="true" '):s.html;return{html:`<span class="${i}"${null===a?"":` role="math" aria-label="${T(a)}"`}>${l}${n}</span>`,h:s.h,d:s.d}}class J{constructor(t){this.o=t,this.p=t.prefix}el(t,e,r="",s=""){return`<span class="${t.split(" ").map(t=>`${this.p}-${t}`).join(" ")}"${r?` style="${r}"`:""}${s}>${e}</span>`}text(t,e){const r=R(this.el(t,T(e)));return r.leaf={kind:t,content:T(e)},r}bin(t){return this.text("bin",t)}rel(t){return this.text("rel",t)}punct(t){return this.text("punct",t)}word(t){return this.text("word",t)}wrap(t,e,r){let s="";void 0!==t.id&&(s+=` data-node="${t.id}"`),"op"===t.type&&(s+=` data-op="${T(t.op)}"`);const i=this.o.attributes&&this.o.attributes(t)||{};for(const[t,e]of Object.entries(i))"class"!==t&&"style"!==t&&(s+=` ${t}="${T(e)}"`);const n=[i.style,this.o.style&&this.o.style(t)].filter(Boolean).join(";"),a=(r.leaf?["n",...e,r.leaf.kind]:["n",...e]).map(t=>`${this.p}-${t}`).concat(i.class?[i.class]:[]).join(" "),l=r.leaf?r.leaf.content:r.html;return{html:`<span class="${a}"${n?` style="${T(n)}"`:""}${s}>${l}</span>`,h:r.h,d:r.d}}render(t,e){return"number"===t.type?this.number(t):"string"===t.type?this.wrap(t,["text"],this.text("text",t.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===t.type?this.wrap(t,["symbol"],this.symbol(t.value)):this.operation(t,e)}number(t){return this.wrap(t,["number"],this.text("num",t.value.replace(/^-/,j)))}symbol(e){return t[e]&&(e=t[e]),E[e]?this.text("ord",E[e]):"\\+"===e||"\\-"===e?this.text("ord",e[1]):"-∞"===e?this.text("ord","−∞"):/^[A-Za-z]$/.test(e)||/^[α-ω]$/.test(e)?this.text("var",e):/^[A-Za-z]′+$/.test(e)?R(this.el("var",T(e[0]))+this.el("prime",T(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?R(this.el("ord","Δ")+this.el("var",e[1])):e.endsWith("⁻¹")?this.script(this.symbol(e.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(e)?this.text("name",e.slice(1)):/^[A-Za-z]{2,}$/.test(e)?this.text("name",e):this.text("ord",e)}operation(t,n){const{op:a,args:l}=t,[o,c]=l,u=(t,e={})=>this.render(t,{...n,...e,forceParens:e.forceParens||!1,before:e.before||!1}),d=A[a]??(/^[a-z0-9]+$/i.test(a)?a:"other"),p=e=>this.wrap(t,["op",`op-${d}`],e),m=(e,r)=>h(t,e,r)&&"/"!==e.op?this.fence(u(e)):u(e);if(O.includes(a)||"log"===a)return p(this.named(t,n));if(S[a])return p(G(this.word(S[a]),this.fence(this.list(l,n))));if(e(a))return p(this.custom(t,n));const f=r(t);if(f)return p(this.matrix(t,f,n));if(W[a])return p(this.fence(this.list(l,n),...W[a]));if(Z[a]&&2===l.length)return p(G(m(o,"left"),this.rel(Z[a]),m(c,"right")));if(q[a]&&2===l.length)return p(G(m(o,"left"),this.bin(q[a]),m(c,"right")));switch(a){case"+":return i(c)?p(G(m(o,"left"),this.bin(j),this.wrap(c,["op","op-mul"],this.render(c.args[1],n)))):"number"===c.type&&c.value.startsWith("-")?p(G(m(o,"left"),this.bin(j),this.wrap(c,["number"],this.text("num",c.value.slice(1))))):p(G(m(o,"left"),this.bin("+"),this.signed(c,m(c,"right"))));case"-":return p(G(m(o,"left"),this.bin(j),this.signed(c,m(c,"right"))));case"*":return p(this.product(t,n));case"/":return p(this.fraction(t,n));case"^":return p(this.power(t,n));case"_":return p(this.script(u(o,{forceParens:!0}),null,n,u(c,{level:n.level+1})));case"neg":return p(G(this.text("sign",j),s(a,o)?this.fence(u(o)):u(o,{before:n.before})));case"pm":return p(G(this.text("sign","±"),s(a,o)?this.fence(u(o)):u(o)));case"!":return p(G(s(a,o)?this.fence(u(o)):u(o,{forceParens:!0}),this.text("ord","!")));case"\\not":return p(G(this.text("sign","¬"),s(a,o)?this.fence(u(o)):u(o)));case"pmod":return p(G(u(o),this.fence(G(this.word("mod"),this.text("space",""),u(c)))));case"sqrt":return p(this.radical(u(o)));case"root":return p(this.radical(u(c),this.render(o,{level:n.level+2})));case"abs":return p(this.fence(u(o),"|","|"));case"floor":return p(this.fence(u(o),"⌊","⌋"));case"ceil":return p(this.fence(u(o),"⌈","⌉"));case"loglog":return p(G(this.word("ln"),this.fence(G(this.word("ln"),this.fence(u(o))))));case"logloglog":return p(G(this.word("ln"),this.fence(G(this.word("ln"),this.fence(G(this.word("ln"),this.fence(u(o))))))));case"perm":return p(this.script(this.script(R(""),this.render(o,{level:n.level+1}),n),null,n,this.render(c,{level:n.level+1}),this.word("P")));case"comb":return p(this.fence(this.stack(u(o),u(c),!1)));case"?:":return p(this.o.cases?this.cases(t,n):G(u(o),this.bin("?"),u(c),this.bin(":"),u(l[2])));case"sum":return p(G(l.map((t,e)=>e?[this.bin("+"),u(t)]:[u(t)]).flat()));case"prod":return p(G(l.map((t,e)=>e?[this.bin("·"),u(t)]:[u(t)]).flat()));case"der":return p(this.derivative(t,n));case"int":return p(this.integral(l,n));case"lim":return p(this.limit(l,n));case"\\sumidx":return p(this.bigOperator("sum",l,n));case"\\prodidx":return p(this.bigOperator("prod",l,n))}throw new Error(`Inline Math cannot draw '${a}'`)}signed(t,e){return("number"===t.type?t.value.startsWith("-"):"neg"===t.op||"pm"===t.op)&&!e.fenced?this.fence(e):e}list(t,e){return G(t.map((t,r)=>r?[this.punct(","),this.render(t,e)]:[this.render(t,e)]).flat())}product(t,r){const[s,l]=t.args;if(i(t))return G(this.text("sign",j),this.render(l,r));const h=n(t),o=a(s,l,h),c=function(t){for(;"op"===t.type;){if(O.includes(t.op)||"log"===t.op||S[t.op]||e(t.op))return!0;if("^"!==t.op&&"*"!==t.op)return!1;t=t.args[0]}return!1}(l),u=h.left?this.fence(this.render(s,r)):this.render(s,{...r,before:o&&!c}),d=h.right?this.fence(this.render(l,r)):this.render(l,{...r,before:r.before});return G(u,o?R(this.el(c?"fnspace":"times","")):this.bin("·"),d)}named(t,e,r=null){const{op:s,args:i}=t,n="log"===s?i[1]:i[0];let a;a=F[s]&&"power"===this.o.inverseTrig?this.script(this.word(F[s]),this.text("num","−1"),e):this.word(s),r&&(a=this.script(a,r,e)),"log"===s&&(a=this.script(a,null,e,this.render(i[0],{level:e.level+1})));const l="auto"===this.o.fnParens&&!e.forceParens&&!e.before&&K(n),h=this.render(n,{...e,forceParens:!1,before:!1});return G(a,l?G(R(this.el("fnspace","")),h):this.fence(h))}custom(t,e){const r=l(t.op),s=t.args;if(I.includes(r)&&1===s.length)return this.decorate(r,this.render(s[0],e));return G(/^[A-Za-z]′*(⁻¹)?$/.test(r)?this.symbol(r):this.word(r),R(this.el("callgap","")),this.fence(this.list(s,e)))}decorate(t,e){switch(t){case"boxed":return R(this.el("boxed",e.html),e.h+.22,e.d+.22);case"cancel":return R(this.el("cancel",e.html+M("cancel",`${this.p}-cancel-line`)),e.h,e.d);case"underline":return R(this.el("underline",e.html),e.h,e.d+.12);case"overline":case"bar":return R(this.el("over",e.html),e.h+.14,e.d);default:return R(this.el("accent",this.el("accent-mark",_[t])+e.html),e.h+.3,e.d)}}fraction(t,e){const[r,s]=t.args;if(e.level>0&&"slash"===this.o.scriptFractions&&K(r,!0)&&K(s,!0)){const t=t=>"op"!==t.type||K(t)?this.render(t,e):this.fence(this.render(t,e));return G(t(r),this.text("ord","/"),t(s))}const i=e.level>0||e.inFraction||!this.o.display?.8:1,n={...e,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(r,n),this.render(s,n),!0,i)}stack(t,e,r=!0,s=1){const i=t=>1===s?t.html:this.el("scaled",t.html,`font-size:${D(s)}`),n=r?.06:0,a=z+n/2+.1+Math.max(C,s*t.d),l=this.el("frac"+(r?"":" frac-nobar"),this.el("numer",i(t))+this.el("denom",i(e)),`vertical-align:${D(a)}`);return R(l,a+Math.max(k,s*t.h),Math.max(k,s*e.h)+Math.max(C,s*e.d)+.1+n/2-z)}power(t,e){const[r,s]=t.args,i={...e,level:e.level+1,forceParens:!1,before:!1,inFraction:!1},n=()=>this.render(s,i);if(this.o.trigPowers&&B.includes(r.op)&&U(s))return this.wrap(r,["op",`op-${r.op}`],this.named(r,e,n()));if("_"===r.op){const t=this.render(r.args[1],i);return this.wrap(r,["op","op-subscript"],this.script(this.render(r.args[0],{...e,forceParens:!0}),n(),e,t))}const a=h(t,r,"left")||"number"===r.type&&r.value.startsWith("-")||"/"===r.op||O.includes(r.op)?this.fence(this.render(r,e)):this.render(r,{...e,forceParens:!0});return this.script(a,n(),e)}script(t,e,r,s=null,i=null){const n=r.level>0?.8:P,a=i?G(t,i):t;let l=e?Math.max(.42,t.h-.38,n*e.d+.12):0,h=s?Math.max(.2,t.d-.05,n*s.h-.45):0;if(e&&s){const t=.1-(l-n*e.d-(n*s.h-h));t>0&&(h+=t)}const o=t=>this.el("script",t.html,`font-size:${D(n)}`);if(e&&!s)return R(t.html+this.el("sup",e.html,`font-size:${D(n)};vertical-align:${D(l/n)}`),Math.max(a.h,l+n*e.h),Math.max(a.d,n*e.d-l));if(s&&!e)return R(a.html+this.el("sub",s.html,`font-size:${D(n)};vertical-align:${D(-h/n)}`),Math.max(a.h,n*s.h-h),Math.max(a.d,h+n*s.d));const c=l+n*e.h,u=h+n*s.d,d=this.el("subsup",o(e)+o(s),`vertical-align:${D(l)};height:${D(c+u)}`);return R(a.html+d,Math.max(a.h,c),Math.max(a.d,u))}radical(t,e=null){const r=Math.max(t.h,k)+.1+.06,s=Math.max(t.d,C),i=r+s,n=M("sqrt",`${this.p}-hook`,`height:${D(i)};width:${D(.5+.06*(i-1))};vertical-align:${D(-s)}`);let a="";if(e){const t=.8*P;a=this.el("rootindex",e.html,`font-size:${D(t)};vertical-align:${D((.55*i-s)/t)}`)}return R(this.el("sqrt",a+n+this.el("radicand",t.html)),r,s)}fence(t,e="(",r=")"){const s=Math.max(t.h,k)+Math.max(t.d,C),i=s>1.25,n=i?.1:0,a=(t,e)=>{if(!t)return{html:"",w:0};const r={"(":.26,")":.26,"{":.36,"}":.36}[t];if(r){const n=r+(i?Math.min(.2,.05*(s-1)):0);return{html:M(t,`${this.p}-delim ${this.p}-delim-${e}`,`width:${D(n)}`),w:n+.1}}const n={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[t];return{html:this.el(`delim ${n} delim-${e}`,""),w:"|"===t?.18:.3}},l=a(e,"l"),h=a(r,"r"),o=`padding:${D(n)} ${D(h.w)} ${D(n)} ${D(l.w)}`,c=R(this.el("fence",l.html+t.html+h.html,o),Math.max(t.h,k)+n,Math.max(t.d,C)+n);return c.fenced=!0,c}derivative(t,e){const{n:r,body:s,by:i,variable:n}=o(t),a={...e,level:e.level+1},l=()=>this.text("d","d"),h=()=>r>1?this.render({type:"number",value:String(r)},a):null,d={...e,inFraction:!0},p=G(l(),h()?this.script(this.render(i,d),h(),d):this.render(i,d)),m=t=>G(h()?this.script(l(),h(),d):l(),t||[]),f=e.level>0||e.inFraction||!this.o.display?.8:1;if(n)return this.stack(m(this.render(s,d)),p,!0,f);const g=c(s)&&u(c(s))<100,[b,$]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],x=g?this.fence(this.render(s,e),b,$):this.render(s,e);return G(this.stack(m(),p,!0,f),x)}integral(t,e){const[r,s,i,n]=t,a=t=>this.render(t,e),l=t=>t?this.render(t,{...e,level:e.level+1}):null,h=()=>this.text("var",m(r)||"x");let o,c=null,u=null;switch(t.length){case 1:o=h();break;case 2:d(s)?o=a(s):(o=h(),c=l(s));break;case 3:d(s)?(o=a(s),c=l(i)):(o=h(),c=l(s),u=l(i));break;default:o=a(s),c=l(i),u=l(n)}const p=a(r),f=R(this.el("dx",this.el("d","d")+o.html),o.h,o.d);return G(this.bigSign("int",p,c,u,e),p,f)}bigSign(t,e,r,s,i){const n=!this.o.display||i.level>0,a=Math.max(n?.6:.95,Math.max(e.h-z,e.d+z)+.12),l=M(t,`${this.p}-bigsign ${this.p}-${t}sign`,`height:${D(2*a)};width:${D(n?.38:.5)};vertical-align:${D(z-a)}`);if(!r&&!s)return R(l,z+a,a-z);const h=P,o=s||R(""),c=r||R(""),u=z+a-h*o.h;c.d;const d=this.el("limits",this.el("script",o.html,`font-size:${D(h)}`)+this.el("script lower",c.html,`font-size:${D(h)}`),`vertical-align:${D(u)};height:${D(2*a)}`);return R(l+d,z+a,a-z)}limit(t,e){const[r,s,i,n]=t,a={...e,level:e.level+1},l=t=>this.render(t,a),h=()=>this.rel("→");let o;switch(t.length){case 1:return G(this.word("lim"),R(this.el("fnspace","")),this.render(r,e));case 2:{const t=m(r),e="number"===s.type||"symbol"===s.type&&s.value.includes("∞");o=t&&e?G(this.text("var",t),h(),l(s)):l(s);break}case 3:o=G(l(s),h(),l(i));break;default:{const t=p(n).toLowerCase().startsWith("r")?"+":j;o=G(l(s),h(),this.script(l(i),this.wrap(n,["symbol"],this.text("ord",t)),a))}}return G(this.under(this.word("lim"),o,e),this.render(r,e))}under(t,e,r){return!this.o.display||r.level>0?this.script(t,null,r,e):R(this.el("under",t.html+this.el("script",e.html,`font-size:${D(.7)}`)),t.h,Math.max(t.d,C)+.05+.7*(e.h+e.d))}bigOperator(t,e,r){const[s,i,n]=e,a={...r,level:r.level+1},l=i?this.render(i,a):null,h=n?this.render(n,a):null,o=this.render(s,r);if(!this.o.display||r.level>0){const e=.55,s=M(t,`${this.p}-bigsign`,`height:${D(2*e)};width:${D(.8)};vertical-align:${D(z-e)}`);return G(this.script(R(s,z+e,e-z),h,r,l),o)}const c=.68,u=P,d=M(t,`${this.p}-bigsign`,`height:${D(1.36)};width:${D("sum"===t?1:1.05)}`),p=h?1.01+u*h.d:z-c,m=t=>this.el("script",t.html,`font-size:${D(u)}`),f=this.el("bigop",(h?m(h):"")+d+(l?m(l):""),`vertical-align:${D(p)}`);return G(R(f,.93+(h?.08+u*(h.h+h.d):0),c-z+(l?.08+u*(l.h+l.d):0)),o)}matrix(t,e,r){const s=e.map(t=>t.map(t=>this.render(t,r))),i=s.map(t=>({h:Math.max(k,...t.map(t=>t.h)),d:Math.max(C,...t.map(t=>t.d))})),n=i.reduce((t,e)=>t+e.h+e.d,0)+.3*(e.length-1),a=z+n/2-i[0].h,l=s.map((e,r)=>{const s=e.map(t=>this.el("matrix-cell",t.html)).join(""),i=t.args[r];return i&&"op"===i.type&&"[]"===i.op?this.wrap(i,["op","op-list","matrix-row"],R(s)).html:s}).join(""),h=e[0].length,o=R(this.el("matrix",l,`grid-template-columns:repeat(${h},auto);vertical-align:${D(a)}`),z+n/2,n/2-z),[c,u]=f[t.op]??["[","]"];return this.fence(o,c,u)}cases(t,e){const r=[];let s=t;for(;"op"===s.type&&"?:"===s.op;)r.push([this.render(s.args[1],e),G(this.word("if"),this.text("space",""),this.render(s.args[0],e))]),s=s.args[2];"symbol"===s.type&&"unchanged"===s.value||r.push([this.render(s,e),this.word("otherwise")]);const i=r.map(([t,e])=>({h:Math.max(t.h,e.h),d:Math.max(t.d,e.d)})),n=i.reduce((t,e)=>t+e.h+e.d,0)+.25*(r.length-1),a=z+n/2-i[0].h,l=r.map(([t,e])=>this.el("case-value",t.html)+this.el("case-cond",e.html)).join(""),h=R(this.el("cases",l,`vertical-align:${D(a)}`),z+n/2,n/2-z);return this.fence(h,"{","")}}function K(t,e=!1){return"number"===t.type?!t.value.startsWith("-")||e:"symbol"===t.type||"op"===t.type&&("abs"===t.op||r(t)?!e:!e||"neg"!==t.op&&"^"!==t.op?"*"===t.op&&!i(t)&&t.args.every(t=>"number"===t.type&&!t.value.startsWith("-")||Q(t)||"*"===t.op&&K(t,e)):K(t.args[0],!0)&&("neg"===t.op||K(t.args[1],!0)))}const Q=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(t[e.value])),U=t=>"number"===t.type&&/^[1-9]\d*$/.test(t.value)&&Number(t.value)<10;const V=t=>b(t).join(" ");function X(t,e){const r=new Set;Y(t,e,r);const s=[];return g(t,t=>{r.has(t)&&s.push(t)}),s}function Y(t,e,r){if(null!=e)if(Array.isArray(e))e.forEach(e=>Y(t,e,r));else if("number"!=typeof e)if("function"!=typeof e){if("string"==typeof e){const s=V(v(e));return void g(t,t=>{V(t)===s&&r.add(t)})}if(e.path){const s=tt(t,e.path);return void(s&&r.add(s))}if(e.type){const s=V(e);g(t,t=>{t!==e&&V(t)!==s||r.add(t)})}}else g(t,(t,s)=>{e(t,s)&&r.add(t)});else g(t,t=>{t.id===e&&r.add(t)})}function tt(t,e){let r=t;for(const t of e){if("op"!==r.type||!r.args[t])return null;r=r.args[t]}return r}function et(t,e){const r=[],s=t=>{if(t.id===e)return!0;if("op"!==t.type)return!1;for(let e=0;e<t.args.length;e++){if(r.push(e),s(t.args[e]))return!0;r.pop()}return!1};return s(t)?r:null}function rt(t){let e=0;const r=t=>{"op"===t.type&&(t.args.forEach(r),$(t.op)?.arity===x&&e++),t.id=e++};return r(t),t}function st(t,e={}){const{blocks:r}=e;if("string"==typeof t)return v(t,r?{blocks:t=>r(t,e.scope)}:{});if(Array.isArray(t))return y(t);if(t&&"object"==typeof t&&t.type)return void 0===t.id?rt(structuredClone(t)):t;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function it(t,e={}){const r=st(t,e);return H(r,nt(r,e)).html}function nt(t,e){const{colors:r,highlight:s,scope:i,blocks:n,...a}=e,l=new Map;for(const[e,s]of function(t){return t?Array.isArray(t)?t:Object.entries(t).map(([t,e])=>[/^\d+$/.test(t)?Number(t):t,e]):[]}(r))if(at(s))for(const r of X(t,e))l.set(r,`color:${s}`);const h=new Set(void 0===s?[]:X(t,s));if(!l.size&&!h.size)return a;const o=a.prefix||"mv";return{...a,style:t=>[l.get(t),a.style&&a.style(t)].filter(Boolean).join(";"),attributes:t=>{const e={...a.attributes?a.attributes(t):{}};return h.has(t)&&(e.class=[e.class,`${o}-hl`].filter(Boolean).join(" ")),e}}}function at(t){return"string"==typeof t&&/^[#\w\s.,%()/+-]+$/.test(t)&&!/url\s*\(|expression/i.test(t)}export{N as D,L as P,st as a,nt as b,tt as c,V as d,H as l,rt as n,et as p,X as s,it as t};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/* Inline Math 0.2.0 — MIT licence; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate with an import map */
|
|
2
|
-
const e=Symbol.for("inlinemath.expressions"),t=new Set(["symbol","number"]);function n(e){return e?"symbol"===e.type?e.value:"op"===e.type&&"_"===e.op&&2===e.args.length&&"symbol"===e.args[0].type&&t.has(e.args[1].type)?`${e.args[0].value}_${e.args[1].value}`:null:null}function s(e){const{id:t,from:n,...r}=e;return r.args&&(r.args=r.args.map(s)),r}function r(e){const{id:t,...n}=e;return n.args&&(n.args=n.args.map(r)),n}function i(e,t){const n=(e,s)=>{if(!s&&void 0!==e.from)return t(e.from);const{id:r,from:i,...o}=e;return o.args&&(o.args=o.args.map(e=>n(e,!1))),o};return n(e,!0)}function o(e,t){let i=!1;const o=new Set,a=e=>{const r=n(e);if(null!==r){if(!o.has(r)){const e=t(r);if(e){i=!0,o.add(r);const t={...a(s(e)),from:r};return o.delete(r),t}}return e}return e.args?{...e,args:e.args.map(a)}:e},l=a(e);return{tree:i?r(l):e,changed:i}}const a="[-+]?(?:\\d+\\.?\\d*|\\.\\d+)",l=new RegExp(`^(${a})\\s*\\.\\.\\s*(${a})(?:\\s+step\\s+(${a}))?(?:\\s*=\\s*(${a}))?$`);function u(e){const t=/^\s*\[\[([\s\S]*)\]\]\s*$/.exec(e);if(!t||/\]\s*,\s*\[/.test(t[1]))return null;const n=t[1].trim(),s=l.exec(n);if(s){const e=Number(s[1]),t=Number(s[2]);if(!(t>e))return null;const n=void 0!==s[3]?Number(s[3]):Number.isInteger(e)&&Number.isInteger(t)?1:(t-e)/100;if(!(n>0))return null;const r=void 0!==s[4]?Math.min(t,Math.max(e,Number(s[4]))):e;return{kind:"slider",min:e,max:t,step:n,default:String(r)}}if(n.includes("|")){const e=n.split("|").map(e=>e.trim()).filter(Boolean);if(e.length)return{kind:"dropdown",options:e,default:e[0]}}return{kind:"textbox",default:n}}const c=Symbol("set on the page");class f{constructor(){this.owners=new Map,this.chosen=new Map,this.listeners=new Set}definitions(e){const t=new Map;for(const[n,s]of this.owners)if(n!==e)for(const[e,n]of s)t.delete(e),t.set(e,n);return t}textOf(e){const t=this.chosen.get(e.name);return t&&t.key===e.key?t.text:e.text}get(e){const t=this.definitions().get(e);return t?this.textOf(t):void 0}names(){return[...this.definitions().keys()]}set(e,t){t=String(t);const n=this.definitions().get(e);if(n&&n.input){const s=this.chosen.get(e);if(s&&s.key===n.key&&s.text===t)return this;this.chosen.set(e,{key:n.key,text:t})}else{const n=new Map(this.owners.get(c));n.set(e,{name:e,text:t,key:`page:${t}`,input:null}),this.owners.delete(c),this.owners.set(c,n)}return this.notify(null,e),this}clear(e){return void 0===e?(this.owners.clear(),this.chosen.clear()):(this.owners.get(c)?.delete(e),this.chosen.delete(e)),this.notify(null,e),this}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}own(e,t){const n=this.owners.get(e);var s,r;(s=n,r=t,(s?.size??0)===(r?.size??0)&&[...s??[]].every(([e,t])=>r?.get(e)?.key===t.key))?t&&this.owners.set(e,t):(t&&t.size?this.owners.set(e,t):this.owners.delete(e),this.notify(e))}notify(e,t){for(const n of[...this.listeners])n(e,t)}}function h(){return new f}const d=h();function g(e,t,n){const r=(e,s)=>s===t.length?n:{...e,args:e.args.map((e,n)=>n===t[s]?r(e,s+1):e)};return s(r(e,0))}function m(e,t,{parse:n,commit:s,cancel:r,label:i="Edit"}){const o=e.ownerDocument;if(!o||!o.body)return null;const a=o.defaultView,l=e.getBoundingClientRect(),u=o.createElement("input");u.type="text",u.className="mv-edit",u.value=t,u.spellcheck=!1,u.autocomplete="off",u.setAttribute("aria-label",i);const c=()=>{u.style.width=`${Math.max(4,u.value.length+2)}ch`},f=a.getComputedStyle(e);Object.assign(u.style,{position:"absolute",left:`${l.left+a.scrollX}px`,top:`${l.top+a.scrollY+l.height/2}px`,minWidth:`${Math.max(l.width,32)}px`,fontSize:f.fontSize}),c(),o.body.appendChild(u),a.getSelection?.()?.removeAllRanges(),u.focus(),u.select();let h=!1;const d=()=>{h=!0,u.remove()},g=e=>{if(h)return!0;if(!e||u.value===t)return d(),r&&r(),!0;let i;try{i=n(u.value)}catch(e){return u.setAttribute("aria-invalid","true"),u.title=e.message,!1}return d(),s(i,u.value),!0};return u.addEventListener("keydown",e=>{e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),g(!0)),"Escape"===e.key&&(e.preventDefault(),g(!1))}),u.addEventListener("input",()=>{c(),u.removeAttribute("aria-invalid"),u.removeAttribute("title")}),u.addEventListener("blur",()=>{g(!0)||g(!1)}),u}export{e as E,f as V,s as b,h as c,u as i,n,m as o,g as r,o as s,i as u,d as v};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/* Inline Math 0.2.0 — MIT licence; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
-
const e=Symbol.for("inlinemath.expressions"),t=new Set(["symbol","number"]);function n(e){return e?"symbol"===e.type?e.value:"op"===e.type&&"_"===e.op&&2===e.args.length&&"symbol"===e.args[0].type&&t.has(e.args[1].type)?`${e.args[0].value}_${e.args[1].value}`:null:null}function s(e){const{id:t,from:n,...r}=e;return r.args&&(r.args=r.args.map(s)),r}function r(e){const{id:t,...n}=e;return n.args&&(n.args=n.args.map(r)),n}function i(e,t){const n=(e,s)=>{if(!s&&void 0!==e.from)return t(e.from);const{id:r,from:i,...o}=e;return o.args&&(o.args=o.args.map(e=>n(e,!1))),o};return n(e,!0)}function o(e,t){let i=!1;const o=new Set,a=e=>{const r=n(e);if(null!==r){if(!o.has(r)){const e=t(r);if(e){i=!0,o.add(r);const t={...a(s(e)),from:r};return o.delete(r),t}}return e}return e.args?{...e,args:e.args.map(a)}:e},l=a(e);return{tree:i?r(l):e,changed:i}}const a="[-+]?(?:\\d+\\.?\\d*|\\.\\d+)",l=new RegExp(`^(${a})\\s*\\.\\.\\s*(${a})(?:\\s+step\\s+(${a}))?(?:\\s*=\\s*(${a}))?$`);function u(e){const t=/^\s*\[\[([\s\S]*)\]\]\s*$/.exec(e);if(!t||/\]\s*,\s*\[/.test(t[1]))return null;const n=t[1].trim(),s=l.exec(n);if(s){const e=Number(s[1]),t=Number(s[2]);if(!(t>e))return null;const n=void 0!==s[3]?Number(s[3]):Number.isInteger(e)&&Number.isInteger(t)?1:(t-e)/100;if(!(n>0))return null;const r=void 0!==s[4]?Math.min(t,Math.max(e,Number(s[4]))):e;return{kind:"slider",min:e,max:t,step:n,default:String(r)}}if(n.includes("|")){const e=n.split("|").map(e=>e.trim()).filter(Boolean);if(e.length)return{kind:"dropdown",options:e,default:e[0]}}return{kind:"textbox",default:n}}const c=Symbol("set on the page");class f{constructor(){this.owners=new Map,this.chosen=new Map,this.listeners=new Set}definitions(e){const t=new Map;for(const[n,s]of this.owners)if(n!==e)for(const[e,n]of s)t.delete(e),t.set(e,n);return t}textOf(e){const t=this.chosen.get(e.name);return t&&t.key===e.key?t.text:e.text}get(e){const t=this.definitions().get(e);return t?this.textOf(t):void 0}names(){return[...this.definitions().keys()]}set(e,t){t=String(t);const n=this.definitions().get(e);if(n&&n.input){const s=this.chosen.get(e);if(s&&s.key===n.key&&s.text===t)return this;this.chosen.set(e,{key:n.key,text:t})}else{const n=new Map(this.owners.get(c));n.set(e,{name:e,text:t,key:`page:${t}`,input:null}),this.owners.delete(c),this.owners.set(c,n)}return this.notify(null,e),this}clear(e){return void 0===e?(this.owners.clear(),this.chosen.clear()):(this.owners.get(c)?.delete(e),this.chosen.delete(e)),this.notify(null,e),this}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}own(e,t){const n=this.owners.get(e);var s,r;(s=n,r=t,(s?.size??0)===(r?.size??0)&&[...s??[]].every(([e,t])=>r?.get(e)?.key===t.key))?t&&this.owners.set(e,t):(t&&t.size?this.owners.set(e,t):this.owners.delete(e),this.notify(e))}notify(e,t){for(const n of[...this.listeners])n(e,t)}}function h(){return new f}const d=h();function g(e,t,n){const r=(e,s)=>s===t.length?n:{...e,args:e.args.map((e,n)=>n===t[s]?r(e,s+1):e)};return s(r(e,0))}function m(e,t,{parse:n,commit:s,cancel:r,label:i="Edit"}){const o=e.ownerDocument;if(!o||!o.body)return null;const a=o.defaultView,l=e.getBoundingClientRect(),u=o.createElement("input");u.type="text",u.className="mv-edit",u.value=t,u.spellcheck=!1,u.autocomplete="off",u.setAttribute("aria-label",i);const c=()=>{u.style.width=`${Math.max(4,u.value.length+2)}ch`},f=a.getComputedStyle(e);Object.assign(u.style,{position:"absolute",left:`${l.left+a.scrollX}px`,top:`${l.top+a.scrollY+l.height/2}px`,minWidth:`${Math.max(l.width,32)}px`,fontSize:f.fontSize}),c(),o.body.appendChild(u),a.getSelection?.()?.removeAllRanges(),u.focus(),u.select();let h=!1;const d=()=>{h=!0,u.remove()},g=e=>{if(h)return!0;if(!e||u.value===t)return d(),r&&r(),!0;let i;try{i=n(u.value)}catch(e){return u.setAttribute("aria-invalid","true"),u.title=e.message,!1}return d(),s(i,u.value),!0};return u.addEventListener("keydown",e=>{e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),g(!0)),"Escape"===e.key&&(e.preventDefault(),g(!1))}),u.addEventListener("input",()=>{c(),u.removeAttribute("aria-invalid"),u.removeAttribute("title")}),u.addEventListener("blur",()=>{g(!0)||g(!1)}),u}export{e as E,f as V,s as b,h as c,u as i,n,m as o,g as r,o as s,i as u,d as v};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/* Inline Math 0.2.0 — MIT licence; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate with an import map */
|
|
2
|
-
import{calculateBlock as t}from"mathzetta/calculate";import{t as a,a as o}from"./draw-Bev17BJJ.js";function r(a,r={}){return o(a,{...r,blocks:r.blocks??t})}function s(o,r={}){return a(o,{...r,blocks:r.blocks??t})}export{s as a,r as t};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/* Inline Math 0.2.0 — MIT licence; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
-
import{c as o}from"./calculate-Cz87Lt0N.js";import{e as s,f as t}from"./lite-3Fb-OHbt.js";function c(s,c={}){return t(s,{...c,blocks:c.blocks??o})}function r(t,c={}){return s(t,{...c,blocks:c.blocks??o})}export{r as a,c as t};
|