importNotebook = async (notebook, specifiers = []) => {
runtime;
let fn;
for (const url of [
notebook,
`https://api.observablehq.com/${notebook}.js?v=4&${resolutions_key}`
]) {
try {
fn = eval(`async () => runtime.module((await import("${url}")).default)`);
await fn();
break;
} catch {}
}
if (!fn) throw `Can't resolve ${notebook}`;
const module_variable = `module ${notebook}`;
if (!main._scope.has(module_variable)) {
main.define(module_variable, fn);
}
for (let { imported, local = null } of specifiers) {
if (!local) local = imported;
if (!main._scope.has(local)) {
main.define(local, [module_variable, "@variable"], (_, v) =>
v.import(imported, local, _)
);
} else {
main.redefine(local, [module_variable, "@variable"], (_, v) =>
v.import(imported, local, _)
);
}
}
return md`~~~js
importNotebook("${notebook}", ${JSON.stringify(specifiers)})
~~~`;
}