@dodona/papyros 3.0.1 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/README.md +133 -72
  2. package/dist/Components.d.ts +4 -0
  3. package/dist/Components.js +5 -0
  4. package/dist/Components.js.map +1 -0
  5. package/dist/Papyros.d.ts +18 -127
  6. package/dist/Papyros.js +39 -211
  7. package/dist/Papyros.js.map +1 -1
  8. package/dist/{Backend.d.ts → backend/Backend.d.ts} +3 -12
  9. package/dist/{Backend.js → backend/Backend.js} +4 -17
  10. package/dist/backend/Backend.js.map +1 -0
  11. package/dist/{workers → backend/workers}/javascript/JavaScriptWorker.js +1 -1
  12. package/dist/backend/workers/javascript/JavaScriptWorker.js.map +1 -0
  13. package/dist/backend/workers/javascript/worker.js.map +1 -0
  14. package/dist/{workers → backend/workers}/python/PythonWorker.d.ts +2 -2
  15. package/dist/{workers → backend/workers}/python/PythonWorker.js +2 -2
  16. package/dist/backend/workers/python/PythonWorker.js.map +1 -0
  17. package/dist/backend/workers/python/python_package.tar.gz.load_by_url +0 -0
  18. package/dist/backend/workers/python/worker.js.map +1 -0
  19. package/dist/communication/BackendEvent.js.map +1 -0
  20. package/dist/{BackendEventQueue.d.ts → communication/BackendEventQueue.d.ts} +1 -36
  21. package/dist/{BackendEventQueue.js → communication/BackendEventQueue.js} +2 -45
  22. package/dist/communication/BackendEventQueue.js.map +1 -0
  23. package/dist/{BackendManager.d.ts → communication/BackendManager.d.ts} +2 -2
  24. package/dist/{BackendManager.js → communication/BackendManager.js} +4 -4
  25. package/dist/communication/BackendManager.js.map +1 -0
  26. package/dist/communication/InputServiceWorker.js +37 -0
  27. package/dist/communication/InputServiceWorker.js.map +1 -0
  28. package/dist/communication/InputWorker.js.map +1 -0
  29. package/dist/frontend/components/CodeRunner.d.ts +9 -0
  30. package/dist/frontend/components/CodeRunner.js +60 -0
  31. package/dist/frontend/components/CodeRunner.js.map +1 -0
  32. package/dist/frontend/components/Debugger.d.ts +7 -0
  33. package/dist/frontend/components/Debugger.js +62 -0
  34. package/dist/frontend/components/Debugger.js.map +1 -0
  35. package/dist/frontend/components/Input.d.ts +17 -0
  36. package/dist/frontend/components/Input.js +73 -0
  37. package/dist/frontend/components/Input.js.map +1 -0
  38. package/dist/frontend/components/Output.d.ts +14 -0
  39. package/dist/frontend/components/Output.js +154 -0
  40. package/dist/frontend/components/Output.js.map +1 -0
  41. package/dist/frontend/components/PapyrosElement.d.ts +8 -0
  42. package/dist/frontend/components/PapyrosElement.js +24 -0
  43. package/dist/frontend/components/PapyrosElement.js.map +1 -0
  44. package/dist/frontend/components/app/App.d.ts +24 -0
  45. package/dist/frontend/components/app/App.js +204 -0
  46. package/dist/frontend/components/app/App.js.map +1 -0
  47. package/dist/frontend/components/app/ExamplePicker.d.ts +7 -0
  48. package/dist/frontend/components/app/ExamplePicker.js +35 -0
  49. package/dist/frontend/components/app/ExamplePicker.js.map +1 -0
  50. package/dist/frontend/components/app/LanguagePicker.d.ts +7 -0
  51. package/dist/frontend/components/app/LanguagePicker.js +35 -0
  52. package/dist/frontend/components/app/LanguagePicker.js.map +1 -0
  53. package/dist/frontend/components/app/ProgrammingLanguagePicker.d.ts +7 -0
  54. package/dist/frontend/components/app/ProgrammingLanguagePicker.js +39 -0
  55. package/dist/frontend/components/app/ProgrammingLanguagePicker.js.map +1 -0
  56. package/dist/frontend/components/app/examples/JavaScriptExamples.js.map +1 -0
  57. package/dist/frontend/components/app/examples/PythonExamples.js.map +1 -0
  58. package/dist/frontend/components/app/themes/ThemePicker.d.ts +11 -0
  59. package/dist/frontend/components/app/themes/ThemePicker.js +47 -0
  60. package/dist/frontend/components/app/themes/ThemePicker.js.map +1 -0
  61. package/dist/frontend/components/app/themes/ThemedButton.d.ts +9 -0
  62. package/dist/frontend/components/app/themes/ThemedButton.js +43 -0
  63. package/dist/frontend/components/app/themes/ThemedButton.js.map +1 -0
  64. package/dist/frontend/components/code_mirror/BatchInputEditor.d.ts +8 -0
  65. package/dist/frontend/components/code_mirror/BatchInputEditor.js +54 -0
  66. package/dist/frontend/components/code_mirror/BatchInputEditor.js.map +1 -0
  67. package/dist/frontend/components/code_mirror/CodeEditor.d.ts +24 -0
  68. package/dist/frontend/components/code_mirror/CodeEditor.js +206 -0
  69. package/dist/frontend/components/code_mirror/CodeEditor.js.map +1 -0
  70. package/dist/frontend/components/code_mirror/CodeMirrorEditor.d.ts +20 -0
  71. package/dist/frontend/components/code_mirror/CodeMirrorEditor.js +99 -0
  72. package/dist/frontend/components/code_mirror/CodeMirrorEditor.js.map +1 -0
  73. package/dist/frontend/components/code_mirror/Extensions.d.ts +15 -0
  74. package/dist/frontend/components/code_mirror/Extensions.js +169 -0
  75. package/dist/frontend/components/code_mirror/Extensions.js.map +1 -0
  76. package/dist/frontend/components/code_mirror/MaterialTheme.d.ts +5 -0
  77. package/dist/frontend/components/code_mirror/MaterialTheme.js +114 -0
  78. package/dist/frontend/components/code_mirror/MaterialTheme.js.map +1 -0
  79. package/dist/frontend/components/code_runner/ButtonLint.d.ts +9 -0
  80. package/dist/frontend/components/code_runner/ButtonLint.js +76 -0
  81. package/dist/frontend/components/code_runner/ButtonLint.js.map +1 -0
  82. package/dist/frontend/components/code_runner/Code.d.ts +7 -0
  83. package/dist/frontend/components/code_runner/Code.js +46 -0
  84. package/dist/frontend/components/code_runner/Code.js.map +1 -0
  85. package/dist/frontend/components/code_runner/RunState.d.ts +7 -0
  86. package/dist/frontend/components/code_runner/RunState.js +41 -0
  87. package/dist/frontend/components/code_runner/RunState.js.map +1 -0
  88. package/dist/frontend/components/input/BatchInput.d.ts +19 -0
  89. package/dist/frontend/components/input/BatchInput.js +92 -0
  90. package/dist/frontend/components/input/BatchInput.js.map +1 -0
  91. package/dist/frontend/components/input/InteractiveInput.d.ts +13 -0
  92. package/dist/frontend/components/input/InteractiveInput.js +73 -0
  93. package/dist/frontend/components/input/InteractiveInput.js.map +1 -0
  94. package/dist/frontend/state/Constants.d.ts +38 -0
  95. package/dist/frontend/state/Constants.js +108 -0
  96. package/dist/frontend/state/Constants.js.map +1 -0
  97. package/dist/frontend/state/Debugger.d.ts +23 -0
  98. package/dist/frontend/state/Debugger.js +80 -0
  99. package/dist/frontend/state/Debugger.js.map +1 -0
  100. package/dist/frontend/state/Examples.d.ts +11 -0
  101. package/dist/frontend/state/Examples.js +36 -0
  102. package/dist/frontend/state/Examples.js.map +1 -0
  103. package/dist/frontend/state/I18n.d.ts +16 -0
  104. package/dist/frontend/state/I18n.js +75 -0
  105. package/dist/frontend/state/I18n.js.map +1 -0
  106. package/dist/frontend/state/InputOutput.d.ts +55 -0
  107. package/dist/frontend/state/InputOutput.js +93 -0
  108. package/dist/frontend/state/InputOutput.js.map +1 -0
  109. package/dist/frontend/state/Runner.d.ts +118 -0
  110. package/dist/frontend/state/Runner.js +330 -0
  111. package/dist/frontend/state/Runner.js.map +1 -0
  112. package/dist/frontend/state/Test.d.ts +11 -0
  113. package/dist/frontend/state/Test.js +59 -0
  114. package/dist/frontend/state/Test.js.map +1 -0
  115. package/dist/frontend/state/Translations.d.ts +178 -0
  116. package/dist/frontend/state/Translations.js +188 -0
  117. package/dist/frontend/state/Translations.js.map +1 -0
  118. package/dist/frontend/state/themes/blue-dark.d.ts +2 -0
  119. package/dist/frontend/state/themes/blue-dark.js +55 -0
  120. package/dist/frontend/state/themes/blue-dark.js.map +1 -0
  121. package/dist/frontend/state/themes/blue-light.d.ts +2 -0
  122. package/dist/frontend/state/themes/blue-light.js +55 -0
  123. package/dist/frontend/state/themes/blue-light.js.map +1 -0
  124. package/dist/frontend/state/themes/green-dark.d.ts +2 -0
  125. package/dist/frontend/state/themes/green-dark.js +55 -0
  126. package/dist/frontend/state/themes/green-dark.js.map +1 -0
  127. package/dist/frontend/state/themes/green-light.d.ts +2 -0
  128. package/dist/frontend/state/themes/green-light.js +55 -0
  129. package/dist/frontend/state/themes/green-light.js.map +1 -0
  130. package/dist/frontend/state/themes/red-dark.d.ts +2 -0
  131. package/dist/frontend/state/themes/red-dark.js +55 -0
  132. package/dist/frontend/state/themes/red-dark.js.map +1 -0
  133. package/dist/frontend/state/themes/red-light.d.ts +2 -0
  134. package/dist/frontend/state/themes/red-light.js +55 -0
  135. package/dist/frontend/state/themes/red-light.js.map +1 -0
  136. package/dist/util/Util.d.ts +1 -4
  137. package/dist/util/Util.js +7 -8
  138. package/dist/util/Util.js.map +1 -1
  139. package/package.json +13 -26
  140. package/dist/App.d.ts +0 -1
  141. package/dist/App.js +0 -76
  142. package/dist/App.js.map +0 -1
  143. package/dist/Backend.js.map +0 -1
  144. package/dist/BackendEvent.js.map +0 -1
  145. package/dist/BackendEventQueue.js.map +0 -1
  146. package/dist/BackendManager.js.map +0 -1
  147. package/dist/CodeRunner.d.ts +0 -188
  148. package/dist/CodeRunner.js +0 -548
  149. package/dist/CodeRunner.js.map +0 -1
  150. package/dist/Constants.d.ts +0 -31
  151. package/dist/Constants.js +0 -36
  152. package/dist/Constants.js.map +0 -1
  153. package/dist/Debugger.d.ts +0 -18
  154. package/dist/Debugger.js +0 -86
  155. package/dist/Debugger.js.map +0 -1
  156. package/dist/InputManager.d.ts +0 -38
  157. package/dist/InputManager.js +0 -101
  158. package/dist/InputManager.js.map +0 -1
  159. package/dist/InputServiceWorker.js.map +0 -1
  160. package/dist/Library.d.ts +0 -12
  161. package/dist/Library.js +0 -9
  162. package/dist/Library.js.map +0 -1
  163. package/dist/OutputManager.d.ts +0 -90
  164. package/dist/OutputManager.js +0 -172
  165. package/dist/OutputManager.js.map +0 -1
  166. package/dist/Papyros.css +0 -657
  167. package/dist/Translations.d.ts +0 -180
  168. package/dist/Translations.js +0 -191
  169. package/dist/Translations.js.map +0 -1
  170. package/dist/editor/BatchInputEditor.d.ts +0 -41
  171. package/dist/editor/BatchInputEditor.js +0 -80
  172. package/dist/editor/BatchInputEditor.js.map +0 -1
  173. package/dist/editor/CodeEditor.d.ts +0 -81
  174. package/dist/editor/CodeEditor.js +0 -213
  175. package/dist/editor/CodeEditor.js.map +0 -1
  176. package/dist/editor/CodeMirrorEditor.d.ts +0 -133
  177. package/dist/editor/CodeMirrorEditor.js +0 -169
  178. package/dist/editor/CodeMirrorEditor.js.map +0 -1
  179. package/dist/editor/DarkTheme.d.ts +0 -1
  180. package/dist/editor/DarkTheme.js +0 -72
  181. package/dist/editor/DarkTheme.js.map +0 -1
  182. package/dist/editor/DebugExtension.d.ts +0 -11
  183. package/dist/editor/DebugExtension.js +0 -70
  184. package/dist/editor/DebugExtension.js.map +0 -1
  185. package/dist/editor/Gutters.d.ts +0 -109
  186. package/dist/editor/Gutters.js +0 -201
  187. package/dist/editor/Gutters.js.map +0 -1
  188. package/dist/editor/LineEffectExtension.d.ts +0 -13
  189. package/dist/editor/LineEffectExtension.js +0 -48
  190. package/dist/editor/LineEffectExtension.js.map +0 -1
  191. package/dist/editor/TestCodeExtension.d.ts +0 -21
  192. package/dist/editor/TestCodeExtension.js +0 -134
  193. package/dist/editor/TestCodeExtension.js.map +0 -1
  194. package/dist/examples/Examples.d.ts +0 -6
  195. package/dist/examples/Examples.js +0 -23
  196. package/dist/examples/Examples.js.map +0 -1
  197. package/dist/examples/JavaScriptExamples.js.map +0 -1
  198. package/dist/examples/PythonExamples.js.map +0 -1
  199. package/dist/input/BatchInputHandler.d.ts +0 -55
  200. package/dist/input/BatchInputHandler.js +0 -131
  201. package/dist/input/BatchInputHandler.js.map +0 -1
  202. package/dist/input/InteractiveInputHandler.d.ts +0 -27
  203. package/dist/input/InteractiveInputHandler.js +0 -89
  204. package/dist/input/InteractiveInputHandler.js.map +0 -1
  205. package/dist/input/UserInputHandler.d.ts +0 -68
  206. package/dist/input/UserInputHandler.js +0 -39
  207. package/dist/input/UserInputHandler.js.map +0 -1
  208. package/dist/util/HTMLShapes.d.ts +0 -15
  209. package/dist/util/HTMLShapes.js +0 -25
  210. package/dist/util/HTMLShapes.js.map +0 -1
  211. package/dist/util/Rendering.d.ts +0 -120
  212. package/dist/util/Rendering.js +0 -142
  213. package/dist/util/Rendering.js.map +0 -1
  214. package/dist/workers/input/InputWorker.js.map +0 -1
  215. package/dist/workers/javascript/JavaScriptWorker.js.map +0 -1
  216. package/dist/workers/javascript/worker.js.map +0 -1
  217. package/dist/workers/python/PythonWorker.js.map +0 -1
  218. package/dist/workers/python/python_package.tar.gz.load_by_url +0 -0
  219. package/dist/workers/python/worker.js.map +0 -1
  220. /package/dist/{workers → backend/workers}/javascript/JavaScriptWorker.d.ts +0 -0
  221. /package/dist/{workers → backend/workers}/javascript/worker.d.ts +0 -0
  222. /package/dist/{workers → backend/workers}/javascript/worker.js +0 -0
  223. /package/dist/{workers → backend/workers}/python/worker.d.ts +0 -0
  224. /package/dist/{workers → backend/workers}/python/worker.js +0 -0
  225. /package/dist/{BackendEvent.d.ts → communication/BackendEvent.d.ts} +0 -0
  226. /package/dist/{BackendEvent.js → communication/BackendEvent.js} +0 -0
  227. /package/dist/{InputServiceWorker.d.ts → communication/InputServiceWorker.d.ts} +0 -0
  228. /package/dist/{workers/input → communication}/InputWorker.d.ts +0 -0
  229. /package/dist/{workers/input → communication}/InputWorker.js +0 -0
  230. /package/dist/{examples → frontend/components/app/examples}/JavaScriptExamples.d.ts +0 -0
  231. /package/dist/{examples → frontend/components/app/examples}/JavaScriptExamples.js +0 -0
  232. /package/dist/{examples → frontend/components/app/examples}/PythonExamples.d.ts +0 -0
  233. /package/dist/{examples → frontend/components/app/examples}/PythonExamples.js +0 -0
package/README.md CHANGED
@@ -12,113 +12,174 @@
12
12
  </a>
13
13
  </p>
14
14
 
15
- Papyros is a programming scratchpad in the browser. It allows running code
16
- directly in your browser, no installation required. Right now, the focus is on providing a great experience for Python, while also supporting JavaScript.
17
- By taking away obstacles between students and coding, the learning experience becomes
18
- smoother and less error-prone.
15
+ Papyros is a programming scratchpad in the browser. It allows running code directly in your browser, no installation required.
16
+ Right now, the focus is on providing a great experience for Python, while also supporting JavaScript.
17
+ By taking away obstacles between students and coding, the learning experience becomes smoother and less error-prone.
19
18
 
20
19
  Currently, Papyros provides support for the following programming languages:
21
20
  - Python, powered by [Pyodide](https://pyodide.org/en/stable/)
22
21
  - JavaScript, powered by your browser
23
22
 
24
- ## Using Papyros in your own project
23
+ ---
25
24
 
26
- You can add Papyros to your project as follows:
27
- - npm:
28
- ```shell
29
- npm install @dodona/papyros
30
- ```
31
- - yarn:
32
- ```shell
33
- yarn add @dodona/papyros
34
- ```
25
+ ## Try it Online
35
26
 
36
- Papyros currently supports two modes of operation: stand-alone and embedded.
27
+ Start coding directly in your [browser](https://papyros.dodona.be/).
37
28
 
38
- In stand-alone mode, Papyros runs as a full application in the browser.
39
- This includes extra UI elements to allow selecting a locale, a programming language, ...
29
+ ---
40
30
 
41
- In embedded mode, the layout is reduced to the minimum. Dynamic selections are not displayed,
42
- as the user knows for what purpose Papyros is being used. For example, when used in the
43
- scope of a Python exercise in Dodona, there is no need to support other programming languages.
44
- The locale should also match that of the actual application.
31
+ ## Use papyros in your project
45
32
 
46
- Using Papyros in your project is done by following a few steps. First, you create a new
47
- Papyros instance with a `PapyrosConfig` object.
48
- The following options are supported:
33
+ ### Installation
49
34
 
50
- - `standAlone`: Whether to operate in stand-alone or embedded mode as described above.
51
- - `programmingLanguage`: The [programming language](/src/ProgrammingLanguage.ts) to use in the CodeEditor and Backend.
52
- - `locale`: The locale to use, currently English and Dutch translations are provided.
53
- - `inputMode`: How the users can provide input, according to the [InputMode enum](/src/InputManager.ts)
54
- - `example`: Optional name of the selected example, only appliccable in standAlone-mode
55
- - `channelOptions`: Optional options to provide to the [sync-message](https://github.com/alexmojaki/sync-message) channel. Extra is the serviceWorkerName, which is the relative pathname to the service worker script
35
+ Install via npm or yarn:
56
36
 
57
- Furthermore, you can provide fine-grained configuration by providing `RenderOptions` to each main component in the application when rendering Papyros. You minimally need to specify the ID of the parent element.
58
- You can also specify attributes, such as `style`, `data`-attributes or `classNames` to be used.
59
- The components you can style like this are the following:
60
- - `standAloneOptions`: for the global application in standAlone mode
61
- - `codeEditorOptions`: for the CodeEditor.
62
- - `statusPanelOptions`: for the StatusPanel in the CodeEditor
63
- - `inputOptions`: for the field that handles the user input
64
- - `outputOptions`: for the panel that displays the output of the code
37
+ ```shell
38
+ npm install @dodona/papyros
39
+ # or
40
+ yarn add @dodona/papyros
41
+ ```
42
+
43
+ ### Setup input handling
65
44
 
66
- ### User input
45
+ Running interactive programs in the browser requires special handling of synchronous input.
46
+ Papyros supports two approaches (via [`sync-message`](https://github.com/alexmojaki/sync-message)):
67
47
 
68
- Important to note is that handling asynchronous input in a synchronous way is not straightforward.
69
- This requires advanced features which are not available by default in your browser. We support two options based on [sync-message](https://github.com/alexmojaki/sync-message).
48
+ #### COOP/COEP headers
49
+ Add the following HTTP headers to your server responses:
70
50
 
71
- The most efficient and practical way is using SharedArrayBuffers, which requires the presence of certain HTTP headers.
72
- The following headers must be set on resources using Papyros.
73
51
  ```yaml
74
52
  {
75
53
  "Cross-Origin-Opener-Policy": "same-origin",
76
54
  "Cross-Origin-Embedder-Policy": "require-corp"
77
55
  }
78
56
  ```
79
- If you are also embedding other components (such as iframes, videos or images) in those pages, you will also need to set the `Cross-Origin-Resource-Policy`-header to `cross-origin` to make them work correctly. If these elements come from external URLs, it will likely not be possible to keep using them. An alternative is described below.
57
+ These headers are required to enable `SharedArrayBuffer`, which is the preferred way to handle synchronous input.
58
+ They need to be set on all assets that are loaded, including scripts, images, fonts, etc.
80
59
 
81
- If you would like to use this project without enabling these HTTP headers, we provide a solution using a service worker.
82
- If your application does not use a service worker yet, you can create one based on the [service worker used in stand-alone mode](src/InputServiceWorker.ts)).
83
- If you already use a service worker, simply include our [InputWorker](src/workers/input/InputWorker.ts) in your existing service worker using imports (you can import it separately from /dist/workers/input/InputWorker). An example of how to use it can be found in our described service worker. Afterwards, inform Papyros of the location using the channelOptions described earlier.
60
+ #### Service Worker
61
+ If you cannot set these headers, you can use a service worker to handle input.
62
+ We provide a compiled and minified version of the `InputServiceWorker` in the `dist` folder.
63
+ You need to serve this file from the root of your domain (i.e. `/input-sw.js`).
64
+ You can then register the service worker in your application before launching: `papyros.serviceWorkerName = 'input-sw.js';`.
84
65
 
85
- ### Code editor
66
+ ---
86
67
 
87
- The editor used in Papyros is powered by [CodeMirror 6](https://codemirror.net/6/). It is accessible in code via an instance of Papyros and by default allows configuring many options:
88
- - the [programming language](/src/ProgrammingLanguage.ts) of the contents (for e.g. syntax higlighting)
89
- - the displayed placeholder
90
- - the indentation unit
91
- - the shown panel
92
- - the autocompletion source
93
- - the linting source
94
- - the theme used to style the editor
68
+ ## Usage
95
69
 
96
- If you need more specific functionality, this can be added in your own code by accessing the internal CodeMirror editorView.
70
+ ### Minimal setup
97
71
 
98
- ## Documentation
72
+ If you only want to use the state and runner logic without UI components:
99
73
 
100
- Visit our documentation page at <https://docs.dodona.be/papyros/>.
74
+ ```ts
75
+ import { papyros } from "@dodona/papyros/Papyros";
101
76
 
102
- ## Building and developing
77
+ papyros.launch(); // heavy operation, loads workers and Pyodide
78
+ papyros.runner.code = "print(input())";
103
79
 
104
- Clone the repository using git.
105
- ```shell
106
- git@github.com:dodona-edu/papyros.git
80
+ papyros.io.subscribe(
81
+ () => (papyros.io.awaitingInput ? papyros.io.provideInput("foo") : ""),
82
+ "awaitingInput"
83
+ );
84
+
85
+ await papyros.runner.start();
86
+ console.log(papyros.runner.io.output[0].content);
107
87
  ```
108
88
 
109
- Install the required dependencies.
110
- ```shell
111
- yarn install
89
+ ### Minimal setup with components
90
+
91
+ Papyros provides four web components for visualization.
92
+ Each expects a `papyros` state instance, but defaults to the global `papyros`.
93
+
94
+ ```html
95
+ <script type="module">
96
+ import { papyros } from "@dodona/papyros/Papyros";
97
+ import "@dodona/papyros/components";
98
+
99
+ papyros.launch();
100
+ </script>
101
+
102
+ <p-code-runner></p-code-runner>
103
+ <p-debugger></p-debugger>
104
+ <p-input></p-input>
105
+ <p-output></p-output>
112
106
  ```
113
107
 
114
- Start the local dev-server, powered by webpack.
108
+ ---
109
+
110
+ ## Theming
111
+
112
+ Papyros uses [Material Web Components](https://github.com/material-components/material-web) for buttons, inputs, sliders, etc.
113
+ All styling is driven by Material color system CSS variables (`--md-sys-color-...`).
114
+ Generate your own theme using the [Material Theme Builder](https://material-foundation.github.io/material-theme-builder/).
115
+
116
+ * Three example themes (light + dark) are provided via `papyros.constants.themes`.
117
+ * A theme picker component is available out of the box.
118
+
119
+ ---
120
+
121
+ ## Structure
122
+
123
+ The codebase organized into clear layers:
124
+
125
+ * `backend`: code execution functionality (runs in Web Workers)
126
+ * `communication`: helpers to connect frontend and backend
127
+ * `frontend`: all browser-side code
128
+ * `state`: state management (e.g. execution state, debugger, input/output)
129
+ * `components`: visualization of that state, as Lit web components
130
+
131
+ ### Components
132
+
133
+ #### `<p-code-runner>`
134
+
135
+ A [CodeMirror 6](https://codemirror.net/6/) editor to edit, run, and debug code.
136
+ Additional buttons can be added via the `.buttons` slot.
137
+
138
+ #### `<p-input>`
139
+
140
+ Lets users provide input (batch or interactive), passed to `papyros.io`.
141
+
142
+ #### `<p-output>`
143
+
144
+ Visualizes program output: stdout, stderr, and images.
145
+
146
+ #### `<p-debugger>`
147
+
148
+ Displays execution traces using [`@dodona/json-tracer`](https://github.com/dodona-edu/json-tracer).
149
+
150
+ ### State API
151
+
152
+ A `Papyros` instance contains multiple logical parts:
153
+
154
+ * `papyros.constants`: general settings, constants, and themes (can be overridden).
155
+ * `papyros.debugger`: debug frames and currently active frame.
156
+ * `papyros.examples`: available code examples.
157
+ * `papyros.i18n`: translations (extend or override as needed).
158
+ * `papyros.io`: input/output handling. Subscribe to `awaitingInput` to supply input when needed.
159
+ * `papyros.runner`: code, execution state, programming language. Run code with `papyros.runner.start()`.
160
+ * `papyros.test`: test code (appended to the code document).
161
+
162
+ ---
163
+
164
+ ## Development
165
+
115
166
  ```shell
167
+ # Clone the repository:
168
+ git clone git@github.com:dodona-edu/papyros.git
169
+ cd papyros
170
+ # Install dependencies:
171
+ yarn install
172
+ # Build the python packages:
173
+ yarn setup
174
+ # Start a local server with live reload:
116
175
  yarn start
117
176
  ```
118
177
 
119
- You can now develop with live-reloading.
120
- You can view the results in your browser by visting http://localhost:8080.
121
-
122
- ## Try it online
178
+ ## Publishing
123
179
 
124
- Start coding immediately in your [browser](https://papyros.dodona.be/).
180
+ ```shell
181
+ # Build as library
182
+ yarn build:lib
183
+ # Publish to npm
184
+ yarn publish
185
+ ```
@@ -0,0 +1,4 @@
1
+ import "./frontend/components/Input";
2
+ import "./frontend/components/Output";
3
+ import "./frontend/components/CodeRunner";
4
+ import "./frontend/components/Debugger";
@@ -0,0 +1,5 @@
1
+ import "./frontend/components/Input";
2
+ import "./frontend/components/Output";
3
+ import "./frontend/components/CodeRunner";
4
+ import "./frontend/components/Debugger";
5
+ //# sourceMappingURL=Components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Components.js","sourceRoot":"","sources":["../src/Components.ts"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,CAAC;AACrC,OAAO,8BAA8B,CAAC;AACtC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,gCAAgC,CAAC"}
package/dist/Papyros.d.ts CHANGED
@@ -1,117 +1,25 @@
1
- import { InputManagerRenderOptions, InputMode } from "./InputManager";
2
- import { ProgrammingLanguage } from "./ProgrammingLanguage";
3
- import { RunState, CodeRunner } from "./CodeRunner";
4
- import { AtomicsChannelOptions, ServiceWorkerChannelOptions } from "sync-message";
5
- import { ButtonOptions, Renderable, RenderOptions } from "./util/Rendering";
6
- /**
7
- * Configuration options for this instance of Papyros
8
- */
9
- export interface PapyrosConfig {
10
- /**
11
- * Whether Papyros is run in standAlone mode or embedded in an application
12
- */
13
- standAlone: boolean;
14
- /**
15
- * The programming language to use
16
- */
17
- programmingLanguage: ProgrammingLanguage;
18
- /**
19
- * The language to use
20
- */
21
- locale: string;
22
- /**
23
- * The InputMode to use
24
- */
25
- inputMode: InputMode;
26
- /**
27
- * The selected code example
28
- */
29
- example?: string;
30
- /**
31
- * Configuration for the input channel
32
- */
33
- channelOptions?: {
34
- serviceWorkerName?: string;
35
- root?: string;
36
- } & AtomicsChannelOptions & ServiceWorkerChannelOptions;
37
- }
38
- /**
39
- * Options for rendering Papyros
40
- */
41
- export interface PapyrosRenderOptions {
42
- /**
43
- * Options to render Papyros itself, only used in standAlone mode
44
- */
45
- standAloneOptions?: RenderOptions;
46
- /**
47
- * RenderOptions for the code editor
48
- */
49
- codeEditorOptions?: RenderOptions;
50
- /**
51
- * RenderOptions for the status panel in the editor
52
- */
53
- statusPanelOptions?: RenderOptions;
54
- /**
55
- * RenderOptions for the input field
56
- */
57
- inputOptions?: InputManagerRenderOptions;
58
- /**
59
- * RenderOptions for the output field
60
- */
61
- outputOptions?: RenderOptions;
62
- /**
63
- * Whether to render in dark mode
64
- */
65
- darkMode?: boolean;
66
- traceOptions?: RenderOptions;
67
- }
68
- /**
69
- * Class that manages multiple components to form a coding scratchpad
70
- */
71
- export declare class Papyros extends Renderable<PapyrosRenderOptions> {
72
- /**
73
- * Config used to initialize Papyros
74
- */
75
- private config;
76
- /**
77
- * Component to run code entered by the user
78
- */
79
- readonly codeRunner: CodeRunner;
80
- /**
81
- * Construct a new Papyros instance
82
- * @param {PapyrosConfig} config Properties to configure this instance
83
- */
84
- constructor(config: PapyrosConfig);
85
- /**
86
- * @return {RunState} The current state of the user's code
87
- */
88
- getState(): RunState;
1
+ import { State } from "@dodona/lit-state";
2
+ import { Debugger } from "./frontend/state/Debugger";
3
+ import { Runner } from "./frontend/state/Runner";
4
+ import { InputOutput } from "./frontend/state/InputOutput";
5
+ import { Constants } from "./frontend/state/Constants";
6
+ import { Examples } from "./frontend/state/Examples";
7
+ import { I18n } from "./frontend/state/I18n";
8
+ import { Test } from "./frontend/state/Test";
9
+ export declare class Papyros extends State {
10
+ readonly debugger: Debugger;
11
+ readonly runner: Runner;
12
+ readonly io: InputOutput;
13
+ readonly constants: Constants;
14
+ readonly examples: Examples;
15
+ readonly i18n: I18n;
16
+ readonly test: Test;
17
+ serviceWorkerName: string;
89
18
  /**
90
19
  * Launch this instance of Papyros, making it ready to run code
91
20
  * @return {Promise<Papyros>} Promise of launching, chainable
92
21
  */
93
22
  launch(): Promise<Papyros>;
94
- /**
95
- * Set the used programming language to the given one to allow editing and running code
96
- * @param {ProgrammingLanguage} programmingLanguage The language to use
97
- */
98
- setProgrammingLanguage(programmingLanguage: ProgrammingLanguage): Promise<void>;
99
- /**
100
- * @param {string} locale The locale to use
101
- */
102
- setLocale(locale: string): void;
103
- /**
104
- * @param {boolean} darkMode Whether to use dark mode
105
- */
106
- setDarkMode(darkMode: boolean): void;
107
- /**
108
- * @param {string} code The code to use in the editor
109
- */
110
- setCode(code: string): void;
111
- /**
112
- * @return {string} The currently written code
113
- */
114
- getCode(): string;
115
23
  /**
116
24
  * Configure how user input is handled within Papyros
117
25
  * By default, we will try to use SharedArrayBuffers
@@ -120,22 +28,5 @@ export declare class Papyros extends Renderable<PapyrosRenderOptions> {
120
28
  * @return {Promise<boolean>} Promise of configuring input
121
29
  */
122
30
  private configureInput;
123
- protected _render(renderOptions: PapyrosRenderOptions): void;
124
- /**
125
- * Add a button to the status panel within Papyros
126
- * @param {ButtonOptions} options Options to render the button with
127
- * @param {function} onClick Listener for click events on the button
128
- */
129
- addButton(options: ButtonOptions, onClick: () => void): void;
130
- /**
131
- * @param {ProgrammingLanguage} language The language to check
132
- * @return {boolean} Whether Papyros supports this language by default
133
- */
134
- static supportsProgrammingLanguage(language: string): boolean;
135
- /**
136
- * Convert a string to a ProgrammingLanguage
137
- * @param {string} language The language to convert
138
- * @return {ProgrammingLanguage | undefined} The ProgrammingLanguage, or undefined if not supported
139
- */
140
- static toProgrammingLanguage(language: string): ProgrammingLanguage | undefined;
141
31
  }
32
+ export declare const papyros: Papyros;