@dodona/papyros 0.1.62 → 0.1.90

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 (50) hide show
  1. package/dist/App.js +1 -0
  2. package/dist/Backend.d.ts +16 -6
  3. package/dist/Backend.js +1 -0
  4. package/dist/BackendManager.d.ts +10 -1
  5. package/dist/BackendManager.js +1 -0
  6. package/dist/CodeEditor.d.ts +86 -0
  7. package/dist/CodeEditor.js +1 -0
  8. package/dist/Constants.d.ts +17 -16
  9. package/dist/Constants.js +1 -0
  10. package/dist/InputManager.d.ts +24 -16
  11. package/dist/InputManager.js +1 -0
  12. package/dist/{inputServiceWorker.js → InputServiceWorker.js} +1 -1
  13. package/dist/{library.d.ts → Library.d.ts} +3 -2
  14. package/dist/Library.js +1 -0
  15. package/dist/OutputManager.d.ts +59 -5
  16. package/dist/OutputManager.js +1 -0
  17. package/dist/Papyros.d.ts +176 -33
  18. package/dist/Papyros.js +1 -0
  19. package/dist/PapyrosEvent.d.ts +19 -3
  20. package/dist/PapyrosEvent.js +1 -0
  21. package/dist/ProgrammingLanguage.d.ts +3 -0
  22. package/dist/ProgrammingLanguage.js +1 -0
  23. package/dist/RunListener.d.ts +13 -0
  24. package/dist/RunListener.js +1 -0
  25. package/dist/RunStateManager.d.ts +67 -0
  26. package/dist/RunStateManager.js +1 -0
  27. package/dist/Translations.js +1 -0
  28. package/dist/examples/Examples.js +1 -0
  29. package/dist/examples/JavaScriptExamples.js +1 -0
  30. package/dist/examples/PythonExamples.js +1 -0
  31. package/dist/input/BatchInputHandler.d.ts +32 -0
  32. package/dist/input/BatchInputHandler.js +1 -0
  33. package/dist/input/InteractiveInputHandler.d.ts +28 -0
  34. package/dist/input/InteractiveInputHandler.js +1 -0
  35. package/dist/input/UserInputHandler.d.ts +70 -0
  36. package/dist/input/UserInputHandler.js +1 -0
  37. package/dist/util/HTMLShapes.d.ts +13 -0
  38. package/dist/util/HTMLShapes.js +1 -0
  39. package/dist/util/Logging.d.ts +9 -0
  40. package/dist/util/Logging.js +1 -0
  41. package/dist/util/Util.d.ts +94 -2
  42. package/dist/util/Util.js +1 -0
  43. package/dist/workers/input/InputWorker.d.ts +19 -3
  44. package/dist/workers/input/InputWorker.js +1 -0
  45. package/dist/workers/python/Pyodide.d.ts +19 -0
  46. package/dist/workers/python/Pyodide.js +1 -0
  47. package/package.json +6 -5
  48. package/dist/StatusPanel.d.ts +0 -8
  49. package/dist/index.js +0 -2
  50. package/dist/index.js.LICENSE.txt +0 -7
@@ -1,15 +1,107 @@
1
1
  import I18n from "i18n-js";
2
+ import { PapyrosEvent } from "../PapyrosEvent";
2
3
  export declare const t: typeof I18n.t;
4
+ /**
5
+ * Add the translations for Papyros to the I18n instance
6
+ */
3
7
  export declare function loadTranslations(): void;
4
8
  export declare function getLocales(): Array<string>;
9
+ /**
10
+ * Constructs the options for use within an HTML select element
11
+ * @param {Array<T>} options All options to display in the list
12
+ * @param {function(T):string} optionText Function to convert the elements to a string
13
+ * @param {T} selected The initially selected element in the list, if any
14
+ * @return {string} The string representation of the select options
15
+ */
5
16
  export declare function getSelectOptions<T>(options: Array<T>, optionText: (option: T) => string, selected?: T): string;
17
+ /**
18
+ * Constructs an HTML select element
19
+ * @param {string} selectId The HTML id for the element
20
+ * @param {Array<T>} options to display in the list
21
+ * @param {function(T):string} optionText to convert elements to a string
22
+ * @param {T} selected The initially selected element in the list, if any
23
+ * @param {string} labelText Optional text to display in a label
24
+ * @return {string} The string representation of the select element
25
+ */
6
26
  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;
27
+ /**
28
+ * Interface for options to use while rendering a button element
29
+ */
30
+ export interface ButtonOptions {
31
+ /**
32
+ * The HTML id of the button
33
+ */
34
+ id: string;
35
+ /**
36
+ * The text to display in the button, can also be HTML
37
+ */
38
+ buttonText: string;
39
+ /**
40
+ * Optional classes to apply to the button
41
+ */
42
+ extraClasses?: string;
43
+ }
44
+ /**
45
+ * Construct a HTML button string from the given options
46
+ * @param {ButtonOptions} options The options for the button
47
+ * @return {string} HTML string for the button
48
+ */
49
+ export declare function renderButton(options: ButtonOptions): string;
50
+ /**
51
+ * Helper type to access a HTML element, either via its id or the element itself
52
+ */
53
+ declare type ElementIdentifier = string | HTMLElement;
54
+ /**
55
+ * Add a listener to an HTML element for an event on an attribute
56
+ * Element attributes tend to be strings, but string Enums can also be used
57
+ * by using the type-parameter T
58
+ * @param {ElementIdentifier} elementId Identifier for the element
59
+ * @param {function(T)} onEvent The listener for the event
60
+ * @param {string} eventType The type of the event
61
+ * @param {string} attribute The attribute affected by the event
62
+ */
63
+ export declare function addListener<T extends string>(elementId: ElementIdentifier, onEvent: (e: T) => void, eventType?: string, attribute?: string): void;
64
+ /**
65
+ * Unset the selected item of a select element to prevent a default selection
66
+ * @param {ElementIdentifier} selectId Identifier for the select element
67
+ */
8
68
  export declare function removeSelection(selectId: string): void;
69
+ /**
70
+ * Useful options for rendering an element
71
+ */
9
72
  export interface RenderOptions {
73
+ /**
74
+ * String identifier for the parent in which the element will be rendered
75
+ */
10
76
  parentElementId: string;
77
+ /**
78
+ * Names of HTML classes to be added to the element, separated by 1 space
79
+ */
11
80
  classNames?: string;
81
+ /**
82
+ * Extra attributes to add to the element, such as style or data
83
+ */
12
84
  attributes?: Map<string, string>;
13
85
  }
14
- export declare function getElement(element: string | HTMLElement): HTMLElement;
86
+ /**
87
+ * Resolve an ElementIdentifier to the corresponding HTLMElement
88
+ * @param {ElementIdentifier} elementId The identifier for the element
89
+ * @return {T} The corresponding element
90
+ */
91
+ export declare function getElement<T extends HTMLElement>(elementId: ElementIdentifier): T;
92
+ /**
93
+ * Renders an element with the given options
94
+ * @param {RenderOptions} options Options to be used while rendering
95
+ * @param {string | HTMLElement} content What to fill the parent with.
96
+ * If the content is a string, it should be properly formatted HTML
97
+ * @return {HTMLElement} The parent with the new child
98
+ */
15
99
  export declare function renderWithOptions(options: RenderOptions, content: string | HTMLElement): HTMLElement;
100
+ /**
101
+ * Parse the data contained within a PapyrosEvent using its contentType
102
+ * Supported content types are: text/plain, text/json, img/png;base64
103
+ * @param {PapyrosEvent} e Event containing data
104
+ * @return {any} The parsed data
105
+ */
106
+ export declare function parseEventData(e: PapyrosEvent): any;
107
+ export {};
@@ -0,0 +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,(function(){return(()=>{var e={13:function(e,t,r){var n,a;a=this,n=function(){return function(e){"use strict";var t=e&&e.I18n||{},r=Array.prototype.slice,n=function(e){return("0"+e.toString()).substr(-2)},a=function(e,t){return d("round",e,-t).toFixed(t)},o=function(e){var t=typeof e;return"function"===t||"object"===t},i=function(e){return"function"==typeof e},l=function(e){return null!=e},s=function(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)},u=function(e){return"string"==typeof e||"[object String]"===Object.prototype.toString.call(e)},c=function(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)},p=function(e){return!0===e||!1===e},f=function(e){return null===e},d=function(e,t,r){return void 0===r||0==+r?Math[e](t):(t=+t,r=+r,isNaN(t)||"number"!=typeof r||r%1!=0?NaN:(t=t.toString().split("e"),+((t=(t=Math[e](+(t[0]+"e"+(t[1]?+t[1]-r:-r)))).toString().split("e"))[0]+"e"+(t[1]?+t[1]+r:r))))},h=function(e,t){return i(e)?e(t):e},g=function(e,t){var r,n;for(r in t)t.hasOwnProperty(r)&&(n=t[r],u(n)||c(n)||p(n)||s(n)||f(n)?e[r]=n:(null==e[r]&&(e[r]={}),g(e[r],n)));return e},m={day_names:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbr_day_names:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],month_names:[null,"January","February","March","April","May","June","July","August","September","October","November","December"],abbr_month_names:[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],meridian:["AM","PM"]},y={precision:3,separator:".",delimiter:",",strip_insignificant_zeros:!1},v={unit:"$",precision:2,format:"%u%n",sign_first:!0,delimiter:",",separator:"."},b={unit:"%",precision:3,format:"%n%u",separator:".",delimiter:""},S=[null,"kb","mb","gb","tb"],_={defaultLocale:"en",locale:"en",defaultSeparator:".",placeholder:/(?:\{\{|%\{)(.*?)(?:\}\}?)/gm,fallbacks:!1,translations:{},missingBehaviour:"message",missingTranslationPrefix:""};return t.reset=function(){var e;for(e in _)this[e]=_[e]},t.initializeOptions=function(){var e;for(e in _)l(this[e])||(this[e]=_[e])},t.initializeOptions(),t.locales={},t.locales.get=function(e){var r=this[e]||this[t.locale]||this.default;return i(r)&&(r=r(e)),!1===s(r)&&(r=[r]),r},t.locales.default=function(e){var r=[],n=[];return e&&r.push(e),!e&&t.locale&&r.push(t.locale),t.fallbacks&&t.defaultLocale&&r.push(t.defaultLocale),r.forEach((function(e){var r=e.split("-"),a=null,o=null;3===r.length?(a=[r[0],r[1]].join("-"),o=r[0]):2===r.length&&(a=r[0]),-1===n.indexOf(e)&&n.push(e),t.fallbacks&&[a,o].forEach((function(t){null!=t&&t!==e&&-1===n.indexOf(t)&&n.push(t)}))})),r.length||r.push("en"),n},t.pluralization={},t.pluralization.get=function(e){return this[e]||this[t.locale]||this.default},t.pluralization.default=function(e){switch(e){case 0:return["zero","other"];case 1:return["one"];default:return["other"]}},t.currentLocale=function(){return this.locale||this.defaultLocale},t.isSet=l,t.lookup=function(e,t){t=t||{};var r,n,a,o,i=this.locales.get(t.locale).slice();for(a=this.getFullScope(e,t);i.length;)if(r=i.shift(),n=a.split(t.separator||this.defaultSeparator),o=this.translations[r]){for(;n.length&&null!=(o=o[n.shift()]););if(null!=o)return o}if(l(t.defaultValue))return h(t.defaultValue,e)},t.pluralizationLookupWithoutFallback=function(e,t,r){var n,a,i=this.pluralization.get(t)(e);if(o(r))for(;i.length;)if(n=i.shift(),l(r[n])){a=r[n];break}return a},t.pluralizationLookup=function(e,t,r){r=r||{};var n,a,i,s,u=this.locales.get(r.locale).slice();for(t=this.getFullScope(t,r);u.length;)if(n=u.shift(),a=t.split(r.separator||this.defaultSeparator),i=this.translations[n]){for(;a.length&&(i=i[a.shift()],o(i));)0===a.length&&(s=this.pluralizationLookupWithoutFallback(e,n,i));if(null!=s)break}return null==s&&l(r.defaultValue)&&(s=o(r.defaultValue)?this.pluralizationLookupWithoutFallback(e,r.locale,r.defaultValue):r.defaultValue,i=r.defaultValue),{message:s,translations:i}},t.meridian=function(){var e=this.lookup("time"),t=this.lookup("date");return e&&e.am&&e.pm?[e.am,e.pm]:t&&t.meridian?t.meridian:m.meridian},t.prepareOptions=function(){for(var e,t=r.call(arguments),n={};t.length;)if("object"==typeof(e=t.shift()))for(var a in e)e.hasOwnProperty(a)&&(l(n[a])||(n[a]=e[a]));return n},t.createTranslationOptions=function(e,t){var r=[{scope:e}];return l(t.defaults)&&(r=r.concat(t.defaults)),l(t.defaultValue)&&r.push({message:t.defaultValue}),r},t.translate=function(e,t){t=t||{};var r,n=this.createTranslationOptions(e,t),a=e,i=this.prepareOptions(t);return delete i.defaultValue,n.some((function(t){if(l(t.scope)?(a=t.scope,r=this.lookup(a,i)):l(t.message)&&(r=h(t.message,e)),null!=r)return!0}),this)?("string"==typeof r?r=this.interpolate(r,t):s(r)?r=r.map((function(e){return"string"==typeof e?this.interpolate(e,t):e}),this):o(r)&&l(t.count)&&(r=this.pluralize(t.count,a,t)),r):this.missingTranslation(e,t)},t.interpolate=function(e,t){if(null==e)return e;t=t||{};var r,n,a,o,i=e.match(this.placeholder);if(!i)return e;for(;i.length;)a=(r=i.shift()).replace(this.placeholder,"$1"),n=l(t[a])?t[a].toString().replace(/\$/gm,"_#$#_"):a in t?this.nullPlaceholder(r,e,t):this.missingPlaceholder(r,e,t),o=new RegExp(r.replace(/{/gm,"\\{").replace(/}/gm,"\\}")),e=e.replace(o,n);return e.replace(/_#\$#_/g,"$")},t.pluralize=function(e,t,r){var n,a;return r=this.prepareOptions({count:String(e)},r),void 0===(a=this.pluralizationLookup(e,t,r)).translations||null==a.translations?this.missingTranslation(t,r):void 0!==a.message&&null!=a.message?this.interpolate(a.message,r):(n=this.pluralization.get(r.locale),this.missingTranslation(t+"."+n(e)[0],r))},t.missingTranslation=function(e,t){if("guess"===this.missingBehaviour){var r=e.split(".").slice(-1)[0];return(this.missingTranslationPrefix.length>0?this.missingTranslationPrefix:"")+r.replace(/_/g," ").replace(/([a-z])([A-Z])/g,(function(e,t,r){return t+" "+r.toLowerCase()}))}return'[missing "'+[null!=t&&null!=t.locale?t.locale:this.currentLocale(),this.getFullScope(e,t)].join(t.separator||this.defaultSeparator)+'" translation]'},t.missingPlaceholder=function(e,t,r){return"[missing "+e+" value]"},t.nullPlaceholder=function(){return t.missingPlaceholder.apply(t,arguments)},t.toNumber=function(e,t){t=this.prepareOptions(t,this.lookup("number.format"),y);var r,n,o=e<0,i=a(Math.abs(e),t.precision).toString().split("."),l=[],s=t.format||"%n",u=o?"-":"";for(e=i[0],r=i[1];e.length>0;)l.unshift(e.substr(Math.max(0,e.length-3),3)),e=e.substr(0,e.length-3);return n=l.join(t.delimiter),t.strip_insignificant_zeros&&r&&(r=r.replace(/0+$/,"")),t.precision>0&&r&&(n+=t.separator+r),n=(s=t.sign_first?"%s"+s:s.replace("%n","%s%n")).replace("%u",t.unit).replace("%n",n).replace("%s",u)},t.toCurrency=function(e,t){return t=this.prepareOptions(t,this.lookup("number.currency.format",t),this.lookup("number.format",t),v),this.toNumber(e,t)},t.localize=function(e,t,r){switch(r||(r={}),e){case"currency":return this.toCurrency(t,r);case"number":return e=this.lookup("number.format",r),this.toNumber(t,e);case"percentage":return this.toPercentage(t,r);default:var n;return n=e.match(/^(date|time)/)?this.toTime(e,t,r):t.toString(),this.interpolate(n,r)}},t.parseDate=function(e){var t,r,n;if(null==e)return e;if("object"==typeof e)return e;if(t=e.toString().match(/(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2}):(\d{2})([\.,]\d{1,3})?)?(Z|\+00:?00)?/)){for(var a=1;a<=6;a++)t[a]=parseInt(t[a],10)||0;t[2]-=1,n=t[7]?1e3*("0"+t[7]):null,r=t[8]?new Date(Date.UTC(t[1],t[2],t[3],t[4],t[5],t[6],n)):new Date(t[1],t[2],t[3],t[4],t[5],t[6],n)}else"number"==typeof e?(r=new Date).setTime(e):e.match(/([A-Z][a-z]{2}) ([A-Z][a-z]{2}) (\d+) (\d+:\d+:\d+) ([+-]\d+) (\d+)/)?(r=new Date).setTime(Date.parse([RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$6,RegExp.$4,RegExp.$5].join(" "))):(e.match(/\d+ \d+:\d+:\d+ [+-]\d+ \d+/),(r=new Date).setTime(Date.parse(e)));return r},t.strftime=function(e,r,a){a=this.lookup("date",a);var o=t.meridian();if(a||(a={}),a=this.prepareOptions(a,m),isNaN(e.getTime()))throw new Error("I18n.strftime() requires a valid date object, but received an invalid date.");var i=e.getDay(),l=e.getDate(),s=e.getFullYear(),u=e.getMonth()+1,c=e.getHours(),p=c,f=c>11?1:0,d=e.getSeconds(),h=e.getMinutes(),g=e.getTimezoneOffset(),y=Math.floor(Math.abs(g/60)),v=Math.abs(g)-60*y,b=(g>0?"-":"+")+(y.toString().length<2?"0"+y:y)+(v.toString().length<2?"0"+v:v);return p>12?p-=12:0===p&&(p=12),r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=r.replace("%a",a.abbr_day_names[i])).replace("%A",a.day_names[i])).replace("%b",a.abbr_month_names[u])).replace("%B",a.month_names[u])).replace("%d",n(l))).replace("%e",l)).replace("%-d",l)).replace("%H",n(c))).replace("%-H",c)).replace("%k",c)).replace("%I",n(p))).replace("%-I",p)).replace("%l",p)).replace("%m",n(u))).replace("%-m",u)).replace("%M",n(h))).replace("%-M",h)).replace("%p",o[f])).replace("%P",o[f].toLowerCase())).replace("%S",n(d))).replace("%-S",d)).replace("%w",i)).replace("%y",n(s))).replace("%-y",n(s).replace(/^0+/,""))).replace("%Y",s)).replace("%z",b)).replace("%Z",b)},t.toTime=function(e,t,r){var n=this.parseDate(t),a=this.lookup(e,r);if(null==n)return n;var o=n.toString();return o.match(/invalid/i)?o:a?this.strftime(n,a,r):o},t.toPercentage=function(e,t){return t=this.prepareOptions(t,this.lookup("number.percentage.format",t),this.lookup("number.format",t),b),this.toNumber(e,t)},t.toHumanSize=function(e,t){for(var r,n,a,o=1024,i=e,l=0;i>=o&&l<4;)i/=o,l+=1;return 0===l?(a=this.getFullScope("number.human.storage_units.units.byte",t),r=this.t(a,{count:i}),n=0):(a=this.getFullScope("number.human.storage_units.units."+S[l],t),r=this.t(a),n=i-Math.floor(i)==0?0:1),t=this.prepareOptions(t,{unit:r,precision:n,format:"%n%u",delimiter:""}),this.toNumber(i,t)},t.getFullScope=function(e,t){return t=t||{},s(e)&&(e=e.join(t.separator||this.defaultSeparator)),t.scope&&(e=[t.scope,e].join(t.separator||this.defaultSeparator)),e},t.extend=function(e,t){return void 0===e&&void 0===t?{}:g(e,t)},t.t=t.translate.bind(t),t.l=t.localize.bind(t),t.p=t.pluralize.bind(t),t}(a)}.call(t,r,t,e),void 0===n||(e.exports=n)},155:(e,t,r)=>{"use strict";r.d(t,{LogType:()=>n,papyrosLog:()=>i});var n,a=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,a,o=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)i.push(n.value)}catch(e){a={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(a)throw a.error}}return i},o=function(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))};!function(e){e[e.Debug=0]="Debug",e[e.Error=1]="Error",e[e.Important=2]="Important"}(n||(n={}));function i(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var i=e!==n.Debug;i&&(e===n.Error?console.error.apply(console,o([],a(t),!1)):console.log.apply(console,o([],a(t),!1)))}},963:e=>{const t={en:{Papyros:{Papyros:"Papyros",code:"Code",code_placeholder:"Write your %{programmingLanguage} code here and click 'Run' to execute...",input:"Input",input_placeholder:{interactive:"Provide input and press enter to send",batch:"Provide all input required by your code here.\nYou can enter multiple lines by pressing enter."},input_disabled:"You can only provide input when your code requires it in interactive mode",output:"Output",output_placeholder:"The output of your code will appear here",run:"Run",stop:"Stop",finished:"Code executed in %{time} s",states:{running:"Running",stopping:"Stopping",loading:"Loading",awaiting_input:"Awaiting input",ready:" "},programming_language:"Programming language",programming_languages:{Python:"Python",JavaScript:"JavaScript"},locales:{en:"English",nl:"Nederlands"},input_modes:{switch_to_interactive:"Switch to interactive mode",switch_to_batch:"Switch to batch input"},enter:"Enter",examples:"Examples"}},nl:{Papyros:{Papyros:"Papyros",code:"Code",code_placeholder:"Schrijf hier je %{programmingLanguage} code en klik op 'Run' om uit te voeren...",input:"Invoer",input_placeholder:{interactive:"Geef invoer in en druk op enter",batch:"Geef hier alle invoer die je code nodig heeft vooraf in.\nJe kan verschillende lijnen ingeven door op enter te drukken."},input_disabled:"Je kan enkel invoer invullen als je code erom vraagt in interactieve modus",output:"Uitvoer",output_placeholder:"Hier komt de uitvoer van je code",run:"Run",stop:"Stop",states:{running:"Aan het uitvoeren",stopping:"Aan het stoppen",loading:"Aan het laden",awaiting_input:"Aan het wachten op invoer",ready:" "},finished:"Code uitgevoerd in %{time} s",programming_language:"Programmeertaal",programming_languages:{Python:"Python",JavaScript:"JavaScript"},locales:{en:"English",nl:"Nederlands"},input_modes:{switch_to_interactive:"Wissel naar interactieve invoer",switch_to_batch:"Geef invoer vooraf in"},enter:"Enter",examples:"Voorbeelden"}}};e.exports.TRANSLATIONS=t}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.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,{t:()=>u,loadTranslations:()=>c,getLocales:()=>p,getSelectOptions:()=>f,renderSelect:()=>d,renderButton:()=>h,addListener:()=>g,removeSelection:()=>m,getElement:()=>y,renderWithOptions:()=>v,parseEventData:()=>b});var e=r(13),t=r.n(e),a=r(963),o=r(155),i=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},l=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,a,o=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)i.push(n.value)}catch(e){a={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(a)throw a.error}}return i},s=function(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))},u=t().t;function c(){var e,r;try{for(var n=i(Object.entries(a.TRANSLATIONS)),o=n.next();!o.done;o=n.next()){var s=l(o.value,2),u=s[0],c=s[1];t().translations[u]=Object.assign(t().translations[u]||{},c)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(e)throw e.error}}}function p(){return Object.keys(a.TRANSLATIONS)}function f(e,t,r){return e.map((function(e){return"\n <option ".concat(e===r?"selected":"",' value="').concat(e,'">\n ').concat(t(e),"\n </option>\n ")})).join("\n")}function d(e,t,r,n,a){var o=a?'<label for="'.concat(e,'">').concat(a,": </label>\n "):"",i='\n <select id="'.concat(e,'" class="m-2 border-2">\n ').concat(f(t,r,n),"\n </select>");return"\n ".concat(o,"\n ").concat(i,"\n ")}function h(e){return e.extraClasses&&(e.extraClasses=" ".concat(e.extraClasses)),'\n<button id="'.concat(e.id,'" type="button"\n class="border-2 m-1 px-4 inset-y-2 rounded-lg\n disabled:opacity-50 disabled:cursor-wait').concat(e.extraClasses,'">\n ').concat(e.buttonText,"\n</button>")}function g(e,t,r,n){void 0===r&&(r="change"),void 0===n&&(n="value");var a=y(e);a.addEventListener(r,(function(){t(a[n]||a.getAttribute(n))}))}function m(e){y(e).selectedIndex=-1}function y(e){return"string"==typeof e?document.getElementById(e):e}function v(e,t){var r,n,a,o=y(e.parentElementId);if(e.classNames&&(r=o.classList).add.apply(r,s([],l(e.classNames.split(" ")),!1)),e.attributes)try{for(var u=i(e.attributes.entries()),c=u.next();!c.done;c=u.next()){var p=l(c.value,2),f=p[0],d=p[1];o.setAttribute(f,d)}}catch(e){n={error:e}}finally{try{c&&!c.done&&(a=u.return)&&a.call(u)}finally{if(n)throw n.error}}return"string"==typeof t?o.innerHTML=t:o.replaceChildren(t),o}function b(e){var t=e.data,r=l(e.contentType.split("/"),2),n=r[0],a=r[1];switch(n){case"text":switch(a){case"plain":return t;case"json":return JSON.parse(t)}break;case"img":if("png;base64"===a)return t}return(0,o.papyrosLog)(o.LogType.Important,"Unhandled content type: ".concat(e.contentType)),t}})(),n})()}));
@@ -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;
4
- constructor(hostName: string);
9
+ private hostName;
10
+ private syncMessageListener;
11
+ /**
12
+ * Create a worker for a specific domain
13
+ * @param {string} hostName Optional name of the host domain
14
+ */
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
  }
@@ -0,0 +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,(function(){return(()=>{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:()=>d,writeMessage:()=>y,makeChannel:()=>v,makeAtomicsChannel:()=>h,makeServiceWorkerChannel:()=>m,readMessage:()=>w,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 s(e){try{u(n.next(e))}catch(e){i(e)}}function a(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(s,a)}u((n=n.apply(e,t||[])).next())}))},i=function(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)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 s.label++,{value:i[1],done:!1};case 5:s.label++,n=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],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},s="__SyncMessageServiceWorkerInput__",a="__sync-message-v2__";function u(){var e={},t={};return function(r){var n=r.request.url;return!!n.includes(s)&&(r.respondWith(function(){return o(this,void 0,void 0,(function(){function o(e){var t={message:e,version:a};return new Response(JSON.stringify(t),{status:200})}var s,u,c,l,f,p,d,y;return i(this,(function(i){switch(i.label){case 0:return n.endsWith("/read")?[4,r.request.json()]:[3,5];case 1:return s=i.sent(),u=s.messageId,c=s.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,d=f.messageId,(y=t[d])?(y(o(p)),delete t[d]):e[d]=p,[2,o({early:!y})];case 7:if(n.endsWith("/version"))return[2,new Response(a,{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 d(e,t,r){return o(this,void 0,void 0,(function(){var n,o,s,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 s={message:t,messageId:r},[4,fetch(n,{method:"POST",body:JSON.stringify(s)})];case 3:return u=i.sent(),(l=200===u.status)?[4,u.json()]:[3,5];case 4:l=i.sent().version===a,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 y(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,d(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?h(e.atomics):"serviceWorker"in navigator?m(e.serviceWorker):null}function h(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 m(e){return void 0===e&&(e={}),{type:"serviceWorker",baseUrl:(e.scope||"/")+s,timeout:e.timeout||5e3}}function b(e,t){return e>0?+e:t}function w(e,t,r){var n=void 0===r?{}:r,o=n.checkInterrupt,i=n.checkTimeout,s=n.timeout,u=performance.now();i=b(i,o?100:5e3);var c,l=b(s,Number.POSITIVE_INFINITY);if("atomics"===e.type){var p=e.data,d=e.meta;c=function(){if("timed-out"===Atomics.wait(d,1,0,i))return null;var e=Atomics.exchange(d,0,0),t=p.slice(0,e);Atomics.store(d,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 s=r.status;if(408===s)return null;if(200===s){var c=JSON.parse(r.responseText);return c.version!==a?null:c.message}if(performance.now()-u<e.timeout)return null;throw new f(n,s)};for(;;){var y=l-(performance.now()-u);if(y<=0)return null;i=Math.min(i,y);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 w(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}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:()=>i});var e=r(137),t=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{u(n.next(e))}catch(e){i(e)}}function a(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(s,a)}u((n=n.apply(e,t||[])).next())}))},o=function(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)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 s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.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],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},i=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,8 +1,27 @@
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>;
7
26
  }
8
27
  export declare const PYODIDE_INDEX_URL: string;
@@ -0,0 +1 @@
1
+ !function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.Papyros=o():e.Papyros=o()}(self,(function(){return(()=>{"use strict";var e={d:(o,t)=>{for(var r in t)e.o(t,r)&&!e.o(o,r)&&Object.defineProperty(o,r,{enumerable:!0,get:t[r]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{PYODIDE_INDEX_URL:()=>t,PYODIDE_JS_URL:()=>r});var t="https://cdn.jsdelivr.net/pyodide/".concat("v0.19.0","/full/"),r=t+"pyodide.js";return o})()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dodona/papyros",
3
- "version": "0.1.62",
3
+ "version": "0.1.90",
4
4
  "private": false,
5
5
  "homepage": ".",
6
6
  "devDependencies": {
@@ -19,6 +19,7 @@
19
19
  "eslint-plugin-import": "^2.22.1",
20
20
  "eslint-plugin-jest": "^25.2.4",
21
21
  "eslint-webpack-plugin": "^2.5.2",
22
+ "glob": "^7.2.0",
22
23
  "i18n-extract": "^0.6.7",
23
24
  "jest": "^27.3.1",
24
25
  "jest-junit": "^13.0.0",
@@ -28,6 +29,7 @@
28
29
  "raw-loader": "^4.0.2",
29
30
  "style-loader": "^3.3.1",
30
31
  "tailwindcss": "^2.2.19",
32
+ "terser-webpack-plugin": "^5.3.1",
31
33
  "ts-jest": "^27.0.7",
32
34
  "ts-loader": "^9.2.6",
33
35
  "typescript": "^4.1.2",
@@ -57,8 +59,7 @@
57
59
  },
58
60
  "scripts": {
59
61
  "start": "webpack serve --mode development",
60
- "build:package": "webpack build --mode production --env=entry=./src/Library.ts",
61
- "build:app": "webpack build --mode production --env=entry=./src/App.ts",
62
+ "build": "webpack build --mode production",
62
63
  "test": "echo No tests defined yet",
63
64
  "lint": "eslint --ext '.js' --ext '.ts' src",
64
65
  "validate:translations": "node scripts/ValidateTranslations.js"
@@ -82,6 +83,6 @@
82
83
  "bugs": {
83
84
  "url": "https://github.com/dodona-edu/papyros/issues"
84
85
  },
85
- "main": "./dist/index.js",
86
- "types": "./dist/library.d.ts"
86
+ "main": "./dist/Library.js",
87
+ "types": "./dist/Library.d.ts"
87
88
  }
@@ -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
- }