desmost 0.7.3 → 0.8.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/compiler/compile.d.ts +25 -1
- package/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js +32 -2
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/evaluate.d.ts +11 -0
- package/dist/compiler/evaluate.d.ts.map +1 -1
- package/dist/compiler/evaluate.js +15 -11
- package/dist/compiler/evaluate.js.map +1 -1
- package/dist/compiler/format.d.ts +13 -0
- package/dist/compiler/format.d.ts.map +1 -1
- package/dist/compiler/format.js +23 -0
- package/dist/compiler/format.js.map +1 -1
- package/dist/compiler/index.d.ts.map +1 -1
- package/dist/compiler/index.js.map +1 -1
- package/dist/compiler/options.d.ts +79 -0
- package/dist/compiler/options.d.ts.map +1 -1
- package/dist/compiler/options.js +18 -11
- package/dist/compiler/options.js.map +1 -1
- package/dist/decompiler/decompile.d.ts +20 -0
- package/dist/decompiler/decompile.d.ts.map +1 -0
- package/dist/decompiler/decompile.js +32 -0
- package/dist/decompiler/decompile.js.map +1 -0
- package/dist/decompiler/emit.d.ts +10 -0
- package/dist/decompiler/emit.d.ts.map +1 -0
- package/dist/decompiler/emit.js +37 -0
- package/dist/decompiler/emit.js.map +1 -0
- package/dist/decompiler/extract.d.ts +14 -0
- package/dist/decompiler/extract.d.ts.map +1 -0
- package/dist/decompiler/extract.js +63 -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 +14 -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 +3 -0
- package/dist/desmos.d.ts.map +1 -1
- package/dist/desmos.js +3 -0
- package/dist/desmos.js.map +1 -1
- package/dist/errors.d.ts +18 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +13 -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 +2 -1
- package/dist/index.internal.d.ts.map +1 -1
- package/dist/index.internal.js +2 -1
- 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 +1 -0
- 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 +1 -0
- 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 +3 -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.map +1 -1
- package/dist/magic/global/viewport.js +0 -1
- package/dist/magic/global/viewport.js.map +1 -1
- package/dist/magic/incantation.d.ts +44 -0
- package/dist/magic/incantation.d.ts.map +1 -1
- package/dist/magic/incantation.js +38 -0
- package/dist/magic/incantation.js.map +1 -1
- package/dist/magic/index.d.ts +7 -0
- package/dist/magic/index.d.ts.map +1 -1
- package/dist/magic/index.js +7 -0
- package/dist/magic/index.js.map +1 -1
- package/dist/magic/local/anim.d.ts.map +1 -1
- package/dist/magic/local/anim.js +1 -0
- 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 +1 -0
- 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 +1 -0
- package/dist/magic/local/slider.js.map +1 -1
- package/dist/parser/ast.d.ts +9 -0
- package/dist/parser/ast.d.ts.map +1 -1
- package/dist/parser/ast.js +1 -0
- package/dist/parser/ast.js.map +1 -1
- package/dist/parser/desmost-parser.d.ts +101 -1
- package/dist/parser/desmost-parser.d.ts.map +1 -1
- package/dist/parser/desmost-parser.js +129 -2
- package/dist/parser/desmost-parser.js.map +1 -1
- package/dist/parser/generic-parser.d.ts +47 -0
- package/dist/parser/generic-parser.d.ts.map +1 -1
- package/dist/parser/generic-parser.js +50 -0
- package/dist/parser/generic-parser.js.map +1 -1
- package/dist/parser/index.d.ts.map +1 -1
- package/dist/parser/index.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +5 -2
- package/src/compiler/compile.ts +124 -124
- package/src/compiler/evaluate.ts +86 -118
- package/src/compiler/format.ts +39 -6
- package/src/compiler/index.ts +0 -7
- package/src/compiler/options.ts +83 -77
- package/src/compiler/readme.md +5 -0
- 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/decompiler/readme.md +34 -0
- package/src/desmos.ts +6 -6
- package/src/errors.ts +19 -19
- package/src/index.internal.ts +3 -1
- 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 +18 -15
- package/src/magic/global/index.ts +8 -3
- package/src/magic/global/viewport.ts +19 -20
- 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/magic/readme.md +5 -0
- package/src/parser/ast.ts +46 -46
- package/src/parser/desmost-parser.ts +550 -550
- package/src/parser/generic-parser.ts +176 -176
- package/src/parser/index.ts +0 -4
- package/src/parser/readme.md +21 -0
- package/src/utils.ts +33 -33
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { Incantation, ArgIncantation, type GLOBAL } from "../incantation";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
type DesmosSettings = Desmos.GraphConfiguration & Desmos.GraphSettings
|
|
5
|
+
|
|
6
|
+
|
|
4
7
|
export class DesmosIncantation extends ArgIncantation<GLOBAL>
|
|
5
8
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
override readonly description
|
|
10
|
+
= "Set the configuration of the calculator via `Calculator.updateSettings()`."
|
|
11
|
+
|
|
12
|
+
override readonly identifier = "desmos"
|
|
13
|
+
override readonly requires_arg = false
|
|
14
|
+
override readonly arg_type = Incantation.ArgType.OBJECT
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
override apply(
|
|
17
|
+
target: Desmos.Calculator,
|
|
18
|
+
data?: DesmosSettings,
|
|
19
|
+
): void
|
|
20
|
+
{
|
|
21
|
+
if (data != undefined) {
|
|
22
|
+
target.updateSettings(data);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
22
25
|
}
|
|
@@ -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,32 +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
|
-
console.log(`existing =`, existing);
|
|
20
|
+
apply(target: Desmos.Calculator, data: ViewportBounds)
|
|
21
|
+
{
|
|
22
|
+
let existing = target.graphpaperBounds.mathCoordinates;
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
let {
|
|
25
|
+
left = existing.left,
|
|
26
|
+
right = existing.right,
|
|
27
|
+
bottom = existing.bottom,
|
|
28
|
+
top = existing.top,
|
|
29
|
+
} = data;
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
target.setMathBounds({ left, right, bottom, top });
|
|
32
|
+
}
|
|
34
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
|
}
|
package/src/magic/local/hide.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { Incantation, type LOCAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
export class HideIncantation extends Incantation<LOCAL>
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
override readonly description
|
|
7
|
+
= "Hide rendering for a block. This includes graphs, points, polygons, etc."
|
|
8
|
+
|
|
9
|
+
override readonly identifier = "hide"
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
apply(target: Desmos.ExpressionState)
|
|
12
|
+
{
|
|
13
|
+
super.require_expr_type(target.type, "expression");
|
|
14
|
+
target.hidden = true;
|
|
15
|
+
}
|
|
16
16
|
}
|
package/src/magic/local/index.ts
CHANGED
|
@@ -15,15 +15,15 @@ import { SliderIncantation } from "./slider";
|
|
|
15
15
|
|
|
16
16
|
export const LOCAL_INCANTATIONS: Incantation<LOCAL>[] =
|
|
17
17
|
[
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
new AnimIncantation(),
|
|
19
|
+
new ColourIncantation(),
|
|
20
|
+
new DashedIncantation(),
|
|
21
|
+
new FillIncantation(),
|
|
22
|
+
new HideIncantation(),
|
|
23
|
+
new LabelIncantation(),
|
|
24
|
+
new LineIncantation(),
|
|
25
|
+
new NoLineIncantation(),
|
|
26
|
+
new PointIncantation(),
|
|
27
|
+
new SecretIncantation(),
|
|
28
|
+
new SliderIncantation(),
|
|
29
29
|
];
|
package/src/magic/local/label.ts
CHANGED
|
@@ -4,60 +4,60 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
|
|
|
4
4
|
|
|
5
5
|
interface LabelOptions
|
|
6
6
|
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
text: string;
|
|
8
|
+
show?: boolean;
|
|
9
|
+
size?: number | keyof typeof Desmos.LabelSizes;
|
|
10
|
+
pos?: keyof typeof Desmos.LabelOrientations;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
export class LabelIncantation extends ArgIncantation<LOCAL>
|
|
15
15
|
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
16
|
+
override readonly description
|
|
17
|
+
= "Label a block that evaluates to a point(s)."
|
|
18
|
+
|
|
19
|
+
override readonly identifier = "label"
|
|
20
|
+
override readonly requires_arg = true
|
|
21
|
+
override readonly arg_type = Incantation.ArgType.OBJECT
|
|
22
|
+
|
|
23
|
+
override apply(target: Desmos.ExpressionState, data: LabelOptions)
|
|
24
|
+
{
|
|
25
|
+
super.require_expr_type(target.type, "expression");
|
|
26
|
+
target.label = data.text;
|
|
27
|
+
target.showLabel = data.show ?? true;
|
|
28
|
+
// @ts-expect-error: outdated types TODO check
|
|
29
|
+
if (data.size != undefined) target.labelSize = data.size;
|
|
30
|
+
if (data.pos != undefined) target.labelOrientation = data.pos;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override evaluate_arg(raw: string): LabelOptions
|
|
34
|
+
{
|
|
35
|
+
let out = super.evaluate_arg(raw) as LabelOptions;
|
|
36
|
+
|
|
37
|
+
if (!("text" in out)) {
|
|
38
|
+
throw new UnrecoverableError.InvalidArgument(
|
|
39
|
+
`/label requires a \`text\` argument, such as: \`/label{ text: "sup world!" }\``
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (typeof out.pos != "undefined") {
|
|
44
|
+
let pos = out.pos.trim().toUpperCase();
|
|
45
|
+
|
|
46
|
+
switch (pos) {
|
|
47
|
+
case "ABOVE":
|
|
48
|
+
case "BELOW":
|
|
49
|
+
case "LEFT":
|
|
50
|
+
case "RIGHT":
|
|
51
|
+
out.pos = pos;
|
|
52
|
+
break;
|
|
53
|
+
|
|
54
|
+
default:
|
|
55
|
+
throw new UnrecoverableError.InvalidArgument(
|
|
56
|
+
`/label: Invalid label position: ${pos}`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
63
|
}
|