-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextTransform.plug.js
1 lines (1 loc) · 9.99 KB
/
textTransform.plug.js
1
var G=Object.defineProperty;var Y=(e,r)=>{for(var t in r)G(e,t,{get:r[t],enumerable:!0})};var m=e=>{throw new Error("Not initialized yet")},R=typeof window>"u"&&typeof globalThis.WebSocketPair>"u";typeof Deno>"u"&&(self.Deno={args:[],build:{arch:"x86_64"},env:{get(){}}});var h=new Map,x=0;R&&(globalThis.syscall=async(e,...r)=>await new Promise((t,a)=>{x++,h.set(x,{resolve:t,reject:a}),m({type:"sys",id:x,name:e,args:r})}));function v(e,r,t){R&&(m=t,self.addEventListener("message",a=>{(async()=>{let i=a.data;switch(i.type){case"inv":{let s=e[i.name];if(!s)throw new Error(`Function not loaded: ${i.name}`);try{let u=await Promise.resolve(s(...i.args||[]));m({type:"invr",id:i.id,result:u})}catch(u){console.error("An exception was thrown as a result of invoking function",i.name,"error:",u.message),m({type:"invr",id:i.id,error:u.message})}}break;case"sysr":{let s=i.id,u=h.get(s);if(!u)throw Error("Invalid request id");h.delete(s),i.error?u.reject(new Error(i.error)):u.resolve(i.result)}break}})().catch(console.error)}),m({type:"manifest",manifest:r}))}function X(e){let r=atob(e),t=r.length,a=new Uint8Array(t);for(let i=0;i<t;i++)a[i]=r.charCodeAt(i);return a}function U(e){typeof e=="string"&&(e=new TextEncoder().encode(e));let r="",t=e.byteLength;for(let a=0;a<t;a++)r+=String.fromCharCode(e[a]);return btoa(r)}async function Z(e,r){if(typeof e!="string"){let t=new Uint8Array(await e.arrayBuffer()),a=t.length>0?U(t):void 0;r={method:e.method,headers:Object.fromEntries(e.headers.entries()),base64Body:a},e=e.url}return syscall("sandboxFetch.fetch",e,r)}globalThis.nativeFetch=globalThis.fetch;function ee(){globalThis.fetch=async function(e,r){let t=r&&r.body?U(new Uint8Array(await new Response(r.body).arrayBuffer())):void 0,a=await Z(e,r&&{method:r.method,headers:r.headers,base64Body:t});return new Response(a.base64Body?X(a.base64Body):null,{status:a.status,headers:a.headers})}}R&&ee();var o={};Y(o,{confirm:()=>Ue,copyToClipboard:()=>Ne,deleteLine:()=>Le,dispatch:()=>Fe,downloadFile:()=>ye,filterBox:()=>he,flashNotification:()=>xe,fold:()=>Ke,foldAll:()=>Ce,getCurrentPage:()=>re,getCursor:()=>oe,getSelection:()=>ae,getText:()=>te,getUiOption:()=>Me,goHistory:()=>Te,hidePanel:()=>be,insertAtCursor:()=>Se,insertAtPos:()=>Pe,moveCursor:()=>Ae,moveCursorToLine:()=>ke,navigate:()=>ce,openCommandPalette:()=>fe,openPageNavigator:()=>ue,openSearchPanel:()=>Ie,openUrl:()=>ge,prompt:()=>ve,redo:()=>De,reloadConfigAndCommands:()=>me,reloadPage:()=>pe,reloadUI:()=>le,replaceRange:()=>we,save:()=>se,setSelection:()=>ie,setText:()=>ne,setUiOption:()=>Oe,showPanel:()=>Re,toggleFold:()=>Ee,undo:()=>We,unfold:()=>Be,unfoldAll:()=>je,uploadFile:()=>de,vimEx:()=>ze});typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});function n(e,...r){return globalThis.syscall(e,...r)}function re(){return n("editor.getCurrentPage")}function te(){return n("editor.getText")}function ne(e){return n("editor.setText",e)}function oe(){return n("editor.getCursor")}function ae(){return n("editor.getSelection")}function ie(e,r){return n("editor.setSelection",e,r)}function se(){return n("editor.save")}function ce(e,r=!1,t=!1){return n("editor.navigate",e,r,t)}function ue(e="page"){return n("editor.openPageNavigator",e)}function fe(){return n("editor.openCommandPalette")}function pe(){return n("editor.reloadPage")}function le(){return n("editor.reloadUI")}function me(){return n("editor.reloadConfigAndCommands")}function ge(e,r=!1){return n("editor.openUrl",e,r)}function Te(e){return n("editor.goHistory",e)}function ye(e,r){return n("editor.downloadFile",e,r)}function de(e,r){return n("editor.uploadFile",e,r)}function xe(e,r="info"){return n("editor.flashNotification",e,r)}function he(e,r,t="",a=""){return n("editor.filterBox",e,r,t,a)}function Re(e,r,t,a=""){return n("editor.showPanel",e,r,t,a)}function be(e){return n("editor.hidePanel",e)}function Pe(e,r){return n("editor.insertAtPos",e,r)}function we(e,r,t){return n("editor.replaceRange",e,r,t)}function Ae(e,r=!1){return n("editor.moveCursor",e,r)}function ke(e,r=1,t=!1){return n("editor.moveCursorToLine",e,r,t)}function Se(e){return n("editor.insertAtCursor",e)}function Fe(e){return n("editor.dispatch",e)}function ve(e,r=""){return n("editor.prompt",e,r)}function Ue(e){return n("editor.confirm",e)}function Me(e){return n("editor.getUiOption",e)}function Oe(e,r){return n("editor.setUiOption",e,r)}function Ke(){return n("editor.fold")}function Be(){return n("editor.unfold")}function Ee(){return n("editor.toggleFold")}function Ce(){return n("editor.foldAll")}function je(){return n("editor.unfoldAll")}function We(){return n("editor.undo")}function De(){return n("editor.redo")}function Ie(){return n("editor.openSearchPanel")}function Ne(e){return n("editor.copyToClipboard",e)}function Le(){return n("editor.deleteLine")}function ze(e){return n("editor.vimEx",e)}function P(e,...r){return function(...t){let a=[],i=0;for(let s=0;s<r.length;s++){let u=r[s];u===P.placeholder?a.push(t[i++]):a.push(u)}for(let s=i;s<t.length;s++)a.push(t[s]);return e.apply(this,a)}}var wr=Symbol("partial.placeholder");P.placeholder=wr;function w(e,...r){return function(...t){let a=r.filter(f=>f===K).length,i=Math.max(t.length-a,0),s=[],u=0;for(let f=0;f<i;f++)s.push(t[u++]);for(let f=0;f<r.length;f++){let F=r[f];F===w.placeholder?s.push(t[u++]):s.push(F)}return e.apply(this,s)}}var K=Symbol("partialRight.placeholder");w.placeholder=K;function p(e){return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}var Wr=/\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?!\p{Ll})|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;function c(e){return Array.from(e.match(Wr)??[])}function A(e){let r=c(e);if(r.length===0)return"";let[t,...a]=r;return`${t.toLowerCase()}${a.map(i=>p(i)).join("")}`}var ap=new Map(Object.entries({\u00C6:"Ae",\u00D0:"D",\u00D8:"O",\u00DE:"Th",\u00DF:"ss",\u00E6:"ae",\u00F0:"d",\u00F8:"o",\u00FE:"th",\u0110:"D",\u0111:"d",\u0126:"H",\u0127:"h",\u0131:"i",\u0132:"IJ",\u0133:"ij",\u0138:"k",\u013F:"L",\u0140:"l",\u0141:"L",\u0142:"l",\u0149:"'n",\u014A:"N",\u014B:"n",\u0152:"Oe",\u0153:"oe",\u0166:"T",\u0167:"t",\u017F:"s"}));function d(e){return c(e).map(t=>t.toLowerCase()).join("-")}function g(e){return c(e).map(t=>t.toLowerCase()).join(" ")}function T(e){return c(e).map(t=>t.toLowerCase()).join("_")}function l(e){let r=c(e.trim()),t="";for(let a=0;a<r.length;a++){let i=r[a];t&&(t+=" "),t+=i[0].toUpperCase()+i.slice(1).toLowerCase()}return t}function k(e){let r=c(e),t="";for(let a=0;a<r.length;a++)t+=r[a].toUpperCase(),a<r.length-1&&(t+=" ");return t}function S(e){return e.substring(0,1).toUpperCase()+e.substring(1)}async function C(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=k(e),await o.replaceRange(t,r.to,e)}async function j(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=g(e),await o.replaceRange(t,r.to,e)}async function W(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=p(e),await o.replaceRange(t,r.to,e)}async function D(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=l(e),await o.replaceRange(t,r.to,e)}async function I(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=S(g(e)),await o.replaceRange(t,r.to,e)}async function N(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=T(e),await o.replaceRange(t,r.to,e)}async function L(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=A(e),await o.replaceRange(t,r.to,e)}async function z(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=d(e),await o.replaceRange(t,r.to,e)}async function q(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=d(e).replace("-","."),await o.replaceRange(t,r.to,e)}async function V(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=T(l(e)),await o.replaceRange(t,r.to,e)}async function $(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=T(l(e)),await o.replaceRange(t,r.to,e)}async function _(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=g(l(e)),await o.replaceRange(t,r.to,e)}async function J(){let e=await o.getText(),r=await o.getSelection(),t=r.from;e=e.slice(t,r.to),e=e.replace(/ /g,""),await o.replaceRange(t,r.to,e)}var Q={uppercase:C,lowercase:j,capitalize:W,titleCase:D,sentenceCase:I,snakeCase:N,camelCase:L,kebabCase:z,dotCase:q,camelToSnake:V,kebabToSnake:$,camelToSpace:_,removeSpaces:J},H={name:"textTransform",functions:{uppercase:{path:"textTransform.ts:toUppercase",command:{name:"Text: Convert text to uppercase",requireMode:"rw"}},lowercase:{path:"textTransform.ts:toLowercase",command:{name:"Text: Convert text to lowercase",requireMode:"rw"}},capitalize:{path:"textTransform.ts:toCapitalize",command:{name:"Text: Convert text to capitalize",requireMode:"rw"}},titleCase:{path:"textTransform.ts:toTitleCase",command:{name:"Text: Convert text to title case",requireMode:"rw"}},sentenceCase:{path:"textTransform.ts:toSentenceCase",command:{name:"Text: Convert text to sentence case",requireMode:"rw"}},snakeCase:{path:"textTransform.ts:toSnakeCase",command:{name:"Text: Convert text to snake case",requireMode:"rw"}},camelCase:{path:"textTransform.ts:toCamelCase",command:{name:"Text: Convert text to camel case",requireMode:"rw"}},kebabCase:{path:"textTransform.ts:toKebabCase",command:{name:"Text: Convert text to kebab case",requireMode:"rw"}},dotCase:{path:"textTransform.ts:toDotCase",command:{name:"Text: Convert text to dot case",requireMode:"rw"}},camelToSnake:{path:"textTransform.ts:camelToSnake",command:{name:"Text: Convert camelCase to snake_case",requireMode:"rw"}},kebabToSnake:{path:"textTransform.ts:kebabToSnake",command:{name:"Text: Convert kebab-case to snake_case",requireMode:"rw"}},camelToSpace:{path:"textTransform.ts:camelToSpace",command:{name:"Text: Convert camelCase to spaces",requireMode:"rw"}},removeSpaces:{path:"textTransform.ts:removeSpaces",command:{name:"Text: Remove spaces",requireMode:"rw"}}},assets:{}},Dl={manifest:H,functionMapping:Q};v(Q,H,self.postMessage);export{Dl as plug};