Skip to content

Commit 65e5465

Browse files
committed
标识符设置
1 parent 58042ca commit 65e5465

File tree

7 files changed

+212
-79
lines changed

7 files changed

+212
-79
lines changed

src/editor/inputs/implicit.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<template>
22
<div class="input-inner">
33
<div class="field main-fn">
4-
<FunctionField class="fn" label="f(x,y)" v-model="self.fn" />
4+
<FunctionField
5+
class="fn"
6+
label="f(x,y)"
7+
v-model="self.fn"
8+
:identifiers="['x', 'y']"
9+
/>
510
<span class="label styled"> =0 </span>
611
</div>
712
<AnimatedFold :folded="props.folded">
@@ -17,10 +22,7 @@
1722
</div>
1823
<div class="switches">
1924
<!-- closed -->
20-
<s-checkbox
21-
type="checkbox"
22-
v-model.lazy="self.closed"
23-
>
25+
<s-checkbox type="checkbox" v-model.lazy="self.closed">
2426
{{ t("data.more.closed") }}
2527
</s-checkbox>
2628
</div>

src/editor/inputs/parametric.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22
<div class="input-inner">
33
<div class="field main-fn">
44
<span class="label styled">x=</span>
5-
<FunctionField class="fn" label="f(t)" v-model="self.x" />
5+
<FunctionField
6+
class="fn"
7+
label="f(t)"
8+
v-model="self.x"
9+
:identifiers="['t']"
10+
/>
611
</div>
712
<div class="field main-fn">
813
<span class="label styled">y=</span>
9-
<FunctionField class="fn" label="g(t)" v-model="self.y" />
14+
<FunctionField
15+
class="fn"
16+
label="g(t)"
17+
v-model="self.y"
18+
:identifiers="['t']"
19+
/>
1020
</div>
1121
<AnimatedFold :folded="props.folded">
1222
<s-divider>{{ t("data.more.dividerTitle") }}</s-divider>

src/editor/inputs/polar.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
ref="inputBox"
88
label="f(θ)"
99
v-model="self.r"
10+
:identifiers="['theta']"
1011
/>
1112
</div>
1213
<AnimatedFold :folded="props.folded">
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[
2+
"''''",
3+
"'''",
4+
"''",
5+
"QED",
6+
"Q.E.D.",
7+
"s.t.",
8+
"PI",
9+
"theta",
10+
"abs",
11+
"grad",
12+
"Inf",
13+
"inf",
14+
"lim",
15+
"max",
16+
"min",
17+
"mod",
18+
"NaN",
19+
"sqrt",
20+
"rank",
21+
"sgn",
22+
"sup",
23+
"exp",
24+
"ln",
25+
"log",
26+
"acos",
27+
"arccos",
28+
"arcsin",
29+
"arctan",
30+
"asin",
31+
"atan",
32+
"cos",
33+
"cosh",
34+
"cot",
35+
"csc",
36+
"sec",
37+
"sin",
38+
"sinh",
39+
"tan",
40+
"tanh"
41+
]

src/editor/inputs/subblocks/function.vue

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { computed, ref, watch } from "vue";
2020
const value = defineModel<string>({ required: true });
2121
const props = defineProps<{
2222
label: string;
23+
identifiers?: string[];
2324
}>();
2425
const isFocus = ref(false);
2526
const isEmpty = computed(() => value.value === "");
@@ -40,15 +41,18 @@ import { tokenize } from "./functionTokenize";
4041
const labelContent = computed(() =>
4142
isEmpty.value
4243
? [<span>{props.label}</span>]
43-
: tokenize(value.value).map((token) => (
44+
: tokenize(value.value, props.identifiers || ["x"]).map((token) => (
4445
<span
4546
class={[
4647
token.type,
48+
token.raw,
4749
"function-label-item",
48-
token.level ? "level-" + token.level : undefined,
50+
token.level ? "level-" + Math.min(token.level, 5) : undefined,
51+
token.err ? "error" : undefined,
52+
token.sqrtLevel ? "under-sqrt" : undefined,
4953
]}
5054
>
51-
{token.raw}
55+
<span class="inner">{token.raw}</span>
5256
</span>
5357
))
5458
);
@@ -66,6 +70,7 @@ const labelContent = computed(() =>
6670
padding: 0;
6771
display: flex;
6872
font-family: var(--font-math);
73+
position: relative;
6974
&.focus {
7075
background-color: var(--s-color-surface-container-highest);
7176
border-bottom-color: var(--s-color-primary);
@@ -80,19 +85,22 @@ const labelContent = computed(() =>
8085
width: 0;
8186
flex-grow: 1;
8287
caret-color: var(--s-color-primary);
83-
line-height: 1.2;
8488
z-index: 1;
8589
color: transparent;
8690
}
8791
label {
92+
display: block;
8893
color: var(--s-color-outline);
8994
position: absolute;
90-
line-height: 1.2;
9195
white-space: pre;
96+
max-width: 100%;
97+
box-sizing: border-box;
9298
}
9399
input,
94100
label {
95-
padding: 0.4em 0.45em 0.3em 0.45em;
101+
padding: 0.2em 0.45em 0.1em 0.45em;
102+
line-height: 1.6;
103+
overflow: hidden;
96104
}
97105
&.styled label {
98106
transform: translateY(-0.05em);
@@ -103,21 +111,21 @@ const labelContent = computed(() =>
103111
}
104112
105113
.function-label {
106-
.function-label-item {
114+
.function-label-item,
115+
.function-label-item .inner {
107116
display: inline-block;
108117
}
109118
.identifier {
110119
color: var(--s-color-primary);
111120
}
112121
.operator {
113122
color: var(--s-color-secondary);
114-
opacity: 0.8;
115123
}
116124
.bracket {
117125
color: var(--s-color-secondary);
118126
}
119127
@for $i from 1 through 5 {
120-
.bracket.level-#{$i} {
128+
.bracket.level-#{$i} .inner {
121129
transform: scaleY(#{0.8 + $i * 0.2});
122130
}
123131
}
@@ -127,5 +135,26 @@ const labelContent = computed(() =>
127135
.function {
128136
color: var(--s-color-tertiary);
129137
}
138+
.error .inner {
139+
text-decoration: underline var(--s-color-error);
140+
text-decoration-thickness: 0.05em;
141+
text-underline-offset: 0.1em;
142+
}
143+
.sqrt {
144+
transform: scaleY(1.3) translateY(-1px);
145+
}
146+
.under-sqrt {
147+
background-image: linear-gradient(
148+
to bottom,
149+
transparent 0.1em,
150+
var(--s-color-tertiary) 0.1em,
151+
var(--s-color-tertiary) 0.14em,
152+
transparent 0.14em,
153+
transparent 100%
154+
);
155+
&.sqrt {
156+
transform: none !important;
157+
}
158+
}
130159
}
131160
</style>

0 commit comments

Comments
 (0)