xmmath 1.0.6 → 1.0.7
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/xmmath.es.js +527 -496
- package/dist/xmmath.es.js.map +1 -1
- package/dist/xmmath.umd.js +4 -2
- package/dist/xmmath.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/main.ts +73 -25
- package/src/symbols.json +2 -0
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -27,7 +27,7 @@ const mathvariant = "mathvariant";
|
|
|
27
27
|
import GraphemeSplitter from "grapheme-splitter";
|
|
28
28
|
var splitter = new GraphemeSplitter();
|
|
29
29
|
|
|
30
|
-
type vtype = "" | "str" | "v" | "f" | "blank" | "group";
|
|
30
|
+
type vtype = "" | "str" | "v" | "f" | "blank" | "group" | "group1"; // group1组合基本类型,提高优先级
|
|
31
31
|
type tree = { type: vtype; value: string; children?: tree; esc?: boolean }[];
|
|
32
32
|
|
|
33
33
|
function ast(str: string) {
|
|
@@ -159,7 +159,7 @@ function ast(str: string) {
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
import symbols from "./symbols.json?raw";
|
|
162
|
-
/** @see https://github.com/typst/typst/blob/
|
|
162
|
+
/** @see https://github.com/typst/typst/blob/v0.6.0/library/src/symbols/sym.rs */
|
|
163
163
|
let s = JSON.parse(symbols);
|
|
164
164
|
|
|
165
165
|
// symbols路径简写
|
|
@@ -721,14 +721,20 @@ function in_kh(x: tree) {
|
|
|
721
721
|
return k;
|
|
722
722
|
}
|
|
723
723
|
|
|
724
|
+
function is_sup(x: tree[0]) {
|
|
725
|
+
return x && x.type == "v" && x.value == "^" && !x.esc;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function is_sub(x: tree[0]) {
|
|
729
|
+
return x && x.type == "v" && x.value == "_" && !x.esc;
|
|
730
|
+
}
|
|
731
|
+
|
|
724
732
|
function is_frac(x: tree[0]) {
|
|
725
|
-
|
|
726
|
-
return x.value == "/" && !x.esc;
|
|
733
|
+
return x && x.type == "v" && x.value == "/" && !x.esc;
|
|
727
734
|
}
|
|
728
735
|
|
|
729
736
|
function is_br(x: tree[0]) {
|
|
730
|
-
|
|
731
|
-
return x.value == "br" && x.esc;
|
|
737
|
+
return x && x.value == "br" && x.esc;
|
|
732
738
|
}
|
|
733
739
|
|
|
734
740
|
function is_limit(tree: tree) {
|
|
@@ -770,6 +776,14 @@ function is_dot(x: tree[0]) {
|
|
|
770
776
|
return x && x.type == "v" && x.value == ".";
|
|
771
777
|
}
|
|
772
778
|
|
|
779
|
+
function is_dot_f(x: tree[0]) {
|
|
780
|
+
return x && (x.type == "f" || (x.type == "v" && x.value.match(/[a-z]/)));
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
function is_factorial(x: tree[0]) {
|
|
784
|
+
return x && x.type == "v" && x.value == "!" && !x.esc;
|
|
785
|
+
}
|
|
786
|
+
|
|
773
787
|
let dh: tree[0] = { type: "v", value: "," };
|
|
774
788
|
|
|
775
789
|
function v_f(str: string): tree[0] {
|
|
@@ -922,6 +936,29 @@ function ast2(tree: tree) {
|
|
|
922
936
|
tree = t;
|
|
923
937
|
}
|
|
924
938
|
|
|
939
|
+
// 处理!
|
|
940
|
+
{
|
|
941
|
+
let t: tree = [];
|
|
942
|
+
let tmpx: tree = [];
|
|
943
|
+
for (let n = 0; n < tree.length; n++) {
|
|
944
|
+
let x = tree[n];
|
|
945
|
+
|
|
946
|
+
if (is_factorial(tree?.[n + 1]) && !is_sup(x) && !is_sub(x) && !is_frac(x)) {
|
|
947
|
+
tmpx.push(x);
|
|
948
|
+
} else {
|
|
949
|
+
if (tmpx.length) {
|
|
950
|
+
tmpx.push(x);
|
|
951
|
+
t.push({ type: "group1", value: "", children: tmpx });
|
|
952
|
+
tmpx = [];
|
|
953
|
+
} else {
|
|
954
|
+
t.push(x);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
tree = t;
|
|
960
|
+
}
|
|
961
|
+
|
|
925
962
|
// 处理带.的f
|
|
926
963
|
{
|
|
927
964
|
let t: tree = [];
|
|
@@ -929,11 +966,15 @@ function ast2(tree: tree) {
|
|
|
929
966
|
for (let n = 0; n < tree.length; n++) {
|
|
930
967
|
let x = tree[n];
|
|
931
968
|
|
|
932
|
-
if (x
|
|
933
|
-
f
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
969
|
+
if (is_dot_f(x) && is_dot(tree[n + 1])) {
|
|
970
|
+
if (f || (!f && x.type == "f")) {
|
|
971
|
+
f += x.value + ".";
|
|
972
|
+
n++;
|
|
973
|
+
continue;
|
|
974
|
+
} else {
|
|
975
|
+
t.push(x);
|
|
976
|
+
}
|
|
977
|
+
} else if (f && is_dot_f(x)) {
|
|
937
978
|
f += x.value;
|
|
938
979
|
if (!is_dot(tree[n + 1])) {
|
|
939
980
|
t.push({ type: "f", value: f });
|
|
@@ -990,17 +1031,11 @@ function ast2(tree: tree) {
|
|
|
990
1031
|
let start = NaN;
|
|
991
1032
|
for (let n = 0; n < tree.length; n++) {
|
|
992
1033
|
const x = tree[n];
|
|
993
|
-
if (x
|
|
994
|
-
if (
|
|
995
|
-
(tree[n + 1]?.value == "^" || tree[n + 1]?.value == "_") &&
|
|
996
|
-
!(tree[n - 1]?.value == "^" || tree[n - 1]?.value == "_")
|
|
997
|
-
) {
|
|
1034
|
+
if (!is_sup(x) && !is_sub(x)) {
|
|
1035
|
+
if ((is_sup(tree[n + 1]) || is_sub(tree[n + 1])) && !(is_sup(tree[n - 1]) || is_sub(tree[n - 1]))) {
|
|
998
1036
|
if (!start) start = n;
|
|
999
1037
|
}
|
|
1000
|
-
if (
|
|
1001
|
-
(tree[n - 1]?.value == "^" || tree[n - 1]?.value == "_") &&
|
|
1002
|
-
!(tree[n + 1]?.value == "^" || tree[n + 1]?.value == "_")
|
|
1003
|
-
) {
|
|
1038
|
+
if ((is_sup(tree[n - 1]) || is_sub(tree[n - 1])) && !(is_sup(tree[n + 1]) || is_sub(tree[n + 1]))) {
|
|
1004
1039
|
index.push([start, n]);
|
|
1005
1040
|
start = NaN;
|
|
1006
1041
|
}
|
|
@@ -1013,7 +1048,7 @@ function ast2(tree: tree) {
|
|
|
1013
1048
|
{
|
|
1014
1049
|
let tmp: tree[0] = tree[index[0][1]];
|
|
1015
1050
|
for (let i = index[0][1]; i >= index[0][0]; i--) {
|
|
1016
|
-
if (tree[i - 1]
|
|
1051
|
+
if (is_sup(tree[i - 1]) && is_sub(tree[i - 3])) {
|
|
1017
1052
|
let o = is_limit([tree[i - 4]])
|
|
1018
1053
|
? { t: out_kh(tmp), b: out_kh(tree[i - 2]) }
|
|
1019
1054
|
: { tr: out_kh(tmp), br: out_kh(tree[i - 2]) };
|
|
@@ -1025,7 +1060,7 @@ function ast2(tree: tree) {
|
|
|
1025
1060
|
i -= 4 - 1;
|
|
1026
1061
|
continue;
|
|
1027
1062
|
}
|
|
1028
|
-
if (tree[i - 1]
|
|
1063
|
+
if (is_sub(tree[i - 1]) && is_sup(tree[i - 3])) {
|
|
1029
1064
|
let o = is_limit([tree[i - 4]])
|
|
1030
1065
|
? { t: out_kh(tree[i - 2]), b: out_kh(tmp) }
|
|
1031
1066
|
: { tr: out_kh(tree[i - 2]), br: out_kh(tmp) };
|
|
@@ -1037,7 +1072,7 @@ function ast2(tree: tree) {
|
|
|
1037
1072
|
i -= 4 - 1;
|
|
1038
1073
|
continue;
|
|
1039
1074
|
}
|
|
1040
|
-
if (tree[i - 1]
|
|
1075
|
+
if (is_sup(tree[i - 1])) {
|
|
1041
1076
|
let o = is_limit([tree[i - 2]]) ? { t: out_kh(tmp) } : { tr: out_kh(tmp) };
|
|
1042
1077
|
tmp = {
|
|
1043
1078
|
type: "f",
|
|
@@ -1047,7 +1082,7 @@ function ast2(tree: tree) {
|
|
|
1047
1082
|
i -= 2 - 1;
|
|
1048
1083
|
continue;
|
|
1049
1084
|
}
|
|
1050
|
-
if (tree[i - 1]
|
|
1085
|
+
if (is_sub(tree[i - 1])) {
|
|
1051
1086
|
let o = is_limit([tree[i - 2]]) ? { b: out_kh(tmp) } : { br: out_kh(tmp) };
|
|
1052
1087
|
tmp = {
|
|
1053
1088
|
type: "f",
|
|
@@ -1094,7 +1129,7 @@ function ast2(tree: tree) {
|
|
|
1094
1129
|
{
|
|
1095
1130
|
let tmp: tree[0] = tree[index[0][0]];
|
|
1096
1131
|
for (let i = index[0][0]; i <= index[0][1]; i++) {
|
|
1097
|
-
if (tree[i + 1]
|
|
1132
|
+
if (is_frac(tree[i + 1])) {
|
|
1098
1133
|
tmp = {
|
|
1099
1134
|
type: "f",
|
|
1100
1135
|
value: "frac",
|
|
@@ -1294,6 +1329,19 @@ function render(tree: tree, e?: fonts) {
|
|
|
1294
1329
|
}
|
|
1295
1330
|
}
|
|
1296
1331
|
|
|
1332
|
+
// 移除group1
|
|
1333
|
+
{
|
|
1334
|
+
let t: tree = [];
|
|
1335
|
+
for (let x of tree) {
|
|
1336
|
+
if (x.type == "group1") {
|
|
1337
|
+
t.push(...x.children);
|
|
1338
|
+
} else {
|
|
1339
|
+
t.push(x);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
tree = t;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1297
1345
|
for (let i in tree) {
|
|
1298
1346
|
let n = Number(i);
|
|
1299
1347
|
let x = tree[n];
|
package/src/symbols.json
CHANGED
|
@@ -185,6 +185,7 @@
|
|
|
185
185
|
"dot": "⋗",
|
|
186
186
|
"double": "≫",
|
|
187
187
|
"eq": "≥",
|
|
188
|
+
"eq.slant": "⩾",
|
|
188
189
|
"eq.lt": "⋛",
|
|
189
190
|
"eq.not": "≱",
|
|
190
191
|
"eqq": "≧",
|
|
@@ -211,6 +212,7 @@
|
|
|
211
212
|
"dot": "⋖",
|
|
212
213
|
"double": "≪",
|
|
213
214
|
"eq": "≤",
|
|
215
|
+
"eq.slant": "⩽",
|
|
214
216
|
"eq.gt": "⋚",
|
|
215
217
|
"eq.not": "≰",
|
|
216
218
|
"eqq": "≦",
|