desmost 0.7.2 → 0.8.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/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/evaluate.d.ts.map +1 -1
- package/dist/compiler/evaluate.js +2 -14
- package/dist/compiler/evaluate.js.map +1 -1
- package/dist/compiler/format.d.ts +2 -0
- package/dist/compiler/format.d.ts.map +1 -1
- package/dist/compiler/format.js +11 -0
- package/dist/compiler/format.js.map +1 -1
- package/dist/compiler/options.d.ts.map +1 -1
- package/dist/compiler/options.js.map +1 -1
- package/dist/decompiler/decompile.d.ts +9 -0
- package/dist/decompiler/decompile.d.ts.map +1 -0
- package/dist/decompiler/decompile.js +21 -0
- package/dist/decompiler/decompile.js.map +1 -0
- package/dist/decompiler/emit.d.ts +4 -0
- package/dist/decompiler/emit.d.ts.map +1 -0
- package/dist/decompiler/emit.js +28 -0
- package/dist/decompiler/emit.js.map +1 -0
- package/dist/decompiler/extract.d.ts +5 -0
- package/dist/decompiler/extract.d.ts.map +1 -0
- package/dist/decompiler/extract.js +53 -0
- package/dist/decompiler/extract.js.map +1 -0
- package/dist/decompiler/format.d.ts +3 -0
- package/dist/decompiler/format.d.ts.map +1 -0
- package/dist/decompiler/format.js +11 -0
- package/dist/decompiler/format.js.map +1 -0
- package/dist/decompiler/index.d.ts +2 -0
- package/dist/decompiler/index.d.ts.map +1 -0
- package/dist/decompiler/index.js +2 -0
- package/dist/decompiler/index.js.map +1 -0
- package/dist/desmos.d.ts.map +1 -1
- package/dist/desmos.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.internal.d.ts +1 -0
- package/dist/index.internal.d.ts.map +1 -1
- package/dist/index.internal.js +1 -0
- package/dist/index.internal.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/magic/expr/index.js.map +1 -1
- package/dist/magic/expr/latex.d.ts.map +1 -1
- package/dist/magic/expr/latex.js.map +1 -1
- package/dist/magic/expr/text.d.ts.map +1 -1
- package/dist/magic/expr/text.js.map +1 -1
- package/dist/magic/global/dark-mode.d.ts.map +1 -1
- package/dist/magic/global/dark-mode.js.map +1 -1
- package/dist/magic/global/desmos.d.ts.map +1 -1
- package/dist/magic/global/desmos.js.map +1 -1
- package/dist/magic/global/index.d.ts +3 -0
- package/dist/magic/global/index.d.ts.map +1 -1
- package/dist/magic/global/index.js +3 -0
- package/dist/magic/global/index.js.map +1 -1
- package/dist/magic/global/viewport.d.ts +4 -4
- package/dist/magic/global/viewport.d.ts.map +1 -1
- package/dist/magic/global/viewport.js +3 -1
- package/dist/magic/global/viewport.js.map +1 -1
- package/dist/magic/incantation.d.ts.map +1 -1
- package/dist/magic/incantation.js.map +1 -1
- package/dist/magic/local/anim.d.ts.map +1 -1
- package/dist/magic/local/anim.js.map +1 -1
- package/dist/magic/local/colour.d.ts.map +1 -1
- package/dist/magic/local/colour.js.map +1 -1
- package/dist/magic/local/dashed.d.ts.map +1 -1
- package/dist/magic/local/dashed.js.map +1 -1
- package/dist/magic/local/fill.d.ts.map +1 -1
- package/dist/magic/local/fill.js.map +1 -1
- package/dist/magic/local/hide.d.ts.map +1 -1
- package/dist/magic/local/hide.js.map +1 -1
- package/dist/magic/local/index.js.map +1 -1
- package/dist/magic/local/label.d.ts.map +1 -1
- package/dist/magic/local/label.js.map +1 -1
- package/dist/magic/local/line.d.ts.map +1 -1
- package/dist/magic/local/line.js.map +1 -1
- package/dist/magic/local/no-line.d.ts.map +1 -1
- package/dist/magic/local/no-line.js.map +1 -1
- package/dist/magic/local/point.d.ts.map +1 -1
- package/dist/magic/local/point.js.map +1 -1
- package/dist/magic/local/secret.d.ts.map +1 -1
- package/dist/magic/local/secret.js.map +1 -1
- package/dist/magic/local/slider.d.ts.map +1 -1
- package/dist/magic/local/slider.js.map +1 -1
- package/dist/parser/ast.d.ts.map +1 -1
- package/dist/parser/ast.js.map +1 -1
- package/dist/parser/desmost-parser.d.ts.map +1 -1
- package/dist/parser/desmost-parser.js +1 -1
- package/dist/parser/desmost-parser.js.map +1 -1
- package/dist/parser/generic-parser.d.ts.map +1 -1
- package/dist/parser/generic-parser.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/compiler/compile.ts +124 -124
- package/src/compiler/evaluate.ts +86 -120
- package/src/compiler/format.ts +39 -6
- package/src/compiler/options.ts +78 -75
- package/src/decompiler/decompile.ts +48 -0
- package/src/decompiler/emit.ts +47 -0
- package/src/decompiler/extract.ts +100 -0
- package/src/decompiler/format.ts +20 -0
- package/src/decompiler/index.ts +1 -0
- package/src/desmos.ts +6 -6
- package/src/errors.ts +12 -12
- package/src/index.internal.ts +2 -0
- package/src/index.ts +1 -0
- package/src/magic/expr/index.ts +2 -2
- package/src/magic/expr/latex.ts +16 -16
- package/src/magic/expr/text.ts +13 -13
- package/src/magic/global/dark-mode.ts +10 -10
- package/src/magic/global/desmos.ts +15 -15
- package/src/magic/global/index.ts +8 -3
- package/src/magic/global/viewport.ts +21 -14
- package/src/magic/incantation.ts +94 -94
- package/src/magic/local/anim.ts +10 -10
- package/src/magic/local/colour.ts +26 -26
- package/src/magic/local/dashed.ts +9 -9
- package/src/magic/local/fill.ts +12 -12
- package/src/magic/local/hide.ts +9 -9
- package/src/magic/local/index.ts +11 -11
- package/src/magic/local/label.ts +51 -51
- package/src/magic/local/line.ts +16 -16
- package/src/magic/local/no-line.ts +9 -9
- package/src/magic/local/point.ts +16 -16
- package/src/magic/local/secret.ts +9 -9
- package/src/magic/local/slider.ts +15 -15
- package/src/parser/ast.ts +45 -45
- package/src/parser/desmost-parser.ts +550 -547
- package/src/parser/generic-parser.ts +176 -176
- package/src/utils.ts +33 -33
package/src/desmos.ts
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
export enum DesmosColour
|
|
6
6
|
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
RED = "#c74440",
|
|
8
|
+
BLUE = "#2d70b3",
|
|
9
|
+
GREEN = "#388c46",
|
|
10
|
+
PURPLE = "#6042a6",
|
|
11
|
+
ORANGE = "#fa7e19",
|
|
12
|
+
BLACK = "#000000",
|
|
13
13
|
}
|
package/src/errors.ts
CHANGED
|
@@ -7,24 +7,24 @@ export class UnrecoverableError extends Error {}
|
|
|
7
7
|
|
|
8
8
|
export namespace UnrecoverableError
|
|
9
9
|
{
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/** The parser unexpectedly reached the end of its entire input source code. */
|
|
11
|
+
export class UnexpectedEnd extends UnrecoverableError {}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/** The parser did not receive input that it expected. */
|
|
14
|
+
export class MissingInput extends UnrecoverableError {}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/** The parser received input that did not match what it expected. */
|
|
17
|
+
export class UnexpectedInput extends UnrecoverableError {}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/** The parser received excess input that it did not expect. */
|
|
20
|
+
export class ExcessInput extends UnrecoverableError {}
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/** An incantation can't be applied here. */
|
|
24
|
+
export class IllegalIncantation extends UnrecoverableError {}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
/** An incantation's argument couldn't be parsed. */
|
|
27
|
+
export class InvalidArgument extends UnrecoverableError {}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
|
package/src/index.internal.ts
CHANGED
package/src/index.ts
CHANGED
package/src/magic/expr/index.ts
CHANGED
package/src/magic/expr/latex.ts
CHANGED
|
@@ -3,22 +3,22 @@ import { Incantation, ArgIncantation, type EXPR } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
export class LatexIncantation extends ArgIncantation<EXPR>
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
override readonly description
|
|
7
|
+
= "Produce a LaTeX expression. This allows the input to span multiple lines."
|
|
8
|
+
|
|
9
|
+
override readonly identifier = "latex"
|
|
10
|
+
override readonly requires_arg = true
|
|
11
|
+
override readonly arg_type = Incantation.ArgType.LATEX
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
apply(target: Desmos.ExpressionState, data: string): void
|
|
14
|
+
{
|
|
15
|
+
target.type = "expression";
|
|
16
|
+
// @ts-expect-error: outdated types
|
|
17
|
+
target.latex = data === "" ? " " : data;
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
override evaluate_arg(data: string): string
|
|
21
|
+
{
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
24
|
}
|
package/src/magic/expr/text.ts
CHANGED
|
@@ -3,18 +3,18 @@ import { Incantation, ArgIncantation, type EXPR } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
export class TextIncantation extends ArgIncantation<EXPR>
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
override readonly description
|
|
7
|
+
= "Produce a text expression (“Add Note” in the Desmos GUI)."
|
|
8
|
+
|
|
9
|
+
override readonly identifier = "text"
|
|
10
|
+
override readonly alias = "note"
|
|
11
|
+
override readonly requires_arg = true
|
|
12
|
+
override readonly arg_type = Incantation.ArgType.STRING
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
override apply(target: Desmos.ExpressionState, data: string)
|
|
15
|
+
{
|
|
16
|
+
target.type = "text";
|
|
17
|
+
// @ts-expect-error: outdated types
|
|
18
|
+
target.text = data;
|
|
19
|
+
}
|
|
20
20
|
}
|
|
@@ -3,15 +3,15 @@ import { Incantation, type GLOBAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
export class DarkModeIncantation extends Incantation<GLOBAL>
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
override readonly description
|
|
7
|
+
= "Enable dark mode for the calculator, which inverts all colours."
|
|
8
|
+
|
|
9
|
+
override readonly identifier = "dark"
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
apply(target: Desmos.Calculator)
|
|
12
|
+
{
|
|
13
|
+
target.updateSettings({
|
|
14
|
+
invertedColors: true,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
17
|
}
|
|
@@ -3,20 +3,20 @@ import { Incantation, ArgIncantation, type GLOBAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
export class DesmosIncantation extends ArgIncantation<GLOBAL>
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
override readonly description
|
|
7
|
+
= "Set the configuration of the calculator via `Calculator.updateSettings()`."
|
|
8
|
+
|
|
9
|
+
override readonly identifier = "desmos"
|
|
10
|
+
override readonly requires_arg = false
|
|
11
|
+
override readonly arg_type = Incantation.ArgType.OBJECT
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
override apply(
|
|
14
|
+
target: Desmos.Calculator,
|
|
15
|
+
data?: Desmos.GraphConfiguration & Desmos.GraphSettings,
|
|
16
|
+
): void
|
|
17
|
+
{
|
|
18
|
+
if (data != undefined) {
|
|
19
|
+
target.updateSettings(data);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
22
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export { DesmosIncantation } from "./desmos";
|
|
2
|
+
export { ViewportIncantation } from "./viewport";
|
|
3
|
+
export { DarkModeIncantation } from "./dark-mode";
|
|
4
|
+
|
|
5
|
+
|
|
1
6
|
import { Incantation, type GLOBAL } from "../incantation";
|
|
2
7
|
|
|
3
8
|
import { DesmosIncantation } from "./desmos";
|
|
@@ -7,7 +12,7 @@ import { DarkModeIncantation } from "./dark-mode";
|
|
|
7
12
|
|
|
8
13
|
export const GLOBAL_INCANTATIONS: Incantation<GLOBAL>[] =
|
|
9
14
|
[
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
new DesmosIncantation(),
|
|
16
|
+
new ViewportIncantation(),
|
|
17
|
+
new DarkModeIncantation(),
|
|
13
18
|
];
|
|
@@ -3,24 +3,31 @@ import { Incantation, ArgIncantation, type GLOBAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
interface ViewportBounds
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
left?: number; right?: number;
|
|
7
|
+
bottom?: number; top?: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
export class ViewportIncantation extends ArgIncantation<GLOBAL>
|
|
12
12
|
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
override readonly description
|
|
14
|
+
= "Set the bounds of the viewport via `Calculator.setMathBounds()`."
|
|
15
|
+
|
|
16
|
+
override readonly identifier = "viewport"
|
|
17
|
+
override readonly requires_arg = true
|
|
18
|
+
override readonly arg_type = Incantation.ArgType.OBJECT
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
apply(target: Desmos.Calculator, data: ViewportBounds)
|
|
21
|
+
{
|
|
22
|
+
let existing = target.graphpaperBounds.mathCoordinates;
|
|
23
|
+
|
|
24
|
+
let {
|
|
25
|
+
left = existing.left,
|
|
26
|
+
right = existing.right,
|
|
27
|
+
bottom = existing.bottom,
|
|
28
|
+
top = existing.top,
|
|
29
|
+
} = data;
|
|
30
|
+
|
|
31
|
+
target.setMathBounds({ left, right, bottom, top });
|
|
32
|
+
}
|
|
26
33
|
}
|
package/src/magic/incantation.ts
CHANGED
|
@@ -17,38 +17,38 @@ import { UnrecoverableError, type Unrecoverable } from "../errors";
|
|
|
17
17
|
* Incantations that accept an argument derive from `ArgIncantation`.
|
|
18
18
|
*/
|
|
19
19
|
export abstract class Incantation<
|
|
20
|
-
|
|
20
|
+
Effect extends Incantation.Effect = Incantation.Effect
|
|
21
21
|
>
|
|
22
22
|
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
23
|
+
/** Short user-facing description of what the incantation does. */
|
|
24
|
+
public abstract readonly description: string
|
|
25
|
+
|
|
26
|
+
/** The raw text sequence that matches this incantation, such as `viewport` or `hidden`. */
|
|
27
|
+
public abstract readonly identifier: string
|
|
28
|
+
|
|
29
|
+
/** An alternative `.identifier`, strictly for localisation purposes only. */
|
|
30
|
+
public readonly alias?: string
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/** Apply this incantation's effect to `target`, using the provided `data` if required. */
|
|
34
|
+
public abstract apply(
|
|
35
|
+
target: Effect extends GLOBAL ? Desmos.Calculator : Desmos.ExpressionState,
|
|
36
|
+
data?: unknown,
|
|
37
|
+
): void
|
|
38
|
+
|
|
39
|
+
/** Error if the `actual` type of the given expression is not `required`. */
|
|
40
|
+
protected require_expr_type<T extends Desmos.ExpressionState["type"]>(
|
|
41
|
+
actual: unknown,
|
|
42
|
+
required: T,
|
|
43
|
+
): asserts actual is T
|
|
44
|
+
{
|
|
45
|
+
if ((actual ?? "expression") !== required)
|
|
46
|
+
{
|
|
47
|
+
throw new UnrecoverableError.IllegalIncantation(
|
|
48
|
+
`/${this.identifier} can only applied to ${required === "expression" ? "latex" : required} expressions, but target block has type: ${actual}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
|
|
@@ -56,77 +56,77 @@ export abstract class Incantation<
|
|
|
56
56
|
* An incantation that accepts an argument.
|
|
57
57
|
*/
|
|
58
58
|
export abstract class ArgIncantation<
|
|
59
|
-
|
|
59
|
+
Effect extends Incantation.Effect = Incantation.Effect
|
|
60
60
|
>
|
|
61
|
-
|
|
61
|
+
extends Incantation<Effect>
|
|
62
62
|
{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
63
|
+
/** Does this incantation always require an argument to be passed? */
|
|
64
|
+
public readonly requires_arg: boolean = true
|
|
65
|
+
|
|
66
|
+
/** What type of argument does this incantation accept? */
|
|
67
|
+
public abstract readonly arg_type: Incantation.ArgType
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Evaluate the argument provided to this incantation, throwing if an error is encountered.
|
|
72
|
+
*
|
|
73
|
+
* For instance, for `/viewport{ left: -1, right: 1 }`, this returns the POJO `{ left: -1, right: 1 }`.
|
|
74
|
+
*
|
|
75
|
+
* ## Notes
|
|
76
|
+
*
|
|
77
|
+
* Child incantation classes should override this method, though the defaults should cover most cases (except `ArgType.ENUM`).
|
|
78
|
+
*/
|
|
79
|
+
public evaluate_arg(raw: string): Unrecoverable<unknown>
|
|
80
|
+
{
|
|
81
|
+
switch (this.arg_type) {
|
|
82
|
+
case Incantation.ArgType.STRING: return raw;
|
|
83
|
+
case Incantation.ArgType.LATEX: return raw;
|
|
84
|
+
case Incantation.ArgType.ENUM: return raw;
|
|
85
|
+
|
|
86
|
+
case Incantation.ArgType.OBJECT: {
|
|
87
|
+
try {
|
|
88
|
+
return Json5.parse(`{${raw}}`);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
// @ts-expect-error: fine
|
|
92
|
+
throw new UnrecoverableError.InvalidArgument(e.message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
|
|
100
100
|
export namespace Incantation
|
|
101
101
|
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
102
|
+
/** The kind of effect an incantation produces - it either modifies only one block, or modifies the calculator as a whole. */
|
|
103
|
+
export enum Effect
|
|
104
|
+
{
|
|
105
|
+
/** An incantation that affects the entire Desmos calculator state, like `/desmos` or `/viewport`. */
|
|
106
|
+
GLOBAL,
|
|
107
|
+
|
|
108
|
+
/** An incantation that affects only the expression immediately following it, like `/hide` or `/slider`. */
|
|
109
|
+
LOCAL,
|
|
110
|
+
|
|
111
|
+
/** An incantation that produces an expression, like `/latex` or `/text`. */
|
|
112
|
+
EXPR,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The type of argument an incantation accepts, which affects how it is parsed. */
|
|
116
|
+
export enum ArgType
|
|
117
|
+
{
|
|
118
|
+
/** Any arbitrary user text content, where characters like `"` and `'` don't have semantic meaning and can be ignored. */
|
|
119
|
+
STRING = "String",
|
|
120
|
+
|
|
121
|
+
/** LaTeX, which should have balanced `{}` braces. */
|
|
122
|
+
LATEX = "LaTeX",
|
|
123
|
+
|
|
124
|
+
/** Specific value from an allowed set of values, which will map to an enum value in the Desmos API. */
|
|
125
|
+
ENUM = "Enum",
|
|
126
|
+
|
|
127
|
+
/** JavaScript object fields, where characters like `{}` and `"` all have semantic meaning, and must be balanced. */
|
|
128
|
+
OBJECT = "Object",
|
|
129
|
+
}
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
|
package/src/magic/local/anim.ts
CHANGED
|
@@ -3,15 +3,15 @@ import { Incantation, type LOCAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
export class AnimIncantation extends Incantation<LOCAL>
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
override readonly description
|
|
7
|
+
= "Animate the slider of a block."
|
|
8
|
+
|
|
9
|
+
override readonly identifier = "anim"
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
override apply(target: Desmos.ExpressionState)
|
|
12
|
+
{
|
|
13
|
+
super.require_expr_type(target.type, "expression");
|
|
14
|
+
// @ts-expect-error: outdated types
|
|
15
|
+
target.playing = true;
|
|
16
|
+
}
|
|
17
17
|
}
|
|
@@ -6,33 +6,33 @@ import { DesmosColour } from "../../desmos";
|
|
|
6
6
|
|
|
7
7
|
export class ColourIncantation extends ArgIncantation<LOCAL>
|
|
8
8
|
{
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
override readonly description
|
|
10
|
+
= ""
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
override readonly identifier = "color"
|
|
13
|
+
override readonly alias = "colour"
|
|
14
|
+
override readonly requires_arg = true
|
|
15
|
+
override readonly arg_type = Incantation.ArgType.ENUM
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
override apply(target: Desmos.ExpressionState, data: DesmosColour)
|
|
18
|
+
{
|
|
19
|
+
super.require_expr_type(target.type, "expression");
|
|
20
|
+
target.color = data;
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
override evaluate_arg(data: string): DesmosColour
|
|
24
|
+
{
|
|
25
|
+
switch (data.trim().toUpperCase()) {
|
|
26
|
+
case "RED": return DesmosColour.RED;
|
|
27
|
+
case "BLUE": return DesmosColour.BLUE;
|
|
28
|
+
case "GREEN": return DesmosColour.GREEN;
|
|
29
|
+
case "PURPLE": return DesmosColour.PURPLE;
|
|
30
|
+
case "ORANGE": return DesmosColour.ORANGE;
|
|
31
|
+
case "BLACK": return DesmosColour.BLACK;
|
|
32
|
+
default:
|
|
33
|
+
throw new UnrecoverableError(
|
|
34
|
+
`Invalid colour: \`${data}\``
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
38
|
}
|
|
@@ -3,14 +3,14 @@ import { Incantation, type LOCAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
export class DashedIncantation extends Incantation<LOCAL>
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
override readonly description
|
|
7
|
+
= "Render a block as a dashed line."
|
|
8
|
+
|
|
9
|
+
override readonly identifier = "dashed"
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
override apply(target: Desmos.ExpressionState)
|
|
12
|
+
{
|
|
13
|
+
super.require_expr_type(target.type, "expression");
|
|
14
|
+
target.lineStyle = Desmos.Styles.DASHED;
|
|
15
|
+
}
|
|
16
16
|
}
|
package/src/magic/local/fill.ts
CHANGED
|
@@ -3,22 +3,22 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
interface FillOptions
|
|
5
5
|
{
|
|
6
|
-
|
|
6
|
+
opacity: number;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
export class FillIncantation extends ArgIncantation<LOCAL>
|
|
11
11
|
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
override readonly description
|
|
13
|
+
= "Change fill styles for a rendered block."
|
|
14
|
+
|
|
15
|
+
override readonly identifier = "fill"
|
|
16
|
+
override readonly requires_arg = true
|
|
17
|
+
override readonly arg_type = Incantation.ArgType.OBJECT
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
override apply(target: Desmos.ExpressionState, data: FillOptions)
|
|
20
|
+
{
|
|
21
|
+
super.require_expr_type(target.type, "expression");
|
|
22
|
+
target.fillOpacity = data.opacity;
|
|
23
|
+
}
|
|
24
24
|
}
|