@dodona/papyros 0.3.8 → 0.4.0-es6

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.
File without changes
package/dist/Papyros.d.ts CHANGED
File without changes
File without changes
@@ -0,0 +1,27 @@
1
+ import { CodeMirrorEditor } from "./CodeMirrorEditor";
2
+ import { UsedInputGutterInfo } from "./Gutters";
3
+ /**
4
+ * Editor to handle and highlight user input
5
+ */
6
+ export declare class BatchInputEditor extends CodeMirrorEditor {
7
+ /**
8
+ * Style classes used to highlight lines
9
+ */
10
+ private static HIGHLIGHT_CLASSES;
11
+ /**
12
+ * Gutters to show which lines were used
13
+ */
14
+ private usedInputGutters;
15
+ constructor();
16
+ /**
17
+ * Apply highlighting to the lines in the Editor
18
+ * @param {function(number): UsedInputGutterInfo} getInfo Function to obtain gutter
19
+ * info per line (1-based indexing)
20
+ */
21
+ highlight(getInfo: (lineNr: number) => UsedInputGutterInfo): void;
22
+ /**
23
+ * @return {Array<string>} Array of valid user input
24
+ * Data in the last line that is not terminated by a newline is omitted
25
+ */
26
+ getLines(): Array<string>;
27
+ }
@@ -1,20 +1,17 @@
1
- import { ProgrammingLanguage } from "./ProgrammingLanguage";
2
- import { Renderable, RenderOptions } from "./util/Rendering";
1
+ import { ProgrammingLanguage } from "../ProgrammingLanguage";
3
2
  import { CompletionSource } from "@codemirror/autocomplete";
4
3
  import { EditorView } from "@codemirror/view";
5
4
  import { Diagnostic } from "@codemirror/lint";
5
+ import { CodeMirrorEditor } from "./CodeMirrorEditor";
6
6
  /**
7
7
  * Component that provides useful features to users writing code
8
8
  */
9
- export declare class CodeEditor extends Renderable {
10
- /**
11
- * Reference to the user interface of the editor
12
- */
13
- readonly editorView: EditorView;
14
- /**
15
- * Mapping from CodeEditorOptions to a configurable compartment
16
- */
17
- private compartments;
9
+ export declare class CodeEditor extends CodeMirrorEditor {
10
+ static PROGRAMMING_LANGUAGE: string;
11
+ static INDENTATION: string;
12
+ static PANEL: string;
13
+ static AUTOCOMPLETION: string;
14
+ static LINTING: string;
18
15
  /**
19
16
  * Construct a new CodeEditor
20
17
  * @param {Function} onRunRequest Callback for when the user wants to run the code
@@ -22,20 +19,7 @@ export declare class CodeEditor extends Renderable {
22
19
  * @param {number} indentLength The length in spaces for the indent unit
23
20
  */
24
21
  constructor(onRunRequest: () => void, initialCode?: string, indentLength?: number);
25
- /**
26
- * Helper method to dispatch configuration changes at runtime
27
- * @param {Array<[Option, Extension]>} items Array of items to reconfigure
28
- * The option indicates the relevant compartment
29
- * The extension indicates the new configuration
30
- */
31
- private reconfigure;
32
- /**
33
- * Render the editor with the given options and panel
34
- * @param {RenderOptions} options Options for rendering
35
- * @param {HTMLElement} panel The panel to display at the bottom
36
- * @return {HTMLElement} The rendered element
37
- */
38
- protected _render(options: RenderOptions): void;
22
+ setDarkMode(darkMode: boolean): void;
39
23
  /**
40
24
  * @param {ProgrammingLanguage} language The language to use
41
25
  */
@@ -52,26 +36,10 @@ export declare class CodeEditor extends Renderable {
52
36
  * @param {number} indentLength The number of spaces to use for indentation
53
37
  */
54
38
  setIndentLength(indentLength: number): void;
55
- /**
56
- * @param {Function} onChange Listener that performs actions on the new contents
57
- */
58
- onChange(onChange: ((newContent: string) => void)): void;
59
39
  /**
60
40
  * @param {HTMLElement} panel The panel to display at the bottom of the editor
61
41
  */
62
42
  setPanel(panel: HTMLElement): void;
63
- /**
64
- * @return {string} The code within the editor
65
- */
66
- getCode(): string;
67
- /**
68
- * @param {string} code The new code to be shown in the editor
69
- */
70
- setCode(code: string): void;
71
- /**
72
- * Put focus on the CodeEditor
73
- */
74
- focus(): void;
75
43
  /**
76
44
  * @param {number} indentLength The amount of spaces to use
77
45
  * @return {string} The indentation unit to be used by CodeMirror
@@ -97,6 +65,7 @@ export declare class CodeEditor extends Renderable {
97
65
  * - active line highlighting
98
66
  * - active line gutter highlighting
99
67
  * - selection match highlighting
68
+ * - gutter for linting
100
69
  * Keymaps:
101
70
  * - the default command bindings
102
71
  * - bracket closing
@@ -0,0 +1,126 @@
1
+ /// <reference types="node" />
2
+ import { Compartment, Extension } from "@codemirror/state";
3
+ import { EditorView } from "@codemirror/view";
4
+ import { Renderable, RenderOptions } from "../util/Rendering";
5
+ import { StyleSpec } from "style-mod";
6
+ /**
7
+ * Data structure containing common elements for styling
8
+ */
9
+ export interface EditorStyling {
10
+ /**
11
+ * Array of HTML classes to apply to this editor
12
+ */
13
+ classes: Array<string>;
14
+ /**
15
+ * The maximum height of the editor
16
+ */
17
+ maxHeight: string;
18
+ /**
19
+ * The minimum height of the editor
20
+ */
21
+ minHeight: string;
22
+ /**
23
+ * Extra theme options to be passed to EditorView.theme
24
+ */
25
+ theme?: {
26
+ [selectorSpec: string]: StyleSpec;
27
+ };
28
+ }
29
+ /**
30
+ * Interface for listeners to textual changes in the editor
31
+ */
32
+ export interface DocChangeListener {
33
+ /**
34
+ * Method to call with the new document value
35
+ */
36
+ onChange: (code: string) => void;
37
+ /**
38
+ * How many milliseconds should pass since the last change
39
+ * before notifying (in case computations are expensive)
40
+ */
41
+ delay?: number;
42
+ }
43
+ /**
44
+ * Interface for storing data related to delayed function calls
45
+ */
46
+ interface TimeoutData {
47
+ /**
48
+ * The time in ms at which the last call occurred
49
+ */
50
+ lastCalled: number;
51
+ /**
52
+ * The timeout identifier associated with the delayed call
53
+ * null if not currently scheduled
54
+ */
55
+ timeout: NodeJS.Timeout | null;
56
+ }
57
+ /**
58
+ * Base class for Editors implemented using CodeMirror 6
59
+ * https://codemirror.net/6/
60
+ */
61
+ export declare abstract class CodeMirrorEditor extends Renderable {
62
+ static STYLE: string;
63
+ static PLACEHOLDER: string;
64
+ /**
65
+ * CodeMirror EditorView representing the internal editor
66
+ */
67
+ readonly editorView: EditorView;
68
+ /**
69
+ * Mapping of strings to Compartments associated with that property
70
+ */
71
+ protected compartments: Map<string, Compartment>;
72
+ /**
73
+ * Data to style this Editor
74
+ */
75
+ protected styling: EditorStyling;
76
+ /**
77
+ * Mapping for each change listener to its timeout identifier and last call time
78
+ */
79
+ protected listenerTimeouts: Map<DocChangeListener, TimeoutData>;
80
+ /**
81
+ * @param {Set<string>} compartments Identifiers for configurable extensions
82
+ * @param {EditorStyling} styling Data to style this editor
83
+ */
84
+ constructor(compartments: Set<string>, styling: EditorStyling);
85
+ /**
86
+ * @param {Extension} extension The extension to add to the Editor
87
+ */
88
+ protected addExtension(extension: Extension): void;
89
+ /**
90
+ * @return {string} The text within the editor
91
+ */
92
+ getText(): string;
93
+ /**
94
+ * @param {string} text The new value to be shown in the editor
95
+ */
96
+ setText(text: string): void;
97
+ /**
98
+ * Helper method to dispatch configuration changes at runtime
99
+ * @param {Array<[Option, Extension]>} items Array of items to reconfigure
100
+ * The option indicates the relevant compartment
101
+ * The extension indicates the new configuration
102
+ */
103
+ reconfigure(...items: Array<[string, Extension]>): void;
104
+ /**
105
+ * Apply focus to the Editor
106
+ */
107
+ focus(): void;
108
+ /**
109
+ * @param {string} placeholderValue The contents of the placeholder
110
+ */
111
+ setPlaceholder(placeholderValue: string): void;
112
+ /**
113
+ * @param {boolean} darkMode Whether to use dark mode
114
+ */
115
+ setDarkMode(darkMode: boolean): void;
116
+ protected _render(options: RenderOptions): void;
117
+ /**
118
+ * Process the changes by informing the listeners of the new contents
119
+ */
120
+ private handleChange;
121
+ /**
122
+ * @param {DocChangeListener} changeListener Listener that performs actions on the new contents
123
+ */
124
+ onChange(changeListener: DocChangeListener): void;
125
+ }
126
+ export {};
@@ -0,0 +1,94 @@
1
+ import { StateEffectType, StateField } from "@codemirror/state";
2
+ import { Extension } from "@codemirror/state";
3
+ import { GutterMarker } from "@codemirror/view";
4
+ import { EditorView } from "@codemirror/view";
5
+ /**
6
+ * Data used in Gutter elements
7
+ */
8
+ export interface GutterInfo {
9
+ /**
10
+ * The number of the line (1-based)
11
+ */
12
+ lineNr: number;
13
+ /**
14
+ * Whether the Gutter element should be shown
15
+ */
16
+ on: boolean;
17
+ }
18
+ /**
19
+ * Configuration for Gutters
20
+ */
21
+ export interface IGutterConfig<Info extends GutterInfo> {
22
+ /**
23
+ * Name of this Gutter
24
+ */
25
+ name: string;
26
+ /**
27
+ * Handler for when a Gutter element is clicked
28
+ */
29
+ onClick?: (view: EditorView, info: Info) => void;
30
+ /**
31
+ * Extra extensions to use for the Gutters
32
+ */
33
+ extraExtensions?: Extension;
34
+ }
35
+ export declare abstract class Gutters<Info extends GutterInfo = GutterInfo, Config extends IGutterConfig<Info> = IGutterConfig<Info>> {
36
+ /**
37
+ * Config used to initialize the Gutters
38
+ */
39
+ protected config: Config;
40
+ /**
41
+ * Effect to signal changes in the Gutters
42
+ */
43
+ protected effect: StateEffectType<Info>;
44
+ /**
45
+ * Current state of the Gutters
46
+ * Consists of a mapping for line numbers to Info objects
47
+ */
48
+ protected state: StateField<Map<number, Info>>;
49
+ constructor(config: Config);
50
+ /**
51
+ * Render a marker with the given info
52
+ * @param {Info} info Info used to render the marker
53
+ * Will only be called when info.on is True
54
+ */
55
+ protected abstract marker(info: Info): GutterMarker;
56
+ /**
57
+ * Set a marker with the given info
58
+ * @param {EditorView} view View in which the Gutters live
59
+ * @param {Info} info Info used to render the marker
60
+ */
61
+ setMarker(view: EditorView, info: Info): void;
62
+ /**
63
+ * @return {Extension} The Gutters as a CodeMirror Extension
64
+ */
65
+ toExtension(): Extension;
66
+ }
67
+ /**
68
+ * Gutters to show and allow toggling of breakpoints
69
+ */
70
+ export declare class BreakpointsGutter extends Gutters {
71
+ constructor();
72
+ protected marker(): GutterMarker;
73
+ /**
74
+ * @param {EditorView} view The view in which the Gutters live
75
+ * @return {Set<number>} The 1-based line numbers with a breakpoint
76
+ */
77
+ getBreakpoints(view: EditorView): Set<number>;
78
+ }
79
+ /**
80
+ * Extra data used to represent input gutters
81
+ */
82
+ export interface UsedInputGutterInfo extends GutterInfo {
83
+ /**
84
+ * Text value to display when hovering over the Gutter element
85
+ */
86
+ title: string;
87
+ }
88
+ /**
89
+ * Gutters to show a checkmark for used input
90
+ */
91
+ export declare class UsedInputGutters extends Gutters<UsedInputGutterInfo> {
92
+ constructor();
93
+ protected marker(info: UsedInputGutterInfo): GutterMarker;
94
+ }
File without changes
File without changes
File without changes
@@ -1,11 +1,20 @@
1
1
  import { InputMode } from "../InputManager";
2
2
  import { UserInputHandler } from "./UserInputHandler";
3
3
  import { RenderOptions } from "../util/Rendering";
4
+ import { BatchInputEditor } from "../editor/BatchInputEditor";
4
5
  export declare class BatchInputHandler extends UserInputHandler {
5
6
  /**
6
7
  * The index of the next line in lines to send
7
8
  */
8
9
  private lineNr;
10
+ /**
11
+ * Messages used when asking for user input
12
+ */
13
+ private prompts;
14
+ /**
15
+ * Editor containing the input of the user
16
+ */
17
+ readonly batchEditor: BatchInputEditor;
9
18
  /**
10
19
  * The previous input of the user
11
20
  * Is restored upon switching back to InputMode.Batch
@@ -16,6 +25,11 @@ export declare class BatchInputHandler extends UserInputHandler {
16
25
  * @param {function()} inputCallback Callback for when the user has entered a value
17
26
  */
18
27
  constructor(inputCallback: () => void);
28
+ /**
29
+ * Handle new input, potentially sending it to the awaiting receiver
30
+ * @param {string} newInput The new user input
31
+ */
32
+ private handleInputChanged;
19
33
  toggle(active: boolean): void;
20
34
  getInputMode(): InputMode;
21
35
  /**
@@ -24,8 +38,12 @@ export declare class BatchInputHandler extends UserInputHandler {
24
38
  */
25
39
  protected get lines(): Array<string>;
26
40
  hasNext(): boolean;
41
+ private highlight;
27
42
  next(): string;
28
43
  onRunStart(): void;
29
44
  onRunEnd(): void;
45
+ waitWithPrompt(waiting: boolean, prompt?: string): void;
46
+ protected setPlaceholder(placeholderValue: string): void;
47
+ focus(): void;
30
48
  protected _render(options: RenderOptions): void;
31
49
  }
File without changes
@@ -48,6 +48,14 @@ export declare abstract class UserInputHandler extends Renderable {
48
48
  * Retrieve the HTMLInputElement for this InputHandler
49
49
  */
50
50
  get inputArea(): HTMLInputElement;
51
+ /**
52
+ * @param {string} placeholder The placeholder to show
53
+ */
54
+ protected setPlaceholder(placeholder: string): void;
55
+ /**
56
+ * Focus the area in which the user enters input
57
+ */
58
+ focus(): void;
51
59
  /**
52
60
  * Wait for input of the user for a certain prompt
53
61
  * @param {boolean} waiting Whether we are waiting for input
File without changes
File without changes
File without changes
@@ -45,4 +45,10 @@ export declare function downloadResults(data: string, filename: string): void;
45
45
  * @return {string} The current url
46
46
  */
47
47
  export declare function cleanCurrentUrl(endingSlash?: boolean): string;
48
+ /**
49
+ * Focus an element, setting the user's caret at the end of the contents
50
+ * Needed to ensure focusing a contenteditable element works as expected
51
+ * @param {HTMLElement} el The element to focus
52
+ */
53
+ export declare function placeCaretAtEnd(el: HTMLElement): void;
48
54
  export {};
File without changes
@@ -1 +1 @@
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,(()=>(()=>{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,{isServiceWorkerRequest:()=>s,serviceWorkerFetchListener:()=>i,asyncSleep:()=>u,ServiceWorkerError:()=>a,writeMessageAtomics:()=>c,writeMessageServiceWorker:()=>f,writeMessage:()=>l,makeChannel:()=>d,makeAtomicsChannel:()=>y,makeServiceWorkerChannel:()=>p,readMessage:()=>h,syncSleep:()=>v,uuidv4:()=>g});var r=function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{a(n.next(e))}catch(e){s(e)}}function u(e){try{a(n.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}a((n=n.apply(e,t||[])).next())}))};const n="__SyncMessageServiceWorkerInput__",o="__sync-message-v2__";function s(e){return"string"!=typeof e&&(e=e.request.url),e.includes(n)}function i(){const e={},t={};return n=>{const{url:i}=n.request;return!!s(i)&&(n.respondWith(function(){return r(this,void 0,void 0,(function*(){function r(e){const t={message:e,version:o};return new Response(JSON.stringify(t),{status:200})}if(i.endsWith("/read")){const{messageId:o,timeout:s}=yield n.request.json(),i=e[o];return i?(delete e[o],r(i)):yield new Promise((e=>{t[o]=e,setTimeout((function(){delete t[o],e(new Response("",{status:408}))}),s)}))}if(i.endsWith("/write")){const{message:o,messageId:s}=yield n.request.json(),i=t[s];return i?(i(r(o)),delete t[s]):e[s]=o,r({early:!i})}if(i.endsWith("/version"))return new Response(o,{status:200})}))}()),!0)}}function u(e){return new Promise((t=>setTimeout(t,e)))}class a 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,a.prototype)}}function c(e,t){const r=(new TextEncoder).encode(JSON.stringify(t)),{data:n,meta:o}=e;if(r.length>n.length)throw new Error("Message is too big, increase bufferSize when making channel.");n.set(r,0),Atomics.store(o,0,r.length),Atomics.store(o,1,1),Atomics.notify(o,1)}function f(e,t,n){return r(this,void 0,void 0,(function*(){yield navigator.serviceWorker.ready;const r=e.baseUrl+"/write",s=Date.now();for(;;){const i={message:t,messageId:n},c=yield fetch(r,{method:"POST",body:JSON.stringify(i)});if(200===c.status&&(yield c.json()).version===o)return;if(!(Date.now()-s<e.timeout))throw new a(r,c.status);yield u(100)}}))}function l(e,t,n){return r(this,void 0,void 0,(function*(){"atomics"===e.type?c(e,t):yield f(e,t,n)}))}function d(e={}){return"undefined"!=typeof SharedArrayBuffer?y(e.atomics):"serviceWorker"in navigator?p(e.serviceWorker):null}function y({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||"/")+n,timeout:e.timeout||5e3}}function m(e,t){return e>0?+e:t}function h(e,t,{checkInterrupt:r,checkTimeout:n,timeout:s}={}){const i=performance.now();n=m(n,r?100:5e3);const u=m(s,Number.POSITIVE_INFINITY);let c;if("atomics"===e.type){const{data:t,meta:r}=e;c=()=>{if("timed-out"===Atomics.wait(r,1,0,n))return null;{const e=Atomics.exchange(r,0,0),n=t.slice(0,e);Atomics.store(r,1,0);const o=(new TextDecoder).decode(n);return JSON.parse(o)}}}else c=()=>{const r=new XMLHttpRequest,s=e.baseUrl+"/read";r.open("POST",s,!1);const u={messageId:t,timeout:n};r.send(JSON.stringify(u));const{status:c}=r;if(408===c)return null;if(200===c){const e=JSON.parse(r.responseText);return e.version!==o?null:e.message}if(performance.now()-i<e.timeout)return null;throw new a(s,c)};for(;;){const e=u-(performance.now()-i);if(e<=0)return null;n=Math.min(n,e);const t=c();if(null!==t)return t;if(null==r?void 0:r())return null}}function v(e,t){if(e=m(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} ${g()}`,{timeout:e})}let g;return g="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 r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{InputWorker:()=>s});var e=r(137),t=function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{a(n.next(e))}catch(e){s(e)}}function u(e){try{a(n.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}a((n=n.apply(e,t||[])).next())}))},o=function(e,t){var r,n,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},s=function(){function r(t){void 0===t&&(t=""),this.hostName=t,this.syncMessageListener=(0,e.serviceWorkerFetchListener)()}return r.prototype.handleInputRequest=function(e){return t(this,void 0,void 0,(function(){var t;return o(this,(function(r){return this.syncMessageListener(e)?[2,!0]:(t=e.request.url,this.hostName&&t.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])}))}))},r}()})(),n})()));
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,(()=>(()=>{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,{isServiceWorkerRequest:()=>s,serviceWorkerFetchListener:()=>i,asyncSleep:()=>u,ServiceWorkerError:()=>c,writeMessageAtomics:()=>a,writeMessageServiceWorker:()=>f,writeMessage:()=>d,makeChannel:()=>l,makeAtomicsChannel:()=>y,makeServiceWorkerChannel:()=>p,readMessage:()=>h,syncSleep:()=>v,uuidv4:()=>g});var r=function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function u(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}c((n=n.apply(e,t||[])).next())}))};const n="__SyncMessageServiceWorkerInput__",o="__sync-message-v2__";function s(e){return"string"!=typeof e&&(e=e.request.url),e.includes(n)}function i(){const e={},t={};return n=>{const{url:i}=n.request;return!!s(i)&&(n.respondWith(function(){return r(this,void 0,void 0,(function*(){function r(e){const t={message:e,version:o};return new Response(JSON.stringify(t),{status:200})}if(i.endsWith("/read")){const{messageId:o,timeout:s}=yield n.request.json(),i=e[o];return i?(delete e[o],r(i)):yield new Promise((e=>{t[o]=e,setTimeout((function(){delete t[o],e(new Response("",{status:408}))}),s)}))}if(i.endsWith("/write")){const{message:o,messageId:s}=yield n.request.json(),i=t[s];return i?(i(r(o)),delete t[s]):e[s]=o,r({early:!i})}if(i.endsWith("/version"))return new Response(o,{status:200})}))}()),!0)}}function u(e){return new Promise((t=>setTimeout(t,e)))}class c 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,c.prototype)}}function a(e,t){const r=(new TextEncoder).encode(JSON.stringify(t)),{data:n,meta:o}=e;if(r.length>n.length)throw new Error("Message is too big, increase bufferSize when making channel.");n.set(r,0),Atomics.store(o,0,r.length),Atomics.store(o,1,1),Atomics.notify(o,1)}function f(e,t,n){return r(this,void 0,void 0,(function*(){yield navigator.serviceWorker.ready;const r=e.baseUrl+"/write",s=Date.now();for(;;){const i={message:t,messageId:n},a=yield fetch(r,{method:"POST",body:JSON.stringify(i)});if(200===a.status&&(yield a.json()).version===o)return;if(!(Date.now()-s<e.timeout))throw new c(r,a.status);yield u(100)}}))}function d(e,t,n){return r(this,void 0,void 0,(function*(){"atomics"===e.type?a(e,t):yield f(e,t,n)}))}function l(e={}){return"undefined"!=typeof SharedArrayBuffer?y(e.atomics):"serviceWorker"in navigator?p(e.serviceWorker):null}function y({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||"/")+n,timeout:e.timeout||5e3}}function m(e,t){return e>0?+e:t}function h(e,t,{checkInterrupt:r,checkTimeout:n,timeout:s}={}){const i=performance.now();n=m(n,r?100:5e3);const u=m(s,Number.POSITIVE_INFINITY);let a;if("atomics"===e.type){const{data:t,meta:r}=e;a=()=>{if("timed-out"===Atomics.wait(r,1,0,n))return null;{const e=Atomics.exchange(r,0,0),n=t.slice(0,e);Atomics.store(r,1,0);const o=(new TextDecoder).decode(n);return JSON.parse(o)}}}else a=()=>{const r=new XMLHttpRequest,s=e.baseUrl+"/read";r.open("POST",s,!1);const u={messageId:t,timeout:n};r.send(JSON.stringify(u));const{status:a}=r;if(408===a)return null;if(200===a){const e=JSON.parse(r.responseText);return e.version!==o?null:e.message}if(performance.now()-i<e.timeout)return null;throw new c(s,a)};for(;;){const e=u-(performance.now()-i);if(e<=0)return null;n=Math.min(n,e);const t=a();if(null!==t)return t;if(null==r?void 0:r())return null}}function v(e,t){if(e=m(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} ${g()}`,{timeout:e})}let g;return g="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 r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{InputWorker:()=>o});var e=r(137),t=function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function u(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}c((n=n.apply(e,t||[])).next())}))};class o{constructor(t=""){this.hostName=t,this.syncMessageListener=(0,e.serviceWorkerFetchListener)()}handleInputRequest(e){return t(this,void 0,void 0,(function*(){if(this.syncMessageListener(e))return!0;const t=e.request.url;return!(!this.hostName||!t.includes(this.hostName))&&(e.respondWith(fetch(e.request).then((e=>{const t=new Headers(e.headers);t.set("Cross-Origin-Embedder-Policy","require-corp"),t.set("Cross-Origin-Opener-Policy","same-origin"),t.set("Cross-Origin-Resource-Policy","cross-origin");return new Response(e.body,{status:e.status||200,statusText:e.statusText,headers:t})}))),!0)}))}}})(),n})()));
File without changes
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@dodona/papyros",
3
- "version": "0.3.8",
3
+ "version": "0.4.0-es6",
4
4
  "private": false,
5
5
  "homepage": ".",
6
6
  "devDependencies": {
7
7
  "@types/escape-html": "^1.0.1",
8
8
  "@types/i18n-js": "^3.8.2",
9
9
  "@types/jest": "27.4.1",
10
- "@types/serviceworker": "^0.0.44",
10
+ "@types/serviceworker": "^0.0.46",
11
11
  "@typescript-eslint/eslint-plugin": "^5.21.0",
12
12
  "@typescript-eslint/parser": "^5.21.0",
13
13
  "autoprefixer": "^10.4.0",
@@ -19,7 +19,7 @@
19
19
  "jest": "27.0.0",
20
20
  "postcss": "^8.3.11",
21
21
  "postcss-import": "^14.0.2",
22
- "postcss-loader": "^6.2.0",
22
+ "postcss-loader": "^7.0.0",
23
23
  "style-loader": "^3.3.1",
24
24
  "tailwindcss": "^3.0.24",
25
25
  "terser-webpack-plugin": "^5.3.1",