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.
Files changed (167) hide show
  1. package/dist/compiler/compile.d.ts +25 -1
  2. package/dist/compiler/compile.d.ts.map +1 -1
  3. package/dist/compiler/compile.js +32 -2
  4. package/dist/compiler/compile.js.map +1 -1
  5. package/dist/compiler/evaluate.d.ts +11 -0
  6. package/dist/compiler/evaluate.d.ts.map +1 -1
  7. package/dist/compiler/evaluate.js +15 -11
  8. package/dist/compiler/evaluate.js.map +1 -1
  9. package/dist/compiler/format.d.ts +13 -0
  10. package/dist/compiler/format.d.ts.map +1 -1
  11. package/dist/compiler/format.js +23 -0
  12. package/dist/compiler/format.js.map +1 -1
  13. package/dist/compiler/index.d.ts.map +1 -1
  14. package/dist/compiler/index.js.map +1 -1
  15. package/dist/compiler/options.d.ts +79 -0
  16. package/dist/compiler/options.d.ts.map +1 -1
  17. package/dist/compiler/options.js +18 -11
  18. package/dist/compiler/options.js.map +1 -1
  19. package/dist/decompiler/decompile.d.ts +20 -0
  20. package/dist/decompiler/decompile.d.ts.map +1 -0
  21. package/dist/decompiler/decompile.js +32 -0
  22. package/dist/decompiler/decompile.js.map +1 -0
  23. package/dist/decompiler/emit.d.ts +10 -0
  24. package/dist/decompiler/emit.d.ts.map +1 -0
  25. package/dist/decompiler/emit.js +37 -0
  26. package/dist/decompiler/emit.js.map +1 -0
  27. package/dist/decompiler/extract.d.ts +14 -0
  28. package/dist/decompiler/extract.d.ts.map +1 -0
  29. package/dist/decompiler/extract.js +63 -0
  30. package/dist/decompiler/extract.js.map +1 -0
  31. package/dist/decompiler/format.d.ts +3 -0
  32. package/dist/decompiler/format.d.ts.map +1 -0
  33. package/dist/decompiler/format.js +14 -0
  34. package/dist/decompiler/format.js.map +1 -0
  35. package/dist/decompiler/index.d.ts +2 -0
  36. package/dist/decompiler/index.d.ts.map +1 -0
  37. package/dist/decompiler/index.js +2 -0
  38. package/dist/decompiler/index.js.map +1 -0
  39. package/dist/desmos.d.ts +3 -0
  40. package/dist/desmos.d.ts.map +1 -1
  41. package/dist/desmos.js +3 -0
  42. package/dist/desmos.js.map +1 -1
  43. package/dist/errors.d.ts +18 -4
  44. package/dist/errors.d.ts.map +1 -1
  45. package/dist/errors.js +13 -1
  46. package/dist/errors.js.map +1 -1
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.internal.d.ts +2 -1
  50. package/dist/index.internal.d.ts.map +1 -1
  51. package/dist/index.internal.js +2 -1
  52. package/dist/index.internal.js.map +1 -1
  53. package/dist/index.js +1 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/magic/expr/index.js.map +1 -1
  56. package/dist/magic/expr/latex.d.ts.map +1 -1
  57. package/dist/magic/expr/latex.js +1 -0
  58. package/dist/magic/expr/latex.js.map +1 -1
  59. package/dist/magic/expr/text.d.ts.map +1 -1
  60. package/dist/magic/expr/text.js +1 -0
  61. package/dist/magic/expr/text.js.map +1 -1
  62. package/dist/magic/global/dark-mode.d.ts.map +1 -1
  63. package/dist/magic/global/dark-mode.js.map +1 -1
  64. package/dist/magic/global/desmos.d.ts +3 -1
  65. package/dist/magic/global/desmos.d.ts.map +1 -1
  66. package/dist/magic/global/desmos.js.map +1 -1
  67. package/dist/magic/global/index.d.ts +3 -0
  68. package/dist/magic/global/index.d.ts.map +1 -1
  69. package/dist/magic/global/index.js +3 -0
  70. package/dist/magic/global/index.js.map +1 -1
  71. package/dist/magic/global/viewport.d.ts.map +1 -1
  72. package/dist/magic/global/viewport.js +0 -1
  73. package/dist/magic/global/viewport.js.map +1 -1
  74. package/dist/magic/incantation.d.ts +44 -0
  75. package/dist/magic/incantation.d.ts.map +1 -1
  76. package/dist/magic/incantation.js +38 -0
  77. package/dist/magic/incantation.js.map +1 -1
  78. package/dist/magic/index.d.ts +7 -0
  79. package/dist/magic/index.d.ts.map +1 -1
  80. package/dist/magic/index.js +7 -0
  81. package/dist/magic/index.js.map +1 -1
  82. package/dist/magic/local/anim.d.ts.map +1 -1
  83. package/dist/magic/local/anim.js +1 -0
  84. package/dist/magic/local/anim.js.map +1 -1
  85. package/dist/magic/local/colour.d.ts.map +1 -1
  86. package/dist/magic/local/colour.js.map +1 -1
  87. package/dist/magic/local/dashed.d.ts.map +1 -1
  88. package/dist/magic/local/dashed.js.map +1 -1
  89. package/dist/magic/local/fill.d.ts.map +1 -1
  90. package/dist/magic/local/fill.js.map +1 -1
  91. package/dist/magic/local/hide.d.ts.map +1 -1
  92. package/dist/magic/local/hide.js.map +1 -1
  93. package/dist/magic/local/index.js.map +1 -1
  94. package/dist/magic/local/label.d.ts.map +1 -1
  95. package/dist/magic/local/label.js +1 -0
  96. package/dist/magic/local/label.js.map +1 -1
  97. package/dist/magic/local/line.d.ts.map +1 -1
  98. package/dist/magic/local/line.js.map +1 -1
  99. package/dist/magic/local/no-line.d.ts.map +1 -1
  100. package/dist/magic/local/no-line.js.map +1 -1
  101. package/dist/magic/local/point.d.ts.map +1 -1
  102. package/dist/magic/local/point.js.map +1 -1
  103. package/dist/magic/local/secret.d.ts.map +1 -1
  104. package/dist/magic/local/secret.js.map +1 -1
  105. package/dist/magic/local/slider.d.ts.map +1 -1
  106. package/dist/magic/local/slider.js +1 -0
  107. package/dist/magic/local/slider.js.map +1 -1
  108. package/dist/parser/ast.d.ts +9 -0
  109. package/dist/parser/ast.d.ts.map +1 -1
  110. package/dist/parser/ast.js +1 -0
  111. package/dist/parser/ast.js.map +1 -1
  112. package/dist/parser/desmost-parser.d.ts +101 -1
  113. package/dist/parser/desmost-parser.d.ts.map +1 -1
  114. package/dist/parser/desmost-parser.js +129 -2
  115. package/dist/parser/desmost-parser.js.map +1 -1
  116. package/dist/parser/generic-parser.d.ts +47 -0
  117. package/dist/parser/generic-parser.d.ts.map +1 -1
  118. package/dist/parser/generic-parser.js +50 -0
  119. package/dist/parser/generic-parser.js.map +1 -1
  120. package/dist/parser/index.d.ts.map +1 -1
  121. package/dist/parser/index.js.map +1 -1
  122. package/dist/utils.d.ts.map +1 -1
  123. package/dist/utils.js.map +1 -1
  124. package/package.json +5 -2
  125. package/src/compiler/compile.ts +124 -124
  126. package/src/compiler/evaluate.ts +86 -118
  127. package/src/compiler/format.ts +39 -6
  128. package/src/compiler/index.ts +0 -7
  129. package/src/compiler/options.ts +83 -77
  130. package/src/compiler/readme.md +5 -0
  131. package/src/decompiler/decompile.ts +48 -0
  132. package/src/decompiler/emit.ts +47 -0
  133. package/src/decompiler/extract.ts +100 -0
  134. package/src/decompiler/format.ts +20 -0
  135. package/src/decompiler/index.ts +1 -0
  136. package/src/decompiler/readme.md +34 -0
  137. package/src/desmos.ts +6 -6
  138. package/src/errors.ts +19 -19
  139. package/src/index.internal.ts +3 -1
  140. package/src/index.ts +1 -0
  141. package/src/magic/expr/index.ts +2 -2
  142. package/src/magic/expr/latex.ts +16 -16
  143. package/src/magic/expr/text.ts +13 -13
  144. package/src/magic/global/dark-mode.ts +10 -10
  145. package/src/magic/global/desmos.ts +18 -15
  146. package/src/magic/global/index.ts +8 -3
  147. package/src/magic/global/viewport.ts +19 -20
  148. package/src/magic/incantation.ts +94 -94
  149. package/src/magic/local/anim.ts +10 -10
  150. package/src/magic/local/colour.ts +26 -26
  151. package/src/magic/local/dashed.ts +9 -9
  152. package/src/magic/local/fill.ts +12 -12
  153. package/src/magic/local/hide.ts +9 -9
  154. package/src/magic/local/index.ts +11 -11
  155. package/src/magic/local/label.ts +51 -51
  156. package/src/magic/local/line.ts +16 -16
  157. package/src/magic/local/no-line.ts +9 -9
  158. package/src/magic/local/point.ts +16 -16
  159. package/src/magic/local/secret.ts +9 -9
  160. package/src/magic/local/slider.ts +15 -15
  161. package/src/magic/readme.md +5 -0
  162. package/src/parser/ast.ts +46 -46
  163. package/src/parser/desmost-parser.ts +550 -550
  164. package/src/parser/generic-parser.ts +176 -176
  165. package/src/parser/index.ts +0 -4
  166. package/src/parser/readme.md +21 -0
  167. 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
- 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
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
- 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
- }
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
- new DesmosIncantation(),
11
- new ViewportIncantation(),
12
- new DarkModeIncantation(),
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
- 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
- let existing = target.graphpaperBounds.mathCoordinates;
23
- console.log(`existing =`, existing);
20
+ apply(target: Desmos.Calculator, data: ViewportBounds)
21
+ {
22
+ let existing = target.graphpaperBounds.mathCoordinates;
24
23
 
25
- let {
26
- left = existing.left,
27
- right = existing.right,
28
- bottom = existing.bottom,
29
- top = existing.top,
30
- } = data;
24
+ let {
25
+ left = existing.left,
26
+ right = existing.right,
27
+ bottom = existing.bottom,
28
+ top = existing.top,
29
+ } = data;
31
30
 
32
- target.setMathBounds({ left, right, bottom, top });
33
- }
31
+ target.setMathBounds({ left, right, bottom, top });
32
+ }
34
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
  }
@@ -3,14 +3,14 @@ import { Incantation, type LOCAL } from "../incantation";
3
3
 
4
4
  export class HideIncantation extends Incantation<LOCAL>
5
5
  {
6
- override readonly description
7
- = "Hide rendering for a block. This includes graphs, points, polygons, etc."
8
-
9
- override readonly identifier = "hide"
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
- apply(target: Desmos.ExpressionState)
12
- {
13
- super.require_expr_type(target.type, "expression");
14
- target.hidden = true;
15
- }
11
+ apply(target: Desmos.ExpressionState)
12
+ {
13
+ super.require_expr_type(target.type, "expression");
14
+ target.hidden = true;
15
+ }
16
16
  }
@@ -15,15 +15,15 @@ import { SliderIncantation } from "./slider";
15
15
 
16
16
  export const LOCAL_INCANTATIONS: Incantation<LOCAL>[] =
17
17
  [
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(),
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
  ];
@@ -4,60 +4,60 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
4
4
 
5
5
  interface LabelOptions
6
6
  {
7
- text: string;
8
- show?: boolean;
9
- size?: number | keyof typeof Desmos.LabelSizes;
10
- pos?: keyof typeof Desmos.LabelOrientations;
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
- 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
- }
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
  }