-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
code-runner-wc.min.js
8 lines (8 loc) · 16.1 KB
/
code-runner-wc.min.js
1
2
3
4
5
6
7
8
/**!
* @license Code-Runner-Web-Component - A web component that allows you to run high level programming languages on your websites.
* VERSION: 1.0.5
* LICENSED UNDER GPL-3.0 LICENSE
* Created by Jared Van Valkengoed @ https://github.com/MarketingPipeline
* MORE INFO CAN BE FOUND AT https://github.com/MarketingPipeline/Code-Runner-Web-Component/
*/
onload=function(){let e=[{language:"matl",version:"22.5.0",aliases:[]},{language:"bash",version:"5.2.0",aliases:["sh"]},{language:"befunge93",version:"0.2.0",aliases:["b93"]},{language:"bqn",version:"1.0.0",aliases:[]},{language:"brachylog",version:"1.0.0",aliases:[]},{language:"brainfuck",version:"2.7.3",aliases:["bf"]},{language:"cjam",version:"0.6.5",aliases:[]},{language:"clojure",version:"1.10.3",aliases:["clojure","clj"]},{language:"cobol",version:"3.1.2",aliases:["cob"]},{language:"coffeescript",version:"2.5.1",aliases:["coffeescript","coffee"]},{language:"cow",version:"1.0.0",aliases:["cow"]},{language:"crystal",version:"0.36.1",aliases:["crystal","cr"]},{language:"dart",version:"2.19.6",aliases:[]},{language:"dash",version:"0.5.11",aliases:["dash"]},{language:"typescript",version:"1.32.3",aliases:["deno","deno-ts"],runtime:"deno"},{language:"javascript",version:"1.32.3",aliases:["deno-js"],runtime:"deno"},{language:"basic.net",version:"5.0.201",aliases:["basic","visual-basic","visual-basic.net","vb","vb.net","vb-dotnet","dotnet-vb","basic-dotnet","dotnet-basic"],runtime:"dotnet"},{language:"fsharp.net",version:"5.0.201",aliases:["fsharp","fs","f#","fs.net","f#.net","fsharp-dotnet","fs-dotnet","f#-dotnet","dotnet-fsharp","dotnet-fs","dotnet-fs"],runtime:"dotnet"},{language:"csharp.net",version:"5.0.201",aliases:["csharp","c#","cs","c#.net","cs.net","c#-dotnet","cs-dotnet","csharp-dotnet","dotnet-c#","dotnet-cs","dotnet-csharp"],runtime:"dotnet"},{language:"fsi",version:"5.0.201",aliases:["fsx","fsharp-interactive","f#-interactive","dotnet-fsi","fsi-dotnet","fsi.net"],runtime:"dotnet"},{language:"dragon",version:"1.9.8",aliases:[]},{language:"elixir",version:"1.11.3",aliases:["elixir","exs"]},{language:"emacs",version:"27.1.0",aliases:["emacs","el","elisp"]},{language:"emojicode",version:"1.0.2",aliases:["emojic"]},{language:"erlang",version:"23.0.0",aliases:["erlang","erl","escript"]},{language:"file",version:"0.0.1",aliases:["executable","elf","binary"]},{language:"forte",version:"1.0.0",aliases:["forter"]},{language:"forth",version:"0.7.3",aliases:["gforth"]},{language:"freebasic",version:"1.9.0",aliases:["bas","fbc","basic","qbasic","quickbasic"]},{language:"awk",version:"5.1.0",aliases:["gawk"],runtime:"gawk"},{language:"c",version:"10.2.0",aliases:["gcc"],runtime:"gcc"},{language:"c++",version:"10.2.0",aliases:["cpp","g++"],runtime:"gcc"},{language:"d",version:"10.2.0",aliases:["gdc"],runtime:"gcc"},{language:"fortran",version:"10.2.0",aliases:["fortran","f90"],runtime:"gcc"},{language:"go",version:"1.16.2",aliases:["go","golang"]},{language:"golfscript",version:"1.0.0",aliases:["golfscript"]},{language:"groovy",version:"3.0.7",aliases:["groovy","gvy"]},{language:"haskell",version:"9.0.1",aliases:["haskell","hs"]},{language:"husk",version:"1.0.0",aliases:[]},{language:"iverilog",version:"11.0.0",aliases:["verilog","vvp"]},{language:"japt",version:"2.0.0",aliases:["japt"]},{language:"java",version:"15.0.2",aliases:[]},{language:"jelly",version:"0.1.31",aliases:[]},{language:"julia",version:"1.8.5",aliases:["jl"]},{language:"kotlin",version:"1.8.20",aliases:["kt"]},{language:"lisp",version:"2.1.2",aliases:["lisp","cl","sbcl","commonlisp"]},{language:"llvm_ir",version:"12.0.1",aliases:["llvm","llvm-ir","ll"]},{language:"lolcode",version:"0.11.2",aliases:["lol","lci"]},{language:"lua",version:"5.4.4",aliases:[]},{language:"csharp",version:"6.12.0",aliases:["mono","mono-csharp","mono-c#","mono-cs","c#","cs"],runtime:"mono"},{language:"basic",version:"6.12.0",aliases:["vb","mono-vb","mono-basic","visual-basic","visual basic"],runtime:"mono"},{language:"nasm",version:"2.15.5",aliases:["asm","nasm32"],runtime:"nasm"},{language:"nasm64",version:"2.15.5",aliases:["asm64"],runtime:"nasm"},{language:"nim",version:"1.6.2",aliases:[]},{language:"javascript",version:"18.15.0",aliases:["node-javascript","node-js","node.js","javascript","js"],runtime:"node"},{language:"ocaml",version:"4.12.0",aliases:["ocaml","ml"]},{language:"octave",version:"8.1.0",aliases:["matlab","m"]},{language:"osabie",version:"1.0.1",aliases:["osabie","05AB1E","usable"]},{language:"paradoc",version:"0.6.0",aliases:["paradoc"]},{language:"pascal",version:"3.2.2",aliases:["freepascal","pp","pas"]},{language:"perl",version:"5.36.0",aliases:["pl"]},{language:"php",version:"8.2.3",aliases:[]},{language:"ponylang",version:"0.39.0",aliases:["pony","ponyc"]},{language:"prolog",version:"8.2.4",aliases:["prolog","plg"]},{language:"pure",version:"0.68.0",aliases:[]},{language:"powershell",version:"7.1.4",aliases:["ps","pwsh","ps1"],runtime:"pwsh"},{language:"pyth",version:"1.0.0",aliases:["pyth"]},{language:"python2",version:"2.7.18",aliases:["py2","python2"]},{language:"python",version:"3.10.0",aliases:["py","py3","python3","python3.10"]},{language:"racket",version:"8.3.0",aliases:["rkt"]},{language:"raku",version:"6.100.0",aliases:["raku","rakudo","perl6","p6","pl6"]},{language:"retina",version:"1.2.0",aliases:["ret"]},{language:"rockstar",version:"1.0.0",aliases:["rock","rocky"]},{language:"rscript",version:"4.1.1",aliases:["r"]},{language:"ruby",version:"3.0.1",aliases:["ruby3","rb"]},{language:"rust",version:"1.68.2",aliases:["rs"]},{language:"samarium",version:"0.3.1",aliases:["sm"]},{language:"scala",version:"3.2.2",aliases:["sc"]},{language:"smalltalk",version:"3.2.3",aliases:["st"]},{language:"sqlite3",version:"3.36.0",aliases:["sqlite","sql"]},{language:"swift",version:"5.3.3",aliases:["swift"]},{language:"typescript",version:"5.0.3",aliases:["ts","node-ts","tsc","typescript5","ts5"]},{language:"vlang",version:"0.3.3",aliases:["v"]},{language:"vyxal",version:"2.4.1",aliases:[]},{language:"yeethon",version:"3.10.0",aliases:["yeethon3"]},{language:"zig",version:"0.9.1",aliases:["zig"]}];class n extends HTMLElement{constructor(){super()}connectedCallback(){const e=this.getAttribute("language"),n="<style> /*compress*/ .code-knack-playground { position: relative; background-color: #3a3636; background-color: var(--bg, #3a3636); border-radius: 10px; border: 1px solid var(--border, rgba(0, 0, 0, 0.1));} .code-knack-playground.line-number .CodeMirror { padding-left: 0px;} .code-knack-playground img { max-width: 90% !important; display: inline-block !important; border-radius: 0 !important; box-shadow: none !important;} .code-knack-playground .code-knack-pane { height: 40px; display: flex; border-radius: 3px;} .code-knack-playground .code-knack-pane .code-knack-title { flex: 1; padding-left: 20px; color: var(--title, #fff); display: flex; font-size: 14px; font-family: 'Metropolis-Medium', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, 'Helvetica Neue', sans-serif; align-items: center; opacity: 0.5; text-transform: uppercase;} .code-knack-playground .code-knack-pane .code-knack-ctrl { flex: 1; display: flex; justify-content: flex-end;} .code-knack-playground .code-knack-pane button.ck-button { height: 40px; padding: 0 16px; font-size: 14px; background: transparent; border: none; border-radius: 0; color: var(--button-text, wheat); opacity: 0.8; outline: none; display: flex; align-items: center; box-shadow: -1px 0 0 0 var(--button-border, rgba(0, 0, 0, 0.5));} .code-knack-playground .code-knack-pane button.ck-button img { height: 14px; margin-right: 3px;} .code-knack-playground .code-knack-pane button.ck-button:hover { opacity: 1;} .code-knack-playground .code-knack-pane button.ck-button:active { opacity: 0.6;} .code-knack-playground pre { background: transparent; color: var(--code, white); border-bottom-left-radius: 3px; border-bottom-right-radius: 3px;} .code-knack-playground .CodeMirror { padding-left: 16px;} .code-knack-playground .CodeMirror, .code-knack-playground .code-knack-text { font-size: 14px; line-height: 18px; height: auto;} .code-knack-playground .CodeMirror pre, .code-knack-playground .code-knack-text pre { padding: 0 4px; font-family: 'Menlo', 'Roboto Mono', 'Courier New', Courier, monospace !important;} .code-knack-playground .code-knack-text { color: var(--code, white); border: none; width: 100%; height: 100%; border-radius: 0px 0px 10px 10px; background: var(--code-bg, rgba(39, 40, 35, 1)); font-family: 'Menlo', 'Roboto Mono', 'Courier New', Courier, monospace !important;} .code-knack-playground .code-knack-output { display: none; background: var(--bg, #3a3636); font-family: 'Menlo', 'Roboto Mono', 'Courier New', Courier, monospace !important; border-top: 1px solid var(--border, rgba(0, 0, 0, 0.1));} .code-knack-playground .code-knack-output .code-knack-output-title { color: var(--text, white); opacity: 0.6; font-size: 12px; margin: 0 10px 0 20px; padding: 4px 0; font-family: \"Metropolis-Medium\" -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, 'Helvetica Neue', sans-serif; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgba(255, 255, 255, 0.06);} .code-knack-playground .code-knack-output .code-knack-output-content { color: var(--text, white); white-space: pre-line; padding: 8px 12px 8px 20px; font-size: 14px; overflow: auto; white-space: pre-wrap;} .code-knack-playground .code-knack-output.html-output .code-knack-output-content { max-width: 100% !important; background: rgba(252, 253, 255, 1); margin: 0 10px; color: #000; border-radius: 3px; border: 1px solid var(--border, rgba(0, 0, 0, 0.1));} .code-knack-playground .code-knack-output.html-output .code-knack-output-content .katex .base { margin: 10px 0;} .code-knack-playground .code-knack-footer { background-color: #3a3636; background-color: var(--bg, #3a3636); height: 10px; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;} .code-knack-playground .code-knack-mask { display: none; position: absolute; top: 0; left: 0; right: 0; bottom: 0; color: white; z-index: 10; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.4);}/*endcompress*/ </style> ";if(!e)return this.innerHTML=n+' \x3c!--compress--\x3e <div> <pre style="padding: 0px; --bg:rgb(58, 54, 54); --text:rgb(255, 255, 255); --border:rgba(0,0,0,0.3); --code:rgb(255, 255, 255); --code-bg:rgba(39, 40, 35, 1); --title:rgb(255, 255, 255); --button-text:wheat; --button-border:rgba(0,0,0,0.18);"><div class="code-knack-playground "><div class="code-knack-pane"><div class="code-knack-title">Error!</div> </div><div id="codetorun" class="code-knack-text" style="/* display: none; */">Error: Language Attribute Is Missing For Web Component ... </div> </div> </div> \x3c!--endcompress--\x3e ';if(this.spellcheck=!1,this.innerHTML=` ${n} \x3c!--compress--\x3e <div code-runner-component language=${e}> <pre style="padding: 0px; --bg:rgb(58, 54, 54); --text:rgb(255, 255, 255); --border:rgba(0,0,0,0.3); --code:rgb(255, 255, 255); --code-bg:rgba(39, 40, 35, 1); --title:rgb(255, 255, 255); --button-text:wheat; --button-border:rgba(0,0,0,0.18);"><div class="code-knack-playground " data-lang="cpp" data-options=""><div class="code-knack-pane"><div class="code-knack-title">${e}</div> <div class="code-knack-mask">Copied to the clipboard.</div><div class="code-knack-ctrl"><button class="ck-button run-button" code-runner-button><img src="https://lyricat.github.io/code-knack/demo/lib/code-knack/images/icon-play-dark.svg"><span >run</span></button><button class="ck-button copy-button" code-runner-copy-button><img src="https://lyricat.github.io/code-knack/demo/lib/code-knack/images/icon-copy-dark.svg"><span>copy</span></button></div> </div><div id="codetorun" class="code-knack-text" contenteditable style="/* display: none; */">${this.innerHTML}</div><div id="output_section" class="code-knack-output text-output"><div class="code-knack-output-title">Output</div><pre class="code-knack-output-content" id="result">Loading..<br></pre></div></div></pre> </div> </div> \x3c!--endcompress--\x3e `,!this.hasAttribute("custom-compiler")){if(null==t(this.getAttribute("language").toLowerCase(),"GETNAME"))return this.innerHTML=`${n} \x3c!--compress--\x3e <div> <pre style="padding: 0px; --bg:rgb(58, 54, 54); --text:rgb(255, 255, 255); --border:rgba(0,0,0,0.3); --code:rgb(255, 255, 255); --code-bg:rgba(39, 40, 35, 1); --title:rgb(255, 255, 255); --button-text:wheat; --button-border:rgba(0,0,0,0.18);"><div class="code-knack-playground "><div class="code-knack-pane"><div class="code-knack-title">Error!</div> </div><div id="codetorun" class="code-knack-text" style="/* display: none; */">Error: ${this.getAttribute("language")} is not detected or supported by the Code-Runner web-component. See the repo if there is any plugins that support "${this.getAttribute("language")}" @ https://github.com/MarketingPipeline/Code-Runner-Web-Component </div> </div> </div> \x3c!--endcompress--\x3e `;!async function(e){"true"===(await l()).loaded&&c(e,t(e.getAttribute("language").toLowerCase(),"GETNAME"))}(this)}this.querySelector("[ code-runner-button]").addEventListener("click",e=>{var n;(n=this).hasAttribute("custom-compiler")||async function(e){if(e.querySelector("#output_section").style.display="block",navigator.onLine)try{1!=a.loaded&&(a.ansiUp=await import("https://cdn.skypack.dev/ansi_up@5.1.0"),a.ansiUp=a.ansiUp.default,a.ansiUp=new a.ansiUp,a.loaded=!0);const n=await fetch("https://emkc.org/api/v2/piston/execute",{method:"POST",body:JSON.stringify({language:e.getAttribute("language").toLowerCase(),version:t(e.getAttribute("language").toLowerCase()),files:[{content:ace.edit(e.querySelector("#codetorun")).getValue()}]})}),o=await n.json();o.message?e.querySelector("#result").innerText=JSON.stringify("Error "+o.message):e.querySelector("#result").innerHTML=a.ansiUp.ansi_to_html(o.run.output)}catch(n){e.querySelector("#result").innerText=n.message}else e.querySelector("#result").innerText="Error: You must be connected to the internet to use this!"}(n)}),this.querySelector("[code-runner-copy-button]").addEventListener("click",e=>{return n=this,navigator.clipboard.writeText(n.querySelector("#codetorun").innerText),n.querySelector(".code-knack-mask").style.display="flex",void setTimeout(()=>{n.querySelector(".code-knack-mask").style.display="none"},"3000");var n})}}let a={loaded:!1,ansiUp:null};function t(n,a){data=e;for(const e in data){if(!n==data[e].language)return console.log("Error: Code-Runner could not auto-detect version to use for "+n),"undefined";if(n==data[e].language)return a?data[e].language:data[e].version;for(const t in data[e].aliases)if(n==data[e].aliases[t])return a?data[e].language:data[e].version}}let o,s=["https://cdn.jsdelivr.net/npm/ace-min-noconflict@1.1.9/ace.min.js","https://cdn.jsdelivr.net/npm/ace-min-noconflict@1.1.9/ext-modelist.js","https://cdn.jsdelivr.net/npm/ace-min-noconflict@1.1.9/ext-themelist.js"],r=[],i=!1;async function l(){if("undefined"==typeof CodeRunner_DisableAceEditor&&!1===i){s.forEach((function(e){r.push((e=>new Promise((function(n,a){let t=document.createElement("script");t.src=e,t.async=!1,t.onload=()=>{n(e)},t.onerror=()=>{a(e)},document.body.appendChild(t)})))(e))}));return await Promise.all(r).then((async function(){return{loaded:"true"}})).catch((function(e){return i=!0,{loaded:"false"}}))}}function c(e,n){ace.config.set("basePath","https://cdn.jsdelivr.net/npm/ace-min-noconflict@1.1.9/");let a=e.querySelector("#codetorun").textContent;if(o=ace.edit(e.querySelector("#codetorun")),o.$blockScrolling=1/0,"undefined"==typeof CodeRunner_AceEditor_Theme)o.setTheme("ace/theme/monokai");else{null!=ace.require("ace/ext/themelist").themesByName[CodeRunner_AceEditor_Theme.toLowerCase()]?o.setTheme("ace/theme/"+CodeRunner_AceEditor_Theme.toLowerCase()):(console.log(`Code Runner Error: ${CodeRunner_AceEditor_Theme} is not a valid theme - setting to default.`),o.setTheme("ace/theme/monokai"))}n&&(null!=ace.require("ace/ext/modelist").modesByName[n]?o.getSession().setMode("ace/mode/"+n):console.log("Code Runner Error: Ace Editor Language Mode Could Not Be Found For "+(n.charAt(0).toUpperCase()+n.slice(1)))),o.setShowPrintMargin(!1),o.setValue(a),o.clearSelection(),o.setOptions({maxLines:1/0})}window.customElements.define("code-runner",n)}