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.
- package/README.md +6 -6
- package/dist/compiler/compile.d.ts +1 -1
- package/dist/compiler/compile.js +1 -1
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compiler.js +9 -8
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/format.js +1 -1
- package/dist/compiler/format.js.map +1 -1
- package/dist/decompiler/decompile.d.ts +13 -5
- package/dist/decompiler/decompile.d.ts.map +1 -1
- package/dist/decompiler/decompile.js +24 -13
- package/dist/decompiler/decompile.js.map +1 -1
- package/dist/decompiler/emit.d.ts +5 -2
- package/dist/decompiler/emit.d.ts.map +1 -1
- package/dist/decompiler/emit.js +41 -20
- package/dist/decompiler/emit.js.map +1 -1
- package/dist/decompiler/extract.d.ts +1 -9
- package/dist/decompiler/extract.d.ts.map +1 -1
- package/dist/decompiler/extract.js +24 -58
- package/dist/decompiler/extract.js.map +1 -1
- package/dist/decompiler/format.d.ts +0 -1
- package/dist/decompiler/format.d.ts.map +1 -1
- package/dist/decompiler/format.js +3 -9
- package/dist/decompiler/format.js.map +1 -1
- package/dist/errors.d.ts +14 -7
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +20 -2
- package/dist/errors.js.map +1 -1
- package/dist/magic/expr/index.js +6 -6
- package/dist/magic/expr/index.js.map +1 -1
- package/dist/magic/expr/latex.d.ts +5 -2
- package/dist/magic/expr/latex.d.ts.map +1 -1
- package/dist/magic/expr/latex.js +4 -2
- package/dist/magic/expr/latex.js.map +1 -1
- package/dist/magic/expr/text.d.ts +5 -2
- package/dist/magic/expr/text.d.ts.map +1 -1
- package/dist/magic/expr/text.js +4 -2
- package/dist/magic/expr/text.js.map +1 -1
- package/dist/magic/global/{dark-mode.d.ts → dark.d.ts} +6 -2
- package/dist/magic/global/dark.d.ts.map +1 -0
- package/dist/magic/global/dark.js +20 -0
- package/dist/magic/global/dark.js.map +1 -0
- package/dist/magic/global/desmos.d.ts +4 -1
- package/dist/magic/global/desmos.d.ts.map +1 -1
- package/dist/magic/global/desmos.js +23 -0
- package/dist/magic/global/desmos.js.map +1 -1
- package/dist/magic/global/index.d.ts +5 -5
- package/dist/magic/global/index.d.ts.map +1 -1
- package/dist/magic/global/index.js +8 -11
- package/dist/magic/global/index.js.map +1 -1
- package/dist/magic/global/viewport.d.ts +3 -0
- package/dist/magic/global/viewport.d.ts.map +1 -1
- package/dist/magic/global/viewport.js +20 -0
- package/dist/magic/global/viewport.js.map +1 -1
- package/dist/magic/incantation.d.ts +15 -2
- package/dist/magic/incantation.d.ts.map +1 -1
- package/dist/magic/incantation.js +8 -1
- package/dist/magic/incantation.js.map +1 -1
- package/dist/magic/local/anim.d.ts +5 -1
- package/dist/magic/local/anim.d.ts.map +1 -1
- package/dist/magic/local/anim.js +12 -1
- package/dist/magic/local/anim.js.map +1 -1
- package/dist/magic/local/colour.d.ts +7 -3
- package/dist/magic/local/colour.d.ts.map +1 -1
- package/dist/magic/local/colour.js +13 -3
- package/dist/magic/local/colour.js.map +1 -1
- package/dist/magic/local/dashed.d.ts +5 -1
- package/dist/magic/local/dashed.d.ts.map +1 -1
- package/dist/magic/local/dashed.js +12 -1
- package/dist/magic/local/dashed.js.map +1 -1
- package/dist/magic/local/fill.d.ts +5 -1
- package/dist/magic/local/fill.d.ts.map +1 -1
- package/dist/magic/local/fill.js +15 -1
- package/dist/magic/local/fill.js.map +1 -1
- package/dist/magic/local/hide.d.ts +5 -1
- package/dist/magic/local/hide.d.ts.map +1 -1
- package/dist/magic/local/hide.js +12 -1
- package/dist/magic/local/hide.js.map +1 -1
- package/dist/magic/local/index.d.ts +13 -2
- package/dist/magic/local/index.d.ts.map +1 -1
- package/dist/magic/local/index.js +24 -24
- package/dist/magic/local/index.js.map +1 -1
- package/dist/magic/local/label.d.ts +6 -2
- package/dist/magic/local/label.d.ts.map +1 -1
- package/dist/magic/local/label.js +19 -1
- package/dist/magic/local/label.js.map +1 -1
- package/dist/magic/local/line.d.ts +5 -1
- package/dist/magic/local/line.d.ts.map +1 -1
- package/dist/magic/local/line.js +19 -1
- package/dist/magic/local/line.js.map +1 -1
- package/dist/magic/local/no-line.d.ts +5 -1
- package/dist/magic/local/no-line.d.ts.map +1 -1
- package/dist/magic/local/no-line.js +12 -1
- package/dist/magic/local/no-line.js.map +1 -1
- package/dist/magic/local/point.d.ts +5 -1
- package/dist/magic/local/point.d.ts.map +1 -1
- package/dist/magic/local/point.js +19 -1
- package/dist/magic/local/point.js.map +1 -1
- package/dist/magic/local/secret.d.ts +5 -1
- package/dist/magic/local/secret.d.ts.map +1 -1
- package/dist/magic/local/secret.js +12 -1
- package/dist/magic/local/secret.js.map +1 -1
- package/dist/magic/local/slider.d.ts +5 -1
- package/dist/magic/local/slider.d.ts.map +1 -1
- package/dist/magic/local/slider.js +13 -1
- package/dist/magic/local/slider.js.map +1 -1
- package/dist/parser/ast.d.ts +9 -3
- package/dist/parser/ast.d.ts.map +1 -1
- package/dist/parser/ast.js +3 -1
- package/dist/parser/ast.js.map +1 -1
- package/dist/parser/desmost-parser.d.ts +2 -2
- package/dist/parser/desmost-parser.d.ts.map +1 -1
- package/dist/parser/desmost-parser.js +21 -19
- package/dist/parser/desmost-parser.js.map +1 -1
- package/dist/parser/errors.d.ts +11 -0
- package/dist/parser/errors.d.ts.map +1 -0
- package/dist/parser/errors.js +4 -0
- package/dist/parser/errors.js.map +1 -0
- package/dist/parser/generic-parser.d.ts +13 -11
- package/dist/parser/generic-parser.d.ts.map +1 -1
- package/dist/parser/generic-parser.js +21 -24
- package/dist/parser/generic-parser.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/compiler/compile.ts +1 -1
- package/src/compiler/compiler.ts +10 -9
- package/src/compiler/format.ts +1 -1
- package/src/decompiler/decompile.ts +30 -14
- package/src/decompiler/emit.ts +57 -25
- package/src/decompiler/extract.ts +30 -89
- package/src/decompiler/format.ts +3 -14
- package/src/decompiler/readme.md +2 -2
- package/src/errors.ts +13 -7
- package/src/magic/.template.ts +8 -0
- package/src/magic/expr/index.ts +6 -7
- package/src/magic/expr/latex.ts +8 -4
- package/src/magic/expr/text.ts +8 -4
- package/src/magic/global/dark.ts +29 -0
- package/src/magic/global/desmos.ts +35 -5
- package/src/magic/global/index.ts +8 -14
- package/src/magic/global/viewport.ts +29 -0
- package/src/magic/incantation.ts +28 -6
- package/src/magic/local/anim.ts +16 -3
- package/src/magic/local/colour.ts +18 -6
- package/src/magic/local/dashed.ts +16 -2
- package/src/magic/local/fill.ts +20 -3
- package/src/magic/local/hide.ts +16 -2
- package/src/magic/local/index.ts +24 -25
- package/src/magic/local/label.ts +31 -8
- package/src/magic/local/line.ts +25 -3
- package/src/magic/local/no-line.ts +16 -2
- package/src/magic/local/point.ts +27 -3
- package/src/magic/local/secret.ts +16 -2
- package/src/magic/local/slider.ts +18 -3
- package/src/parser/ast.ts +10 -7
- package/src/parser/desmost-parser.ts +25 -21
- package/src/parser/errors.ts +10 -0
- package/src/parser/generic-parser.ts +23 -25
- package/src/utils.ts +1 -1
- package/svelte/desmost.svelte +107 -107
- package/dist/magic/expr/index.d.ts +0 -3
- package/dist/magic/expr/index.d.ts.map +0 -1
- package/dist/magic/global/dark-mode.d.ts.map +0 -1
- package/dist/magic/global/dark-mode.js +0 -9
- package/dist/magic/global/dark-mode.js.map +0 -1
- package/src/magic/global/dark-mode.ts +0 -15
package/src/parser/ast.ts
CHANGED
|
@@ -3,15 +3,17 @@ import { Incantation, ArgIncantation } from "../magic";
|
|
|
3
3
|
|
|
4
4
|
export namespace Ast
|
|
5
5
|
{
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/**
|
|
7
|
+
* What kind of AST node this is.
|
|
8
|
+
*/
|
|
9
|
+
export enum Kind {
|
|
9
10
|
EXPRESSION = "Expression",
|
|
10
11
|
INCANTATION_INVOCATION = "Incantation-Invocation",
|
|
11
12
|
}
|
|
12
|
-
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* A Desmos expression to add to the calculator.
|
|
16
|
+
*/
|
|
15
17
|
export interface Expression
|
|
16
18
|
{
|
|
17
19
|
kind: Kind.EXPRESSION
|
|
@@ -19,8 +21,9 @@ export namespace Ast
|
|
|
19
21
|
incantations: IncantationInvocation<Incantation.Effect.LOCAL>[]
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* A pending incantation invocation that requires applying its argument (if any), then applying its effect.
|
|
26
|
+
*/
|
|
24
27
|
export type IncantationInvocation<Effect extends Incantation.Effect = Incantation.Effect> =
|
|
25
28
|
| {
|
|
26
29
|
kind: Kind.INCANTATION_INVOCATION
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { GenericParser } from "./generic-parser";
|
|
2
2
|
import { Ast } from "./ast";
|
|
3
|
+
import { NO_MATCH, INVALID_PARSE } from "./errors";
|
|
4
|
+
import type { NoMatch, InvalidParse } from "./errors";
|
|
3
5
|
|
|
4
6
|
import type { DesmostOptions } from "../options";
|
|
5
|
-
import {
|
|
6
|
-
import type { NoMatch, Fallible } from "../errors";
|
|
7
|
+
import { DesmostError, type Fallible } from "../errors";
|
|
7
8
|
import * as utils from "../utils";
|
|
8
9
|
|
|
9
10
|
import {
|
|
@@ -49,7 +50,7 @@ export class DesmostParser extends GenericParser
|
|
|
49
50
|
{
|
|
50
51
|
this.errors = [];
|
|
51
52
|
|
|
52
|
-
this.
|
|
53
|
+
this.eat_whitespace();
|
|
53
54
|
|
|
54
55
|
if (this.out_of_bounds()) {
|
|
55
56
|
return undefined;
|
|
@@ -97,7 +98,7 @@ export class DesmostParser extends GenericParser
|
|
|
97
98
|
blocks.push(this.parse_post_sep());
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
this.
|
|
101
|
+
this.eat_end_of_block();
|
|
101
102
|
|
|
102
103
|
return { blocks, errors: this.errors };
|
|
103
104
|
}
|
|
@@ -116,10 +117,10 @@ export class DesmostParser extends GenericParser
|
|
|
116
117
|
{
|
|
117
118
|
// 1 global incantation
|
|
118
119
|
try {
|
|
119
|
-
let r = this.try_parse_incantation(GLOBAL_INCANTATIONS);
|
|
120
|
+
let r = this.try_parse_incantation(Object.values(GLOBAL_INCANTATIONS));
|
|
120
121
|
|
|
121
122
|
if (r !== NO_MATCH) {
|
|
122
|
-
this.
|
|
123
|
+
this.eat_whitespace();
|
|
123
124
|
return { global: r };
|
|
124
125
|
}
|
|
125
126
|
}
|
|
@@ -133,7 +134,7 @@ export class DesmostParser extends GenericParser
|
|
|
133
134
|
|
|
134
135
|
while (this.current === "/") {
|
|
135
136
|
try {
|
|
136
|
-
var invocation = this.try_parse_incantation(LOCAL_INCANTATIONS);
|
|
137
|
+
var invocation = this.try_parse_incantation(Object.values(LOCAL_INCANTATIONS));
|
|
137
138
|
}
|
|
138
139
|
catch (e) {
|
|
139
140
|
this.errors.push(e as Error);
|
|
@@ -142,7 +143,7 @@ export class DesmostParser extends GenericParser
|
|
|
142
143
|
|
|
143
144
|
if (invocation === NO_MATCH) break;
|
|
144
145
|
incantations.push(invocation);
|
|
145
|
-
this.
|
|
146
|
+
this.eat_newlines();
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
return { locals: incantations };
|
|
@@ -153,10 +154,10 @@ export class DesmostParser extends GenericParser
|
|
|
153
154
|
*/
|
|
154
155
|
parse_sep(): Fallible<void>
|
|
155
156
|
{
|
|
156
|
-
this.
|
|
157
|
+
this.eat_newlines();
|
|
157
158
|
|
|
158
159
|
try {
|
|
159
|
-
this.
|
|
160
|
+
this.eat("::", {
|
|
160
161
|
msg: `Expected \`::\` separator between local incantations and expression, but found: \`${this.preview()}\``,
|
|
161
162
|
hint: `Use \`/incantation :: ${this.preview()}\``,
|
|
162
163
|
});
|
|
@@ -181,10 +182,10 @@ export class DesmostParser extends GenericParser
|
|
|
181
182
|
}
|
|
182
183
|
}));
|
|
183
184
|
|
|
184
|
-
this.
|
|
185
|
+
this.eat("::");
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
this.
|
|
188
|
+
this.eat_newlines();
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
/**
|
|
@@ -195,7 +196,7 @@ export class DesmostParser extends GenericParser
|
|
|
195
196
|
*/
|
|
196
197
|
parse_post_sep(): Fallible<Ast.Expression>
|
|
197
198
|
{
|
|
198
|
-
this.
|
|
199
|
+
this.eat_whitespace();
|
|
199
200
|
|
|
200
201
|
switch (this.current) {
|
|
201
202
|
// empty block
|
|
@@ -260,9 +261,9 @@ export class DesmostParser extends GenericParser
|
|
|
260
261
|
{
|
|
261
262
|
let init = this.i;
|
|
262
263
|
|
|
263
|
-
if (this.
|
|
264
|
+
if (this.try_eat("/") === NO_MATCH) return NO_MATCH;
|
|
264
265
|
|
|
265
|
-
let ident = this.
|
|
266
|
+
let ident = this.try_eat_identifier();
|
|
266
267
|
if (ident === NO_MATCH) {
|
|
267
268
|
this.i = init;
|
|
268
269
|
return NO_MATCH;
|
|
@@ -302,22 +303,25 @@ export class DesmostParser extends GenericParser
|
|
|
302
303
|
{
|
|
303
304
|
let init = this.i;
|
|
304
305
|
|
|
305
|
-
if (this.
|
|
306
|
+
if (this.try_eat("/") === NO_MATCH) return NO_MATCH;
|
|
306
307
|
|
|
307
|
-
let ident = this.
|
|
308
|
+
let ident = this.try_eat_identifier();
|
|
308
309
|
if (ident === NO_MATCH) {
|
|
309
310
|
this.i = init;
|
|
310
311
|
return NO_MATCH;
|
|
311
312
|
}
|
|
312
313
|
|
|
313
|
-
let incantation =
|
|
314
|
+
let incantation =
|
|
315
|
+
Object.values(EXPR_INCANTATIONS)
|
|
316
|
+
.find(inc => inc.identifier === ident || inc.alias === ident);
|
|
317
|
+
|
|
314
318
|
if (incantation == undefined) {
|
|
315
319
|
this.i = init;
|
|
316
320
|
return NO_MATCH;
|
|
317
321
|
}
|
|
318
322
|
|
|
319
323
|
/* NOTE: All expression incantations currently require arguments, and all for the foreseeable future will too */
|
|
320
|
-
let arg_raw = this.parse_incantation_arg(
|
|
324
|
+
let arg_raw = this.parse_incantation_arg(incantation.arg_type);
|
|
321
325
|
|
|
322
326
|
let data = {};
|
|
323
327
|
incantation.apply(data, arg_raw);
|
|
@@ -398,7 +402,7 @@ export class DesmostParser extends GenericParser
|
|
|
398
402
|
{
|
|
399
403
|
let init = this.i;
|
|
400
404
|
|
|
401
|
-
this.
|
|
405
|
+
this.eat("{", {
|
|
402
406
|
msg: `Expected \`{\` to start incantation argument, but found: \`${this.preview()}\``
|
|
403
407
|
});
|
|
404
408
|
|
|
@@ -431,7 +435,7 @@ export class DesmostParser extends GenericParser
|
|
|
431
435
|
stack.push(Ctx.ENUM);
|
|
432
436
|
indices_to_insert_quotes.push(this.i);
|
|
433
437
|
}
|
|
434
|
-
else if (top === Ctx.ENUM && this.current?.match(/[^a-zA-Z]/)) {
|
|
438
|
+
else if (top === Ctx.ENUM && this.current?.match(/[^a-zA-Z-_]/)) {
|
|
435
439
|
stack.pop();
|
|
436
440
|
indices_to_insert_quotes.push(this.i);
|
|
437
441
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The parser failed to parse something (usually during speculative parsing), which only results in internal backtracking. */
|
|
2
|
+
export const NO_MATCH = Symbol("no-match");
|
|
3
|
+
|
|
4
|
+
/** The compiler encountered a non-fatal recoverable failure (usually during speculative parsing), which only results in internal backtracking. */
|
|
5
|
+
export type NoMatch = typeof NO_MATCH & { readonly __brand?: unique symbol };
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const INVALID_PARSE = Symbol("invalid-parse");
|
|
9
|
+
|
|
10
|
+
export type InvalidParse = typeof INVALID_PARSE & { readonly __brand?: unique symbol };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { NO_MATCH,
|
|
2
|
-
import type { NoMatch,
|
|
1
|
+
import { NO_MATCH, INVALID_PARSE } from "./errors";
|
|
2
|
+
import type { NoMatch, InvalidParse } from "./errors";
|
|
3
|
+
|
|
4
|
+
import { DesmostError, type Fallible } from "../errors";
|
|
3
5
|
|
|
4
6
|
|
|
5
7
|
const IGNORED_CHARACTERS = new Set([
|
|
@@ -111,15 +113,15 @@ export class GenericParser
|
|
|
111
113
|
this.i++;
|
|
112
114
|
|
|
113
115
|
// @ts-expect-error: `this.current == undefined` is a true negative
|
|
114
|
-
|
|
115
|
-
this.
|
|
116
|
+
while (IGNORED_CHARACTERS.has(this.current)) {
|
|
117
|
+
this.i++;
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
/**
|
|
120
122
|
* Consume `raw`, erroring if `raw` was not found.
|
|
121
123
|
*/
|
|
122
|
-
protected
|
|
124
|
+
protected eat(raw: string, error_data?: DesmostError.Data): Fallible<void>
|
|
123
125
|
{
|
|
124
126
|
if (this.out_of_bounds()) {
|
|
125
127
|
throw new DesmostError.UnexpectedEnd({
|
|
@@ -154,7 +156,7 @@ export class GenericParser
|
|
|
154
156
|
/**
|
|
155
157
|
* Attempt to consume `raw`, backtracking if `raw` was not found.
|
|
156
158
|
*/
|
|
157
|
-
protected
|
|
159
|
+
protected try_eat(raw: string): void | NoMatch
|
|
158
160
|
{
|
|
159
161
|
let init = this.i;
|
|
160
162
|
let ii = 0;
|
|
@@ -172,7 +174,7 @@ export class GenericParser
|
|
|
172
174
|
return NO_MATCH;
|
|
173
175
|
}
|
|
174
176
|
|
|
175
|
-
protected
|
|
177
|
+
protected try_eat_identifier(): string | NoMatch
|
|
176
178
|
{
|
|
177
179
|
let init = this.i;
|
|
178
180
|
|
|
@@ -189,44 +191,40 @@ export class GenericParser
|
|
|
189
191
|
}
|
|
190
192
|
|
|
191
193
|
/**
|
|
192
|
-
* Consume 0 or more space characters.
|
|
194
|
+
* Consume 0 or more space or tab characters (but not newlines).
|
|
195
|
+
*
|
|
196
|
+
* This is always safe to call, and will match 0 characters if the parser is out of bounds.
|
|
193
197
|
*/
|
|
194
|
-
protected
|
|
198
|
+
protected eat_whitespace(): void
|
|
195
199
|
{
|
|
196
|
-
|
|
197
|
-
if (this.out_of_bounds()) return;
|
|
198
|
-
|
|
199
|
-
while (this.current === " ") {
|
|
200
|
+
while (this.current === ' ' || this.current === '\t') {
|
|
200
201
|
this.advance();
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
|
|
204
205
|
/**
|
|
205
|
-
* Consume 0 or more whitespace characters.
|
|
206
|
+
* Consume 0 or more whitespace characters (including newlines).
|
|
206
207
|
*
|
|
207
|
-
*
|
|
208
|
+
* This is always safe to call, and will match 0 characters if the parser is out of bounds.
|
|
208
209
|
*/
|
|
209
|
-
protected
|
|
210
|
+
protected eat_newlines(): void
|
|
210
211
|
{
|
|
211
|
-
/* NOTE: Callers should be able to assume this is safe to call even when at end of input, since it should just match 0 characters */
|
|
212
|
-
if (this.i >= this.length) return;
|
|
213
|
-
|
|
214
212
|
while (
|
|
215
|
-
this.current ===
|
|
216
|
-
|| this.current ===
|
|
217
|
-
|| this.current ===
|
|
213
|
+
this.current === ' '
|
|
214
|
+
|| this.current === '\n'
|
|
215
|
+
|| this.current === '\t'
|
|
218
216
|
) {
|
|
219
217
|
this.advance();
|
|
220
218
|
}
|
|
221
219
|
}
|
|
222
220
|
|
|
223
|
-
protected
|
|
221
|
+
protected eat_end_of_block(error_data?: DesmostError.Data): Fallible<void>
|
|
224
222
|
{
|
|
225
223
|
if (this.i >= this.length) return;
|
|
226
224
|
|
|
227
|
-
this.
|
|
225
|
+
this.eat_whitespace();
|
|
228
226
|
|
|
229
|
-
this.
|
|
227
|
+
this.eat("\n", {
|
|
230
228
|
msg: `Expected a newline at the end of a block, but found: \`${this.preview()}\``,
|
|
231
229
|
...error_data
|
|
232
230
|
});
|
package/src/utils.ts
CHANGED
package/svelte/desmost.svelte
CHANGED
|
@@ -12,11 +12,11 @@ When this component is unmounted, it calls `.destroy()` on each calculator insta
|
|
|
12
12
|
|
|
13
13
|
```svelte
|
|
14
14
|
<script>
|
|
15
|
-
|
|
15
|
+
import Content from "./content.md";
|
|
16
16
|
</script>
|
|
17
17
|
|
|
18
18
|
<Desmost>
|
|
19
|
-
|
|
19
|
+
<Content />
|
|
20
20
|
</Desmost>
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -24,7 +24,7 @@ With compile options:
|
|
|
24
24
|
|
|
25
25
|
```svelte
|
|
26
26
|
<Desmost options={{ errors: "crash" }}>
|
|
27
|
-
|
|
27
|
+
<Content />
|
|
28
28
|
</Desmost>
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -32,7 +32,7 @@ With styling:
|
|
|
32
32
|
|
|
33
33
|
```svelte
|
|
34
34
|
<Desmost width="100%" height="50vh">
|
|
35
|
-
|
|
35
|
+
<Content />
|
|
36
36
|
</Desmost>
|
|
37
37
|
```
|
|
38
38
|
-->
|
|
@@ -47,72 +47,72 @@ import { onMount, type Snippet } from "svelte";
|
|
|
47
47
|
|
|
48
48
|
interface Props
|
|
49
49
|
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
50
|
+
children: Snippet;
|
|
51
|
+
|
|
52
|
+
/** Compile options to pass to Desmost.*/
|
|
53
|
+
options?: DesmostOptions;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Default settings to apply to all Desmos calculator instances.
|
|
57
|
+
*
|
|
58
|
+
* These are applied *before* compilation, so individual Desmost blocks can override them with `/desmos`.
|
|
59
|
+
*/
|
|
60
|
+
settings?: Desmos.GraphConfiguration & Desmos.GraphSettings;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Should compilation be lazy using `IntersectionObserver`?
|
|
64
|
+
*
|
|
65
|
+
* ## Example
|
|
66
|
+
*
|
|
67
|
+
* ```svelte
|
|
68
|
+
* <Desmost lazy />
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
lazy?: true;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* CSS styles to apply to each Desmos calculator's containing element.
|
|
75
|
+
*
|
|
76
|
+
* ## Example
|
|
77
|
+
*
|
|
78
|
+
* ```svelte
|
|
79
|
+
* <Desmost style="margin: 1rem; border: 1px solid red" />
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
style?: string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Width of each Desmos calculator's containing element.
|
|
86
|
+
*
|
|
87
|
+
* ## Example
|
|
88
|
+
*
|
|
89
|
+
* ```svelte
|
|
90
|
+
* <Desmost width="500px" />
|
|
91
|
+
* <Desmost width="40rem" />
|
|
92
|
+
* <Desmost width="80vw" />
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
width?: string;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Height of each Desmos calculator's containing element.
|
|
99
|
+
*
|
|
100
|
+
* ## Example
|
|
101
|
+
*
|
|
102
|
+
* ```svelte
|
|
103
|
+
* <Desmost height="500px" />
|
|
104
|
+
* <Desmost height="40rem" />
|
|
105
|
+
* <Desmost height="80vw" />
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
height?: string;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
let {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
children,
|
|
113
|
+
options, settings,
|
|
114
|
+
lazy,
|
|
115
|
+
style, width, height,
|
|
116
116
|
}: Props = $props();
|
|
117
117
|
|
|
118
118
|
|
|
@@ -123,56 +123,56 @@ let lazy_observers: IntersectionObserver[] = [];
|
|
|
123
123
|
|
|
124
124
|
onMount(() =>
|
|
125
125
|
{
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
126
|
+
let sources = root.querySelectorAll("pre[lang='desmos'], pre.language-desmos");
|
|
127
|
+
|
|
128
|
+
for (let source of sources.values()) {
|
|
129
|
+
source.style.display = "none";
|
|
130
|
+
|
|
131
|
+
let el_desmos = source.parentNode!.insertBefore(
|
|
132
|
+
document.createElement("div"),
|
|
133
|
+
source.nextSibling,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (width != undefined) el_desmos.style.width = width;
|
|
137
|
+
if (height != undefined) el_desmos.style.height = height;
|
|
138
|
+
if (style != undefined) el_desmos.style.cssText += style;
|
|
139
|
+
|
|
140
|
+
if (!lazy) {
|
|
141
|
+
inject(el_desmos, source.textContent);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
let observer = new IntersectionObserver(([entry]) => {
|
|
145
|
+
if (entry.isIntersecting) {
|
|
146
|
+
inject(el_desmos, source.textContent);
|
|
147
|
+
observer.disconnect();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
observer.observe(el_desmos);
|
|
151
|
+
lazy_observers.push(observer);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return () => {
|
|
156
|
+
desmos_instances.forEach(d => d.destroy());
|
|
157
|
+
lazy_observers.forEach(o => o.disconnect());
|
|
158
|
+
};
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
function inject(el_desmos: HTMLElement, source: string)
|
|
162
162
|
{
|
|
163
|
-
|
|
163
|
+
let desmos = Desmos.GraphingCalculator(el_desmos);
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
if (settings != undefined) {
|
|
166
|
+
desmos.updateSettings(settings);
|
|
167
|
+
}
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
desmos_instances.push(desmos);
|
|
170
|
+
compile(desmos, source, options);
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
</script>
|
|
174
174
|
|
|
175
175
|
|
|
176
176
|
<div bind:this={root} style:display="contents">
|
|
177
|
-
|
|
177
|
+
{@render children?.()}
|
|
178
178
|
</div>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/magic/expr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAM3D,eAAO,MAAM,iBAAiB,EAAE,cAAc,CAAC,IAAI,CAAC,EAInD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dark-mode.d.ts","sourceRoot":"","sources":["../../../src/magic/global/dark-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG1D,qBAAa,mBAAoB,SAAQ,WAAW,CAAC,MAAM,CAAC;IAE3D,SAAkB,WAAW,qEACuC;IAEpE,SAAkB,UAAU,UAAS;IAErC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU;CAI/B"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Incantation } from "../incantation.js";
|
|
2
|
-
export class DarkModeIncantation extends Incantation {
|
|
3
|
-
description = "Enable dark mode for the calculator, which inverts all colours.";
|
|
4
|
-
identifier = "dark";
|
|
5
|
-
apply(target) {
|
|
6
|
-
target.updateSettings({ invertedColors: true });
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=dark-mode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dark-mode.js","sourceRoot":"","sources":["../../../src/magic/global/dark-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,gBAAgB,CAAC;AAG1D,MAAM,OAAO,mBAAoB,SAAQ,WAAmB;IAEzC,WAAW,GAC1B,iEAAiE,CAAA;IAElD,UAAU,GAAG,MAAM,CAAA;IAErC,KAAK,CAAC,MAAyB;QAE9B,MAAM,CAAC,cAAc,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;CACD"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Incantation, type GLOBAL } from "../incantation";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export class DarkModeIncantation extends Incantation<GLOBAL>
|
|
5
|
-
{
|
|
6
|
-
override readonly description
|
|
7
|
-
= "Enable dark mode for the calculator, which inverts all colours."
|
|
8
|
-
|
|
9
|
-
override readonly identifier = "dark"
|
|
10
|
-
|
|
11
|
-
apply(target: Desmos.Calculator)
|
|
12
|
-
{
|
|
13
|
-
target.updateSettings({ invertedColors: true });
|
|
14
|
-
}
|
|
15
|
-
}
|