forked from Willyfrog/silverbullet-plug-template
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathhello.plug.js
More file actions
2 lines (2 loc) · 7.25 KB
/
hello.plug.js
File metadata and controls
2 lines (2 loc) · 7.25 KB
1
2
var h=Object.defineProperty;var v=(e,r)=>{for(var o in r)h(e,o,{get:r[o],enumerable:!0})};function b(e){let r=atob(e),o=r.length,n=new Uint8Array(o);for(let i=0;i<o;i++)n[i]=r.charCodeAt(i);return n}function f(e){typeof e=="string"&&(e=new TextEncoder().encode(e));let r="",o=e.byteLength;for(let n=0;n<o;n++)r+=String.fromCharCode(e[n]);return btoa(r)}var Ge=new Uint8Array(16),w=class{constructor(e="",r=1e3){this.prefix=e,this.maxCaptureSize=r,this.prefix=e,this.originalConsole={log:console.log.bind(console),info:console.info.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),debug:console.debug.bind(console)},this.patchConsole()}originalConsole;logBuffer=[];patchConsole(){let e=r=>(...o)=>{let n=this.prefix?[this.prefix,...o]:o;this.originalConsole[r](...n),this.captureLog(r,o)};console.log=e("log"),console.info=e("info"),console.warn=e("warn"),console.error=e("error"),console.debug=e("debug")}captureLog(e,r){let o={level:e,timestamp:Date.now(),message:r.map(n=>{if(typeof n=="string")return n;try{return JSON.stringify(n)}catch{return String(n)}}).join(" ")};this.logBuffer.push(o),this.logBuffer.length>this.maxCaptureSize&&this.logBuffer.shift()}async postToServer(e,r){if(this.logBuffer.length>0){let n=[...this.logBuffer];this.logBuffer=[];try{if(!(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n.map(a=>({...a,source:r})))})).ok)throw new Error("Failed to post logs to server")}catch(i){console.warn("Could not post logs to server",i.message),this.logBuffer.unshift(...n)}}}},m;function C(e=""){return m=new w(e),m}var u=e=>{throw new Error("Not initialized yet")},p=typeof window>"u"&&typeof globalThis.WebSocketPair>"u",d=new Map,l=0;p&&(globalThis.syscall=async(e,...r)=>await new Promise((o,n)=>{l++,d.set(l,{resolve:o,reject:n}),u({type:"sys",id:l,name:e,args:r})}));function g(e,r,o){p&&(u=o,self.addEventListener("message",n=>{(async()=>{let i=n.data;switch(i.type){case"inv":{let a=e[i.name];if(!a)throw new Error(`Function not loaded: ${i.name}`);try{let s=await Promise.resolve(a(...i.args||[]));u({type:"invr",id:i.id,result:s})}catch(s){console.error("An exception was thrown as a result of invoking function",i.name,"error:",s.message),u({type:"invr",id:i.id,error:s.message})}}break;case"sysr":{let a=i.id,s=d.get(a);if(!s)throw Error("Invalid request id");d.delete(a),i.error?s.reject(new Error(i.error)):s.resolve(i.result)}break}})().catch(console.error)}),u({type:"manifest",manifest:r}),C(`[${r.name} plug]`))}async function T(e,r){if(typeof e!="string"){let o=new Uint8Array(await e.arrayBuffer()),n=o.length>0?f(o):void 0;r={method:e.method,headers:Object.fromEntries(e.headers.entries()),base64Body:n},e=e.url}return syscall("sandboxFetch.fetch",e,r)}globalThis.nativeFetch=globalThis.fetch;function S(){globalThis.fetch=async(e,r)=>{let o=r?.body?f(new Uint8Array(await new Response(r.body).arrayBuffer())):void 0,n=await T(e,r&&{method:r.method,headers:r.headers,base64Body:o});return new Response(n.base64Body?b(n.base64Body):null,{status:n.status,headers:n.headers})}}p&&S();var c={};v(c,{alert:()=>ce,configureVimMode:()=>Ae,confirm:()=>ue,copyToClipboard:()=>ve,deleteLine:()=>be,dispatch:()=>se,downloadFile:()=>I,filterBox:()=>X,flashNotification:()=>J,fold:()=>pe,foldAll:()=>ge,getCurrentEditor:()=>E,getCurrentPage:()=>A,getCurrentPageMeta:()=>M,getCurrentPath:()=>F,getCursor:()=>L,getRecentlyOpenedPages:()=>U,getSelection:()=>B,getText:()=>K,getUiOption:()=>le,goHistory:()=>_,hidePanel:()=>Z,insertAtCursor:()=>ie,insertAtPos:()=>te,invokeCommand:()=>R,isMobile:()=>Fe,moveCursor:()=>oe,moveCursorToLine:()=>ne,moveLineDown:()=>Te,moveLineUp:()=>Ce,navigate:()=>j,newWindow:()=>G,openCommandPalette:()=>W,openPageNavigator:()=>Q,openSearchPanel:()=>he,openUrl:()=>$,prompt:()=>ae,rebuildEditorState:()=>H,redo:()=>Pe,reloadConfigAndCommands:()=>N,reloadPage:()=>q,reloadUI:()=>V,replaceRange:()=>re,save:()=>O,sendMessage:()=>Me,setSelection:()=>k,setText:()=>D,setUiOption:()=>de,showPanel:()=>Y,showProgress:()=>ee,toggleComment:()=>we,toggleFold:()=>fe,undo:()=>xe,unfold:()=>me,unfoldAll:()=>ye,uploadFile:()=>z,vimEx:()=>Se});typeof globalThis.syscall>"u"&&(globalThis.syscall=()=>{throw new Error("Not implemented here")});function t(e,...r){return globalThis.syscall(e,...r)}function A(){return t("editor.getCurrentPage")}function M(){return t("editor.getCurrentPageMeta")}function F(){return t("editor.getCurrentPath")}function U(){return t("editor.getRecentlyOpenedPages")}function E(){return t("editor.getCurrentEditor")}function K(){return t("editor.getText")}function D(e,r=!1){return t("editor.setText",e,r)}function L(){return t("editor.getCursor")}function B(){return t("editor.getSelection")}function k(e,r){return t("editor.setSelection",e,r)}function R(e,r){return t("editor.invokeCommand",e,r)}function O(){return t("editor.save")}function j(e,r=!1,o=!1){return t("editor.navigate",e,r,o)}function Q(e="page"){return t("editor.openPageNavigator",e)}function W(){return t("editor.openCommandPalette")}function q(){return t("editor.reloadPage")}function V(){return t("editor.reloadUI")}function H(){return t("editor.rebuildEditorState")}function N(){return t("editor.reloadConfigAndCommands")}function $(e,r=!1){return t("editor.openUrl",e,r)}function G(){return t("editor.newWindow")}function _(e){return t("editor.goHistory",e)}function I(e,r){return t("editor.downloadFile",e,r)}function z(e,r){return t("editor.uploadFile",e,r)}function J(e,r="info"){return t("editor.flashNotification",e,r)}function X(e,r,o="",n=""){return t("editor.filterBox",e,r,o,n)}function Y(e,r,o,n=""){return t("editor.showPanel",e,r,o,n)}function Z(e){return t("editor.hidePanel",e)}function ee(e,r){return t("editor.showProgress",e,r)}function te(e,r){return t("editor.insertAtPos",e,r)}function re(e,r,o){return t("editor.replaceRange",e,r,o)}function oe(e,r=!1){return t("editor.moveCursor",e,r)}function ne(e,r=1,o=!1){return t("editor.moveCursorToLine",e,r,o)}function ie(e,r=!1,o=!1){return t("editor.insertAtCursor",e,r,o)}function se(e){return t("editor.dispatch",e)}function ae(e,r=""){return t("editor.prompt",e,r)}function ue(e){return t("editor.confirm",e)}function ce(e){return t("editor.alert",e)}function le(e){return t("editor.getUiOption",e)}function de(e,r){return t("editor.setUiOption",e,r)}function pe(){return t("editor.fold")}function me(){return t("editor.unfold")}function fe(){return t("editor.toggleFold")}function ge(){return t("editor.foldAll")}function ye(){return t("editor.unfoldAll")}function xe(){return t("editor.undo")}function Pe(){return t("editor.redo")}function he(){return t("editor.openSearchPanel")}function ve(e){return t("editor.copyToClipboard",e)}function be(){return t("editor.deleteLine")}function we(){return t("editor.toggleComment")}function Ce(){return t("editor.moveLineUp")}function Te(){return t("editor.moveLineDown")}function Se(e){return t("editor.vimEx",e)}function Ae(){return t("editor.configureVimMode")}function Me(e,r){return t("editor.sendMessage",e,r)}function Fe(){return t("editor.isMobile")}var nt=new Uint8Array(16);async function y(){await c.flashNotification("Hello world!")}var x={helloWorld:y},P={name:"hello",functions:{helloWorld:{path:"hello.ts:helloWorld",command:{name:"Say hello"}}},assets:{}},Ct={manifest:P,functionMapping:x};g(x,P,self.postMessage);export{Ct as plug};
//# sourceMappingURL=hello.plug.js.map