// Node module-resolution hook: resolve bare specifiers with the page's import map.
let map;
export function initialize(data) { map = data; }
export async function resolve(spec, ctx, next) {
for (const [k, v] of Object.entries(map.imports)) {
if (spec === k || (k.endsWith('/') && spec.startsWith(k))) {
return { url: new URL(v + spec.slice(k.length), map.base).href, shortCircuit: true };
}
}
return next(spec, ctx);
}