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
package/src/magic/local/line.ts
CHANGED
|
@@ -3,27 +3,27 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
interface LineOptions
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
style?: keyof typeof Desmos.Styles; // TODO allow raw enum
|
|
7
|
+
width?: number;
|
|
8
|
+
opacity?: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
export class LineIncantation extends ArgIncantation<LOCAL>
|
|
13
13
|
{
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
override readonly description
|
|
15
|
+
= "Change line styles for a rendered block."
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
override readonly identifier = "line"
|
|
18
|
+
override readonly requires_arg = true
|
|
19
|
+
override readonly arg_type = Incantation.ArgType.OBJECT
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
override apply(target: Desmos.ExpressionState, data: LineOptions)
|
|
22
|
+
{
|
|
23
|
+
super.require_expr_type(target.type, "expression");
|
|
24
|
+
|
|
25
|
+
if (data.style != undefined) target.lineStyle = data.style;
|
|
26
|
+
if (data.width != undefined) target.lineWidth = data.width;
|
|
27
|
+
if (data.opacity != undefined) target.lineOpacity = data.opacity;
|
|
28
|
+
}
|
|
29
29
|
}
|
|
@@ -3,14 +3,14 @@ import { Incantation, type LOCAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
export class NoLineIncantation extends Incantation<LOCAL>
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
override readonly description
|
|
7
|
+
= "Disable rendering lines for a block."
|
|
8
|
+
|
|
9
|
+
override readonly identifier = "no-line"
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
override apply(target: Desmos.ExpressionState)
|
|
12
|
+
{
|
|
13
|
+
super.require_expr_type(target.type, "expression");
|
|
14
|
+
target.lines = false;
|
|
15
|
+
}
|
|
16
16
|
}
|
package/src/magic/local/point.ts
CHANGED
|
@@ -3,27 +3,27 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
interface PointStyles
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
style?: keyof typeof Desmos.Styles;
|
|
7
|
+
size?: number;
|
|
8
|
+
opacity?: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
export class PointIncantation extends ArgIncantation<LOCAL>
|
|
13
13
|
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
override readonly description
|
|
15
|
+
= ""
|
|
16
|
+
|
|
17
|
+
override readonly identifier = "point"
|
|
18
|
+
override readonly requires_arg = true
|
|
19
|
+
override readonly arg_type = Incantation.ArgType.OBJECT
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
override apply(target: Desmos.ExpressionState, data: Partial<PointStyles>)
|
|
22
|
+
{
|
|
23
|
+
super.require_expr_type(target.type, "expression");
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
if (data.style != undefined) target.pointStyle = data.style;
|
|
26
|
+
if (data.size != undefined) target.pointSize = data.size;
|
|
27
|
+
if (data.opacity != undefined) target.pointOpacity = data.opacity;
|
|
28
|
+
}
|
|
29
29
|
}
|
|
@@ -3,14 +3,14 @@ import { Incantation, type LOCAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
export class SecretIncantation extends Incantation<LOCAL>
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
override readonly description
|
|
7
|
+
= "Turn a block into a secret expression, which is hidden from the end user."
|
|
8
|
+
|
|
9
|
+
override readonly identifier = "secret"
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
override apply(target: Desmos.ExpressionState)
|
|
12
|
+
{
|
|
13
|
+
super.require_expr_type(target.type, "expression");
|
|
14
|
+
target.secret = true;
|
|
15
|
+
}
|
|
16
16
|
}
|
|
@@ -3,25 +3,25 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
|
|
|
3
3
|
|
|
4
4
|
interface SliderBounds
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
min?: number | string;
|
|
7
|
+
max?: number | string;
|
|
8
|
+
step?: number | string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
export class SliderIncantation extends ArgIncantation<LOCAL>
|
|
13
13
|
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
override readonly description
|
|
15
|
+
= "Set the bounds of the slider for a variable."
|
|
16
|
+
|
|
17
|
+
override readonly identifier = "slider"
|
|
18
|
+
override readonly requires_arg = true
|
|
19
|
+
override readonly arg_type = Incantation.ArgType.OBJECT
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
override apply(target: Desmos.ExpressionState, data: SliderBounds)
|
|
22
|
+
{
|
|
23
|
+
super.require_expr_type(target.type, "expression");
|
|
24
|
+
// @ts-expect-error: outdated types
|
|
25
|
+
target.sliderBounds = data;
|
|
26
|
+
}
|
|
27
27
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Incantations
|
|
2
|
+
|
|
3
|
+
This module implements how incantations are represented, and the individual logic for every incantation in Desmost.
|
|
4
|
+
|
|
5
|
+
Each incantation is defined in its own file as a class deriving from `ArgIncantation` or `Incantation`. They can then implement whatever logic they require for `apply()` and `evaluate_arg()`.
|
package/src/parser/ast.ts
CHANGED
|
@@ -4,57 +4,57 @@ import { Incantation, ArgIncantation } from "../magic";
|
|
|
4
4
|
|
|
5
5
|
export namespace Ast
|
|
6
6
|
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
/** What kind of AST node this is. */
|
|
8
|
+
export enum Kind
|
|
9
|
+
{
|
|
10
|
+
EXPRESSION = "Expression",
|
|
11
|
+
INCANTATION_INVOCATION = "Incantation-Invocation",
|
|
12
|
+
INVALID_INCANTATION = "Invalid-Incantation",
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
|
|
16
|
+
/** A Desmos expression to add to the calculator. */
|
|
17
|
+
export interface Expression
|
|
18
|
+
{
|
|
19
|
+
kind: Kind.EXPRESSION
|
|
20
|
+
data: Desmos.ExpressionState
|
|
21
|
+
incantations: Array<
|
|
22
|
+
| IncantationInvocation<Incantation.Effect.LOCAL>
|
|
23
|
+
| InvalidInvocation
|
|
24
|
+
>
|
|
25
|
+
}
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
/** A pending incantation invocation that requires applying its argument (if any), then applying its effect. */
|
|
29
|
+
export type IncantationInvocation<Effect extends Incantation.Effect = Incantation.Effect> =
|
|
30
|
+
| {
|
|
31
|
+
kind: Kind.INCANTATION_INVOCATION
|
|
32
|
+
incantation: Incantation<Effect>
|
|
33
|
+
arg_raw: undefined
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
kind: Kind.INCANTATION_INVOCATION
|
|
37
|
+
incantation: ArgIncantation<Effect>
|
|
38
|
+
arg_raw: string | undefined
|
|
39
|
+
};
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
/**
|
|
42
|
+
* An invalid invantation invocation that raised an error when parsed.
|
|
43
|
+
*
|
|
44
|
+
* This will be propogated to the user as an extra Desmos text expression (unless they have `errors: "suppress"` configured).
|
|
45
|
+
*/
|
|
46
|
+
export interface InvalidInvocation
|
|
47
|
+
{
|
|
48
|
+
kind: Kind.INVALID_INCANTATION
|
|
49
|
+
incantation: Incantation
|
|
50
|
+
arg_raw?: string
|
|
51
|
+
error: UnrecoverableError
|
|
52
|
+
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/** An abstract object produced by
|
|
55
|
+
/** An abstract object produced by the parser. */
|
|
56
56
|
export type Ast =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
| Ast.Expression
|
|
58
|
+
| Ast.IncantationInvocation
|
|
59
|
+
| Ast.InvalidInvocation
|
|
60
60
|
;
|