desmost 0.10.0 → 0.11.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 (167) hide show
  1. package/README.md +6 -6
  2. package/dist/compiler/compile.d.ts +1 -1
  3. package/dist/compiler/compile.js +1 -1
  4. package/dist/compiler/compiler.d.ts.map +1 -1
  5. package/dist/compiler/compiler.js +9 -8
  6. package/dist/compiler/compiler.js.map +1 -1
  7. package/dist/compiler/format.js +1 -1
  8. package/dist/compiler/format.js.map +1 -1
  9. package/dist/decompiler/decompile.d.ts +13 -5
  10. package/dist/decompiler/decompile.d.ts.map +1 -1
  11. package/dist/decompiler/decompile.js +24 -13
  12. package/dist/decompiler/decompile.js.map +1 -1
  13. package/dist/decompiler/emit.d.ts +5 -2
  14. package/dist/decompiler/emit.d.ts.map +1 -1
  15. package/dist/decompiler/emit.js +41 -20
  16. package/dist/decompiler/emit.js.map +1 -1
  17. package/dist/decompiler/extract.d.ts +1 -9
  18. package/dist/decompiler/extract.d.ts.map +1 -1
  19. package/dist/decompiler/extract.js +24 -58
  20. package/dist/decompiler/extract.js.map +1 -1
  21. package/dist/decompiler/format.d.ts +0 -1
  22. package/dist/decompiler/format.d.ts.map +1 -1
  23. package/dist/decompiler/format.js +3 -9
  24. package/dist/decompiler/format.js.map +1 -1
  25. package/dist/errors.d.ts +14 -7
  26. package/dist/errors.d.ts.map +1 -1
  27. package/dist/errors.js +20 -2
  28. package/dist/errors.js.map +1 -1
  29. package/dist/magic/expr/index.js +6 -6
  30. package/dist/magic/expr/index.js.map +1 -1
  31. package/dist/magic/expr/latex.d.ts +5 -2
  32. package/dist/magic/expr/latex.d.ts.map +1 -1
  33. package/dist/magic/expr/latex.js +4 -2
  34. package/dist/magic/expr/latex.js.map +1 -1
  35. package/dist/magic/expr/text.d.ts +5 -2
  36. package/dist/magic/expr/text.d.ts.map +1 -1
  37. package/dist/magic/expr/text.js +4 -2
  38. package/dist/magic/expr/text.js.map +1 -1
  39. package/dist/magic/global/{dark-mode.d.ts → dark.d.ts} +6 -2
  40. package/dist/magic/global/dark.d.ts.map +1 -0
  41. package/dist/magic/global/dark.js +20 -0
  42. package/dist/magic/global/dark.js.map +1 -0
  43. package/dist/magic/global/desmos.d.ts +4 -1
  44. package/dist/magic/global/desmos.d.ts.map +1 -1
  45. package/dist/magic/global/desmos.js +23 -0
  46. package/dist/magic/global/desmos.js.map +1 -1
  47. package/dist/magic/global/index.d.ts +5 -5
  48. package/dist/magic/global/index.d.ts.map +1 -1
  49. package/dist/magic/global/index.js +8 -11
  50. package/dist/magic/global/index.js.map +1 -1
  51. package/dist/magic/global/viewport.d.ts +3 -0
  52. package/dist/magic/global/viewport.d.ts.map +1 -1
  53. package/dist/magic/global/viewport.js +20 -0
  54. package/dist/magic/global/viewport.js.map +1 -1
  55. package/dist/magic/incantation.d.ts +15 -2
  56. package/dist/magic/incantation.d.ts.map +1 -1
  57. package/dist/magic/incantation.js +8 -1
  58. package/dist/magic/incantation.js.map +1 -1
  59. package/dist/magic/local/anim.d.ts +5 -1
  60. package/dist/magic/local/anim.d.ts.map +1 -1
  61. package/dist/magic/local/anim.js +12 -1
  62. package/dist/magic/local/anim.js.map +1 -1
  63. package/dist/magic/local/colour.d.ts +7 -3
  64. package/dist/magic/local/colour.d.ts.map +1 -1
  65. package/dist/magic/local/colour.js +13 -3
  66. package/dist/magic/local/colour.js.map +1 -1
  67. package/dist/magic/local/dashed.d.ts +5 -1
  68. package/dist/magic/local/dashed.d.ts.map +1 -1
  69. package/dist/magic/local/dashed.js +12 -1
  70. package/dist/magic/local/dashed.js.map +1 -1
  71. package/dist/magic/local/fill.d.ts +5 -1
  72. package/dist/magic/local/fill.d.ts.map +1 -1
  73. package/dist/magic/local/fill.js +15 -1
  74. package/dist/magic/local/fill.js.map +1 -1
  75. package/dist/magic/local/hide.d.ts +5 -1
  76. package/dist/magic/local/hide.d.ts.map +1 -1
  77. package/dist/magic/local/hide.js +12 -1
  78. package/dist/magic/local/hide.js.map +1 -1
  79. package/dist/magic/local/index.d.ts +13 -2
  80. package/dist/magic/local/index.d.ts.map +1 -1
  81. package/dist/magic/local/index.js +24 -24
  82. package/dist/magic/local/index.js.map +1 -1
  83. package/dist/magic/local/label.d.ts +6 -2
  84. package/dist/magic/local/label.d.ts.map +1 -1
  85. package/dist/magic/local/label.js +19 -1
  86. package/dist/magic/local/label.js.map +1 -1
  87. package/dist/magic/local/line.d.ts +5 -1
  88. package/dist/magic/local/line.d.ts.map +1 -1
  89. package/dist/magic/local/line.js +19 -1
  90. package/dist/magic/local/line.js.map +1 -1
  91. package/dist/magic/local/no-line.d.ts +5 -1
  92. package/dist/magic/local/no-line.d.ts.map +1 -1
  93. package/dist/magic/local/no-line.js +12 -1
  94. package/dist/magic/local/no-line.js.map +1 -1
  95. package/dist/magic/local/point.d.ts +5 -1
  96. package/dist/magic/local/point.d.ts.map +1 -1
  97. package/dist/magic/local/point.js +19 -1
  98. package/dist/magic/local/point.js.map +1 -1
  99. package/dist/magic/local/secret.d.ts +5 -1
  100. package/dist/magic/local/secret.d.ts.map +1 -1
  101. package/dist/magic/local/secret.js +12 -1
  102. package/dist/magic/local/secret.js.map +1 -1
  103. package/dist/magic/local/slider.d.ts +5 -1
  104. package/dist/magic/local/slider.d.ts.map +1 -1
  105. package/dist/magic/local/slider.js +13 -1
  106. package/dist/magic/local/slider.js.map +1 -1
  107. package/dist/parser/ast.d.ts +9 -3
  108. package/dist/parser/ast.d.ts.map +1 -1
  109. package/dist/parser/ast.js +3 -1
  110. package/dist/parser/ast.js.map +1 -1
  111. package/dist/parser/desmost-parser.d.ts +2 -2
  112. package/dist/parser/desmost-parser.d.ts.map +1 -1
  113. package/dist/parser/desmost-parser.js +21 -19
  114. package/dist/parser/desmost-parser.js.map +1 -1
  115. package/dist/parser/errors.d.ts +11 -0
  116. package/dist/parser/errors.d.ts.map +1 -0
  117. package/dist/parser/errors.js +4 -0
  118. package/dist/parser/errors.js.map +1 -0
  119. package/dist/parser/generic-parser.d.ts +13 -11
  120. package/dist/parser/generic-parser.d.ts.map +1 -1
  121. package/dist/parser/generic-parser.js +21 -24
  122. package/dist/parser/generic-parser.js.map +1 -1
  123. package/dist/utils.js +1 -1
  124. package/dist/utils.js.map +1 -1
  125. package/package.json +1 -1
  126. package/src/compiler/compile.ts +1 -1
  127. package/src/compiler/compiler.ts +10 -9
  128. package/src/compiler/format.ts +1 -1
  129. package/src/decompiler/decompile.ts +30 -14
  130. package/src/decompiler/emit.ts +57 -25
  131. package/src/decompiler/extract.ts +30 -89
  132. package/src/decompiler/format.ts +3 -14
  133. package/src/decompiler/readme.md +2 -2
  134. package/src/errors.ts +13 -7
  135. package/src/magic/.template.ts +8 -0
  136. package/src/magic/expr/index.ts +6 -7
  137. package/src/magic/expr/latex.ts +8 -4
  138. package/src/magic/expr/text.ts +8 -4
  139. package/src/magic/global/dark.ts +29 -0
  140. package/src/magic/global/desmos.ts +35 -5
  141. package/src/magic/global/index.ts +8 -14
  142. package/src/magic/global/viewport.ts +29 -0
  143. package/src/magic/incantation.ts +28 -6
  144. package/src/magic/local/anim.ts +16 -3
  145. package/src/magic/local/colour.ts +18 -6
  146. package/src/magic/local/dashed.ts +16 -2
  147. package/src/magic/local/fill.ts +20 -3
  148. package/src/magic/local/hide.ts +16 -2
  149. package/src/magic/local/index.ts +24 -25
  150. package/src/magic/local/label.ts +31 -8
  151. package/src/magic/local/line.ts +25 -3
  152. package/src/magic/local/no-line.ts +16 -2
  153. package/src/magic/local/point.ts +27 -3
  154. package/src/magic/local/secret.ts +16 -2
  155. package/src/magic/local/slider.ts +18 -3
  156. package/src/parser/ast.ts +10 -7
  157. package/src/parser/desmost-parser.ts +25 -21
  158. package/src/parser/errors.ts +10 -0
  159. package/src/parser/generic-parser.ts +23 -25
  160. package/src/utils.ts +1 -1
  161. package/svelte/desmost.svelte +107 -107
  162. package/dist/magic/expr/index.d.ts +0 -3
  163. package/dist/magic/expr/index.d.ts.map +0 -1
  164. package/dist/magic/global/dark-mode.d.ts.map +0 -1
  165. package/dist/magic/global/dark-mode.js +0 -9
  166. package/dist/magic/global/dark-mode.js.map +0 -1
  167. package/src/magic/global/dark-mode.ts +0 -15
@@ -1,18 +1,12 @@
1
- export { DesmosIncantation } from "./desmos";
2
- export { ViewportIncantation } from "./viewport";
3
- export { DarkModeIncantation } from "./dark-mode";
4
-
5
-
6
1
  import { Incantation, type GLOBAL } from "../incantation";
7
2
 
8
- import { DesmosIncantation } from "./desmos";
9
- import { ViewportIncantation } from "./viewport";
10
- import { DarkModeIncantation } from "./dark-mode";
3
+ import { desmos } from "./desmos";
4
+ import { viewport } from "./viewport";
5
+ import { dark } from "./dark";
11
6
 
12
7
 
13
- export const GLOBAL_INCANTATIONS: Incantation<GLOBAL>[] =
14
- [
15
- new DesmosIncantation(),
16
- new ViewportIncantation(),
17
- new DarkModeIncantation(),
18
- ];
8
+ export const GLOBAL_INCANTATIONS = {
9
+ desmos,
10
+ viewport,
11
+ dark,
12
+ } satisfies Record<string, Incantation<GLOBAL>>;
@@ -2,6 +2,7 @@ import { Incantation, ArgIncantation, type GLOBAL } from "../incantation";
2
2
 
3
3
  import { DesmostError, type Fallible } from "../../errors";
4
4
  import type { DesmostOptions } from "../../options";
5
+ import { Ast } from "../../parser";
5
6
 
6
7
 
7
8
  interface ViewportBounds
@@ -63,4 +64,32 @@ export class ViewportIncantation extends ArgIncantation<GLOBAL>
63
64
 
64
65
  return out;
65
66
  }
67
+
68
+ override extract(
69
+ target: Desmos.Calculator,
70
+ blank: Desmos.Calculator,
71
+ ): Ast.IncantationInvocation<Incantation.Effect.GLOBAL> | void
72
+ {
73
+ let { left, right, bottom, top } = target.graphpaperBounds.mathCoordinates;
74
+ let bounds = { left, right, bottom, top };
75
+
76
+ let defaults = blank.graphpaperBounds.mathCoordinates;
77
+
78
+ for (let [key, val] of Object.entries(bounds)) {
79
+ if (Math.abs(val - defaults[key]) < 0.001) {
80
+ delete bounds[key];
81
+ }
82
+ }
83
+
84
+ let arg_raw = super.emit_object_arg(bounds);
85
+ if (arg_raw.trim() === "") return;
86
+
87
+ return {
88
+ kind: Ast.Kind.INCANTATION_INVOCATION,
89
+ incantation: viewport,
90
+ arg_raw,
91
+ };
92
+ }
66
93
  }
94
+
95
+ export const viewport = new ViewportIncantation();
@@ -2,6 +2,7 @@ import Json5 from "json5";
2
2
  import dedent from "dedent";
3
3
 
4
4
  import type { DesmostOptions } from "../options";
5
+ import type { Ast } from "../parser";
5
6
  import { DesmostError, type Fallible } from "../errors";
6
7
 
7
8
 
@@ -18,12 +19,10 @@ import { DesmostError, type Fallible } from "../errors";
18
19
  *
19
20
  * Incantations that accept an argument derive from `ArgIncantation`.
20
21
  */
21
- export abstract class Incantation<
22
- Effect extends Incantation.Effect = Incantation.Effect
23
- >
22
+ export abstract class Incantation<Effect extends Incantation.Effect = Incantation.Effect>
24
23
  {
25
- /** Short user-facing description of what the incantation does. */
26
- abstract readonly description: string
24
+ /** Whether the incantation is a global, local or expression incantation. */
25
+ abstract readonly effect: Effect
27
26
 
28
27
  /** The raw text sequence that matches this incantation, such as `viewport` or `hidden`. */
29
28
  abstract readonly identifier: string
@@ -31,6 +30,9 @@ export abstract class Incantation<
31
30
  /** An alternative `.identifier`, strictly for localisation purposes only. */
32
31
  readonly alias?: string
33
32
 
33
+ /** Short user-facing description of what the incantation does. */
34
+ abstract readonly description: string
35
+
34
36
 
35
37
  /** Apply this incantation's effect to `target`, using the provided `data` if required. */
36
38
  abstract apply(
@@ -49,10 +51,20 @@ export abstract class Incantation<
49
51
  let req = required === "expression" ? "latex" : required;
50
52
 
51
53
  throw new DesmostError.IllegalIncantation({
52
- msg: `/${this.identifier} can only applied to ${req} blocks, but target block has type: ${actual}`,
54
+ msg: `/${this.identifier} can only applied to \`${req}\` blocks, but target block has type: \`${actual}\``,
53
55
  });
54
56
  }
55
57
  }
58
+
59
+ /**
60
+ * Extract the AST representation of this incantation from `target`.
61
+ *
62
+ * (The opposite of {@linkcode apply()}.)
63
+ */
64
+ abstract extract(
65
+ target: Effect extends GLOBAL ? Desmos.Calculator : Desmos.ExpressionState,
66
+ blank?: Effect extends GLOBAL ? Desmos.Calculator : never,
67
+ ): Ast.IncantationInvocation<Effect> | void
56
68
  }
57
69
 
58
70
 
@@ -133,6 +145,16 @@ export abstract class ArgIncantation<
133
145
  }
134
146
  }
135
147
  }
148
+
149
+ /**
150
+ * Stringify an object argument to its raw source text.
151
+ */
152
+ protected emit_object_arg(data: object): string
153
+ {
154
+ let defined = Object.fromEntries(Object.entries(data).filter((k, v) => Boolean(v)));
155
+
156
+ return Json5.stringify(defined).slice(1, -1);
157
+ }
136
158
  }
137
159
 
138
160
 
@@ -1,16 +1,29 @@
1
1
  import { Incantation, type LOCAL } from "../incantation";
2
+ import { Ast } from "../../parser";
2
3
 
3
4
 
4
5
  export class AnimIncantation extends Incantation<LOCAL>
5
6
  {
6
- override readonly description
7
- = "Animate the slider of a block."
8
-
7
+ override readonly effect = Incantation.Effect.LOCAL
9
8
  override readonly identifier = "anim"
9
+ override readonly description
10
+ = `Animate the slider of a block.`
10
11
 
11
12
  override apply(target: Desmos.ExpressionState)
12
13
  {
13
14
  super.require_expr_type(target.type, "expression");
14
15
  target.playing = true;
15
16
  }
17
+
18
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
19
+ {
20
+ if (target.playing) {
21
+ return {
22
+ kind: Ast.Kind.INCANTATION_INVOCATION,
23
+ incantation: anim,
24
+ };
25
+ }
26
+ }
16
27
  }
28
+
29
+ export const anim = new AnimIncantation();
@@ -1,7 +1,8 @@
1
1
  import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
2
2
 
3
- import { DesmostError } from "../../errors";
4
3
  import type { DesmostOptions } from "../../options";
4
+ import { DesmostError } from "../../errors";
5
+ import { Ast } from "../../parser";
5
6
 
6
7
 
7
8
  type DesmosColourName = keyof typeof Desmos.Colors;
@@ -12,13 +13,13 @@ const VALID_COLOURS = ["RED", "BLUE", "GREEN", "PURPLE", "ORANGE", "BLACK"];
12
13
 
13
14
  export class ColourIncantation extends ArgIncantation<LOCAL>
14
15
  {
15
- override readonly description
16
- = "Change the colour of a rendered expression, such as a line, region, polygon, etc."
17
-
18
- override readonly identifier = "color"
19
- override readonly alias = "colour"
16
+ override readonly effect = Incantation.Effect.LOCAL
17
+ override readonly identifier = "colour"
18
+ override readonly alias = "color"
20
19
  override readonly requires_arg = true
21
20
  override readonly arg_type = Incantation.ArgType.ENUM
21
+ override readonly description
22
+ = "Change the colour of a rendered expression, such as a line, region, polygon, etc."
22
23
 
23
24
  override apply(target: Desmos.ExpressionState, data: DesmosColour)
24
25
  {
@@ -46,4 +47,15 @@ export class ColourIncantation extends ArgIncantation<LOCAL>
46
47
  return internal;
47
48
  }
48
49
  }
50
+
51
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL>
52
+ {
53
+ return {
54
+ kind: Ast.Kind.INCANTATION_INVOCATION,
55
+ incantation: colour,
56
+ arg_raw: target.color, // FIXME use name
57
+ };
58
+ }
49
59
  }
60
+
61
+ export const colour = new ColourIncantation();
@@ -1,16 +1,30 @@
1
1
  import { Incantation, type LOCAL } from "../incantation";
2
2
 
3
+ import { Ast } from "../../parser";
4
+
3
5
 
4
6
  export class DashedIncantation extends Incantation<LOCAL>
5
7
  {
8
+ override readonly effect = Incantation.Effect.LOCAL
9
+ override readonly identifier = "dashed"
6
10
  override readonly description
7
11
  = "Render a block as a dashed line."
8
-
9
- override readonly identifier = "dashed"
10
12
 
11
13
  override apply(target: Desmos.ExpressionState)
12
14
  {
13
15
  super.require_expr_type(target.type, "expression");
14
16
  target.lineStyle = Desmos.Styles.DASHED;
15
17
  }
18
+
19
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
20
+ {
21
+ if (target.lineStyle === Desmos.Styles.DASHED) {
22
+ return {
23
+ kind: Ast.Kind.INCANTATION_INVOCATION,
24
+ incantation: dashed,
25
+ };
26
+ }
27
+ }
16
28
  }
29
+
30
+ export const dashed = new DashedIncantation();
@@ -1,5 +1,7 @@
1
1
  import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
2
2
 
3
+ import { Ast } from "../../parser";
4
+
3
5
 
4
6
  interface FillOptions
5
7
  {
@@ -9,16 +11,31 @@ interface FillOptions
9
11
 
10
12
  export class FillIncantation extends ArgIncantation<LOCAL>
11
13
  {
12
- override readonly description
13
- = "Change fill styles for a rendered block."
14
-
14
+ override readonly effect = Incantation.Effect.LOCAL
15
15
  override readonly identifier = "fill"
16
16
  override readonly requires_arg = true
17
17
  override readonly arg_type = Incantation.ArgType.OBJECT
18
+ override readonly description
19
+ = "Change fill styles for a rendered block."
18
20
 
19
21
  override apply(target: Desmos.ExpressionState, data: FillOptions)
20
22
  {
21
23
  super.require_expr_type(target.type, "expression");
22
24
  target.fillOpacity = data.opacity;
23
25
  }
26
+
27
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
28
+ {
29
+ if (target.fillOpacity) {
30
+ return {
31
+ kind: Ast.Kind.INCANTATION_INVOCATION,
32
+ incantation: fill,
33
+ arg_raw: super.emit_object_arg({
34
+ opacity: target.fillOpacity,
35
+ }),
36
+ };
37
+ }
38
+ }
24
39
  }
40
+
41
+ export const fill = new FillIncantation();
@@ -1,16 +1,30 @@
1
1
  import { Incantation, type LOCAL } from "../incantation";
2
2
 
3
+ import { Ast } from "../../parser";
4
+
3
5
 
4
6
  export class HideIncantation extends Incantation<LOCAL>
5
7
  {
8
+ override readonly effect = Incantation.Effect.LOCAL
9
+ override readonly identifier = "hide"
6
10
  override readonly description
7
11
  = "Hide rendering for a block. This includes graphs, points, polygons, etc."
8
-
9
- override readonly identifier = "hide"
10
12
 
11
13
  apply(target: Desmos.ExpressionState)
12
14
  {
13
15
  super.require_expr_type(target.type, "expression");
14
16
  target.hidden = true;
15
17
  }
18
+
19
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
20
+ {
21
+ if (target.hidden) {
22
+ return {
23
+ kind: Ast.Kind.INCANTATION_INVOCATION,
24
+ incantation: hide,
25
+ };
26
+ }
27
+ }
16
28
  }
29
+
30
+ export const hide = new HideIncantation();
@@ -1,29 +1,28 @@
1
1
  import { Incantation, type LOCAL } from "../incantation";
2
- import { AnimIncantation } from "./anim";
3
2
 
4
- import { ColourIncantation } from "./colour";
5
- import { DashedIncantation } from "./dashed";
6
- import { FillIncantation } from "./fill";
7
- import { HideIncantation } from "./hide";
8
- import { LabelIncantation } from "./label";
9
- import { LineIncantation } from "./line";
10
- import { NoLineIncantation } from "./no-line";
11
- import { PointIncantation } from "./point";
12
- import { SecretIncantation } from "./secret";
13
- import { SliderIncantation } from "./slider";
3
+ import { anim } from "./anim";
4
+ import { colour } from "./colour";
5
+ import { dashed } from "./dashed";
6
+ import { fill } from "./fill";
7
+ import { hide } from "./hide";
8
+ import { label } from "./label";
9
+ import { line } from "./line";
10
+ import { no_line } from "./no-line";
11
+ import { point } from "./point";
12
+ import { secret } from "./secret";
13
+ import { slider } from "./slider";
14
14
 
15
15
 
16
- export const LOCAL_INCANTATIONS: Incantation<LOCAL>[] =
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(),
29
- ];
16
+ export const LOCAL_INCANTATIONS = {
17
+ anim,
18
+ colour,
19
+ dashed,
20
+ fill,
21
+ hide,
22
+ label,
23
+ line,
24
+ no_line,
25
+ point,
26
+ secret,
27
+ slider,
28
+ } satisfies Record<string, Incantation<LOCAL>>;
@@ -1,20 +1,25 @@
1
1
  import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
2
2
 
3
- import { DesmostError } from "../../errors";
4
3
  import type { DesmostOptions } from "../../options";
4
+ import { DesmostError } from "../../errors";
5
+ import { Ast } from "../../parser";
5
6
 
6
7
 
7
8
  interface LabelOptions
8
9
  {
9
- text: string;
10
- show?: boolean;
11
- size?: number;
12
- pos?: "ABOVE" | "BELOW" | "LEFT" | "RIGHT" | "ABOVE_LEFT" | "ABOVE_RIGHT" | "BELOW_LEFT" | "BELOW_RIGHT";
10
+ text: string
11
+ show?: boolean
12
+ size?: number
13
+ pos?:
14
+ | "DEFAULT"
15
+ | "ABOVE" | "BELOW" | "LEFT" | "RIGHT"
16
+ | "ABOVE_LEFT" | "ABOVE_RIGHT" | "BELOW_LEFT" | "BELOW_RIGHT"
13
17
  }
14
18
 
15
19
  const VALID_FIELDS = ["text", "show", "size", "pos"];
16
20
 
17
21
  const VALID_POSITIONS = [
22
+ "DEFAULT",
18
23
  "ABOVE", "BELOW", "LEFT", "RIGHT",
19
24
  "ABOVE_LEFT", "ABOVE_RIGHT", "BELOW_LEFT", "BELOW_RIGHT",
20
25
  ];
@@ -22,12 +27,12 @@ const VALID_POSITIONS = [
22
27
 
23
28
  export class LabelIncantation extends ArgIncantation<LOCAL>
24
29
  {
25
- override readonly description
26
- = "Label a block that evaluates to a point(s)."
27
-
30
+ override readonly effect = Incantation.Effect.LOCAL
28
31
  override readonly identifier = "label"
29
32
  override readonly requires_arg = true
30
33
  override readonly arg_type = Incantation.ArgType.OBJECT
34
+ override readonly description
35
+ = "Label a block that evaluates to a point(s)."
31
36
 
32
37
  override apply(target: Desmos.ExpressionState, data: LabelOptions)
33
38
  {
@@ -84,4 +89,22 @@ export class LabelIncantation extends ArgIncantation<LOCAL>
84
89
 
85
90
  return out;
86
91
  }
92
+
93
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
94
+ {
95
+ if (target.label || target.showLabel) {
96
+ return {
97
+ kind: Ast.Kind.INCANTATION_INVOCATION,
98
+ incantation: label,
99
+ arg_raw: super.emit_object_arg({
100
+ text: target.label,
101
+ show: target.showLabel,
102
+ size: target.labelSize,
103
+ pos: target.labelOrientation,
104
+ }),
105
+ };
106
+ }
107
+ }
87
108
  }
109
+
110
+ export const label = new LabelIncantation();
@@ -2,6 +2,7 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
2
2
 
3
3
  import type { DesmostOptions } from "../../options";
4
4
  import type { Fallible } from "../../errors";
5
+ import { Ast } from "../../parser";
5
6
 
6
7
 
7
8
  interface LineOptions
@@ -16,12 +17,12 @@ const VALID_FIELDS = ["style", "width", "opacity"];
16
17
 
17
18
  export class LineIncantation extends ArgIncantation<LOCAL>
18
19
  {
19
- override readonly description
20
- = "Change line styles for a rendered block."
21
-
20
+ override readonly effect = Incantation.Effect.LOCAL
22
21
  override readonly identifier = "line"
23
22
  override readonly requires_arg = true
24
23
  override readonly arg_type = Incantation.ArgType.OBJECT
24
+ override readonly description
25
+ = "Change line styles for a rendered block."
25
26
 
26
27
  override apply(target: Desmos.ExpressionState, data: LineOptions)
27
28
  {
@@ -43,4 +44,25 @@ export class LineIncantation extends ArgIncantation<LOCAL>
43
44
 
44
45
  return out;
45
46
  }
47
+
48
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
49
+ {
50
+ if (
51
+ target.lineStyle !== Desmos.Styles.SOLID
52
+ || target.lineWidth
53
+ || target.lineOpacity
54
+ ) {
55
+ return {
56
+ kind: Ast.Kind.INCANTATION_INVOCATION,
57
+ incantation: line,
58
+ arg_raw: super.emit_object_arg({
59
+ style: target.lineStyle,
60
+ width: target.lineWidth,
61
+ opacity: target.lineOpacity,
62
+ }),
63
+ };
64
+ }
65
+ }
46
66
  }
67
+
68
+ export const line = new LineIncantation();
@@ -1,16 +1,30 @@
1
1
  import { Incantation, type LOCAL } from "../incantation";
2
2
 
3
+ import { Ast } from "../../parser";
4
+
3
5
 
4
6
  export class NoLineIncantation extends Incantation<LOCAL>
5
7
  {
8
+ override readonly effect = Incantation.Effect.LOCAL
9
+ override readonly identifier = "no-line"
6
10
  override readonly description
7
11
  = "Disable rendering lines for a block."
8
-
9
- override readonly identifier = "no-line"
10
12
 
11
13
  override apply(target: Desmos.ExpressionState)
12
14
  {
13
15
  super.require_expr_type(target.type, "expression");
14
16
  target.lines = false;
15
17
  }
18
+
19
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
20
+ {
21
+ if (target.lines === false) {
22
+ return {
23
+ kind: Ast.Kind.INCANTATION_INVOCATION,
24
+ incantation: no_line,
25
+ };
26
+ }
27
+ }
16
28
  }
29
+
30
+ export const no_line = new NoLineIncantation();
@@ -1,5 +1,7 @@
1
1
  import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
2
2
 
3
+ import { Ast } from "../../parser";
4
+
3
5
 
4
6
  interface PointStyles
5
7
  {
@@ -11,12 +13,12 @@ interface PointStyles
11
13
 
12
14
  export class PointIncantation extends ArgIncantation<LOCAL>
13
15
  {
14
- override readonly description
15
- = ""
16
-
16
+ override readonly effect = Incantation.Effect.LOCAL
17
17
  override readonly identifier = "point"
18
18
  override readonly requires_arg = true
19
19
  override readonly arg_type = Incantation.ArgType.OBJECT
20
+ override readonly description
21
+ = ""
20
22
 
21
23
  override apply(target: Desmos.ExpressionState, data: Partial<PointStyles>)
22
24
  {
@@ -26,4 +28,26 @@ export class PointIncantation extends ArgIncantation<LOCAL>
26
28
  if (data.size != undefined) target.pointSize = data.size;
27
29
  if (data.opacity != undefined) target.pointOpacity = data.opacity;
28
30
  }
31
+
32
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
33
+ {
34
+ if (
35
+ target.pointStyle && target.pointStyle !== Desmos.Styles.POINT
36
+ || target.pointSize
37
+ || target.pointOpacity
38
+ )
39
+ {
40
+ return {
41
+ kind: Ast.Kind.INCANTATION_INVOCATION,
42
+ incantation: point,
43
+ arg_raw: super.emit_object_arg({
44
+ style: target.pointStyle,
45
+ size: target.pointSize,
46
+ opacity: target.pointOpacity,
47
+ }),
48
+ };
49
+ }
50
+ }
29
51
  }
52
+
53
+ export const point = new PointIncantation();
@@ -1,16 +1,30 @@
1
1
  import { Incantation, type LOCAL } from "../incantation";
2
2
 
3
+ import { Ast } from "../../parser";
4
+
3
5
 
4
6
  export class SecretIncantation extends Incantation<LOCAL>
5
7
  {
8
+ override readonly effect = Incantation.Effect.LOCAL
9
+ override readonly identifier = "secret"
6
10
  override readonly description
7
11
  = "Turn a block into a secret expression, which is hidden from the end user."
8
-
9
- override readonly identifier = "secret"
10
12
 
11
13
  override apply(target: Desmos.ExpressionState)
12
14
  {
13
15
  super.require_expr_type(target.type, "expression");
14
16
  target.secret = true;
15
17
  }
18
+
19
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
20
+ {
21
+ if (target.secret) {
22
+ return {
23
+ kind: Ast.Kind.INCANTATION_INVOCATION,
24
+ incantation: secret,
25
+ };
26
+ }
27
+ }
16
28
  }
29
+
30
+ export const secret = new SecretIncantation();
@@ -1,5 +1,7 @@
1
1
  import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
2
2
 
3
+ import { Ast } from "../../parser";
4
+
3
5
 
4
6
  interface SliderBounds
5
7
  {
@@ -11,16 +13,29 @@ interface SliderBounds
11
13
 
12
14
  export class SliderIncantation extends ArgIncantation<LOCAL>
13
15
  {
14
- override readonly description
15
- = "Set the bounds of the slider for a variable."
16
-
16
+ override readonly effect = Incantation.Effect.LOCAL
17
17
  override readonly identifier = "slider"
18
18
  override readonly requires_arg = true
19
19
  override readonly arg_type = Incantation.ArgType.OBJECT
20
+ override readonly description
21
+ = "Set the bounds of the slider for a variable."
20
22
 
21
23
  override apply(target: Desmos.ExpressionState, data: SliderBounds)
22
24
  {
23
25
  super.require_expr_type(target.type, "expression");
24
26
  target.sliderBounds = data;
25
27
  }
28
+
29
+ override extract(target: Desmos.Expression): Ast.IncantationInvocation<LOCAL> | void
30
+ {
31
+ if (target.sliderBounds != undefined) {
32
+ return {
33
+ kind: Ast.Kind.INCANTATION_INVOCATION,
34
+ incantation: slider,
35
+ arg_raw: super.emit_object_arg(target.sliderBounds),
36
+ };
37
+ }
38
+ }
26
39
  }
40
+
41
+ export const slider = new SliderIncantation();