@observablehq/notebook-kit 1.9.1 → 2.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.
package/dist/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "1.9.1",
8
+ "version": "2.0.0",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -18,113 +18,7 @@ export declare class NotebookRuntime {
18
18
  fileAttachments: typeof fileAttachments;
19
19
  };
20
20
  readonly main: Module;
21
- constructor(builtins?: {
22
- aapl: () => Promise<any>;
23
- alphabet: () => Promise<any>;
24
- cars: () => Promise<any>;
25
- citywages: () => Promise<any>;
26
- diamonds: () => Promise<any>;
27
- flare: () => Promise<any>;
28
- industries: () => Promise<any>;
29
- miserables: () => Promise<any>;
30
- olympians: () => Promise<any>;
31
- penguins: () => Promise<any>;
32
- pizza: () => Promise<any>;
33
- weather: () => Promise<any>;
34
- _: () => Promise<any>;
35
- aq: () => Promise<any>;
36
- Arrow: () => Promise<any>;
37
- d3: () => Promise<any>;
38
- dot: () => Promise<import("./stdlib/template.js").RawTemplateRenderer>;
39
- duckdb: () => Promise<any>;
40
- DuckDBClient: () => Promise<typeof import("./stdlib/duckdb.js").DuckDBClient>;
41
- echarts: () => Promise<any>;
42
- htl: () => Promise<any>;
43
- html: () => Promise<any>;
44
- svg: () => Promise<any>;
45
- Inputs: () => Promise<typeof import("./stdlib/inputs.js")>;
46
- L: () => Promise<typeof import("./stdlib/leaflet.js")>;
47
- mapboxgl: () => Promise<any>;
48
- md: () => Promise<import("./stdlib/template.js").TemplateRenderer>;
49
- mermaid: () => Promise<import("./stdlib/template.js").AsyncRawTemplateRenderer>;
50
- Plot: () => Promise<any>;
51
- React: () => Promise<any>;
52
- ReactDOM: () => Promise<any>;
53
- tex: () => Promise<import("./stdlib/template.js").RawTemplateRenderer & {
54
- options: (options?: any) => import("./stdlib/template.js").RawTemplateRenderer;
55
- block: import("./stdlib/template.js").RawTemplateRenderer;
56
- }>;
57
- topojson: () => Promise<any>;
58
- vl: () => Promise<any>;
59
- dark: () => ObservableAsyncGenerator<boolean>;
60
- now: () => AsyncGenerator<number, void, unknown>;
61
- width: () => ObservableAsyncGenerator<number>;
62
- DatabaseClient: () => {
63
- (name: string, options?: import("./stdlib/databaseClient.js").QueryOptionsSpec): import("./stdlib/databaseClient.js").DatabaseClient;
64
- revive: ({ rows, schema, date, ...meta }: import("../databases/index.js").SerializableQueryResult) => import("./stdlib/databaseClient.js").QueryResult;
65
- prototype: {
66
- readonly name: string;
67
- readonly options: import("./stdlib/databaseClient.js").QueryOptions;
68
- sql(strings: readonly string[], ...params: import("./stdlib/databaseClient.js").QueryParam[]): Promise<import("./stdlib/databaseClient.js").QueryResult>;
69
- cachePath(strings: readonly string[], ...params: import("./stdlib/databaseClient.js").QueryParam[]): Promise<string>;
70
- };
71
- };
72
- FileAttachment: () => {
73
- (name: string, base?: string): import("./stdlib/fileAttachment.js").FileAttachment;
74
- prototype: {
75
- href: string;
76
- name: string;
77
- mimeType: string;
78
- lastModified: number | undefined;
79
- size: number | undefined;
80
- url(): Promise<string>;
81
- blob(): Promise<Blob>;
82
- arrayBuffer(): Promise<ArrayBuffer>;
83
- text(encoding?: string): Promise<string>;
84
- json(): Promise<any>;
85
- stream(): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>;
86
- dsv({ delimiter, array, typed }?: {
87
- delimiter?: string | undefined;
88
- array?: boolean | undefined;
89
- typed?: boolean | undefined;
90
- }): Promise<import("./stdlib/fileAttachment.js").DsvResult>;
91
- csv(options?: Omit<import("./stdlib/fileAttachment.js").DsvOptions, "delimiter">): Promise<import("./stdlib/fileAttachment.js").DsvResult>;
92
- tsv(options?: Omit<import("./stdlib/fileAttachment.js").DsvOptions, "delimiter">): Promise<import("./stdlib/fileAttachment.js").DsvResult>;
93
- image(props?: Partial<HTMLImageElement>): Promise<HTMLImageElement>;
94
- arrow(): Promise<any>;
95
- arquero(options?: any): Promise<any>;
96
- parquet(): Promise<any>;
97
- zip(): Promise<import("./stdlib/zip.js").ZipArchive>;
98
- xml(mimeType?: DOMParserSupportedType): Promise<Document>;
99
- html(): Promise<Document>;
100
- xlsx(): Promise<import("./stdlib/xlsx.js").Workbook>;
101
- };
102
- };
103
- Generators: () => typeof import("./stdlib/generators/index.js");
104
- Interpreter: () => {
105
- (name: string, options?: import("./stdlib/interpreter.js").InterpreterOptionsSpec): import("./stdlib/interpreter.js").Interpreter;
106
- prototype: {
107
- readonly name: string;
108
- readonly options: import("./stdlib/interpreter.js").InterpreterOptions;
109
- run(input: string): Promise<import("./stdlib/fileAttachment.js").FileAttachment>;
110
- cachePath(input: string): Promise<string>;
111
- };
112
- };
113
- Mutable: () => typeof import("./stdlib/mutable.js").Mutable;
114
- Promises: () => typeof import("./stdlib/promises/index.js");
115
- Files: () => typeof import("./stdlib/files/index.js");
116
- DOM: () => typeof import("./stdlib/dom/index.js");
117
- require: () => {
118
- (...specifiers: unknown[]): Promise<unknown>;
119
- resolve: (specifier: unknown) => string;
120
- } & {
121
- alias: (aliases: Record<string, string>) => {
122
- (...specifiers: unknown[]): Promise<unknown>;
123
- resolve: (specifier: unknown) => string;
124
- };
125
- };
126
- __ojs_observer: () => () => import("./stdlib/observer.js").Observer;
127
- });
21
+ constructor(builtins?: Record<string, () => unknown>);
128
22
  define(state: DefineState, definition: Definition, observer?: typeof observe): void;
129
23
  }
130
24
  export declare const runtime: Runtime & {
@@ -104,14 +104,5 @@ export declare const library: {
104
104
  Promises: () => typeof Promises;
105
105
  Files: () => typeof Files;
106
106
  DOM: () => typeof DOM;
107
- require: () => {
108
- (...specifiers: unknown[]): Promise<unknown>;
109
- resolve: (specifier: unknown) => string;
110
- } & {
111
- alias: (aliases: Record<string, string>) => {
112
- (...specifiers: unknown[]): Promise<unknown>;
113
- resolve: (specifier: unknown) => string;
114
- };
115
- };
116
107
  __ojs_observer: () => () => Observer;
117
108
  };
@@ -8,7 +8,6 @@ import { Mutable } from "./mutable.js";
8
8
  import { Observer } from "./observer.js";
9
9
  import * as Promises from "./promises/index.js";
10
10
  import * as recommendedLibraries from "./recommendedLibraries.js";
11
- import { require } from "./require.js";
12
11
  import * as sampleDatasets from "./sampleDatasets.js";
13
12
  export const root = document.querySelector("main") ?? document.body;
14
13
  export const library = {
@@ -23,7 +22,6 @@ export const library = {
23
22
  Promises: () => Promises, // deprecated!
24
23
  Files: () => Files, // deprecated!
25
24
  DOM: () => DOM, // deprecated!
26
- require: () => require, // deprecated!
27
25
  __ojs_observer: () => () => new Observer(),
28
26
  ...recommendedLibraries,
29
27
  ...sampleDatasets
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "1.9.1",
8
+ "version": "2.0.0",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -1,11 +0,0 @@
1
- export declare const require: {
2
- (...specifiers: unknown[]): Promise<unknown>;
3
- resolve: (specifier: unknown) => string;
4
- } & {
5
- alias: typeof alias;
6
- };
7
- declare function alias(aliases: Record<string, string>): {
8
- (...specifiers: unknown[]): Promise<unknown>;
9
- resolve: (specifier: unknown) => string;
10
- };
11
- export {};
@@ -1,73 +0,0 @@
1
- const cache = new WeakMap();
2
- export const require = Object.assign(Requirer(resolve), { alias });
3
- function Requirer(resolve) {
4
- async function require(...specifiers) {
5
- return specifiers.length === 1
6
- ? import(/* @vite-ignore */ resolve(specifiers[0])).then(objectify)
7
- : Promise.all(specifiers.map((s) => require(s))).then(merge);
8
- }
9
- require.resolve = resolve;
10
- return require;
11
- }
12
- function parseNpmSpecifier(specifier) {
13
- const parts = specifier.split("/");
14
- const namerange = specifier.startsWith("@")
15
- ? [parts.shift(), parts.shift()].join("/")
16
- : parts.shift();
17
- const ranged = namerange.indexOf("@", 1);
18
- const name = ranged > 0 ? namerange.slice(0, ranged) : namerange;
19
- const range = ranged > 0 ? namerange.slice(ranged) : "";
20
- const path = parts.length > 0 ? `/${parts.join("/")}` : "";
21
- return { name, range, path };
22
- }
23
- function alias(aliases) {
24
- return Requirer((specifier) => {
25
- if (specifier in aliases)
26
- specifier = aliases[specifier];
27
- return resolve(specifier);
28
- });
29
- }
30
- function resolve(_specifier) {
31
- const specifier = String(_specifier);
32
- if (isProtocol(specifier) || isLocal(specifier))
33
- return specifier;
34
- const { name, range, path } = parseNpmSpecifier(specifier);
35
- return `https://cdn.jsdelivr.net/npm/${name}${range}${path + ((isFile(path) && !isJavaScript(path)) || isDirectory(path) ? "" : "/+esm")}`;
36
- }
37
- /** Promote exclusive default export to module. */
38
- function defaultify(module) {
39
- for (const key in module)
40
- if (key !== "default")
41
- return { ...module }; // any named export
42
- return "default" in module ? module.default : { ...module }; // promote exclusive default export
43
- }
44
- /** Allow mutation of required modules while maintaining a canonical instance; ugly! */
45
- function objectify(module) {
46
- let object = cache.get(module);
47
- if (!object)
48
- cache.set(module, (object = defaultify(module)));
49
- return object;
50
- }
51
- function merge(modules) {
52
- return Object.assign({}, ...modules);
53
- }
54
- /** Returns true for e.g. https://example.com/ */
55
- function isProtocol(specifier) {
56
- return /^\w+:/.test(specifier);
57
- }
58
- /** Returns true for e.g. ./foo.js */
59
- function isLocal(specifier) {
60
- return /^(\.\/|\.\.\/|\/)/.test(specifier);
61
- }
62
- /** Returns true for e.g. foo/bar.js */
63
- function isJavaScript(specifier) {
64
- return /\.js$/i.test(specifier);
65
- }
66
- /** Returns true for e.g. foo/bar.txt */
67
- function isFile(specifier) {
68
- return /\.\w*$/.test(specifier);
69
- }
70
- /** Returns true for e.g. foo/bar/ */
71
- function isDirectory(specifier) {
72
- return /\/$/.test(specifier);
73
- }