@nice2dev/ui-math 1.1.10 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -6
- package/dist/index.cjs +5 -5
- package/dist/index.d.ts +28 -4
- package/dist/index.mjs +1218 -1120
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
5
|
-
import { NiceAppShell, NiceIcon } from "@nice2dev/ui";
|
|
6
|
-
import { NiceTutorialButton, resolveTutorial, resolveCssColor, NiceIcon as
|
|
7
|
-
import
|
|
8
|
-
const
|
|
1
|
+
var pe = Object.defineProperty;
|
|
2
|
+
var ue = (e, t, r) => t in e ? pe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var T = (e, t, r) => ue(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { jsx as d, jsxs as v, Fragment as oe } from "react/jsx-runtime";
|
|
5
|
+
import { NiceAppShell as ge, NiceIcon as X } from "@nice2dev/ui";
|
|
6
|
+
import { NiceTutorialButton as xe, resolveTutorial as me, resolveCssColor as I, NiceIcon as G } from "@nice2dev/ui-core";
|
|
7
|
+
import ye, { useMemo as he, useContext as j, createContext as F, useState as P, useRef as U, useCallback as R, useEffect as V } from "react";
|
|
8
|
+
const J = {
|
|
9
9
|
en: {
|
|
10
10
|
"calculator.matrixA": "Matrix A",
|
|
11
11
|
"calculator.matrixB": "Matrix B",
|
|
@@ -21,7 +21,12 @@ const translations = {
|
|
|
21
21
|
"editor.clear": "Clear",
|
|
22
22
|
"editor.recognize": "Recognize",
|
|
23
23
|
"editor.recognizing": "Recognizing...",
|
|
24
|
-
"editor.
|
|
24
|
+
"editor.latexInput": "LaTeX Input",
|
|
25
|
+
"editor.handwriting": "Handwriting",
|
|
26
|
+
"editor.handwritingNote": "Draw your equation above. Handwriting recognition requires external API integration.",
|
|
27
|
+
"editor.templates": "Templates",
|
|
28
|
+
"editor.copyLatex": "Copy LaTeX",
|
|
29
|
+
"plotter.close": "Close"
|
|
25
30
|
},
|
|
26
31
|
pl: {
|
|
27
32
|
"calculator.matrixA": "Macierz A",
|
|
@@ -38,7 +43,12 @@ const translations = {
|
|
|
38
43
|
"editor.clear": "Wyczyść",
|
|
39
44
|
"editor.recognize": "Rozpoznaj",
|
|
40
45
|
"editor.recognizing": "Rozpoznawanie...",
|
|
41
|
-
"editor.
|
|
46
|
+
"editor.latexInput": "Wpis LaTeX",
|
|
47
|
+
"editor.handwriting": "Pismo odręczne",
|
|
48
|
+
"editor.handwritingNote": "Narysuj równanie powyżej. Rozpoznawanie pisma wymaga zewnętrznej integracji API.",
|
|
49
|
+
"editor.templates": "Szablony",
|
|
50
|
+
"editor.copyLatex": "Kopiuj LaTeX",
|
|
51
|
+
"plotter.close": "Zamknij"
|
|
42
52
|
},
|
|
43
53
|
de: {
|
|
44
54
|
"calculator.matrixA": "Matrix A",
|
|
@@ -55,7 +65,12 @@ const translations = {
|
|
|
55
65
|
"editor.clear": "Löschen",
|
|
56
66
|
"editor.recognize": "Erkennen",
|
|
57
67
|
"editor.recognizing": "Erkennung läuft...",
|
|
58
|
-
"editor.
|
|
68
|
+
"editor.latexInput": "LaTeX-Eingabe",
|
|
69
|
+
"editor.handwriting": "Handschrift",
|
|
70
|
+
"editor.handwritingNote": "Zeichnen Sie Ihre Gleichung oben. Die Handschrifterkennung erfordert eine externe API-Integration.",
|
|
71
|
+
"editor.templates": "Vorlagen",
|
|
72
|
+
"editor.copyLatex": "LaTeX kopieren",
|
|
73
|
+
"plotter.close": "Schließen"
|
|
59
74
|
},
|
|
60
75
|
fr: {
|
|
61
76
|
"calculator.matrixA": "Matrice A",
|
|
@@ -72,7 +87,12 @@ const translations = {
|
|
|
72
87
|
"editor.clear": "Effacer",
|
|
73
88
|
"editor.recognize": "Reconnaître",
|
|
74
89
|
"editor.recognizing": "Reconnaissance...",
|
|
75
|
-
"editor.
|
|
90
|
+
"editor.latexInput": "Saisie LaTeX",
|
|
91
|
+
"editor.handwriting": "Écriture manuscrite",
|
|
92
|
+
"editor.handwritingNote": "Dessinez votre équation ci-dessus. La reconnaissance d'écriture nécessite une intégration API externe.",
|
|
93
|
+
"editor.templates": "Modèles",
|
|
94
|
+
"editor.copyLatex": "Copier le LaTeX",
|
|
95
|
+
"plotter.close": "Fermer"
|
|
76
96
|
},
|
|
77
97
|
es: {
|
|
78
98
|
"calculator.matrixA": "Matriz A",
|
|
@@ -89,7 +109,12 @@ const translations = {
|
|
|
89
109
|
"editor.clear": "Borrar",
|
|
90
110
|
"editor.recognize": "Reconocer",
|
|
91
111
|
"editor.recognizing": "Reconociendo...",
|
|
92
|
-
"editor.
|
|
112
|
+
"editor.latexInput": "Entrada LaTeX",
|
|
113
|
+
"editor.handwriting": "Escritura a mano",
|
|
114
|
+
"editor.handwritingNote": "Dibuja tu ecuación arriba. El reconocimiento de escritura requiere integración con una API externa.",
|
|
115
|
+
"editor.templates": "Plantillas",
|
|
116
|
+
"editor.copyLatex": "Copiar LaTeX",
|
|
117
|
+
"plotter.close": "Cerrar"
|
|
93
118
|
},
|
|
94
119
|
it: {
|
|
95
120
|
"calculator.matrixA": "Matrice A",
|
|
@@ -106,7 +131,12 @@ const translations = {
|
|
|
106
131
|
"editor.clear": "Cancella",
|
|
107
132
|
"editor.recognize": "Riconosci",
|
|
108
133
|
"editor.recognizing": "Riconoscimento...",
|
|
109
|
-
"editor.
|
|
134
|
+
"editor.latexInput": "Input LaTeX",
|
|
135
|
+
"editor.handwriting": "Scrittura a mano",
|
|
136
|
+
"editor.handwritingNote": "Disegna la tua equazione qui sopra. Il riconoscimento della scrittura richiede un’integrazione API esterna.",
|
|
137
|
+
"editor.templates": "Modelli",
|
|
138
|
+
"editor.copyLatex": "Copia LaTeX",
|
|
139
|
+
"plotter.close": "Chiudi"
|
|
110
140
|
},
|
|
111
141
|
pt: {
|
|
112
142
|
"calculator.matrixA": "Matriz A",
|
|
@@ -123,7 +153,12 @@ const translations = {
|
|
|
123
153
|
"editor.clear": "Limpar",
|
|
124
154
|
"editor.recognize": "Reconhecer",
|
|
125
155
|
"editor.recognizing": "A reconhecer...",
|
|
126
|
-
"editor.
|
|
156
|
+
"editor.latexInput": "Entrada LaTeX",
|
|
157
|
+
"editor.handwriting": "Escrita à mão",
|
|
158
|
+
"editor.handwritingNote": "Desenhe a sua equação acima. O reconhecimento de escrita requer integração com uma API externa.",
|
|
159
|
+
"editor.templates": "Modelos",
|
|
160
|
+
"editor.copyLatex": "Copiar LaTeX",
|
|
161
|
+
"plotter.close": "Fechar"
|
|
127
162
|
},
|
|
128
163
|
cs: {
|
|
129
164
|
"calculator.matrixA": "Matice A",
|
|
@@ -140,7 +175,12 @@ const translations = {
|
|
|
140
175
|
"editor.clear": "Vymazat",
|
|
141
176
|
"editor.recognize": "Rozpoznat",
|
|
142
177
|
"editor.recognizing": "Rozpoznávání...",
|
|
143
|
-
"editor.
|
|
178
|
+
"editor.latexInput": "Zadání LaTeX",
|
|
179
|
+
"editor.handwriting": "Rukopis",
|
|
180
|
+
"editor.handwritingNote": "Nakreslete svou rovnici výše. Rozpoznávání rukopisu vyžaduje externí integraci API.",
|
|
181
|
+
"editor.templates": "Šablony",
|
|
182
|
+
"editor.copyLatex": "Kopírovat LaTeX",
|
|
183
|
+
"plotter.close": "Zavřít"
|
|
144
184
|
},
|
|
145
185
|
uk: {
|
|
146
186
|
"calculator.matrixA": "Матриця A",
|
|
@@ -157,23 +197,28 @@ const translations = {
|
|
|
157
197
|
"editor.clear": "Очистити",
|
|
158
198
|
"editor.recognize": "Розпізнати",
|
|
159
199
|
"editor.recognizing": "Розпізнавання...",
|
|
160
|
-
"editor.
|
|
161
|
-
|
|
162
|
-
|
|
200
|
+
"editor.latexInput": "Введення LaTeX",
|
|
201
|
+
"editor.handwriting": "Рукопис",
|
|
202
|
+
"editor.handwritingNote": "Намалюйте своє рівняння вище. Розпізнавання рукопису потребує зовнішньої інтеграції з API.",
|
|
203
|
+
"editor.templates": "Шаблони",
|
|
204
|
+
"editor.copyLatex": "Копіювати LaTeX",
|
|
205
|
+
"plotter.close": "Закрити"
|
|
206
|
+
}
|
|
207
|
+
}, ae = /* @__PURE__ */ F({
|
|
163
208
|
locale: "en",
|
|
164
209
|
t: (e, t) => t ?? e
|
|
165
210
|
});
|
|
166
|
-
function
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
return { locale: e, t: (i,
|
|
211
|
+
function Qe({ locale: e = "en", overrides: t, children: r }) {
|
|
212
|
+
const o = he(() => {
|
|
213
|
+
const a = { ...J.en, ...J[e], ...t };
|
|
214
|
+
return { locale: e, t: (i, c) => a[i] ?? c ?? i };
|
|
170
215
|
}, [e, t]);
|
|
171
|
-
return
|
|
216
|
+
return ye.createElement(ae.Provider, { value: o }, r);
|
|
172
217
|
}
|
|
173
|
-
function
|
|
174
|
-
return
|
|
218
|
+
function L() {
|
|
219
|
+
return j(ae);
|
|
175
220
|
}
|
|
176
|
-
const
|
|
221
|
+
const fe = [
|
|
177
222
|
{
|
|
178
223
|
target: ".nice-math-editor",
|
|
179
224
|
titleKey: "tutorial.mathEditor.intro.title",
|
|
@@ -182,7 +227,7 @@ const MATH_EDITOR_TOUR = [
|
|
|
182
227
|
content: "Write equations as LaTeX or insert symbols from the palette; switch to handwriting input, and preview the rendered formula live.",
|
|
183
228
|
placement: "auto"
|
|
184
229
|
}
|
|
185
|
-
],
|
|
230
|
+
], be = [
|
|
186
231
|
// Greek lowercase
|
|
187
232
|
{ name: "alpha", latex: "\\alpha", category: "greek", preview: "α" },
|
|
188
233
|
{ name: "beta", latex: "\\beta", category: "greek", preview: "β" },
|
|
@@ -359,10 +404,10 @@ const MATH_EDITOR_TOUR = [
|
|
|
359
404
|
preview: "{ }"
|
|
360
405
|
}
|
|
361
406
|
];
|
|
362
|
-
function
|
|
363
|
-
return
|
|
407
|
+
function ve(e) {
|
|
408
|
+
return be.filter((t) => t.category === e);
|
|
364
409
|
}
|
|
365
|
-
const
|
|
410
|
+
const we = [
|
|
366
411
|
// Basic
|
|
367
412
|
{ name: "Fraction", latex: "\\frac{a}{b}", category: "basic" },
|
|
368
413
|
{ name: "Square root", latex: "\\sqrt{x}", category: "basic" },
|
|
@@ -421,11 +466,11 @@ const EQUATION_TEMPLATES = [
|
|
|
421
466
|
category: "physics"
|
|
422
467
|
}
|
|
423
468
|
];
|
|
424
|
-
class
|
|
469
|
+
class ke {
|
|
425
470
|
constructor(t = {}) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
471
|
+
T(this, "equations", /* @__PURE__ */ new Map());
|
|
472
|
+
T(this, "config");
|
|
473
|
+
T(this, "nextNumber");
|
|
429
474
|
this.config = {
|
|
430
475
|
enableNumbering: t.enableNumbering ?? !0,
|
|
431
476
|
startNumber: t.startNumber ?? 1,
|
|
@@ -434,7 +479,7 @@ class MathEditorService {
|
|
|
434
479
|
}
|
|
435
480
|
/** Create new equation */
|
|
436
481
|
createEquation(t, r) {
|
|
437
|
-
const
|
|
482
|
+
const o = {
|
|
438
483
|
id: this.generateId(),
|
|
439
484
|
latex: t,
|
|
440
485
|
label: r,
|
|
@@ -442,17 +487,17 @@ class MathEditorService {
|
|
|
442
487
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
443
488
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
444
489
|
};
|
|
445
|
-
return this.equations.set(
|
|
490
|
+
return this.equations.set(o.id, o), o;
|
|
446
491
|
}
|
|
447
492
|
/** Update equation */
|
|
448
|
-
updateEquation(t, r,
|
|
449
|
-
const
|
|
450
|
-
if (!
|
|
493
|
+
updateEquation(t, r, o) {
|
|
494
|
+
const a = this.equations.get(t);
|
|
495
|
+
if (!a)
|
|
451
496
|
throw new Error(`Equation not found: ${t}`);
|
|
452
497
|
const n = {
|
|
453
|
-
...
|
|
498
|
+
...a,
|
|
454
499
|
latex: r,
|
|
455
|
-
label:
|
|
500
|
+
label: o ?? a.label,
|
|
456
501
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
457
502
|
};
|
|
458
503
|
return this.equations.set(t, n), n;
|
|
@@ -488,14 +533,14 @@ class MathEditorService {
|
|
|
488
533
|
}
|
|
489
534
|
/** Parse LaTeX and extract equations */
|
|
490
535
|
parseLatex(t) {
|
|
491
|
-
const r = [],
|
|
492
|
-
let
|
|
493
|
-
for (; (
|
|
494
|
-
r.push(this.createEquation(
|
|
536
|
+
const r = [], o = /\\\[([\s\S]*?)\\\]/g;
|
|
537
|
+
let a;
|
|
538
|
+
for (; (a = o.exec(t)) !== null; )
|
|
539
|
+
r.push(this.createEquation(a[1].trim()));
|
|
495
540
|
const n = /\\begin\{equation\}([\s\S]*?)\\end\{equation\}/g;
|
|
496
|
-
for (; (
|
|
497
|
-
const i =
|
|
498
|
-
r.push(this.createEquation(
|
|
541
|
+
for (; (a = n.exec(t)) !== null; ) {
|
|
542
|
+
const i = a[1].match(/\\label\{([^}]+)\}/), c = a[1].replace(/\\label\{[^}]+\}/, "").trim();
|
|
543
|
+
r.push(this.createEquation(c, i == null ? void 0 : i[1]));
|
|
499
544
|
}
|
|
500
545
|
return r;
|
|
501
546
|
}
|
|
@@ -503,24 +548,24 @@ class MathEditorService {
|
|
|
503
548
|
return Date.now().toString(36) + Math.random().toString(36).substring(2, 8);
|
|
504
549
|
}
|
|
505
550
|
}
|
|
506
|
-
function
|
|
507
|
-
return new
|
|
551
|
+
function Je(e) {
|
|
552
|
+
return new ke(e);
|
|
508
553
|
}
|
|
509
|
-
async function
|
|
554
|
+
async function Ce(e) {
|
|
510
555
|
return await new Promise((r) => setTimeout(r, 500)), {
|
|
511
|
-
latex: e.reduce((r,
|
|
556
|
+
latex: e.reduce((r, o) => r + o.points.length, 0) > 50 ? "\\sqrt{x^2 + y^2}" : "x",
|
|
512
557
|
confidence: 0.85,
|
|
513
558
|
alternatives: ["x", "X", "\\times"]
|
|
514
559
|
};
|
|
515
560
|
}
|
|
516
|
-
const
|
|
517
|
-
function
|
|
518
|
-
const e =
|
|
561
|
+
const ne = /* @__PURE__ */ F(null);
|
|
562
|
+
function W() {
|
|
563
|
+
const e = j(ne);
|
|
519
564
|
if (!e)
|
|
520
565
|
throw new Error("useMathEditor must be used within MathEditorProvider");
|
|
521
566
|
return e;
|
|
522
567
|
}
|
|
523
|
-
const
|
|
568
|
+
const A = {
|
|
524
569
|
toolbar: {
|
|
525
570
|
display: "flex",
|
|
526
571
|
gap: "8px",
|
|
@@ -603,108 +648,110 @@ const styles$3 = {
|
|
|
603
648
|
cursor: "crosshair"
|
|
604
649
|
}
|
|
605
650
|
};
|
|
606
|
-
function
|
|
651
|
+
function et({
|
|
607
652
|
service: e,
|
|
608
653
|
initialLatex: t = "",
|
|
609
654
|
onChange: r,
|
|
610
|
-
className:
|
|
611
|
-
style:
|
|
655
|
+
className: o,
|
|
656
|
+
style: a,
|
|
612
657
|
tutorial: n
|
|
613
658
|
}) {
|
|
614
|
-
const { t: i } =
|
|
615
|
-
(
|
|
616
|
-
|
|
659
|
+
const { t: i } = L(), [c, u] = P(t), [s, p] = P("input"), m = U(null), y = R(
|
|
660
|
+
(b) => {
|
|
661
|
+
u(b), r == null || r(b);
|
|
617
662
|
},
|
|
618
663
|
[r]
|
|
619
|
-
),
|
|
620
|
-
(
|
|
621
|
-
const
|
|
622
|
-
if (!
|
|
623
|
-
y(
|
|
664
|
+
), f = R(
|
|
665
|
+
(b) => {
|
|
666
|
+
const l = m.current;
|
|
667
|
+
if (!l) {
|
|
668
|
+
y(c + b);
|
|
624
669
|
return;
|
|
625
670
|
}
|
|
626
|
-
const
|
|
627
|
-
y(
|
|
628
|
-
|
|
671
|
+
const g = l.selectionStart, w = l.selectionEnd, M = c.slice(0, g) + b + c.slice(w);
|
|
672
|
+
y(M), setTimeout(() => {
|
|
673
|
+
l.focus(), l.selectionStart = l.selectionEnd = g + b.length;
|
|
629
674
|
}, 0);
|
|
630
675
|
},
|
|
631
|
-
[
|
|
632
|
-
),
|
|
633
|
-
(
|
|
634
|
-
|
|
676
|
+
[c, y]
|
|
677
|
+
), C = R(
|
|
678
|
+
(b) => {
|
|
679
|
+
f(b.latex);
|
|
635
680
|
},
|
|
636
|
-
[
|
|
637
|
-
),
|
|
681
|
+
[f]
|
|
682
|
+
), x = {
|
|
638
683
|
service: e,
|
|
639
|
-
latex:
|
|
684
|
+
latex: c,
|
|
640
685
|
setLatex: y,
|
|
641
|
-
insertSymbol:
|
|
642
|
-
insertTemplate:
|
|
686
|
+
insertSymbol: f,
|
|
687
|
+
insertTemplate: C,
|
|
643
688
|
mode: s,
|
|
644
|
-
setMode:
|
|
689
|
+
setMode: p
|
|
645
690
|
};
|
|
646
|
-
return /* @__PURE__ */
|
|
647
|
-
|
|
691
|
+
return /* @__PURE__ */ d(ne.Provider, { value: x, children: /* @__PURE__ */ v(
|
|
692
|
+
ge,
|
|
648
693
|
{
|
|
649
694
|
flush: !0,
|
|
650
|
-
className: `nice-math-editor ${
|
|
651
|
-
style: { position: "relative", ...
|
|
652
|
-
toolbar: /* @__PURE__ */
|
|
653
|
-
sidebar: /* @__PURE__ */
|
|
695
|
+
className: `nice-math-editor ${o ?? ""}`,
|
|
696
|
+
style: { position: "relative", ...a },
|
|
697
|
+
toolbar: /* @__PURE__ */ d(Pe, {}),
|
|
698
|
+
sidebar: /* @__PURE__ */ d(Me, {}),
|
|
654
699
|
children: [
|
|
655
|
-
/* @__PURE__ */
|
|
656
|
-
/* @__PURE__ */
|
|
657
|
-
/* @__PURE__ */
|
|
700
|
+
/* @__PURE__ */ d("span", { style: { position: "absolute", top: 6, right: 6, zIndex: 30 }, children: /* @__PURE__ */ d(xe, { steps: me(n, fe) }) }),
|
|
701
|
+
/* @__PURE__ */ d("div", { style: A.editor, children: s === "input" ? /* @__PURE__ */ v(oe, { children: [
|
|
702
|
+
/* @__PURE__ */ d(
|
|
658
703
|
"textarea",
|
|
659
704
|
{
|
|
660
|
-
ref:
|
|
661
|
-
value:
|
|
662
|
-
onChange: (
|
|
705
|
+
ref: m,
|
|
706
|
+
value: c,
|
|
707
|
+
onChange: (b) => y(b.target.value),
|
|
663
708
|
placeholder: i("editor.latexPlaceholder", "Enter LaTeX equation..."),
|
|
664
|
-
style:
|
|
709
|
+
style: A.input
|
|
665
710
|
}
|
|
666
711
|
),
|
|
667
|
-
/* @__PURE__ */
|
|
668
|
-
] }) : /* @__PURE__ */
|
|
712
|
+
/* @__PURE__ */ d(Se, { latex: c })
|
|
713
|
+
] }) : /* @__PURE__ */ d(Be, {}) })
|
|
669
714
|
]
|
|
670
715
|
}
|
|
671
716
|
) });
|
|
672
717
|
}
|
|
673
|
-
function
|
|
674
|
-
const {
|
|
675
|
-
return /* @__PURE__ */
|
|
676
|
-
/* @__PURE__ */
|
|
718
|
+
function Pe() {
|
|
719
|
+
const { t: e } = L(), { mode: t, setMode: r, latex: o, insertTemplate: a } = W(), [n, i] = P(!1);
|
|
720
|
+
return /* @__PURE__ */ v("div", { style: A.toolbar, children: [
|
|
721
|
+
/* @__PURE__ */ v(
|
|
677
722
|
"button",
|
|
678
723
|
{
|
|
679
|
-
onClick: () =>
|
|
724
|
+
onClick: () => r("input"),
|
|
680
725
|
style: {
|
|
681
|
-
...
|
|
682
|
-
backgroundColor:
|
|
726
|
+
...A.button,
|
|
727
|
+
backgroundColor: t === "input" ? "var(--nice-primary-hover, #1976d2)" : "var(--nice-bg-tertiary, #9e9e9e)",
|
|
683
728
|
// the inactive state sits on a theme surface: theme text, not the button's white
|
|
684
|
-
color:
|
|
729
|
+
color: t === "input" ? "var(--nice-color-white, #fff)" : "var(--nice-text-primary, #fff)"
|
|
685
730
|
},
|
|
686
731
|
children: [
|
|
687
|
-
/* @__PURE__ */
|
|
688
|
-
"
|
|
732
|
+
/* @__PURE__ */ d(X, { name: "keyboard", size: 14 }),
|
|
733
|
+
" ",
|
|
734
|
+
e("editor.latexInput", "LaTeX Input")
|
|
689
735
|
]
|
|
690
736
|
}
|
|
691
737
|
),
|
|
692
|
-
/* @__PURE__ */
|
|
738
|
+
/* @__PURE__ */ v(
|
|
693
739
|
"button",
|
|
694
740
|
{
|
|
695
|
-
onClick: () =>
|
|
741
|
+
onClick: () => r("handwriting"),
|
|
696
742
|
style: {
|
|
697
|
-
...
|
|
698
|
-
backgroundColor:
|
|
699
|
-
color:
|
|
743
|
+
...A.button,
|
|
744
|
+
backgroundColor: t === "handwriting" ? "var(--nice-primary-hover, #1976d2)" : "var(--nice-bg-tertiary, #9e9e9e)",
|
|
745
|
+
color: t === "handwriting" ? "var(--nice-color-white, #fff)" : "var(--nice-text-primary, #fff)"
|
|
700
746
|
},
|
|
701
747
|
children: [
|
|
702
|
-
/* @__PURE__ */
|
|
703
|
-
"
|
|
748
|
+
/* @__PURE__ */ d(X, { name: "pen", size: 14 }),
|
|
749
|
+
" ",
|
|
750
|
+
e("editor.handwriting", "Handwriting")
|
|
704
751
|
]
|
|
705
752
|
}
|
|
706
753
|
),
|
|
707
|
-
/* @__PURE__ */
|
|
754
|
+
/* @__PURE__ */ d(
|
|
708
755
|
"div",
|
|
709
756
|
{
|
|
710
757
|
style: {
|
|
@@ -714,13 +761,15 @@ function Toolbar$1() {
|
|
|
714
761
|
}
|
|
715
762
|
}
|
|
716
763
|
),
|
|
717
|
-
/* @__PURE__ */
|
|
718
|
-
/* @__PURE__ */
|
|
719
|
-
/* @__PURE__ */
|
|
720
|
-
"
|
|
721
|
-
|
|
764
|
+
/* @__PURE__ */ v("div", { style: { position: "relative" }, children: [
|
|
765
|
+
/* @__PURE__ */ v("button", { onClick: () => i(!n), style: A.button, children: [
|
|
766
|
+
/* @__PURE__ */ d(X, { name: "ruler", size: 14 }),
|
|
767
|
+
" ",
|
|
768
|
+
e("editor.templates", "Templates"),
|
|
769
|
+
" ",
|
|
770
|
+
/* @__PURE__ */ d(X, { name: "chevron-down", size: 12 })
|
|
722
771
|
] }),
|
|
723
|
-
|
|
772
|
+
n && /* @__PURE__ */ d(
|
|
724
773
|
"div",
|
|
725
774
|
{
|
|
726
775
|
style: {
|
|
@@ -737,24 +786,24 @@ function Toolbar$1() {
|
|
|
737
786
|
overflow: "auto"
|
|
738
787
|
},
|
|
739
788
|
children: ["basic", "calculus", "algebra", "geometry", "statistics", "physics"].map(
|
|
740
|
-
(
|
|
741
|
-
/* @__PURE__ */
|
|
742
|
-
|
|
789
|
+
(c) => /* @__PURE__ */ v("div", { children: [
|
|
790
|
+
/* @__PURE__ */ d("div", { style: A.categoryHeader, children: c }),
|
|
791
|
+
we.filter((u) => u.category === c).map((u) => /* @__PURE__ */ v(
|
|
743
792
|
"div",
|
|
744
793
|
{
|
|
745
794
|
onClick: () => {
|
|
746
|
-
a(
|
|
795
|
+
a(u), i(!1);
|
|
747
796
|
},
|
|
748
797
|
style: {
|
|
749
798
|
padding: "8px 12px",
|
|
750
799
|
cursor: "pointer",
|
|
751
800
|
borderBottom: "1px solid var(--nice-border, #eee)"
|
|
752
801
|
},
|
|
753
|
-
onMouseOver: (
|
|
754
|
-
onMouseOut: (
|
|
802
|
+
onMouseOver: (s) => s.target.style.backgroundColor = "var(--nice-bg-secondary, #f5f5f5)",
|
|
803
|
+
onMouseOut: (s) => s.target.style.backgroundColor = "transparent",
|
|
755
804
|
children: [
|
|
756
|
-
/* @__PURE__ */
|
|
757
|
-
/* @__PURE__ */
|
|
805
|
+
/* @__PURE__ */ d("div", { style: { fontWeight: 500 }, children: u.name }),
|
|
806
|
+
/* @__PURE__ */ v(
|
|
758
807
|
"div",
|
|
759
808
|
{
|
|
760
809
|
style: {
|
|
@@ -763,36 +812,37 @@ function Toolbar$1() {
|
|
|
763
812
|
fontFamily: "monospace"
|
|
764
813
|
},
|
|
765
814
|
children: [
|
|
766
|
-
|
|
767
|
-
|
|
815
|
+
u.latex.substring(0, 40),
|
|
816
|
+
u.latex.length > 40 ? "..." : ""
|
|
768
817
|
]
|
|
769
818
|
}
|
|
770
819
|
)
|
|
771
820
|
]
|
|
772
821
|
},
|
|
773
|
-
|
|
822
|
+
u.name
|
|
774
823
|
))
|
|
775
|
-
] },
|
|
824
|
+
] }, c)
|
|
776
825
|
)
|
|
777
826
|
}
|
|
778
827
|
)
|
|
779
828
|
] }),
|
|
780
|
-
/* @__PURE__ */
|
|
781
|
-
/* @__PURE__ */
|
|
829
|
+
/* @__PURE__ */ d("div", { style: { flex: 1 } }),
|
|
830
|
+
/* @__PURE__ */ v(
|
|
782
831
|
"button",
|
|
783
832
|
{
|
|
784
|
-
onClick: () => navigator.clipboard.writeText(
|
|
785
|
-
style: { ...
|
|
833
|
+
onClick: () => navigator.clipboard.writeText(o),
|
|
834
|
+
style: { ...A.button, backgroundColor: "var(--nice-success, #4caf50)" },
|
|
786
835
|
children: [
|
|
787
|
-
/* @__PURE__ */
|
|
788
|
-
"
|
|
836
|
+
/* @__PURE__ */ d(X, { name: "copy", size: 14 }),
|
|
837
|
+
" ",
|
|
838
|
+
e("editor.copyLatex", "Copy LaTeX")
|
|
789
839
|
]
|
|
790
840
|
}
|
|
791
841
|
)
|
|
792
842
|
] });
|
|
793
843
|
}
|
|
794
|
-
function
|
|
795
|
-
const { insertSymbol: e } =
|
|
844
|
+
function Me() {
|
|
845
|
+
const { insertSymbol: e } = W(), [t, r] = P("greek"), o = [
|
|
796
846
|
"greek",
|
|
797
847
|
"operators",
|
|
798
848
|
"relations",
|
|
@@ -804,9 +854,9 @@ function SymbolPalette() {
|
|
|
804
854
|
"logic",
|
|
805
855
|
"calculus",
|
|
806
856
|
"matrices"
|
|
807
|
-
],
|
|
808
|
-
return /* @__PURE__ */
|
|
809
|
-
/* @__PURE__ */
|
|
857
|
+
], a = ve(t);
|
|
858
|
+
return /* @__PURE__ */ v("div", { style: A.sidebar, children: [
|
|
859
|
+
/* @__PURE__ */ d("div", { style: { display: "flex", flexWrap: "wrap", padding: "8px", gap: "4px" }, children: o.map((n) => /* @__PURE__ */ d(
|
|
810
860
|
"button",
|
|
811
861
|
{
|
|
812
862
|
onClick: () => r(n),
|
|
@@ -816,18 +866,18 @@ function SymbolPalette() {
|
|
|
816
866
|
border: "1px solid var(--nice-border, #ddd)",
|
|
817
867
|
borderRadius: "4px",
|
|
818
868
|
backgroundColor: t === n ? "var(--nice-primary-hover, #1976d2)" : "var(--nice-bg, #fff)",
|
|
819
|
-
color: t === n ? "var(--nice-
|
|
869
|
+
color: t === n ? "var(--nice-color-white, #fff)" : "var(--nice-text, #333)",
|
|
820
870
|
cursor: "pointer"
|
|
821
871
|
},
|
|
822
872
|
children: n
|
|
823
873
|
},
|
|
824
874
|
n
|
|
825
875
|
)) }),
|
|
826
|
-
/* @__PURE__ */
|
|
876
|
+
/* @__PURE__ */ d("div", { style: A.symbolGrid, children: a.map((n) => /* @__PURE__ */ d(
|
|
827
877
|
"button",
|
|
828
878
|
{
|
|
829
879
|
onClick: () => e(n.latex),
|
|
830
|
-
style:
|
|
880
|
+
style: A.symbolButton,
|
|
831
881
|
title: `${n.name}: ${n.latex}`,
|
|
832
882
|
children: n.preview || n.latex
|
|
833
883
|
},
|
|
@@ -835,122 +885,122 @@ function SymbolPalette() {
|
|
|
835
885
|
)) })
|
|
836
886
|
] });
|
|
837
887
|
}
|
|
838
|
-
function
|
|
839
|
-
return /* @__PURE__ */
|
|
840
|
-
/* @__PURE__ */
|
|
888
|
+
function Se({ latex: e }) {
|
|
889
|
+
return /* @__PURE__ */ v("div", { style: A.preview, children: [
|
|
890
|
+
/* @__PURE__ */ d(
|
|
841
891
|
"div",
|
|
842
892
|
{
|
|
843
893
|
style: { fontSize: "12px", color: "var(--nice-text-secondary, #666)", marginBottom: "8px" },
|
|
844
894
|
children: "Preview (requires KaTeX/MathJax integration):"
|
|
845
895
|
}
|
|
846
896
|
),
|
|
847
|
-
/* @__PURE__ */
|
|
897
|
+
/* @__PURE__ */ d("code", { style: { fontSize: "16px" }, children: e || "(empty)" })
|
|
848
898
|
] });
|
|
849
899
|
}
|
|
850
|
-
function
|
|
851
|
-
const { t: e } =
|
|
852
|
-
const
|
|
853
|
-
if (!
|
|
900
|
+
function Be() {
|
|
901
|
+
const { t: e } = L(), { setLatex: t, setMode: r } = W(), o = U(null), [a, n] = P([]), [i, c] = P([]), [u, s] = P(!1), [p, m] = P(!1), y = (l) => {
|
|
902
|
+
const g = o.current;
|
|
903
|
+
if (!g)
|
|
854
904
|
return;
|
|
855
905
|
s(!0);
|
|
856
|
-
const
|
|
857
|
-
|
|
906
|
+
const w = g.getBoundingClientRect();
|
|
907
|
+
c([
|
|
858
908
|
{
|
|
859
|
-
x:
|
|
860
|
-
y:
|
|
861
|
-
pressure:
|
|
909
|
+
x: l.clientX - w.left,
|
|
910
|
+
y: l.clientY - w.top,
|
|
911
|
+
pressure: l.pressure,
|
|
862
912
|
timestamp: Date.now()
|
|
863
913
|
}
|
|
864
914
|
]);
|
|
865
|
-
},
|
|
866
|
-
if (!
|
|
915
|
+
}, f = (l) => {
|
|
916
|
+
if (!u)
|
|
867
917
|
return;
|
|
868
|
-
const
|
|
869
|
-
if (!
|
|
918
|
+
const g = o.current, w = g == null ? void 0 : g.getContext("2d");
|
|
919
|
+
if (!g || !w)
|
|
870
920
|
return;
|
|
871
|
-
const
|
|
872
|
-
x:
|
|
873
|
-
y:
|
|
874
|
-
pressure:
|
|
921
|
+
const M = g.getBoundingClientRect(), h = {
|
|
922
|
+
x: l.clientX - M.left,
|
|
923
|
+
y: l.clientY - M.top,
|
|
924
|
+
pressure: l.pressure,
|
|
875
925
|
timestamp: Date.now()
|
|
876
926
|
};
|
|
877
|
-
if (
|
|
878
|
-
const
|
|
879
|
-
|
|
927
|
+
if (c((k) => [...k, h]), i.length > 0) {
|
|
928
|
+
const k = i[i.length - 1];
|
|
929
|
+
w.beginPath(), w.moveTo(k.x, k.y), w.lineTo(h.x, h.y), w.strokeStyle = I("var(--nice-text, #000)", w.canvas), w.lineWidth = 2, w.lineCap = "round", w.stroke();
|
|
880
930
|
}
|
|
881
|
-
},
|
|
882
|
-
if (
|
|
931
|
+
}, C = () => {
|
|
932
|
+
if (u) {
|
|
883
933
|
if (s(!1), i.length > 1) {
|
|
884
|
-
const
|
|
934
|
+
const l = {
|
|
885
935
|
id: Date.now().toString(),
|
|
886
936
|
points: [...i]
|
|
887
937
|
};
|
|
888
|
-
n((
|
|
938
|
+
n((g) => [...g, l]);
|
|
889
939
|
}
|
|
890
|
-
|
|
940
|
+
c([]);
|
|
891
941
|
}
|
|
892
|
-
},
|
|
893
|
-
const
|
|
894
|
-
|
|
895
|
-
},
|
|
896
|
-
if (
|
|
897
|
-
|
|
942
|
+
}, x = () => {
|
|
943
|
+
const l = o.current, g = l == null ? void 0 : l.getContext("2d");
|
|
944
|
+
g && l && g.clearRect(0, 0, l.width, l.height), n([]);
|
|
945
|
+
}, b = async () => {
|
|
946
|
+
if (a.length !== 0) {
|
|
947
|
+
m(!0);
|
|
898
948
|
try {
|
|
899
|
-
const
|
|
900
|
-
t(
|
|
949
|
+
const l = await Ce(a);
|
|
950
|
+
t(l.latex), r("input");
|
|
901
951
|
} finally {
|
|
902
|
-
|
|
952
|
+
m(!1);
|
|
903
953
|
}
|
|
904
954
|
}
|
|
905
955
|
};
|
|
906
|
-
return
|
|
907
|
-
const
|
|
908
|
-
|
|
909
|
-
}, []), /* @__PURE__ */
|
|
910
|
-
/* @__PURE__ */
|
|
956
|
+
return V(() => {
|
|
957
|
+
const l = o.current;
|
|
958
|
+
l && (l.width = l.offsetWidth, l.height = 200);
|
|
959
|
+
}, []), /* @__PURE__ */ v("div", { children: [
|
|
960
|
+
/* @__PURE__ */ d(
|
|
911
961
|
"canvas",
|
|
912
962
|
{
|
|
913
|
-
ref:
|
|
914
|
-
style:
|
|
963
|
+
ref: o,
|
|
964
|
+
style: A.canvas,
|
|
915
965
|
onPointerDown: y,
|
|
916
|
-
onPointerMove:
|
|
917
|
-
onPointerUp:
|
|
918
|
-
onPointerLeave:
|
|
966
|
+
onPointerMove: f,
|
|
967
|
+
onPointerUp: C,
|
|
968
|
+
onPointerLeave: C
|
|
919
969
|
}
|
|
920
970
|
),
|
|
921
|
-
/* @__PURE__ */
|
|
922
|
-
/* @__PURE__ */
|
|
971
|
+
/* @__PURE__ */ v("div", { style: { display: "flex", gap: "8px", marginTop: "12px" }, children: [
|
|
972
|
+
/* @__PURE__ */ d(
|
|
923
973
|
"button",
|
|
924
974
|
{
|
|
925
|
-
onClick:
|
|
926
|
-
style: { ...
|
|
975
|
+
onClick: x,
|
|
976
|
+
style: { ...A.button, backgroundColor: "var(--nice-danger, #f44336)" },
|
|
927
977
|
children: e("editor.clear", "Clear")
|
|
928
978
|
}
|
|
929
979
|
),
|
|
930
|
-
/* @__PURE__ */
|
|
980
|
+
/* @__PURE__ */ d(
|
|
931
981
|
"button",
|
|
932
982
|
{
|
|
933
|
-
onClick:
|
|
934
|
-
disabled:
|
|
935
|
-
style:
|
|
936
|
-
children:
|
|
983
|
+
onClick: b,
|
|
984
|
+
disabled: a.length === 0 || p,
|
|
985
|
+
style: A.button,
|
|
986
|
+
children: p ? e("editor.recognizing", "Recognizing...") : e("editor.recognize", "Recognize")
|
|
937
987
|
}
|
|
938
988
|
)
|
|
939
989
|
] }),
|
|
940
|
-
/* @__PURE__ */
|
|
990
|
+
/* @__PURE__ */ d("p", { style: { fontSize: "12px", color: "var(--nice-text-secondary, #666)", marginTop: "8px" }, children: e(
|
|
941
991
|
"editor.handwritingNote",
|
|
942
992
|
"Draw your equation above. Handwriting recognition requires external API integration."
|
|
943
993
|
) })
|
|
944
994
|
] });
|
|
945
995
|
}
|
|
946
|
-
const
|
|
996
|
+
const $e = {
|
|
947
997
|
pi: Math.PI,
|
|
948
998
|
PI: Math.PI,
|
|
949
999
|
e: Math.E,
|
|
950
1000
|
E: Math.E,
|
|
951
1001
|
phi: (1 + Math.sqrt(5)) / 2,
|
|
952
1002
|
tau: Math.PI * 2
|
|
953
|
-
},
|
|
1003
|
+
}, Re = {
|
|
954
1004
|
sin: Math.sin,
|
|
955
1005
|
cos: Math.cos,
|
|
956
1006
|
tan: Math.tan,
|
|
@@ -982,15 +1032,19 @@ const mathConstants = {
|
|
|
982
1032
|
cot: (e) => 1 / Math.tan(e),
|
|
983
1033
|
ln: Math.log
|
|
984
1034
|
};
|
|
985
|
-
class
|
|
986
|
-
constructor() {
|
|
987
|
-
|
|
988
|
-
|
|
1035
|
+
class ie {
|
|
1036
|
+
constructor(t = {}) {
|
|
1037
|
+
T(this, "pos", 0);
|
|
1038
|
+
T(this, "expr", "");
|
|
1039
|
+
T(this, "options");
|
|
1040
|
+
this.options = t;
|
|
989
1041
|
}
|
|
990
1042
|
parse(t) {
|
|
991
|
-
this.expr = t.replace(/\s+/g, ""), this.pos = 0;
|
|
1043
|
+
this.expr = t.replace(/\s+/g, "").replace(/×/g, "*").replace(/÷/g, "/").replace(/−/g, "-").replace(/π/g, "pi").replace(/√(\d+(?:\.\d+)?)/g, "sqrt($1)").replace(/√/g, "sqrt"), this.pos = 0;
|
|
992
1044
|
const r = this.parseAddSub();
|
|
993
|
-
|
|
1045
|
+
if (this.options.strict && this.pos < this.expr.length)
|
|
1046
|
+
throw new Error(`Unexpected "${this.expr.slice(this.pos)}"`);
|
|
1047
|
+
return (o) => this.evaluate(r, o);
|
|
994
1048
|
}
|
|
995
1049
|
parseAddSub() {
|
|
996
1050
|
let t = this.parseMulDiv();
|
|
@@ -999,102 +1053,126 @@ class ExpressionParser {
|
|
|
999
1053
|
if (r !== "+" && r !== "-")
|
|
1000
1054
|
break;
|
|
1001
1055
|
this.pos++;
|
|
1002
|
-
const
|
|
1003
|
-
t = { type: "binary", op: r, left: t, right:
|
|
1056
|
+
const o = this.parseMulDiv();
|
|
1057
|
+
t = { type: "binary", op: r, left: t, right: o };
|
|
1004
1058
|
}
|
|
1005
1059
|
return t;
|
|
1006
1060
|
}
|
|
1007
1061
|
parseMulDiv() {
|
|
1008
|
-
let t = this.
|
|
1062
|
+
let t = this.parseUnary();
|
|
1009
1063
|
for (; this.pos < this.expr.length; ) {
|
|
1010
1064
|
const r = this.expr[this.pos];
|
|
1011
|
-
if (r
|
|
1065
|
+
if (r === "*" || r === "/")
|
|
1066
|
+
this.pos++, t = { type: "binary", op: r, left: t, right: this.parseUnary() };
|
|
1067
|
+
else if (/[0-9a-zA-Z_(]/.test(r))
|
|
1068
|
+
t = { type: "binary", op: "*", left: t, right: this.parsePower() };
|
|
1069
|
+
else
|
|
1012
1070
|
break;
|
|
1013
|
-
this.pos++;
|
|
1014
|
-
const a = this.parsePower();
|
|
1015
|
-
t = { type: "binary", op: r, left: t, right: a };
|
|
1016
|
-
}
|
|
1017
|
-
return t;
|
|
1018
|
-
}
|
|
1019
|
-
parsePower() {
|
|
1020
|
-
let t = this.parseUnary();
|
|
1021
|
-
for (; this.pos < this.expr.length && this.expr[this.pos] === "^"; ) {
|
|
1022
|
-
this.pos++;
|
|
1023
|
-
const r = this.parseUnary();
|
|
1024
|
-
t = { type: "binary", op: "^", left: t, right: r };
|
|
1025
1071
|
}
|
|
1026
1072
|
return t;
|
|
1027
1073
|
}
|
|
1028
1074
|
parseUnary() {
|
|
1029
|
-
return this.expr[this.pos] === "-" ? (this.pos++, { type: "unary",
|
|
1075
|
+
return this.expr[this.pos] === "-" ? (this.pos++, { type: "unary", arg: this.parseUnary() }) : this.expr[this.pos] === "+" ? (this.pos++, this.parseUnary()) : this.parsePower();
|
|
1076
|
+
}
|
|
1077
|
+
parsePower() {
|
|
1078
|
+
const t = this.parsePrimary();
|
|
1079
|
+
return this.expr[this.pos] === "^" ? (this.pos++, { type: "binary", op: "^", left: t, right: this.parseUnary() }) : t;
|
|
1030
1080
|
}
|
|
1031
1081
|
parsePrimary() {
|
|
1032
1082
|
if (this.expr[this.pos] === "(") {
|
|
1033
1083
|
this.pos++;
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1084
|
+
const o = this.parseAddSub();
|
|
1085
|
+
if (this.expr[this.pos] === ")")
|
|
1086
|
+
this.pos++;
|
|
1087
|
+
else if (this.options.strict)
|
|
1088
|
+
throw new Error('Missing ")"');
|
|
1089
|
+
return o;
|
|
1036
1090
|
}
|
|
1037
|
-
const t = this.expr.slice(this.pos).match(/^(\d+\.?\d
|
|
1091
|
+
const t = this.expr.slice(this.pos).match(/^(\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/);
|
|
1038
1092
|
if (t)
|
|
1039
|
-
return this.pos += t[
|
|
1093
|
+
return this.pos += t[0].length, { type: "number", value: parseFloat(t[0]) };
|
|
1040
1094
|
const r = this.expr.slice(this.pos).match(/^([a-zA-Z_][a-zA-Z0-9_]*)/);
|
|
1041
1095
|
if (r) {
|
|
1042
|
-
const
|
|
1043
|
-
if (this.pos +=
|
|
1096
|
+
const o = r[1];
|
|
1097
|
+
if (this.pos += o.length, this.expr[this.pos] === "(") {
|
|
1044
1098
|
this.pos++;
|
|
1045
|
-
const
|
|
1099
|
+
const a = [];
|
|
1046
1100
|
for (; this.expr[this.pos] !== ")" && this.pos < this.expr.length; )
|
|
1047
|
-
|
|
1048
|
-
|
|
1101
|
+
if (a.push(this.parseAddSub()), this.expr[this.pos] === ",")
|
|
1102
|
+
this.pos++;
|
|
1103
|
+
else if (this.expr[this.pos] !== ")")
|
|
1104
|
+
break;
|
|
1105
|
+
if (this.expr[this.pos] === ")")
|
|
1106
|
+
this.pos++;
|
|
1107
|
+
else if (this.options.strict)
|
|
1108
|
+
throw new Error('Missing ")"');
|
|
1109
|
+
return { type: "call", name: o, args: a };
|
|
1049
1110
|
}
|
|
1050
|
-
return { type: "variable", name:
|
|
1111
|
+
return { type: "variable", name: o };
|
|
1051
1112
|
}
|
|
1113
|
+
if (this.options.strict)
|
|
1114
|
+
throw new Error(
|
|
1115
|
+
this.pos < this.expr.length ? `Unexpected "${this.expr[this.pos]}"` : "Unexpected end"
|
|
1116
|
+
);
|
|
1052
1117
|
return { type: "number", value: 0 };
|
|
1053
1118
|
}
|
|
1119
|
+
/** A name from a table, honouring `ignoreCase`. */
|
|
1120
|
+
lookup(t, r) {
|
|
1121
|
+
if (r in t)
|
|
1122
|
+
return t[r];
|
|
1123
|
+
if (this.options.ignoreCase) {
|
|
1124
|
+
const o = r.toLowerCase(), a = Object.keys(t).find((n) => n.toLowerCase() === o);
|
|
1125
|
+
return a === void 0 ? void 0 : t[a];
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1054
1128
|
evaluate(t, r) {
|
|
1055
1129
|
switch (t.type) {
|
|
1056
1130
|
case "number":
|
|
1057
1131
|
return t.value;
|
|
1058
|
-
case "variable":
|
|
1132
|
+
case "variable": {
|
|
1059
1133
|
if (t.name in r)
|
|
1060
1134
|
return r[t.name];
|
|
1135
|
+
const o = this.lookup({ ...$e, ...this.options.constants }, t.name);
|
|
1136
|
+
if (o !== void 0)
|
|
1137
|
+
return o;
|
|
1061
1138
|
throw new Error(`Unknown variable: ${t.name}`);
|
|
1139
|
+
}
|
|
1062
1140
|
case "unary":
|
|
1063
|
-
return
|
|
1141
|
+
return -this.evaluate(t.arg, r);
|
|
1064
1142
|
case "binary": {
|
|
1065
|
-
const
|
|
1143
|
+
const o = this.evaluate(t.left, r), a = this.evaluate(t.right, r);
|
|
1066
1144
|
switch (t.op) {
|
|
1067
1145
|
case "+":
|
|
1068
|
-
return
|
|
1146
|
+
return o + a;
|
|
1069
1147
|
case "-":
|
|
1070
|
-
return
|
|
1148
|
+
return o - a;
|
|
1071
1149
|
case "*":
|
|
1072
|
-
return
|
|
1150
|
+
return o * a;
|
|
1073
1151
|
case "/":
|
|
1074
|
-
return
|
|
1152
|
+
return o / a;
|
|
1075
1153
|
case "^":
|
|
1076
|
-
return Math.pow(
|
|
1154
|
+
return Math.pow(o, a);
|
|
1077
1155
|
default:
|
|
1078
1156
|
return 0;
|
|
1079
1157
|
}
|
|
1080
1158
|
}
|
|
1081
1159
|
case "call": {
|
|
1082
|
-
const
|
|
1083
|
-
if (!
|
|
1160
|
+
const o = this.lookup({ ...Re, ...this.options.functions }, t.name);
|
|
1161
|
+
if (!o)
|
|
1084
1162
|
throw new Error(`Unknown function: ${t.name}`);
|
|
1085
|
-
const
|
|
1086
|
-
return
|
|
1163
|
+
const a = t.args.map((n) => this.evaluate(n, r));
|
|
1164
|
+
return o(...a);
|
|
1087
1165
|
}
|
|
1088
1166
|
default:
|
|
1089
1167
|
return 0;
|
|
1090
1168
|
}
|
|
1091
1169
|
}
|
|
1092
1170
|
}
|
|
1093
|
-
class
|
|
1171
|
+
class Te {
|
|
1094
1172
|
constructor(t = {}) {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1173
|
+
T(this, "plots", /* @__PURE__ */ new Map());
|
|
1174
|
+
T(this, "parser", new ie());
|
|
1175
|
+
T(this, "config");
|
|
1098
1176
|
this.config = {
|
|
1099
1177
|
defaultResolution: t.defaultResolution ?? 200,
|
|
1100
1178
|
maxResolution: t.maxResolution ?? 1e3
|
|
@@ -1120,11 +1198,11 @@ class GraphService {
|
|
|
1120
1198
|
}
|
|
1121
1199
|
/** Update a plot */
|
|
1122
1200
|
updatePlot(t, r) {
|
|
1123
|
-
const
|
|
1124
|
-
if (!
|
|
1201
|
+
const o = this.plots.get(t);
|
|
1202
|
+
if (!o)
|
|
1125
1203
|
throw new Error(`Plot not found: ${t}`);
|
|
1126
|
-
const
|
|
1127
|
-
return this.plots.set(t,
|
|
1204
|
+
const a = { ...o, ...r, id: o.id };
|
|
1205
|
+
return this.plots.set(t, a), a;
|
|
1128
1206
|
}
|
|
1129
1207
|
/** Remove a plot */
|
|
1130
1208
|
removePlot(t) {
|
|
@@ -1139,41 +1217,41 @@ class GraphService {
|
|
|
1139
1217
|
return this.plots.get(t);
|
|
1140
1218
|
}
|
|
1141
1219
|
/** Compute 2D function points */
|
|
1142
|
-
compute2DFunction(t, r,
|
|
1143
|
-
const n = this.parser.parse(t), i = [],
|
|
1144
|
-
for (let
|
|
1145
|
-
const s = r.min +
|
|
1220
|
+
compute2DFunction(t, r, o, a) {
|
|
1221
|
+
const n = this.parser.parse(t), i = [], c = (r.max - r.min) / o;
|
|
1222
|
+
for (let u = 0; u <= o; u++) {
|
|
1223
|
+
const s = r.min + u * c;
|
|
1146
1224
|
try {
|
|
1147
|
-
const
|
|
1148
|
-
Number.isFinite(
|
|
1225
|
+
const p = n({ x: s, ...a });
|
|
1226
|
+
Number.isFinite(p) && i.push({ x: s, y: p });
|
|
1149
1227
|
} catch {
|
|
1150
1228
|
}
|
|
1151
1229
|
}
|
|
1152
1230
|
return i;
|
|
1153
1231
|
}
|
|
1154
1232
|
/** Compute 2D parametric curve */
|
|
1155
|
-
compute2DParametric(t, r,
|
|
1156
|
-
const i = this.parser.parse(t),
|
|
1157
|
-
for (let
|
|
1158
|
-
const
|
|
1233
|
+
compute2DParametric(t, r, o, a, n) {
|
|
1234
|
+
const i = this.parser.parse(t), c = this.parser.parse(r), u = [], s = (o.max - o.min) / a;
|
|
1235
|
+
for (let p = 0; p <= a; p++) {
|
|
1236
|
+
const m = o.min + p * s;
|
|
1159
1237
|
try {
|
|
1160
|
-
const y = i({ t:
|
|
1161
|
-
Number.isFinite(y) && Number.isFinite(
|
|
1238
|
+
const y = i({ t: m, ...n }), f = c({ t: m, ...n });
|
|
1239
|
+
Number.isFinite(y) && Number.isFinite(f) && u.push({ x: y, y: f });
|
|
1162
1240
|
} catch {
|
|
1163
1241
|
}
|
|
1164
1242
|
}
|
|
1165
|
-
return
|
|
1243
|
+
return u;
|
|
1166
1244
|
}
|
|
1167
1245
|
/** Compute 2D polar curve */
|
|
1168
|
-
compute2DPolar(t, r,
|
|
1169
|
-
const n = this.parser.parse(t), i = [],
|
|
1170
|
-
for (let
|
|
1171
|
-
const s = r.min +
|
|
1246
|
+
compute2DPolar(t, r, o, a) {
|
|
1247
|
+
const n = this.parser.parse(t), i = [], c = (r.max - r.min) / o;
|
|
1248
|
+
for (let u = 0; u <= o; u++) {
|
|
1249
|
+
const s = r.min + u * c;
|
|
1172
1250
|
try {
|
|
1173
|
-
const
|
|
1174
|
-
if (Number.isFinite(
|
|
1175
|
-
const
|
|
1176
|
-
i.push({ x:
|
|
1251
|
+
const p = n({ theta: s, t: s, ...a });
|
|
1252
|
+
if (Number.isFinite(p)) {
|
|
1253
|
+
const m = p * Math.cos(s), y = p * Math.sin(s);
|
|
1254
|
+
i.push({ x: m, y });
|
|
1177
1255
|
}
|
|
1178
1256
|
} catch {
|
|
1179
1257
|
}
|
|
@@ -1181,88 +1259,88 @@ class GraphService {
|
|
|
1181
1259
|
return i;
|
|
1182
1260
|
}
|
|
1183
1261
|
/** Compute 3D surface points */
|
|
1184
|
-
compute3DSurface(t, r,
|
|
1185
|
-
const i = this.parser.parse(t),
|
|
1186
|
-
for (let
|
|
1187
|
-
const
|
|
1188
|
-
for (let
|
|
1189
|
-
const
|
|
1262
|
+
compute3DSurface(t, r, o, a, n) {
|
|
1263
|
+
const i = this.parser.parse(t), c = [], u = (r.max - r.min) / a, s = (o.max - o.min) / a;
|
|
1264
|
+
for (let p = 0; p <= a; p++) {
|
|
1265
|
+
const m = [], y = r.min + p * u;
|
|
1266
|
+
for (let f = 0; f <= a; f++) {
|
|
1267
|
+
const C = o.min + f * s;
|
|
1190
1268
|
try {
|
|
1191
|
-
const
|
|
1192
|
-
Number.isFinite(
|
|
1269
|
+
const x = i({ x: y, y: C, ...n });
|
|
1270
|
+
Number.isFinite(x) ? m.push({ x: y, y: C, z: x }) : m.push({ x: y, y: C, z: 0 });
|
|
1193
1271
|
} catch {
|
|
1194
|
-
|
|
1272
|
+
m.push({ x: y, y: C, z: 0 });
|
|
1195
1273
|
}
|
|
1196
1274
|
}
|
|
1197
|
-
|
|
1275
|
+
c.push(m);
|
|
1198
1276
|
}
|
|
1199
|
-
return
|
|
1277
|
+
return c;
|
|
1200
1278
|
}
|
|
1201
1279
|
/** Export plot data as SVG */
|
|
1202
|
-
exportSVG(t, r,
|
|
1203
|
-
const i =
|
|
1204
|
-
`<svg xmlns="http://www.w3.org/2000/svg" width="${
|
|
1280
|
+
exportSVG(t, r, o, a) {
|
|
1281
|
+
const i = o - 80, c = a - 80, u = (m) => 40 + (m - r.xRange.min) / (r.xRange.max - r.xRange.min) * i, s = (m) => a - 40 - (m - r.yRange.min) / (r.yRange.max - r.yRange.min) * c, p = [
|
|
1282
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${a}">`,
|
|
1205
1283
|
`<rect width="100%" height="100%" fill="rgb(${r.backgroundColor.r},${r.backgroundColor.g},${r.backgroundColor.b})"/>`
|
|
1206
1284
|
];
|
|
1207
1285
|
if (r.showGrid) {
|
|
1208
|
-
|
|
1209
|
-
for (let
|
|
1210
|
-
const y =
|
|
1211
|
-
|
|
1286
|
+
p.push('<g stroke="var(--nice-border, #ddd)" stroke-width="0.5">');
|
|
1287
|
+
for (let m = Math.ceil(r.xRange.min); m <= r.xRange.max; m++) {
|
|
1288
|
+
const y = u(m);
|
|
1289
|
+
p.push(`<line x1="${y}" y1="40" x2="${y}" y2="${a - 40}"/>`);
|
|
1212
1290
|
}
|
|
1213
|
-
for (let
|
|
1214
|
-
const y = s(
|
|
1215
|
-
|
|
1291
|
+
for (let m = Math.ceil(r.yRange.min); m <= r.yRange.max; m++) {
|
|
1292
|
+
const y = s(m);
|
|
1293
|
+
p.push(`<line x1="40" y1="${y}" x2="${o - 40}" y2="${y}"/>`);
|
|
1216
1294
|
}
|
|
1217
|
-
|
|
1295
|
+
p.push("</g>");
|
|
1218
1296
|
}
|
|
1219
1297
|
if (r.showAxes) {
|
|
1220
|
-
|
|
1221
|
-
const
|
|
1222
|
-
|
|
1298
|
+
p.push('<g stroke="var(--nice-text, #333)" stroke-width="1">');
|
|
1299
|
+
const m = s(0), y = u(0);
|
|
1300
|
+
p.push(`<line x1="40" y1="${m}" x2="${o - 40}" y2="${m}"/>`), p.push(`<line x1="${y}" y1="40" x2="${y}" y2="${a - 40}"/>`), p.push("</g>");
|
|
1223
1301
|
}
|
|
1224
|
-
for (const
|
|
1225
|
-
if (
|
|
1226
|
-
const y = this.compute2DFunction(
|
|
1302
|
+
for (const m of t.filter((y) => y.visible))
|
|
1303
|
+
if (m.type === "2d-function") {
|
|
1304
|
+
const y = this.compute2DFunction(m.expression, r.xRange, m.resolution || 200);
|
|
1227
1305
|
if (y.length > 0) {
|
|
1228
|
-
const
|
|
1229
|
-
|
|
1230
|
-
`<path d="${
|
|
1306
|
+
const f = y.map((C, x) => `${x === 0 ? "M" : "L"}${u(C.x)},${s(C.y)}`).join(" ");
|
|
1307
|
+
p.push(
|
|
1308
|
+
`<path d="${f}" fill="none" stroke="rgb(${m.color.r},${m.color.g},${m.color.b})" stroke-width="${m.lineWidth}"/>`
|
|
1231
1309
|
);
|
|
1232
1310
|
}
|
|
1233
1311
|
}
|
|
1234
|
-
return r.showLabels && (
|
|
1235
|
-
`<text x="${
|
|
1236
|
-
),
|
|
1237
|
-
`<text x="10" y="${
|
|
1238
|
-
)),
|
|
1312
|
+
return r.showLabels && (p.push(
|
|
1313
|
+
`<text x="${o / 2}" y="${a - 10}" text-anchor="middle" font-size="12">x</text>`
|
|
1314
|
+
), p.push(
|
|
1315
|
+
`<text x="10" y="${a / 2}" text-anchor="middle" font-size="12" transform="rotate(-90,10,${a / 2})">y</text>`
|
|
1316
|
+
)), p.push("</svg>"), p.join(`
|
|
1239
1317
|
`);
|
|
1240
1318
|
}
|
|
1241
1319
|
/** Export as PNG (data URL) */
|
|
1242
|
-
async exportPNG(t, r,
|
|
1243
|
-
const n = this.exportSVG(t, r,
|
|
1244
|
-
return new Promise((i,
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1320
|
+
async exportPNG(t, r, o, a) {
|
|
1321
|
+
const n = this.exportSVG(t, r, o, a);
|
|
1322
|
+
return new Promise((i, c) => {
|
|
1323
|
+
const u = new Image();
|
|
1324
|
+
u.onload = () => {
|
|
1247
1325
|
const s = document.createElement("canvas");
|
|
1248
|
-
s.width =
|
|
1249
|
-
const
|
|
1250
|
-
if (!
|
|
1251
|
-
|
|
1326
|
+
s.width = o, s.height = a;
|
|
1327
|
+
const p = s.getContext("2d");
|
|
1328
|
+
if (!p) {
|
|
1329
|
+
c(new Error("Could not get canvas context"));
|
|
1252
1330
|
return;
|
|
1253
1331
|
}
|
|
1254
|
-
|
|
1255
|
-
},
|
|
1332
|
+
p.drawImage(u, 0, 0), i(s.toDataURL("image/png"));
|
|
1333
|
+
}, u.onerror = c, u.src = "data:image/svg+xml;base64," + btoa(n);
|
|
1256
1334
|
});
|
|
1257
1335
|
}
|
|
1258
1336
|
generateId() {
|
|
1259
1337
|
return Date.now().toString(36) + Math.random().toString(36).substring(2, 8);
|
|
1260
1338
|
}
|
|
1261
1339
|
}
|
|
1262
|
-
function
|
|
1263
|
-
return new
|
|
1340
|
+
function tt(e) {
|
|
1341
|
+
return new Te(e);
|
|
1264
1342
|
}
|
|
1265
|
-
const
|
|
1343
|
+
const ee = [
|
|
1266
1344
|
// Basic
|
|
1267
1345
|
{ name: "Linear", expression: "x", type: "2d-function", category: "basic" },
|
|
1268
1346
|
{ name: "Quadratic", expression: "x^2", type: "2d-function", category: "basic" },
|
|
@@ -1345,14 +1423,14 @@ const FUNCTION_PRESETS = [
|
|
|
1345
1423
|
type: "3d-surface",
|
|
1346
1424
|
category: "3d"
|
|
1347
1425
|
}
|
|
1348
|
-
],
|
|
1349
|
-
function
|
|
1350
|
-
const e =
|
|
1426
|
+
], se = /* @__PURE__ */ F(null);
|
|
1427
|
+
function Y() {
|
|
1428
|
+
const e = j(se);
|
|
1351
1429
|
if (!e)
|
|
1352
1430
|
throw new Error("useGraph must be used within GraphProvider");
|
|
1353
1431
|
return e;
|
|
1354
1432
|
}
|
|
1355
|
-
const
|
|
1433
|
+
const $ = {
|
|
1356
1434
|
container: {
|
|
1357
1435
|
display: "flex",
|
|
1358
1436
|
height: "100%",
|
|
@@ -1411,14 +1489,14 @@ const styles$2 = {
|
|
|
1411
1489
|
backgroundColor: "var(--nice-bg-secondary, #fafafa)"
|
|
1412
1490
|
}
|
|
1413
1491
|
};
|
|
1414
|
-
function
|
|
1492
|
+
function rt({
|
|
1415
1493
|
service: e,
|
|
1416
1494
|
width: t = 800,
|
|
1417
1495
|
height: r = 600,
|
|
1418
|
-
className:
|
|
1419
|
-
style:
|
|
1496
|
+
className: o,
|
|
1497
|
+
style: a
|
|
1420
1498
|
}) {
|
|
1421
|
-
const [n, i] =
|
|
1499
|
+
const [n, i] = P([]), [c, u] = P({
|
|
1422
1500
|
xRange: { min: -10, max: 10 },
|
|
1423
1501
|
yRange: { min: -10, max: 10 },
|
|
1424
1502
|
zRange: { min: -5, max: 5 },
|
|
@@ -1429,63 +1507,63 @@ function NiceGraphPlotter({
|
|
|
1429
1507
|
cameraRotationX: 30,
|
|
1430
1508
|
cameraRotationY: 45,
|
|
1431
1509
|
cameraDistance: 5
|
|
1432
|
-
}), [s,
|
|
1510
|
+
}), [s, p] = P({
|
|
1433
1511
|
isPlaying: !1,
|
|
1434
1512
|
parameter: "a",
|
|
1435
1513
|
currentValue: 0,
|
|
1436
1514
|
minValue: -5,
|
|
1437
1515
|
maxValue: 5,
|
|
1438
1516
|
speed: 1
|
|
1439
|
-
}),
|
|
1517
|
+
}), m = R(() => {
|
|
1440
1518
|
i(e.getPlots());
|
|
1441
|
-
}, [e]), y =
|
|
1442
|
-
|
|
1443
|
-
}, []),
|
|
1444
|
-
|
|
1445
|
-
}, []),
|
|
1446
|
-
(
|
|
1447
|
-
e.addPlot(
|
|
1519
|
+
}, [e]), y = R((g) => {
|
|
1520
|
+
u((w) => ({ ...w, ...g }));
|
|
1521
|
+
}, []), f = R((g) => {
|
|
1522
|
+
p((w) => ({ ...w, ...g }));
|
|
1523
|
+
}, []), C = R(
|
|
1524
|
+
(g) => {
|
|
1525
|
+
e.addPlot(g), m();
|
|
1448
1526
|
},
|
|
1449
|
-
[e,
|
|
1450
|
-
),
|
|
1451
|
-
(
|
|
1452
|
-
e.removePlot(
|
|
1527
|
+
[e, m]
|
|
1528
|
+
), x = R(
|
|
1529
|
+
(g) => {
|
|
1530
|
+
e.removePlot(g), m();
|
|
1453
1531
|
},
|
|
1454
|
-
[e,
|
|
1455
|
-
),
|
|
1456
|
-
(
|
|
1457
|
-
e.updatePlot(
|
|
1532
|
+
[e, m]
|
|
1533
|
+
), b = R(
|
|
1534
|
+
(g, w) => {
|
|
1535
|
+
e.updatePlot(g, w), m();
|
|
1458
1536
|
},
|
|
1459
|
-
[e,
|
|
1460
|
-
),
|
|
1537
|
+
[e, m]
|
|
1538
|
+
), l = {
|
|
1461
1539
|
service: e,
|
|
1462
1540
|
plots: n,
|
|
1463
|
-
view:
|
|
1541
|
+
view: c,
|
|
1464
1542
|
setView: y,
|
|
1465
|
-
addPlot:
|
|
1466
|
-
removePlot:
|
|
1467
|
-
updatePlot:
|
|
1543
|
+
addPlot: C,
|
|
1544
|
+
removePlot: x,
|
|
1545
|
+
updatePlot: b,
|
|
1468
1546
|
animation: s,
|
|
1469
|
-
setAnimation:
|
|
1470
|
-
refresh:
|
|
1547
|
+
setAnimation: f,
|
|
1548
|
+
refresh: m
|
|
1471
1549
|
};
|
|
1472
|
-
return /* @__PURE__ */
|
|
1473
|
-
/* @__PURE__ */
|
|
1474
|
-
/* @__PURE__ */
|
|
1475
|
-
/* @__PURE__ */
|
|
1550
|
+
return /* @__PURE__ */ d(se.Provider, { value: l, children: /* @__PURE__ */ v("div", { className: o, style: { ...$.container, ...a }, children: [
|
|
1551
|
+
/* @__PURE__ */ v("div", { style: $.sidebar, children: [
|
|
1552
|
+
/* @__PURE__ */ d(Ae, {}),
|
|
1553
|
+
/* @__PURE__ */ d(ze, {})
|
|
1476
1554
|
] }),
|
|
1477
|
-
/* @__PURE__ */
|
|
1478
|
-
/* @__PURE__ */
|
|
1479
|
-
/* @__PURE__ */
|
|
1555
|
+
/* @__PURE__ */ v("div", { style: $.main, children: [
|
|
1556
|
+
/* @__PURE__ */ d(Ee, { width: t, height: r }),
|
|
1557
|
+
/* @__PURE__ */ d(Ie, { width: t, height: r })
|
|
1480
1558
|
] })
|
|
1481
1559
|
] }) });
|
|
1482
1560
|
}
|
|
1483
|
-
function
|
|
1484
|
-
const { t: e } =
|
|
1561
|
+
function Ae() {
|
|
1562
|
+
const { t: e } = L(), { addPlot: t } = Y(), [r, o] = P("sin(x)"), [a, n] = P("2d-function"), [i, c] = P("cos(x)"), u = () => {
|
|
1485
1563
|
t({
|
|
1486
|
-
type:
|
|
1564
|
+
type: a,
|
|
1487
1565
|
expression: r,
|
|
1488
|
-
expressionY:
|
|
1566
|
+
expressionY: a === "2d-parametric" ? i : void 0,
|
|
1489
1567
|
color: {
|
|
1490
1568
|
r: Math.floor(Math.random() * 200),
|
|
1491
1569
|
g: Math.floor(Math.random() * 200),
|
|
@@ -1493,52 +1571,52 @@ function PlotControls() {
|
|
|
1493
1571
|
}
|
|
1494
1572
|
});
|
|
1495
1573
|
};
|
|
1496
|
-
return /* @__PURE__ */
|
|
1497
|
-
/* @__PURE__ */
|
|
1574
|
+
return /* @__PURE__ */ v("div", { style: { padding: "12px", borderBottom: "1px solid var(--nice-border, #e0e0e0)" }, children: [
|
|
1575
|
+
/* @__PURE__ */ d("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ v(
|
|
1498
1576
|
"select",
|
|
1499
1577
|
{
|
|
1500
|
-
value:
|
|
1578
|
+
value: a,
|
|
1501
1579
|
onChange: (s) => n(s.target.value),
|
|
1502
|
-
style: {
|
|
1580
|
+
style: { ...$.input, width: "100%" },
|
|
1503
1581
|
children: [
|
|
1504
|
-
/* @__PURE__ */
|
|
1505
|
-
/* @__PURE__ */
|
|
1506
|
-
/* @__PURE__ */
|
|
1507
|
-
/* @__PURE__ */
|
|
1582
|
+
/* @__PURE__ */ d("option", { value: "2d-function", children: "y = f(x)" }),
|
|
1583
|
+
/* @__PURE__ */ d("option", { value: "2d-parametric", children: "Parametric (x(t), y(t))" }),
|
|
1584
|
+
/* @__PURE__ */ d("option", { value: "2d-polar", children: "Polar r = f(θ)" }),
|
|
1585
|
+
/* @__PURE__ */ d("option", { value: "3d-surface", children: "3D Surface z = f(x,y)" })
|
|
1508
1586
|
]
|
|
1509
1587
|
}
|
|
1510
1588
|
) }),
|
|
1511
|
-
/* @__PURE__ */
|
|
1589
|
+
/* @__PURE__ */ d("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ d(
|
|
1512
1590
|
"input",
|
|
1513
1591
|
{
|
|
1514
1592
|
type: "text",
|
|
1515
1593
|
value: r,
|
|
1516
|
-
onChange: (s) =>
|
|
1517
|
-
placeholder:
|
|
1518
|
-
style: {
|
|
1594
|
+
onChange: (s) => o(s.target.value),
|
|
1595
|
+
placeholder: a === "2d-parametric" ? "x(t) = ..." : "Expression...",
|
|
1596
|
+
style: { ...$.input, width: "100%" }
|
|
1519
1597
|
}
|
|
1520
1598
|
) }),
|
|
1521
|
-
|
|
1599
|
+
a === "2d-parametric" && /* @__PURE__ */ d("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ d(
|
|
1522
1600
|
"input",
|
|
1523
1601
|
{
|
|
1524
1602
|
type: "text",
|
|
1525
1603
|
value: i,
|
|
1526
|
-
onChange: (s) =>
|
|
1604
|
+
onChange: (s) => c(s.target.value),
|
|
1527
1605
|
placeholder: "y(t) = ...",
|
|
1528
|
-
style: {
|
|
1606
|
+
style: { ...$.input, width: "100%" }
|
|
1529
1607
|
}
|
|
1530
1608
|
) }),
|
|
1531
|
-
/* @__PURE__ */
|
|
1532
|
-
/* @__PURE__ */
|
|
1609
|
+
/* @__PURE__ */ d("button", { onClick: u, style: { ...$.button, width: "100%" }, children: "+ Add Plot" }),
|
|
1610
|
+
/* @__PURE__ */ v(
|
|
1533
1611
|
"select",
|
|
1534
1612
|
{
|
|
1535
1613
|
onChange: (s) => {
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1538
|
-
type:
|
|
1539
|
-
expression:
|
|
1540
|
-
expressionY:
|
|
1541
|
-
label:
|
|
1614
|
+
const p = ee.find((m) => m.name === s.target.value);
|
|
1615
|
+
p && t({
|
|
1616
|
+
type: p.type,
|
|
1617
|
+
expression: p.expression,
|
|
1618
|
+
expressionY: p.expressionY,
|
|
1619
|
+
label: p.name,
|
|
1542
1620
|
color: {
|
|
1543
1621
|
r: Math.floor(Math.random() * 200),
|
|
1544
1622
|
g: Math.floor(Math.random() * 200),
|
|
@@ -1546,24 +1624,24 @@ function PlotControls() {
|
|
|
1546
1624
|
}
|
|
1547
1625
|
});
|
|
1548
1626
|
},
|
|
1549
|
-
style: {
|
|
1627
|
+
style: { ...$.input, width: "100%", marginTop: "8px" },
|
|
1550
1628
|
value: "",
|
|
1551
1629
|
children: [
|
|
1552
|
-
/* @__PURE__ */
|
|
1553
|
-
["basic", "trigonometric", "exponential", "parametric", "polar", "3d"].map((s) => /* @__PURE__ */
|
|
1554
|
-
|
|
1630
|
+
/* @__PURE__ */ d("option", { value: "", disabled: !0, children: e("plotter.quickAdd", "Quick add preset...") }),
|
|
1631
|
+
["basic", "trigonometric", "exponential", "parametric", "polar", "3d"].map((s) => /* @__PURE__ */ d("optgroup", { label: s.charAt(0).toUpperCase() + s.slice(1), children: ee.filter((p) => p.category === s).map((p) => /* @__PURE__ */ v("option", { value: p.name, children: [
|
|
1632
|
+
p.name,
|
|
1555
1633
|
": ",
|
|
1556
|
-
|
|
1557
|
-
] },
|
|
1634
|
+
p.expression
|
|
1635
|
+
] }, p.name)) }, s))
|
|
1558
1636
|
]
|
|
1559
1637
|
}
|
|
1560
1638
|
)
|
|
1561
1639
|
] });
|
|
1562
1640
|
}
|
|
1563
|
-
function
|
|
1564
|
-
const { t: e } =
|
|
1565
|
-
return /* @__PURE__ */
|
|
1566
|
-
t.length === 0 && /* @__PURE__ */
|
|
1641
|
+
function ze() {
|
|
1642
|
+
const { t: e } = L(), { plots: t, removePlot: r, updatePlot: o } = Y();
|
|
1643
|
+
return /* @__PURE__ */ v("div", { style: $.plotList, children: [
|
|
1644
|
+
t.length === 0 && /* @__PURE__ */ d(
|
|
1567
1645
|
"div",
|
|
1568
1646
|
{
|
|
1569
1647
|
style: {
|
|
@@ -1574,32 +1652,33 @@ function PlotList() {
|
|
|
1574
1652
|
children: e("plotter.noPlots", "No plots added yet")
|
|
1575
1653
|
}
|
|
1576
1654
|
),
|
|
1577
|
-
t.map((
|
|
1578
|
-
/* @__PURE__ */
|
|
1579
|
-
/* @__PURE__ */
|
|
1655
|
+
t.map((a) => /* @__PURE__ */ v("div", { style: $.plotItem, children: [
|
|
1656
|
+
/* @__PURE__ */ v("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginBottom: "8px" }, children: [
|
|
1657
|
+
/* @__PURE__ */ d(
|
|
1580
1658
|
"input",
|
|
1581
1659
|
{
|
|
1582
1660
|
type: "checkbox",
|
|
1583
|
-
checked:
|
|
1584
|
-
onChange: (n) => a
|
|
1661
|
+
checked: a.visible,
|
|
1662
|
+
onChange: (n) => o(a.id, { visible: n.target.checked })
|
|
1585
1663
|
}
|
|
1586
1664
|
),
|
|
1587
|
-
/* @__PURE__ */
|
|
1665
|
+
/* @__PURE__ */ d(
|
|
1588
1666
|
"div",
|
|
1589
1667
|
{
|
|
1590
1668
|
style: {
|
|
1591
1669
|
width: "16px",
|
|
1592
1670
|
height: "16px",
|
|
1593
1671
|
borderRadius: "3px",
|
|
1594
|
-
backgroundColor: `rgb(${
|
|
1672
|
+
backgroundColor: `rgb(${a.color.r},${a.color.g},${a.color.b})`
|
|
1595
1673
|
}
|
|
1596
1674
|
}
|
|
1597
1675
|
),
|
|
1598
|
-
/* @__PURE__ */
|
|
1599
|
-
/* @__PURE__ */
|
|
1676
|
+
/* @__PURE__ */ d("span", { style: { flex: 1, fontWeight: 500 }, children: a.label || a.expression }),
|
|
1677
|
+
/* @__PURE__ */ d(
|
|
1600
1678
|
"button",
|
|
1601
1679
|
{
|
|
1602
|
-
|
|
1680
|
+
"aria-label": e("plotter.close", "Close"),
|
|
1681
|
+
onClick: () => r(a.id),
|
|
1603
1682
|
style: {
|
|
1604
1683
|
padding: "2px 6px",
|
|
1605
1684
|
backgroundColor: "var(--nice-danger, #f44336)",
|
|
@@ -1609,11 +1688,11 @@ function PlotList() {
|
|
|
1609
1688
|
cursor: "pointer",
|
|
1610
1689
|
fontSize: "12px"
|
|
1611
1690
|
},
|
|
1612
|
-
children: "
|
|
1691
|
+
children: /* @__PURE__ */ d(G, { name: "close", size: 14 })
|
|
1613
1692
|
}
|
|
1614
1693
|
)
|
|
1615
1694
|
] }),
|
|
1616
|
-
/* @__PURE__ */
|
|
1695
|
+
/* @__PURE__ */ d(
|
|
1617
1696
|
"div",
|
|
1618
1697
|
{
|
|
1619
1698
|
style: {
|
|
@@ -1621,79 +1700,79 @@ function PlotList() {
|
|
|
1621
1700
|
color: "var(--nice-text-secondary, #666)",
|
|
1622
1701
|
fontFamily: "monospace"
|
|
1623
1702
|
},
|
|
1624
|
-
children:
|
|
1703
|
+
children: a.type === "2d-parametric" ? /* @__PURE__ */ v(oe, { children: [
|
|
1625
1704
|
"x(t) = ",
|
|
1626
|
-
|
|
1627
|
-
/* @__PURE__ */
|
|
1705
|
+
a.expression,
|
|
1706
|
+
/* @__PURE__ */ d("br", {}),
|
|
1628
1707
|
"y(t) = ",
|
|
1629
|
-
|
|
1630
|
-
] }) :
|
|
1708
|
+
a.expressionY
|
|
1709
|
+
] }) : a.expression
|
|
1631
1710
|
}
|
|
1632
1711
|
)
|
|
1633
|
-
] },
|
|
1712
|
+
] }, a.id))
|
|
1634
1713
|
] });
|
|
1635
1714
|
}
|
|
1636
|
-
function
|
|
1637
|
-
const { t: r } =
|
|
1638
|
-
const s =
|
|
1639
|
-
y.href =
|
|
1640
|
-
},
|
|
1641
|
-
const s = await
|
|
1642
|
-
|
|
1715
|
+
function Ee({ width: e, height: t }) {
|
|
1716
|
+
const { t: r } = L(), { service: o, plots: a, view: n, setView: i } = Y(), c = () => {
|
|
1717
|
+
const s = o.exportSVG(a, n, e, t), p = new Blob([s], { type: "image/svg+xml" }), m = URL.createObjectURL(p), y = document.createElement("a");
|
|
1718
|
+
y.href = m, y.download = "graph.svg", y.click(), URL.revokeObjectURL(m);
|
|
1719
|
+
}, u = async () => {
|
|
1720
|
+
const s = await o.exportPNG(a, n, e, t), p = document.createElement("a");
|
|
1721
|
+
p.href = s, p.download = "graph.png", p.click();
|
|
1643
1722
|
};
|
|
1644
|
-
return /* @__PURE__ */
|
|
1645
|
-
/* @__PURE__ */
|
|
1723
|
+
return /* @__PURE__ */ v("div", { style: $.toolbar, children: [
|
|
1724
|
+
/* @__PURE__ */ v("label", { style: { fontSize: "12px" }, children: [
|
|
1646
1725
|
"X: [",
|
|
1647
1726
|
" ",
|
|
1648
|
-
/* @__PURE__ */
|
|
1727
|
+
/* @__PURE__ */ d(
|
|
1649
1728
|
"input",
|
|
1650
1729
|
{
|
|
1651
1730
|
type: "number",
|
|
1652
1731
|
value: n.xRange.min,
|
|
1653
1732
|
onChange: (s) => i({ xRange: { ...n.xRange, min: Number(s.target.value) } }),
|
|
1654
|
-
style: {
|
|
1733
|
+
style: { ...$.input, width: "50px" }
|
|
1655
1734
|
}
|
|
1656
1735
|
),
|
|
1657
1736
|
",",
|
|
1658
1737
|
" ",
|
|
1659
|
-
/* @__PURE__ */
|
|
1738
|
+
/* @__PURE__ */ d(
|
|
1660
1739
|
"input",
|
|
1661
1740
|
{
|
|
1662
1741
|
type: "number",
|
|
1663
1742
|
value: n.xRange.max,
|
|
1664
1743
|
onChange: (s) => i({ xRange: { ...n.xRange, max: Number(s.target.value) } }),
|
|
1665
|
-
style: {
|
|
1744
|
+
style: { ...$.input, width: "50px" }
|
|
1666
1745
|
}
|
|
1667
1746
|
),
|
|
1668
1747
|
"]"
|
|
1669
1748
|
] }),
|
|
1670
|
-
/* @__PURE__ */
|
|
1749
|
+
/* @__PURE__ */ v("label", { style: { fontSize: "12px" }, children: [
|
|
1671
1750
|
"Y: [",
|
|
1672
1751
|
" ",
|
|
1673
|
-
/* @__PURE__ */
|
|
1752
|
+
/* @__PURE__ */ d(
|
|
1674
1753
|
"input",
|
|
1675
1754
|
{
|
|
1676
1755
|
type: "number",
|
|
1677
1756
|
value: n.yRange.min,
|
|
1678
1757
|
onChange: (s) => i({ yRange: { ...n.yRange, min: Number(s.target.value) } }),
|
|
1679
|
-
style: {
|
|
1758
|
+
style: { ...$.input, width: "50px" }
|
|
1680
1759
|
}
|
|
1681
1760
|
),
|
|
1682
1761
|
",",
|
|
1683
1762
|
" ",
|
|
1684
|
-
/* @__PURE__ */
|
|
1763
|
+
/* @__PURE__ */ d(
|
|
1685
1764
|
"input",
|
|
1686
1765
|
{
|
|
1687
1766
|
type: "number",
|
|
1688
1767
|
value: n.yRange.max,
|
|
1689
1768
|
onChange: (s) => i({ yRange: { ...n.yRange, max: Number(s.target.value) } }),
|
|
1690
|
-
style: {
|
|
1769
|
+
style: { ...$.input, width: "50px" }
|
|
1691
1770
|
}
|
|
1692
1771
|
),
|
|
1693
1772
|
"]"
|
|
1694
1773
|
] }),
|
|
1695
|
-
/* @__PURE__ */
|
|
1696
|
-
/* @__PURE__ */
|
|
1774
|
+
/* @__PURE__ */ v("label", { style: { fontSize: "12px" }, children: [
|
|
1775
|
+
/* @__PURE__ */ d(
|
|
1697
1776
|
"input",
|
|
1698
1777
|
{
|
|
1699
1778
|
type: "checkbox",
|
|
@@ -1703,8 +1782,8 @@ function GraphToolbar({ width: e, height: t }) {
|
|
|
1703
1782
|
),
|
|
1704
1783
|
r("plotter.grid", "Grid")
|
|
1705
1784
|
] }),
|
|
1706
|
-
/* @__PURE__ */
|
|
1707
|
-
/* @__PURE__ */
|
|
1785
|
+
/* @__PURE__ */ v("label", { style: { fontSize: "12px" }, children: [
|
|
1786
|
+
/* @__PURE__ */ d(
|
|
1708
1787
|
"input",
|
|
1709
1788
|
{
|
|
1710
1789
|
type: "checkbox",
|
|
@@ -1714,112 +1793,112 @@ function GraphToolbar({ width: e, height: t }) {
|
|
|
1714
1793
|
),
|
|
1715
1794
|
r("plotter.axes", "Axes")
|
|
1716
1795
|
] }),
|
|
1717
|
-
/* @__PURE__ */
|
|
1718
|
-
/* @__PURE__ */
|
|
1796
|
+
/* @__PURE__ */ d("div", { style: { flex: 1 } }),
|
|
1797
|
+
/* @__PURE__ */ v(
|
|
1719
1798
|
"button",
|
|
1720
1799
|
{
|
|
1721
|
-
onClick:
|
|
1722
|
-
style: {
|
|
1800
|
+
onClick: c,
|
|
1801
|
+
style: { ...$.button, backgroundColor: "var(--nice-success, #4caf50)" },
|
|
1723
1802
|
children: [
|
|
1724
|
-
/* @__PURE__ */
|
|
1803
|
+
/* @__PURE__ */ d(G, { name: "download", size: 14 }),
|
|
1725
1804
|
" SVG"
|
|
1726
1805
|
]
|
|
1727
1806
|
}
|
|
1728
1807
|
),
|
|
1729
|
-
/* @__PURE__ */
|
|
1808
|
+
/* @__PURE__ */ v(
|
|
1730
1809
|
"button",
|
|
1731
1810
|
{
|
|
1732
|
-
onClick:
|
|
1733
|
-
style: {
|
|
1811
|
+
onClick: u,
|
|
1812
|
+
style: { ...$.button, backgroundColor: "var(--nice-warning, #ff9800)" },
|
|
1734
1813
|
children: [
|
|
1735
|
-
/* @__PURE__ */
|
|
1814
|
+
/* @__PURE__ */ d(G, { name: "download", size: 14 }),
|
|
1736
1815
|
" PNG"
|
|
1737
1816
|
]
|
|
1738
1817
|
}
|
|
1739
1818
|
)
|
|
1740
1819
|
] });
|
|
1741
1820
|
}
|
|
1742
|
-
function
|
|
1743
|
-
const r =
|
|
1744
|
-
return
|
|
1745
|
-
const
|
|
1746
|
-
if (!
|
|
1821
|
+
function Ie({ width: e, height: t }) {
|
|
1822
|
+
const r = U(null), { service: o, plots: a, view: n, animation: i } = Y(), c = 40;
|
|
1823
|
+
return V(() => {
|
|
1824
|
+
const u = r.current, s = u == null ? void 0 : u.getContext("2d");
|
|
1825
|
+
if (!u || !s)
|
|
1747
1826
|
return;
|
|
1748
1827
|
s.fillStyle = `rgb(${n.backgroundColor.r},${n.backgroundColor.g},${n.backgroundColor.b})`, s.fillRect(0, 0, e, t);
|
|
1749
|
-
const
|
|
1828
|
+
const p = e - c * 2, m = t - c * 2, y = (x) => c + (x - n.xRange.min) / (n.xRange.max - n.xRange.min) * p, f = (x) => t - c - (x - n.yRange.min) / (n.yRange.max - n.yRange.min) * m;
|
|
1750
1829
|
if (n.showGrid) {
|
|
1751
|
-
s.strokeStyle =
|
|
1752
|
-
for (let
|
|
1753
|
-
const
|
|
1754
|
-
s.beginPath(), s.moveTo(
|
|
1830
|
+
s.strokeStyle = I("var(--nice-border, #e0e0e0)", s.canvas), s.lineWidth = 0.5;
|
|
1831
|
+
for (let x = Math.ceil(n.xRange.min); x <= n.xRange.max; x++) {
|
|
1832
|
+
const b = y(x);
|
|
1833
|
+
s.beginPath(), s.moveTo(b, c), s.lineTo(b, t - c), s.stroke();
|
|
1755
1834
|
}
|
|
1756
|
-
for (let
|
|
1757
|
-
const
|
|
1758
|
-
s.beginPath(), s.moveTo(
|
|
1835
|
+
for (let x = Math.ceil(n.yRange.min); x <= n.yRange.max; x++) {
|
|
1836
|
+
const b = f(x);
|
|
1837
|
+
s.beginPath(), s.moveTo(c, b), s.lineTo(e - c, b), s.stroke();
|
|
1759
1838
|
}
|
|
1760
1839
|
}
|
|
1761
1840
|
if (n.showAxes) {
|
|
1762
|
-
s.strokeStyle =
|
|
1763
|
-
const
|
|
1764
|
-
s.beginPath(), s.moveTo(
|
|
1765
|
-
const
|
|
1766
|
-
if (s.beginPath(), s.moveTo(
|
|
1767
|
-
s.fillStyle =
|
|
1768
|
-
for (let
|
|
1769
|
-
|
|
1770
|
-
for (let
|
|
1771
|
-
|
|
1841
|
+
s.strokeStyle = I("var(--nice-text, #333)", s.canvas), s.lineWidth = 1;
|
|
1842
|
+
const x = f(0);
|
|
1843
|
+
s.beginPath(), s.moveTo(c, x), s.lineTo(e - c, x), s.stroke();
|
|
1844
|
+
const b = y(0);
|
|
1845
|
+
if (s.beginPath(), s.moveTo(b, c), s.lineTo(b, t - c), s.stroke(), n.showLabels) {
|
|
1846
|
+
s.fillStyle = I("var(--nice-text, #333)", s.canvas), s.font = "12px sans-serif", s.textAlign = "center", s.fillText("x", e - c + 15, x + 4), s.fillText("y", b, c - 10), s.font = "10px sans-serif";
|
|
1847
|
+
for (let l = Math.ceil(n.xRange.min); l <= n.xRange.max; l++)
|
|
1848
|
+
l !== 0 && s.fillText(String(l), y(l), x + 15);
|
|
1849
|
+
for (let l = Math.ceil(n.yRange.min); l <= n.yRange.max; l++)
|
|
1850
|
+
l !== 0 && (s.textAlign = "right", s.fillText(String(l), b - 5, f(l) + 4));
|
|
1772
1851
|
}
|
|
1773
1852
|
}
|
|
1774
|
-
const
|
|
1775
|
-
for (const
|
|
1776
|
-
const
|
|
1777
|
-
s.strokeStyle =
|
|
1778
|
-
let
|
|
1779
|
-
switch (
|
|
1853
|
+
const C = i.isPlaying ? { [i.parameter]: i.currentValue } : {};
|
|
1854
|
+
for (const x of a.filter((b) => b.visible)) {
|
|
1855
|
+
const b = `rgb(${x.color.r},${x.color.g},${x.color.b})`;
|
|
1856
|
+
s.strokeStyle = b, s.lineWidth = x.lineWidth || 2;
|
|
1857
|
+
let l = [];
|
|
1858
|
+
switch (x.type) {
|
|
1780
1859
|
case "2d-function":
|
|
1781
|
-
|
|
1782
|
-
|
|
1860
|
+
l = o.compute2DFunction(
|
|
1861
|
+
x.expression,
|
|
1783
1862
|
n.xRange,
|
|
1784
|
-
|
|
1785
|
-
|
|
1863
|
+
x.resolution || 200,
|
|
1864
|
+
C
|
|
1786
1865
|
);
|
|
1787
1866
|
break;
|
|
1788
1867
|
case "2d-parametric":
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1868
|
+
l = o.compute2DParametric(
|
|
1869
|
+
x.expression,
|
|
1870
|
+
x.expressionY || "sin(t)",
|
|
1871
|
+
x.parameterRange || { min: 0, max: 2 * Math.PI },
|
|
1872
|
+
x.resolution || 200,
|
|
1873
|
+
C
|
|
1795
1874
|
);
|
|
1796
1875
|
break;
|
|
1797
1876
|
case "2d-polar":
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1877
|
+
l = o.compute2DPolar(
|
|
1878
|
+
x.expression,
|
|
1879
|
+
x.parameterRange || { min: 0, max: 2 * Math.PI },
|
|
1880
|
+
x.resolution || 200,
|
|
1881
|
+
C
|
|
1803
1882
|
);
|
|
1804
1883
|
break;
|
|
1805
1884
|
}
|
|
1806
|
-
if (
|
|
1885
|
+
if (l.length > 0) {
|
|
1807
1886
|
s.beginPath();
|
|
1808
|
-
let
|
|
1809
|
-
for (const
|
|
1810
|
-
const
|
|
1811
|
-
if (
|
|
1812
|
-
|
|
1887
|
+
let g = !1;
|
|
1888
|
+
for (const w of l) {
|
|
1889
|
+
const M = y(w.x), h = f(w.y);
|
|
1890
|
+
if (h < 0 || h > t) {
|
|
1891
|
+
g = !1;
|
|
1813
1892
|
continue;
|
|
1814
1893
|
}
|
|
1815
|
-
|
|
1894
|
+
g ? s.lineTo(M, h) : (s.moveTo(M, h), g = !0);
|
|
1816
1895
|
}
|
|
1817
1896
|
s.stroke();
|
|
1818
1897
|
}
|
|
1819
1898
|
}
|
|
1820
|
-
}, [
|
|
1899
|
+
}, [a, n, i, o, e, t]), /* @__PURE__ */ d("canvas", { ref: r, width: e, height: t, style: $.canvas });
|
|
1821
1900
|
}
|
|
1822
|
-
const
|
|
1901
|
+
const O = [
|
|
1823
1902
|
// Length
|
|
1824
1903
|
{ name: "Meter", symbol: "m", category: "Length", toBase: (e) => e, fromBase: (e) => e },
|
|
1825
1904
|
{
|
|
@@ -2089,12 +2168,12 @@ const UNITS = [
|
|
|
2089
2168
|
fromBase: (e) => e / 1099511627776
|
|
2090
2169
|
},
|
|
2091
2170
|
{ name: "Bit", symbol: "bit", category: "Data", toBase: (e) => e / 8, fromBase: (e) => e * 8 }
|
|
2092
|
-
],
|
|
2171
|
+
], z = {
|
|
2093
2172
|
create(e, t, r = 0) {
|
|
2094
|
-
const
|
|
2095
|
-
for (let
|
|
2096
|
-
|
|
2097
|
-
return { rows: e, cols: t, data:
|
|
2173
|
+
const o = [];
|
|
2174
|
+
for (let a = 0; a < e; a++)
|
|
2175
|
+
o.push(new Array(t).fill(r));
|
|
2176
|
+
return { rows: e, cols: t, data: o };
|
|
2098
2177
|
},
|
|
2099
2178
|
identity(e) {
|
|
2100
2179
|
const t = this.create(e, e);
|
|
@@ -2106,45 +2185,45 @@ const UNITS = [
|
|
|
2106
2185
|
if (e.rows !== t.rows || e.cols !== t.cols)
|
|
2107
2186
|
throw new Error("Matrix dimensions must match for addition");
|
|
2108
2187
|
const r = this.create(e.rows, e.cols);
|
|
2109
|
-
for (let
|
|
2110
|
-
for (let
|
|
2111
|
-
r.data[
|
|
2188
|
+
for (let o = 0; o < e.rows; o++)
|
|
2189
|
+
for (let a = 0; a < e.cols; a++)
|
|
2190
|
+
r.data[o][a] = e.data[o][a] + t.data[o][a];
|
|
2112
2191
|
return r;
|
|
2113
2192
|
},
|
|
2114
2193
|
subtract(e, t) {
|
|
2115
2194
|
if (e.rows !== t.rows || e.cols !== t.cols)
|
|
2116
2195
|
throw new Error("Matrix dimensions must match for subtraction");
|
|
2117
2196
|
const r = this.create(e.rows, e.cols);
|
|
2118
|
-
for (let
|
|
2119
|
-
for (let
|
|
2120
|
-
r.data[
|
|
2197
|
+
for (let o = 0; o < e.rows; o++)
|
|
2198
|
+
for (let a = 0; a < e.cols; a++)
|
|
2199
|
+
r.data[o][a] = e.data[o][a] - t.data[o][a];
|
|
2121
2200
|
return r;
|
|
2122
2201
|
},
|
|
2123
2202
|
multiply(e, t) {
|
|
2124
2203
|
if (e.cols !== t.rows)
|
|
2125
2204
|
throw new Error("Matrix A columns must equal Matrix B rows for multiplication");
|
|
2126
2205
|
const r = this.create(e.rows, t.cols);
|
|
2127
|
-
for (let
|
|
2128
|
-
for (let
|
|
2206
|
+
for (let o = 0; o < e.rows; o++)
|
|
2207
|
+
for (let a = 0; a < t.cols; a++) {
|
|
2129
2208
|
let n = 0;
|
|
2130
2209
|
for (let i = 0; i < e.cols; i++)
|
|
2131
|
-
n += e.data[
|
|
2132
|
-
r.data[
|
|
2210
|
+
n += e.data[o][i] * t.data[i][a];
|
|
2211
|
+
r.data[o][a] = n;
|
|
2133
2212
|
}
|
|
2134
2213
|
return r;
|
|
2135
2214
|
},
|
|
2136
2215
|
scalar(e, t) {
|
|
2137
2216
|
const r = this.create(e.rows, e.cols);
|
|
2138
|
-
for (let
|
|
2139
|
-
for (let
|
|
2140
|
-
r.data[
|
|
2217
|
+
for (let o = 0; o < e.rows; o++)
|
|
2218
|
+
for (let a = 0; a < e.cols; a++)
|
|
2219
|
+
r.data[o][a] = e.data[o][a] * t;
|
|
2141
2220
|
return r;
|
|
2142
2221
|
},
|
|
2143
2222
|
transpose(e) {
|
|
2144
2223
|
const t = this.create(e.cols, e.rows);
|
|
2145
2224
|
for (let r = 0; r < e.rows; r++)
|
|
2146
|
-
for (let
|
|
2147
|
-
t.data[
|
|
2225
|
+
for (let o = 0; o < e.cols; o++)
|
|
2226
|
+
t.data[o][r] = e.data[r][o];
|
|
2148
2227
|
return t;
|
|
2149
2228
|
},
|
|
2150
2229
|
determinant(e) {
|
|
@@ -2160,29 +2239,29 @@ const UNITS = [
|
|
|
2160
2239
|
return t;
|
|
2161
2240
|
},
|
|
2162
2241
|
minor(e, t, r) {
|
|
2163
|
-
const
|
|
2164
|
-
let
|
|
2242
|
+
const o = this.create(e.rows - 1, e.cols - 1);
|
|
2243
|
+
let a = 0;
|
|
2165
2244
|
for (let n = 0; n < e.rows; n++) {
|
|
2166
2245
|
if (n === t)
|
|
2167
2246
|
continue;
|
|
2168
2247
|
let i = 0;
|
|
2169
|
-
for (let
|
|
2170
|
-
|
|
2171
|
-
|
|
2248
|
+
for (let c = 0; c < e.cols; c++)
|
|
2249
|
+
c !== r && (o.data[a][i] = e.data[n][c], i++);
|
|
2250
|
+
a++;
|
|
2172
2251
|
}
|
|
2173
|
-
return
|
|
2252
|
+
return o;
|
|
2174
2253
|
},
|
|
2175
2254
|
inverse(e) {
|
|
2176
2255
|
const t = this.determinant(e);
|
|
2177
2256
|
if (t === 0)
|
|
2178
2257
|
throw new Error("Matrix is singular, cannot compute inverse");
|
|
2179
|
-
const r = e.rows,
|
|
2180
|
-
for (let
|
|
2258
|
+
const r = e.rows, o = this.create(r, r);
|
|
2259
|
+
for (let a = 0; a < r; a++)
|
|
2181
2260
|
for (let n = 0; n < r; n++) {
|
|
2182
|
-
const i = Math.pow(-1,
|
|
2183
|
-
|
|
2261
|
+
const i = Math.pow(-1, a + n), c = this.determinant(this.minor(e, a, n));
|
|
2262
|
+
o.data[n][a] = i * c;
|
|
2184
2263
|
}
|
|
2185
|
-
return this.scalar(
|
|
2264
|
+
return this.scalar(o, 1 / t);
|
|
2186
2265
|
},
|
|
2187
2266
|
trace(e) {
|
|
2188
2267
|
if (e.rows !== e.cols)
|
|
@@ -2195,17 +2274,17 @@ const UNITS = [
|
|
|
2195
2274
|
eigenvalues2x2(e) {
|
|
2196
2275
|
if (e.rows !== 2 || e.cols !== 2)
|
|
2197
2276
|
throw new Error("Only 2x2 matrices supported for eigenvalues");
|
|
2198
|
-
const t = e.data[0][0], r = e.data[0][1],
|
|
2199
|
-
if (
|
|
2277
|
+
const t = e.data[0][0], r = e.data[0][1], o = e.data[1][0], a = e.data[1][1], n = t + a, i = t * a - r * o, c = n * n - 4 * i;
|
|
2278
|
+
if (c < 0)
|
|
2200
2279
|
throw new Error("Complex eigenvalues not supported");
|
|
2201
|
-
const
|
|
2202
|
-
return [(n +
|
|
2280
|
+
const u = Math.sqrt(c);
|
|
2281
|
+
return [(n + u) / 2, (n - u) / 2];
|
|
2203
2282
|
},
|
|
2204
2283
|
toString(e, t = 4) {
|
|
2205
|
-
return e.data.map((r) => "[ " + r.map((
|
|
2284
|
+
return e.data.map((r) => "[ " + r.map((o) => o.toFixed(t).padStart(10)).join(" ") + " ]").join(`
|
|
2206
2285
|
`);
|
|
2207
2286
|
}
|
|
2208
|
-
},
|
|
2287
|
+
}, te = {
|
|
2209
2288
|
/** Numerical derivative at a point */
|
|
2210
2289
|
derivative(e, t, r = 1e-7) {
|
|
2211
2290
|
return (e(t + r) - e(t - r)) / (2 * r);
|
|
@@ -2215,27 +2294,27 @@ const UNITS = [
|
|
|
2215
2294
|
return (e(t + r) - 2 * e(t) + e(t - r)) / (r * r);
|
|
2216
2295
|
},
|
|
2217
2296
|
/** Numerical integration using Simpson's rule */
|
|
2218
|
-
integrate(e, t, r,
|
|
2219
|
-
|
|
2220
|
-
const
|
|
2297
|
+
integrate(e, t, r, o = 1e3) {
|
|
2298
|
+
o % 2 !== 0 && o++;
|
|
2299
|
+
const a = (r - t) / o;
|
|
2221
2300
|
let n = e(t) + e(r);
|
|
2222
|
-
for (let i = 1; i <
|
|
2223
|
-
const
|
|
2224
|
-
n += i % 2 === 0 ? 2 * e(
|
|
2301
|
+
for (let i = 1; i < o; i++) {
|
|
2302
|
+
const c = t + i * a;
|
|
2303
|
+
n += i % 2 === 0 ? 2 * e(c) : 4 * e(c);
|
|
2225
2304
|
}
|
|
2226
|
-
return
|
|
2305
|
+
return a / 3 * n;
|
|
2227
2306
|
},
|
|
2228
2307
|
/** Find root using Newton-Raphson method */
|
|
2229
|
-
findRoot(e, t, r = 1e-10,
|
|
2230
|
-
let
|
|
2231
|
-
for (let n = 0; n <
|
|
2232
|
-
const i = e(
|
|
2308
|
+
findRoot(e, t, r = 1e-10, o = 100) {
|
|
2309
|
+
let a = t;
|
|
2310
|
+
for (let n = 0; n < o; n++) {
|
|
2311
|
+
const i = e(a);
|
|
2233
2312
|
if (Math.abs(i) < r)
|
|
2234
|
-
return
|
|
2235
|
-
const
|
|
2236
|
-
if (
|
|
2313
|
+
return a;
|
|
2314
|
+
const c = this.derivative(e, a);
|
|
2315
|
+
if (c === 0)
|
|
2237
2316
|
throw new Error("Derivative is zero, Newton-Raphson failed");
|
|
2238
|
-
|
|
2317
|
+
a = a - i / c;
|
|
2239
2318
|
}
|
|
2240
2319
|
throw new Error("Newton-Raphson did not converge");
|
|
2241
2320
|
},
|
|
@@ -2247,13 +2326,13 @@ const UNITS = [
|
|
|
2247
2326
|
return "1";
|
|
2248
2327
|
const t = e.match(/^x\^(\d+)$/);
|
|
2249
2328
|
if (t) {
|
|
2250
|
-
const
|
|
2251
|
-
return
|
|
2329
|
+
const o = parseInt(t[1], 10);
|
|
2330
|
+
return o === 1 ? "1" : o === 2 ? "2*x" : `${o}*x^${o - 1}`;
|
|
2252
2331
|
}
|
|
2253
2332
|
const r = e.match(/^(-?\d+\.?\d*)\*x\^(\d+)$/);
|
|
2254
2333
|
if (r) {
|
|
2255
|
-
const
|
|
2256
|
-
return
|
|
2334
|
+
const o = parseFloat(r[1]), a = parseInt(r[2], 10), n = o * a;
|
|
2335
|
+
return a === 1 ? String(n) : a === 2 ? `${n}*x` : `${n}*x^${a - 1}`;
|
|
2257
2336
|
}
|
|
2258
2337
|
return e === "sin(x)" ? "cos(x)" : e === "cos(x)" ? "-sin(x)" : e === "e^x" || e === "exp(x)" ? "e^x" : e === "ln(x)" ? "1/x" : `d/dx(${e})`;
|
|
2259
2338
|
},
|
|
@@ -2272,48 +2351,64 @@ const UNITS = [
|
|
|
2272
2351
|
},
|
|
2273
2352
|
/** Solve quadratic equation ax² + bx + c = 0 */
|
|
2274
2353
|
solveQuadratic(e, t, r) {
|
|
2275
|
-
const
|
|
2276
|
-
if (
|
|
2354
|
+
const o = t * t - 4 * e * r;
|
|
2355
|
+
if (o < 0)
|
|
2277
2356
|
throw new Error("No real solutions (complex roots)");
|
|
2278
|
-
if (
|
|
2357
|
+
if (o === 0)
|
|
2279
2358
|
return [-t / (2 * e)];
|
|
2280
|
-
const
|
|
2281
|
-
return [(-t +
|
|
2359
|
+
const a = Math.sqrt(o);
|
|
2360
|
+
return [(-t + a) / (2 * e), (-t - a) / (2 * e)];
|
|
2282
2361
|
}
|
|
2283
2362
|
};
|
|
2284
|
-
class
|
|
2285
|
-
constructor(
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2363
|
+
class Le {
|
|
2364
|
+
constructor(t = {}) {
|
|
2365
|
+
T(this, "history", []);
|
|
2366
|
+
T(this, "memory", 0);
|
|
2367
|
+
T(this, "variables", /* @__PURE__ */ new Map());
|
|
2368
|
+
T(this, "config");
|
|
2290
2369
|
this.config = {
|
|
2291
|
-
precision:
|
|
2292
|
-
angleUnit:
|
|
2370
|
+
precision: t.precision ?? 12,
|
|
2371
|
+
angleUnit: t.angleUnit ?? "rad"
|
|
2293
2372
|
};
|
|
2294
2373
|
}
|
|
2295
|
-
/**
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2374
|
+
/**
|
|
2375
|
+
* Evaluate an expression — parsed by {@link ExpressionParser}, never run as code (until 1.2.0 a
|
|
2376
|
+
* chain of regex replacements fed `new Function`: `asin` came out as `aMath.sin`, `ceil` lost
|
|
2377
|
+
* its `e` to Euler's number, a result in exponent notation summed wrongly, and any text ran).
|
|
2378
|
+
* `log` is base 10 like the key, `ln` natural; trig functions follow `angleUnit`.
|
|
2379
|
+
*/
|
|
2380
|
+
evaluate(t) {
|
|
2381
|
+
const r = this.config.angleUnit === "deg", o = (c) => r ? c * Math.PI / 180 : c, a = (c) => r ? c * 180 / Math.PI : c, n = new ie({
|
|
2382
|
+
strict: !0,
|
|
2383
|
+
ignoreCase: !0,
|
|
2384
|
+
functions: {
|
|
2385
|
+
log: Math.log10,
|
|
2386
|
+
sin: (c) => Math.sin(o(c)),
|
|
2387
|
+
cos: (c) => Math.cos(o(c)),
|
|
2388
|
+
tan: (c) => Math.tan(o(c)),
|
|
2389
|
+
asin: (c) => a(Math.asin(c)),
|
|
2390
|
+
acos: (c) => a(Math.acos(c)),
|
|
2391
|
+
atan: (c) => a(Math.atan(c))
|
|
2392
|
+
}
|
|
2393
|
+
});
|
|
2394
|
+
let i;
|
|
2300
2395
|
try {
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
return result;
|
|
2305
|
-
} catch (e) {
|
|
2306
|
-
throw new Error(`Invalid expression: ${e.message}`);
|
|
2396
|
+
i = n.parse(t)(Object.fromEntries(this.variables));
|
|
2397
|
+
} catch (c) {
|
|
2398
|
+
throw new Error(`Invalid expression: ${c.message}`);
|
|
2307
2399
|
}
|
|
2400
|
+
if (!Number.isFinite(i))
|
|
2401
|
+
throw new Error("Invalid expression: Invalid result");
|
|
2402
|
+
return i;
|
|
2308
2403
|
}
|
|
2309
2404
|
/** Add to history */
|
|
2310
|
-
addHistory(
|
|
2405
|
+
addHistory(t, r, o) {
|
|
2311
2406
|
this.history.unshift({
|
|
2312
2407
|
id: Date.now().toString(36),
|
|
2313
|
-
expression:
|
|
2314
|
-
result:
|
|
2408
|
+
expression: t,
|
|
2409
|
+
result: r,
|
|
2315
2410
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2316
|
-
mode:
|
|
2411
|
+
mode: o
|
|
2317
2412
|
}), this.history.length > 100 && this.history.pop();
|
|
2318
2413
|
}
|
|
2319
2414
|
/** Get history */
|
|
@@ -2325,67 +2420,67 @@ class CalculatorService {
|
|
|
2325
2420
|
this.history = [];
|
|
2326
2421
|
}
|
|
2327
2422
|
/** Memory operations */
|
|
2328
|
-
memoryStore(
|
|
2329
|
-
this.memory =
|
|
2423
|
+
memoryStore(t) {
|
|
2424
|
+
this.memory = t;
|
|
2330
2425
|
}
|
|
2331
2426
|
memoryRecall() {
|
|
2332
2427
|
return this.memory;
|
|
2333
2428
|
}
|
|
2334
|
-
memoryAdd(
|
|
2335
|
-
this.memory +=
|
|
2429
|
+
memoryAdd(t) {
|
|
2430
|
+
this.memory += t;
|
|
2336
2431
|
}
|
|
2337
2432
|
memoryClear() {
|
|
2338
2433
|
this.memory = 0;
|
|
2339
2434
|
}
|
|
2340
2435
|
/** Variable operations */
|
|
2341
|
-
setVariable(
|
|
2342
|
-
this.variables.set(
|
|
2436
|
+
setVariable(t, r) {
|
|
2437
|
+
this.variables.set(t, r);
|
|
2343
2438
|
}
|
|
2344
|
-
getVariable(
|
|
2345
|
-
return this.variables.get(
|
|
2439
|
+
getVariable(t) {
|
|
2440
|
+
return this.variables.get(t);
|
|
2346
2441
|
}
|
|
2347
2442
|
/** Convert between number bases */
|
|
2348
|
-
convertBase(
|
|
2349
|
-
const a = { BIN: 2, OCT: 8, DEC: 10, HEX: 16 },
|
|
2350
|
-
if (isNaN(
|
|
2443
|
+
convertBase(t, r, o) {
|
|
2444
|
+
const a = { BIN: 2, OCT: 8, DEC: 10, HEX: 16 }, n = parseInt(t, a[r]);
|
|
2445
|
+
if (isNaN(n))
|
|
2351
2446
|
throw new Error("Invalid number for base conversion");
|
|
2352
|
-
return
|
|
2447
|
+
return n.toString(a[o]).toUpperCase();
|
|
2353
2448
|
}
|
|
2354
2449
|
/** Convert units */
|
|
2355
|
-
convertUnits(
|
|
2356
|
-
const a =
|
|
2357
|
-
if (!a || !
|
|
2450
|
+
convertUnits(t, r, o) {
|
|
2451
|
+
const a = O.find((c) => c.symbol === r), n = O.find((c) => c.symbol === o);
|
|
2452
|
+
if (!a || !n)
|
|
2358
2453
|
throw new Error("Unknown unit");
|
|
2359
|
-
if (a.category !==
|
|
2454
|
+
if (a.category !== n.category)
|
|
2360
2455
|
throw new Error("Cannot convert between different unit categories");
|
|
2361
|
-
const
|
|
2362
|
-
return
|
|
2456
|
+
const i = a.toBase(t);
|
|
2457
|
+
return n.fromBase(i);
|
|
2363
2458
|
}
|
|
2364
2459
|
/** Get units by category */
|
|
2365
|
-
getUnitsByCategory(
|
|
2366
|
-
return
|
|
2460
|
+
getUnitsByCategory(t) {
|
|
2461
|
+
return O.filter((r) => r.category === t);
|
|
2367
2462
|
}
|
|
2368
2463
|
/** Get all unit categories */
|
|
2369
2464
|
getUnitCategories() {
|
|
2370
|
-
return [...new Set(
|
|
2465
|
+
return [...new Set(O.map((t) => t.category))];
|
|
2371
2466
|
}
|
|
2372
2467
|
/** Format number with precision */
|
|
2373
|
-
format(
|
|
2374
|
-
const
|
|
2375
|
-
return Math.abs(
|
|
2468
|
+
format(t) {
|
|
2469
|
+
const r = this.config.precision;
|
|
2470
|
+
return Math.abs(t) < 1e-10 ? "0" : Math.abs(t) > 1e10 || Math.abs(t) < 1e-6 ? t.toExponential(r) : parseFloat(t.toPrecision(r)).toString();
|
|
2376
2471
|
}
|
|
2377
2472
|
}
|
|
2378
|
-
function
|
|
2379
|
-
return new
|
|
2473
|
+
function ot(e) {
|
|
2474
|
+
return new Le(e);
|
|
2380
2475
|
}
|
|
2381
|
-
const
|
|
2382
|
-
function
|
|
2383
|
-
const e =
|
|
2476
|
+
const ce = /* @__PURE__ */ F(null);
|
|
2477
|
+
function N() {
|
|
2478
|
+
const e = j(ce);
|
|
2384
2479
|
if (!e)
|
|
2385
2480
|
throw new Error("useCalculator must be used within CalculatorProvider");
|
|
2386
2481
|
return e;
|
|
2387
2482
|
}
|
|
2388
|
-
const
|
|
2483
|
+
const B = {
|
|
2389
2484
|
container: {
|
|
2390
2485
|
width: "400px",
|
|
2391
2486
|
fontFamily: "'Inter', sans-serif",
|
|
@@ -2430,7 +2525,7 @@ const styles$1 = {
|
|
|
2430
2525
|
padding: "20px",
|
|
2431
2526
|
border: "none",
|
|
2432
2527
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2433
|
-
color: "var(--nice-
|
|
2528
|
+
color: "var(--nice-color-white, #fff)",
|
|
2434
2529
|
fontSize: "18px",
|
|
2435
2530
|
cursor: "pointer",
|
|
2436
2531
|
transition: "background-color 0.1s"
|
|
@@ -2440,52 +2535,52 @@ const styles$1 = {
|
|
|
2440
2535
|
color: "var(--nice-text, #000)"
|
|
2441
2536
|
},
|
|
2442
2537
|
keyFunction: {
|
|
2443
|
-
backgroundColor: "#505050"
|
|
2538
|
+
backgroundColor: "var(--nice-bg-tertiary, #505050)"
|
|
2444
2539
|
}
|
|
2445
2540
|
};
|
|
2446
|
-
function
|
|
2541
|
+
function at({
|
|
2447
2542
|
service: e,
|
|
2448
2543
|
className: t,
|
|
2449
2544
|
style: r
|
|
2450
2545
|
}) {
|
|
2451
|
-
const [
|
|
2452
|
-
(
|
|
2453
|
-
s && /[0-9.]/.test(
|
|
2546
|
+
const [o, a] = P("0"), [n, i] = P("standard"), [c, u] = P([]), [s, p] = P(!1), m = R(
|
|
2547
|
+
(x) => {
|
|
2548
|
+
s && /[0-9.]/.test(x) ? (a(x), p(!1)) : (a((b) => b === "0" && x !== "." ? x : b + x), p(!1));
|
|
2454
2549
|
},
|
|
2455
2550
|
[s]
|
|
2456
|
-
), y =
|
|
2457
|
-
|
|
2458
|
-
}, []),
|
|
2551
|
+
), y = R(() => {
|
|
2552
|
+
a("0"), p(!1);
|
|
2553
|
+
}, []), f = R(() => {
|
|
2459
2554
|
try {
|
|
2460
|
-
const
|
|
2461
|
-
e.addHistory(
|
|
2555
|
+
const x = e.evaluate(o), b = e.format(x);
|
|
2556
|
+
e.addHistory(o, b, n), u(e.getHistory()), a(b), p(!0);
|
|
2462
2557
|
} catch {
|
|
2463
|
-
|
|
2558
|
+
a("Error"), p(!0);
|
|
2464
2559
|
}
|
|
2465
|
-
}, [
|
|
2560
|
+
}, [o, n, e]), C = {
|
|
2466
2561
|
service: e,
|
|
2467
|
-
display:
|
|
2468
|
-
setDisplay:
|
|
2562
|
+
display: o,
|
|
2563
|
+
setDisplay: a,
|
|
2469
2564
|
mode: n,
|
|
2470
2565
|
setMode: i,
|
|
2471
|
-
history:
|
|
2472
|
-
calculate:
|
|
2473
|
-
appendDigit:
|
|
2566
|
+
history: c,
|
|
2567
|
+
calculate: f,
|
|
2568
|
+
appendDigit: m,
|
|
2474
2569
|
clear: y
|
|
2475
2570
|
};
|
|
2476
|
-
return /* @__PURE__ */
|
|
2477
|
-
/* @__PURE__ */
|
|
2478
|
-
/* @__PURE__ */
|
|
2479
|
-
n === "standard" && /* @__PURE__ */
|
|
2480
|
-
n === "scientific" && /* @__PURE__ */
|
|
2481
|
-
n === "programmer" && /* @__PURE__ */
|
|
2482
|
-
n === "matrix" && /* @__PURE__ */
|
|
2483
|
-
n === "calculus" && /* @__PURE__ */
|
|
2484
|
-
n === "units" && /* @__PURE__ */
|
|
2571
|
+
return /* @__PURE__ */ d(ce.Provider, { value: C, children: /* @__PURE__ */ v("div", { className: t, style: { ...B.container, ...r }, children: [
|
|
2572
|
+
/* @__PURE__ */ d(De, {}),
|
|
2573
|
+
/* @__PURE__ */ d(qe, {}),
|
|
2574
|
+
n === "standard" && /* @__PURE__ */ d(le, {}),
|
|
2575
|
+
n === "scientific" && /* @__PURE__ */ d(Ne, {}),
|
|
2576
|
+
n === "programmer" && /* @__PURE__ */ d(Xe, {}),
|
|
2577
|
+
n === "matrix" && /* @__PURE__ */ d(Ge, {}),
|
|
2578
|
+
n === "calculus" && /* @__PURE__ */ d(je, {}),
|
|
2579
|
+
n === "units" && /* @__PURE__ */ d(Fe, {})
|
|
2485
2580
|
] }) });
|
|
2486
2581
|
}
|
|
2487
|
-
function
|
|
2488
|
-
const { mode: e, setMode: t } =
|
|
2582
|
+
function De() {
|
|
2583
|
+
const { mode: e, setMode: t } = N(), r = [
|
|
2489
2584
|
{ id: "standard", label: "Standard" },
|
|
2490
2585
|
{ id: "scientific", label: "Scientific" },
|
|
2491
2586
|
{ id: "programmer", label: "Programmer" },
|
|
@@ -2493,61 +2588,61 @@ function ModeSelector() {
|
|
|
2493
2588
|
{ id: "calculus", label: "Calculus" },
|
|
2494
2589
|
{ id: "units", label: "Units" }
|
|
2495
2590
|
];
|
|
2496
|
-
return /* @__PURE__ */
|
|
2591
|
+
return /* @__PURE__ */ d("div", { style: B.modeSelector, children: r.map((o) => /* @__PURE__ */ d(
|
|
2497
2592
|
"button",
|
|
2498
2593
|
{
|
|
2499
|
-
onClick: () => t(
|
|
2594
|
+
onClick: () => t(o.id),
|
|
2500
2595
|
style: {
|
|
2501
|
-
...
|
|
2502
|
-
backgroundColor: e ===
|
|
2503
|
-
color: e ===
|
|
2596
|
+
...B.modeButton,
|
|
2597
|
+
backgroundColor: e === o.id ? "var(--nice-primary-hover, #1976d2)" : "transparent",
|
|
2598
|
+
color: e === o.id ? "var(--nice-color-white, #fff)" : "var(--nice-text-secondary, #888)"
|
|
2504
2599
|
},
|
|
2505
|
-
children:
|
|
2600
|
+
children: o.label
|
|
2506
2601
|
},
|
|
2507
|
-
|
|
2602
|
+
o.id
|
|
2508
2603
|
)) });
|
|
2509
2604
|
}
|
|
2510
|
-
function
|
|
2511
|
-
const { display: e } =
|
|
2512
|
-
return /* @__PURE__ */
|
|
2605
|
+
function qe() {
|
|
2606
|
+
const { display: e } = N();
|
|
2607
|
+
return /* @__PURE__ */ d("div", { style: B.display, children: /* @__PURE__ */ d("div", { style: B.displayText, children: e }) });
|
|
2513
2608
|
}
|
|
2514
|
-
function
|
|
2515
|
-
const { appendDigit: e, clear: t, calculate: r, setDisplay:
|
|
2516
|
-
{ label: "AC", action: t, style:
|
|
2609
|
+
function le() {
|
|
2610
|
+
const { appendDigit: e, clear: t, calculate: r, setDisplay: o, display: a } = N(), n = [
|
|
2611
|
+
{ label: "AC", action: t, style: B.keyFunction },
|
|
2517
2612
|
{
|
|
2518
2613
|
label: "±",
|
|
2519
|
-
action: () => a
|
|
2520
|
-
style:
|
|
2614
|
+
action: () => o(a.startsWith("-") ? a.slice(1) : "-" + a),
|
|
2615
|
+
style: B.keyFunction
|
|
2521
2616
|
},
|
|
2522
|
-
{ label: "%", action: () => e("/100"), style:
|
|
2523
|
-
{ label: "÷", action: () => e("/"), style:
|
|
2617
|
+
{ label: "%", action: () => e("/100"), style: B.keyFunction },
|
|
2618
|
+
{ label: "÷", action: () => e("/"), style: B.keyOperator },
|
|
2524
2619
|
{ label: "7", action: () => e("7") },
|
|
2525
2620
|
{ label: "8", action: () => e("8") },
|
|
2526
2621
|
{ label: "9", action: () => e("9") },
|
|
2527
|
-
{ label: "×", action: () => e("*"), style:
|
|
2622
|
+
{ label: "×", action: () => e("*"), style: B.keyOperator },
|
|
2528
2623
|
{ label: "4", action: () => e("4") },
|
|
2529
2624
|
{ label: "5", action: () => e("5") },
|
|
2530
2625
|
{ label: "6", action: () => e("6") },
|
|
2531
|
-
{ label: "−", action: () => e("-"), style:
|
|
2626
|
+
{ label: "−", action: () => e("-"), style: B.keyOperator },
|
|
2532
2627
|
{ label: "1", action: () => e("1") },
|
|
2533
2628
|
{ label: "2", action: () => e("2") },
|
|
2534
2629
|
{ label: "3", action: () => e("3") },
|
|
2535
|
-
{ label: "+", action: () => e("+"), style:
|
|
2630
|
+
{ label: "+", action: () => e("+"), style: B.keyOperator },
|
|
2536
2631
|
{ label: "0", action: () => e("0") },
|
|
2537
2632
|
{ label: ".", action: () => e(".") },
|
|
2538
|
-
{ label: "⌫", action: () => a
|
|
2539
|
-
{ label: "=", action: r, style:
|
|
2633
|
+
{ label: "⌫", action: () => o(a.length > 1 ? a.slice(0, -1) : "0") },
|
|
2634
|
+
{ label: "=", action: r, style: B.keyOperator }
|
|
2540
2635
|
];
|
|
2541
|
-
return /* @__PURE__ */
|
|
2636
|
+
return /* @__PURE__ */ d("div", { style: B.keypad, children: n.map((i, c) => /* @__PURE__ */ d("button", { onClick: i.action, style: { ...B.key, ...i.style || {} }, children: i.label }, c)) });
|
|
2542
2637
|
}
|
|
2543
|
-
function
|
|
2638
|
+
function Ne() {
|
|
2544
2639
|
const {
|
|
2545
2640
|
appendDigit: e,
|
|
2546
2641
|
clear: t,
|
|
2547
2642
|
calculate: r,
|
|
2548
|
-
setDisplay:
|
|
2549
|
-
display:
|
|
2550
|
-
} =
|
|
2643
|
+
setDisplay: o,
|
|
2644
|
+
display: a
|
|
2645
|
+
} = N(), n = [
|
|
2551
2646
|
{ label: "sin", action: () => e("sin(") },
|
|
2552
2647
|
{ label: "cos", action: () => e("cos(") },
|
|
2553
2648
|
{ label: "tan", action: () => e("tan(") },
|
|
@@ -2559,37 +2654,37 @@ function ScientificKeypad() {
|
|
|
2559
2654
|
{ label: "xʸ", action: () => e("^") },
|
|
2560
2655
|
{ label: "√", action: () => e("sqrt(") },
|
|
2561
2656
|
{ label: "eˣ", action: () => e("exp(") }
|
|
2562
|
-
],
|
|
2657
|
+
], c = [
|
|
2563
2658
|
{ label: "(", action: () => e("(") },
|
|
2564
2659
|
{ label: ")", action: () => e(")") },
|
|
2565
2660
|
{ label: "π", action: () => e("π") },
|
|
2566
2661
|
{ label: "e", action: () => e("e") },
|
|
2567
2662
|
{ label: "AC", action: t }
|
|
2568
2663
|
];
|
|
2569
|
-
return /* @__PURE__ */
|
|
2570
|
-
/* @__PURE__ */
|
|
2664
|
+
return /* @__PURE__ */ v("div", { children: [
|
|
2665
|
+
/* @__PURE__ */ d("div", { style: { ...B.keypad, gridTemplateColumns: "repeat(5, 1fr)" }, children: [...n, ...i, ...c].map((u, s) => /* @__PURE__ */ d(
|
|
2571
2666
|
"button",
|
|
2572
2667
|
{
|
|
2573
|
-
onClick:
|
|
2574
|
-
style: { ...
|
|
2575
|
-
children:
|
|
2668
|
+
onClick: u.action,
|
|
2669
|
+
style: { ...B.key, ...B.keyFunction, padding: "12px" },
|
|
2670
|
+
children: u.label
|
|
2576
2671
|
},
|
|
2577
2672
|
s
|
|
2578
2673
|
)) }),
|
|
2579
|
-
/* @__PURE__ */
|
|
2674
|
+
/* @__PURE__ */ d(le, {})
|
|
2580
2675
|
] });
|
|
2581
2676
|
}
|
|
2582
|
-
function
|
|
2583
|
-
const { display: e, setDisplay: t, service: r } =
|
|
2677
|
+
function Xe() {
|
|
2678
|
+
const { display: e, setDisplay: t, service: r } = N(), [o, a] = P("DEC"), n = (c) => {
|
|
2584
2679
|
try {
|
|
2585
|
-
const
|
|
2586
|
-
t(
|
|
2680
|
+
const u = r.convertBase(e, o, c);
|
|
2681
|
+
t(u), a(c);
|
|
2587
2682
|
} catch {
|
|
2588
2683
|
t("Error");
|
|
2589
2684
|
}
|
|
2590
|
-
}, i =
|
|
2591
|
-
return /* @__PURE__ */
|
|
2592
|
-
/* @__PURE__ */
|
|
2685
|
+
}, i = o === "HEX" ? ["A", "B", "C", "D", "E", "F"] : [];
|
|
2686
|
+
return /* @__PURE__ */ v("div", { children: [
|
|
2687
|
+
/* @__PURE__ */ d(
|
|
2593
2688
|
"div",
|
|
2594
2689
|
{
|
|
2595
2690
|
style: {
|
|
@@ -2598,35 +2693,35 @@ function ProgrammerKeypad() {
|
|
|
2598
2693
|
padding: "8px",
|
|
2599
2694
|
backgroundColor: "var(--nice-bg-secondary, #252525)"
|
|
2600
2695
|
},
|
|
2601
|
-
children: ["BIN", "OCT", "DEC", "HEX"].map((
|
|
2696
|
+
children: ["BIN", "OCT", "DEC", "HEX"].map((c) => /* @__PURE__ */ d(
|
|
2602
2697
|
"button",
|
|
2603
2698
|
{
|
|
2604
|
-
onClick: () => n(
|
|
2699
|
+
onClick: () => n(c),
|
|
2605
2700
|
style: {
|
|
2606
2701
|
flex: 1,
|
|
2607
2702
|
padding: "8px",
|
|
2608
2703
|
border: "none",
|
|
2609
2704
|
borderRadius: "4px",
|
|
2610
|
-
backgroundColor:
|
|
2611
|
-
color: "var(--nice-
|
|
2705
|
+
backgroundColor: o === c ? "var(--nice-primary-hover, #1976d2)" : "var(--nice-border, #3c3c3c)",
|
|
2706
|
+
color: "var(--nice-color-white, #fff)",
|
|
2612
2707
|
cursor: "pointer"
|
|
2613
2708
|
},
|
|
2614
|
-
children:
|
|
2709
|
+
children: c
|
|
2615
2710
|
},
|
|
2616
|
-
|
|
2711
|
+
c
|
|
2617
2712
|
))
|
|
2618
2713
|
}
|
|
2619
2714
|
),
|
|
2620
|
-
i.length > 0 && /* @__PURE__ */
|
|
2715
|
+
i.length > 0 && /* @__PURE__ */ d("div", { style: { ...B.keypad, gridTemplateColumns: "repeat(6, 1fr)" }, children: i.map((c) => /* @__PURE__ */ d(
|
|
2621
2716
|
"button",
|
|
2622
2717
|
{
|
|
2623
|
-
onClick: () => t(e === "0" ?
|
|
2624
|
-
style:
|
|
2625
|
-
children:
|
|
2718
|
+
onClick: () => t(e === "0" ? c : e + c),
|
|
2719
|
+
style: B.key,
|
|
2720
|
+
children: c
|
|
2626
2721
|
},
|
|
2627
|
-
|
|
2722
|
+
c
|
|
2628
2723
|
)) }),
|
|
2629
|
-
/* @__PURE__ */
|
|
2724
|
+
/* @__PURE__ */ d("div", { style: { ...B.keypad, gridTemplateColumns: "repeat(4, 1fr)" }, children: [
|
|
2630
2725
|
"7",
|
|
2631
2726
|
"8",
|
|
2632
2727
|
"9",
|
|
@@ -2643,63 +2738,63 @@ function ProgrammerKeypad() {
|
|
|
2643
2738
|
"NOT",
|
|
2644
2739
|
"<<",
|
|
2645
2740
|
">>"
|
|
2646
|
-
].map((
|
|
2647
|
-
const
|
|
2648
|
-
return /* @__PURE__ */
|
|
2741
|
+
].map((c) => {
|
|
2742
|
+
const u = ["AND", "OR", "XOR", "NOT", "<<", ">>"].includes(c);
|
|
2743
|
+
return /* @__PURE__ */ d(
|
|
2649
2744
|
"button",
|
|
2650
2745
|
{
|
|
2651
|
-
onClick: () => t(e === "0" ?
|
|
2652
|
-
style: { ...
|
|
2653
|
-
children:
|
|
2746
|
+
onClick: () => t(e === "0" ? c : e + c),
|
|
2747
|
+
style: { ...B.key, ...u ? B.keyFunction : {} },
|
|
2748
|
+
children: c
|
|
2654
2749
|
},
|
|
2655
|
-
|
|
2750
|
+
c
|
|
2656
2751
|
);
|
|
2657
2752
|
}) })
|
|
2658
2753
|
] });
|
|
2659
2754
|
}
|
|
2660
|
-
function
|
|
2661
|
-
const { t: e } =
|
|
2662
|
-
const
|
|
2663
|
-
|
|
2664
|
-
},
|
|
2665
|
-
{ label: "A + B", fn: () =>
|
|
2666
|
-
{ label: "A - B", fn: () =>
|
|
2667
|
-
{ label: "A × B", fn: () =>
|
|
2668
|
-
{ label: "det(A)", fn: () =>
|
|
2669
|
-
{ label: "Aᵀ", fn: () =>
|
|
2670
|
-
{ label: "A⁻¹", fn: () =>
|
|
2755
|
+
function Ge() {
|
|
2756
|
+
const { t: e } = L(), [t, r] = P(z.create(2, 2)), [o, a] = P(z.create(2, 2)), [n, i] = P(""), c = (s, p, m, y, f) => {
|
|
2757
|
+
const C = { ...s, data: s.data.map((x) => [...x]) };
|
|
2758
|
+
C.data[m][y] = parseFloat(f) || 0, p(C);
|
|
2759
|
+
}, u = [
|
|
2760
|
+
{ label: "A + B", fn: () => z.toString(z.add(t, o)) },
|
|
2761
|
+
{ label: "A - B", fn: () => z.toString(z.subtract(t, o)) },
|
|
2762
|
+
{ label: "A × B", fn: () => z.toString(z.multiply(t, o)) },
|
|
2763
|
+
{ label: "det(A)", fn: () => z.determinant(t).toFixed(4) },
|
|
2764
|
+
{ label: "Aᵀ", fn: () => z.toString(z.transpose(t)) },
|
|
2765
|
+
{ label: "A⁻¹", fn: () => z.toString(z.inverse(t)) }
|
|
2671
2766
|
];
|
|
2672
|
-
return /* @__PURE__ */
|
|
2673
|
-
/* @__PURE__ */
|
|
2674
|
-
/* @__PURE__ */
|
|
2675
|
-
/* @__PURE__ */
|
|
2676
|
-
/* @__PURE__ */
|
|
2677
|
-
|
|
2767
|
+
return /* @__PURE__ */ v("div", { style: { padding: "12px", backgroundColor: "var(--nice-bg-secondary, #252525)" }, children: [
|
|
2768
|
+
/* @__PURE__ */ v("div", { style: { display: "flex", gap: "12px", marginBottom: "12px" }, children: [
|
|
2769
|
+
/* @__PURE__ */ v("div", { children: [
|
|
2770
|
+
/* @__PURE__ */ d("div", { style: { color: "var(--nice-text-secondary, #888)", marginBottom: "4px" }, children: e("calculator.matrixA", "Matrix A") }),
|
|
2771
|
+
/* @__PURE__ */ d(
|
|
2772
|
+
re,
|
|
2678
2773
|
{
|
|
2679
2774
|
matrix: t,
|
|
2680
|
-
onChange: (s,
|
|
2775
|
+
onChange: (s, p, m) => c(t, r, s, p, m)
|
|
2681
2776
|
}
|
|
2682
2777
|
)
|
|
2683
2778
|
] }),
|
|
2684
|
-
/* @__PURE__ */
|
|
2685
|
-
/* @__PURE__ */
|
|
2686
|
-
/* @__PURE__ */
|
|
2687
|
-
|
|
2779
|
+
/* @__PURE__ */ v("div", { children: [
|
|
2780
|
+
/* @__PURE__ */ d("div", { style: { color: "var(--nice-text-secondary, #888)", marginBottom: "4px" }, children: e("calculator.matrixB", "Matrix B") }),
|
|
2781
|
+
/* @__PURE__ */ d(
|
|
2782
|
+
re,
|
|
2688
2783
|
{
|
|
2689
|
-
matrix:
|
|
2690
|
-
onChange: (s,
|
|
2784
|
+
matrix: o,
|
|
2785
|
+
onChange: (s, p, m) => c(o, a, s, p, m)
|
|
2691
2786
|
}
|
|
2692
2787
|
)
|
|
2693
2788
|
] })
|
|
2694
2789
|
] }),
|
|
2695
|
-
/* @__PURE__ */
|
|
2790
|
+
/* @__PURE__ */ d("div", { style: { display: "flex", gap: "4px", flexWrap: "wrap", marginBottom: "12px" }, children: u.map((s) => /* @__PURE__ */ d(
|
|
2696
2791
|
"button",
|
|
2697
2792
|
{
|
|
2698
2793
|
onClick: () => {
|
|
2699
2794
|
try {
|
|
2700
2795
|
i(s.fn());
|
|
2701
|
-
} catch (
|
|
2702
|
-
i(
|
|
2796
|
+
} catch (p) {
|
|
2797
|
+
i(p.message);
|
|
2703
2798
|
}
|
|
2704
2799
|
},
|
|
2705
2800
|
style: {
|
|
@@ -2714,7 +2809,7 @@ function MatrixMode() {
|
|
|
2714
2809
|
},
|
|
2715
2810
|
s.label
|
|
2716
2811
|
)) }),
|
|
2717
|
-
n && /* @__PURE__ */
|
|
2812
|
+
n && /* @__PURE__ */ d(
|
|
2718
2813
|
"pre",
|
|
2719
2814
|
{
|
|
2720
2815
|
style: {
|
|
@@ -2727,41 +2822,41 @@ function MatrixMode() {
|
|
|
2727
2822
|
)
|
|
2728
2823
|
] });
|
|
2729
2824
|
}
|
|
2730
|
-
function
|
|
2825
|
+
function re({
|
|
2731
2826
|
matrix: e,
|
|
2732
2827
|
onChange: t
|
|
2733
2828
|
}) {
|
|
2734
|
-
return /* @__PURE__ */
|
|
2829
|
+
return /* @__PURE__ */ d(
|
|
2735
2830
|
"div",
|
|
2736
2831
|
{
|
|
2737
2832
|
style: { display: "grid", gridTemplateColumns: `repeat(${e.cols}, 50px)`, gap: "4px" },
|
|
2738
2833
|
children: e.data.map(
|
|
2739
|
-
(r,
|
|
2834
|
+
(r, o) => r.map((a, n) => /* @__PURE__ */ d(
|
|
2740
2835
|
"input",
|
|
2741
2836
|
{
|
|
2742
2837
|
type: "number",
|
|
2743
|
-
value:
|
|
2744
|
-
onChange: (i) => t(
|
|
2838
|
+
value: a,
|
|
2839
|
+
onChange: (i) => t(o, n, i.target.value),
|
|
2745
2840
|
style: {
|
|
2746
2841
|
width: "100%",
|
|
2747
2842
|
padding: "4px",
|
|
2748
2843
|
textAlign: "center",
|
|
2749
2844
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2750
|
-
color: "var(--nice-
|
|
2845
|
+
color: "var(--nice-color-white, #fff)",
|
|
2751
2846
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2752
2847
|
borderRadius: "4px"
|
|
2753
2848
|
}
|
|
2754
2849
|
},
|
|
2755
|
-
`${
|
|
2850
|
+
`${o}-${n}`
|
|
2756
2851
|
))
|
|
2757
2852
|
)
|
|
2758
2853
|
}
|
|
2759
2854
|
);
|
|
2760
2855
|
}
|
|
2761
|
-
function
|
|
2762
|
-
const { t: e } =
|
|
2763
|
-
return /* @__PURE__ */
|
|
2764
|
-
/* @__PURE__ */
|
|
2856
|
+
function je() {
|
|
2857
|
+
const { t: e } = L(), [t, r] = P("x^2"), [o, a] = P("");
|
|
2858
|
+
return /* @__PURE__ */ v("div", { style: { padding: "12px", backgroundColor: "var(--nice-bg-secondary, #252525)" }, children: [
|
|
2859
|
+
/* @__PURE__ */ d(
|
|
2765
2860
|
"input",
|
|
2766
2861
|
{
|
|
2767
2862
|
type: "text",
|
|
@@ -2773,17 +2868,17 @@ function CalculusMode() {
|
|
|
2773
2868
|
padding: "8px",
|
|
2774
2869
|
marginBottom: "12px",
|
|
2775
2870
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2776
|
-
color: "var(--nice-
|
|
2871
|
+
color: "var(--nice-color-white, #fff)",
|
|
2777
2872
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2778
2873
|
borderRadius: "4px"
|
|
2779
2874
|
}
|
|
2780
2875
|
}
|
|
2781
2876
|
),
|
|
2782
|
-
/* @__PURE__ */
|
|
2783
|
-
/* @__PURE__ */
|
|
2877
|
+
/* @__PURE__ */ v("div", { style: { display: "flex", gap: "4px", flexWrap: "wrap", marginBottom: "12px" }, children: [
|
|
2878
|
+
/* @__PURE__ */ d(
|
|
2784
2879
|
"button",
|
|
2785
2880
|
{
|
|
2786
|
-
onClick: () =>
|
|
2881
|
+
onClick: () => a(`d/dx(${t}) = ${te.symbolicDerivative(t)}`),
|
|
2787
2882
|
style: {
|
|
2788
2883
|
padding: "8px 12px",
|
|
2789
2884
|
backgroundColor: "var(--nice-success, #4caf50)",
|
|
@@ -2795,10 +2890,10 @@ function CalculusMode() {
|
|
|
2795
2890
|
children: e("calculator.differentiate", "Differentiate")
|
|
2796
2891
|
}
|
|
2797
2892
|
),
|
|
2798
|
-
/* @__PURE__ */
|
|
2893
|
+
/* @__PURE__ */ d(
|
|
2799
2894
|
"button",
|
|
2800
2895
|
{
|
|
2801
|
-
onClick: () =>
|
|
2896
|
+
onClick: () => a(`∫(${t})dx = ${te.symbolicIntegral(t)}`),
|
|
2802
2897
|
style: {
|
|
2803
2898
|
padding: "8px 12px",
|
|
2804
2899
|
backgroundColor: "var(--nice-primary, #2196f3)",
|
|
@@ -2811,7 +2906,7 @@ function CalculusMode() {
|
|
|
2811
2906
|
}
|
|
2812
2907
|
)
|
|
2813
2908
|
] }),
|
|
2814
|
-
|
|
2909
|
+
o && /* @__PURE__ */ d(
|
|
2815
2910
|
"div",
|
|
2816
2911
|
{
|
|
2817
2912
|
style: {
|
|
@@ -2821,108 +2916,108 @@ function CalculusMode() {
|
|
|
2821
2916
|
backgroundColor: "var(--nice-bg, #1e1e1e)",
|
|
2822
2917
|
borderRadius: "4px"
|
|
2823
2918
|
},
|
|
2824
|
-
children:
|
|
2919
|
+
children: o
|
|
2825
2920
|
}
|
|
2826
2921
|
)
|
|
2827
2922
|
] });
|
|
2828
2923
|
}
|
|
2829
|
-
function
|
|
2830
|
-
const { t: e } =
|
|
2924
|
+
function Fe() {
|
|
2925
|
+
const { t: e } = L(), { service: t } = N(), [r, o] = P("1"), [a, n] = P("m"), [i, c] = P("ft"), [u, s] = P("Length"), [p, m] = P(""), y = t.getUnitCategories(), f = t.getUnitsByCategory(u), C = () => {
|
|
2831
2926
|
try {
|
|
2832
|
-
const
|
|
2833
|
-
|
|
2834
|
-
} catch (
|
|
2835
|
-
|
|
2927
|
+
const x = t.convertUnits(parseFloat(r), a, i);
|
|
2928
|
+
m(`${r} ${a} = ${t.format(x)} ${i}`);
|
|
2929
|
+
} catch (x) {
|
|
2930
|
+
m(x.message);
|
|
2836
2931
|
}
|
|
2837
2932
|
};
|
|
2838
|
-
return /* @__PURE__ */
|
|
2839
|
-
/* @__PURE__ */
|
|
2933
|
+
return /* @__PURE__ */ v("div", { style: { padding: "12px", backgroundColor: "var(--nice-bg-secondary, #252525)" }, children: [
|
|
2934
|
+
/* @__PURE__ */ d(
|
|
2840
2935
|
"select",
|
|
2841
2936
|
{
|
|
2842
|
-
value:
|
|
2843
|
-
onChange: (
|
|
2844
|
-
s(
|
|
2845
|
-
const
|
|
2846
|
-
|
|
2937
|
+
value: u,
|
|
2938
|
+
onChange: (x) => {
|
|
2939
|
+
s(x.target.value);
|
|
2940
|
+
const b = t.getUnitsByCategory(x.target.value);
|
|
2941
|
+
b.length >= 2 && (n(b[0].symbol), c(b[1].symbol));
|
|
2847
2942
|
},
|
|
2848
2943
|
style: {
|
|
2849
2944
|
width: "100%",
|
|
2850
2945
|
padding: "8px",
|
|
2851
2946
|
marginBottom: "12px",
|
|
2852
2947
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2853
|
-
color: "var(--nice-
|
|
2948
|
+
color: "var(--nice-color-white, #fff)",
|
|
2854
2949
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2855
2950
|
borderRadius: "4px"
|
|
2856
2951
|
},
|
|
2857
|
-
children: y.map((
|
|
2952
|
+
children: y.map((x) => /* @__PURE__ */ d("option", { value: x, children: x }, x))
|
|
2858
2953
|
}
|
|
2859
2954
|
),
|
|
2860
|
-
/* @__PURE__ */
|
|
2861
|
-
/* @__PURE__ */
|
|
2955
|
+
/* @__PURE__ */ v("div", { style: { display: "flex", gap: "8px", alignItems: "center", marginBottom: "12px" }, children: [
|
|
2956
|
+
/* @__PURE__ */ d(
|
|
2862
2957
|
"input",
|
|
2863
2958
|
{
|
|
2864
2959
|
type: "number",
|
|
2865
2960
|
value: r,
|
|
2866
|
-
onChange: (
|
|
2961
|
+
onChange: (x) => o(x.target.value),
|
|
2867
2962
|
style: {
|
|
2868
2963
|
flex: 1,
|
|
2869
2964
|
padding: "8px",
|
|
2870
2965
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2871
|
-
color: "var(--nice-
|
|
2966
|
+
color: "var(--nice-color-white, #fff)",
|
|
2872
2967
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2873
2968
|
borderRadius: "4px"
|
|
2874
2969
|
}
|
|
2875
2970
|
}
|
|
2876
2971
|
),
|
|
2877
|
-
/* @__PURE__ */
|
|
2972
|
+
/* @__PURE__ */ d(
|
|
2878
2973
|
"select",
|
|
2879
2974
|
{
|
|
2880
|
-
value:
|
|
2881
|
-
onChange: (
|
|
2975
|
+
value: a,
|
|
2976
|
+
onChange: (x) => n(x.target.value),
|
|
2882
2977
|
style: {
|
|
2883
2978
|
padding: "8px",
|
|
2884
2979
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2885
|
-
color: "var(--nice-
|
|
2980
|
+
color: "var(--nice-color-white, #fff)",
|
|
2886
2981
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2887
2982
|
borderRadius: "4px"
|
|
2888
2983
|
},
|
|
2889
|
-
children:
|
|
2890
|
-
|
|
2984
|
+
children: f.map((x) => /* @__PURE__ */ v("option", { value: x.symbol, children: [
|
|
2985
|
+
x.name,
|
|
2891
2986
|
" (",
|
|
2892
|
-
|
|
2987
|
+
x.symbol,
|
|
2893
2988
|
")"
|
|
2894
|
-
] },
|
|
2989
|
+
] }, x.symbol))
|
|
2895
2990
|
}
|
|
2896
2991
|
)
|
|
2897
2992
|
] }),
|
|
2898
|
-
/* @__PURE__ */
|
|
2899
|
-
/* @__PURE__ */
|
|
2900
|
-
/* @__PURE__ */
|
|
2993
|
+
/* @__PURE__ */ v("div", { style: { display: "flex", gap: "8px", alignItems: "center", marginBottom: "12px" }, children: [
|
|
2994
|
+
/* @__PURE__ */ d("span", { style: { color: "var(--nice-text-secondary, #888)" }, children: /* @__PURE__ */ d(G, { name: "arrow-right", size: 12 }) }),
|
|
2995
|
+
/* @__PURE__ */ d(
|
|
2901
2996
|
"select",
|
|
2902
2997
|
{
|
|
2903
2998
|
value: i,
|
|
2904
|
-
onChange: (
|
|
2999
|
+
onChange: (x) => c(x.target.value),
|
|
2905
3000
|
style: {
|
|
2906
3001
|
flex: 1,
|
|
2907
3002
|
padding: "8px",
|
|
2908
3003
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2909
|
-
color: "var(--nice-
|
|
3004
|
+
color: "var(--nice-color-white, #fff)",
|
|
2910
3005
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2911
3006
|
borderRadius: "4px"
|
|
2912
3007
|
},
|
|
2913
|
-
children:
|
|
2914
|
-
|
|
3008
|
+
children: f.map((x) => /* @__PURE__ */ v("option", { value: x.symbol, children: [
|
|
3009
|
+
x.name,
|
|
2915
3010
|
" (",
|
|
2916
|
-
|
|
3011
|
+
x.symbol,
|
|
2917
3012
|
")"
|
|
2918
|
-
] },
|
|
3013
|
+
] }, x.symbol))
|
|
2919
3014
|
}
|
|
2920
3015
|
)
|
|
2921
3016
|
] }),
|
|
2922
|
-
/* @__PURE__ */
|
|
3017
|
+
/* @__PURE__ */ d(
|
|
2923
3018
|
"button",
|
|
2924
3019
|
{
|
|
2925
|
-
onClick:
|
|
3020
|
+
onClick: C,
|
|
2926
3021
|
style: {
|
|
2927
3022
|
width: "100%",
|
|
2928
3023
|
padding: "12px",
|
|
@@ -2936,7 +3031,7 @@ function UnitsMode() {
|
|
|
2936
3031
|
children: e("calculator.convert", "Convert")
|
|
2937
3032
|
}
|
|
2938
3033
|
),
|
|
2939
|
-
|
|
3034
|
+
p && /* @__PURE__ */ d(
|
|
2940
3035
|
"div",
|
|
2941
3036
|
{
|
|
2942
3037
|
style: {
|
|
@@ -2945,12 +3040,12 @@ function UnitsMode() {
|
|
|
2945
3040
|
fontSize: "18px",
|
|
2946
3041
|
textAlign: "center"
|
|
2947
3042
|
},
|
|
2948
|
-
children:
|
|
3043
|
+
children: p
|
|
2949
3044
|
}
|
|
2950
3045
|
)
|
|
2951
3046
|
] });
|
|
2952
3047
|
}
|
|
2953
|
-
const
|
|
3048
|
+
const E = {
|
|
2954
3049
|
/** Distance between two points */
|
|
2955
3050
|
distance(e, t) {
|
|
2956
3051
|
return Math.sqrt((t.x - e.x) ** 2 + (t.y - e.y) ** 2);
|
|
@@ -2961,8 +3056,8 @@ const GeoMath = {
|
|
|
2961
3056
|
},
|
|
2962
3057
|
/** Angle between three points (vertex at p2) */
|
|
2963
3058
|
angle(e, t, r) {
|
|
2964
|
-
const
|
|
2965
|
-
let n = Math.atan2(r.y - t.y, r.x - t.x) -
|
|
3059
|
+
const o = Math.atan2(e.y - t.y, e.x - t.x);
|
|
3060
|
+
let n = Math.atan2(r.y - t.y, r.x - t.x) - o;
|
|
2966
3061
|
return n < 0 && (n += 2 * Math.PI), n;
|
|
2967
3062
|
},
|
|
2968
3063
|
/** Angle in degrees */
|
|
@@ -2971,79 +3066,79 @@ const GeoMath = {
|
|
|
2971
3066
|
},
|
|
2972
3067
|
/** Point on line closest to given point */
|
|
2973
3068
|
closestPointOnLine(e, t, r) {
|
|
2974
|
-
const
|
|
2975
|
-
return { x: e.x + n *
|
|
3069
|
+
const o = t.x - e.x, a = t.y - e.y, n = ((r.x - e.x) * o + (r.y - e.y) * a) / (o * o + a * a);
|
|
3070
|
+
return { x: e.x + n * o, y: e.y + n * a };
|
|
2976
3071
|
},
|
|
2977
3072
|
/** Line-line intersection */
|
|
2978
|
-
lineIntersection(e, t, r,
|
|
2979
|
-
const
|
|
2980
|
-
if (Math.abs(
|
|
3073
|
+
lineIntersection(e, t, r, o) {
|
|
3074
|
+
const a = (e.x - t.x) * (r.y - o.y) - (e.y - t.y) * (r.x - o.x);
|
|
3075
|
+
if (Math.abs(a) < 1e-10)
|
|
2981
3076
|
return null;
|
|
2982
|
-
const n = ((e.x - r.x) * (r.y -
|
|
3077
|
+
const n = ((e.x - r.x) * (r.y - o.y) - (e.y - r.y) * (r.x - o.x)) / a;
|
|
2983
3078
|
return {
|
|
2984
3079
|
x: e.x + n * (t.x - e.x),
|
|
2985
3080
|
y: e.y + n * (t.y - e.y)
|
|
2986
3081
|
};
|
|
2987
3082
|
},
|
|
2988
3083
|
/** Circle-line intersection */
|
|
2989
|
-
circleLineIntersection(e, t, r,
|
|
2990
|
-
const
|
|
2991
|
-
if (
|
|
3084
|
+
circleLineIntersection(e, t, r, o) {
|
|
3085
|
+
const a = o.x - r.x, n = o.y - r.y, i = r.x - e.x, c = r.y - e.y, u = a * a + n * n, s = 2 * (i * a + c * n), p = i * i + c * c - t * t, m = s * s - 4 * u * p;
|
|
3086
|
+
if (m < 0)
|
|
2992
3087
|
return [];
|
|
2993
|
-
const y = Math.sqrt(
|
|
2994
|
-
return
|
|
3088
|
+
const y = Math.sqrt(m), f = (-s - y) / (2 * u), C = (-s + y) / (2 * u), x = [];
|
|
3089
|
+
return f >= 0 && f <= 1 && x.push({ x: r.x + f * a, y: r.y + f * n }), C >= 0 && C <= 1 && Math.abs(C - f) > 1e-10 && x.push({ x: r.x + C * a, y: r.y + C * n }), x;
|
|
2995
3090
|
},
|
|
2996
3091
|
/** Circle-circle intersection */
|
|
2997
|
-
circleCircleIntersection(e, t, r,
|
|
2998
|
-
const
|
|
2999
|
-
if (
|
|
3092
|
+
circleCircleIntersection(e, t, r, o) {
|
|
3093
|
+
const a = this.distance(e, r);
|
|
3094
|
+
if (a > t + o || a < Math.abs(t - o) || a === 0)
|
|
3000
3095
|
return [];
|
|
3001
|
-
const n = (t * t -
|
|
3096
|
+
const n = (t * t - o * o + a * a) / (2 * a), i = Math.sqrt(t * t - n * n), c = e.x + n * (r.x - e.x) / a, u = e.y + n * (r.y - e.y) / a;
|
|
3002
3097
|
return [
|
|
3003
|
-
{ x:
|
|
3004
|
-
{ x:
|
|
3098
|
+
{ x: c + i * (r.y - e.y) / a, y: u - i * (r.x - e.x) / a },
|
|
3099
|
+
{ x: c - i * (r.y - e.y) / a, y: u + i * (r.x - e.x) / a }
|
|
3005
3100
|
];
|
|
3006
3101
|
},
|
|
3007
3102
|
/** Perpendicular line through point */
|
|
3008
3103
|
perpendicularThrough(e, t, r) {
|
|
3009
3104
|
this.closestPointOnLine(e, t, r);
|
|
3010
|
-
const
|
|
3105
|
+
const o = t.x - e.x, a = t.y - e.y;
|
|
3011
3106
|
return {
|
|
3012
3107
|
p1: r,
|
|
3013
|
-
p2: { x: r.x -
|
|
3108
|
+
p2: { x: r.x - a, y: r.y + o }
|
|
3014
3109
|
};
|
|
3015
3110
|
},
|
|
3016
3111
|
/** Parallel line through point */
|
|
3017
3112
|
parallelThrough(e, t, r) {
|
|
3018
|
-
const
|
|
3113
|
+
const o = t.x - e.x, a = t.y - e.y;
|
|
3019
3114
|
return {
|
|
3020
3115
|
p1: r,
|
|
3021
|
-
p2: { x: r.x +
|
|
3116
|
+
p2: { x: r.x + o, y: r.y + a }
|
|
3022
3117
|
};
|
|
3023
3118
|
},
|
|
3024
3119
|
/** Angle bisector */
|
|
3025
3120
|
angleBisector(e, t, r) {
|
|
3026
|
-
const
|
|
3027
|
-
let n = (
|
|
3028
|
-
return Math.abs(
|
|
3121
|
+
const o = Math.atan2(e.y - t.y, e.x - t.x), a = Math.atan2(r.y - t.y, r.x - t.x);
|
|
3122
|
+
let n = (o + a) / 2;
|
|
3123
|
+
return Math.abs(a - o) > Math.PI && (n += Math.PI), {
|
|
3029
3124
|
x: t.x + Math.cos(n),
|
|
3030
3125
|
y: t.y + Math.sin(n)
|
|
3031
3126
|
};
|
|
3032
3127
|
},
|
|
3033
3128
|
/** Reflect point over line */
|
|
3034
3129
|
reflect(e, t, r) {
|
|
3035
|
-
const
|
|
3130
|
+
const o = this.closestPointOnLine(t, r, e);
|
|
3036
3131
|
return {
|
|
3037
|
-
x: 2 *
|
|
3038
|
-
y: 2 *
|
|
3132
|
+
x: 2 * o.x - e.x,
|
|
3133
|
+
y: 2 * o.y - e.y
|
|
3039
3134
|
};
|
|
3040
3135
|
},
|
|
3041
3136
|
/** Rotate point around center */
|
|
3042
3137
|
rotate(e, t, r) {
|
|
3043
|
-
const
|
|
3138
|
+
const o = Math.cos(r), a = Math.sin(r), n = e.x - t.x, i = e.y - t.y;
|
|
3044
3139
|
return {
|
|
3045
|
-
x: t.x + n *
|
|
3046
|
-
y: t.y + n *
|
|
3140
|
+
x: t.x + n * o - i * a,
|
|
3141
|
+
y: t.y + n * a + i * o
|
|
3047
3142
|
};
|
|
3048
3143
|
},
|
|
3049
3144
|
/** Translate point */
|
|
@@ -3061,9 +3156,9 @@ const GeoMath = {
|
|
|
3061
3156
|
polygonArea(e) {
|
|
3062
3157
|
let t = 0;
|
|
3063
3158
|
const r = e.length;
|
|
3064
|
-
for (let
|
|
3065
|
-
const
|
|
3066
|
-
t += e[
|
|
3159
|
+
for (let o = 0; o < r; o++) {
|
|
3160
|
+
const a = (o + 1) % r;
|
|
3161
|
+
t += e[o].x * e[a].y, t -= e[a].x * e[o].y;
|
|
3067
3162
|
}
|
|
3068
3163
|
return Math.abs(t) / 2;
|
|
3069
3164
|
},
|
|
@@ -3071,23 +3166,23 @@ const GeoMath = {
|
|
|
3071
3166
|
polygonPerimeter(e) {
|
|
3072
3167
|
let t = 0;
|
|
3073
3168
|
const r = e.length;
|
|
3074
|
-
for (let
|
|
3075
|
-
const
|
|
3076
|
-
t += this.distance(e[
|
|
3169
|
+
for (let o = 0; o < r; o++) {
|
|
3170
|
+
const a = (o + 1) % r;
|
|
3171
|
+
t += this.distance(e[o], e[a]);
|
|
3077
3172
|
}
|
|
3078
3173
|
return t;
|
|
3079
3174
|
},
|
|
3080
3175
|
/** Triangle circumcenter */
|
|
3081
3176
|
circumcenter(e, t, r) {
|
|
3082
|
-
const
|
|
3083
|
-
return { x:
|
|
3177
|
+
const o = 2 * (e.x * (t.y - r.y) + t.x * (r.y - e.y) + r.x * (e.y - t.y)), a = ((e.x ** 2 + e.y ** 2) * (t.y - r.y) + (t.x ** 2 + t.y ** 2) * (r.y - e.y) + (r.x ** 2 + r.y ** 2) * (e.y - t.y)) / o, n = ((e.x ** 2 + e.y ** 2) * (r.x - t.x) + (t.x ** 2 + t.y ** 2) * (e.x - r.x) + (r.x ** 2 + r.y ** 2) * (t.x - e.x)) / o;
|
|
3178
|
+
return { x: a, y: n };
|
|
3084
3179
|
},
|
|
3085
3180
|
/** Triangle incenter */
|
|
3086
3181
|
incenter(e, t, r) {
|
|
3087
|
-
const
|
|
3182
|
+
const o = this.distance(e, t), a = this.distance(t, r), n = this.distance(r, e), i = o + a + n;
|
|
3088
3183
|
return {
|
|
3089
|
-
x: (
|
|
3090
|
-
y: (
|
|
3184
|
+
x: (a * e.x + n * t.x + o * r.x) / i,
|
|
3185
|
+
y: (a * e.y + n * t.y + o * r.y) / i
|
|
3091
3186
|
};
|
|
3092
3187
|
},
|
|
3093
3188
|
/** Triangle centroid */
|
|
@@ -3098,15 +3193,15 @@ const GeoMath = {
|
|
|
3098
3193
|
};
|
|
3099
3194
|
}
|
|
3100
3195
|
};
|
|
3101
|
-
class
|
|
3196
|
+
class Oe {
|
|
3102
3197
|
constructor() {
|
|
3103
|
-
|
|
3104
|
-
|
|
3198
|
+
T(this, "elements", /* @__PURE__ */ new Map());
|
|
3199
|
+
T(this, "nextLabel", 1);
|
|
3105
3200
|
}
|
|
3106
3201
|
/** Add element */
|
|
3107
3202
|
addElement(t) {
|
|
3108
|
-
const r = this.generateId(),
|
|
3109
|
-
return this.elements.set(r,
|
|
3203
|
+
const r = this.generateId(), o = { ...t, id: r };
|
|
3204
|
+
return this.elements.set(r, o), o;
|
|
3110
3205
|
}
|
|
3111
3206
|
/** Get element */
|
|
3112
3207
|
getElement(t) {
|
|
@@ -3119,15 +3214,15 @@ class GeometryService {
|
|
|
3119
3214
|
}
|
|
3120
3215
|
/** Update element */
|
|
3121
3216
|
updateElement(t, r) {
|
|
3122
|
-
const
|
|
3123
|
-
|
|
3217
|
+
const o = this.elements.get(t);
|
|
3218
|
+
o && this.elements.set(t, { ...o, ...r, id: t, type: o.type });
|
|
3124
3219
|
}
|
|
3125
3220
|
/** Delete element */
|
|
3126
3221
|
deleteElement(t) {
|
|
3127
3222
|
var r;
|
|
3128
3223
|
this.elements.delete(t);
|
|
3129
|
-
for (const [
|
|
3130
|
-
(r =
|
|
3224
|
+
for (const [o, a] of this.elements)
|
|
3225
|
+
(r = a.dependencies) != null && r.includes(t) && this.deleteElement(o);
|
|
3131
3226
|
}
|
|
3132
3227
|
/** Get all elements */
|
|
3133
3228
|
getAllElements() {
|
|
@@ -3142,12 +3237,12 @@ class GeometryService {
|
|
|
3142
3237
|
this.elements.clear(), this.nextLabel = 1;
|
|
3143
3238
|
}
|
|
3144
3239
|
/** Create point */
|
|
3145
|
-
createPoint(t, r,
|
|
3240
|
+
createPoint(t, r, o) {
|
|
3146
3241
|
return this.addElement({
|
|
3147
3242
|
type: "point",
|
|
3148
3243
|
x: t,
|
|
3149
3244
|
y: r,
|
|
3150
|
-
label:
|
|
3245
|
+
label: o ?? this.getNextLabel(),
|
|
3151
3246
|
color: { r: 0, g: 0, b: 0 },
|
|
3152
3247
|
visible: !0,
|
|
3153
3248
|
selected: !1,
|
|
@@ -3232,65 +3327,65 @@ class GeometryService {
|
|
|
3232
3327
|
}
|
|
3233
3328
|
/** Create midpoint */
|
|
3234
3329
|
createMidpoint(t, r) {
|
|
3235
|
-
const
|
|
3236
|
-
if (!
|
|
3330
|
+
const o = this.getPoint(t), a = this.getPoint(r);
|
|
3331
|
+
if (!o || !a)
|
|
3237
3332
|
return null;
|
|
3238
|
-
const n =
|
|
3333
|
+
const n = E.midpoint(o, a), i = this.createPoint(n.x, n.y);
|
|
3239
3334
|
return i.dependencies = [t, r], i.color = { r: 0, g: 150, b: 0 }, i;
|
|
3240
3335
|
}
|
|
3241
3336
|
/** Create perpendicular */
|
|
3242
|
-
createPerpendicular(t, r,
|
|
3243
|
-
const
|
|
3244
|
-
if (!
|
|
3337
|
+
createPerpendicular(t, r, o) {
|
|
3338
|
+
const a = this.getPoint(t), n = this.getPoint(r), i = this.getPoint(o);
|
|
3339
|
+
if (!a || !n || !i)
|
|
3245
3340
|
return null;
|
|
3246
|
-
const
|
|
3247
|
-
return s.dependencies = [t, r,
|
|
3341
|
+
const c = E.perpendicularThrough(a, n, i), u = this.createPoint(c.p2.x, c.p2.y), s = this.createLine(o, u.id);
|
|
3342
|
+
return s.dependencies = [t, r, o], s;
|
|
3248
3343
|
}
|
|
3249
3344
|
/** Create parallel */
|
|
3250
|
-
createParallel(t, r,
|
|
3251
|
-
const
|
|
3252
|
-
if (!
|
|
3345
|
+
createParallel(t, r, o) {
|
|
3346
|
+
const a = this.getPoint(t), n = this.getPoint(r), i = this.getPoint(o);
|
|
3347
|
+
if (!a || !n || !i)
|
|
3253
3348
|
return null;
|
|
3254
|
-
const
|
|
3255
|
-
return s.dependencies = [t, r,
|
|
3349
|
+
const c = E.parallelThrough(a, n, i), u = this.createPoint(c.p2.x, c.p2.y), s = this.createLine(o, u.id);
|
|
3350
|
+
return s.dependencies = [t, r, o], s;
|
|
3256
3351
|
}
|
|
3257
3352
|
/** Create intersection point */
|
|
3258
3353
|
createIntersection(t, r) {
|
|
3259
|
-
const
|
|
3260
|
-
if (!
|
|
3354
|
+
const o = this.elements.get(t), a = this.elements.get(r);
|
|
3355
|
+
if (!o || !a)
|
|
3261
3356
|
return [];
|
|
3262
3357
|
const n = [], i = (s) => {
|
|
3263
3358
|
if (s.type === "line" || s.type === "segment" || s.type === "ray") {
|
|
3264
|
-
const
|
|
3265
|
-
if (
|
|
3266
|
-
return [
|
|
3359
|
+
const p = s, m = this.getPoint(p.point1Id ?? p.originId), y = this.getPoint(p.point2Id ?? p.throughId);
|
|
3360
|
+
if (m && y)
|
|
3361
|
+
return [m, y];
|
|
3267
3362
|
}
|
|
3268
3363
|
return null;
|
|
3269
|
-
},
|
|
3270
|
-
if (
|
|
3271
|
-
const s =
|
|
3364
|
+
}, c = i(o), u = i(a);
|
|
3365
|
+
if (c && u) {
|
|
3366
|
+
const s = E.lineIntersection(c[0], c[1], u[0], u[1]);
|
|
3272
3367
|
if (s) {
|
|
3273
|
-
const
|
|
3274
|
-
|
|
3368
|
+
const p = this.createPoint(s.x, s.y);
|
|
3369
|
+
p.dependencies = [t, r], p.color = { r: 255, g: 0, b: 0 }, n.push(p);
|
|
3275
3370
|
}
|
|
3276
3371
|
}
|
|
3277
|
-
if (
|
|
3278
|
-
const s =
|
|
3279
|
-
if (
|
|
3280
|
-
const
|
|
3281
|
-
for (const y of
|
|
3282
|
-
const
|
|
3283
|
-
|
|
3372
|
+
if (o.type === "circle" && u) {
|
|
3373
|
+
const s = o, p = this.getPoint(s.centerId);
|
|
3374
|
+
if (p) {
|
|
3375
|
+
const m = E.circleLineIntersection(p, s.radius, u[0], u[1]);
|
|
3376
|
+
for (const y of m) {
|
|
3377
|
+
const f = this.createPoint(y.x, y.y);
|
|
3378
|
+
f.dependencies = [t, r], f.color = { r: 255, g: 0, b: 0 }, n.push(f);
|
|
3284
3379
|
}
|
|
3285
3380
|
}
|
|
3286
3381
|
}
|
|
3287
|
-
if (
|
|
3288
|
-
const s =
|
|
3289
|
-
if (
|
|
3290
|
-
const
|
|
3291
|
-
for (const
|
|
3292
|
-
const
|
|
3293
|
-
|
|
3382
|
+
if (o.type === "circle" && a.type === "circle") {
|
|
3383
|
+
const s = o, p = a, m = this.getPoint(s.centerId), y = this.getPoint(p.centerId);
|
|
3384
|
+
if (m && y) {
|
|
3385
|
+
const f = E.circleCircleIntersection(m, s.radius, y, p.radius);
|
|
3386
|
+
for (const C of f) {
|
|
3387
|
+
const x = this.createPoint(C.x, C.y);
|
|
3388
|
+
x.dependencies = [t, r], x.color = { r: 255, g: 0, b: 0 }, n.push(x);
|
|
3294
3389
|
}
|
|
3295
3390
|
}
|
|
3296
3391
|
}
|
|
@@ -3300,23 +3395,23 @@ class GeometryService {
|
|
|
3300
3395
|
calculateMeasurement(t, r) {
|
|
3301
3396
|
switch (t) {
|
|
3302
3397
|
case "distance": {
|
|
3303
|
-
const
|
|
3304
|
-
if (
|
|
3305
|
-
return
|
|
3398
|
+
const o = this.getPoint(r[0]), a = this.getPoint(r[1]);
|
|
3399
|
+
if (o && a)
|
|
3400
|
+
return E.distance(o, a);
|
|
3306
3401
|
break;
|
|
3307
3402
|
}
|
|
3308
3403
|
case "angle": {
|
|
3309
|
-
const
|
|
3310
|
-
if (
|
|
3311
|
-
return
|
|
3404
|
+
const o = this.getPoint(r[0]), a = this.getPoint(r[1]), n = this.getPoint(r[2]);
|
|
3405
|
+
if (o && a && n)
|
|
3406
|
+
return E.angleDegrees(o, a, n);
|
|
3312
3407
|
break;
|
|
3313
3408
|
}
|
|
3314
3409
|
case "area":
|
|
3315
3410
|
case "perimeter": {
|
|
3316
|
-
const
|
|
3317
|
-
if ((
|
|
3318
|
-
const
|
|
3319
|
-
return t === "area" ?
|
|
3411
|
+
const o = this.elements.get(r[0]);
|
|
3412
|
+
if ((o == null ? void 0 : o.type) === "polygon") {
|
|
3413
|
+
const a = o.pointIds.map((n) => this.getPoint(n)).filter(Boolean);
|
|
3414
|
+
return t === "area" ? E.polygonArea(a) : E.polygonPerimeter(a);
|
|
3320
3415
|
}
|
|
3321
3416
|
break;
|
|
3322
3417
|
}
|
|
@@ -3324,76 +3419,76 @@ class GeometryService {
|
|
|
3324
3419
|
return 0;
|
|
3325
3420
|
}
|
|
3326
3421
|
/** Export to SVG */
|
|
3327
|
-
exportSVG(t, r,
|
|
3328
|
-
const
|
|
3422
|
+
exportSVG(t, r, o) {
|
|
3423
|
+
const a = [
|
|
3329
3424
|
`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${r}" viewBox="0 0 ${t} ${r}">`
|
|
3330
3425
|
];
|
|
3331
|
-
|
|
3332
|
-
`<rect width="100%" height="100%" fill="rgb(${
|
|
3426
|
+
a.push(
|
|
3427
|
+
`<rect width="100%" height="100%" fill="rgb(${o.backgroundColor.r},${o.backgroundColor.g},${o.backgroundColor.b})"/>`
|
|
3333
3428
|
);
|
|
3334
|
-
const n = (i,
|
|
3335
|
-
x: t / 2 + (i -
|
|
3336
|
-
y: r / 2 - (
|
|
3429
|
+
const n = (i, c) => ({
|
|
3430
|
+
x: t / 2 + (i - o.centerX) * o.scale,
|
|
3431
|
+
y: r / 2 - (c - o.centerY) * o.scale
|
|
3337
3432
|
});
|
|
3338
|
-
if (
|
|
3339
|
-
|
|
3340
|
-
for (let i = Math.floor(-t / 2 /
|
|
3341
|
-
const
|
|
3342
|
-
|
|
3433
|
+
if (o.showGrid) {
|
|
3434
|
+
a.push('<g stroke="var(--nice-border, #ddd)" stroke-width="0.5">');
|
|
3435
|
+
for (let i = Math.floor(-t / 2 / o.scale + o.centerX); i <= t / 2 / o.scale + o.centerX; i += o.gridSpacing) {
|
|
3436
|
+
const c = n(i, 0);
|
|
3437
|
+
a.push(`<line x1="${c.x}" y1="0" x2="${c.x}" y2="${r}"/>`);
|
|
3343
3438
|
}
|
|
3344
|
-
for (let i = Math.floor(-r / 2 /
|
|
3345
|
-
const
|
|
3346
|
-
|
|
3439
|
+
for (let i = Math.floor(-r / 2 / o.scale + o.centerY); i <= r / 2 / o.scale + o.centerY; i += o.gridSpacing) {
|
|
3440
|
+
const c = n(0, i);
|
|
3441
|
+
a.push(`<line x1="0" y1="${c.y}" x2="${t}" y2="${c.y}"/>`);
|
|
3347
3442
|
}
|
|
3348
|
-
|
|
3443
|
+
a.push("</g>");
|
|
3349
3444
|
}
|
|
3350
|
-
if (
|
|
3445
|
+
if (o.showAxes) {
|
|
3351
3446
|
const i = n(0, 0);
|
|
3352
|
-
|
|
3447
|
+
a.push('<g stroke="var(--nice-text, #333)" stroke-width="1">'), a.push(`<line x1="0" y1="${i.y}" x2="${t}" y2="${i.y}"/>`), a.push(`<line x1="${i.x}" y1="0" x2="${i.x}" y2="${r}"/>`), a.push("</g>");
|
|
3353
3448
|
}
|
|
3354
3449
|
for (const i of this.getAllElements()) {
|
|
3355
3450
|
if (!i.visible)
|
|
3356
3451
|
continue;
|
|
3357
|
-
const
|
|
3452
|
+
const c = `rgb(${i.color.r},${i.color.g},${i.color.b})`;
|
|
3358
3453
|
switch (i.type) {
|
|
3359
3454
|
case "point": {
|
|
3360
|
-
const
|
|
3361
|
-
|
|
3455
|
+
const u = n(i.x, i.y);
|
|
3456
|
+
a.push(`<circle cx="${u.x}" cy="${u.y}" r="${i.size}" fill="${c}"/>`), i.label && a.push(`<text x="${u.x + 8}" y="${u.y - 8}" font-size="12">${i.label}</text>`);
|
|
3362
3457
|
break;
|
|
3363
3458
|
}
|
|
3364
3459
|
case "segment": {
|
|
3365
|
-
const
|
|
3366
|
-
if (
|
|
3367
|
-
const
|
|
3368
|
-
|
|
3369
|
-
`<line x1="${
|
|
3460
|
+
const u = this.getPoint(i.point1Id), s = this.getPoint(i.point2Id);
|
|
3461
|
+
if (u && s) {
|
|
3462
|
+
const p = n(u.x, u.y), m = n(s.x, s.y);
|
|
3463
|
+
a.push(
|
|
3464
|
+
`<line x1="${p.x}" y1="${p.y}" x2="${m.x}" y2="${m.y}" stroke="${c}" stroke-width="${i.width}"/>`
|
|
3370
3465
|
);
|
|
3371
3466
|
}
|
|
3372
3467
|
break;
|
|
3373
3468
|
}
|
|
3374
3469
|
case "circle": {
|
|
3375
|
-
const
|
|
3376
|
-
if (
|
|
3377
|
-
const s = n(
|
|
3378
|
-
|
|
3379
|
-
`<circle cx="${s.x}" cy="${s.y}" r="${
|
|
3470
|
+
const u = this.getPoint(i.centerId);
|
|
3471
|
+
if (u) {
|
|
3472
|
+
const s = n(u.x, u.y), p = i.radius * o.scale, m = i.fill ? `rgba(${i.fill.r},${i.fill.g},${i.fill.b},${i.fill.a ?? 0.2})` : "none";
|
|
3473
|
+
a.push(
|
|
3474
|
+
`<circle cx="${s.x}" cy="${s.y}" r="${p}" fill="${m}" stroke="${c}" stroke-width="${i.width}"/>`
|
|
3380
3475
|
);
|
|
3381
3476
|
}
|
|
3382
3477
|
break;
|
|
3383
3478
|
}
|
|
3384
3479
|
case "polygon": {
|
|
3385
|
-
const
|
|
3386
|
-
if (
|
|
3387
|
-
const
|
|
3388
|
-
|
|
3389
|
-
`<path d="${
|
|
3480
|
+
const u = i.pointIds.map((s) => this.getPoint(s)).filter(Boolean);
|
|
3481
|
+
if (u.length > 0) {
|
|
3482
|
+
const p = u.map((y) => n(y.x, y.y)).map((y, f) => `${f === 0 ? "M" : "L"}${y.x},${y.y}`).join(" ") + " Z", m = i.fill ? `rgba(${i.fill.r},${i.fill.g},${i.fill.b},${i.fill.a ?? 0.2})` : "none";
|
|
3483
|
+
a.push(
|
|
3484
|
+
`<path d="${p}" fill="${m}" stroke="${c}" stroke-width="${i.width}"/>`
|
|
3390
3485
|
);
|
|
3391
3486
|
}
|
|
3392
3487
|
break;
|
|
3393
3488
|
}
|
|
3394
3489
|
}
|
|
3395
3490
|
}
|
|
3396
|
-
return
|
|
3491
|
+
return a.push("</svg>"), a.join(`
|
|
3397
3492
|
`);
|
|
3398
3493
|
}
|
|
3399
3494
|
generateId() {
|
|
@@ -3404,17 +3499,17 @@ class GeometryService {
|
|
|
3404
3499
|
return this.nextLabel++, r < 26 ? t[r] : t[r % 26] + Math.floor(r / 26);
|
|
3405
3500
|
}
|
|
3406
3501
|
}
|
|
3407
|
-
function
|
|
3408
|
-
return new
|
|
3502
|
+
function nt() {
|
|
3503
|
+
return new Oe();
|
|
3409
3504
|
}
|
|
3410
|
-
const
|
|
3411
|
-
function
|
|
3412
|
-
const e =
|
|
3505
|
+
const de = /* @__PURE__ */ F(null);
|
|
3506
|
+
function H() {
|
|
3507
|
+
const e = j(de);
|
|
3413
3508
|
if (!e)
|
|
3414
3509
|
throw new Error("useGeometry must be used within GeometryProvider");
|
|
3415
3510
|
return e;
|
|
3416
3511
|
}
|
|
3417
|
-
const
|
|
3512
|
+
const q = {
|
|
3418
3513
|
container: {
|
|
3419
3514
|
display: "flex",
|
|
3420
3515
|
height: "100%",
|
|
@@ -3463,14 +3558,14 @@ const styles = {
|
|
|
3463
3558
|
color: "var(--nice-text-secondary, #666)"
|
|
3464
3559
|
}
|
|
3465
3560
|
};
|
|
3466
|
-
function
|
|
3561
|
+
function it({
|
|
3467
3562
|
service: e,
|
|
3468
3563
|
width: t = 800,
|
|
3469
3564
|
height: r = 600,
|
|
3470
|
-
className:
|
|
3471
|
-
style:
|
|
3565
|
+
className: o,
|
|
3566
|
+
style: a
|
|
3472
3567
|
}) {
|
|
3473
|
-
const [n, i] =
|
|
3568
|
+
const [n, i] = P([]), [c, u] = P("point"), [s, p] = P([]), [m, y] = P({
|
|
3474
3569
|
centerX: 0,
|
|
3475
3570
|
centerY: 0,
|
|
3476
3571
|
scale: 40,
|
|
@@ -3480,35 +3575,35 @@ function NiceGeometry({
|
|
|
3480
3575
|
snapToGrid: !0,
|
|
3481
3576
|
snapToPoints: !0,
|
|
3482
3577
|
backgroundColor: { r: 255, g: 255, b: 255 }
|
|
3483
|
-
}),
|
|
3578
|
+
}), f = R(() => {
|
|
3484
3579
|
i(e.getAllElements());
|
|
3485
|
-
}, [e]),
|
|
3486
|
-
y((
|
|
3580
|
+
}, [e]), C = R((b) => {
|
|
3581
|
+
y((l) => ({ ...l, ...b }));
|
|
3487
3582
|
}, []);
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
}, [
|
|
3491
|
-
const
|
|
3583
|
+
V(() => {
|
|
3584
|
+
f();
|
|
3585
|
+
}, [f]);
|
|
3586
|
+
const x = {
|
|
3492
3587
|
service: e,
|
|
3493
3588
|
elements: n,
|
|
3494
|
-
tool:
|
|
3495
|
-
setTool:
|
|
3496
|
-
view:
|
|
3497
|
-
setView:
|
|
3589
|
+
tool: c,
|
|
3590
|
+
setTool: u,
|
|
3591
|
+
view: m,
|
|
3592
|
+
setView: C,
|
|
3498
3593
|
selectedIds: s,
|
|
3499
|
-
setSelectedIds:
|
|
3500
|
-
refresh:
|
|
3594
|
+
setSelectedIds: p,
|
|
3595
|
+
refresh: f
|
|
3501
3596
|
};
|
|
3502
|
-
return /* @__PURE__ */
|
|
3503
|
-
/* @__PURE__ */
|
|
3504
|
-
/* @__PURE__ */
|
|
3505
|
-
/* @__PURE__ */
|
|
3506
|
-
/* @__PURE__ */
|
|
3597
|
+
return /* @__PURE__ */ d(de.Provider, { value: x, children: /* @__PURE__ */ v("div", { className: o, style: { ...q.container, ...a }, children: [
|
|
3598
|
+
/* @__PURE__ */ d(Ue, {}),
|
|
3599
|
+
/* @__PURE__ */ v("div", { style: q.main, children: [
|
|
3600
|
+
/* @__PURE__ */ d(Ve, { width: t, height: r }),
|
|
3601
|
+
/* @__PURE__ */ d(Ye, { width: t, height: r })
|
|
3507
3602
|
] })
|
|
3508
3603
|
] }) });
|
|
3509
3604
|
}
|
|
3510
|
-
function
|
|
3511
|
-
const { tool: e, setTool: t } =
|
|
3605
|
+
function Ue() {
|
|
3606
|
+
const { tool: e, setTool: t } = H(), r = [
|
|
3512
3607
|
{ id: "select", icon: "cursor", title: "Select" },
|
|
3513
3608
|
{ id: "point", icon: "•", title: "Point" },
|
|
3514
3609
|
{ id: "segment", icon: "—", title: "Segment" },
|
|
@@ -3525,205 +3620,208 @@ function Toolbar() {
|
|
|
3525
3620
|
{ id: "rotate", icon: "refresh", title: "Rotate" },
|
|
3526
3621
|
{ id: "measure", icon: "ruler", title: "Measure" }
|
|
3527
3622
|
];
|
|
3528
|
-
return /* @__PURE__ */
|
|
3623
|
+
return /* @__PURE__ */ d("div", { style: q.toolbar, children: r.map((o) => /* @__PURE__ */ d(
|
|
3529
3624
|
"button",
|
|
3530
3625
|
{
|
|
3531
|
-
onClick: () => t(
|
|
3532
|
-
title:
|
|
3626
|
+
onClick: () => t(o.id),
|
|
3627
|
+
title: o.title,
|
|
3533
3628
|
style: {
|
|
3534
|
-
...
|
|
3535
|
-
backgroundColor: e ===
|
|
3536
|
-
color: e ===
|
|
3629
|
+
...q.toolButton,
|
|
3630
|
+
backgroundColor: e === o.id ? "var(--nice-primary-hover, #1976d2)" : "transparent",
|
|
3631
|
+
color: e === o.id ? "var(--nice-color-white, #fff)" : "var(--nice-text, #333)"
|
|
3537
3632
|
},
|
|
3538
|
-
children: /^[a-z][a-z0-9-]*$/.test(
|
|
3633
|
+
children: /^[a-z][a-z0-9-]*$/.test(o.icon) ? /* @__PURE__ */ d(G, { name: o.icon, size: 16 }) : o.icon
|
|
3539
3634
|
},
|
|
3540
|
-
|
|
3635
|
+
o.id
|
|
3541
3636
|
)) });
|
|
3542
3637
|
}
|
|
3543
|
-
function
|
|
3544
|
-
const r =
|
|
3545
|
-
(
|
|
3546
|
-
const
|
|
3638
|
+
function Ve({ width: e, height: t }) {
|
|
3639
|
+
const r = U(null), { service: o, elements: a, tool: n, view: i, selectedIds: c, setSelectedIds: u, refresh: s } = H(), [p, m] = P([]), y = R(
|
|
3640
|
+
(b, l) => {
|
|
3641
|
+
const g = (b - e / 2) / i.scale + i.centerX, w = -(l - t / 2) / i.scale + i.centerY;
|
|
3547
3642
|
return i.snapToGrid ? {
|
|
3548
|
-
x: Math.round(
|
|
3549
|
-
y: Math.round(
|
|
3550
|
-
} : { x, y:
|
|
3643
|
+
x: Math.round(g / i.gridSpacing) * i.gridSpacing,
|
|
3644
|
+
y: Math.round(w / i.gridSpacing) * i.gridSpacing
|
|
3645
|
+
} : { x: g, y: w };
|
|
3551
3646
|
},
|
|
3552
3647
|
[e, t, i]
|
|
3553
|
-
),
|
|
3554
|
-
(
|
|
3555
|
-
x: e / 2 + (
|
|
3556
|
-
y: t / 2 - (
|
|
3648
|
+
), f = R(
|
|
3649
|
+
(b, l) => ({
|
|
3650
|
+
x: e / 2 + (b - i.centerX) * i.scale,
|
|
3651
|
+
y: t / 2 - (l - i.centerY) * i.scale
|
|
3557
3652
|
}),
|
|
3558
3653
|
[e, t, i]
|
|
3559
|
-
),
|
|
3560
|
-
(
|
|
3561
|
-
var
|
|
3562
|
-
const
|
|
3563
|
-
if (!
|
|
3654
|
+
), C = R(
|
|
3655
|
+
(b) => {
|
|
3656
|
+
var w;
|
|
3657
|
+
const l = (w = r.current) == null ? void 0 : w.getBoundingClientRect();
|
|
3658
|
+
if (!l)
|
|
3564
3659
|
return;
|
|
3565
|
-
const
|
|
3660
|
+
const g = y(b.clientX - l.left, b.clientY - l.top);
|
|
3566
3661
|
switch (n) {
|
|
3567
3662
|
case "point": {
|
|
3568
|
-
|
|
3663
|
+
o.createPoint(g.x, g.y), s();
|
|
3569
3664
|
break;
|
|
3570
3665
|
}
|
|
3571
3666
|
case "segment":
|
|
3572
3667
|
case "line":
|
|
3573
3668
|
case "ray": {
|
|
3574
|
-
const
|
|
3575
|
-
if (
|
|
3576
|
-
|
|
3577
|
-
const
|
|
3578
|
-
return
|
|
3669
|
+
const M = x(g);
|
|
3670
|
+
if (M)
|
|
3671
|
+
m((h) => {
|
|
3672
|
+
const k = [...h, M.id];
|
|
3673
|
+
return k.length === 2 ? (n === "segment" ? o.createSegment(k[0], k[1]) : n === "line" ? o.createLine(k[0], k[1]) : n === "ray" && o.createRay(k[0], k[1]), s(), []) : k;
|
|
3579
3674
|
});
|
|
3580
3675
|
else {
|
|
3581
|
-
const
|
|
3582
|
-
|
|
3583
|
-
const
|
|
3584
|
-
return
|
|
3676
|
+
const h = o.createPoint(g.x, g.y);
|
|
3677
|
+
m((k) => {
|
|
3678
|
+
const S = [...k, h.id];
|
|
3679
|
+
return S.length === 2 ? (n === "segment" ? o.createSegment(S[0], S[1]) : n === "line" ? o.createLine(S[0], S[1]) : n === "ray" && o.createRay(S[0], S[1]), s(), []) : S;
|
|
3585
3680
|
}), s();
|
|
3586
3681
|
}
|
|
3587
3682
|
break;
|
|
3588
3683
|
}
|
|
3589
3684
|
case "circle": {
|
|
3590
|
-
const
|
|
3591
|
-
if (
|
|
3592
|
-
|
|
3593
|
-
if (
|
|
3594
|
-
return [
|
|
3595
|
-
const
|
|
3596
|
-
if (
|
|
3597
|
-
const
|
|
3598
|
-
|
|
3685
|
+
const M = x(g);
|
|
3686
|
+
if (M)
|
|
3687
|
+
m((h) => {
|
|
3688
|
+
if (h.length === 0)
|
|
3689
|
+
return [M.id];
|
|
3690
|
+
const k = o.getPoint(h[0]);
|
|
3691
|
+
if (k) {
|
|
3692
|
+
const S = E.distance(k, g);
|
|
3693
|
+
o.createCircle(h[0], S), s();
|
|
3599
3694
|
}
|
|
3600
3695
|
return [];
|
|
3601
3696
|
});
|
|
3602
|
-
else if (
|
|
3603
|
-
const
|
|
3604
|
-
if (
|
|
3605
|
-
const
|
|
3606
|
-
|
|
3697
|
+
else if (p.length === 1) {
|
|
3698
|
+
const h = o.getPoint(p[0]);
|
|
3699
|
+
if (h) {
|
|
3700
|
+
const k = E.distance(h, g);
|
|
3701
|
+
o.createCircle(p[0], k), s(), m([]);
|
|
3607
3702
|
}
|
|
3608
3703
|
} else {
|
|
3609
|
-
const
|
|
3610
|
-
|
|
3704
|
+
const h = o.createPoint(g.x, g.y);
|
|
3705
|
+
m([h.id]), s();
|
|
3611
3706
|
}
|
|
3612
3707
|
break;
|
|
3613
3708
|
}
|
|
3614
3709
|
case "midpoint": {
|
|
3615
|
-
const
|
|
3616
|
-
|
|
3617
|
-
const
|
|
3618
|
-
return
|
|
3710
|
+
const M = x(g);
|
|
3711
|
+
M && m((h) => {
|
|
3712
|
+
const k = [...h, M.id];
|
|
3713
|
+
return k.length === 2 ? (o.createMidpoint(k[0], k[1]), s(), []) : k;
|
|
3619
3714
|
});
|
|
3620
3715
|
break;
|
|
3621
3716
|
}
|
|
3622
3717
|
case "select": {
|
|
3623
|
-
const
|
|
3624
|
-
|
|
3718
|
+
const M = x(g);
|
|
3719
|
+
u(M ? [M.id] : []);
|
|
3625
3720
|
break;
|
|
3626
3721
|
}
|
|
3627
3722
|
}
|
|
3628
3723
|
},
|
|
3629
|
-
[n,
|
|
3630
|
-
),
|
|
3631
|
-
for (const
|
|
3632
|
-
if (
|
|
3633
|
-
return
|
|
3724
|
+
[n, o, s, y, p, u]
|
|
3725
|
+
), x = (b) => {
|
|
3726
|
+
for (const g of a)
|
|
3727
|
+
if (g.type === "point" && E.distance(g, b) < 0.5)
|
|
3728
|
+
return g;
|
|
3634
3729
|
};
|
|
3635
|
-
return
|
|
3636
|
-
const
|
|
3637
|
-
if (!(!
|
|
3638
|
-
if (
|
|
3639
|
-
|
|
3640
|
-
const
|
|
3641
|
-
for (let
|
|
3642
|
-
|
|
3643
|
-
for (let
|
|
3644
|
-
|
|
3730
|
+
return V(() => {
|
|
3731
|
+
const b = r.current, l = b == null ? void 0 : b.getContext("2d");
|
|
3732
|
+
if (!(!b || !l)) {
|
|
3733
|
+
if (l.fillStyle = `rgb(${i.backgroundColor.r},${i.backgroundColor.g},${i.backgroundColor.b})`, l.fillRect(0, 0, e, t), i.showGrid) {
|
|
3734
|
+
l.strokeStyle = I("var(--nice-border, #e0e0e0)", l.canvas), l.lineWidth = 0.5;
|
|
3735
|
+
const g = i.gridSpacing * i.scale, w = (e / 2 - i.centerX * i.scale) % g, M = (t / 2 + i.centerY * i.scale) % g;
|
|
3736
|
+
for (let h = w; h < e; h += g)
|
|
3737
|
+
l.beginPath(), l.moveTo(h, 0), l.lineTo(h, t), l.stroke();
|
|
3738
|
+
for (let h = M; h < t; h += g)
|
|
3739
|
+
l.beginPath(), l.moveTo(0, h), l.lineTo(e, h), l.stroke();
|
|
3645
3740
|
}
|
|
3646
3741
|
if (i.showAxes) {
|
|
3647
|
-
const
|
|
3648
|
-
|
|
3742
|
+
const g = f(0, 0);
|
|
3743
|
+
l.strokeStyle = I("var(--nice-text, #333)", l.canvas), l.lineWidth = 1, l.beginPath(), l.moveTo(0, g.y), l.lineTo(e, g.y), l.stroke(), l.beginPath(), l.moveTo(g.x, 0), l.lineTo(g.x, t), l.stroke();
|
|
3649
3744
|
}
|
|
3650
|
-
for (const
|
|
3651
|
-
if (!
|
|
3745
|
+
for (const g of a) {
|
|
3746
|
+
if (!g.visible)
|
|
3652
3747
|
continue;
|
|
3653
|
-
const
|
|
3654
|
-
switch (
|
|
3748
|
+
const w = `rgb(${g.color.r},${g.color.g},${g.color.b})`, M = c.includes(g.id);
|
|
3749
|
+
switch (g.type) {
|
|
3655
3750
|
case "point": {
|
|
3656
|
-
const
|
|
3657
|
-
|
|
3751
|
+
const h = f(g.x, g.y);
|
|
3752
|
+
l.beginPath(), l.arc(h.x, h.y, M ? g.size + 2 : g.size, 0, 2 * Math.PI), l.fillStyle = M ? I("var(--nice-primary-hover, #1976d2)", l.canvas) : w, l.fill(), g.label && (l.fillStyle = I("var(--nice-text, #333)", l.canvas), l.font = "12px sans-serif", l.fillText(g.label, h.x + 8, h.y - 8));
|
|
3658
3753
|
break;
|
|
3659
3754
|
}
|
|
3660
3755
|
case "segment": {
|
|
3661
|
-
const
|
|
3662
|
-
if (
|
|
3663
|
-
const
|
|
3664
|
-
|
|
3756
|
+
const h = o.getPoint(g.point1Id), k = o.getPoint(g.point2Id);
|
|
3757
|
+
if (h && k) {
|
|
3758
|
+
const S = f(h.x, h.y), D = f(k.x, k.y);
|
|
3759
|
+
l.strokeStyle = w, l.lineWidth = g.width, l.beginPath(), l.moveTo(S.x, S.y), l.lineTo(D.x, D.y), l.stroke();
|
|
3665
3760
|
}
|
|
3666
3761
|
break;
|
|
3667
3762
|
}
|
|
3668
3763
|
case "line": {
|
|
3669
|
-
const
|
|
3670
|
-
if (
|
|
3671
|
-
const
|
|
3672
|
-
|
|
3764
|
+
const h = o.getPoint(g.point1Id), k = o.getPoint(g.point2Id);
|
|
3765
|
+
if (h && k) {
|
|
3766
|
+
const S = k.x - h.x, D = k.y - h.y, _ = -1e3, K = 1e3, Z = f(h.x + _ * S, h.y + _ * D), Q = f(h.x + K * S, h.y + K * D);
|
|
3767
|
+
l.strokeStyle = w, l.lineWidth = g.width, l.beginPath(), l.moveTo(Z.x, Z.y), l.lineTo(Q.x, Q.y), l.stroke();
|
|
3673
3768
|
}
|
|
3674
3769
|
break;
|
|
3675
3770
|
}
|
|
3676
3771
|
case "circle": {
|
|
3677
|
-
const
|
|
3678
|
-
if (
|
|
3679
|
-
const
|
|
3680
|
-
|
|
3772
|
+
const h = o.getPoint(g.centerId);
|
|
3773
|
+
if (h) {
|
|
3774
|
+
const k = f(h.x, h.y), S = g.radius * i.scale;
|
|
3775
|
+
l.beginPath(), l.arc(k.x, k.y, S, 0, 2 * Math.PI), g.fill && (l.fillStyle = `rgba(${g.fill.r},${g.fill.g},${g.fill.b},${g.fill.a ?? 0.2})`, l.fill()), l.strokeStyle = w, l.lineWidth = g.width, l.stroke();
|
|
3681
3776
|
}
|
|
3682
3777
|
break;
|
|
3683
3778
|
}
|
|
3684
3779
|
case "polygon": {
|
|
3685
|
-
const
|
|
3686
|
-
if (
|
|
3687
|
-
|
|
3688
|
-
const
|
|
3689
|
-
|
|
3690
|
-
for (let
|
|
3691
|
-
const
|
|
3692
|
-
|
|
3780
|
+
const h = g.pointIds.map((k) => o.getPoint(k)).filter(Boolean);
|
|
3781
|
+
if (h.length > 0) {
|
|
3782
|
+
l.beginPath();
|
|
3783
|
+
const k = f(h[0].x, h[0].y);
|
|
3784
|
+
l.moveTo(k.x, k.y);
|
|
3785
|
+
for (let S = 1; S < h.length; S++) {
|
|
3786
|
+
const D = f(h[S].x, h[S].y);
|
|
3787
|
+
l.lineTo(D.x, D.y);
|
|
3693
3788
|
}
|
|
3694
|
-
|
|
3789
|
+
l.closePath(), g.fill && (l.fillStyle = `rgba(${g.fill.r},${g.fill.g},${g.fill.b},${g.fill.a ?? 0.2})`, l.fill()), l.strokeStyle = w, l.lineWidth = g.width, l.stroke();
|
|
3695
3790
|
}
|
|
3696
3791
|
break;
|
|
3697
3792
|
}
|
|
3698
3793
|
}
|
|
3699
3794
|
}
|
|
3700
|
-
if (
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3795
|
+
if (p.length > 0) {
|
|
3796
|
+
l.fillStyle = I(
|
|
3797
|
+
"var(--nice-primary-tint-30, rgba(25, 118, 210, 0.3))",
|
|
3798
|
+
l.canvas
|
|
3799
|
+
);
|
|
3800
|
+
for (const g of p) {
|
|
3801
|
+
const w = o.getPoint(g);
|
|
3802
|
+
if (w) {
|
|
3803
|
+
const M = f(w.x, w.y);
|
|
3804
|
+
l.beginPath(), l.arc(M.x, M.y, 12, 0, 2 * Math.PI), l.fill();
|
|
3707
3805
|
}
|
|
3708
3806
|
}
|
|
3709
3807
|
}
|
|
3710
3808
|
}
|
|
3711
|
-
}, [
|
|
3809
|
+
}, [a, i, e, t, c, p, o, f]), /* @__PURE__ */ d(
|
|
3712
3810
|
"canvas",
|
|
3713
3811
|
{
|
|
3714
3812
|
ref: r,
|
|
3715
3813
|
width: e,
|
|
3716
3814
|
height: t,
|
|
3717
|
-
style:
|
|
3718
|
-
onClick:
|
|
3815
|
+
style: q.canvas,
|
|
3816
|
+
onClick: C
|
|
3719
3817
|
}
|
|
3720
3818
|
);
|
|
3721
3819
|
}
|
|
3722
|
-
function
|
|
3820
|
+
function Ye({
|
|
3723
3821
|
width: e,
|
|
3724
3822
|
height: t
|
|
3725
3823
|
}) {
|
|
3726
|
-
const { tool: r, elements:
|
|
3824
|
+
const { tool: r, elements: o, view: a, service: n } = H(), [i, c] = P(null), u = {
|
|
3727
3825
|
select: "Select",
|
|
3728
3826
|
point: "Point",
|
|
3729
3827
|
line: "Line",
|
|
@@ -3745,56 +3843,56 @@ function StatusBar({
|
|
|
3745
3843
|
dilate: "Dilate",
|
|
3746
3844
|
measure: "Measure",
|
|
3747
3845
|
text: "Text"
|
|
3748
|
-
}, s =
|
|
3749
|
-
return /* @__PURE__ */
|
|
3750
|
-
/* @__PURE__ */
|
|
3846
|
+
}, s = o.filter((p) => p.type === "point").length;
|
|
3847
|
+
return /* @__PURE__ */ v("div", { style: q.statusBar, children: [
|
|
3848
|
+
/* @__PURE__ */ v("span", { children: [
|
|
3751
3849
|
"Tool: ",
|
|
3752
|
-
|
|
3850
|
+
u[r]
|
|
3753
3851
|
] }),
|
|
3754
|
-
/* @__PURE__ */
|
|
3755
|
-
/* @__PURE__ */
|
|
3852
|
+
/* @__PURE__ */ d("span", { style: { margin: "0 16px" }, children: "|" }),
|
|
3853
|
+
/* @__PURE__ */ v("span", { children: [
|
|
3756
3854
|
"Objects: ",
|
|
3757
|
-
|
|
3855
|
+
o.length
|
|
3758
3856
|
] }),
|
|
3759
|
-
/* @__PURE__ */
|
|
3760
|
-
/* @__PURE__ */
|
|
3857
|
+
/* @__PURE__ */ d("span", { style: { margin: "0 16px" }, children: "|" }),
|
|
3858
|
+
/* @__PURE__ */ v("span", { children: [
|
|
3761
3859
|
"Points: ",
|
|
3762
3860
|
s
|
|
3763
3861
|
] }),
|
|
3764
|
-
/* @__PURE__ */
|
|
3765
|
-
/* @__PURE__ */
|
|
3862
|
+
/* @__PURE__ */ d("span", { style: { margin: "0 16px" }, children: "|" }),
|
|
3863
|
+
/* @__PURE__ */ v("span", { children: [
|
|
3766
3864
|
"Scale: ",
|
|
3767
|
-
|
|
3865
|
+
a.scale.toFixed(1),
|
|
3768
3866
|
"x"
|
|
3769
3867
|
] })
|
|
3770
3868
|
] });
|
|
3771
3869
|
}
|
|
3772
3870
|
export {
|
|
3773
|
-
CalculatorService,
|
|
3774
|
-
CalculusOps,
|
|
3775
|
-
EQUATION_TEMPLATES,
|
|
3776
|
-
ExpressionParser,
|
|
3777
|
-
FUNCTION_PRESETS,
|
|
3778
|
-
GeoMath,
|
|
3779
|
-
GeometryService,
|
|
3780
|
-
GraphService,
|
|
3781
|
-
MATH_SYMBOLS,
|
|
3782
|
-
MathEditorService,
|
|
3783
|
-
MatrixOps,
|
|
3784
|
-
NiceCalculator,
|
|
3785
|
-
NiceGeometry,
|
|
3786
|
-
NiceGraphPlotter,
|
|
3787
|
-
NiceI18nProvider,
|
|
3788
|
-
NiceMathEditor,
|
|
3789
|
-
createCalculatorService,
|
|
3790
|
-
createGeometryService,
|
|
3791
|
-
createGraphService,
|
|
3792
|
-
createMathEditorService,
|
|
3793
|
-
getSymbolsByCategory,
|
|
3794
|
-
recognizeHandwriting,
|
|
3795
|
-
useCalculator,
|
|
3796
|
-
useGeometry,
|
|
3797
|
-
useGraph,
|
|
3798
|
-
useMathEditor,
|
|
3799
|
-
useNiceTranslation
|
|
3871
|
+
Le as CalculatorService,
|
|
3872
|
+
te as CalculusOps,
|
|
3873
|
+
we as EQUATION_TEMPLATES,
|
|
3874
|
+
ie as ExpressionParser,
|
|
3875
|
+
ee as FUNCTION_PRESETS,
|
|
3876
|
+
E as GeoMath,
|
|
3877
|
+
Oe as GeometryService,
|
|
3878
|
+
Te as GraphService,
|
|
3879
|
+
be as MATH_SYMBOLS,
|
|
3880
|
+
ke as MathEditorService,
|
|
3881
|
+
z as MatrixOps,
|
|
3882
|
+
at as NiceCalculator,
|
|
3883
|
+
it as NiceGeometry,
|
|
3884
|
+
rt as NiceGraphPlotter,
|
|
3885
|
+
Qe as NiceI18nProvider,
|
|
3886
|
+
et as NiceMathEditor,
|
|
3887
|
+
ot as createCalculatorService,
|
|
3888
|
+
nt as createGeometryService,
|
|
3889
|
+
tt as createGraphService,
|
|
3890
|
+
Je as createMathEditorService,
|
|
3891
|
+
ve as getSymbolsByCategory,
|
|
3892
|
+
Ce as recognizeHandwriting,
|
|
3893
|
+
N as useCalculator,
|
|
3894
|
+
H as useGeometry,
|
|
3895
|
+
Y as useGraph,
|
|
3896
|
+
W as useMathEditor,
|
|
3897
|
+
L as useNiceTranslation
|
|
3800
3898
|
};
|