desmost 0.5.5 → 0.6.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/dist/index.internal.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.internal.d.ts","sourceRoot":"","sources":["../src/index.internal.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.internal.d.ts","sourceRoot":"","sources":["../src/index.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.internal.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.internal.js","sourceRoot":"","sources":["../src/index.internal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.internal.js","sourceRoot":"","sources":["../src/index.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "desmost",
|
|
3
3
|
"author": "Sup#2.0",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
|
|
7
7
|
"description": "A tiny DSL for compiling LaTeX to Desmos",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
{
|
|
70
70
|
"@types/desmos": "1.11",
|
|
71
71
|
"@types/node": "^26.0",
|
|
72
|
+
"jsdom": "^30.0",
|
|
72
73
|
"oxlint": "^1.78",
|
|
73
74
|
"oxlint-tsgolint": "^7.0",
|
|
74
75
|
"tsc-alias": "^1.9",
|
package/src/index.internal.ts
CHANGED
package/svelte/desmost.svelte
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
<!-- @component `<Desmost>`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Mass-compile Desmost.
|
|
4
4
|
|
|
5
5
|
This transforms `<pre lang="desmos">` blocks into Desmos calculator embeds. It selects each `<pre lang="desmos">` block in its children, and for each constructs a `Desmos.GraphingCalculator` instance then calls the Desmost compiler on the source.
|
|
6
6
|
|
|
7
|
+
This is intended to be used with MDsveX or similar, where Markdown content containing ` ```desmos ` blocks is compiled into HTML.
|
|
8
|
+
|
|
7
9
|
When this component is unmounted, it calls `.destroy()` on each calculator instance to cleanup resources.
|
|
8
10
|
|
|
9
11
|
## Example
|
|
10
12
|
|
|
11
13
|
```svelte
|
|
12
14
|
<script>
|
|
13
|
-
|
|
15
|
+
import Content from "./content.md";
|
|
14
16
|
</script>
|
|
15
17
|
|
|
16
18
|
<Desmost>
|
|
17
|
-
|
|
19
|
+
<Content />
|
|
18
20
|
</Desmost>
|
|
19
21
|
```
|
|
20
22
|
|
|
21
23
|
With compile options:
|
|
22
24
|
|
|
23
25
|
```svelte
|
|
24
|
-
<Desmost errors
|
|
25
|
-
|
|
26
|
+
<Desmost options={{ errors: "crash" }}>
|
|
27
|
+
<Content />
|
|
26
28
|
</Desmost>
|
|
27
29
|
```
|
|
28
30
|
|
|
@@ -30,7 +32,7 @@ With styling:
|
|
|
30
32
|
|
|
31
33
|
```svelte
|
|
32
34
|
<Desmost width="100%" height="50vh">
|
|
33
|
-
|
|
35
|
+
<Content />
|
|
34
36
|
</Desmost>
|
|
35
37
|
```
|
|
36
38
|
-->
|
|
@@ -43,26 +45,81 @@ import { compile, type DesmostOptions } from "../src";
|
|
|
43
45
|
import { onMount, type Snippet } from "svelte";
|
|
44
46
|
|
|
45
47
|
|
|
46
|
-
interface Props
|
|
48
|
+
interface Props
|
|
47
49
|
{
|
|
48
50
|
children: Snippet;
|
|
49
51
|
|
|
50
|
-
/**
|
|
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
|
+
*/
|
|
51
82
|
style?: string;
|
|
52
83
|
|
|
53
|
-
/**
|
|
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
|
+
*/
|
|
54
95
|
width?: string;
|
|
55
96
|
|
|
56
|
-
/**
|
|
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
|
+
*/
|
|
57
108
|
height?: string;
|
|
58
109
|
}
|
|
59
110
|
|
|
60
|
-
let {
|
|
111
|
+
let {
|
|
112
|
+
children,
|
|
113
|
+
options, settings,
|
|
114
|
+
lazy,
|
|
115
|
+
style, width, height,
|
|
116
|
+
}: Props = $props();
|
|
61
117
|
|
|
62
118
|
|
|
63
119
|
let root: HTMLElement;
|
|
64
120
|
|
|
65
121
|
let desmos_instances: Desmos.Calculator[] = [];
|
|
122
|
+
let lazy_observers: IntersectionObserver[] = [];
|
|
66
123
|
|
|
67
124
|
onMount(() =>
|
|
68
125
|
{
|
|
@@ -80,10 +137,16 @@ onMount(() =>
|
|
|
80
137
|
if (height != undefined) el_desmos.style.height = height;
|
|
81
138
|
if (style != undefined) el_desmos.style.cssText += style;
|
|
82
139
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
140
|
+
if (!lazy) {
|
|
141
|
+
inject(el_desmos, source.textContent);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
let observer = new IntersectionObserver(
|
|
145
|
+
_ => inject(el_desmos, source.textContent)
|
|
146
|
+
);
|
|
147
|
+
observer.observe(el_desmos);
|
|
148
|
+
lazy_observers.push(observer);
|
|
149
|
+
}
|
|
87
150
|
}
|
|
88
151
|
|
|
89
152
|
return () => {
|
|
@@ -93,6 +156,18 @@ onMount(() =>
|
|
|
93
156
|
};
|
|
94
157
|
});
|
|
95
158
|
|
|
159
|
+
function inject(el_desmos: HTMLElement, source: string)
|
|
160
|
+
{
|
|
161
|
+
let desmos = Desmos.GraphingCalculator(el_desmos);
|
|
162
|
+
|
|
163
|
+
if (settings != undefined) {
|
|
164
|
+
desmos.updateSettings(settings);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
desmos_instances.push(desmos);
|
|
168
|
+
compile(desmos, source, options);
|
|
169
|
+
}
|
|
170
|
+
|
|
96
171
|
</script>
|
|
97
172
|
|
|
98
173
|
|