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.
Files changed (132) hide show
  1. package/dist/compiler/compile.d.ts.map +1 -1
  2. package/dist/compiler/compile.js.map +1 -1
  3. package/dist/compiler/evaluate.d.ts.map +1 -1
  4. package/dist/compiler/evaluate.js +2 -14
  5. package/dist/compiler/evaluate.js.map +1 -1
  6. package/dist/compiler/format.d.ts +2 -0
  7. package/dist/compiler/format.d.ts.map +1 -1
  8. package/dist/compiler/format.js +11 -0
  9. package/dist/compiler/format.js.map +1 -1
  10. package/dist/compiler/options.d.ts.map +1 -1
  11. package/dist/compiler/options.js.map +1 -1
  12. package/dist/decompiler/decompile.d.ts +9 -0
  13. package/dist/decompiler/decompile.d.ts.map +1 -0
  14. package/dist/decompiler/decompile.js +21 -0
  15. package/dist/decompiler/decompile.js.map +1 -0
  16. package/dist/decompiler/emit.d.ts +4 -0
  17. package/dist/decompiler/emit.d.ts.map +1 -0
  18. package/dist/decompiler/emit.js +28 -0
  19. package/dist/decompiler/emit.js.map +1 -0
  20. package/dist/decompiler/extract.d.ts +5 -0
  21. package/dist/decompiler/extract.d.ts.map +1 -0
  22. package/dist/decompiler/extract.js +53 -0
  23. package/dist/decompiler/extract.js.map +1 -0
  24. package/dist/decompiler/format.d.ts +3 -0
  25. package/dist/decompiler/format.d.ts.map +1 -0
  26. package/dist/decompiler/format.js +11 -0
  27. package/dist/decompiler/format.js.map +1 -0
  28. package/dist/decompiler/index.d.ts +2 -0
  29. package/dist/decompiler/index.d.ts.map +1 -0
  30. package/dist/decompiler/index.js +2 -0
  31. package/dist/decompiler/index.js.map +1 -0
  32. package/dist/desmos.d.ts.map +1 -1
  33. package/dist/desmos.js.map +1 -1
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js.map +1 -1
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.internal.d.ts +1 -0
  39. package/dist/index.internal.d.ts.map +1 -1
  40. package/dist/index.internal.js +1 -0
  41. package/dist/index.internal.js.map +1 -1
  42. package/dist/index.js +1 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/magic/expr/index.js.map +1 -1
  45. package/dist/magic/expr/latex.d.ts.map +1 -1
  46. package/dist/magic/expr/latex.js.map +1 -1
  47. package/dist/magic/expr/text.d.ts.map +1 -1
  48. package/dist/magic/expr/text.js.map +1 -1
  49. package/dist/magic/global/dark-mode.d.ts.map +1 -1
  50. package/dist/magic/global/dark-mode.js.map +1 -1
  51. package/dist/magic/global/desmos.d.ts.map +1 -1
  52. package/dist/magic/global/desmos.js.map +1 -1
  53. package/dist/magic/global/index.d.ts +3 -0
  54. package/dist/magic/global/index.d.ts.map +1 -1
  55. package/dist/magic/global/index.js +3 -0
  56. package/dist/magic/global/index.js.map +1 -1
  57. package/dist/magic/global/viewport.d.ts +4 -4
  58. package/dist/magic/global/viewport.d.ts.map +1 -1
  59. package/dist/magic/global/viewport.js +3 -1
  60. package/dist/magic/global/viewport.js.map +1 -1
  61. package/dist/magic/incantation.d.ts.map +1 -1
  62. package/dist/magic/incantation.js.map +1 -1
  63. package/dist/magic/local/anim.d.ts.map +1 -1
  64. package/dist/magic/local/anim.js.map +1 -1
  65. package/dist/magic/local/colour.d.ts.map +1 -1
  66. package/dist/magic/local/colour.js.map +1 -1
  67. package/dist/magic/local/dashed.d.ts.map +1 -1
  68. package/dist/magic/local/dashed.js.map +1 -1
  69. package/dist/magic/local/fill.d.ts.map +1 -1
  70. package/dist/magic/local/fill.js.map +1 -1
  71. package/dist/magic/local/hide.d.ts.map +1 -1
  72. package/dist/magic/local/hide.js.map +1 -1
  73. package/dist/magic/local/index.js.map +1 -1
  74. package/dist/magic/local/label.d.ts.map +1 -1
  75. package/dist/magic/local/label.js.map +1 -1
  76. package/dist/magic/local/line.d.ts.map +1 -1
  77. package/dist/magic/local/line.js.map +1 -1
  78. package/dist/magic/local/no-line.d.ts.map +1 -1
  79. package/dist/magic/local/no-line.js.map +1 -1
  80. package/dist/magic/local/point.d.ts.map +1 -1
  81. package/dist/magic/local/point.js.map +1 -1
  82. package/dist/magic/local/secret.d.ts.map +1 -1
  83. package/dist/magic/local/secret.js.map +1 -1
  84. package/dist/magic/local/slider.d.ts.map +1 -1
  85. package/dist/magic/local/slider.js.map +1 -1
  86. package/dist/parser/ast.d.ts.map +1 -1
  87. package/dist/parser/ast.js.map +1 -1
  88. package/dist/parser/desmost-parser.d.ts.map +1 -1
  89. package/dist/parser/desmost-parser.js +1 -1
  90. package/dist/parser/desmost-parser.js.map +1 -1
  91. package/dist/parser/generic-parser.d.ts.map +1 -1
  92. package/dist/parser/generic-parser.js.map +1 -1
  93. package/dist/utils.d.ts.map +1 -1
  94. package/dist/utils.js.map +1 -1
  95. package/package.json +1 -1
  96. package/src/compiler/compile.ts +124 -124
  97. package/src/compiler/evaluate.ts +86 -120
  98. package/src/compiler/format.ts +39 -6
  99. package/src/compiler/options.ts +78 -75
  100. package/src/decompiler/decompile.ts +48 -0
  101. package/src/decompiler/emit.ts +47 -0
  102. package/src/decompiler/extract.ts +100 -0
  103. package/src/decompiler/format.ts +20 -0
  104. package/src/decompiler/index.ts +1 -0
  105. package/src/desmos.ts +6 -6
  106. package/src/errors.ts +12 -12
  107. package/src/index.internal.ts +2 -0
  108. package/src/index.ts +1 -0
  109. package/src/magic/expr/index.ts +2 -2
  110. package/src/magic/expr/latex.ts +16 -16
  111. package/src/magic/expr/text.ts +13 -13
  112. package/src/magic/global/dark-mode.ts +10 -10
  113. package/src/magic/global/desmos.ts +15 -15
  114. package/src/magic/global/index.ts +8 -3
  115. package/src/magic/global/viewport.ts +21 -14
  116. package/src/magic/incantation.ts +94 -94
  117. package/src/magic/local/anim.ts +10 -10
  118. package/src/magic/local/colour.ts +26 -26
  119. package/src/magic/local/dashed.ts +9 -9
  120. package/src/magic/local/fill.ts +12 -12
  121. package/src/magic/local/hide.ts +9 -9
  122. package/src/magic/local/index.ts +11 -11
  123. package/src/magic/local/label.ts +51 -51
  124. package/src/magic/local/line.ts +16 -16
  125. package/src/magic/local/no-line.ts +9 -9
  126. package/src/magic/local/point.ts +16 -16
  127. package/src/magic/local/secret.ts +9 -9
  128. package/src/magic/local/slider.ts +15 -15
  129. package/src/parser/ast.ts +45 -45
  130. package/src/parser/desmost-parser.ts +550 -547
  131. package/src/parser/generic-parser.ts +176 -176
  132. 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
- RED = "#c74440",
8
- BLUE = "#2d70b3",
9
- GREEN = "#388c46",
10
- PURPLE = "#6042a6",
11
- ORANGE = "#fa7e19",
12
- BLACK = "#000000",
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
- /** The parser unexpectedly reached the end of its entire input source code. */
11
- export class UnexpectedEnd extends UnrecoverableError {}
10
+ /** The parser unexpectedly reached the end of its entire input source code. */
11
+ export class UnexpectedEnd extends UnrecoverableError {}
12
12
 
13
- /** The parser did not receive input that it expected. */
14
- export class MissingInput extends UnrecoverableError {}
13
+ /** The parser did not receive input that it expected. */
14
+ export class MissingInput extends UnrecoverableError {}
15
15
 
16
- /** The parser received input that did not match what it expected. */
17
- export class UnexpectedInput extends UnrecoverableError {}
16
+ /** The parser received input that did not match what it expected. */
17
+ export class UnexpectedInput extends UnrecoverableError {}
18
18
 
19
- /** The parser received excess input that it did not expect. */
20
- export class ExcessInput extends UnrecoverableError {}
19
+ /** The parser received excess input that it did not expect. */
20
+ export class ExcessInput extends UnrecoverableError {}
21
21
 
22
22
 
23
- /** An incantation can't be applied here. */
24
- export class IllegalIncantation extends UnrecoverableError {}
23
+ /** An incantation can't be applied here. */
24
+ export class IllegalIncantation extends UnrecoverableError {}
25
25
 
26
- /** An incantation's argument couldn't be parsed. */
27
- export class InvalidArgument extends UnrecoverableError {}
26
+ /** An incantation's argument couldn't be parsed. */
27
+ export class InvalidArgument extends UnrecoverableError {}
28
28
  }
29
29
 
30
30
 
@@ -2,3 +2,5 @@ export { fill_defaults } from "./compiler/options";
2
2
  export type { DesmostDebug } from "./compiler/compile";
3
3
 
4
4
  export { Ast } from "./parser";
5
+
6
+ export { desmos_to_ast, ast_to_source } from "./decompiler/decompile";
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { compile, type DesmostOptions } from "./compiler";
2
+ export { decompile } from "./decompiler";
@@ -6,6 +6,6 @@ import { TextIncantation } from "./text";
6
6
 
7
7
  export const EXPR_INCANTATIONS: ArgIncantation<EXPR>[] =
8
8
  [
9
- new LatexIncantation(),
10
- new TextIncantation(),
9
+ new LatexIncantation(),
10
+ new TextIncantation(),
11
11
  ];
@@ -3,22 +3,22 @@ import { Incantation, ArgIncantation, type EXPR } from "../incantation";
3
3
 
4
4
  export class LatexIncantation extends ArgIncantation<EXPR>
5
5
  {
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
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
- apply(target: Desmos.ExpressionState, data: string): void
14
- {
15
- target.type = "expression";
16
- // @ts-expect-error: outdated types
17
- target.latex = data === "" ? " " : data;
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
- override evaluate_arg(data: string): string
21
- {
22
- return data;
23
- }
20
+ override evaluate_arg(data: string): string
21
+ {
22
+ return data;
23
+ }
24
24
  }
@@ -3,18 +3,18 @@ import { Incantation, ArgIncantation, type EXPR } from "../incantation";
3
3
 
4
4
  export class TextIncantation extends ArgIncantation<EXPR>
5
5
  {
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
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
- override apply(target: Desmos.ExpressionState, data: string)
15
- {
16
- target.type = "text";
17
- // @ts-expect-error: outdated types
18
- target.text = data;
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
- override readonly description
7
- = "Enable dark mode for the calculator, which inverts all colours."
8
-
9
- override readonly identifier = "dark"
6
+ override readonly description
7
+ = "Enable dark mode for the calculator, which inverts all colours."
8
+
9
+ override readonly identifier = "dark"
10
10
 
11
- apply(target: Desmos.Calculator)
12
- {
13
- target.updateSettings({
14
- invertedColors: true,
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
- 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
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
- 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
- }
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
- new DesmosIncantation(),
11
- new ViewportIncantation(),
12
- new DarkModeIncantation(),
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
- left: number; right: number;
7
- bottom: number; top: number;
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
- 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
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
- apply(target: Desmos.Calculator, data: ViewportBounds)
21
- {
22
- // FIXME broken?
23
- // TODO validate bounds
24
- target.setMathBounds(data);
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
  }
@@ -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
- Effect extends Incantation.Effect = Incantation.Effect
20
+ Effect extends Incantation.Effect = Incantation.Effect
21
21
  >
22
22
  {
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
- }
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
- Effect extends Incantation.Effect = Incantation.Effect
59
+ Effect extends Incantation.Effect = Incantation.Effect
60
60
  >
61
- extends Incantation<Effect>
61
+ extends Incantation<Effect>
62
62
  {
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
- }
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
- /** 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
- }
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
 
@@ -3,15 +3,15 @@ import { Incantation, type LOCAL } from "../incantation";
3
3
 
4
4
  export class AnimIncantation extends Incantation<LOCAL>
5
5
  {
6
- override readonly description
7
- = "Animate the slider of a block."
8
-
9
- override readonly identifier = "anim"
6
+ override readonly description
7
+ = "Animate the slider of a block."
8
+
9
+ override readonly identifier = "anim"
10
10
 
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
- }
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
- override readonly description
10
- = ""
9
+ override readonly description
10
+ = ""
11
11
 
12
- override readonly identifier = "color"
13
- override readonly alias = "colour"
14
- override readonly requires_arg = true
15
- override readonly arg_type = Incantation.ArgType.ENUM
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
- override apply(target: Desmos.ExpressionState, data: DesmosColour)
18
- {
19
- super.require_expr_type(target.type, "expression");
20
- target.color = data;
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
- 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
- }
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
- override readonly description
7
- = "Render a block as a dashed line."
8
-
9
- override readonly identifier = "dashed"
6
+ override readonly description
7
+ = "Render a block as a dashed line."
8
+
9
+ override readonly identifier = "dashed"
10
10
 
11
- override apply(target: Desmos.ExpressionState)
12
- {
13
- super.require_expr_type(target.type, "expression");
14
- target.lineStyle = Desmos.Styles.DASHED;
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
  }
@@ -3,22 +3,22 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
3
3
 
4
4
  interface FillOptions
5
5
  {
6
- opacity: number;
6
+ opacity: number;
7
7
  }
8
8
 
9
9
 
10
10
  export class FillIncantation extends ArgIncantation<LOCAL>
11
11
  {
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
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
- override apply(target: Desmos.ExpressionState, data: FillOptions)
20
- {
21
- super.require_expr_type(target.type, "expression");
22
- target.fillOpacity = data.opacity;
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
  }