@hpcc-js/observablehq-compiler 1.1.1 → 1.1.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.
Files changed (52) hide show
  1. package/LICENSE +43 -0
  2. package/README.md +105 -105
  3. package/bin/ojscc.mjs +74 -74
  4. package/dist/index.esm.js +586 -562
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/index.esm.min.js +2 -2
  7. package/dist/index.esm.min.js.map +1 -1
  8. package/dist/index.js +6716 -6688
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.min.js +3 -3
  11. package/dist/index.min.js.map +1 -1
  12. package/package.json +5 -4
  13. package/src/__package__.ts +3 -3
  14. package/src/__tests__/File Attachments.ts +894 -894
  15. package/src/__tests__/Introduction to Imports.ts +748 -748
  16. package/src/__tests__/Observable TimeChart.ts +771 -771
  17. package/src/__tests__/index.ts +13 -13
  18. package/src/__tests__/node.ts +177 -177
  19. package/src/compiler.md +234 -234
  20. package/src/compiler.ts +279 -264
  21. package/src/cst.ts +172 -172
  22. package/src/index.css +459 -459
  23. package/src/index.ts +6 -7
  24. package/src/util.md +113 -113
  25. package/src/util.ts +163 -153
  26. package/src/writer.ts +80 -80
  27. package/types/__package__.d.ts +3 -3
  28. package/types/__tests__/File Attachments.d.ts +109 -109
  29. package/types/__tests__/Introduction to Imports.d.ts +119 -119
  30. package/types/__tests__/Observable TimeChart.d.ts +110 -110
  31. package/types/__tests__/index.d.ts +1 -1
  32. package/types/__tests__/node.d.ts +1 -1
  33. package/types/compiler.d.ts +90 -87
  34. package/types/compiler.d.ts.map +1 -1
  35. package/types/cst.d.ts +41 -41
  36. package/types/index.d.ts +4 -5
  37. package/types/index.d.ts.map +1 -1
  38. package/types/util.d.ts +28 -25
  39. package/types/util.d.ts.map +1 -1
  40. package/types/writer.d.ts +18 -18
  41. package/types-3.4/__package__.d.ts +4 -0
  42. package/types-3.4/__tests__/File Attachments.d.ts +110 -0
  43. package/types-3.4/__tests__/Introduction to Imports.d.ts +120 -0
  44. package/types-3.4/__tests__/Observable TimeChart.d.ts +111 -0
  45. package/types-3.4/__tests__/index.d.ts +2 -0
  46. package/types-3.4/__tests__/node.d.ts +2 -0
  47. package/types-3.4/compiler.d.ts +94 -0
  48. package/types-3.4/cst.d.ts +42 -0
  49. package/types-3.4/index.d.ts +5 -0
  50. package/types-3.4/util.d.ts +29 -0
  51. package/types-3.4/writer.d.ts +19 -0
  52. package/src/__tests__/tsconfig.json +0 -21
package/src/compiler.md CHANGED
@@ -1,234 +1,234 @@
1
- # Compiler
2
-
3
- Observable HQ Notebook Compiler and Interpreter
4
-
5
- ## Minimal JSON Notebook
6
-
7
- While the compiler supports and persists the entire Observable HQ Notebook (v3), it only needs a minimal subset to actually function:
8
-
9
- ```ts
10
- interface Notebook {
11
- files: File[];
12
- nodes: Node[];
13
- }
14
-
15
- interface Node {
16
- id: number | string;
17
- mode: "js" | "md";
18
- value: string;
19
- }
20
-
21
- interface File {
22
- name: string;
23
- url: string;
24
- mime_type?: string;
25
- }
26
- ```
27
-
28
- ---
29
-
30
- <a name="compile" href="#compile">#</a> **compile**(_notebook_) => Promise\<function\> · [<>](https://github.com/hpcc-systems/Visualization/blob/trunk/packages/observablehq/compiler/src/compiler.ts "Source")
31
-
32
- * _notebook_: JSON Notebook, see [utilities](./util) for examples on how to fetch or create a notebook.
33
- * _returns_: Returns a Promise to a "define" function that is compatible with the ["@observablehq/runtime"](https://github.com/observablehq/runtime) and ["@observablehq/inspector"](https://github.com/observablehq/inspector)
34
-
35
- ## Hello World Example
36
-
37
- First take a simple hello world notebook
38
-
39
- ```js
40
- const notebook = {
41
- files: [],
42
- nodes: [
43
- {
44
- id: 1,
45
- value: "md`# ${h} ${w}`",
46
- mode: "js"
47
- },
48
- {
49
- id: 2,
50
- value: "h = \"Hello\"",
51
- mode: "js"
52
- },
53
- {
54
- id: 3,
55
- value: "w = \"World\"",
56
- mode: "js"
57
- }
58
- ]
59
- }
60
- ```
61
-
62
- Then import the compiler and invoke it:
63
-
64
- ```js
65
- import { compile } from "@hpcc-js/observablehq-compiler";
66
-
67
- const compiledNotebook = await compile(notebook);
68
- ```
69
-
70
- To render it to a web page, simply follow the same steps as if you had downloaded a compiled version from ObservableHQ site:
71
-
72
- ```js
73
-
74
- import { Library, Runtime, Inspector } from "https://cdn.skypack.dev/@observablehq/runtime";
75
-
76
- const placeholder = document.getElementById("placeholder");
77
-
78
- const library = new Library();
79
- const runtime = new Runtime(library);
80
-
81
- compiledNotebook(runtime, name => {
82
- const div = document.createElement("div");
83
- placeholder.appendChild(div);
84
- return new Inspector(div);
85
- });
86
-
87
- ```
88
-
89
- Putting it all together:
90
-
91
- <ClientOnly>
92
- <hpcc-vitepress preview_height_ratio=0.4 style="width:100%;height:400px">
93
- <div id="placeholder" style="height:100%;overflow-y:scroll">
94
- </div>
95
- <script type="module">
96
- import { Library, Runtime, Inspector } from "https://cdn.skypack.dev/@observablehq/runtime";
97
- import { compile } from "@hpcc-js/observablehq-compiler";
98
-
99
- const placeholder = document.getElementById("placeholder");
100
-
101
- const notebook = {
102
- files: [],
103
- nodes: [
104
- {
105
- id: 1,
106
- value: "md`# ${h} ${w}`",
107
- mode: "js"
108
- },
109
- {
110
- id: 1,
111
- value: "h = \"Hello\"",
112
- mode: "js"
113
- },
114
- {
115
- id: 2,
116
- value: "w = \"World\"",
117
- mode: "js"
118
- }
119
- ]
120
- }
121
-
122
- const compiledNotebook = await compile(notebook);
123
-
124
- const library = new Library();
125
- const runtime = new Runtime(library);
126
- compiledNotebook(runtime, name => {
127
- const div = document.createElement("div");
128
- placeholder.appendChild(div);
129
- return new Inspector(div);
130
- });
131
- </script>
132
- </hpcc-vitepress>
133
- </ClientOnly>
134
-
135
- ---
136
-
137
- To output the generated code simply call `toString` on the compiled function:
138
-
139
- <ClientOnly>
140
- <hpcc-vitepress style="width:100%;height:600px">
141
- <hpcc-codemirror id="placeholder" mode="javascript" theme="dark" style="width:100%;height:100%">
142
- </hpcc-codemirror>
143
- <script type="module">
144
- import "@hpcc-js/wc-editor";
145
- import { compile } from "@hpcc-js/observablehq-compiler";
146
-
147
- const notebook = {
148
- files: [],
149
- nodes: [
150
- {
151
- id: 1,
152
- value: "md`# ${h} ${w}`",
153
- mode: "js"
154
- },
155
- {
156
- id: 1,
157
- value: "h = \"Hello\"",
158
- mode: "js"
159
- },
160
- {
161
- id: 2,
162
- value: "w = \"World\"",
163
- mode: "js"
164
- }
165
- ]
166
- }
167
-
168
- const compiledNotebook = await compile(notebook);
169
- const placeholder = document.getElementById("placeholder");
170
- placeholder.text = compiledNotebook.toString();
171
- </script>
172
- </hpcc-vitepress>
173
- </ClientOnly>
174
-
175
- ---
176
-
177
- ## MoreExamples
178
-
179
- * [@observablehq/plot](https://observablehq.com/@observablehq/plot)
180
-
181
- <ClientOnly>
182
- <hpcc-vitepress style="width:100%;height:600px">
183
- <div id="placeholder" style="height:400px;overflow-y:scroll">
184
- </div>
185
- <script type="module">
186
- import { Library, Runtime, Inspector } from "https://cdn.skypack.dev/@observablehq/runtime";
187
- import { download, compile } from "@hpcc-js/observablehq-compiler";
188
-
189
- const notebookUrl = "https://observablehq.com/@observablehq/plot";
190
- const placeholder = document.getElementById("placeholder");
191
-
192
- const notebook = await download(notebookUrl);
193
- const compiledNB = await compile(notebook);
194
-
195
- const library = new Library();
196
- const runtime = new Runtime(library);
197
- compiledNB(runtime, name => {
198
- const div = document.createElement("div");
199
- placeholder.appendChild(div);
200
- return new Inspector(div);
201
- });
202
- </script>
203
- </hpcc-vitepress>
204
- </ClientOnly>
205
-
206
- ---
207
-
208
- * [@mbostock/fullscreen-canvas](https://observablehq.com/@mbostock/fullscreen-canvas)
209
-
210
- <ClientOnly>
211
- <hpcc-vitepress style="width:100%;height:600px">
212
- <div id="placeholder" style="height:400px;overflow-y:scroll">
213
- </div>
214
- <script type="module">
215
- import { Library, Runtime, Inspector } from "https://cdn.skypack.dev/@observablehq/runtime";
216
- import { download, compile } from "@hpcc-js/observablehq-compiler";
217
-
218
- const notebookUrl = "https://observablehq.com/@mbostock/fullscreen-canvas";
219
- const placeholder = document.getElementById("placeholder");
220
-
221
- const notebook = await download(notebookUrl);
222
- const compiledNB = await compile(notebook);
223
-
224
- const library = new Library();
225
- const runtime = new Runtime(library);
226
- compiledNB(runtime, name => {
227
- const div = document.createElement("div");
228
- placeholder.appendChild(div);
229
- return new Inspector(div);
230
- });
231
- </script>
232
- </hpcc-vitepress>
233
- </ClientOnly>
234
-
1
+ # Compiler
2
+
3
+ Observable HQ Notebook Compiler and Interpreter
4
+
5
+ ## Minimal JSON Notebook
6
+
7
+ While the compiler supports and persists the entire Observable HQ Notebook (v3), it only needs a minimal subset to actually function:
8
+
9
+ ```ts
10
+ interface Notebook {
11
+ files: File[];
12
+ nodes: Node[];
13
+ }
14
+
15
+ interface Node {
16
+ id: number | string;
17
+ mode: "js" | "md";
18
+ value: string;
19
+ }
20
+
21
+ interface File {
22
+ name: string;
23
+ url: string;
24
+ mime_type?: string;
25
+ }
26
+ ```
27
+
28
+ ---
29
+
30
+ <a name="compile" href="#compile">#</a> **compile**(_notebook_) => Promise\<function\> · [<>](https://github.com/hpcc-systems/Visualization/blob/trunk/packages/observablehq/compiler/src/compiler.ts "Source")
31
+
32
+ * _notebook_: JSON Notebook, see [utilities](./util) for examples on how to fetch or create a notebook.
33
+ * _returns_: Returns a Promise to a "define" function that is compatible with the ["@observablehq/runtime"](https://github.com/observablehq/runtime) and ["@observablehq/inspector"](https://github.com/observablehq/inspector)
34
+
35
+ ## Hello World Example
36
+
37
+ First take a simple hello world notebook
38
+
39
+ ```js
40
+ const notebook = {
41
+ files: [],
42
+ nodes: [
43
+ {
44
+ id: 1,
45
+ value: "md`# ${h} ${w}`",
46
+ mode: "js"
47
+ },
48
+ {
49
+ id: 2,
50
+ value: "h = \"Hello\"",
51
+ mode: "js"
52
+ },
53
+ {
54
+ id: 3,
55
+ value: "w = \"World\"",
56
+ mode: "js"
57
+ }
58
+ ]
59
+ }
60
+ ```
61
+
62
+ Then import the compiler and invoke it:
63
+
64
+ ```js
65
+ import { compile } from "@hpcc-js/observablehq-compiler";
66
+
67
+ const compiledNotebook = await compile(notebook);
68
+ ```
69
+
70
+ To render it to a web page, simply follow the same steps as if you had downloaded a compiled version from ObservableHQ site:
71
+
72
+ ```js
73
+
74
+ import { Library, Runtime, Inspector } from "https://cdn.skypack.dev/@observablehq/runtime";
75
+
76
+ const placeholder = document.getElementById("placeholder");
77
+
78
+ const library = new Library();
79
+ const runtime = new Runtime(library);
80
+
81
+ compiledNotebook(runtime, name => {
82
+ const div = document.createElement("div");
83
+ placeholder.appendChild(div);
84
+ return new Inspector(div);
85
+ });
86
+
87
+ ```
88
+
89
+ Putting it all together:
90
+
91
+ <ClientOnly>
92
+ <hpcc-vitepress preview_height_ratio=0.4 style="width:100%;height:400px">
93
+ <div id="placeholder" style="height:100%;overflow-y:scroll">
94
+ </div>
95
+ <script type="module">
96
+ import { Library, Runtime, Inspector } from "https://cdn.skypack.dev/@observablehq/runtime";
97
+ import { compile } from "@hpcc-js/observablehq-compiler";
98
+
99
+ const placeholder = document.getElementById("placeholder");
100
+
101
+ const notebook = {
102
+ files: [],
103
+ nodes: [
104
+ {
105
+ id: 1,
106
+ value: "md`# ${h} ${w}`",
107
+ mode: "js"
108
+ },
109
+ {
110
+ id: 2,
111
+ value: "h = \"Hello\"",
112
+ mode: "js"
113
+ },
114
+ {
115
+ id: 3,
116
+ value: "w = \"World\"",
117
+ mode: "js"
118
+ }
119
+ ]
120
+ }
121
+
122
+ const compiledNotebook = await compile(notebook);
123
+
124
+ const library = new Library();
125
+ const runtime = new Runtime(library);
126
+ compiledNotebook(runtime, name => {
127
+ const div = document.createElement("div");
128
+ placeholder.appendChild(div);
129
+ return new Inspector(div);
130
+ });
131
+ </script>
132
+ </hpcc-vitepress>
133
+ </ClientOnly>
134
+
135
+ ---
136
+
137
+ To output the generated code simply call `toString` on the compiled function:
138
+
139
+ <ClientOnly>
140
+ <hpcc-vitepress style="width:100%;height:600px">
141
+ <hpcc-codemirror id="placeholder" mode="javascript" theme="dark" style="width:100%;height:100%">
142
+ </hpcc-codemirror>
143
+ <script type="module">
144
+ import "@hpcc-js/wc-editor";
145
+ import { compile } from "@hpcc-js/observablehq-compiler";
146
+
147
+ const notebook = {
148
+ files: [],
149
+ nodes: [
150
+ {
151
+ id: 1,
152
+ value: "md`# ${h} ${w}`",
153
+ mode: "js"
154
+ },
155
+ {
156
+ id: 2,
157
+ value: "h = \"Hello\"",
158
+ mode: "js"
159
+ },
160
+ {
161
+ id: 3,
162
+ value: "w = \"World\"",
163
+ mode: "js"
164
+ }
165
+ ]
166
+ }
167
+
168
+ const compiledNotebook = await compile(notebook);
169
+ const placeholder = document.getElementById("placeholder");
170
+ placeholder.text = compiledNotebook.toString();
171
+ </script>
172
+ </hpcc-vitepress>
173
+ </ClientOnly>
174
+
175
+ ---
176
+
177
+ ## MoreExamples
178
+
179
+ * [@observablehq/plot](https://observablehq.com/@observablehq/plot)
180
+
181
+ <ClientOnly>
182
+ <hpcc-vitepress style="width:100%;height:600px">
183
+ <div id="placeholder" style="height:400px;overflow-y:scroll">
184
+ </div>
185
+ <script type="module">
186
+ import { Library, Runtime, Inspector } from "https://cdn.skypack.dev/@observablehq/runtime";
187
+ import { download, compile } from "@hpcc-js/observablehq-compiler";
188
+
189
+ const notebookUrl = "https://observablehq.com/@observablehq/plot";
190
+ const placeholder = document.getElementById("placeholder");
191
+
192
+ const notebook = await download(notebookUrl);
193
+ const compiledNB = await compile(notebook);
194
+
195
+ const library = new Library();
196
+ const runtime = new Runtime(library);
197
+ compiledNB(runtime, name => {
198
+ const div = document.createElement("div");
199
+ placeholder.appendChild(div);
200
+ return new Inspector(div);
201
+ });
202
+ </script>
203
+ </hpcc-vitepress>
204
+ </ClientOnly>
205
+
206
+ ---
207
+
208
+ * [@mbostock/fullscreen-canvas](https://observablehq.com/@mbostock/fullscreen-canvas)
209
+
210
+ <ClientOnly>
211
+ <hpcc-vitepress style="width:100%;height:600px">
212
+ <div id="placeholder" style="height:400px;overflow-y:scroll">
213
+ </div>
214
+ <script type="module">
215
+ import { Library, Runtime, Inspector } from "https://cdn.skypack.dev/@observablehq/runtime";
216
+ import { download, compile } from "@hpcc-js/observablehq-compiler";
217
+
218
+ const notebookUrl = "https://observablehq.com/@mbostock/fullscreen-canvas";
219
+ const placeholder = document.getElementById("placeholder");
220
+
221
+ const notebook = await download(notebookUrl);
222
+ const compiledNB = await compile(notebook);
223
+
224
+ const library = new Library();
225
+ const runtime = new Runtime(library);
226
+ compiledNB(runtime, name => {
227
+ const div = document.createElement("div");
228
+ placeholder.appendChild(div);
229
+ return new Inspector(div);
230
+ });
231
+ </script>
232
+ </hpcc-vitepress>
233
+ </ClientOnly>
234
+