desmost 0.5.1 → 0.5.2
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/package.json +2 -1
- package/svelte/desmost.svelte +61 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "desmost",
|
|
3
3
|
"author": "Sup#2.0",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
|
|
7
7
|
"description": "A tiny DSL for compiling LaTeX to Desmos",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"./src/",
|
|
24
24
|
"./dist/",
|
|
25
|
+
"./svelte/",
|
|
25
26
|
"package.json",
|
|
26
27
|
"LICENCE",
|
|
27
28
|
"README.md"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<!-- @component `<Desmost>`
|
|
2
|
+
|
|
3
|
+
Compile Desmost from Markdown.
|
|
4
|
+
|
|
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
|
+
-->
|
|
7
|
+
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
/// <reference types="desmos" />
|
|
10
|
+
|
|
11
|
+
import { compile, DesmostOptions } from "../src";
|
|
12
|
+
|
|
13
|
+
import { onMount } from "svelte";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
interface Props extends DesmostOptions
|
|
17
|
+
{
|
|
18
|
+
children: unknown; // FIXME
|
|
19
|
+
style: string;
|
|
20
|
+
width: string;
|
|
21
|
+
height: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let { children, style, width, height, ...options }: Props = $props();
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const root: HTMLElement;
|
|
28
|
+
|
|
29
|
+
let desmos_instances: Desmos.Calculator[] = [];
|
|
30
|
+
|
|
31
|
+
onMount(() =>
|
|
32
|
+
{
|
|
33
|
+
let sources = root.querySelectorAll("pre[lang='desmos'], pre.language-desmos");
|
|
34
|
+
|
|
35
|
+
for (let source of sources.values()) {
|
|
36
|
+
source.style.display = "none";
|
|
37
|
+
|
|
38
|
+
let el_desmos = source.parentNode!.insertBefore(
|
|
39
|
+
document.createElement("div"),
|
|
40
|
+
source.nextSibling,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
let desmos = Desmos.GraphingCalculator(el_desmos);
|
|
44
|
+
desmos_instances.push(desmos);
|
|
45
|
+
|
|
46
|
+
compile(desmos, source.textContent, options);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return () => {
|
|
50
|
+
for (let instance of desmos_instances) {
|
|
51
|
+
instance.destroy();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
<div bind:this={root}>
|
|
60
|
+
{@render children?.()}
|
|
61
|
+
</div>
|