@observablehq/notebook-kit 1.9.2 → 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
|
@@ -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
|
@@ -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
|
-
}
|