library-browser.js (894B)
1 import { fetchBytes } from './bundle.js'; 2 import { libraryIndex } from './library-index.js'; 3 let pending; 4 export function loadLibraries() { 5 return pending ??= fetchBytes(new URL('../reference/libraries.json', import.meta.url), 2_097_152) 6 .then(bytes => libraryIndex(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)))) 7 .catch(error => { pending = undefined; throw error; }); 8 } 9 export function renderLibraryExports(list, names, query, choose) { 10 list.replaceChildren(); 11 for (const name of names.filter(name => name.toLowerCase().includes(query.toLowerCase()))) { 12 const button = document.createElement('button'); 13 button.type = 'button'; 14 button.textContent = name; 15 button.onclick = () => choose(name); 16 list.append(button); 17 } 18 if (!list.children.length) 19 list.textContent = 'No matching exports.'; 20 }