index.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <!-- Note:
  2. This site was created by modifying code pen https://codepen.io/antonmedv/pen/PoPoGwg
  3. written by 'Anton Medvedev' the license can be found bellow.
  4. LICENSE
  5. -------
  6. Copyright (c) 2022 by Anton Medvedev (https://codepen.io/antonmedv/pen/PoPoGwg)
  7. Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. this software and associated documentation files (the "Software"), to deal in
  9. the Software without restriction, including without limitation the rights to
  10. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  11. of the Software, and to permit persons to whom the Software is furnished to do
  12. so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. DEALINGS IN THE SOFTWARE. -->
  22. <!DOCTYPE html>
  23. <html lang="en">
  24. <head>
  25. <meta charset="UTF-8">
  26. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  27. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  28. <script src="static/codejar/codejar.js"></script>
  29. <script src="static/codejar/linenumbers.js"></script>
  30. <script src="static/highlight.js/highlight.min.js"></script>
  31. <link rel="stylesheet" href="static/highlight.js/github-dark-dimmed.min.css" id="highlight-theme">
  32. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  33. <style>
  34. @import url("https://fonts.googleapis.com/css2?family=Lato:wght@300&family=PT+Mono&display=swap");
  35. .hljs {
  36. display: block;
  37. overflow-x: auto;
  38. padding: .5em;
  39. background: #282a36;
  40. }
  41. .hljs-keyword,
  42. .hljs-selector-tag,
  43. .hljs-literal,
  44. .hljs-section,
  45. .hljs-link {
  46. color: #73cbde;
  47. }
  48. .hljs,
  49. .hljs-subst {
  50. color: #f8f8f2;
  51. }
  52. .hljs-string,
  53. .hljs-title,
  54. .hljs-name,
  55. .hljs-type,
  56. .hljs-attribute,
  57. .hljs-symbol,
  58. .hljs-bullet,
  59. .hljs-addition,
  60. .hljs-variable,
  61. .hljs-template-tag,
  62. .hljs-template-variable {
  63. color: #f1fa8c;
  64. }
  65. .hljs-comment,
  66. .hljs-quote,
  67. .hljs-deletion,
  68. .hljs-meta {
  69. color: #6272a4;
  70. }
  71. .hljs-keyword,
  72. .hljs-selector-tag,
  73. .hljs-literal,
  74. .hljs-title,
  75. .hljs-section,
  76. .hljs-doctag,
  77. .hljs-type,
  78. .hljs-name,
  79. .hljs-strong {
  80. font-weight: bold;
  81. }
  82. .hljs-emphasis {
  83. font-style: italic;
  84. }
  85. :root {
  86. --window-width: 80%;
  87. --editor-bg: #282a36;
  88. --editor-text: #f8f8f2;
  89. --output-bg: #282a36;
  90. --output-text: #ffffff;
  91. --editor-line-highlight: rgba(255, 255, 255, 0.07);
  92. }
  93. body {
  94. background-color: #778abb;
  95. font-family: Lato, sans-serif;
  96. font-weight: 300;
  97. font-size: 15px;
  98. margin: 0;
  99. }
  100. *,
  101. *:before,
  102. *:after {
  103. box-sizing: border-box;
  104. }
  105. *:focus {
  106. outline: none;
  107. }
  108. a,
  109. a:visited,
  110. a:active {
  111. color: black;
  112. }
  113. main {
  114. min-height: 100vh;
  115. display: flex;
  116. align-items: center;
  117. flex-direction: column;
  118. }
  119. .title {
  120. color: #fff;
  121. text-align: center;
  122. font-weight: 300;
  123. font-size: 34px;
  124. margin-top: 20px;
  125. }
  126. .window {
  127. width: var(--window-width);
  128. border-radius: 6px;
  129. box-shadow: 0 8px 12px rgba(0, 0, 0, 0.1);
  130. overflow: hidden;
  131. margin-bottom: 20px;
  132. }
  133. .window .window-header {
  134. height: 25px;
  135. background: Gainsboro;
  136. position: relative;
  137. }
  138. .window .window-header .action-buttons {
  139. position: absolute;
  140. top: 50%;
  141. left: 10px;
  142. margin-top: -5px;
  143. width: 10px;
  144. height: 10px;
  145. background: Crimson;
  146. border-radius: 50%;
  147. box-shadow: 15px 0 0 Orange, 30px 0 0 LimeGreen;
  148. }
  149. #code-editor {
  150. border-bottom-left-radius: 6px;
  151. border-bottom-right-radius: 6px;
  152. box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12),
  153. 0 3px 1px -2px rgba(0, 0, 0, 0.2);
  154. font-family: "PT Mono", monospace;
  155. font-size: 14px;
  156. font-weight: 400;
  157. min-height: 300px;
  158. letter-spacing: normal;
  159. line-height: 20px;
  160. padding: 10px;
  161. resize: none !important;
  162. tab-size: 4;
  163. background-color: var(--editor-bg);
  164. color: var(--editor-text);
  165. }
  166. #run-button {
  167. padding-left: 10px;
  168. padding-right: 10px;
  169. font-weight: bold;
  170. cursor: pointer;
  171. }
  172. #theme-toggle {
  173. padding-left: 10px;
  174. padding-right: 10px;
  175. font-weight: bold;
  176. cursor: pointer;
  177. margin-right: 10px;
  178. }
  179. #code-editor.hljs {
  180. padding: 10px;
  181. }
  182. #output-wrapper {
  183. font-family: "PT Mono", monospace;
  184. width: var(--window-width);
  185. min-height: 50px;
  186. background-color: var(--output-bg);
  187. border-radius: 6px;
  188. padding: 10px;
  189. color: var(--output-text);
  190. margin: 0 !important;
  191. }
  192. #code-output span.error-line {
  193. color: #ec5424;
  194. }
  195. .controls {
  196. font-size: 14px;
  197. position: absolute;
  198. top: 50%;
  199. right: 10px;
  200. margin-top: -10px;
  201. display: flex;
  202. }
  203. .controls>div:first-child>a {
  204. display: inline-block;
  205. width: 40px;
  206. }
  207. .features {
  208. width: 547px;
  209. font-size: 16px;
  210. margin-bottom: 30px;
  211. }
  212. /* VS Code Light+ theme styles */
  213. .editor-light-theme {
  214. --editor-bg: #FFFFFF;
  215. --editor-text: #000000;
  216. --output-bg: #FFFFFF;
  217. --output-text: #000000;
  218. --editor-line-highlight: rgba(0, 0, 0, 0.07);
  219. }
  220. .editor-light-theme .hljs {
  221. background: #FFFFFF;
  222. color: #000000;
  223. }
  224. /* Syntax colors matching VS Code Light+ */
  225. .editor-light-theme .hljs-keyword,
  226. .editor-light-theme .hljs-selector-tag,
  227. .editor-light-theme .hljs-literal {
  228. color: #0000FF; /* Blue for keywords */
  229. }
  230. .editor-light-theme .hljs-string {
  231. color: #A31515; /* Maroon for strings */
  232. }
  233. .editor-light-theme .hljs-comment {
  234. color: #008000; /* Green for comments */
  235. font-style: italic;
  236. }
  237. .editor-light-theme .hljs-number {
  238. color: #098658; /* Green for numbers */
  239. }
  240. .editor-light-theme .hljs-built_in,
  241. .editor-light-theme .hljs-title {
  242. color: #795E26; /* Brown for built-ins */
  243. }
  244. .editor-light-theme .hljs-params {
  245. color: #001080; /* Dark blue for parameters */
  246. }
  247. .editor-light-theme .hljs-function {
  248. color: #000000; /* Black for function names */
  249. }
  250. .editor-light-theme .hljs-meta {
  251. color: #AF00DB; /* Purple for meta tags */
  252. }
  253. </style>
  254. <title>Try Online</title>
  255. </head>
  256. <body id="tryonline-body">
  257. <main>
  258. <br>
  259. <div class="window">
  260. <div class="window-header">
  261. <div class="action-buttons"></div>
  262. <div class="controls">
  263. <div id="theme-toggle">Light</div>
  264. <div id="run-button">Run</div>
  265. </div>
  266. </div>
  267. <div class="window-body">
  268. <div id="code-editor" class="language-python" data-gramm="false"></div>
  269. </div>
  270. </div>
  271. <pre id="output-wrapper"><div id="code-output">...</div></pre>
  272. <br>
  273. </main>
  274. <script>
  275. var Module = {
  276. onRuntimeInitialized: function () {
  277. Module.ccall('py_initialize', null, [], []);
  278. console.log("py_initialize() called");
  279. },
  280. print: function (text) {
  281. code_output.innerText += text + '\n';
  282. },
  283. onabort: function (what) {
  284. code_output.innerText += 'Aborted: ' + what + '\n';
  285. Module.ccall('py_finalize', null, [], []);
  286. console.log("py_finalize() called");
  287. }
  288. };
  289. </script>
  290. <script src="lib/pocketpy.js"></script>
  291. <script>
  292. let code_editor = document.querySelector('#code-editor');
  293. let code_output = document.querySelector('#code-output');
  294. let run_button = document.querySelector('#run-button');
  295. let themeToggle = document.querySelector('#theme-toggle');
  296. let highlightTheme = document.querySelector('#highlight-theme');
  297. let mainElement = document.querySelector('main');
  298. code_editor.textContent = '# A recursive fibonacci function.\ndef fib(n):\n if n < 2:\n return n\n return fib(n-1) + fib(n-2)\n\n# Prints all fibonacci from 0 to 10 exclusive.\nfor i in range(10):\n print(f"fib({i}) = {fib(i)}")\n';
  299. let highlight = withLineNumbers(function (editor) {
  300. editor.textContent = editor.textContent;
  301. hljs.highlightElement(editor);
  302. });
  303. highlight(code_editor);
  304. CodeJar(code_editor, highlight);
  305. // Theme toggle functionality
  306. themeToggle.addEventListener('click', function() {
  307. if (mainElement.classList.contains('editor-light-theme')) {
  308. // Switch to dark theme
  309. mainElement.classList.remove('editor-light-theme');
  310. highlightTheme.href = 'static/highlight.js/github-dark-dimmed.min.css';
  311. themeToggle.textContent = 'Light';
  312. } else {
  313. // Switch to light theme
  314. mainElement.classList.add('editor-light-theme');
  315. highlightTheme.href = 'static/highlight.js/vs.min.css'; // Changed to VS theme
  316. themeToggle.textContent = 'Dark';
  317. }
  318. // Re-highlight the code with the new theme
  319. highlight(code_editor);
  320. });
  321. window.onload = function () {
  322. run_button.onclick = function () {
  323. code_output.innerText = '';
  324. const source = code_editor.textContent;
  325. var ok = Module.ccall(
  326. 'py_exec', 'boolean', ['string', 'string', 'number', 'number'],
  327. [source, 'main.py', 0, 0]
  328. );
  329. console.log("py_exec() called");
  330. if (!ok) {
  331. Module.ccall('py_printexc', null, [], []);
  332. Module.ccall('py_clearexc', null, ['number'], [0]);
  333. }
  334. }
  335. }
  336. </script>
  337. </body>
  338. </html>