import {readFile} from 'node:fs/promises'; import ts from 'typescript'; const compile=async path=>ts.transpileModule(await readFile(new URL('../../'+path,import.meta.url),'utf8'),{compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.ESNext}}).outputText; const moduleUrl=source=>'data:text/javascript;base64,'+Buffer.from(source).toString('base64'); export const siteUrl=moduleUrl(await compile('src/lib/site.ts')); const routingUrl=moduleUrl(await compile('src/lib/routing.ts')); const protocolUrl=moduleUrl(await compile('src/lib/api/protocol.ts')); const playbackUrl=moduleUrl((await compile('src/lib/client/playback.ts')).replace("'../api/protocol'",JSON.stringify(protocolUrl))); export const structuredUrl=moduleUrl((await compile('src/lib/structured-data.ts')).replace("'./routing'",JSON.stringify(routingUrl))); export const structuredData=await import(structuredUrl); export const seoUrl=moduleUrl((await compile('src/lib/seo.ts')).replace("'./site'",JSON.stringify(siteUrl)).replace("'./routing'",JSON.stringify(routingUrl)).replace("'./structured-data'",JSON.stringify(structuredUrl)).replace("'./client/playback'",JSON.stringify(playbackUrl))); export const seo=await import(seoUrl); export const clientSeo=await import(moduleUrl((await compile('src/lib/client/seo.ts')).replace("'../structured-data'",JSON.stringify(structuredUrl)))); export function headDocument(){ const nodes=[]; const doc={title:'',head:{ querySelectorAll(selector){ const match=selector.match(/^(meta|link|script)\[([\w-]+)(?:="([^"]+)")?\]$/); return match?nodes.filter(node=>node.tagName===match[1]&&(match[3]===undefined?Object.hasOwn(node.attributes,match[2]):node.attributes[match[2]]===match[3])):[]; }, appendChild(node){nodes.push(node);}, },createElement(tagName){return {tagName,attributes:{},setAttribute(name,value){this.attributes[name]=value;},remove(){const i=nodes.indexOf(this);if(i>=0)nodes.splice(i,1);}};}}; doc.value=selector=>doc.head.querySelectorAll(selector)[0]?.attributes[selector.startsWith('link')?'href':'content']; doc.querySelectorAll=selector=>doc.head.querySelectorAll(selector); doc.nodes=nodes; return doc; }