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