@nice2dev/ui-math 1.1.10 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -6
- package/dist/index.cjs +5 -5
- package/dist/index.mjs +177 -157
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -21,6 +21,8 @@ const translations = {
|
|
|
21
21
|
"editor.clear": "Clear",
|
|
22
22
|
"editor.recognize": "Recognize",
|
|
23
23
|
"editor.recognizing": "Recognizing...",
|
|
24
|
+
"editor.latexInput": "LaTeX Input",
|
|
25
|
+
"editor.handwriting": "Handwriting",
|
|
24
26
|
"editor.handwritingNote": "Draw your equation above. Handwriting recognition requires external API integration."
|
|
25
27
|
},
|
|
26
28
|
pl: {
|
|
@@ -38,6 +40,8 @@ const translations = {
|
|
|
38
40
|
"editor.clear": "Wyczyść",
|
|
39
41
|
"editor.recognize": "Rozpoznaj",
|
|
40
42
|
"editor.recognizing": "Rozpoznawanie...",
|
|
43
|
+
"editor.latexInput": "Wpis LaTeX",
|
|
44
|
+
"editor.handwriting": "Pismo odręczne",
|
|
41
45
|
"editor.handwritingNote": "Narysuj równanie powyżej. Rozpoznawanie pisma wymaga zewnętrznej integracji API."
|
|
42
46
|
},
|
|
43
47
|
de: {
|
|
@@ -55,6 +59,8 @@ const translations = {
|
|
|
55
59
|
"editor.clear": "Löschen",
|
|
56
60
|
"editor.recognize": "Erkennen",
|
|
57
61
|
"editor.recognizing": "Erkennung läuft...",
|
|
62
|
+
"editor.latexInput": "LaTeX-Eingabe",
|
|
63
|
+
"editor.handwriting": "Handschrift",
|
|
58
64
|
"editor.handwritingNote": "Zeichnen Sie Ihre Gleichung oben. Die Handschrifterkennung erfordert eine externe API-Integration."
|
|
59
65
|
},
|
|
60
66
|
fr: {
|
|
@@ -72,6 +78,8 @@ const translations = {
|
|
|
72
78
|
"editor.clear": "Effacer",
|
|
73
79
|
"editor.recognize": "Reconnaître",
|
|
74
80
|
"editor.recognizing": "Reconnaissance...",
|
|
81
|
+
"editor.latexInput": "Saisie LaTeX",
|
|
82
|
+
"editor.handwriting": "Écriture manuscrite",
|
|
75
83
|
"editor.handwritingNote": "Dessinez votre équation ci-dessus. La reconnaissance d'écriture nécessite une intégration API externe."
|
|
76
84
|
},
|
|
77
85
|
es: {
|
|
@@ -89,6 +97,8 @@ const translations = {
|
|
|
89
97
|
"editor.clear": "Borrar",
|
|
90
98
|
"editor.recognize": "Reconocer",
|
|
91
99
|
"editor.recognizing": "Reconociendo...",
|
|
100
|
+
"editor.latexInput": "Entrada LaTeX",
|
|
101
|
+
"editor.handwriting": "Escritura a mano",
|
|
92
102
|
"editor.handwritingNote": "Dibuja tu ecuación arriba. El reconocimiento de escritura requiere integración con una API externa."
|
|
93
103
|
},
|
|
94
104
|
it: {
|
|
@@ -106,6 +116,8 @@ const translations = {
|
|
|
106
116
|
"editor.clear": "Cancella",
|
|
107
117
|
"editor.recognize": "Riconosci",
|
|
108
118
|
"editor.recognizing": "Riconoscimento...",
|
|
119
|
+
"editor.latexInput": "Input LaTeX",
|
|
120
|
+
"editor.handwriting": "Scrittura a mano",
|
|
109
121
|
"editor.handwritingNote": "Disegna la tua equazione qui sopra. Il riconoscimento della scrittura richiede un’integrazione API esterna."
|
|
110
122
|
},
|
|
111
123
|
pt: {
|
|
@@ -123,6 +135,8 @@ const translations = {
|
|
|
123
135
|
"editor.clear": "Limpar",
|
|
124
136
|
"editor.recognize": "Reconhecer",
|
|
125
137
|
"editor.recognizing": "A reconhecer...",
|
|
138
|
+
"editor.latexInput": "Entrada LaTeX",
|
|
139
|
+
"editor.handwriting": "Escrita à mão",
|
|
126
140
|
"editor.handwritingNote": "Desenhe a sua equação acima. O reconhecimento de escrita requer integração com uma API externa."
|
|
127
141
|
},
|
|
128
142
|
cs: {
|
|
@@ -140,6 +154,8 @@ const translations = {
|
|
|
140
154
|
"editor.clear": "Vymazat",
|
|
141
155
|
"editor.recognize": "Rozpoznat",
|
|
142
156
|
"editor.recognizing": "Rozpoznávání...",
|
|
157
|
+
"editor.latexInput": "Zadání LaTeX",
|
|
158
|
+
"editor.handwriting": "Rukopis",
|
|
143
159
|
"editor.handwritingNote": "Nakreslete svou rovnici výše. Rozpoznávání rukopisu vyžaduje externí integraci API."
|
|
144
160
|
},
|
|
145
161
|
uk: {
|
|
@@ -157,6 +173,8 @@ const translations = {
|
|
|
157
173
|
"editor.clear": "Очистити",
|
|
158
174
|
"editor.recognize": "Розпізнати",
|
|
159
175
|
"editor.recognizing": "Розпізнавання...",
|
|
176
|
+
"editor.latexInput": "Введення LaTeX",
|
|
177
|
+
"editor.handwriting": "Рукопис",
|
|
160
178
|
"editor.handwritingNote": "Намалюйте своє рівняння вище. Розпізнавання рукопису потребує зовнішньої інтеграції з API."
|
|
161
179
|
}
|
|
162
180
|
}, I18nContext = createContext({
|
|
@@ -623,9 +641,9 @@ function NiceMathEditor({
|
|
|
623
641
|
y(l + f);
|
|
624
642
|
return;
|
|
625
643
|
}
|
|
626
|
-
const
|
|
644
|
+
const u = c.selectionStart, b = c.selectionEnd, k = l.slice(0, u) + f + l.slice(b);
|
|
627
645
|
y(k), setTimeout(() => {
|
|
628
|
-
c.focus(), c.selectionStart = c.selectionEnd =
|
|
646
|
+
c.focus(), c.selectionStart = c.selectionEnd = u + f.length;
|
|
629
647
|
}, 0);
|
|
630
648
|
},
|
|
631
649
|
[l, y]
|
|
@@ -634,7 +652,7 @@ function NiceMathEditor({
|
|
|
634
652
|
h(f.latex);
|
|
635
653
|
},
|
|
636
654
|
[h]
|
|
637
|
-
),
|
|
655
|
+
), x = {
|
|
638
656
|
service: e,
|
|
639
657
|
latex: l,
|
|
640
658
|
setLatex: y,
|
|
@@ -643,7 +661,7 @@ function NiceMathEditor({
|
|
|
643
661
|
mode: s,
|
|
644
662
|
setMode: d
|
|
645
663
|
};
|
|
646
|
-
return /* @__PURE__ */ jsx(MathEditorContext.Provider, { value:
|
|
664
|
+
return /* @__PURE__ */ jsx(MathEditorContext.Provider, { value: x, children: /* @__PURE__ */ jsxs(
|
|
647
665
|
NiceAppShell,
|
|
648
666
|
{
|
|
649
667
|
flush: !0,
|
|
@@ -671,36 +689,38 @@ function NiceMathEditor({
|
|
|
671
689
|
) });
|
|
672
690
|
}
|
|
673
691
|
function Toolbar$1() {
|
|
674
|
-
const {
|
|
692
|
+
const { t: e } = useNiceTranslation(), { mode: t, setMode: r, latex: a, insertTemplate: o } = useMathEditor(), [n, i] = useState(!1);
|
|
675
693
|
return /* @__PURE__ */ jsxs("div", { style: styles$3.toolbar, children: [
|
|
676
694
|
/* @__PURE__ */ jsxs(
|
|
677
695
|
"button",
|
|
678
696
|
{
|
|
679
|
-
onClick: () =>
|
|
697
|
+
onClick: () => r("input"),
|
|
680
698
|
style: {
|
|
681
699
|
...styles$3.button,
|
|
682
|
-
backgroundColor:
|
|
700
|
+
backgroundColor: t === "input" ? "var(--nice-primary-hover, #1976d2)" : "var(--nice-bg-tertiary, #9e9e9e)",
|
|
683
701
|
// the inactive state sits on a theme surface: theme text, not the button's white
|
|
684
|
-
color:
|
|
702
|
+
color: t === "input" ? "var(--nice-color-white, #fff)" : "var(--nice-text-primary, #fff)"
|
|
685
703
|
},
|
|
686
704
|
children: [
|
|
687
705
|
/* @__PURE__ */ jsx(NiceIcon, { name: "keyboard", size: 14 }),
|
|
688
|
-
"
|
|
706
|
+
" ",
|
|
707
|
+
e("editor.latexInput", "LaTeX Input")
|
|
689
708
|
]
|
|
690
709
|
}
|
|
691
710
|
),
|
|
692
711
|
/* @__PURE__ */ jsxs(
|
|
693
712
|
"button",
|
|
694
713
|
{
|
|
695
|
-
onClick: () =>
|
|
714
|
+
onClick: () => r("handwriting"),
|
|
696
715
|
style: {
|
|
697
716
|
...styles$3.button,
|
|
698
|
-
backgroundColor:
|
|
699
|
-
color:
|
|
717
|
+
backgroundColor: t === "handwriting" ? "var(--nice-primary-hover, #1976d2)" : "var(--nice-bg-tertiary, #9e9e9e)",
|
|
718
|
+
color: t === "handwriting" ? "var(--nice-color-white, #fff)" : "var(--nice-text-primary, #fff)"
|
|
700
719
|
},
|
|
701
720
|
children: [
|
|
702
721
|
/* @__PURE__ */ jsx(NiceIcon, { name: "pen", size: 14 }),
|
|
703
|
-
"
|
|
722
|
+
" ",
|
|
723
|
+
e("editor.handwriting", "Handwriting")
|
|
704
724
|
]
|
|
705
725
|
}
|
|
706
726
|
),
|
|
@@ -715,12 +735,12 @@ function Toolbar$1() {
|
|
|
715
735
|
}
|
|
716
736
|
),
|
|
717
737
|
/* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
|
|
718
|
-
/* @__PURE__ */ jsxs("button", { onClick: () =>
|
|
738
|
+
/* @__PURE__ */ jsxs("button", { onClick: () => i(!n), style: styles$3.button, children: [
|
|
719
739
|
/* @__PURE__ */ jsx(NiceIcon, { name: "ruler", size: 14 }),
|
|
720
740
|
" Templates ",
|
|
721
741
|
/* @__PURE__ */ jsx(NiceIcon, { name: "chevron-down", size: 12 })
|
|
722
742
|
] }),
|
|
723
|
-
|
|
743
|
+
n && /* @__PURE__ */ jsx(
|
|
724
744
|
"div",
|
|
725
745
|
{
|
|
726
746
|
style: {
|
|
@@ -737,23 +757,23 @@ function Toolbar$1() {
|
|
|
737
757
|
overflow: "auto"
|
|
738
758
|
},
|
|
739
759
|
children: ["basic", "calculus", "algebra", "geometry", "statistics", "physics"].map(
|
|
740
|
-
(
|
|
741
|
-
/* @__PURE__ */ jsx("div", { style: styles$3.categoryHeader, children:
|
|
742
|
-
EQUATION_TEMPLATES.filter((
|
|
760
|
+
(l) => /* @__PURE__ */ jsxs("div", { children: [
|
|
761
|
+
/* @__PURE__ */ jsx("div", { style: styles$3.categoryHeader, children: l }),
|
|
762
|
+
EQUATION_TEMPLATES.filter((p) => p.category === l).map((p) => /* @__PURE__ */ jsxs(
|
|
743
763
|
"div",
|
|
744
764
|
{
|
|
745
765
|
onClick: () => {
|
|
746
|
-
|
|
766
|
+
o(p), i(!1);
|
|
747
767
|
},
|
|
748
768
|
style: {
|
|
749
769
|
padding: "8px 12px",
|
|
750
770
|
cursor: "pointer",
|
|
751
771
|
borderBottom: "1px solid var(--nice-border, #eee)"
|
|
752
772
|
},
|
|
753
|
-
onMouseOver: (
|
|
754
|
-
onMouseOut: (
|
|
773
|
+
onMouseOver: (s) => s.target.style.backgroundColor = "var(--nice-bg-secondary, #f5f5f5)",
|
|
774
|
+
onMouseOut: (s) => s.target.style.backgroundColor = "transparent",
|
|
755
775
|
children: [
|
|
756
|
-
/* @__PURE__ */ jsx("div", { style: { fontWeight: 500 }, children:
|
|
776
|
+
/* @__PURE__ */ jsx("div", { style: { fontWeight: 500 }, children: p.name }),
|
|
757
777
|
/* @__PURE__ */ jsxs(
|
|
758
778
|
"div",
|
|
759
779
|
{
|
|
@@ -763,16 +783,16 @@ function Toolbar$1() {
|
|
|
763
783
|
fontFamily: "monospace"
|
|
764
784
|
},
|
|
765
785
|
children: [
|
|
766
|
-
|
|
767
|
-
|
|
786
|
+
p.latex.substring(0, 40),
|
|
787
|
+
p.latex.length > 40 ? "..." : ""
|
|
768
788
|
]
|
|
769
789
|
}
|
|
770
790
|
)
|
|
771
791
|
]
|
|
772
792
|
},
|
|
773
|
-
|
|
793
|
+
p.name
|
|
774
794
|
))
|
|
775
|
-
] },
|
|
795
|
+
] }, l)
|
|
776
796
|
)
|
|
777
797
|
}
|
|
778
798
|
)
|
|
@@ -781,7 +801,7 @@ function Toolbar$1() {
|
|
|
781
801
|
/* @__PURE__ */ jsxs(
|
|
782
802
|
"button",
|
|
783
803
|
{
|
|
784
|
-
onClick: () => navigator.clipboard.writeText(
|
|
804
|
+
onClick: () => navigator.clipboard.writeText(a),
|
|
785
805
|
style: { ...styles$3.button, backgroundColor: "var(--nice-success, #4caf50)" },
|
|
786
806
|
children: [
|
|
787
807
|
/* @__PURE__ */ jsx(NiceIcon, { name: "copy", size: 14 }),
|
|
@@ -816,7 +836,7 @@ function SymbolPalette() {
|
|
|
816
836
|
border: "1px solid var(--nice-border, #ddd)",
|
|
817
837
|
borderRadius: "4px",
|
|
818
838
|
backgroundColor: t === n ? "var(--nice-primary-hover, #1976d2)" : "var(--nice-bg, #fff)",
|
|
819
|
-
color: t === n ? "var(--nice-
|
|
839
|
+
color: t === n ? "var(--nice-color-white, #fff)" : "var(--nice-text, #333)",
|
|
820
840
|
cursor: "pointer"
|
|
821
841
|
},
|
|
822
842
|
children: n
|
|
@@ -849,11 +869,11 @@ function LatexPreview({ latex: e }) {
|
|
|
849
869
|
}
|
|
850
870
|
function HandwritingCanvas() {
|
|
851
871
|
const { t: e } = useNiceTranslation(), { setLatex: t, setMode: r } = useMathEditor(), a = useRef(null), [o, n] = useState([]), [i, l] = useState([]), [p, s] = useState(!1), [d, g] = useState(!1), y = (c) => {
|
|
852
|
-
const
|
|
853
|
-
if (!
|
|
872
|
+
const u = a.current;
|
|
873
|
+
if (!u)
|
|
854
874
|
return;
|
|
855
875
|
s(!0);
|
|
856
|
-
const b =
|
|
876
|
+
const b = u.getBoundingClientRect();
|
|
857
877
|
l([
|
|
858
878
|
{
|
|
859
879
|
x: c.clientX - b.left,
|
|
@@ -865,10 +885,10 @@ function HandwritingCanvas() {
|
|
|
865
885
|
}, h = (c) => {
|
|
866
886
|
if (!p)
|
|
867
887
|
return;
|
|
868
|
-
const
|
|
869
|
-
if (!
|
|
888
|
+
const u = a.current, b = u == null ? void 0 : u.getContext("2d");
|
|
889
|
+
if (!u || !b)
|
|
870
890
|
return;
|
|
871
|
-
const k =
|
|
891
|
+
const k = u.getBoundingClientRect(), m = {
|
|
872
892
|
x: c.clientX - k.left,
|
|
873
893
|
y: c.clientY - k.top,
|
|
874
894
|
pressure: c.pressure,
|
|
@@ -885,13 +905,13 @@ function HandwritingCanvas() {
|
|
|
885
905
|
id: Date.now().toString(),
|
|
886
906
|
points: [...i]
|
|
887
907
|
};
|
|
888
|
-
n((
|
|
908
|
+
n((u) => [...u, c]);
|
|
889
909
|
}
|
|
890
910
|
l([]);
|
|
891
911
|
}
|
|
892
|
-
},
|
|
893
|
-
const c = a.current,
|
|
894
|
-
|
|
912
|
+
}, x = () => {
|
|
913
|
+
const c = a.current, u = c == null ? void 0 : c.getContext("2d");
|
|
914
|
+
u && c && u.clearRect(0, 0, c.width, c.height), n([]);
|
|
895
915
|
}, f = async () => {
|
|
896
916
|
if (o.length !== 0) {
|
|
897
917
|
g(!0);
|
|
@@ -922,7 +942,7 @@ function HandwritingCanvas() {
|
|
|
922
942
|
/* @__PURE__ */ jsx(
|
|
923
943
|
"button",
|
|
924
944
|
{
|
|
925
|
-
onClick:
|
|
945
|
+
onClick: x,
|
|
926
946
|
style: { ...styles$3.button, backgroundColor: "var(--nice-danger, #f44336)" },
|
|
927
947
|
children: e("editor.clear", "Clear")
|
|
928
948
|
}
|
|
@@ -1188,8 +1208,8 @@ class GraphService {
|
|
|
1188
1208
|
for (let h = 0; h <= o; h++) {
|
|
1189
1209
|
const w = a.min + h * s;
|
|
1190
1210
|
try {
|
|
1191
|
-
const
|
|
1192
|
-
Number.isFinite(
|
|
1211
|
+
const x = i({ x: y, y: w, ...n });
|
|
1212
|
+
Number.isFinite(x) ? g.push({ x: y, y: w, z: x }) : g.push({ x: y, y: w, z: 0 });
|
|
1193
1213
|
} catch {
|
|
1194
1214
|
g.push({ x: y, y: w, z: 0 });
|
|
1195
1215
|
}
|
|
@@ -1225,7 +1245,7 @@ class GraphService {
|
|
|
1225
1245
|
if (g.type === "2d-function") {
|
|
1226
1246
|
const y = this.compute2DFunction(g.expression, r.xRange, g.resolution || 200);
|
|
1227
1247
|
if (y.length > 0) {
|
|
1228
|
-
const h = y.map((w,
|
|
1248
|
+
const h = y.map((w, x) => `${x === 0 ? "M" : "L"}${p(w.x)},${s(w.y)}`).join(" ");
|
|
1229
1249
|
d.push(
|
|
1230
1250
|
`<path d="${h}" fill="none" stroke="rgb(${g.color.r},${g.color.g},${g.color.b})" stroke-width="${g.lineWidth}"/>`
|
|
1231
1251
|
);
|
|
@@ -1438,23 +1458,23 @@ function NiceGraphPlotter({
|
|
|
1438
1458
|
speed: 1
|
|
1439
1459
|
}), g = useCallback(() => {
|
|
1440
1460
|
i(e.getPlots());
|
|
1441
|
-
}, [e]), y = useCallback((
|
|
1442
|
-
p((b) => ({ ...b, ...
|
|
1443
|
-
}, []), h = useCallback((
|
|
1444
|
-
d((b) => ({ ...b, ...
|
|
1461
|
+
}, [e]), y = useCallback((u) => {
|
|
1462
|
+
p((b) => ({ ...b, ...u }));
|
|
1463
|
+
}, []), h = useCallback((u) => {
|
|
1464
|
+
d((b) => ({ ...b, ...u }));
|
|
1445
1465
|
}, []), w = useCallback(
|
|
1446
|
-
(
|
|
1447
|
-
e.addPlot(
|
|
1466
|
+
(u) => {
|
|
1467
|
+
e.addPlot(u), g();
|
|
1448
1468
|
},
|
|
1449
1469
|
[e, g]
|
|
1450
|
-
),
|
|
1451
|
-
(
|
|
1452
|
-
e.removePlot(
|
|
1470
|
+
), x = useCallback(
|
|
1471
|
+
(u) => {
|
|
1472
|
+
e.removePlot(u), g();
|
|
1453
1473
|
},
|
|
1454
1474
|
[e, g]
|
|
1455
1475
|
), f = useCallback(
|
|
1456
|
-
(
|
|
1457
|
-
e.updatePlot(
|
|
1476
|
+
(u, b) => {
|
|
1477
|
+
e.updatePlot(u, b), g();
|
|
1458
1478
|
},
|
|
1459
1479
|
[e, g]
|
|
1460
1480
|
), c = {
|
|
@@ -1463,7 +1483,7 @@ function NiceGraphPlotter({
|
|
|
1463
1483
|
view: l,
|
|
1464
1484
|
setView: y,
|
|
1465
1485
|
addPlot: w,
|
|
1466
|
-
removePlot:
|
|
1486
|
+
removePlot: x,
|
|
1467
1487
|
updatePlot: f,
|
|
1468
1488
|
animation: s,
|
|
1469
1489
|
setAnimation: h,
|
|
@@ -1746,73 +1766,73 @@ function Canvas2D({ width: e, height: t }) {
|
|
|
1746
1766
|
if (!p || !s)
|
|
1747
1767
|
return;
|
|
1748
1768
|
s.fillStyle = `rgb(${n.backgroundColor.r},${n.backgroundColor.g},${n.backgroundColor.b})`, s.fillRect(0, 0, e, t);
|
|
1749
|
-
const d = e - l * 2, g = t - l * 2, y = (
|
|
1769
|
+
const d = e - l * 2, g = t - l * 2, y = (x) => l + (x - n.xRange.min) / (n.xRange.max - n.xRange.min) * d, h = (x) => t - l - (x - n.yRange.min) / (n.yRange.max - n.yRange.min) * g;
|
|
1750
1770
|
if (n.showGrid) {
|
|
1751
1771
|
s.strokeStyle = resolveCssColor("var(--nice-border, #e0e0e0)", s.canvas), s.lineWidth = 0.5;
|
|
1752
|
-
for (let
|
|
1753
|
-
const f = y(
|
|
1772
|
+
for (let x = Math.ceil(n.xRange.min); x <= n.xRange.max; x++) {
|
|
1773
|
+
const f = y(x);
|
|
1754
1774
|
s.beginPath(), s.moveTo(f, l), s.lineTo(f, t - l), s.stroke();
|
|
1755
1775
|
}
|
|
1756
|
-
for (let
|
|
1757
|
-
const f = h(
|
|
1776
|
+
for (let x = Math.ceil(n.yRange.min); x <= n.yRange.max; x++) {
|
|
1777
|
+
const f = h(x);
|
|
1758
1778
|
s.beginPath(), s.moveTo(l, f), s.lineTo(e - l, f), s.stroke();
|
|
1759
1779
|
}
|
|
1760
1780
|
}
|
|
1761
1781
|
if (n.showAxes) {
|
|
1762
1782
|
s.strokeStyle = resolveCssColor("var(--nice-text, #333)", s.canvas), s.lineWidth = 1;
|
|
1763
|
-
const
|
|
1764
|
-
s.beginPath(), s.moveTo(l,
|
|
1783
|
+
const x = h(0);
|
|
1784
|
+
s.beginPath(), s.moveTo(l, x), s.lineTo(e - l, x), s.stroke();
|
|
1765
1785
|
const f = y(0);
|
|
1766
1786
|
if (s.beginPath(), s.moveTo(f, l), s.lineTo(f, t - l), s.stroke(), n.showLabels) {
|
|
1767
|
-
s.fillStyle = resolveCssColor("var(--nice-text, #333)", s.canvas), s.font = "12px sans-serif", s.textAlign = "center", s.fillText("x", e - l + 15,
|
|
1787
|
+
s.fillStyle = resolveCssColor("var(--nice-text, #333)", s.canvas), s.font = "12px sans-serif", s.textAlign = "center", s.fillText("x", e - l + 15, x + 4), s.fillText("y", f, l - 10), s.font = "10px sans-serif";
|
|
1768
1788
|
for (let c = Math.ceil(n.xRange.min); c <= n.xRange.max; c++)
|
|
1769
|
-
c !== 0 && s.fillText(String(c), y(c),
|
|
1789
|
+
c !== 0 && s.fillText(String(c), y(c), x + 15);
|
|
1770
1790
|
for (let c = Math.ceil(n.yRange.min); c <= n.yRange.max; c++)
|
|
1771
1791
|
c !== 0 && (s.textAlign = "right", s.fillText(String(c), f - 5, h(c) + 4));
|
|
1772
1792
|
}
|
|
1773
1793
|
}
|
|
1774
1794
|
const w = i.isPlaying ? { [i.parameter]: i.currentValue } : {};
|
|
1775
|
-
for (const
|
|
1776
|
-
const f = `rgb(${
|
|
1777
|
-
s.strokeStyle = f, s.lineWidth =
|
|
1795
|
+
for (const x of o.filter((f) => f.visible)) {
|
|
1796
|
+
const f = `rgb(${x.color.r},${x.color.g},${x.color.b})`;
|
|
1797
|
+
s.strokeStyle = f, s.lineWidth = x.lineWidth || 2;
|
|
1778
1798
|
let c = [];
|
|
1779
|
-
switch (
|
|
1799
|
+
switch (x.type) {
|
|
1780
1800
|
case "2d-function":
|
|
1781
1801
|
c = a.compute2DFunction(
|
|
1782
|
-
|
|
1802
|
+
x.expression,
|
|
1783
1803
|
n.xRange,
|
|
1784
|
-
|
|
1804
|
+
x.resolution || 200,
|
|
1785
1805
|
w
|
|
1786
1806
|
);
|
|
1787
1807
|
break;
|
|
1788
1808
|
case "2d-parametric":
|
|
1789
1809
|
c = a.compute2DParametric(
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1810
|
+
x.expression,
|
|
1811
|
+
x.expressionY || "sin(t)",
|
|
1812
|
+
x.parameterRange || { min: 0, max: 2 * Math.PI },
|
|
1813
|
+
x.resolution || 200,
|
|
1794
1814
|
w
|
|
1795
1815
|
);
|
|
1796
1816
|
break;
|
|
1797
1817
|
case "2d-polar":
|
|
1798
1818
|
c = a.compute2DPolar(
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1819
|
+
x.expression,
|
|
1820
|
+
x.parameterRange || { min: 0, max: 2 * Math.PI },
|
|
1821
|
+
x.resolution || 200,
|
|
1802
1822
|
w
|
|
1803
1823
|
);
|
|
1804
1824
|
break;
|
|
1805
1825
|
}
|
|
1806
1826
|
if (c.length > 0) {
|
|
1807
1827
|
s.beginPath();
|
|
1808
|
-
let
|
|
1828
|
+
let u = !1;
|
|
1809
1829
|
for (const b of c) {
|
|
1810
1830
|
const k = y(b.x), m = h(b.y);
|
|
1811
1831
|
if (m < 0 || m > t) {
|
|
1812
|
-
|
|
1832
|
+
u = !1;
|
|
1813
1833
|
continue;
|
|
1814
1834
|
}
|
|
1815
|
-
|
|
1835
|
+
u ? s.lineTo(k, m) : (s.moveTo(k, m), u = !0);
|
|
1816
1836
|
}
|
|
1817
1837
|
s.stroke();
|
|
1818
1838
|
}
|
|
@@ -2430,7 +2450,7 @@ const styles$1 = {
|
|
|
2430
2450
|
padding: "20px",
|
|
2431
2451
|
border: "none",
|
|
2432
2452
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2433
|
-
color: "var(--nice-
|
|
2453
|
+
color: "var(--nice-color-white, #fff)",
|
|
2434
2454
|
fontSize: "18px",
|
|
2435
2455
|
cursor: "pointer",
|
|
2436
2456
|
transition: "background-color 0.1s"
|
|
@@ -2449,15 +2469,15 @@ function NiceCalculator({
|
|
|
2449
2469
|
style: r
|
|
2450
2470
|
}) {
|
|
2451
2471
|
const [a, o] = useState("0"), [n, i] = useState("standard"), [l, p] = useState([]), [s, d] = useState(!1), g = useCallback(
|
|
2452
|
-
(
|
|
2453
|
-
s && /[0-9.]/.test(
|
|
2472
|
+
(x) => {
|
|
2473
|
+
s && /[0-9.]/.test(x) ? (o(x), d(!1)) : (o((f) => f === "0" && x !== "." ? x : f + x), d(!1));
|
|
2454
2474
|
},
|
|
2455
2475
|
[s]
|
|
2456
2476
|
), y = useCallback(() => {
|
|
2457
2477
|
o("0"), d(!1);
|
|
2458
2478
|
}, []), h = useCallback(() => {
|
|
2459
2479
|
try {
|
|
2460
|
-
const
|
|
2480
|
+
const x = e.evaluate(a), f = e.format(x);
|
|
2461
2481
|
e.addHistory(a, f, n), p(e.getHistory()), o(f), d(!0);
|
|
2462
2482
|
} catch {
|
|
2463
2483
|
o("Error"), d(!0);
|
|
@@ -2500,7 +2520,7 @@ function ModeSelector() {
|
|
|
2500
2520
|
style: {
|
|
2501
2521
|
...styles$1.modeButton,
|
|
2502
2522
|
backgroundColor: e === a.id ? "var(--nice-primary-hover, #1976d2)" : "transparent",
|
|
2503
|
-
color: e === a.id ? "var(--nice-
|
|
2523
|
+
color: e === a.id ? "var(--nice-color-white, #fff)" : "var(--nice-text-secondary, #888)"
|
|
2504
2524
|
},
|
|
2505
2525
|
children: a.label
|
|
2506
2526
|
},
|
|
@@ -2608,7 +2628,7 @@ function ProgrammerKeypad() {
|
|
|
2608
2628
|
border: "none",
|
|
2609
2629
|
borderRadius: "4px",
|
|
2610
2630
|
backgroundColor: a === l ? "var(--nice-primary-hover, #1976d2)" : "var(--nice-border, #3c3c3c)",
|
|
2611
|
-
color: "var(--nice-
|
|
2631
|
+
color: "var(--nice-color-white, #fff)",
|
|
2612
2632
|
cursor: "pointer"
|
|
2613
2633
|
},
|
|
2614
2634
|
children: l
|
|
@@ -2659,7 +2679,7 @@ function ProgrammerKeypad() {
|
|
|
2659
2679
|
}
|
|
2660
2680
|
function MatrixMode() {
|
|
2661
2681
|
const { t: e } = useNiceTranslation(), [t, r] = useState(MatrixOps.create(2, 2)), [a, o] = useState(MatrixOps.create(2, 2)), [n, i] = useState(""), l = (s, d, g, y, h) => {
|
|
2662
|
-
const w = { ...s, data: s.data.map((
|
|
2682
|
+
const w = { ...s, data: s.data.map((x) => [...x]) };
|
|
2663
2683
|
w.data[g][y] = parseFloat(h) || 0, d(w);
|
|
2664
2684
|
}, p = [
|
|
2665
2685
|
{ label: "A + B", fn: () => MatrixOps.toString(MatrixOps.add(t, a)) },
|
|
@@ -2747,7 +2767,7 @@ function MatrixInput({
|
|
|
2747
2767
|
padding: "4px",
|
|
2748
2768
|
textAlign: "center",
|
|
2749
2769
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2750
|
-
color: "var(--nice-
|
|
2770
|
+
color: "var(--nice-color-white, #fff)",
|
|
2751
2771
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2752
2772
|
borderRadius: "4px"
|
|
2753
2773
|
}
|
|
@@ -2773,7 +2793,7 @@ function CalculusMode() {
|
|
|
2773
2793
|
padding: "8px",
|
|
2774
2794
|
marginBottom: "12px",
|
|
2775
2795
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2776
|
-
color: "var(--nice-
|
|
2796
|
+
color: "var(--nice-color-white, #fff)",
|
|
2777
2797
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2778
2798
|
borderRadius: "4px"
|
|
2779
2799
|
}
|
|
@@ -2829,10 +2849,10 @@ function CalculusMode() {
|
|
|
2829
2849
|
function UnitsMode() {
|
|
2830
2850
|
const { t: e } = useNiceTranslation(), { service: t } = useCalculator(), [r, a] = useState("1"), [o, n] = useState("m"), [i, l] = useState("ft"), [p, s] = useState("Length"), [d, g] = useState(""), y = t.getUnitCategories(), h = t.getUnitsByCategory(p), w = () => {
|
|
2831
2851
|
try {
|
|
2832
|
-
const
|
|
2833
|
-
g(`${r} ${o} = ${t.format(
|
|
2834
|
-
} catch (
|
|
2835
|
-
g(
|
|
2852
|
+
const x = t.convertUnits(parseFloat(r), o, i);
|
|
2853
|
+
g(`${r} ${o} = ${t.format(x)} ${i}`);
|
|
2854
|
+
} catch (x) {
|
|
2855
|
+
g(x.message);
|
|
2836
2856
|
}
|
|
2837
2857
|
};
|
|
2838
2858
|
return /* @__PURE__ */ jsxs("div", { style: { padding: "12px", backgroundColor: "var(--nice-bg-secondary, #252525)" }, children: [
|
|
@@ -2840,9 +2860,9 @@ function UnitsMode() {
|
|
|
2840
2860
|
"select",
|
|
2841
2861
|
{
|
|
2842
2862
|
value: p,
|
|
2843
|
-
onChange: (
|
|
2844
|
-
s(
|
|
2845
|
-
const f = t.getUnitsByCategory(
|
|
2863
|
+
onChange: (x) => {
|
|
2864
|
+
s(x.target.value);
|
|
2865
|
+
const f = t.getUnitsByCategory(x.target.value);
|
|
2846
2866
|
f.length >= 2 && (n(f[0].symbol), l(f[1].symbol));
|
|
2847
2867
|
},
|
|
2848
2868
|
style: {
|
|
@@ -2850,11 +2870,11 @@ function UnitsMode() {
|
|
|
2850
2870
|
padding: "8px",
|
|
2851
2871
|
marginBottom: "12px",
|
|
2852
2872
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2853
|
-
color: "var(--nice-
|
|
2873
|
+
color: "var(--nice-color-white, #fff)",
|
|
2854
2874
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2855
2875
|
borderRadius: "4px"
|
|
2856
2876
|
},
|
|
2857
|
-
children: y.map((
|
|
2877
|
+
children: y.map((x) => /* @__PURE__ */ jsx("option", { value: x, children: x }, x))
|
|
2858
2878
|
}
|
|
2859
2879
|
),
|
|
2860
2880
|
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "8px", alignItems: "center", marginBottom: "12px" }, children: [
|
|
@@ -2863,12 +2883,12 @@ function UnitsMode() {
|
|
|
2863
2883
|
{
|
|
2864
2884
|
type: "number",
|
|
2865
2885
|
value: r,
|
|
2866
|
-
onChange: (
|
|
2886
|
+
onChange: (x) => a(x.target.value),
|
|
2867
2887
|
style: {
|
|
2868
2888
|
flex: 1,
|
|
2869
2889
|
padding: "8px",
|
|
2870
2890
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2871
|
-
color: "var(--nice-
|
|
2891
|
+
color: "var(--nice-color-white, #fff)",
|
|
2872
2892
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2873
2893
|
borderRadius: "4px"
|
|
2874
2894
|
}
|
|
@@ -2878,20 +2898,20 @@ function UnitsMode() {
|
|
|
2878
2898
|
"select",
|
|
2879
2899
|
{
|
|
2880
2900
|
value: o,
|
|
2881
|
-
onChange: (
|
|
2901
|
+
onChange: (x) => n(x.target.value),
|
|
2882
2902
|
style: {
|
|
2883
2903
|
padding: "8px",
|
|
2884
2904
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2885
|
-
color: "var(--nice-
|
|
2905
|
+
color: "var(--nice-color-white, #fff)",
|
|
2886
2906
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2887
2907
|
borderRadius: "4px"
|
|
2888
2908
|
},
|
|
2889
|
-
children: h.map((
|
|
2890
|
-
|
|
2909
|
+
children: h.map((x) => /* @__PURE__ */ jsxs("option", { value: x.symbol, children: [
|
|
2910
|
+
x.name,
|
|
2891
2911
|
" (",
|
|
2892
|
-
|
|
2912
|
+
x.symbol,
|
|
2893
2913
|
")"
|
|
2894
|
-
] },
|
|
2914
|
+
] }, x.symbol))
|
|
2895
2915
|
}
|
|
2896
2916
|
)
|
|
2897
2917
|
] }),
|
|
@@ -2901,21 +2921,21 @@ function UnitsMode() {
|
|
|
2901
2921
|
"select",
|
|
2902
2922
|
{
|
|
2903
2923
|
value: i,
|
|
2904
|
-
onChange: (
|
|
2924
|
+
onChange: (x) => l(x.target.value),
|
|
2905
2925
|
style: {
|
|
2906
2926
|
flex: 1,
|
|
2907
2927
|
padding: "8px",
|
|
2908
2928
|
backgroundColor: "var(--nice-border, #3c3c3c)",
|
|
2909
|
-
color: "var(--nice-
|
|
2929
|
+
color: "var(--nice-color-white, #fff)",
|
|
2910
2930
|
border: "1px solid var(--nice-border-color, #555)",
|
|
2911
2931
|
borderRadius: "4px"
|
|
2912
2932
|
},
|
|
2913
|
-
children: h.map((
|
|
2914
|
-
|
|
2933
|
+
children: h.map((x) => /* @__PURE__ */ jsxs("option", { value: x.symbol, children: [
|
|
2934
|
+
x.name,
|
|
2915
2935
|
" (",
|
|
2916
|
-
|
|
2936
|
+
x.symbol,
|
|
2917
2937
|
")"
|
|
2918
|
-
] },
|
|
2938
|
+
] }, x.symbol))
|
|
2919
2939
|
}
|
|
2920
2940
|
)
|
|
2921
2941
|
] }),
|
|
@@ -2990,8 +3010,8 @@ const GeoMath = {
|
|
|
2990
3010
|
const o = a.x - r.x, n = a.y - r.y, i = r.x - e.x, l = r.y - e.y, p = o * o + n * n, s = 2 * (i * o + l * n), d = i * i + l * l - t * t, g = s * s - 4 * p * d;
|
|
2991
3011
|
if (g < 0)
|
|
2992
3012
|
return [];
|
|
2993
|
-
const y = Math.sqrt(g), h = (-s - y) / (2 * p), w = (-s + y) / (2 * p),
|
|
2994
|
-
return h >= 0 && h <= 1 &&
|
|
3013
|
+
const y = Math.sqrt(g), h = (-s - y) / (2 * p), w = (-s + y) / (2 * p), x = [];
|
|
3014
|
+
return h >= 0 && h <= 1 && x.push({ x: r.x + h * o, y: r.y + h * n }), w >= 0 && w <= 1 && Math.abs(w - h) > 1e-10 && x.push({ x: r.x + w * o, y: r.y + w * n }), x;
|
|
2995
3015
|
},
|
|
2996
3016
|
/** Circle-circle intersection */
|
|
2997
3017
|
circleCircleIntersection(e, t, r, a) {
|
|
@@ -3289,8 +3309,8 @@ class GeometryService {
|
|
|
3289
3309
|
if (g && y) {
|
|
3290
3310
|
const h = GeoMath.circleCircleIntersection(g, s.radius, y, d.radius);
|
|
3291
3311
|
for (const w of h) {
|
|
3292
|
-
const
|
|
3293
|
-
|
|
3312
|
+
const x = this.createPoint(w.x, w.y);
|
|
3313
|
+
x.dependencies = [t, r], x.color = { r: 255, g: 0, b: 0 }, n.push(x);
|
|
3294
3314
|
}
|
|
3295
3315
|
}
|
|
3296
3316
|
}
|
|
@@ -3488,7 +3508,7 @@ function NiceGeometry({
|
|
|
3488
3508
|
useEffect(() => {
|
|
3489
3509
|
h();
|
|
3490
3510
|
}, [h]);
|
|
3491
|
-
const
|
|
3511
|
+
const x = {
|
|
3492
3512
|
service: e,
|
|
3493
3513
|
elements: n,
|
|
3494
3514
|
tool: l,
|
|
@@ -3499,7 +3519,7 @@ function NiceGeometry({
|
|
|
3499
3519
|
setSelectedIds: d,
|
|
3500
3520
|
refresh: h
|
|
3501
3521
|
};
|
|
3502
|
-
return /* @__PURE__ */ jsx(GeometryContext.Provider, { value:
|
|
3522
|
+
return /* @__PURE__ */ jsx(GeometryContext.Provider, { value: x, children: /* @__PURE__ */ jsxs("div", { className: a, style: { ...styles.container, ...o }, children: [
|
|
3503
3523
|
/* @__PURE__ */ jsx(Toolbar, {}),
|
|
3504
3524
|
/* @__PURE__ */ jsxs("div", { style: styles.main, children: [
|
|
3505
3525
|
/* @__PURE__ */ jsx(Canvas, { width: t, height: r }),
|
|
@@ -3533,7 +3553,7 @@ function Toolbar() {
|
|
|
3533
3553
|
style: {
|
|
3534
3554
|
...styles.toolButton,
|
|
3535
3555
|
backgroundColor: e === a.id ? "var(--nice-primary-hover, #1976d2)" : "transparent",
|
|
3536
|
-
color: e === a.id ? "var(--nice-
|
|
3556
|
+
color: e === a.id ? "var(--nice-color-white, #fff)" : "var(--nice-text, #333)"
|
|
3537
3557
|
},
|
|
3538
3558
|
children: /^[a-z][a-z0-9-]*$/.test(a.icon) ? /* @__PURE__ */ jsx(NiceIcon$1, { name: a.icon, size: 16 }) : a.icon
|
|
3539
3559
|
},
|
|
@@ -3543,11 +3563,11 @@ function Toolbar() {
|
|
|
3543
3563
|
function Canvas({ width: e, height: t }) {
|
|
3544
3564
|
const r = useRef(null), { service: a, elements: o, tool: n, view: i, selectedIds: l, setSelectedIds: p, refresh: s } = useGeometry(), [d, g] = useState([]), y = useCallback(
|
|
3545
3565
|
(f, c) => {
|
|
3546
|
-
const
|
|
3566
|
+
const u = (f - e / 2) / i.scale + i.centerX, b = -(c - t / 2) / i.scale + i.centerY;
|
|
3547
3567
|
return i.snapToGrid ? {
|
|
3548
|
-
x: Math.round(
|
|
3568
|
+
x: Math.round(u / i.gridSpacing) * i.gridSpacing,
|
|
3549
3569
|
y: Math.round(b / i.gridSpacing) * i.gridSpacing
|
|
3550
|
-
} : { x, y: b };
|
|
3570
|
+
} : { x: u, y: b };
|
|
3551
3571
|
},
|
|
3552
3572
|
[e, t, i]
|
|
3553
3573
|
), h = useCallback(
|
|
@@ -3562,23 +3582,23 @@ function Canvas({ width: e, height: t }) {
|
|
|
3562
3582
|
const c = (b = r.current) == null ? void 0 : b.getBoundingClientRect();
|
|
3563
3583
|
if (!c)
|
|
3564
3584
|
return;
|
|
3565
|
-
const
|
|
3585
|
+
const u = y(f.clientX - c.left, f.clientY - c.top);
|
|
3566
3586
|
switch (n) {
|
|
3567
3587
|
case "point": {
|
|
3568
|
-
a.createPoint(
|
|
3588
|
+
a.createPoint(u.x, u.y), s();
|
|
3569
3589
|
break;
|
|
3570
3590
|
}
|
|
3571
3591
|
case "segment":
|
|
3572
3592
|
case "line":
|
|
3573
3593
|
case "ray": {
|
|
3574
|
-
const k = u
|
|
3594
|
+
const k = x(u);
|
|
3575
3595
|
if (k)
|
|
3576
3596
|
g((m) => {
|
|
3577
3597
|
const v = [...m, k.id];
|
|
3578
3598
|
return v.length === 2 ? (n === "segment" ? a.createSegment(v[0], v[1]) : n === "line" ? a.createLine(v[0], v[1]) : n === "ray" && a.createRay(v[0], v[1]), s(), []) : v;
|
|
3579
3599
|
});
|
|
3580
3600
|
else {
|
|
3581
|
-
const m = a.createPoint(
|
|
3601
|
+
const m = a.createPoint(u.x, u.y);
|
|
3582
3602
|
g((v) => {
|
|
3583
3603
|
const C = [...v, m.id];
|
|
3584
3604
|
return C.length === 2 ? (n === "segment" ? a.createSegment(C[0], C[1]) : n === "line" ? a.createLine(C[0], C[1]) : n === "ray" && a.createRay(C[0], C[1]), s(), []) : C;
|
|
@@ -3587,14 +3607,14 @@ function Canvas({ width: e, height: t }) {
|
|
|
3587
3607
|
break;
|
|
3588
3608
|
}
|
|
3589
3609
|
case "circle": {
|
|
3590
|
-
const k = u
|
|
3610
|
+
const k = x(u);
|
|
3591
3611
|
if (k)
|
|
3592
3612
|
g((m) => {
|
|
3593
3613
|
if (m.length === 0)
|
|
3594
3614
|
return [k.id];
|
|
3595
3615
|
const v = a.getPoint(m[0]);
|
|
3596
3616
|
if (v) {
|
|
3597
|
-
const C = GeoMath.distance(v,
|
|
3617
|
+
const C = GeoMath.distance(v, u);
|
|
3598
3618
|
a.createCircle(m[0], C), s();
|
|
3599
3619
|
}
|
|
3600
3620
|
return [];
|
|
@@ -3602,17 +3622,17 @@ function Canvas({ width: e, height: t }) {
|
|
|
3602
3622
|
else if (d.length === 1) {
|
|
3603
3623
|
const m = a.getPoint(d[0]);
|
|
3604
3624
|
if (m) {
|
|
3605
|
-
const v = GeoMath.distance(m,
|
|
3625
|
+
const v = GeoMath.distance(m, u);
|
|
3606
3626
|
a.createCircle(d[0], v), s(), g([]);
|
|
3607
3627
|
}
|
|
3608
3628
|
} else {
|
|
3609
|
-
const m = a.createPoint(
|
|
3629
|
+
const m = a.createPoint(u.x, u.y);
|
|
3610
3630
|
g([m.id]), s();
|
|
3611
3631
|
}
|
|
3612
3632
|
break;
|
|
3613
3633
|
}
|
|
3614
3634
|
case "midpoint": {
|
|
3615
|
-
const k = u
|
|
3635
|
+
const k = x(u);
|
|
3616
3636
|
k && g((m) => {
|
|
3617
3637
|
const v = [...m, k.id];
|
|
3618
3638
|
return v.length === 2 ? (a.createMidpoint(v[0], v[1]), s(), []) : v;
|
|
@@ -3620,69 +3640,69 @@ function Canvas({ width: e, height: t }) {
|
|
|
3620
3640
|
break;
|
|
3621
3641
|
}
|
|
3622
3642
|
case "select": {
|
|
3623
|
-
const k = u
|
|
3643
|
+
const k = x(u);
|
|
3624
3644
|
p(k ? [k.id] : []);
|
|
3625
3645
|
break;
|
|
3626
3646
|
}
|
|
3627
3647
|
}
|
|
3628
3648
|
},
|
|
3629
3649
|
[n, a, s, y, d, p]
|
|
3630
|
-
),
|
|
3631
|
-
for (const
|
|
3632
|
-
if (
|
|
3633
|
-
return
|
|
3650
|
+
), x = (f) => {
|
|
3651
|
+
for (const u of o)
|
|
3652
|
+
if (u.type === "point" && GeoMath.distance(u, f) < 0.5)
|
|
3653
|
+
return u;
|
|
3634
3654
|
};
|
|
3635
3655
|
return useEffect(() => {
|
|
3636
3656
|
const f = r.current, c = f == null ? void 0 : f.getContext("2d");
|
|
3637
3657
|
if (!(!f || !c)) {
|
|
3638
3658
|
if (c.fillStyle = `rgb(${i.backgroundColor.r},${i.backgroundColor.g},${i.backgroundColor.b})`, c.fillRect(0, 0, e, t), i.showGrid) {
|
|
3639
3659
|
c.strokeStyle = resolveCssColor("var(--nice-border, #e0e0e0)", c.canvas), c.lineWidth = 0.5;
|
|
3640
|
-
const
|
|
3641
|
-
for (let m = b; m < e; m +=
|
|
3660
|
+
const u = i.gridSpacing * i.scale, b = (e / 2 - i.centerX * i.scale) % u, k = (t / 2 + i.centerY * i.scale) % u;
|
|
3661
|
+
for (let m = b; m < e; m += u)
|
|
3642
3662
|
c.beginPath(), c.moveTo(m, 0), c.lineTo(m, t), c.stroke();
|
|
3643
|
-
for (let m = k; m < t; m +=
|
|
3663
|
+
for (let m = k; m < t; m += u)
|
|
3644
3664
|
c.beginPath(), c.moveTo(0, m), c.lineTo(e, m), c.stroke();
|
|
3645
3665
|
}
|
|
3646
3666
|
if (i.showAxes) {
|
|
3647
|
-
const
|
|
3648
|
-
c.strokeStyle = resolveCssColor("var(--nice-text, #333)", c.canvas), c.lineWidth = 1, c.beginPath(), c.moveTo(0,
|
|
3667
|
+
const u = h(0, 0);
|
|
3668
|
+
c.strokeStyle = resolveCssColor("var(--nice-text, #333)", c.canvas), c.lineWidth = 1, c.beginPath(), c.moveTo(0, u.y), c.lineTo(e, u.y), c.stroke(), c.beginPath(), c.moveTo(u.x, 0), c.lineTo(u.x, t), c.stroke();
|
|
3649
3669
|
}
|
|
3650
|
-
for (const
|
|
3651
|
-
if (!
|
|
3670
|
+
for (const u of o) {
|
|
3671
|
+
if (!u.visible)
|
|
3652
3672
|
continue;
|
|
3653
|
-
const b = `rgb(${
|
|
3654
|
-
switch (
|
|
3673
|
+
const b = `rgb(${u.color.r},${u.color.g},${u.color.b})`, k = l.includes(u.id);
|
|
3674
|
+
switch (u.type) {
|
|
3655
3675
|
case "point": {
|
|
3656
|
-
const m = h(
|
|
3657
|
-
c.beginPath(), c.arc(m.x, m.y, k ?
|
|
3676
|
+
const m = h(u.x, u.y);
|
|
3677
|
+
c.beginPath(), c.arc(m.x, m.y, k ? u.size + 2 : u.size, 0, 2 * Math.PI), c.fillStyle = k ? resolveCssColor("var(--nice-primary-hover, #1976d2)", c.canvas) : b, c.fill(), u.label && (c.fillStyle = resolveCssColor("var(--nice-text, #333)", c.canvas), c.font = "12px sans-serif", c.fillText(u.label, m.x + 8, m.y - 8));
|
|
3658
3678
|
break;
|
|
3659
3679
|
}
|
|
3660
3680
|
case "segment": {
|
|
3661
|
-
const m = a.getPoint(
|
|
3681
|
+
const m = a.getPoint(u.point1Id), v = a.getPoint(u.point2Id);
|
|
3662
3682
|
if (m && v) {
|
|
3663
3683
|
const C = h(m.x, m.y), S = h(v.x, v.y);
|
|
3664
|
-
c.strokeStyle = b, c.lineWidth =
|
|
3684
|
+
c.strokeStyle = b, c.lineWidth = u.width, c.beginPath(), c.moveTo(C.x, C.y), c.lineTo(S.x, S.y), c.stroke();
|
|
3665
3685
|
}
|
|
3666
3686
|
break;
|
|
3667
3687
|
}
|
|
3668
3688
|
case "line": {
|
|
3669
|
-
const m = a.getPoint(
|
|
3689
|
+
const m = a.getPoint(u.point1Id), v = a.getPoint(u.point2Id);
|
|
3670
3690
|
if (m && v) {
|
|
3671
3691
|
const C = v.x - m.x, S = v.y - m.y, P = -1e3, j = 1e3, $ = h(m.x + P * C, m.y + P * S), B = h(m.x + j * C, m.y + j * S);
|
|
3672
|
-
c.strokeStyle = b, c.lineWidth =
|
|
3692
|
+
c.strokeStyle = b, c.lineWidth = u.width, c.beginPath(), c.moveTo($.x, $.y), c.lineTo(B.x, B.y), c.stroke();
|
|
3673
3693
|
}
|
|
3674
3694
|
break;
|
|
3675
3695
|
}
|
|
3676
3696
|
case "circle": {
|
|
3677
|
-
const m = a.getPoint(
|
|
3697
|
+
const m = a.getPoint(u.centerId);
|
|
3678
3698
|
if (m) {
|
|
3679
|
-
const v = h(m.x, m.y), C =
|
|
3680
|
-
c.beginPath(), c.arc(v.x, v.y, C, 0, 2 * Math.PI),
|
|
3699
|
+
const v = h(m.x, m.y), C = u.radius * i.scale;
|
|
3700
|
+
c.beginPath(), c.arc(v.x, v.y, C, 0, 2 * Math.PI), u.fill && (c.fillStyle = `rgba(${u.fill.r},${u.fill.g},${u.fill.b},${u.fill.a ?? 0.2})`, c.fill()), c.strokeStyle = b, c.lineWidth = u.width, c.stroke();
|
|
3681
3701
|
}
|
|
3682
3702
|
break;
|
|
3683
3703
|
}
|
|
3684
3704
|
case "polygon": {
|
|
3685
|
-
const m =
|
|
3705
|
+
const m = u.pointIds.map((v) => a.getPoint(v)).filter(Boolean);
|
|
3686
3706
|
if (m.length > 0) {
|
|
3687
3707
|
c.beginPath();
|
|
3688
3708
|
const v = h(m[0].x, m[0].y);
|
|
@@ -3691,7 +3711,7 @@ function Canvas({ width: e, height: t }) {
|
|
|
3691
3711
|
const S = h(m[C].x, m[C].y);
|
|
3692
3712
|
c.lineTo(S.x, S.y);
|
|
3693
3713
|
}
|
|
3694
|
-
c.closePath(),
|
|
3714
|
+
c.closePath(), u.fill && (c.fillStyle = `rgba(${u.fill.r},${u.fill.g},${u.fill.b},${u.fill.a ?? 0.2})`, c.fill()), c.strokeStyle = b, c.lineWidth = u.width, c.stroke();
|
|
3695
3715
|
}
|
|
3696
3716
|
break;
|
|
3697
3717
|
}
|
|
@@ -3699,8 +3719,8 @@ function Canvas({ width: e, height: t }) {
|
|
|
3699
3719
|
}
|
|
3700
3720
|
if (d.length > 0) {
|
|
3701
3721
|
c.fillStyle = "rgba(25, 118, 210, 0.3)";
|
|
3702
|
-
for (const
|
|
3703
|
-
const b = a.getPoint(
|
|
3722
|
+
for (const u of d) {
|
|
3723
|
+
const b = a.getPoint(u);
|
|
3704
3724
|
if (b) {
|
|
3705
3725
|
const k = h(b.x, b.y);
|
|
3706
3726
|
c.beginPath(), c.arc(k.x, k.y, 12, 0, 2 * Math.PI), c.fill();
|