desmost 0.5.1 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "desmost",
3
3
  "author": "Sup#2.0",
4
- "version": "0.5.1",
4
+ "version": "0.5.3",
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,98 @@
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
+ When this component is unmounted, it calls `.destroy()` on each calculator instance to cleanup resources.
8
+
9
+ ## Example
10
+
11
+ ```svelte
12
+ <script>
13
+ import Content from "./content.svx";
14
+ </script>
15
+
16
+ <Desmost>
17
+ <Content />
18
+ </Desmost>
19
+ ```
20
+
21
+ With compile options:
22
+
23
+ ```svelte
24
+ <Desmost errors="crash">
25
+ <Content />
26
+ </Desmost>
27
+ ```
28
+
29
+ With styling:
30
+
31
+ ```svelte
32
+ <Desmost width="100%" height="50vh">
33
+ <Content />
34
+ </Desmost>
35
+ ```
36
+ -->
37
+
38
+ <script lang="ts">
39
+ /// <reference types="desmos" />
40
+
41
+ import { compile, type DesmostOptions } from "../src";
42
+
43
+ import { onMount, type Snippet } from "svelte";
44
+
45
+
46
+ interface Props extends DesmostOptions
47
+ {
48
+ children: Snippet;
49
+
50
+ /** CSS styles to apply to each Desmos calculator's containing element. */
51
+ style?: string;
52
+
53
+ /** Width of each Desmos calculator's containing element. */
54
+ width?: string;
55
+
56
+ /** Height of each Desmos calculator's containing element. */
57
+ height?: string;
58
+ }
59
+
60
+ let { children, style, width, height, ...options }: Props = $props();
61
+
62
+
63
+ let root: HTMLElement;
64
+
65
+ let desmos_instances: Desmos.Calculator[] = [];
66
+
67
+ onMount(() =>
68
+ {
69
+ let sources = root.querySelectorAll("pre[lang='desmos'], pre.language-desmos");
70
+
71
+ for (let source of sources.values()) {
72
+ source.style.display = "none";
73
+ if (style != undefined) source.cssText = style;
74
+
75
+ let el_desmos = source.parentNode!.insertBefore(
76
+ document.createElement("div"),
77
+ source.nextSibling,
78
+ );
79
+
80
+ let desmos = Desmos.GraphingCalculator(el_desmos);
81
+ desmos_instances.push(desmos);
82
+
83
+ compile(desmos, source.textContent, options);
84
+ }
85
+
86
+ return () => {
87
+ for (let instance of desmos_instances) {
88
+ instance.destroy();
89
+ }
90
+ };
91
+ });
92
+
93
+ </script>
94
+
95
+
96
+ <div bind:this={root} style:display="contents">
97
+ {@render children?.()}
98
+ </div>