@dodona/papyros 0.1.61 → 0.1.91-tar

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.
@@ -0,0 +1,31 @@
1
+ import { InputMode } from "../InputManager";
2
+ import { RenderOptions } from "../util/Util";
3
+ import { UserInputHandler } from "./UserInputHandler";
4
+ export declare class BatchInputHandler extends UserInputHandler {
5
+ /**
6
+ * The index of the next line in lines to send
7
+ */
8
+ private lineNr;
9
+ /**
10
+ * The previous input of the user
11
+ * Is restored upon switching back to InputMode.Batch
12
+ */
13
+ private previousInput;
14
+ /**
15
+ * Construct a new BatchInputHandler
16
+ * @param {function()} inputCallback Callback for when the user has entered a value
17
+ */
18
+ constructor(inputCallback: () => void);
19
+ onToggle(active: boolean): void;
20
+ getInputMode(): InputMode;
21
+ /**
22
+ * Retrieve the lines of input that the user has given so far
23
+ * @return {Array<string>} The entered lines
24
+ */
25
+ protected get lines(): Array<string>;
26
+ hasNext(): boolean;
27
+ next(): string;
28
+ onRunStart(): void;
29
+ onRunEnd(): void;
30
+ render(options: RenderOptions): HTMLElement;
31
+ }
@@ -0,0 +1,20 @@
1
+ import { InputMode } from "../InputManager";
2
+ import { RenderOptions } from "../util/Util";
3
+ import { UserInputHandler } from "./UserInputHandler";
4
+ /**
5
+ * Input handler that takes input from the user in an interactive fashion
6
+ */
7
+ export declare class InteractiveInputHandler extends UserInputHandler {
8
+ /**
9
+ * Retrieve the button that users can click to send their input
10
+ */
11
+ get sendButton(): HTMLButtonElement;
12
+ getInputMode(): InputMode;
13
+ hasNext(): boolean;
14
+ next(): string;
15
+ waitWithPrompt(waiting: boolean, prompt?: string): void;
16
+ onToggle(): void;
17
+ onRunStart(): void;
18
+ onRunEnd(): void;
19
+ render(options: RenderOptions): HTMLElement;
20
+ }
@@ -0,0 +1,61 @@
1
+ import { InputMode } from "../InputManager";
2
+ import { RenderOptions } from "../util/Util";
3
+ /**
4
+ * Base class for components that handle input from the user
5
+ */
6
+ export declare abstract class UserInputHandler {
7
+ /**
8
+ * Whether we are waiting for the user to input data
9
+ */
10
+ protected waiting: boolean;
11
+ protected inputCallback: () => void;
12
+ /**
13
+ * Construct a new UserInputHandler
14
+ * @param {function()} inputCallback Callback for when the user has entered a value
15
+ */
16
+ constructor(inputCallback: () => void);
17
+ /**
18
+ * Whether this handler has input ready
19
+ */
20
+ abstract hasNext(): boolean;
21
+ /**
22
+ * Consume and return the next input value
23
+ *
24
+ * Assumes hasNext() has been called and returned true,
25
+ * otherwise behaviour can produce incorrect results
26
+ * @return {string} The next value
27
+ */
28
+ abstract next(): string;
29
+ /**
30
+ * Render this UserInputHandler with the given options
31
+ * @param {RenderOptions} options The options to use while rendering
32
+ * @return {HTMLElement} The parent with the new content
33
+ */
34
+ abstract render(options: RenderOptions): HTMLElement;
35
+ abstract onRunStart(): void;
36
+ abstract onRunEnd(): void;
37
+ /**
38
+ * Retrieve the InputMode corresponding to this handler
39
+ * @return {InputMode} The InputMode enum value
40
+ */
41
+ abstract getInputMode(): InputMode;
42
+ /**
43
+ * Enable or disable this UserInputHandler
44
+ * @param {boolean} active Whether this component is active
45
+ */
46
+ abstract onToggle(active: boolean): void;
47
+ /**
48
+ * Retrieve the HTMLInputElement for this InputHandler
49
+ */
50
+ get inputArea(): HTMLInputElement;
51
+ /**
52
+ * Wait for input of the user for a certain prompt
53
+ * @param {boolean} waiting Whether we are waiting for input
54
+ * @param {string} prompt Optional message to display if waiting
55
+ */
56
+ waitWithPrompt(waiting: boolean, prompt?: string): void;
57
+ /**
58
+ * Helper method to reset internal state
59
+ */
60
+ protected reset(): void;
61
+ }
@@ -1 +1 @@
1
- (()=>{var e={137:e=>{self,e.exports=(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{serviceWorkerFetchListener:()=>u,asyncSleep:()=>c,ServiceWorkerError:()=>f,writeMessageAtomics:()=>p,writeMessageServiceWorker:()=>h,writeMessage:()=>d,makeChannel:()=>v,makeAtomicsChannel:()=>y,makeServiceWorkerChannel:()=>w,readMessage:()=>m,syncSleep:()=>g,uuidv4:()=>l});var r,n=(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},i=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},a="__SyncMessageServiceWorkerInput__",s="__sync-message-v2__";function u(){var e={},t={};return function(r){var n=r.request.url;return!!n.includes(a)&&(r.respondWith(function(){return o(this,void 0,void 0,(function(){function o(e){var t={message:e,version:s};return new Response(JSON.stringify(t),{status:200})}var a,u,c,l,f,p,h,d;return i(this,(function(i){switch(i.label){case 0:return n.endsWith("/read")?[4,r.request.json()]:[3,5];case 1:return a=i.sent(),u=a.messageId,c=a.timeout,(l=e[u])?(delete e[u],[2,o(l)]):[3,2];case 2:return[4,new Promise((function(e){t[u]=e,setTimeout((function(){delete t[u],e(new Response("",{status:408}))}),c)}))];case 3:return[2,i.sent()];case 4:return[3,8];case 5:return n.endsWith("/write")?[4,r.request.json()]:[3,7];case 6:return f=i.sent(),p=f.message,h=f.messageId,(d=t[h])?(d(o(p)),delete t[h]):e[h]=p,[2,o({early:!d})];case 7:if(n.endsWith("/version"))return[2,new Response(s,{status:200})];i.label=8;case 8:return[2]}}))}))}()),!0)}}function c(e){return new Promise((function(t){return setTimeout(t,e)}))}var l,f=function(e){function t(r,n){var o=e.call(this,"Received status ".concat(n," from ").concat(r,". Ensure the service worker is registered and active."))||this;return o.url=r,o.status=n,Object.setPrototypeOf(o,t.prototype),o}return n(t,e),t}(Error);function p(e,t){var r=(new TextEncoder).encode(JSON.stringify(t)),n=e.data,o=e.meta;if(r.length>n.length)throw"Input is too long";n.set(r,0),Atomics.store(o,0,r.length),Atomics.store(o,1,1),Atomics.notify(o,1)}function h(e,t,r){return o(this,void 0,void 0,(function(){var n,o,a,u,l;return i(this,(function(i){switch(i.label){case 0:return[4,navigator.serviceWorker.ready];case 1:i.sent(),n=e.baseUrl+"/write",o=Date.now(),i.label=2;case 2:return a={message:t,messageId:r},[4,fetch(n,{method:"POST",body:JSON.stringify(a)})];case 3:return u=i.sent(),(l=200===u.status)?[4,u.json()]:[3,5];case 4:l=i.sent().version===s,i.label=5;case 5:return l?[2]:Date.now()-o<e.timeout?[4,c(100)]:[3,7];case 6:return i.sent(),[3,2];case 7:throw new f(n,u.status);case 8:return[2]}}))}))}function d(e,t,r){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return"atomics"!==e.type?[3,1]:(p(e,t),[3,3]);case 1:return[4,h(e,t,r)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))}function v(e){return void 0===e&&(e={}),"undefined"!=typeof SharedArrayBuffer?y(e.atomics):"serviceWorker"in navigator?w(e.serviceWorker):null}function y(e){var t=(void 0===e?{}:e).bufferSize;return{type:"atomics",data:new Uint8Array(new SharedArrayBuffer(t||131072)),meta:new Int32Array(new SharedArrayBuffer(2*Int32Array.BYTES_PER_ELEMENT))}}function w(e){return void 0===e&&(e={}),{type:"serviceWorker",baseUrl:(e.scope||"/")+a,timeout:e.timeout||5e3}}function b(e,t){return e>0?+e:t}function m(e,t,r){var n=void 0===r?{}:r,o=n.checkInterrupt,i=n.checkTimeout,a=n.timeout,u=performance.now();i=b(i,o?100:5e3);var c,l=b(a,Number.POSITIVE_INFINITY);if("atomics"===e.type){var p=e.data,h=e.meta;c=function(){if("timed-out"===Atomics.wait(h,1,0,i))return null;var e=Atomics.exchange(h,0,0),t=p.slice(0,e);Atomics.store(h,1,0);var r=(new TextDecoder).decode(t);return JSON.parse(r)}}else c=function(){var r=new XMLHttpRequest,n=e.baseUrl+"/read";r.open("POST",n,!1);var o={messageId:t,timeout:i};r.send(JSON.stringify(o));var a=r.status;if(408===a)return null;if(200===a){var c=JSON.parse(r.responseText);return c.version!==s?null:c.message}if(performance.now()-u<e.timeout)return null;throw new f(n,a)};for(;;){var d=l-(performance.now()-u);if(d<=0)return null;i=Math.min(i,d);var v=c();if(null!==v)return v;if(null==o?void 0:o())return null}}function g(e,t){if(e=b(e,0))if("undefined"!=typeof SharedArrayBuffer){var r=new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));r[0]=0,Atomics.wait(r,0,0,e)}else m(t,"sleep ".concat(e," ").concat(l()),{timeout:e})}return l="randomUUID"in crypto?function(){return crypto.randomUUID()}:function(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(function(e){var t=Number(e);return(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)}))},t})()}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}(()=>{"use strict";var e=r(137),t=function(){function t(t){this.syncMessageListener=(0,e.serviceWorkerFetchListener)(),this.hostName=t}return t.prototype.handleInputRequest=function(e){return t=this,r=void 0,o=function(){var t;return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}(this,(function(r){return this.syncMessageListener(e)?[2,!0]:e.request.url.includes(this.hostName)?(t=fetch(e.request).then((function(e){var t=new Headers(e.headers);return t.set("Cross-Origin-Embedder-Policy","require-corp"),t.set("Cross-Origin-Opener-Policy","same-origin"),t.set("Cross-Origin-Resource-Policy","cross-origin"),new Response(e.body,{status:e.status||200,statusText:e.statusText,headers:t})})),e.respondWith(t),[2,!0]):[2,!1]}))},new((n=void 0)||(n=Promise))((function(e,i){function a(e){try{u(o.next(e))}catch(e){i(e)}}function s(e){try{u(o.throw(e))}catch(e){i(e)}}function u(t){var r;t.done?e(t.value):(r=t.value,r instanceof n?r:new n((function(e){e(r)}))).then(a,s)}u((o=o.apply(t,r||[])).next())}));var t,r,n,o},t}(),n=new t(location.host);addEventListener("fetch",(function(e){return t=this,r=void 0,i=function(){return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}(this,(function(t){switch(t.label){case 0:return[4,n.handleInputRequest(e)];case 1:return t.sent()||e.respondWith(fetch(e.request)),[2]}}))},new((o=void 0)||(o=Promise))((function(e,n){function a(e){try{u(i.next(e))}catch(e){n(e)}}function s(e){try{u(i.throw(e))}catch(e){n(e)}}function u(t){var r;t.done?e(t.value):(r=t.value,r instanceof o?r:new o((function(e){e(r)}))).then(a,s)}u((i=i.apply(t,r||[])).next())}));var t,r,o,i})),addEventListener("install",(function(e){e.waitUntil(skipWaiting())})),addEventListener("activate",(function(e){e.waitUntil(clients.claim())}))})()})();
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Papyros=t():e.Papyros=t()}(self,(function(){return(()=>{var e={137:e=>{self,e.exports=(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{serviceWorkerFetchListener:()=>i,asyncSleep:()=>s,ServiceWorkerError:()=>u,writeMessageAtomics:()=>a,writeMessageServiceWorker:()=>c,writeMessage:()=>l,makeChannel:()=>f,makeAtomicsChannel:()=>d,makeServiceWorkerChannel:()=>p,readMessage:()=>h,syncSleep:()=>m,uuidv4:()=>v});var n=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function u(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))};const r="__SyncMessageServiceWorkerInput__",o="__sync-message-v2__";function i(){const e={},t={};return i=>{const{url:s}=i.request;return!!s.includes(r)&&(i.respondWith(function(){return n(this,void 0,void 0,(function*(){function n(e){const t={message:e,version:o};return new Response(JSON.stringify(t),{status:200})}if(s.endsWith("/read")){const{messageId:r,timeout:o}=yield i.request.json(),s=e[r];return s?(delete e[r],n(s)):yield new Promise((e=>{t[r]=e,setTimeout((function(){delete t[r],e(new Response("",{status:408}))}),o)}))}if(s.endsWith("/write")){const{message:r,messageId:o}=yield i.request.json(),s=t[o];return s?(s(n(r)),delete t[o]):e[o]=r,n({early:!s})}if(s.endsWith("/version"))return new Response(o,{status:200})}))}()),!0)}}function s(e){return new Promise((t=>setTimeout(t,e)))}class u extends Error{constructor(e,t){super(`Received status ${t} from ${e}. Ensure the service worker is registered and active.`),this.url=e,this.status=t,this.type="ServiceWorkerError",Object.setPrototypeOf(this,u.prototype)}}function a(e,t){const n=(new TextEncoder).encode(JSON.stringify(t)),{data:r,meta:o}=e;if(n.length>r.length)throw new Error("Message is too big, increase bufferSize when making channel.");r.set(n,0),Atomics.store(o,0,n.length),Atomics.store(o,1,1),Atomics.notify(o,1)}function c(e,t,r){return n(this,void 0,void 0,(function*(){yield navigator.serviceWorker.ready;const n=e.baseUrl+"/write",i=Date.now();for(;;){const a={message:t,messageId:r},c=yield fetch(n,{method:"POST",body:JSON.stringify(a)});if(200===c.status&&(yield c.json()).version===o)return;if(!(Date.now()-i<e.timeout))throw new u(n,c.status);yield s(100)}}))}function l(e,t,r){return n(this,void 0,void 0,(function*(){"atomics"===e.type?a(e,t):yield c(e,t,r)}))}function f(e={}){return"undefined"!=typeof SharedArrayBuffer?d(e.atomics):"serviceWorker"in navigator?p(e.serviceWorker):null}function d({bufferSize:e}={}){return{type:"atomics",data:new Uint8Array(new SharedArrayBuffer(e||131072)),meta:new Int32Array(new SharedArrayBuffer(2*Int32Array.BYTES_PER_ELEMENT))}}function p(e={}){return{type:"serviceWorker",baseUrl:(e.scope||"/")+r,timeout:e.timeout||5e3}}function y(e,t){return e>0?+e:t}function h(e,t,{checkInterrupt:n,checkTimeout:r,timeout:i}={}){const s=performance.now();r=y(r,n?100:5e3);const a=y(i,Number.POSITIVE_INFINITY);let c;if("atomics"===e.type){const{data:t,meta:n}=e;c=()=>{if("timed-out"===Atomics.wait(n,1,0,r))return null;{const e=Atomics.exchange(n,0,0),r=t.slice(0,e);Atomics.store(n,1,0);const o=(new TextDecoder).decode(r);return JSON.parse(o)}}}else c=()=>{const n=new XMLHttpRequest,i=e.baseUrl+"/read";n.open("POST",i,!1);const a={messageId:t,timeout:r};n.send(JSON.stringify(a));const{status:c}=n;if(408===c)return null;if(200===c){const e=JSON.parse(n.responseText);return e.version!==o?null:e.message}if(performance.now()-s<e.timeout)return null;throw new u(i,c)};for(;;){const e=a-(performance.now()-s);if(e<=0)return null;r=Math.min(r,e);const t=c();if(null!==t)return t;if(null==n?void 0:n())return null}}function m(e,t){if(e=y(e,0))if("undefined"!=typeof SharedArrayBuffer){const t=new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));t[0]=0,Atomics.wait(t,0,0,e)}else h(t,`sleep ${e} ${v()}`,{timeout:e})}let v;return v="randomUUID"in crypto?function(){return crypto.randomUUID()}:function(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(e=>{const t=Number(e);return(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)}))},t})()}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r);var e=n(137),t=function(){function t(t){this.hostName=t,this.syncMessageListener=(0,e.serviceWorkerFetchListener)()}return t.prototype.handleInputRequest=function(e){return t=this,n=void 0,o=function(){return function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}(this,(function(t){return this.syncMessageListener(e)?[2,!0]:e.request.url.includes(this.hostName)?(e.respondWith(fetch(e.request).then((function(e){var t=new Headers(e.headers);return t.set("Cross-Origin-Embedder-Policy","require-corp"),t.set("Cross-Origin-Opener-Policy","same-origin"),t.set("Cross-Origin-Resource-Policy","cross-origin"),new Response(e.body,{status:e.status||200,statusText:e.statusText,headers:t})}))),[2,!0]):[2,!1]}))},new((r=void 0)||(r=Promise))((function(e,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function u(e){try{a(o.throw(e))}catch(e){i(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r((function(e){e(n)}))).then(s,u)}a((o=o.apply(t,n||[])).next())}));var t,n,r,o},t}(),o=location.href,i=new t(o=o.slice(0,o.lastIndexOf("/")+1));addEventListener("fetch",(function(e){return t=this,n=void 0,o=function(){return function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}(this,(function(t){switch(t.label){case 0:return[4,i.handleInputRequest(e)];case 1:return t.sent()||e.respondWith(fetch(e.request)),[2]}}))},new((r=void 0)||(r=Promise))((function(e,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function u(e){try{a(o.throw(e))}catch(e){i(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r((function(e){e(n)}))).then(s,u)}a((o=o.apply(t,n||[])).next())}));var t,n,r,o})),addEventListener("install",(function(e){e.waitUntil(skipWaiting())})),addEventListener("activate",(function(e){e.waitUntil(clients.claim())}))})(),r})()}));
@@ -1,2 +1,15 @@
1
+ /**
2
+ * Draw a circle using an HTML svg element
3
+ * @param {string} id HTML id for this element
4
+ * @param {string} color The color of the circle
5
+ * @return {string} A string representation of the circle
6
+ */
1
7
  export declare const svgCircle: (id: string, color: string) => string;
8
+ /**
9
+ * Wrap text (best a single character) in a circle to provide information to the user
10
+ * @param {string} content The symbol in the circle, e.g. ? of !
11
+ * @param {string} title The information to display when hovering over the element
12
+ * @param {string} color The color of the circle and the symbol
13
+ * @return {string} A string representation of the circle with content
14
+ */
2
15
  export declare const inCircle: (content: string, title: string, color: string) => string;
@@ -1,6 +1,15 @@
1
+ /**
2
+ * Enum representing the importance of a log message
3
+ * This is helpful for debugging while allowing filtering in production
4
+ */
1
5
  export declare enum LogType {
2
6
  Debug = 0,
3
7
  Error = 1,
4
8
  Important = 2
5
9
  }
10
+ /**
11
+ * Helper method to log useful information at runtime
12
+ * @param {LogType} logType The importance of this log message
13
+ * @param {any[]} args The data to log
14
+ */
6
15
  export declare function papyrosLog(logType: LogType, ...args: any[]): void;
@@ -1,15 +1,107 @@
1
1
  import I18n from "i18n-js";
2
2
  export declare const t: typeof I18n.t;
3
+ /**
4
+ * Add the translations for Papyros to the I18n instance
5
+ */
3
6
  export declare function loadTranslations(): void;
4
7
  export declare function getLocales(): Array<string>;
8
+ /**
9
+ * Constructs the options for use within an HTML select element
10
+ * @param {Array<T>} options All options to display in the list
11
+ * @param {function(T):string} optionText Function to convert the elements to a string
12
+ * @param {T} selected The initially selected element in the list, if any
13
+ * @return {string} The string representation of the select options
14
+ */
5
15
  export declare function getSelectOptions<T>(options: Array<T>, optionText: (option: T) => string, selected?: T): string;
16
+ /**
17
+ * Constructs an HTML select element
18
+ * @param {string} selectId The HTML id for the element
19
+ * @param {Array<T>} options to display in the list
20
+ * @param {function(T):string} optionText to convert elements to a string
21
+ * @param {T} selected The initially selected element in the list, if any
22
+ * @param {string} labelText Optional text to display in a label
23
+ * @return {string} The string representation of the select element
24
+ */
6
25
  export declare function renderSelect<T>(selectId: string, options: Array<T>, optionText: (option: T) => string, selected?: T, labelText?: string): string;
7
- export declare function addListener<T extends string>(elementId: string, onEvent: (e: T) => void, eventType?: string, attribute?: string): void;
26
+ /**
27
+ * Interface for options to use while rendering a button element
28
+ */
29
+ export interface ButtonOptions {
30
+ /**
31
+ * The HTML id of the button
32
+ */
33
+ id: string;
34
+ /**
35
+ * The text to display in the button, can also be HTML
36
+ */
37
+ buttonText: string;
38
+ /**
39
+ * Optional classes to apply to the button
40
+ */
41
+ extraClasses?: string;
42
+ }
43
+ /**
44
+ * Construct a HTML button string from the given options
45
+ * @param {ButtonOptions} options The options for the button
46
+ * @return {string} HTML string for the button
47
+ */
48
+ export declare function renderButton(options: ButtonOptions): string;
49
+ /**
50
+ * Helper type to access a HTML element, either via its id or the element itself
51
+ */
52
+ declare type ElementIdentifier = string | HTMLElement;
53
+ /**
54
+ * Add a listener to an HTML element for an event on an attribute
55
+ * Element attributes tend to be strings, but string Enums can also be used
56
+ * by using the type-parameter T
57
+ * @param {ElementIdentifier} elementId Identifier for the element
58
+ * @param {function(T)} onEvent The listener for the event
59
+ * @param {string} eventType The type of the event
60
+ * @param {string} attribute The attribute affected by the event
61
+ */
62
+ export declare function addListener<T extends string>(elementId: ElementIdentifier, onEvent: (e: T) => void, eventType?: string, attribute?: string): void;
63
+ /**
64
+ * Unset the selected item of a select element to prevent a default selection
65
+ * @param {ElementIdentifier} selectId Identifier for the select element
66
+ */
8
67
  export declare function removeSelection(selectId: string): void;
68
+ /**
69
+ * Useful options for rendering an element
70
+ */
9
71
  export interface RenderOptions {
72
+ /**
73
+ * String identifier for the parent in which the element will be rendered
74
+ */
10
75
  parentElementId: string;
76
+ /**
77
+ * Names of HTML classes to be added to the element, separated by 1 space
78
+ */
11
79
  classNames?: string;
80
+ /**
81
+ * Extra attributes to add to the element, such as style or data
82
+ */
12
83
  attributes?: Map<string, string>;
13
84
  }
14
- export declare function getElement(element: string | HTMLElement): HTMLElement;
85
+ /**
86
+ * Resolve an ElementIdentifier to the corresponding HTLMElement
87
+ * @param {ElementIdentifier} elementId The identifier for the element
88
+ * @return {T} The corresponding element
89
+ */
90
+ export declare function getElement<T extends HTMLElement>(elementId: ElementIdentifier): T;
91
+ /**
92
+ * Renders an element with the given options
93
+ * @param {RenderOptions} options Options to be used while rendering
94
+ * @param {string | HTMLElement} content What to fill the parent with.
95
+ * If the content is a string, it should be properly formatted HTML
96
+ * @return {HTMLElement} The parent with the new child
97
+ */
15
98
  export declare function renderWithOptions(options: RenderOptions, content: string | HTMLElement): HTMLElement;
99
+ /**
100
+ * Parse the data contained within a PapyrosEvent using its contentType
101
+ * Supported content types are: text/plain, text/json, img/png;base64
102
+ * @param {string} data The data to parse
103
+ * @param {string} contentType The content type of the data
104
+ * @return {any} The parsed data
105
+ */
106
+ export declare function parseData(data: string, contentType: string): any;
107
+ export {};
@@ -1,6 +1,22 @@
1
+ /**
2
+ * Class that is used in a service worker to allow synchronous communication
3
+ * between threads. This is achieved in two different ways.
4
+ * Responses can be modified by attaching headers allowing the use of shared memory.
5
+ * Requests to certain endpoints can be used with synchronous requests
6
+ * to achieve the same goal.
7
+ */
1
8
  export declare class InputWorker {
2
- hostName: string;
3
- syncMessageListener: (e: FetchEvent) => boolean;
9
+ private hostName;
10
+ private syncMessageListener;
11
+ /**
12
+ * Create a worker for a specific domain
13
+ * @param {string} hostName The name of the host domain
14
+ */
4
15
  constructor(hostName: string);
16
+ /**
17
+ * Process and potentially handle a fetch request from the application
18
+ * @param {FetchEvent} event The event denoting a request to a url
19
+ * @return {boolean} Whether the event was handled
20
+ */
5
21
  handleInputRequest(event: FetchEvent): Promise<boolean>;
6
22
  }
@@ -1,9 +1,32 @@
1
+ /**
2
+ * TypeScript interface for used Pyodide methods
3
+ */
1
4
  export interface Pyodide {
5
+ /**
6
+ * Runs a string of Python code from JavaScript.
7
+ */
2
8
  runPython: (code: string, globals?: any) => any;
9
+ /**
10
+ * Runs Python code using PyCF_ALLOW_TOP_LEVEL_AWAIT.
11
+ */
3
12
  runPythonAsync: (code: string) => Promise<void>;
13
+ /**
14
+ * Inspect a Python code chunk and use pyodide.loadPackage()
15
+ * to install any known packages that the code chunk imports.
16
+ */
4
17
  loadPackagesFromImports: (code: string) => Promise<void>;
18
+ /**
19
+ * Load a package or a list of packages over the network.
20
+ */
5
21
  loadPackage: (names: string | string[]) => Promise<void>;
22
+ /**
23
+ * An alias to the global Python namespace.
24
+ */
6
25
  globals: Map<string, any>;
26
+ unpackArchive: (buffer: ArrayBuffer, format: string, extractDir?: string) => void;
27
+ pyimport: (name: string) => any;
28
+ registerComlink: any;
29
+ setInterruptBuffer: (buffer: Int32Array) => void;
7
30
  }
8
31
  export declare const PYODIDE_INDEX_URL: string;
9
32
  export declare const PYODIDE_JS_URL: string;
@@ -1,2 +1,4 @@
1
+ import { Pyodide } from "./Pyodide";
2
+ export declare function getPyodide(): Promise<Pyodide>;
1
3
  declare const _default: any;
2
4
  export default _default;
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dodona/papyros",
3
- "version": "0.1.61",
3
+ "version": "0.1.91-tar",
4
4
  "private": false,
5
5
  "homepage": ".",
6
6
  "devDependencies": {
@@ -31,6 +31,7 @@
31
31
  "ts-jest": "^27.0.7",
32
32
  "ts-loader": "^9.2.6",
33
33
  "typescript": "^4.1.2",
34
+ "url-loader": "^4.1.1",
34
35
  "webpack": "^5.64.0",
35
36
  "webpack-cli": "^4.9.1",
36
37
  "webpack-dev-server": "^4.6.0",
@@ -51,12 +52,15 @@
51
52
  "@codemirror/search": "^0.19.3",
52
53
  "@codemirror/state": "^0.19.6",
53
54
  "comlink": "^4.3.1",
55
+ "comsync": "^0.0.6",
54
56
  "escape-html": "^1.0.3",
55
57
  "i18n-js": "^3.8.0",
56
- "sync-message": "^0.0.8"
58
+ "pyodide-worker-runner": "^0.0.7",
59
+ "sync-message": "^0.0.9"
57
60
  },
58
61
  "scripts": {
59
- "start": "webpack serve --mode development",
62
+ "start": "yarn setup && webpack serve --mode development",
63
+ "setup": "bash scripts/setup.sh",
60
64
  "build:package": "webpack build --mode production --env=entry=./src/Library.ts",
61
65
  "build:app": "webpack build --mode production --env=entry=./src/App.ts",
62
66
  "test": "echo No tests defined yet",
@@ -1,6 +0,0 @@
1
- export interface PapyrosEvent {
2
- type: "input" | "output" | "script" | "success" | "error";
3
- data: string;
4
- runId: number;
5
- content?: string;
6
- }
@@ -1,8 +0,0 @@
1
- import { RenderOptions } from "./util/Util";
2
- export declare class StatusPanel {
3
- get statusSpinner(): HTMLElement;
4
- get statusText(): HTMLElement;
5
- showSpinner(show: boolean): void;
6
- setStatus(status: string): void;
7
- render(options: RenderOptions): HTMLElement;
8
- }
package/dist/library.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { CodeEditor } from "./CodeEditor";
2
- import { InputManager, InputMode } from "./InputManager";
3
- import { OutputManager } from "./OutputManager";
4
- import { Papyros } from "./Papyros";
5
- import { PapyrosEvent } from "./PapyrosEvent";
6
- import { StatusPanel } from "./StatusPanel";
7
- export * from "./ProgrammingLanguage";
8
- export type { PapyrosEvent };
9
- export { Papyros, CodeEditor, StatusPanel, InputManager, InputMode, OutputManager, };