desmost 0.7.3 → 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 (131) 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 +1 -11
  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.map +1 -1
  58. package/dist/magic/global/viewport.js +0 -1
  59. package/dist/magic/global/viewport.js.map +1 -1
  60. package/dist/magic/incantation.d.ts.map +1 -1
  61. package/dist/magic/incantation.js.map +1 -1
  62. package/dist/magic/local/anim.d.ts.map +1 -1
  63. package/dist/magic/local/anim.js.map +1 -1
  64. package/dist/magic/local/colour.d.ts.map +1 -1
  65. package/dist/magic/local/colour.js.map +1 -1
  66. package/dist/magic/local/dashed.d.ts.map +1 -1
  67. package/dist/magic/local/dashed.js.map +1 -1
  68. package/dist/magic/local/fill.d.ts.map +1 -1
  69. package/dist/magic/local/fill.js.map +1 -1
  70. package/dist/magic/local/hide.d.ts.map +1 -1
  71. package/dist/magic/local/hide.js.map +1 -1
  72. package/dist/magic/local/index.js.map +1 -1
  73. package/dist/magic/local/label.d.ts.map +1 -1
  74. package/dist/magic/local/label.js.map +1 -1
  75. package/dist/magic/local/line.d.ts.map +1 -1
  76. package/dist/magic/local/line.js.map +1 -1
  77. package/dist/magic/local/no-line.d.ts.map +1 -1
  78. package/dist/magic/local/no-line.js.map +1 -1
  79. package/dist/magic/local/point.d.ts.map +1 -1
  80. package/dist/magic/local/point.js.map +1 -1
  81. package/dist/magic/local/secret.d.ts.map +1 -1
  82. package/dist/magic/local/secret.js.map +1 -1
  83. package/dist/magic/local/slider.d.ts.map +1 -1
  84. package/dist/magic/local/slider.js.map +1 -1
  85. package/dist/parser/ast.d.ts.map +1 -1
  86. package/dist/parser/ast.js.map +1 -1
  87. package/dist/parser/desmost-parser.d.ts.map +1 -1
  88. package/dist/parser/desmost-parser.js +1 -1
  89. package/dist/parser/desmost-parser.js.map +1 -1
  90. package/dist/parser/generic-parser.d.ts.map +1 -1
  91. package/dist/parser/generic-parser.js.map +1 -1
  92. package/dist/utils.d.ts.map +1 -1
  93. package/dist/utils.js.map +1 -1
  94. package/package.json +1 -1
  95. package/src/compiler/compile.ts +124 -124
  96. package/src/compiler/evaluate.ts +86 -118
  97. package/src/compiler/format.ts +39 -6
  98. package/src/compiler/options.ts +78 -75
  99. package/src/decompiler/decompile.ts +48 -0
  100. package/src/decompiler/emit.ts +47 -0
  101. package/src/decompiler/extract.ts +100 -0
  102. package/src/decompiler/format.ts +20 -0
  103. package/src/decompiler/index.ts +1 -0
  104. package/src/desmos.ts +6 -6
  105. package/src/errors.ts +12 -12
  106. package/src/index.internal.ts +2 -0
  107. package/src/index.ts +1 -0
  108. package/src/magic/expr/index.ts +2 -2
  109. package/src/magic/expr/latex.ts +16 -16
  110. package/src/magic/expr/text.ts +13 -13
  111. package/src/magic/global/dark-mode.ts +10 -10
  112. package/src/magic/global/desmos.ts +15 -15
  113. package/src/magic/global/index.ts +8 -3
  114. package/src/magic/global/viewport.ts +19 -20
  115. package/src/magic/incantation.ts +94 -94
  116. package/src/magic/local/anim.ts +10 -10
  117. package/src/magic/local/colour.ts +26 -26
  118. package/src/magic/local/dashed.ts +9 -9
  119. package/src/magic/local/fill.ts +12 -12
  120. package/src/magic/local/hide.ts +9 -9
  121. package/src/magic/local/index.ts +11 -11
  122. package/src/magic/local/label.ts +51 -51
  123. package/src/magic/local/line.ts +16 -16
  124. package/src/magic/local/no-line.ts +9 -9
  125. package/src/magic/local/point.ts +16 -16
  126. package/src/magic/local/secret.ts +9 -9
  127. package/src/magic/local/slider.ts +15 -15
  128. package/src/parser/ast.ts +45 -45
  129. package/src/parser/desmost-parser.ts +550 -550
  130. package/src/parser/generic-parser.ts +176 -176
  131. package/src/utils.ts +33 -33
@@ -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
  }
@@ -3,27 +3,27 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
3
3
 
4
4
  interface LineOptions
5
5
  {
6
- style?: keyof typeof Desmos.Styles; // TODO allow raw enum
7
- width?: number;
8
- opacity?: number;
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
- override readonly description
15
- = "Change line styles for a rendered block."
14
+ override readonly description
15
+ = "Change line styles for a rendered block."
16
16
 
17
- override readonly identifier = "line"
18
- override readonly requires_arg = true
19
- override readonly arg_type = Incantation.ArgType.OBJECT
17
+ override readonly identifier = "line"
18
+ override readonly requires_arg = true
19
+ override readonly arg_type = Incantation.ArgType.OBJECT
20
20
 
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
- }
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
- override readonly description
7
- = "Disable rendering lines for a block."
8
-
9
- override readonly identifier = "no-line"
6
+ override readonly description
7
+ = "Disable rendering lines for a block."
8
+
9
+ override readonly identifier = "no-line"
10
10
 
11
- override apply(target: Desmos.ExpressionState)
12
- {
13
- super.require_expr_type(target.type, "expression");
14
- target.lines = false;
15
- }
11
+ override apply(target: Desmos.ExpressionState)
12
+ {
13
+ super.require_expr_type(target.type, "expression");
14
+ target.lines = false;
15
+ }
16
16
  }
@@ -3,27 +3,27 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
3
3
 
4
4
  interface PointStyles
5
5
  {
6
- style?: keyof typeof Desmos.Styles;
7
- size?: number;
8
- opacity?: number;
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
- override readonly description
15
- = ""
16
-
17
- override readonly identifier = "point"
18
- override readonly requires_arg = true
19
- override readonly arg_type = Incantation.ArgType.OBJECT
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
- override apply(target: Desmos.ExpressionState, data: Partial<PointStyles>)
22
- {
23
- super.require_expr_type(target.type, "expression");
21
+ override apply(target: Desmos.ExpressionState, data: Partial<PointStyles>)
22
+ {
23
+ super.require_expr_type(target.type, "expression");
24
24
 
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
- }
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
- override readonly description
7
- = "Turn a block into a secret expression, which is hidden from the end user."
8
-
9
- override readonly identifier = "secret"
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
- override apply(target: Desmos.ExpressionState)
12
- {
13
- super.require_expr_type(target.type, "expression");
14
- target.secret = true;
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
- min?: number | string;
7
- max?: number | string;
8
- step?: number | string;
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
- 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
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
- 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
- }
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
  }
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
- /** What kind of parse result this is. */
8
- export enum Kind
9
- {
10
- EXPRESSION = "Expression",
11
- INCANTATION_INVOCATION = "Incantation-Invocation",
12
- INVALID_INCANTATION = "Invalid-Incantation",
13
- }
7
+ /** What kind of parse result 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
- /** 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
- }
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
- /** 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
- };
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
- * 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: false` configured).
45
- */
46
- export interface InvalidInvocation
47
- {
48
- kind: Kind.INVALID_INCANTATION
49
- incantation: Incantation
50
- arg_raw?: string
51
- error: UnrecoverableError
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: false` 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
55
  /** An abstract object produced by parsing a block of source code. */
56
56
  export type Ast =
57
- | Ast.Expression
58
- | Ast.IncantationInvocation
59
- | Ast.InvalidInvocation
57
+ | Ast.Expression
58
+ | Ast.IncantationInvocation
59
+ | Ast.InvalidInvocation
60
60
  ;