@observablehq/notebook-kit 1.0.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.
Files changed (182) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +7 -0
  3. package/dist/bin/build.d.ts +2 -0
  4. package/dist/bin/build.js +63 -0
  5. package/dist/bin/download.d.ts +2 -0
  6. package/dist/bin/download.js +49 -0
  7. package/dist/bin/notebooks.d.ts +2 -0
  8. package/dist/bin/notebooks.js +33 -0
  9. package/dist/bin/preview.d.ts +2 -0
  10. package/dist/bin/preview.js +48 -0
  11. package/dist/package.json +73 -0
  12. package/dist/src/index.d.ts +5 -0
  13. package/dist/src/index.js +5 -0
  14. package/dist/src/javascript/assignments.d.ts +2 -0
  15. package/dist/src/javascript/assignments.js +37 -0
  16. package/dist/src/javascript/assignments.test.d.ts +1 -0
  17. package/dist/src/javascript/assignments.test.js +33 -0
  18. package/dist/src/javascript/awaits.d.ts +2 -0
  19. package/dist/src/javascript/awaits.js +23 -0
  20. package/dist/src/javascript/awaits.test.d.ts +1 -0
  21. package/dist/src/javascript/awaits.test.js +22 -0
  22. package/dist/src/javascript/declarations.d.ts +2 -0
  23. package/dist/src/javascript/declarations.js +45 -0
  24. package/dist/src/javascript/files.d.ts +3 -0
  25. package/dist/src/javascript/files.js +18 -0
  26. package/dist/src/javascript/globals.d.ts +1 -0
  27. package/dist/src/javascript/globals.js +86 -0
  28. package/dist/src/javascript/imports/jsr.d.ts +2 -0
  29. package/dist/src/javascript/imports/jsr.js +6 -0
  30. package/dist/src/javascript/imports/npm.d.ts +2 -0
  31. package/dist/src/javascript/imports/npm.js +47 -0
  32. package/dist/src/javascript/imports/npm.test.d.ts +1 -0
  33. package/dist/src/javascript/imports/npm.test.js +32 -0
  34. package/dist/src/javascript/imports/observable.d.ts +8 -0
  35. package/dist/src/javascript/imports/observable.js +64 -0
  36. package/dist/src/javascript/imports/observable.test.d.ts +1 -0
  37. package/dist/src/javascript/imports/observable.test.js +13 -0
  38. package/dist/src/javascript/imports.d.ts +21 -0
  39. package/dist/src/javascript/imports.js +146 -0
  40. package/dist/src/javascript/observable.d.ts +2 -0
  41. package/dist/src/javascript/observable.js +72 -0
  42. package/dist/src/javascript/parse.d.ts +11 -0
  43. package/dist/src/javascript/parse.js +53 -0
  44. package/dist/src/javascript/references.d.ts +8 -0
  45. package/dist/src/javascript/references.js +129 -0
  46. package/dist/src/javascript/references.test.d.ts +1 -0
  47. package/dist/src/javascript/references.test.js +38 -0
  48. package/dist/src/javascript/sourcemap.d.ts +21 -0
  49. package/dist/src/javascript/sourcemap.js +143 -0
  50. package/dist/src/javascript/sourcemap.test.d.ts +1 -0
  51. package/dist/src/javascript/sourcemap.test.js +88 -0
  52. package/dist/src/javascript/strings.d.ts +8 -0
  53. package/dist/src/javascript/strings.js +42 -0
  54. package/dist/src/javascript/strings.test.d.ts +1 -0
  55. package/dist/src/javascript/strings.test.js +31 -0
  56. package/dist/src/javascript/syntaxError.d.ts +2 -0
  57. package/dist/src/javascript/syntaxError.js +5 -0
  58. package/dist/src/javascript/template.d.ts +3 -0
  59. package/dist/src/javascript/template.js +141 -0
  60. package/dist/src/javascript/template.test.d.ts +1 -0
  61. package/dist/src/javascript/template.test.js +32 -0
  62. package/dist/src/javascript/transpile.d.ts +25 -0
  63. package/dist/src/javascript/transpile.js +42 -0
  64. package/dist/src/javascript/transpile.test.d.ts +1 -0
  65. package/dist/src/javascript/transpile.test.js +29 -0
  66. package/dist/src/javascript/walk.d.ts +5 -0
  67. package/dist/src/javascript/walk.js +13 -0
  68. package/dist/src/lib/notebook.d.ts +35 -0
  69. package/dist/src/lib/notebook.js +19 -0
  70. package/dist/src/lib/notebook.test.d.ts +1 -0
  71. package/dist/src/lib/notebook.test.js +26 -0
  72. package/dist/src/lib/serialize.d.ts +5 -0
  73. package/dist/src/lib/serialize.js +97 -0
  74. package/dist/src/lib/serialize.test.d.ts +1 -0
  75. package/dist/src/lib/serialize.test.js +125 -0
  76. package/dist/src/lib/text.d.ts +1 -0
  77. package/dist/src/lib/text.js +3 -0
  78. package/dist/src/runtime/define.d.ts +28 -0
  79. package/dist/src/runtime/define.js +62 -0
  80. package/dist/src/runtime/display.d.ts +16 -0
  81. package/dist/src/runtime/display.js +60 -0
  82. package/dist/src/runtime/index.d.ts +11 -0
  83. package/dist/src/runtime/index.js +14 -0
  84. package/dist/src/runtime/inspect.d.ts +3 -0
  85. package/dist/src/runtime/inspect.js +43 -0
  86. package/dist/src/runtime/stdlib/assets.d.ts +4 -0
  87. package/dist/src/runtime/stdlib/assets.js +110 -0
  88. package/dist/src/runtime/stdlib/assets.test.d.ts +1 -0
  89. package/dist/src/runtime/stdlib/assets.test.js +78 -0
  90. package/dist/src/runtime/stdlib/dom/canvas.d.ts +1 -0
  91. package/dist/src/runtime/stdlib/dom/canvas.js +6 -0
  92. package/dist/src/runtime/stdlib/dom/context2d.d.ts +1 -0
  93. package/dist/src/runtime/stdlib/dom/context2d.js +9 -0
  94. package/dist/src/runtime/stdlib/dom/index.d.ts +5 -0
  95. package/dist/src/runtime/stdlib/dom/index.js +5 -0
  96. package/dist/src/runtime/stdlib/dom/svg.d.ts +1 -0
  97. package/dist/src/runtime/stdlib/dom/svg.js +7 -0
  98. package/dist/src/runtime/stdlib/dom/text.d.ts +1 -0
  99. package/dist/src/runtime/stdlib/dom/text.js +3 -0
  100. package/dist/src/runtime/stdlib/dom/uid.d.ts +8 -0
  101. package/dist/src/runtime/stdlib/dom/uid.js +25 -0
  102. package/dist/src/runtime/stdlib/dot.d.ts +2 -0
  103. package/dist/src/runtime/stdlib/dot.js +34 -0
  104. package/dist/src/runtime/stdlib/duckdb.d.ts +24 -0
  105. package/dist/src/runtime/stdlib/duckdb.js +379 -0
  106. package/dist/src/runtime/stdlib/fileAttachment.d.ts +71 -0
  107. package/dist/src/runtime/stdlib/fileAttachment.js +199 -0
  108. package/dist/src/runtime/stdlib/generators/index.d.ts +5 -0
  109. package/dist/src/runtime/stdlib/generators/index.js +5 -0
  110. package/dist/src/runtime/stdlib/generators/input.d.ts +1 -0
  111. package/dist/src/runtime/stdlib/generators/input.js +45 -0
  112. package/dist/src/runtime/stdlib/generators/now.d.ts +1 -0
  113. package/dist/src/runtime/stdlib/generators/now.js +5 -0
  114. package/dist/src/runtime/stdlib/generators/observe.d.ts +1 -0
  115. package/dist/src/runtime/stdlib/generators/observe.js +31 -0
  116. package/dist/src/runtime/stdlib/generators/queue.d.ts +1 -0
  117. package/dist/src/runtime/stdlib/generators/queue.js +27 -0
  118. package/dist/src/runtime/stdlib/generators/width.d.ts +1 -0
  119. package/dist/src/runtime/stdlib/generators/width.js +13 -0
  120. package/dist/src/runtime/stdlib/highlight.d.ts +2 -0
  121. package/dist/src/runtime/stdlib/highlight.js +76 -0
  122. package/dist/src/runtime/stdlib/index.d.ts +56 -0
  123. package/dist/src/runtime/stdlib/index.js +23 -0
  124. package/dist/src/runtime/stdlib/inputs.css +15 -0
  125. package/dist/src/runtime/stdlib/inputs.d.ts +2 -0
  126. package/dist/src/runtime/stdlib/inputs.js +2 -0
  127. package/dist/src/runtime/stdlib/leaflet.d.ts +1 -0
  128. package/dist/src/runtime/stdlib/leaflet.js +7 -0
  129. package/dist/src/runtime/stdlib/mapboxgl.d.ts +1 -0
  130. package/dist/src/runtime/stdlib/mapboxgl.js +5 -0
  131. package/dist/src/runtime/stdlib/md.d.ts +5 -0
  132. package/dist/src/runtime/stdlib/md.js +72 -0
  133. package/dist/src/runtime/stdlib/mermaid.d.ts +2 -0
  134. package/dist/src/runtime/stdlib/mermaid.js +11 -0
  135. package/dist/src/runtime/stdlib/mutable.d.ts +8 -0
  136. package/dist/src/runtime/stdlib/mutable.js +30 -0
  137. package/dist/src/runtime/stdlib/observer.d.ts +16 -0
  138. package/dist/src/runtime/stdlib/observer.js +42 -0
  139. package/dist/src/runtime/stdlib/recommendedLibraries.d.ts +25 -0
  140. package/dist/src/runtime/stdlib/recommendedLibraries.js +26 -0
  141. package/dist/src/runtime/stdlib/require.d.ts +4 -0
  142. package/dist/src/runtime/stdlib/require.js +40 -0
  143. package/dist/src/runtime/stdlib/sampleDatasets.d.ts +12 -0
  144. package/dist/src/runtime/stdlib/sampleDatasets.js +31 -0
  145. package/dist/src/runtime/stdlib/sql.d.ts +5 -0
  146. package/dist/src/runtime/stdlib/sql.js +5 -0
  147. package/dist/src/runtime/stdlib/template.d.ts +7 -0
  148. package/dist/src/runtime/stdlib/template.js +2 -0
  149. package/dist/src/runtime/stdlib/tex.d.ts +7 -0
  150. package/dist/src/runtime/stdlib/tex.js +18 -0
  151. package/dist/src/runtime/stdlib/vega-lite.d.ts +1 -0
  152. package/dist/src/runtime/stdlib/vega-lite.js +4 -0
  153. package/dist/src/styles/abstract-dark.css +14 -0
  154. package/dist/src/styles/abstract-light.css +14 -0
  155. package/dist/src/styles/global.css +266 -0
  156. package/dist/src/styles/highlight.css +47 -0
  157. package/dist/src/styles/index.css +14 -0
  158. package/dist/src/styles/inspector.css +89 -0
  159. package/dist/src/styles/plot.css +7 -0
  160. package/dist/src/styles/syntax-dark.css +12 -0
  161. package/dist/src/styles/syntax-light.css +12 -0
  162. package/dist/src/styles/theme-air.css +7 -0
  163. package/dist/src/styles/theme-coffee.css +7 -0
  164. package/dist/src/styles/theme-cotton.css +7 -0
  165. package/dist/src/styles/theme-deep-space.css +16 -0
  166. package/dist/src/styles/theme-glacier.css +7 -0
  167. package/dist/src/styles/theme-ink.css +7 -0
  168. package/dist/src/styles/theme-midnight.css +7 -0
  169. package/dist/src/styles/theme-near-midnight.css +7 -0
  170. package/dist/src/styles/theme-ocean-floor.css +7 -0
  171. package/dist/src/styles/theme-parchment.css +7 -0
  172. package/dist/src/styles/theme-slate.css +7 -0
  173. package/dist/src/styles/theme-stark.css +16 -0
  174. package/dist/src/styles/theme-sun-faded.css +7 -0
  175. package/dist/src/templates/default.html +31 -0
  176. package/dist/src/vite/config.d.ts +2 -0
  177. package/dist/src/vite/config.js +30 -0
  178. package/dist/src/vite/index.d.ts +2 -0
  179. package/dist/src/vite/index.js +2 -0
  180. package/dist/src/vite/observable.d.ts +12 -0
  181. package/dist/src/vite/observable.js +176 -0
  182. package/package.json +73 -0
@@ -0,0 +1,45 @@
1
+ import { observe } from "./observe.js";
2
+ export function input(element) {
3
+ return observe((change) => {
4
+ const event = eventof(element);
5
+ const value = valueof(element);
6
+ const inputted = () => change(valueof(element));
7
+ element.addEventListener(event, inputted);
8
+ if (value !== undefined)
9
+ change(value);
10
+ return () => element.removeEventListener(event, inputted);
11
+ });
12
+ }
13
+ function valueof(element) {
14
+ const input = element;
15
+ const select = element;
16
+ if ("type" in element) {
17
+ switch (element.type) {
18
+ case "range":
19
+ case "number":
20
+ return input.valueAsNumber;
21
+ case "date":
22
+ return input.valueAsDate;
23
+ case "checkbox":
24
+ return input.checked;
25
+ case "file":
26
+ return input.multiple ? input.files : input.files[0];
27
+ case "select-multiple":
28
+ return Array.from(select.selectedOptions, (o) => o.value);
29
+ }
30
+ }
31
+ return input.value;
32
+ }
33
+ function eventof(element) {
34
+ if ("type" in element) {
35
+ switch (element.type) {
36
+ case "button":
37
+ case "submit":
38
+ case "checkbox":
39
+ return "click";
40
+ case "file":
41
+ return "change";
42
+ }
43
+ }
44
+ return "input";
45
+ }
@@ -0,0 +1 @@
1
+ export declare function now(): AsyncGenerator<number, void, unknown>;
@@ -0,0 +1,5 @@
1
+ export async function* now() {
2
+ while (true) {
3
+ yield Date.now();
4
+ }
5
+ }
@@ -0,0 +1 @@
1
+ export declare function observe<T>(initialize: (change: (value: T) => void) => unknown): AsyncGenerator<Awaited<T>, void, unknown>;
@@ -0,0 +1,31 @@
1
+ export async function* observe(initialize) {
2
+ let resolve;
3
+ let value;
4
+ let stale = false;
5
+ const dispose = initialize((x) => {
6
+ value = x;
7
+ if (resolve) {
8
+ resolve(x);
9
+ resolve = undefined;
10
+ }
11
+ else {
12
+ stale = true;
13
+ }
14
+ return x;
15
+ });
16
+ if (dispose != null && typeof dispose !== "function") {
17
+ throw new Error(typeof dispose === "object" && "then" in dispose && typeof dispose.then === "function"
18
+ ? "async initializers are not supported"
19
+ : "initializer returned something, but not a dispose function");
20
+ }
21
+ try {
22
+ while (true) {
23
+ yield stale ? ((stale = false), value) : new Promise((_) => (resolve = _));
24
+ }
25
+ }
26
+ finally {
27
+ if (dispose != null) {
28
+ dispose();
29
+ }
30
+ }
31
+ }
@@ -0,0 +1 @@
1
+ export declare function queue<T>(initialize: (change: (value: T) => void) => unknown): AsyncGenerator<Awaited<T>, void, unknown>;
@@ -0,0 +1,27 @@
1
+ export async function* queue(initialize) {
2
+ let resolve;
3
+ const values = [];
4
+ const dispose = initialize((x) => {
5
+ values.push(x);
6
+ if (resolve) {
7
+ resolve(values.shift());
8
+ resolve = undefined;
9
+ }
10
+ return x;
11
+ });
12
+ if (dispose != null && typeof dispose !== "function") {
13
+ throw new Error(typeof dispose === "object" && "then" in dispose && typeof dispose.then === "function"
14
+ ? "async initializers are not supported"
15
+ : "initializer returned something, but not a dispose function");
16
+ }
17
+ try {
18
+ while (true) {
19
+ yield values.length ? values.shift() : new Promise((_) => (resolve = _));
20
+ }
21
+ }
22
+ finally {
23
+ if (dispose != null) {
24
+ dispose();
25
+ }
26
+ }
27
+ }
@@ -0,0 +1 @@
1
+ export declare function width(target: Element, options?: ResizeObserverOptions): AsyncGenerator<number, void, unknown>;
@@ -0,0 +1,13 @@
1
+ import { observe } from "./observe.js";
2
+ export function width(target, options) {
3
+ return observe((notify) => {
4
+ let width;
5
+ const observer = new ResizeObserver(([entry]) => {
6
+ const w = entry.contentRect.width;
7
+ if (w !== width)
8
+ notify((width = w));
9
+ });
10
+ observer.observe(target, options);
11
+ return () => observer.disconnect();
12
+ });
13
+ }
@@ -0,0 +1,2 @@
1
+ export declare const highlighter: import("@lezer/highlight").Highlighter;
2
+ export declare function highlight(code: HTMLElement): Promise<void>;
@@ -0,0 +1,76 @@
1
+ import { highlightCode, tagHighlighter, tags } from "@lezer/highlight";
2
+ // A subset of classHighlighter with the classes we’ve styled.
3
+ // Please keep in sync with src/codemirror/highlight.ts
4
+ // https://github.com/lezer-parser/highlight/blob/95aa69ecd22bfc8b3e1c793610e0d5cda1174e61/src/highlight.ts#L702
5
+ export const highlighter = tagHighlighter([
6
+ { tag: tags.link, class: "tok-link" },
7
+ { tag: [tags.heading, tags.strong], class: "tok-strong" },
8
+ { tag: tags.emphasis, class: "tok-emphasis" },
9
+ { tag: [tags.keyword, tags.typeName], class: "tok-keyword" },
10
+ { tag: tags.atom, class: "tok-atom" },
11
+ { tag: [tags.bool, tags.escape, tags.number], class: "tok-literal" },
12
+ { tag: [tags.string, tags.regexp], class: "tok-string" },
13
+ { tag: tags.comment, class: "tok-comment" },
14
+ { tag: tags.invalid, class: "tok-invalid" },
15
+ { tag: tags.variableName, class: "tok-variable" },
16
+ { tag: [tags.definition(tags.variableName), tags.className, tags.propertyName], class: "tok-definition" },
17
+ { tag: tags.meta, class: "tok-meta" }
18
+ ]);
19
+ export async function highlight(code) {
20
+ const language = getLanguage(code);
21
+ if (!language)
22
+ return;
23
+ const parent = code.parentElement;
24
+ if (parent)
25
+ parent.dataset.language = language;
26
+ const parser = await getParser(language);
27
+ if (!parser)
28
+ return;
29
+ const document = code.ownerDocument;
30
+ const text = code.textContent;
31
+ const tree = parser.parse(text);
32
+ while (code.lastChild)
33
+ code.lastChild.remove();
34
+ function emit(text, classes) {
35
+ let node = document.createTextNode(text);
36
+ if (classes) {
37
+ const span = document.createElement("span");
38
+ span.appendChild(node);
39
+ span.className = classes;
40
+ node = span;
41
+ }
42
+ code.appendChild(node);
43
+ }
44
+ function emitBreak() {
45
+ code.appendChild(document.createTextNode("\n"));
46
+ }
47
+ highlightCode(text, tree, highlighter, emit, emitBreak);
48
+ }
49
+ async function getParser(language) {
50
+ switch (language) {
51
+ case "js":
52
+ case "ts":
53
+ case "jsx":
54
+ return (await import("@lezer/javascript")).parser.configure({ dialect: language });
55
+ case "html":
56
+ return (await import("@lezer/html")).parser;
57
+ case "css":
58
+ return (await import("@lezer/css")).parser;
59
+ case "md":
60
+ case "markdown":
61
+ return (await import("@lezer/markdown")).parser;
62
+ }
63
+ }
64
+ function getLanguage(code) {
65
+ const language = [...code.classList]
66
+ .find((c) => c.startsWith("language-"))
67
+ ?.slice("language-".length)
68
+ ?.toLowerCase();
69
+ switch (language) {
70
+ case "javascript":
71
+ return "js";
72
+ case "typescript":
73
+ return "ts";
74
+ }
75
+ return language;
76
+ }
@@ -0,0 +1,56 @@
1
+ import { Mutable } from "./mutable.js";
2
+ import * as Generators from "./generators/index.js";
3
+ import { FileAttachment } from "./fileAttachment.js";
4
+ import * as DOM from "./dom/index.js";
5
+ import { Observer } from "./observer.js";
6
+ import { require } from "./require.js";
7
+ import { __sql } from "./sql.js";
8
+ export declare const root: HTMLElement;
9
+ export declare const library: {
10
+ aapl: () => Promise<any>;
11
+ alphabet: () => Promise<any>;
12
+ cars: () => Promise<any>;
13
+ citywages: () => Promise<any>;
14
+ diamonds: () => Promise<any>;
15
+ flare: () => Promise<any>;
16
+ industries: () => Promise<any>;
17
+ miserables: () => Promise<any>;
18
+ olympians: () => Promise<any>;
19
+ penguins: () => Promise<any>;
20
+ pizza: () => Promise<any>;
21
+ weather: () => Promise<any>;
22
+ _: () => Promise<any>;
23
+ aq: () => Promise<any>;
24
+ Arrow: () => Promise<any>;
25
+ d3: () => Promise<any>;
26
+ dot: () => Promise<import("./template.js").RawTemplateRenderer>;
27
+ duckdb: () => Promise<any>;
28
+ DuckDBClient: () => Promise<typeof import("./duckdb.js").DuckDBClient>;
29
+ echarts: () => Promise<any>;
30
+ htl: () => Promise<any>;
31
+ html: () => Promise<any>;
32
+ svg: () => Promise<any>;
33
+ Inputs: () => Promise<typeof import("./inputs.js")>;
34
+ L: () => Promise<typeof import("./leaflet.js")>;
35
+ mapboxgl: () => Promise<any>;
36
+ md: () => Promise<import("./template.js").TemplateRenderer>;
37
+ mermaid: () => Promise<import("./template.js").AsyncRawTemplateRenderer>;
38
+ Plot: () => Promise<any>;
39
+ React: () => Promise<any>;
40
+ ReactDOM: () => Promise<any>;
41
+ tex: () => Promise<import("./template.js").RawTemplateRenderer & {
42
+ options: (options?: any) => import("./template.js").RawTemplateRenderer;
43
+ block: import("./template.js").RawTemplateRenderer;
44
+ }>;
45
+ topojson: () => Promise<any>;
46
+ vl: () => Promise<any>;
47
+ now: () => AsyncGenerator<number, void, unknown>;
48
+ width: () => AsyncGenerator<number, void, unknown>;
49
+ FileAttachment: () => typeof FileAttachment;
50
+ Generators: () => typeof Generators;
51
+ Mutable: () => typeof Mutable;
52
+ DOM: () => typeof DOM;
53
+ require: () => typeof require;
54
+ __sql: () => typeof __sql;
55
+ __ojs_observer: () => () => Observer;
56
+ };
@@ -0,0 +1,23 @@
1
+ import { Mutable } from "./mutable.js";
2
+ import * as Generators from "./generators/index.js";
3
+ import { FileAttachment } from "./fileAttachment.js";
4
+ import * as DOM from "./dom/index.js";
5
+ import { Observer } from "./observer.js";
6
+ import * as recommendedLibraries from "./recommendedLibraries.js";
7
+ import { require } from "./require.js";
8
+ import * as sampleDatasets from "./sampleDatasets.js";
9
+ import { __sql } from "./sql.js";
10
+ export const root = document.querySelector("main") ?? document.body;
11
+ export const library = {
12
+ now: () => Generators.now(),
13
+ width: () => Generators.width(root),
14
+ FileAttachment: () => FileAttachment,
15
+ Generators: () => Generators,
16
+ Mutable: () => Mutable,
17
+ DOM: () => DOM, // deprecated!
18
+ require: () => require, // deprecated!
19
+ __sql: () => __sql,
20
+ __ojs_observer: () => () => new Observer(),
21
+ ...recommendedLibraries,
22
+ ...sampleDatasets
23
+ };
@@ -0,0 +1,15 @@
1
+ @import url("https://cdn.jsdelivr.net/npm/@observablehq/inputs/dist/index.css");
2
+
3
+ .inputs-3a86ea-table tr:not(:last-child) td,
4
+ .inputs-3a86ea-table tr:not(:last-child) th {
5
+ border-bottom-color: var(--theme-foreground-faintest);
6
+ }
7
+
8
+ .inputs-3a86ea-table thead tr td,
9
+ .inputs-3a86ea-table thead tr th {
10
+ border-bottom-color: var(--theme-foreground-fainter);
11
+ }
12
+
13
+ .inputs-3a86ea-table thead th {
14
+ background: var(--theme-background);
15
+ }
@@ -0,0 +1,2 @@
1
+ export * from "npm:@observablehq/inputs";
2
+ import "./inputs.css";
@@ -0,0 +1,2 @@
1
+ export * from "npm:@observablehq/inputs";
2
+ import "./inputs.css";
@@ -0,0 +1 @@
1
+ export * from "npm:leaflet";
@@ -0,0 +1,7 @@
1
+ import { Icon } from "npm:leaflet";
2
+ export * from "npm:leaflet";
3
+ Icon.Default.imagePath = "https://cdn.jsdelivr.net/npm/leaflet/dist/images/";
4
+ const link = document.createElement("link");
5
+ link.href = "https://cdn.jsdelivr.net/npm/leaflet/dist/leaflet.css";
6
+ link.rel = "stylesheet";
7
+ document.head.appendChild(link);
@@ -0,0 +1 @@
1
+ export { default } from "npm:mapbox-gl";
@@ -0,0 +1,5 @@
1
+ export { default } from "npm:mapbox-gl";
2
+ const link = document.createElement("link");
3
+ link.href = "https://cdn.jsdelivr.net/npm/mapbox-gl/dist/mapbox-gl.css";
4
+ link.rel = "stylesheet";
5
+ document.head.appendChild(link);
@@ -0,0 +1,5 @@
1
+ import type { TemplateRenderer } from "./template.js";
2
+ export declare function MarkdownRenderer({ document }?: {
3
+ document?: Document;
4
+ }): TemplateRenderer<HTMLElement>;
5
+ export declare const md: TemplateRenderer;
@@ -0,0 +1,72 @@
1
+ import slugify from "@sindresorhus/slugify";
2
+ import MarkdownIt from "markdown-it";
3
+ import MarkdownItAnchor from "markdown-it-anchor";
4
+ const mi = MarkdownIt({ html: true, linkify: true, typographer: true });
5
+ mi.use(MarkdownItAnchor, {
6
+ level: [2, 3],
7
+ slugify: (s) => slugify(s),
8
+ permalink: MarkdownItAnchor.permalink.headerLink({ class: "" })
9
+ });
10
+ export function MarkdownRenderer({ document = window.document } = {}) {
11
+ return function (template, ...values) {
12
+ let source = template[0];
13
+ let fragment = null;
14
+ let partIndex = -1;
15
+ const parts = [];
16
+ // Concatenate the text using comments as placeholders.
17
+ for (let i = 0, n = values.length; i < n; ++i) {
18
+ const value = values[i];
19
+ if (value instanceof Node) {
20
+ parts[++partIndex] = value;
21
+ source += `<!--o:${partIndex}-->`;
22
+ }
23
+ else if (Array.isArray(value)) {
24
+ for (const node of value) {
25
+ if (node instanceof Node) {
26
+ if (fragment === null) {
27
+ parts[++partIndex] = fragment = document.createDocumentFragment();
28
+ source += `<!--o:${partIndex}-->`;
29
+ }
30
+ fragment.appendChild(node);
31
+ }
32
+ else {
33
+ fragment = null;
34
+ source += node;
35
+ }
36
+ }
37
+ fragment = null;
38
+ }
39
+ else {
40
+ source += value;
41
+ }
42
+ source += template[i + 1];
43
+ }
44
+ // Render the text.
45
+ const root = document.createElement("div");
46
+ root.innerHTML = mi.render(source);
47
+ // Walk the rendered content to replace comment placeholders.
48
+ if (++partIndex > 0) {
49
+ const nodes = new Array(partIndex);
50
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT, null);
51
+ while (walker.nextNode()) {
52
+ const node = walker.currentNode;
53
+ if (/^o:\d+$/.test(node.nodeValue)) {
54
+ nodes[+node.nodeValue.slice(2)] = node;
55
+ }
56
+ }
57
+ for (let i = 0; i < partIndex; ++i) {
58
+ const node = nodes[i];
59
+ node.parentNode?.replaceChild(parts[i], node);
60
+ }
61
+ }
62
+ return root;
63
+ };
64
+ }
65
+ let renderer;
66
+ export const md = (template, ...values) => {
67
+ const root = (renderer ?? (renderer = MarkdownRenderer()))(template, ...values);
68
+ const codes = root.querySelectorAll("code[class^=language-]");
69
+ if (codes.length > 0)
70
+ import("./highlight.js").then(({ highlight }) => codes.forEach(highlight));
71
+ return root.childNodes.length === 1 ? root.removeChild(root.firstChild) : root;
72
+ };
@@ -0,0 +1,2 @@
1
+ import type { AsyncRawTemplateRenderer } from "./template.js";
2
+ export declare const mermaid: AsyncRawTemplateRenderer;
@@ -0,0 +1,11 @@
1
+ import mer from "npm:mermaid";
2
+ let nextId = 0;
3
+ const scheme = getComputedStyle(document.body).getPropertyValue("color-scheme");
4
+ const theme = scheme === "dark" ? "dark" : "neutral";
5
+ mer.initialize({ startOnLoad: false, securityLevel: "loose", theme });
6
+ export const mermaid = async (template, ...values) => {
7
+ const source = String.raw.call(String, template, ...values);
8
+ const root = document.createElement("div");
9
+ root.innerHTML = (await mer.render(`mermaid-${++nextId}`, source)).svg;
10
+ return root.removeChild(root.firstChild);
11
+ };
@@ -0,0 +1,8 @@
1
+ export declare function Mutable<T>(value: T): AsyncGenerator<Awaited<T>, void, unknown> & {
2
+ value: T;
3
+ };
4
+ export declare function Mutator<T>(value: T): ((AsyncGenerator<Awaited<T>, void, unknown> & {
5
+ value: T;
6
+ }) | {
7
+ value: T;
8
+ })[];
@@ -0,0 +1,30 @@
1
+ import { observe } from "./generators/observe.js";
2
+ // Mutable returns a generator with a value getter/setting that allows the
3
+ // generated value to be mutated. Therefore, direct mutation is only allowed
4
+ // within the defining cell, but the cell can also export functions that allows
5
+ // other cells to mutate the value as desired.
6
+ export function Mutable(value) {
7
+ let change;
8
+ return Object.defineProperty(observe((_) => {
9
+ change = _;
10
+ if (value !== undefined)
11
+ change(value);
12
+ }), "value", {
13
+ get: () => value,
14
+ set: (x) => ((value = x), void change?.(value))
15
+ });
16
+ }
17
+ export function Mutator(value) {
18
+ const mutable = Mutable(value);
19
+ return [
20
+ mutable,
21
+ {
22
+ get value() {
23
+ return mutable.value;
24
+ },
25
+ set value(v) {
26
+ mutable.value = v;
27
+ }
28
+ }
29
+ ];
30
+ }
@@ -0,0 +1,16 @@
1
+ export declare class Observer {
2
+ #private;
3
+ fulfilled?: (value: unknown) => void;
4
+ rejected?: (error: unknown) => void;
5
+ constructor();
6
+ next(): Promise<{
7
+ done: boolean;
8
+ value: unknown;
9
+ }>;
10
+ throw(): {
11
+ done: boolean;
12
+ };
13
+ return(): {
14
+ done: boolean;
15
+ };
16
+ }
@@ -0,0 +1,42 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _Observer_promise;
13
+ export class Observer {
14
+ constructor() {
15
+ _Observer_promise.set(this, void 0);
16
+ Object.defineProperty(this, "fulfilled", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ Object.defineProperty(this, "rejected", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ this.next();
29
+ }
30
+ async next() {
31
+ const value = await __classPrivateFieldGet(this, _Observer_promise, "f");
32
+ __classPrivateFieldSet(this, _Observer_promise, new Promise((res, rej) => ((this.fulfilled = res), (this.rejected = rej))), "f");
33
+ return { done: false, value };
34
+ }
35
+ throw() {
36
+ return { done: true };
37
+ }
38
+ return() {
39
+ return { done: true };
40
+ }
41
+ }
42
+ _Observer_promise = new WeakMap();
@@ -0,0 +1,25 @@
1
+ export declare const _: () => Promise<any>;
2
+ export declare const aq: () => Promise<any>;
3
+ export declare const Arrow: () => Promise<any>;
4
+ export declare const d3: () => Promise<any>;
5
+ export declare const dot: () => Promise<import("./template.js").RawTemplateRenderer>;
6
+ export declare const duckdb: () => Promise<any>;
7
+ export declare const DuckDBClient: () => Promise<typeof import("./duckdb.js").DuckDBClient>;
8
+ export declare const echarts: () => Promise<any>;
9
+ export declare const htl: () => Promise<any>;
10
+ export declare const html: () => Promise<any>;
11
+ export declare const svg: () => Promise<any>;
12
+ export declare const Inputs: () => Promise<typeof import("./inputs.js")>;
13
+ export declare const L: () => Promise<typeof import("./leaflet.js")>;
14
+ export declare const mapboxgl: () => Promise<any>;
15
+ export declare const md: () => Promise<import("./template.js").TemplateRenderer>;
16
+ export declare const mermaid: () => Promise<import("./template.js").AsyncRawTemplateRenderer>;
17
+ export declare const Plot: () => Promise<any>;
18
+ export declare const React: () => Promise<any>;
19
+ export declare const ReactDOM: () => Promise<any>;
20
+ export declare const tex: () => Promise<import("./template.js").RawTemplateRenderer & {
21
+ options: (options?: any) => import("./template.js").RawTemplateRenderer;
22
+ block: import("./template.js").RawTemplateRenderer;
23
+ }>;
24
+ export declare const topojson: () => Promise<any>;
25
+ export declare const vl: () => Promise<any>;
@@ -0,0 +1,26 @@
1
+ export const _ = () => import("npm:lodash").then((_) => _.default);
2
+ export const aq = () => import("npm:arquero");
3
+ export const Arrow = () => import("npm:apache-arrow");
4
+ export const d3 = () => import("npm:d3");
5
+ export const dot = () => import("./dot.js").then((_) => _.dot);
6
+ export const duckdb = () => import("npm:@duckdb/duckdb-wasm");
7
+ export const DuckDBClient = () => import("./duckdb.js").then((_) => _.DuckDBClient);
8
+ export const echarts = () => import("npm:echarts");
9
+ export const htl = () => import("npm:htl");
10
+ export const html = () => import("npm:htl").then((_) => _.html);
11
+ export const svg = () => import("npm:htl").then((_) => _.svg);
12
+ export const Inputs = () => import("./inputs.js");
13
+ export const L = () => import("./leaflet.js");
14
+ export const mapboxgl = () => import("./mapboxgl.js").then((_) => _.default);
15
+ export const md = () => import("./md.js").then((_) => _.md);
16
+ export const mermaid = () => import("./mermaid.js").then((_) => _.mermaid);
17
+ export const Plot = () => import("npm:@observablehq/plot");
18
+ export const React = () => import("npm:react");
19
+ export const ReactDOM = () => import("npm:react-dom");
20
+ // export const sql = () => import("observablehq:stdlib/duckdb").then((_) => _.sql);
21
+ // export const SQLite = () => import("observablehq:stdlib/sqlite").then((_) => _.default);
22
+ // export const SQLiteDatabaseClient = () => import("observablehq:stdlib/sqlite").then((_) => _.SQLiteDatabaseClient);
23
+ export const tex = () => import("./tex.js").then((_) => _.tex);
24
+ export const topojson = () => import("npm:topojson-client");
25
+ // export const vg = () => import("observablehq:stdlib/vgplot").then((_) => _.default());
26
+ export const vl = () => import("./vega-lite.js").then((_) => _.vl);
@@ -0,0 +1,4 @@
1
+ export declare function require(...specifiers: unknown[]): unknown;
2
+ export declare namespace require {
3
+ var resolve: (_specifier: unknown) => string;
4
+ }
@@ -0,0 +1,40 @@
1
+ require.resolve = resolve;
2
+ export function require(...specifiers) {
3
+ return specifiers.length === 1
4
+ ? import(/* @vite-ignore */ resolve(specifiers[0]))
5
+ : Promise.all(specifiers.map((s) => require(s))).then((modules) => Object.assign({}, ...modules));
6
+ }
7
+ function parseNpmSpecifier(specifier) {
8
+ const parts = specifier.split("/");
9
+ const namerange = specifier.startsWith("@")
10
+ ? [parts.shift(), parts.shift()].join("/")
11
+ : parts.shift();
12
+ const ranged = namerange.indexOf("@", 1);
13
+ const name = ranged > 0 ? namerange.slice(0, ranged) : namerange;
14
+ const range = ranged > 0 ? namerange.slice(ranged) : "";
15
+ const path = parts.length > 0 ? `/${parts.join("/")}` : "";
16
+ return { name, range, path };
17
+ }
18
+ function resolve(_specifier) {
19
+ const specifier = String(_specifier);
20
+ if (isProtocol(specifier) || isLocal(specifier))
21
+ return specifier;
22
+ const { name, range, path } = parseNpmSpecifier(specifier);
23
+ return `https://cdn.jsdelivr.net/npm/${name}${range}${path + (isFile(path) || isDirectory(path) ? "" : "/+esm")}`;
24
+ }
25
+ /** Returns true for e.g. https://example.com/ */
26
+ function isProtocol(specifier) {
27
+ return /^\w+:/.test(specifier);
28
+ }
29
+ /** Returns true for e.g. ./foo.js */
30
+ function isLocal(specifier) {
31
+ return /^(\.\/|\.\.\/|\/)/.test(specifier);
32
+ }
33
+ /** Returns true for e.g. foo/bar.js */
34
+ function isFile(specifier) {
35
+ return /(\.\w*)$/.test(specifier);
36
+ }
37
+ /** Returns true for e.g. foo/bar/ */
38
+ function isDirectory(specifier) {
39
+ return /(\/)$/.test(specifier);
40
+ }