async function importCell(
cell,
notebook,
injections = {}
) {
const library = Object.assign(new Library(), {require: () => require});
const runtime = new Runtime(library);
const main = runtime.module();
for (const name in injections) {
main.define(name, [], () => injections[name]);
}
const origin = `https://api.observablehq.com`;
const {default: define} = await import(
/^@[0-9a-z_-]+\/[0-9a-z_-]+(\/\d+)?([@~]|$)/.test(notebook += "") ? `${origin}/${notebook}.js?v=3`
: /^[0-9a-f]{16}([@~]|$)/.test(notebook) ? `${origin}/d/${notebook}.js?v=3`
: notebook);
const imported = runtime.module(define);
const derived = imported.derive([...Object.keys(injections)], main);
return Generators.observe((notify) => {
main.variable({
fulfilled(value) { notify(value); },
rejected(value) { notify(Promise.reject(value)); }
}).import(cell, derived);
return () => runtime.dispose();
});
}