ScrapJupyter@0.0.1
code:js
https://gyazo.com/cb36864ae9469a053627c59b5a3059f7
原理
2021-08-25
export構文があったときのみiifeにする、みたいなことをしたいのだが、難しそうだな……
exportがあった場合のことは考えないことにしよう。
動作確認用コード
top-level awaitを書ける
code:js
const res = await fetch("/api/projects/shokai");
alert(JSON.stringify(await res.json(), null, 2));
TSでかける
ただし型チェックはされないようだ
JSの構文エラーだけ見てくれる
code:ts
const test: Value = {title:"Hello",hasIcon:false;};
alert(JSON.stringify(test));
code:ts
type Value = {
title: string,
hasIcon: boolean;
};
const test: Value = {title:"Hello",hasIcon:false};
alert(JSON.stringify(test));
code:ts
type Value = {
titleLc: string;
hasIcon: boolean;
};
alert(JSON.stringify(
scrapbox.Project.pages.map((page: Value) => ({title: page.title})),
null,
2
));
JSXも書ける
おっと、生のテキストとして流し込んでいるから、相対URLを使えないのか。
絶対URLでimportしないとbundleできない
JSX pragmaは不要
GitHub版では必要
bundle.tsで指定してある
code:tsx
/** @jsx h */
const App = () => (
<div style={{
position: "fixed",
top: 0,
left: 0,
margin: "10vh 10vw",
borderColor: "lightgreen",
borderRadius: "4px",
color: "var(--page-text-color, gray)",
}}>
{this is /${scrapbox.Project.name}/${scrapbox.Page.title}}
</div>
);
const div = document.createElement("div");
document.getElementById("editor").append(div);
render(<App />, div);
dynamic importはどうだ?
https://gyazo.com/37cc11769e50eecfc79693ed2d50522d
code:ts
console.log(module);
TS/JS以外のコードブロックには何もしない
code:sh
code:md
# markdownです
CSPに引っかかるものは実行できない
code:ts
code:script.ts
/// <reference no-default-lib="true"/>
/// <reference lib="esnext"/>
/// <reference lib="dom"/>
import { getCodeFiles } from "./codeFile.ts";
import { bundle } from "./bundler.ts";
import {
eventName,
Scrapbox,
declare const scrapbox: Scrapbox;
const callback = () => {
const files = getCodeFiles();
// ボタンを全部リセットする
div.remove()
);
files.forEach((file) => {
// TS/JS以外は無視
if (
file.lang.toLowerCase(),
)
) {
return;
}
file.startIds.forEach((id) => {
const line = document.getElementById(L${id});
line?.insertBefore(
createButton({
onClick: async ({ target }) => {
(target as HTMLDivElement).style.color = "red";
try {
const code = await bundle(file.lines.join("\n"));
console.log("execute:", code);
Function((async()=>{${code}})())();
} catch (e) {
console.error(e);
} finally {
(target as HTMLDivElement).style.removeProperty("color");
}
},
}),
line?.firstElementChild,
);
});
});
};
callback();
scrapbox.addListener("lines:changed" as eventName, callback);
function createButton(props: { onClick: (event: MouseEvent) => void }) {
const div = document.createElement("div");
div.style.position = "absolute";
div.style.left = "-1em";
div.style.zIndex = "900";
div.textContent = "▶";
div.dataset.id = "jupyter-button";
div.addEventListener("click", props.onClick);
return div;
}
code:bundler.ts
await initialize({
});
export async function bundle(contents: string) {
const { outputFiles } = await build({
stdin: {
contents,
loader: "tsx",
},
format: "esm",
bundle: true,
minify: true,
jsxFactory: "h",
jsxFragment: "Fragment",
charset: "utf8",
write: false,
});
return outputFiles0.text; }
code:codeFile.ts
type File = {
filename?: string;
lang: string;
/** コードブロックの開始行のid */ startIds: string[];
lines: string[];
};
declare const scrapbox: Scrapbox;
export function getCodeFiles() {
const codeBlocks =
scrapbox.Page.lines?.flatMap((line) => "codeBlock" in line ? line : []) ?? [];
return codeBlocks.reduce((acc: File[], { codeBlock, text, id }) => {
const sameFileIndex = acc.findIndex(({ filename }) =>
filename !== undefined && filename === codeBlock.filename
);
// code blockの先頭かつ新しいコードブロックのときのみ新しいfileを追加する
if (codeBlock.start && sameFileIndex < 0) {
return [...acc, {
filename: codeBlock.filename,
lang: codeBlock.lang,
lines: [] as string[],
}];
}
if (codeBlock.start) {
acc.at(sameFileIndex)?.startIds?.push?.(id);
} else {
// 既存のコードブロックもしくは末尾のコードブロックに追記する
acc.at(sameFileIndex)?.lines?.push?.(text);
}
return acc;
}, []);
}
build
code:sh
code:script.js
function Ie(){return(scrapbox.Page.lines?.flatMap(t=>"codeBlock"in t?t:[])??[]).reduce((t,{codeBlock:r,text:l,id:c})=>{let a=t.findIndex(({filename:i})=>i!==void 0&&i===r.filename);return r.start&&a<0?[...t,{filename:r.filename,lang:r.lang,startIds:c,lines:[]}]:(r.start?t.at(a)?.startIds?.push?.(c):t.at(a)?.lines?.push?.(l),t)},[])}var Xe=Object.defineProperty,Ze=Object.defineProperties,et=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,Te=(e,t,r)=>t in e?Xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):et=r,Ae=(e,t)=>{for(var r in t||(t={}))tt.call(t,r)&&Te(e,r,tr);if(Oe)for(var r of Oe(t))rt.call(t,r)&&Te(e,r,tr);return e},Ue=(e,t)=>Ze(e,et(t));function Ne(e){let t=l=>{if(l===null)r.write8(0);else if(typeof l=="boolean")r.write8(1),r.write8(+l);else if(typeof l=="number")r.write8(2),r.write32(l|0);else if(typeof l=="string")r.write8(3),r.write(ae(l));else if(l instanceof Uint8Array)r.write8(4),r.write(l);else if(l instanceof Array){r.write8(5),r.write32(l.length);for(let c of l)t(c)}else{let c=Object.keys(l);r.write8(6),r.write32(c.length);for(let a of c)r.write(ae(a)),t(la)}},r=new Pe;return r.write32(0),r.write32(e.id<<1|+!e.isRequest),t(e.value),$e(r.buf,r.len-4,0),r.buf.subarray(0,r.len)}function nt(e){let t=()=>{switch(r.read8()){case 0:return null;case 1:return!!r.read8();case 2:return r.read32();case 3:return he(r.read());case 4:return r.read();case 5:{let i=r.read32(),g=[];for(let o=0;o<i;o++)g.push(t());return g}case 6:{let i=r.read32(),g={};for(let o=0;o<i;o++)ghe(r.read())=t();return g}default:throw new Error("Invalid packet")}},r=new Pe(e),l=r.read32(),c=(l&1)==0;l>>>=1;let a=t();if(r.ptr!==e.length)throw new Error("Invalid packet");return{id:l,isRequest:c,value:a}}var Pe=class{constructor(e=new Uint8Array(1024)){this.buf=e,this.len=0,this.ptr=0}_write(e){if(this.len+e>this.buf.length){let t=new Uint8Array((this.len+e)*2);t.set(this.buf),this.buf=t}return this.len+=e,this.len-e}write8(e){let t=this._write(1);this.buft=e}write32(e){let t=this._write(4);$e(this.buf,e,t)}write(e){let t=this._write(4+e.length);$e(this.buf,e.length,t),this.buf.set(e,t+4)}_read(e){if(this.ptr+e>this.buf.length)throw new Error("Invalid packet");return this.ptr+=e,this.ptr-e}read8(){return this.bufthis._read(1)}read32(){return Fe(this.buf,this._read(4))}read(){let e=this.read32(),t=new Uint8Array(e),r=this._read(t.length);return t.set(this.buf.subarray(r,r+e)),t}},ae,he;if(typeof TextEncoder!="undefined"&&typeof TextDecoder!="undefined"){let e=new TextEncoder,t=new TextDecoder;ae=r=>e.encode(r),he=r=>t.decode(r)}else if(typeof Buffer!="undefined")ae=e=>{let t=Buffer.from(e);return t instanceof Uint8Array||(t=new Uint8Array(t)),t},he=e=>{let{buffer:t,byteOffset:r,byteLength:l}=e;return Buffer.from(t,r,l).toString()};else throw new Error("No UTF-8 codec found");function Fe(e,t){return et++|et++<<8|et++<<16|et++<<24}function $e(e,t,r){er++=t,er++=t>>8,er++=t>>16,er++=t>>24}function Ce(e){if(e+="",e.indexOf(",")>=0)throw new Error(Invalid target: ${e});return e}var je=()=>null,J=e=>typeof e=="boolean"?null:"a boolean",st=e=>typeof e=="boolean"||typeof e=="object"&&!Array.isArray(e)?null:"a boolean or an object",w=e=>typeof e=="string"?null:"a string",Me=e=>e instanceof RegExp?null:"a RegExp object",de=e=>typeof e=="number"&&e===(e|0)?null:"an integer",Se=e=>typeof e=="function"?null:"a function",B=e=>Array.isArray(e)?null:"an array",me=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)?null:"an object",it=e=>typeof e=="object"&&e!==null?null:"an array or an object",Le=e=>typeof e=="object"&&!Array.isArray(e)?null:"an object or null",Re=e=>typeof e=="string"||typeof e=="boolean"?null:"a string or a boolean",lt=e=>typeof e=="string"||typeof e=="object"&&e!==null&&!Array.isArray(e)?null:"a string or an object",ot=e=>typeof e=="string"||Array.isArray(e)?null:"a string or an array",at=e=>typeof e=="string"||e instanceof Uint8Array?null:"a string or a Uint8Array";function n(e,t,r,l){let c=er;if(tr+""=!0,c===void 0)return;let a=l(c);if(a!==null)throw new Error("${r}" must be ${a});return c}function z(e,t,r){for(let l in e)if(!(l in t))throw new Error(Invalid option ${r}: "${l}")}function ut(e){let t=Object.create(null),r=n(e,t,"wasmURL",w),l=n(e,t,"worker",J);return z(e,t,"in startService() call"),{wasmURL:r,worker:l}}function xe(e,t,r,l,c){let a=n(t,r,"color",J),i=n(t,r,"logLevel",w),g=n(t,r,"logLimit",de);a!==void 0?e.push(--color=${a}):l&&e.push("--color=true"),e.push(--log-level=${i||c}),e.push(--log-limit=${g||0})}function qe(e,t,r){let l=n(t,r,"legalComments",w),c=n(t,r,"sourceRoot",w),a=n(t,r,"sourcesContent",J),i=n(t,r,"target",ot),g=n(t,r,"format",w),o=n(t,r,"globalName",w),v=n(t,r,"minify",J),$=n(t,r,"minifySyntax",J),N=n(t,r,"minifyWhitespace",J),W=n(t,r,"minifyIdentifiers",J),j=n(t,r,"charset",w),P=n(t,r,"treeShaking",Re),ee=n(t,r,"jsx",w),Q=n(t,r,"jsxFactory",w),ne=n(t,r,"jsxFragment",w),te=n(t,r,"define",me),le=n(t,r,"pure",B),oe=n(t,r,"keepNames",J);if(l&&e.push(--legal-comments=${l}),c!==void 0&&e.push(--source-root=${c}),a!==void 0&&e.push(--sources-content=${a}),i&&(Array.isArray(i)?e.push(--target=${Array.from(i).map(Ce).join(",")}):e.push(--target=${Ce(i)})),g&&e.push(--format=${g}),o&&e.push(--global-name=${o}),v&&e.push("--minify"),$&&e.push("--minify-syntax"),N&&e.push("--minify-whitespace"),W&&e.push("--minify-identifiers"),j&&e.push(--charset=${j}),P!==void 0&&P!==!0&&e.push(--tree-shaking=${P}),ee&&e.push(--jsx=${ee}),Q&&e.push(--jsx-factory=${Q}),ne&&e.push(--jsx-fragment=${ne}),te)for(let G in te){if(G.indexOf("=")>=0)throw new Error(Invalid define: ${G});e.push(--define:${G}=${te[G]})}if(le)for(let G of le)e.push(--pure:${G});oe&&e.push("--keep-names")}function ct(e,t,r,l,c){var a;let i=[],g=[],o=Object.create(null),v=null,$=null,N=null;xe(i,t,o,r,l),qe(i,t,o);let W=n(t,o,"sourcemap",Re),j=n(t,o,"bundle",J),P=n(t,o,"watch",st),ee=n(t,o,"splitting",J),Q=n(t,o,"preserveSymlinks",J),ne=n(t,o,"metafile",J),te=n(t,o,"outfile",w),le=n(t,o,"outdir",w),oe=n(t,o,"outbase",w),G=n(t,o,"platform",w),ve=n(t,o,"tsconfig",w),be=n(t,o,"resolveExtensions",B),m=n(t,o,"nodePaths",B),h=n(t,o,"mainFields",B),u=n(t,o,"conditions",B),p=n(t,o,"external",B),C=n(t,o,"loader",me),T=n(t,o,"outExtension",me),R=n(t,o,"publicPath",w),M=n(t,o,"entryNames",w),_=n(t,o,"chunkNames",w),S=n(t,o,"assetNames",w),b=n(t,o,"inject",B),D=n(t,o,"banner",me),x=n(t,o,"footer",me),k=n(t,o,"entryPoints",it),E=n(t,o,"absWorkingDir",w),d=n(t,o,"stdin",me),y=(a=n(t,o,"write",J))!=null?a:c,A=n(t,o,"allowOverwrite",J),U=n(t,o,"incremental",J)===!0;if(o.plugins=!0,z(t,o,in ${e}() call),W&&i.push(--sourcemap${W===!0?"":=${W}}),j&&i.push("--bundle"),A&&i.push("--allow-overwrite"),P)if(i.push("--watch"),typeof P=="boolean")N={};else{let s=Object.create(null),f=n(P,s,"onRebuild",Se);z(P,s,on "watch" in ${e}() call),N={onRebuild:f}}if(ee&&i.push("--splitting"),Q&&i.push("--preserve-symlinks"),ne&&i.push("--metafile"),te&&i.push(--outfile=${te}),le&&i.push(--outdir=${le}),oe&&i.push(--outbase=${oe}),G&&i.push(--platform=${G}),ve&&i.push(--tsconfig=${ve}),be){let s=[];for(let f of be){if(f+="",f.indexOf(",")>=0)throw new Error(Invalid resolve extension: ${f});s.push(f)}i.push(--resolve-extensions=${s.join(",")})}if(R&&i.push(--public-path=${R}),M&&i.push(--entry-names=${M}),_&&i.push(--chunk-names=${_}),S&&i.push(--asset-names=${S}),h){let s=[];for(let f of h){if(f+="",f.indexOf(",")>=0)throw new Error(Invalid main field: ${f});s.push(f)}i.push(--main-fields=${s.join(",")})}if(u){let s=[];for(let f of u){if(f+="",f.indexOf(",")>=0)throw new Error(Invalid condition: ${f});s.push(f)}i.push(--conditions=${s.join(",")})}if(p)for(let s of p)i.push(--external:${s});if(D)for(let s in D){if(s.indexOf("=")>=0)throw new Error(Invalid banner file type: ${s});i.push(--banner:${s}=${D[s]})}if(x)for(let s in x){if(s.indexOf("=")>=0)throw new Error(Invalid footer file type: ${s});i.push(--footer:${s}=${x[s]})}if(b)for(let s of b)i.push(--inject:${s});if(C)for(let s in C){if(s.indexOf("=")>=0)throw new Error(Invalid loader extension: ${s});i.push(--loader:${s}=${C[s]})}if(T)for(let s in T){if(s.indexOf("=")>=0)throw new Error(Invalid out extension: ${s});i.push(--out-extension:${s}=${T[s]})}if(k)if(Array.isArray(k))for(let s of k)g.push("",s+"");else for(lets,fof Object.entries(k))g.push(s+"",f+"");if(d){let s=Object.create(null),f=n(d,s,"contents",w),L=n(d,s,"resolveDir",w),F=n(d,s,"sourcefile",w),q=n(d,s,"loader",w);z(d,s,'in "stdin" object'),F&&i.push(--sourcefile=${F}),q&&i.push(--loader=${q}),L&&($=L+""),v=f?f+"":""}let I=[];if(m)for(let s of m)s+="",I.push(s);return{entries:g,flags:i,write:y,stdinContents:v,stdinResolveDir:$,absWorkingDir:E,incremental:U,nodePaths:I,watch:N}}function ft(e,t,r,l){let c=[],a=Object.create(null);xe(c,t,a,r,l),qe(c,t,a);let i=n(t,a,"sourcemap",Re),g=n(t,a,"tsconfigRaw",lt),o=n(t,a,"sourcefile",w),v=n(t,a,"loader",w),$=n(t,a,"banner",w),N=n(t,a,"footer",w);return z(t,a,in ${e}() call),i&&c.push(--sourcemap=${i===!0?"external":i}),g&&c.push(--tsconfig-raw=${typeof g=="string"?g:JSON.stringify(g)}),o&&c.push(--sourcefile=${o}),v&&c.push(--loader=${v}),$&&c.push(--banner=${$}),N&&c.push(--footer=${N}),c}function ht(e){let t=new Map,r=new Map,l=new Map,c=new Map,a=0,i=!1,g=0,o=0,v=new Uint8Array(16*1024),$=0,N=m=>{let h=$+m.length;if(h>v.length){let p=new Uint8Array(h*2);p.set(v),v=p}v.set(m,$),$+=m.length;let u=0;for(;u+4<=$;){let p=Fe(v,u);if(u+4+p>$)break;u+=4,ne(v.subarray(u,u+p)),u+=p}u>0&&(v.copyWithin(0,u,$),$-=u)},W=()=>{i=!0;for(let m of t.values())m("The service was stopped",null);t.clear();for(let m of c.values())m.onWait("The service was stopped");c.clear();for(let m of l.values())try{m(new Error("The service was stopped"),null)}catch(h){console.error(h)}l.clear()},j=(m,h,u)=>{if(i)return u("The service is no longer running",null);let p=g++;t.set(p,(C,T)=>{try{u(C,T)}finally{m&&m.unref()}}),m&&m.ref(),e.writeToStdin(Ne({id:p,isRequest:!0,value:h}))},P=(m,h)=>{if(i)throw new Error("The service is no longer running");e.writeToStdin(Ne({id:m,isRequest:!1,value:h}))},ee=async(m,h)=>{try{switch(h.command){case"ping":{P(m,{});break}case"start":{let u=r.get(h.key);u?P(m,await u(h)):P(m,{});break}case"resolve":{let u=r.get(h.key);u?P(m,await u(h)):P(m,{});break}case"load":{let u=r.get(h.key);u?P(m,await u(h)):P(m,{});break}case"serve-request":{let u=c.get(h.serveID);u&&u.onRequest&&u.onRequest(h.args),P(m,{});break}case"serve-wait":{let u=c.get(h.serveID);u&&u.onWait(h.error),P(m,{});break}case"watch-rebuild":{let u=l.get(h.watchID);try{u&&u(null,h.args)}catch(p){console.error(p)}P(m,{});break}default:throw new Error("Invalid command: "+h.command)}}catch(u){P(m,{errors:pe(u,e,null,void 0,"")})}},Q=!0,ne=m=>{if(Q){Q=!1;let u=String.fromCharCode(...m);if(u!=="0.12.22")throw new Error(Cannot start service: Host version "0.12.22" does not match binary version ${JSON.stringify(u)});return}let h=nt(m);if(h.isRequest)ee(h.id,h.value);else{let u=t.get(h.id);t.delete(h.id),h.value.error?u(h.value.error,{}):u(null,h.value)}},te=async(m,h,u,p)=>{let C=[],T=[],R={},M={},_=0,S=0,b=[];h=...h;for(let E of h){let d={};if(typeof E!="object")throw new Error(Plugin at index ${S} must be an object);let y=n(E,d,"name",w);if(typeof y!="string"||y==="")throw new Error(Plugin at index ${S} is missing a name);try{let A=n(E,d,"setup",Se);if(typeof A!="function")throw new Error("Plugin is missing a setup function");z(E,d,on plugin ${JSON.stringify(y)});let U={name:y,onResolve:[],onLoad:[]};S++;let I=A({initialOptions:m,onStart(s){let f='This error came from the "onStart" callback registered here',L=Ee(new Error(f),e,"onStart");C.push({name:y,callback:s,note:L})},onEnd(s){let f='This error came from the "onEnd" callback registered here',L=Ee(new Error(f),e,"onEnd");T.push({name:y,callback:s,note:L})},onResolve(s,f){let L='This error came from the "onResolve" callback registered here',F=Ee(new Error(L),e,"onResolve"),q={},Y=n(s,q,"filter",Me),H=n(s,q,"namespace",w);if(z(s,q,in onResolve() call for plugin ${JSON.stringify(y)}),Y==null)throw new Error("onResolve() call is missing a filter");let V=_++;RV={name:y,callback:f,note:F},U.onResolve.push({id:V,filter:Y.source,namespace:H||""})},onLoad(s,f){let L='This error came from the "onLoad" callback registered here',F=Ee(new Error(L),e,"onLoad"),q={},Y=n(s,q,"filter",Me),H=n(s,q,"namespace",w);if(z(s,q,in onLoad() call for plugin ${JSON.stringify(y)}),Y==null)throw new Error("onLoad() call is missing a filter");let V=_++;MV={name:y,callback:f,note:F},U.onLoad.push({id:V,filter:Y.source,namespace:H||""})}});I&&await I,b.push(U)}catch(A){return{ok:!1,error:A,pluginName:y}}}let D=async E=>{switch(E.command){case"start":{let d={errors:[],warnings:[]};return await Promise.all(C.map(async({name:y,callback:A,note:U})=>{try{let I=await A();if(I!=null){if(typeof I!="object")throw new Error(Expected onStart() callback in plugin ${JSON.stringify(y)} to return an object);let s={},f=n(I,s,"errors",B),L=n(I,s,"warnings",B);z(I,s,from onStart() callback in plugin ${JSON.stringify(y)}),f!=null&&d.errors.push(...ue(f,"errors",p,y)),L!=null&&d.warnings.push(...ue(L,"warnings",p,y))}}catch(I){d.errors.push(pe(I,e,p,U&&U(),y))}})),d}case"resolve":{let d={},y="",A,U;for(let I of E.ids)try{({name:y,callback:A,note:U}=RI);let s=await A({path:E.path,importer:E.importer,namespace:E.namespace,resolveDir:E.resolveDir,kind:E.kind,pluginData:p.load(E.pluginData)});if(s!=null){if(typeof s!="object")throw new Error(Expected onResolve() callback in plugin ${JSON.stringify(y)} to return an object);let f={},L=n(s,f,"pluginName",w),F=n(s,f,"path",w),q=n(s,f,"namespace",w),Y=n(s,f,"external",J),H=n(s,f,"sideEffects",J),V=n(s,f,"pluginData",je),se=n(s,f,"errors",B),ie=n(s,f,"warnings",B),O=n(s,f,"watchFiles",B),K=n(s,f,"watchDirs",B);z(s,f,from onResolve() callback in plugin ${JSON.stringify(y)}),d.id=I,L!=null&&(d.pluginName=L),F!=null&&(d.path=F),q!=null&&(d.namespace=q),Y!=null&&(d.external=Y),H!=null&&(d.sideEffects=H),V!=null&&(d.pluginData=p.store(V)),se!=null&&(d.errors=ue(se,"errors",p,y)),ie!=null&&(d.warnings=ue(ie,"warnings",p,y)),O!=null&&(d.watchFiles=ke(O,"watchFiles")),K!=null&&(d.watchDirs=ke(K,"watchDirs"));break}}catch(s){return{id:I,errors:pe(s,e,p,U&&U(),y)}}return d}case"load":{let d={},y="",A,U;for(let I of E.ids)try{({name:y,callback:A,note:U}=MI);let s=await A({path:E.path,namespace:E.namespace,pluginData:p.load(E.pluginData)});if(s!=null){if(typeof s!="object")throw new Error(Expected onLoad() callback in plugin ${JSON.stringify(y)} to return an object);let f={},L=n(s,f,"pluginName",w),F=n(s,f,"contents",at),q=n(s,f,"resolveDir",w),Y=n(s,f,"pluginData",je),H=n(s,f,"loader",w),V=n(s,f,"errors",B),se=n(s,f,"warnings",B),ie=n(s,f,"watchFiles",B),O=n(s,f,"watchDirs",B);z(s,f,from onLoad() callback in plugin ${JSON.stringify(y)}),d.id=I,L!=null&&(d.pluginName=L),F instanceof Uint8Array?d.contents=F:F!=null&&(d.contents=ae(F)),q!=null&&(d.resolveDir=q),Y!=null&&(d.pluginData=p.store(Y)),H!=null&&(d.loader=H),V!=null&&(d.errors=ue(V,"errors",p,y)),se!=null&&(d.warnings=ue(se,"warnings",p,y)),ie!=null&&(d.watchFiles=ke(ie,"watchFiles")),O!=null&&(d.watchDirs=ke(O,"watchDirs"));break}}catch(s){return{id:I,errors:pe(s,e,p,U&&U(),y)}}return d}default:throw new Error("Invalid command: "+E.command)}},x=(E,d,y)=>y();T.length>0&&(x=(E,d,y)=>{(async()=>{for(let{name:A,callback:U,note:I}of T)try{await U(E)}catch(s){E.errors.push(await new Promise(f=>d(s,A,I&&I(),f)))}})().then(y)});let k=0;return{ok:!0,requestPlugins:b,runOnEndCallbacks:x,pluginRefs:{ref(){++k==1&&r.set(u,D)},unref(){--k==0&&r.delete(u)}}}},le=(m,h,u)=>{let p={},C=n(h,p,"port",de),T=n(h,p,"host",w),R=n(h,p,"servedir",w),M=n(h,p,"onRequest",Se),_=a++,S,b=new Promise((D,x)=>{S=k=>{c.delete(_),k!==null?x(new Error(k)):D()}});return u.serve={serveID:_},z(h,p,"in serve() call"),C!==void 0&&(u.serve.port=C),T!==void 0&&(u.serve.host=T),R!==void 0&&(u.serve.servedir=R),c.set(_,{onRequest:M,onWait:S}),{wait:b,stop(){j(m,{command:"serve-stop",serveID:_},()=>{})}}},oe="warning",G="silent",ve=m=>{let h=o++,u=We(),p,{refs:C,options:T,isTTY:R,callback:M}=m;if(typeof T=="object"){let b=T.plugins;if(b!==void 0){if(!Array.isArray(b))throw new Error('"plugins" must be an array');p=b}}let _=(b,D,x,k)=>{let E=[];try{xe(E,T,{},R,oe)}catch(y){}let d=pe(b,e,u,x,D);j(C,{command:"error",flags:E,error:d},()=>{d.detail=u.load(d.detail),k(d)})},S=(b,D)=>{_(b,D,void 0,x=>{M(ge("Build failed",x,[]),null)})};if(p&&p.length>0){if(e.isSync)return S(new Error("Cannot use plugins in synchronous API calls"),"");te(T,p,h,u).then(b=>{if(!b.ok)S(b.error,b.pluginName);else try{be(Ue(Ae({},m),{key:h,details:u,logPluginError:_,requestPlugins:b.requestPlugins,runOnEndCallbacks:b.runOnEndCallbacks,pluginRefs:b.pluginRefs}))}catch(D){S(D,"")}},b=>S(b,""))}else try{be(Ue(Ae({},m),{key:h,details:u,logPluginError:_,requestPlugins:null,runOnEndCallbacks:(b,D,x)=>x(),pluginRefs:null}))}catch(b){S(b,"")}},be=({callName:m,refs:h,serveOptions:u,options:p,isTTY:C,defaultWD:T,callback:R,key:M,details:_,logPluginError:S,requestPlugins:b,runOnEndCallbacks:D,pluginRefs:x})=>{let k={ref(){x&&x.ref(),h&&h.ref()},unref(){x&&x.unref(),h&&h.unref()}},E=!e.isBrowser,{entries:d,flags:y,write:A,stdinContents:U,stdinResolveDir:I,absWorkingDir:s,incremental:f,nodePaths:L,watch:F}=ct(m,p,C,oe,E),q={command:"build",key:M,entries:d,flags:y,write:A,stdinContents:U,stdinResolveDir:I,absWorkingDir:s||T,incremental:f,nodePaths:L};b&&(q.plugins=b);let Y=u&&le(k,u,q),H,V,se=(O,K)=>{O.outputFiles&&(K.outputFiles=O.outputFiles.map(dt)),O.metafile&&(K.metafile=JSON.parse(O.metafile)),O.writeToStdout!==void 0&&console.log(he(O.writeToStdout).replace(/\n$/,""))},ie=(O,K)=>{let X={errors:we(O.errors,_),warnings:we(O.warnings,_)};se(O,X),D(X,S,()=>{if(X.errors.length>0)return K(ge("Build failed",X.errors,X.warnings),null);if(O.rebuildID!==void 0){if(!H){let re=!1;H=()=>new Promise((ce,fe)=>{if(re||i)throw new Error("Cannot rebuild");j(k,{command:"rebuild",rebuildID:O.rebuildID},(Z,Ke)=>{if(Z)return K(ge("Build failed",[{pluginName:"",text:Z,location:null,notes:[],detail:void 0}],[]),null);ie(Ke,(De,Qe)=>{De?fe(De):ce(Qe)})})}),k.ref(),H.dispose=()=>{re||(re=!0,j(k,{command:"rebuild-dispose",rebuildID:O.rebuildID},()=>{}),k.unref())}}X.rebuild=H}if(O.watchID!==void 0){if(!V){let re=!1;k.ref(),V=()=>{re||(re=!0,l.delete(O.watchID),j(k,{command:"watch-stop",watchID:O.watchID},()=>{}),k.unref())},F&&l.set(O.watchID,(ce,fe)=>{if(ce){F.onRebuild&&F.onRebuild(ce,null);return}let Z={errors:we(fe.errors,_),warnings:we(fe.warnings,_)};se(fe,Z),D(Z,S,()=>{if(Z.errors.length>0){F.onRebuild&&F.onRebuild(ge("Build failed",Z.errors,Z.warnings),null);return}fe.rebuildID!==void 0&&(Z.rebuild=H),Z.stop=V,F.onRebuild&&F.onRebuild(null,Z)})})}X.stop=V}K(null,X)})};if(A&&e.isBrowser)throw new Error('Cannot enable "write" in the browser');if(f&&e.isSync)throw new Error('Cannot use "incremental" with a synchronous build');j(k,q,(O,K)=>{if(O)return R(new Error(O),null);if(Y){let X=K,re=!1;k.ref();let ce={port:X.port,host:X.host,wait:Y.wait,stop(){re||(re=!0,Y.stop(),k.unref())}};return k.ref(),Y.wait.then(k.unref,k.unref),R(null,ce)}return ie(K,R)})};return{readFromStdout:N,afterClose:W,service:{buildOrServe:ve,transform:({callName:m,refs:h,input:u,options:p,isTTY:C,fs:T,callback:R})=>{let M=We(),_=S=>{try{if(typeof u!="string")throw new Error('The input to "transform" must be a string');let b=ft(m,p,C,G);j(h,{command:"transform",flags:b,inputFS:S!==null,input:S!==null?S:u},(D,x)=>{if(D)return R(new Error(D),null);let k=we(x.errors,M),E=we(x.warnings,M),d=1,y=()=>--d==0&&R(null,{warnings:E,code:x.code,map:x.map});if(k.length>0)return R(ge("Transform failed",k,E),null);x.codeFS&&(d++,T.readFile(x.code,(A,U)=>{A!==null?R(A,null):(x.code=U,y())})),x.mapFS&&(d++,T.readFile(x.map,(A,U)=>{A!==null?R(A,null):(x.map=U,y())})),y()})}catch(b){let D=[];try{xe(D,p,{},C,G)}catch(k){}let x=pe(b,e,M,void 0,"");j(h,{command:"error",flags:D,error:x},()=>{x.detail=M.load(x.detail),R(ge("Transform failed",x,[]),null)})}};if(typeof u=="string"&&u.length>1024*1024){let S=_;_=()=>T.writeFile(u,S)}_(null)},formatMessages:({callName:m,refs:h,messages:u,options:p,callback:C})=>{let T=ue(u,"messages",null,"");if(!p)throw new Error(Missing second argument in ${m}() call);let R={},M=n(p,R,"kind",w),_=n(p,R,"color",J),S=n(p,R,"terminalWidth",de);if(z(p,R,in ${m}() call),M===void 0)throw new Error(Missing "kind" in ${m}() call);if(M!=="error"&&M!=="warning")throw new Error(Expected "kind" to be "error" or "warning" in ${m}() call);let b={command:"format-msgs",messages:T,isWarning:M==="warning"};_!==void 0&&(b.color=_),S!==void 0&&(b.terminalWidth=S),j(h,b,(D,x)=>{if(D)return C(new Error(D),null);C(null,x.messages)})}}}}function We(){let e=new Map,t=0;return{load(r){return e.get(r)},store(r){if(r===void 0)return-1;let l=t++;return e.set(l,r),l}}}function Ee(e,t,r){let l,c=!1;return()=>{if(c)return l;c=!0;try{let a=(e.stack+"").split(` );a.splice(1,1);let i=Je(t,a,r);if(i)return l={text:e.message,location:i},l}catch(a){}}}function pe(e,t,r,l,c){let a="Internal error",i=null;try{a=(e&&e.message||e)+""}catch(g){}try{i=Je(t,(e.stack+"").split(
),"")}catch(g){}return{pluginName:c,text:a,location:i,notes:l?[l]:[],detail:r?r.store(e):-1}}function Je(e,t,r){let l=" at ";if(e.readFileSync&&!t[0].startsWith(l)&&t[1].startsWith(l))for(let c=1;c<t.length;c++){let a=t[c];if(a.startsWith(l))for(a=a.slice(l.length);;){let i=/^(?:new |async )?\S+ \((.*)\)$/.exec(a);if(i){a=i[1];continue}if(i=/^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(a),i){a=i[1];continue}if(i=/^(\S+):(\d+):(\d+)$/.exec(a),i){let g;try{g=e.readFileSync(i[1],"utf8")}catch(N){break}let o=g.split(/\r\n|\r|\n|\u2028|\u2029/)[+i[2]-1]||"",v=+i[3]-1,$=o.slice(v,v+r.length)===r?r.length:0;return{file:i[1],namespace:"file",line:+i[2],column:ae(o.slice(0,v)).length,length:ae(o.slice(v,v+$)).length,lineText:o+
+t.slice(1).join(
),suggestion:""}}break}}return null}function ge(e,t,r){let l=5,c=t.length<1?"": with ${t.length} error${t.length<2?"":"s"}:+t.slice(0,l+1).map((i,g)=>{if(g===l)return
...;if(!i.location)return
${o}:${v}:${$}: error: ${N}${i.text}}).join(""),a=new Error(${e}${c});return a.errors=t,a.warnings=r,a}function we(e,t){for(let r of e)r.detail=t.load(r.detail);return e}function Be(e,t){if(e==null)return null;let r={},l=n(e,r,"file",w),c=n(e,r,"namespace",w),a=n(e,r,"line",de),i=n(e,r,"column",de),g=n(e,r,"length",de),o=n(e,r,"lineText",w),v=n(e,r,"suggestion",w);return z(e,r,t),{file:l||"",namespace:c||"",line:a||0,column:i||0,length:g||0,lineText:o||"",suggestion:v||""}}function ue(e,t,r,l){let c=[],a=0;for(let i of e){let g={},o=n(i,g,"pluginName",w),v=n(i,g,"text",w),$=n(i,g,"location",Le),N=n(i,g,"notes",B),W=n(i,g,"detail",je),j=in element ${a} of "${t}";z(i,g,j);let P=[];if(N)for(let ee of N){let Q={},ne=n(ee,Q,"text",w),te=n(ee,Q,"location",Le);z(ee,Q,j),P.push({text:ne||"",location:Be(te,j)})}c.push({pluginName:o||l,text:v||"",location:Be($,j),notes:P,detail:r?r.store(W):-1}),a++}return c}function ke(e,t){let r=[];for(let l of e){if(typeof l!="string")throw new Error(${JSON.stringify(t)} must be an array of strings);r.push(l)}return r}function dt({path:e,contents:t}){let r=null;return{path:e,contents:t,get text(){return r===null&&(r=he(t)),r}}}var Ye=e=>mt().build(e);var ye,_e,mt=()=>{if(_e)return _e;throw ye?new Error('You need to wait for the promise returned from "initialize" to be resolved before calling this'):new Error('You need to call "initialize" before calling this')},Ve=e=>{e=ut(e||{});let t=e.wasmURL,r=e.worker!==!1;if(!t)throw new Error('Must provide the "wasmURL" option');if(t+="",ye)throw new Error('Cannot call "initialize" more than once');return ye=pt(t,r),ye.catch(()=>{ye=void 0}),ye},pt=async(e,t)=>{let r=await fetch(e);if(!r.ok)throw new Error(Failed to download ${JSON.stringify(e)});let l=await r.arrayBuffer(),c='{let global={};for(let o=self;o;o=Object.getPrototypeOf(o))for(let k of Object.getOwnPropertyNames(o))if(!(k in global))Object.defineProperty(global,k,{get:()=>self[k]});\n// Copyright 2018 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n(()=>{if(typeof global=="undefined")if(typeof window!="undefined")window.global=window;else if(typeof self!="undefined")self.global=self;else throw new Error("cannot export Go (neither global, window nor self is defined)");if(!global.require&&typeof require!="undefined"&&(global.require=require),!global.fs&&global.require){const r=require("fs");typeof r=="object"&&r!==null&&Object.keys(r).length!==0&&(global.fs=Object.assign({},r,{write(i,s,n,l,f,h){if(n===0&&l===s.length&&f===null){if(i===process.stdout.fd){try{process.stdout.write(s,u=>u?h(u,0,null):h(null,l,s))}catch(u){h(u,0,null)}return}if(i===process.stderr.fd){try{process.stderr.write(s,u=>u?h(u,0,null):h(null,l,s))}catch(u){h(u,0,null)}return}}r.write(i,s,n,l,f,h)}}))}const a=()=>{const r=new Error("not implemented");return r.code="ENOSYS",r};if(!global.fs){let r="";global.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1},writeSync(i,s){r+=g.decode(s);const n=r.lastIndexOf(\n);return n!=-1&&(console.log(r.substr(0,n)),r=r.substr(n+1)),s.length},write(i,s,n,l,f,h){if(n!==0||l!==s.length||f!==null){h(a());return}const u=this.writeSync(i,s);h(null,u)},chmod(i,s,n){n(a())},chown(i,s,n,l){l(a())},close(i,s){s(a())},fchmod(i,s,n){n(a())},fchown(i,s,n,l){l(a())},fstat(i,s){s(a())},fsync(i,s){s(null)},ftruncate(i,s,n){n(a())},lchown(i,s,n,l){l(a())},link(i,s,n){n(a())},lstat(i,s){s(a())},mkdir(i,s,n){n(a())},open(i,s,n,l){l(a())},read(i,s,n,l,f,h){h(a())},readdir(i,s){s(a())},readlink(i,s){s(a())},rename(i,s,n){n(a())},rmdir(i,s){s(a())},stat(i,s){s(a())},symlink(i,s,n){n(a())},truncate(i,s,n){n(a())},unlink(i,s){s(a())},utimes(i,s,n,l){l(a())}}}if(global.process||(global.process={getuid(){return-1},getgid(){return-1},geteuid(){return-1},getegid(){return-1},getgroups(){throw a()},pid:-1,ppid:-1,umask(){throw a()},cwd(){throw a()},chdir(){throw a()}}),!global.crypto&&global.require){const r=require("crypto");global.crypto={getRandomValues(i){r.randomFillSync(i)}}}if(!global.crypto)throw new Error("global.crypto is not available, polyfill required (getRandomValues only)");if(global.performance||(global.performance={now(){const[r,i]=process.hrtime();return r*1e3+i/1e6}}),!global.TextEncoder&&global.require&&(global.TextEncoder=require("util").TextEncoder),!global.TextEncoder)throw new Error("global.TextEncoder is not available, polyfill required");if(!global.TextDecoder&&global.require&&(global.TextDecoder=require("util").TextDecoder),!global.TextDecoder)throw new Error("global.TextDecoder is not available, polyfill required");const d=new TextEncoder("utf-8"),g=new TextDecoder("utf-8");if(global.Go=class{constructor(){this.argv=["js"],this.env={},this.exit=e=>{e!==0&&console.warn("exit code:",e)},this._exitPromise=new Promise(e=>{this._resolveExitPromise=e}),this._pendingEvent=null,this._scheduledTimeouts=new Map,this._nextCallbackTimeoutID=1;const r=(e,t)=>{this.mem.setUint32(e+0,t,!0),this.mem.setUint32(e+4,Math.floor(t/4294967296),!0)},i=e=>{const t=this.mem.getUint32(e+0,!0),o=this.mem.getInt32(e+4,!0);return t+o*4294967296},s=e=>{const t=this.mem.getFloat64(e,!0);if(t===0)return;if(!isNaN(t))return t;const o=this.mem.getUint32(e,!0);return this._values[o]},n=(e,t)=>{const o=2146959360;if(typeof t=="number"&&t!==0){if(isNaN(t)){this.mem.setUint32(e+4,o,!0),this.mem.setUint32(e,0,!0);return}this.mem.setFloat64(e,t,!0);return}if(t===void 0){this.mem.setFloat64(e,0,!0);return}let c=this._ids.get(t);c===void 0&&(c=this._idPool.pop(),c===void 0&&(c=this._values.length),this._values[c]=t,this._goRefCounts[c]=0,this._ids.set(t,c)),this._goRefCounts[c]++;let m=0;switch(typeof t){case"object":t!==null&&(m=1);break;case"string":m=2;break;case"symbol":m=3;break;case"function":m=4;break}this.mem.setUint32(e+4,o|m,!0),this.mem.setUint32(e,c,!0)},l=e=>{const t=i(e+0),o=i(e+8);return new Uint8Array(this._inst.exports.mem.buffer,t,o)},f=e=>{const t=i(e+0),o=i(e+8),c=new Array(o);for(let m=0;m<o;m++)c[m]=s(t+m*8);return c},h=e=>{const t=i(e+0),o=i(e+8);return g.decode(new DataView(this._inst.exports.mem.buffer,t,o))},u=Date.now()-performance.now();this.importObject={go:{"runtime.wasmExit":e=>{e>>>=0;const t=this.mem.getInt32(e+8,!0);this.exited=!0,delete this._inst,delete this._values,delete this._goRefCounts,delete this._ids,delete this._idPool,this.exit(t)},"runtime.wasmWrite":e=>{e>>>=0;const t=i(e+8),o=i(e+16),c=this.mem.getInt32(e+24,!0);fs.writeSync(t,new Uint8Array(this._inst.exports.mem.buffer,o,c))},"runtime.resetMemoryDataView":e=>{e>>>=0,this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":e=>{e>>>=0,r(e+8,(u+performance.now())*1e6)},"runtime.walltime":e=>{e>>>=0;const t=new Date().getTime();r(e+8,t/1e3),this.mem.setInt32(e+16,t%1e3*1e6,!0)},"runtime.scheduleTimeoutEvent":e=>{e>>>=0;const t=this._nextCallbackTimeoutID;this._nextCallbackTimeoutID++,this._scheduledTimeouts.set(t,setTimeout(()=>{for(this._resume();this._scheduledTimeouts.has(t);)console.warn("scheduleTimeoutEvent: missed timeout event"),this._resume()},i(e+8)+1)),this.mem.setInt32(e+16,t,!0)},"runtime.clearTimeoutEvent":e=>{e>>>=0;const t=this.mem.getInt32(e+8,!0);clearTimeout(this._scheduledTimeouts.get(t)),this._scheduledTimeouts.delete(t)},"runtime.getRandomData":e=>{e>>>=0,crypto.getRandomValues(l(e+8))},"syscall/js.finalizeRef":e=>{e>>>=0;const t=this.mem.getUint32(e+8,!0);if(this._goRefCounts[t]--,this._goRefCounts[t]===0){const o=this._values[t];this._values[t]=null,this._ids.delete(o),this._idPool.push(t)}},"syscall/js.stringVal":e=>{e>>>=0,n(e+24,h(e+8))},"syscall/js.valueGet":e=>{e>>>=0;const t=Reflect.get(s(e+8),h(e+16));e=this._inst.exports.getsp()>>>0,n(e+32,t)},"syscall/js.valueSet":e=>{e>>>=0,Reflect.set(s(e+8),h(e+16),s(e+32))},"syscall/js.valueDelete":e=>{e>>>=0,Reflect.deleteProperty(s(e+8),h(e+16))},"syscall/js.valueIndex":e=>{e>>>=0,n(e+24,Reflect.get(s(e+8),i(e+16)))},"syscall/js.valueSetIndex":e=>{e>>>=0,Reflect.set(s(e+8),i(e+16),s(e+24))},"syscall/js.valueCall":e=>{e>>>=0;try{const t=s(e+8),o=Reflect.get(t,h(e+16)),c=f(e+32),m=Reflect.apply(o,t,c);e=this._inst.exports.getsp()>>>0,n(e+56,m),this.mem.setUint8(e+64,1)}catch(t){e=this._inst.exports.getsp()>>>0,n(e+56,t),this.mem.setUint8(e+64,0)}},"syscall/js.valueInvoke":e=>{e>>>=0;try{const t=s(e+8),o=f(e+16),c=Reflect.apply(t,void 0,o);e=this._inst.exports.getsp()>>>0,n(e+40,c),this.mem.setUint8(e+48,1)}catch(t){e=this._inst.exports.getsp()>>>0,n(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueNew":e=>{e>>>=0;try{const t=s(e+8),o=f(e+16),c=Reflect.construct(t,o);e=this._inst.exports.getsp()>>>0,n(e+40,c),this.mem.setUint8(e+48,1)}catch(t){e=this._inst.exports.getsp()>>>0,n(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueLength":e=>{e>>>=0,r(e+16,parseInt(s(e+8).length))},"syscall/js.valuePrepareString":e=>{e>>>=0;const t=d.encode(String(s(e+8)));n(e+16,t),r(e+24,t.length)},"syscall/js.valueLoadString":e=>{e>>>=0;const t=s(e+8);l(e+16).set(t)},"syscall/js.valueInstanceOf":e=>{e>>>=0,this.mem.setUint8(e+24,s(e+8)instanceof s(e+16)?1:0)},"syscall/js.copyBytesToGo":e=>{e>>>=0;const t=l(e+8),o=s(e+32);if(!(o instanceof Uint8Array||o instanceof Uint8ClampedArray)){this.mem.setUint8(e+48,0);return}const c=o.subarray(0,t.length);t.set(c),r(e+40,c.length),this.mem.setUint8(e+48,1)},"syscall/js.copyBytesToJS":e=>{e>>>=0;const t=s(e+8),o=l(e+16);if(!(t instanceof Uint8Array||t instanceof Uint8ClampedArray)){this.mem.setUint8(e+48,0);return}const c=o.subarray(0,t.length);t.set(c),r(e+40,c.length),this.mem.setUint8(e+48,1)},debug:e=>{console.log(e)}}}}async run(r){if(!(r instanceof WebAssembly.Instance))throw new Error("Go.run: WebAssembly.Instance expected");this._inst=r,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,global,this],this._goRefCounts=new Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[global,5],[this,6]]),this._idPool=[],this.exited=!1;let i=4096;const s=u=>{const e=i,t=d.encode(u+"\\0");return new Uint8Array(this.mem.buffer,i,t.length).set(t),i+=t.length,i%8!=0&&(i+=8-i%8),e},n=this.argv.length,l=[];this.argv.forEach(u=>{l.push(s(u))}),l.push(0),Object.keys(this.env).sort().forEach(u=>{l.push(s(${u}=${this.envu}))}),l.push(0);const h=i;l.forEach(u=>{this.mem.setUint32(i,u,!0),this.mem.setUint32(i+4,0,!0),i+=8}),this._inst.exports.run(n,h),this.exited&&this._resolveExitPromise(),await this._exitPromise}_resume(){if(this.exited)throw new Error("Go program has already exited");this._inst.exports.resume(),this.exited&&this._resolveExitPromise()}_makeFuncWrapper(r){const i=this;return function(){const s={id:r,this:this,args:arguments};return i._pendingEvent=s,i._resume(),s.result}}},typeof module!="undefined"&&global.require&&global.require.main===module&&global.process&&global.process.versions&&!global.process.versions.electron){process.argv.length<3&&(console.error("usage: go_js_wasm_exec [wasm binary] [arguments]"),process.exit(1));const r=new Go;r.argv=process.argv.slice(2),r.env=Object.assign({TMPDIR:require("os").tmpdir()},process.env),r.exit=process.exit,WebAssembly.instantiate(fs.readFileSync(process.argv[2]),r.importObject).then(i=>(process.on("exit",s=>{s===0&&!r.exited&&(r._pendingEvent={id:0},r._resume())}),r.run(i.instance))).catch(i=>{console.error(i),process.exit(1)})}})();\nonmessage=({data:c})=>{let y=new TextDecoder,s=global.fs,a="";s.writeSync=(e,t)=>{if(e===1)postMessage(t);else if(e===2){a+=y.decode(t);let n=a.split(\n);n.length>1&&console.log(n.slice(0,-1).join(\n)),a=n[n.length-1]}else throw new Error("Bad write");return t.length};let l=[],i,r=0;onmessage=({data:e})=>{e.length>0&&(l.push(e),i&&i())},s.read=(e,t,n,d,h,m)=>{if(e!==0||n!==0||d!==t.length||h!==null)throw new Error("Bad read");if(l.length===0){i=()=>s.read(e,t,n,d,h,m);return}let g=l[0],u=Math.max(0,Math.min(d,g.length-r));t.set(g.subarray(r,r+u),n),r+=u,r===g.length&&(l.shift(),r=0),m(null,u)};let o=new global.Go;o.argv=["","--service=0.12.22"],WebAssembly.instantiate(c,o.importObject).then(({instance:e})=>o.run(e))};}',a;if(t){let o=new Blob([c],{type:"text/javascript"});a=new Worker(URL.createObjectURL(o))}else{let o=new Function("postMessage",c+"var onmessage; return m => onmessage(m)")(v=>a.onmessage({data:v}));a={onmessage:null,postMessage:v=>o({data:v}),terminate(){}}}a.postMessage(l),a.onmessage=({data:o})=>i(o);let{readFromStdout:i,service:g}=ht({writeToStdin(o){a.postMessage(o)},isSync:!1,isBrowser:!0});_e={build:o=>new Promise((v,$)=>g.buildOrServe({callName:"build",refs:null,serveOptions:null,options:o,isTTY:!1,defaultWD:"/",callback:(N,W)=>N?$(N):v(W)})),transform:(o,v)=>new Promise(($,N)=>g.transform({callName:"transform",refs:null,input:o,options:v||{},isTTY:!1,fs:{readFile(W,j){j(new Error("Internal error"),null)},writeFile(W,j){j(null)}},callback:(W,j)=>W?N(W):$(j)})),formatMessages:(o,v)=>new Promise(($,N)=>g.formatMessages({callName:"formatMessages",refs:null,messages:o,options:v,callback:(W,j)=>W?N(W):$(j)}))}};var gt="http-fetch",wt=({onResolve:e,onLoad:t})=>{e({filter:/^https:\/\//},yt),e({filter:/.*/,namespace:"http-fetch"},bt),t({filter:/.*/,namespace:"http-fetch"},vt)},yt=({path:e})=>({path:e,namespace:"http-fetch"}),bt=({path:e,importer:t})=>({path:new URL(e,t).href,namespace:"http-fetch"}),vt=async({path:e})=>{let t=await fetch(e);if(!t.ok){let g=GET ${e} failed: status ${t.status};throw new Error(g)}let r=await t.text(),l=/\/\/# sourceMappingURL=(\S+)/,c=r.match(l);if(c){let g=new URL(c[1],t.url),o=//# sourceMappingURL=${await xt(g)};r=r.replace(l,o)}let{pathname:a}=new URL(t.url),i=a.match(/[^.]+$/)[0];return{contents:r,loader:i}},xt=async e=>{let t=await fetch(e),r=t.headers.get("content-type").replace(/\s/g,""),l=await t.arrayBuffer(),c=new Blob([l],{type:r}),a=new FileReader;return new Promise(i=>{a.onload=g=>i(g.target.result),a.readAsDataURL(c)})},ze={name:gt,setup:wt};await Ve({wasmURL:"https://scrapbox.io/files/61231ff40ef655001d6f7109.wasm"});async function He(e){let{outputFiles:t}=await Ye({stdin:{contents:e,loader:"tsx"},format:"esm",bundle:!0,minify:!0,jsxFactory:"h",jsxFragment:"Fragment",charset:"utf8",plugins:[ze],write:!1});return t[0].text}var Ge=()=>{let e=Ie();document.querySelectorAll('[data-id="jupyter-button"]').forEach(t=>t.remove()),e.forEach(t=>{!["ts","js","tsx","jsx","mjs","javascript","typescript"].includes(t.lang.toLowerCase())||t.startIds.forEach(r=>{let l=document.getElementById(L${r});l?.insertBefore(Et({onClick:async({target:c})=>{c.style.color="red";try{let a=await He(t.lines.join( ));console.log("execute:",a),Function((async()=>{${a}})()`)()}catch(a){console.error(a)}finally{c.style.removeProperty("color")}}}),l?.firstElementChild)})})};Ge();scrapbox.addListener("lines:changed",Ge);function Et(e){let t=document.createElement("div");return t.style.position="absolute",t.style.left="-1em",t.style.zIndex="900",t.textContent="▶",t.dataset.id="jupyter-button",t.addEventListener("click",e.onClick),t}