@pyscript/core 0.6.7 → 0.6.9

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 (81) hide show
  1. package/dist/codemirror-1dOfKU91.js +1832 -0
  2. package/dist/{codemirror-BFaBdIfQ.js.map → codemirror-1dOfKU91.js.map} +1 -1
  3. package/dist/codemirror_commands-CKMxnUcp.js +1714 -0
  4. package/dist/codemirror_commands-CKMxnUcp.js.map +1 -0
  5. package/dist/codemirror_lang-python-D9DYtDWr.js +2462 -0
  6. package/dist/{codemirror_lang-python-DvjhpaK2.js.map → codemirror_lang-python-D9DYtDWr.js.map} +1 -1
  7. package/dist/codemirror_language-B5lTPv2c.js +5337 -0
  8. package/dist/{codemirror_language-4kk4Aqm3.js.map → codemirror_language-B5lTPv2c.js.map} +1 -1
  9. package/dist/codemirror_state-n1sFh2hh.js +3930 -0
  10. package/dist/{codemirror_state-1d1uncXx.js.map → codemirror_state-n1sFh2hh.js.map} +1 -1
  11. package/dist/codemirror_view-1a1gCrKZ.js +11428 -0
  12. package/dist/{codemirror_view-aIuSN42d.js.map → codemirror_view-1a1gCrKZ.js.map} +1 -1
  13. package/dist/core-D2ytnMSk.js +4349 -0
  14. package/dist/core-D2ytnMSk.js.map +1 -0
  15. package/dist/core.css +75 -1
  16. package/dist/core.js +1 -1
  17. package/dist/deprecations-manager-Cf_aFUPK.js +29 -0
  18. package/dist/{deprecations-manager-BWDz_-4h.js.map → deprecations-manager-Cf_aFUPK.js.map} +1 -1
  19. package/dist/donkey-Cc8svH2Q.js +170 -0
  20. package/dist/{donkey-DvIAJuTW.js.map → donkey-Cc8svH2Q.js.map} +1 -1
  21. package/dist/error-DWoeKPDI.js +59 -0
  22. package/dist/{error-CVKnHrMr.js.map → error-DWoeKPDI.js.map} +1 -1
  23. package/dist/index-BVFrv_QY.js +1911 -0
  24. package/dist/{index-DqgFLybq.js.map → index-BVFrv_QY.js.map} +1 -1
  25. package/dist/mpy-CQiuZcjW.js +255 -0
  26. package/dist/{mpy-DoOh7bKP.js.map → mpy-CQiuZcjW.js.map} +1 -1
  27. package/dist/py-BgH4mprx.js +182 -0
  28. package/dist/{py-D401PjM8.js.map → py-BgH4mprx.js.map} +1 -1
  29. package/dist/py-editor-Dzsa3rsF.js +433 -0
  30. package/dist/{py-editor-Dxs1clgy.js.map → py-editor-Dzsa3rsF.js.map} +1 -1
  31. package/dist/py-terminal-BX_wPoTi.js +61 -0
  32. package/dist/{py-terminal-eUGMSqwz.js.map → py-terminal-BX_wPoTi.js.map} +1 -1
  33. package/dist/storage.js +421 -1
  34. package/dist/storage.js.map +1 -1
  35. package/dist/toml-CkEFU7ly.js +103 -0
  36. package/dist/{toml-DiUM0_qs.js.map → toml-CkEFU7ly.js.map} +1 -1
  37. package/dist/toml-DTuPg5as.js +5 -0
  38. package/dist/toml-DTuPg5as.js.map +1 -0
  39. package/dist/xterm-eU6F6YKE.js +10 -0
  40. package/dist/xterm-eU6F6YKE.js.map +1 -0
  41. package/dist/xterm-readline-C7HDczqS.js +501 -0
  42. package/dist/xterm-readline-C7HDczqS.js.map +1 -0
  43. package/dist/xterm_addon-fit-Cotzxdkz.js +10 -0
  44. package/dist/xterm_addon-fit-Cotzxdkz.js.map +1 -0
  45. package/dist/xterm_addon-web-links-DoNfCjeX.js +10 -0
  46. package/dist/xterm_addon-web-links-DoNfCjeX.js.map +1 -0
  47. package/dist/zip-Cj6c-tjp.js +13 -0
  48. package/dist/zip-Cj6c-tjp.js.map +1 -0
  49. package/package.json +5 -5
  50. package/src/core.js +2 -2
  51. package/src/stdlib/pyscript.js +13 -13
  52. package/dist/codemirror-BFaBdIfQ.js +0 -2
  53. package/dist/codemirror_commands-CvnouHng.js +0 -2
  54. package/dist/codemirror_commands-CvnouHng.js.map +0 -1
  55. package/dist/codemirror_lang-python-DvjhpaK2.js +0 -2
  56. package/dist/codemirror_language-4kk4Aqm3.js +0 -2
  57. package/dist/codemirror_state-1d1uncXx.js +0 -2
  58. package/dist/codemirror_view-aIuSN42d.js +0 -2
  59. package/dist/core-S0XBQFwV.js +0 -2
  60. package/dist/core-S0XBQFwV.js.map +0 -1
  61. package/dist/deprecations-manager-BWDz_-4h.js +0 -2
  62. package/dist/donkey-DvIAJuTW.js +0 -2
  63. package/dist/error-CVKnHrMr.js +0 -2
  64. package/dist/index-DqgFLybq.js +0 -2
  65. package/dist/mpy-DoOh7bKP.js +0 -2
  66. package/dist/py-D401PjM8.js +0 -2
  67. package/dist/py-editor-Dxs1clgy.js +0 -2
  68. package/dist/py-terminal-eUGMSqwz.js +0 -2
  69. package/dist/toml-CvAfdf9_.js +0 -3
  70. package/dist/toml-CvAfdf9_.js.map +0 -1
  71. package/dist/toml-DiUM0_qs.js +0 -3
  72. package/dist/xterm-BY7uk_OU.js +0 -2
  73. package/dist/xterm-BY7uk_OU.js.map +0 -1
  74. package/dist/xterm-readline-CZfBw7ic.js +0 -2
  75. package/dist/xterm-readline-CZfBw7ic.js.map +0 -1
  76. package/dist/xterm_addon-fit--gyF3PcZ.js +0 -2
  77. package/dist/xterm_addon-fit--gyF3PcZ.js.map +0 -1
  78. package/dist/xterm_addon-web-links-Cnej-nJ6.js +0 -2
  79. package/dist/xterm_addon-web-links-Cnej-nJ6.js.map +0 -1
  80. package/dist/zip-Bf48tRr5.js +0 -2
  81. package/dist/zip-Bf48tRr5.js.map +0 -1
package/dist/core.css CHANGED
@@ -1 +1,75 @@
1
- mpy-config,mpy-script,py-config,py-script{display:none}.mpy-editor-box,.py-editor-box{padding:.5rem}.mpy-editor-input,.py-editor-input{position:relative}.mpy-editor-box:before,.py-editor-box:before{content:attr(data-env);display:block;font-size:x-small;text-align:end}.mpy-editor-output,.py-editor-output{white-space:pre}.mpy-editor-run-button,.py-editor-run-button{bottom:.5rem;opacity:0;position:absolute;right:.5rem;transition:opacity .25s;z-index:1}.mpy-editor-box:hover .mpy-editor-run-button,.mpy-editor-run-button:disabled,.mpy-editor-run-button:focus,.py-editor-box:hover .py-editor-run-button,.py-editor-run-button:disabled,.py-editor-run-button:focus{opacity:1}@keyframes spinner{to{transform:rotate(1turn)}}.mpy-editor-run-button:disabled>*,.py-editor-run-button:disabled>*{display:none}.mpy-editor-run-button:disabled,.py-editor-run-button:disabled{border-width:0}.mpy-editor-run-button:disabled:before,.py-editor-run-button:disabled:before{animation:spinner .6s linear infinite;background-color:#fff;border:2px solid #aaa;border-radius:50%;border-top-color:#000;box-sizing:border-box;content:"";height:20px;left:100%;margin-left:-26px;margin-top:-23px;position:absolute;top:100%;width:20px}
1
+ py-script,
2
+ py-config,
3
+ mpy-script,
4
+ mpy-config {
5
+ display: none;
6
+ }
7
+
8
+ /* PyEditor */
9
+ .py-editor-box,
10
+ .mpy-editor-box {
11
+ padding: 0.5rem;
12
+ }
13
+ .py-editor-input,
14
+ .mpy-editor-input {
15
+ position: relative;
16
+ }
17
+ .py-editor-box::before,
18
+ .mpy-editor-box::before {
19
+ content: attr(data-env);
20
+ display: block;
21
+ font-size: x-small;
22
+ text-align: end;
23
+ }
24
+ .py-editor-output,
25
+ .mpy-editor-output {
26
+ white-space: pre;
27
+ }
28
+ .py-editor-run-button,
29
+ .mpy-editor-run-button {
30
+ position: absolute;
31
+ right: 0.5rem;
32
+ bottom: 0.5rem;
33
+ opacity: 0;
34
+ transition: opacity 0.25s;
35
+ z-index: 1;
36
+ }
37
+ .py-editor-box:hover .py-editor-run-button,
38
+ .mpy-editor-box:hover .mpy-editor-run-button,
39
+ .py-editor-run-button:focus,
40
+ .py-editor-run-button:disabled,
41
+ .mpy-editor-run-button:focus,
42
+ .mpy-editor-run-button:disabled {
43
+ opacity: 1;
44
+ }
45
+
46
+ @keyframes spinner {
47
+ to {
48
+ transform: rotate(360deg);
49
+ }
50
+ }
51
+ .py-editor-run-button:disabled > *,
52
+ .mpy-editor-run-button:disabled > * {
53
+ display: none; /* hide all the child elements of the run button when it is disabled */
54
+ }
55
+ .py-editor-run-button:disabled,
56
+ .mpy-editor-run-button:disabled {
57
+ border-width: 0;
58
+ }
59
+ .py-editor-run-button:disabled::before,
60
+ .mpy-editor-run-button:disabled::before {
61
+ content: "";
62
+ box-sizing: border-box;
63
+ position: absolute;
64
+ top: 100%;
65
+ left: 100%;
66
+ width: 20px;
67
+ height: 20px;
68
+ margin-top: -23px; /* hardcoded value to center the spinner on the run button */
69
+ margin-left: -26px; /* hardcoded value to center the spinner on the run button */
70
+ border-radius: 50%;
71
+ border: 2px solid #aaa;
72
+ border-top-color: #000;
73
+ background-color: #fff;
74
+ animation: spinner 0.6s linear infinite;
75
+ }
package/dist/core.js CHANGED
@@ -1,2 +1,2 @@
1
- export{k as MPWorker,j as PyWorker,T as TYPES,l as config,h as donkey,e as hooks,i as inputFailure,o as offline_interpreter,g as optional,r as relative_url,s as stdlib,m as whenDefined}from"./core-S0XBQFwV.js";
1
+ export { k as MPWorker, j as PyWorker, T as TYPES, l as config, h as donkey, e as hooks, i as inputFailure, o as offline_interpreter, g as optional, r as relative_url, s as stdlib, m as whenDefined } from './core-D2ytnMSk.js';
2
2
  //# sourceMappingURL=core.js.map
@@ -0,0 +1,29 @@
1
+ import { e as exportedHooks } from './core-D2ytnMSk.js';
2
+ import { notify } from './error-DWoeKPDI.js';
3
+
4
+ // PyScript Derepcations Plugin
5
+
6
+ // react lazily on PyScript bootstrap
7
+ exportedHooks.main.onReady.add(checkDeprecations);
8
+ exportedHooks.main.onWorker.add(checkDeprecations);
9
+
10
+ /**
11
+ * Check that there are no scripts loading from pyscript.net/latest
12
+ */
13
+ function checkDeprecations() {
14
+ const scripts = document.querySelectorAll("script");
15
+ for (const script of scripts) checkLoadingScriptsFromLatest(script.src);
16
+ }
17
+
18
+ /**
19
+ * Check if src being loaded from pyscript.net/latest and display a notification if true
20
+ * * @param {string} src
21
+ */
22
+ function checkLoadingScriptsFromLatest(src) {
23
+ if (/\/pyscript\.net\/latest/.test(src)) {
24
+ notify(
25
+ "Loading scripts from latest is deprecated and will be removed soon. Please use a specific version instead.",
26
+ );
27
+ }
28
+ }
29
+ //# sourceMappingURL=deprecations-manager-Cf_aFUPK.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deprecations-manager-BWDz_-4h.js","sources":["../src/plugins/deprecations-manager.js"],"sourcesContent":["// PyScript Derepcations Plugin\nimport { hooks } from \"../core.js\";\nimport { notify } from \"./error.js\";\n\n// react lazily on PyScript bootstrap\nhooks.main.onReady.add(checkDeprecations);\nhooks.main.onWorker.add(checkDeprecations);\n\n/**\n * Check that there are no scripts loading from pyscript.net/latest\n */\nfunction checkDeprecations() {\n const scripts = document.querySelectorAll(\"script\");\n for (const script of scripts) checkLoadingScriptsFromLatest(script.src);\n}\n\n/**\n * Check if src being loaded from pyscript.net/latest and display a notification if true\n * * @param {string} src\n */\nfunction checkLoadingScriptsFromLatest(src) {\n if (/\\/pyscript\\.net\\/latest/.test(src)) {\n notify(\n \"Loading scripts from latest is deprecated and will be removed soon. Please use a specific version instead.\",\n );\n }\n}\n"],"names":["checkDeprecations","scripts","document","querySelectorAll","script","checkLoadingScriptsFromLatest","src","test","notify","hooks","main","onReady","add","onWorker"],"mappings":"+EAWA,SAASA,IACL,MAAMC,EAAUC,SAASC,iBAAiB,UAC1C,IAAK,MAAMC,KAAUH,EAASI,EAA8BD,EAAOE,IACvE,CAMA,SAASD,EAA8BC,GAC/B,0BAA0BC,KAAKD,IAC/BE,EACI,6GAGZ,CArBAC,EAAMC,KAAKC,QAAQC,IAAIZ,GACvBS,EAAMC,KAAKG,SAASD,IAAIZ"}
1
+ {"version":3,"file":"deprecations-manager-Cf_aFUPK.js","sources":["../src/plugins/deprecations-manager.js"],"sourcesContent":["// PyScript Derepcations Plugin\nimport { hooks } from \"../core.js\";\nimport { notify } from \"./error.js\";\n\n// react lazily on PyScript bootstrap\nhooks.main.onReady.add(checkDeprecations);\nhooks.main.onWorker.add(checkDeprecations);\n\n/**\n * Check that there are no scripts loading from pyscript.net/latest\n */\nfunction checkDeprecations() {\n const scripts = document.querySelectorAll(\"script\");\n for (const script of scripts) checkLoadingScriptsFromLatest(script.src);\n}\n\n/**\n * Check if src being loaded from pyscript.net/latest and display a notification if true\n * * @param {string} src\n */\nfunction checkLoadingScriptsFromLatest(src) {\n if (/\\/pyscript\\.net\\/latest/.test(src)) {\n notify(\n \"Loading scripts from latest is deprecated and will be removed soon. Please use a specific version instead.\",\n );\n }\n}\n"],"names":["hooks"],"mappings":";;;AAAA;AAGA;AACA;AACAA,aAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAC1CA,aAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAC3C;AACA;AACA;AACA;AACA,SAAS,iBAAiB,GAAG;AAC7B,IAAI,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AACxD,IAAI,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,6BAA6B,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC5E,CAAC;AACD;AACA;AACA;AACA;AACA;AACA,SAAS,6BAA6B,CAAC,GAAG,EAAE;AAC5C,IAAI,IAAI,yBAAyB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAC7C,QAAQ,MAAM;AACd,YAAY,4GAA4G;AACxH,SAAS,CAAC;AACV,KAAK;AACL"}
@@ -0,0 +1,170 @@
1
+ import { a as dedent, f as assign } from './core-D2ytnMSk.js';
2
+
3
+ const { get } = Reflect;
4
+
5
+ const methods = [
6
+ 'preventDefault',
7
+ 'stopPropagation',
8
+ 'stopImmediatePropagation',
9
+ ];
10
+
11
+ const once = { once: true };
12
+
13
+ // avoid event.preventDefault throwing due illegal Proxy invocation
14
+ const bound = (e, value) => typeof value === 'function' ? value.bind(e) : value;
15
+
16
+ // traps the `event.currentTarget` to be sure it's available later on
17
+ class Handler {
18
+ #currentTarget;
19
+ constructor(currentTarget) {
20
+ this.#currentTarget = currentTarget;
21
+ }
22
+ get(e, name) {
23
+ // Did you know? event.currentTarget disappears from events on
24
+ // next tick, which is why this proxy handler needs to exist.
25
+ return name === 'currentTarget' ? this.#currentTarget : bound(e, get(e, name));
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Add a listener that result as a Promise, fulfilled when the event happens once or rejected if the optional provided signal is aborted.
31
+ * @param {Element} element
32
+ * @param {string} type
33
+ * @param {{ signal?:AbortSignal, capture?:boolean, passive?:boolean, preventDefault?:boolean, stopPropagation?:boolean, stopImmediatePropagation?:boolean }?} options
34
+ * @returns {Promise<Event,Event>}
35
+ */
36
+ var addPromiseListener = (element, type, options = null) => new Promise(
37
+ (resolve, reject) => {
38
+ const handler = new Handler(element);
39
+ if (options.signal) {
40
+ const abort = event => reject(new Proxy(event, handler));
41
+ options.signal.addEventListener('abort', abort, once);
42
+ if (options.signal.aborted)
43
+ return options.signal.dispatchEvent(new Event('abort'));
44
+ }
45
+ element.addEventListener(
46
+ type,
47
+ (event) => {
48
+ for (const method of methods) {
49
+ if (options[method]) event[method]();
50
+ }
51
+ resolve(new Proxy(event, handler));
52
+ },
53
+ { ...options, ...once }
54
+ );
55
+ }
56
+ );
57
+
58
+ const { stringify } = JSON;
59
+
60
+ const invoke = (name, args) => `${name}(code, ${args.join(", ")})`;
61
+
62
+ const donkey = ({ type = "py", persistent, terminal, config }) => {
63
+ const args = persistent ? ["globals()", "__locals__"] : ["{}", "{}"];
64
+
65
+ const src = URL.createObjectURL(
66
+ new Blob([
67
+ [
68
+ // this array is to better minify this code once in production
69
+ "from pyscript import sync, config",
70
+ '__message__ = lambda e,v: f"\x1b[31m\x1b[1m{e.__name__}\x1b[0m: {v}"',
71
+ "__locals__ = {}",
72
+ 'if config["type"] == "py":',
73
+ " import sys",
74
+ " def __error__(_):",
75
+ " info = sys.exc_info()",
76
+ " return __message__(info[0], info[1])",
77
+ "else:",
78
+ " __error__ = lambda e: __message__(e.__class__, e.value)",
79
+ "def execute(code):",
80
+ ` try: return ${invoke("exec", args)};`,
81
+ " except Exception as e: print(__error__(e));",
82
+ "def evaluate(code):",
83
+ ` try: return ${invoke("eval", args)};`,
84
+ " except Exception as e: print(__error__(e));",
85
+ "sync.execute = execute",
86
+ "sync.evaluate = evaluate",
87
+ ].join("\n"),
88
+ ]),
89
+ );
90
+
91
+ // create the script that exposes the code to execute or evaluate
92
+ const script = assign(document.createElement("script"), { type, src });
93
+ script.toggleAttribute("worker", true);
94
+ script.toggleAttribute("terminal", true);
95
+ if (terminal) script.setAttribute("target", terminal);
96
+ if (config) {
97
+ script.setAttribute(
98
+ "config",
99
+ typeof config === "string" ? config : stringify(config),
100
+ );
101
+ }
102
+
103
+ return addPromiseListener(
104
+ document.body.appendChild(script),
105
+ `${type}:done`,
106
+ { stopPropagation: true },
107
+ ).then(() => {
108
+ URL.revokeObjectURL(src);
109
+ return script;
110
+ });
111
+ };
112
+
113
+ const utils = async (options) => {
114
+ const script = await donkey(options);
115
+ const { xworker, process, terminal } = script;
116
+ const { execute, evaluate } = xworker.sync;
117
+ script.remove();
118
+ return {
119
+ xworker,
120
+ process,
121
+ terminal,
122
+ execute,
123
+ evaluate,
124
+ };
125
+ };
126
+
127
+ var donkey$1 = async (options = {}) => {
128
+ let farmer = await utils(options);
129
+ let working = false;
130
+ const kill = () => {
131
+ if (farmer) {
132
+ farmer.xworker.terminate();
133
+ farmer.terminal.dispose();
134
+ farmer = null;
135
+ }
136
+ working = false;
137
+ };
138
+ const reload = async () => {
139
+ kill();
140
+ farmer = await utils(options);
141
+ };
142
+ const asyncTask = (method) => async (code) => {
143
+ // race condition ... a new task has been
144
+ // assigned while the previous one didn't finish
145
+ if (working) await reload();
146
+ working = true;
147
+ try {
148
+ return await farmer[method](dedent(code));
149
+ } catch (e) {
150
+ console.error(e);
151
+ } finally {
152
+ working = false;
153
+ }
154
+ };
155
+ const asyncMethod = (method) => async () => {
156
+ if (working) await reload();
157
+ else farmer?.terminal[method]();
158
+ };
159
+ return {
160
+ process: asyncTask("process"),
161
+ execute: asyncTask("execute"),
162
+ evaluate: asyncTask("evaluate"),
163
+ clear: asyncMethod("clear"),
164
+ reset: asyncMethod("reset"),
165
+ kill,
166
+ };
167
+ };
168
+
169
+ export { donkey$1 as default };
170
+ //# sourceMappingURL=donkey-Cc8svH2Q.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"donkey-DvIAJuTW.js","sources":["../node_modules/add-promise-listener/index.js","../src/plugins/donkey.js"],"sourcesContent":["const { defineProperty } = Object;\nconst { get } = Reflect;\n\nconst methods = [\n 'preventDefault',\n 'stopPropagation',\n 'stopImmediatePropagation',\n];\n\nconst once = { once: true };\n\n// avoid event.preventDefault throwing due illegal Proxy invocation\nconst bound = (e, value) => typeof value === 'function' ? value.bind(e) : value;\n\n// traps the `event.currentTarget` to be sure it's available later on\nclass Handler {\n #currentTarget;\n constructor(currentTarget) {\n this.#currentTarget = currentTarget;\n }\n get(e, name) {\n // Did you know? event.currentTarget disappears from events on\n // next tick, which is why this proxy handler needs to exist.\n return name === 'currentTarget' ? this.#currentTarget : bound(e, get(e, name));\n }\n}\n\n/**\n * Add a listener that result as a Promise, fulfilled when the event happens once or rejected if the optional provided signal is aborted.\n * @param {Element} element\n * @param {string} type\n * @param {{ signal?:AbortSignal, capture?:boolean, passive?:boolean, preventDefault?:boolean, stopPropagation?:boolean, stopImmediatePropagation?:boolean }?} options\n * @returns {Promise<Event,Event>}\n */\nexport default (element, type, options = null) => new Promise(\n (resolve, reject) => {\n const handler = new Handler(element);\n if (options.signal) {\n const abort = event => reject(new Proxy(event, handler));\n options.signal.addEventListener('abort', abort, once);\n if (options.signal.aborted)\n return options.signal.dispatchEvent(new Event('abort'));\n }\n element.addEventListener(\n type,\n (event) => {\n for (const method of methods) {\n if (options[method]) event[method]();\n }\n resolve(new Proxy(event, handler));\n },\n { ...options, ...once }\n );\n }\n);\n","import addPromiseListener from \"add-promise-listener\";\nimport { assign, dedent } from \"polyscript/exports\";\n\nconst { stringify } = JSON;\n\nconst invoke = (name, args) => `${name}(code, ${args.join(\", \")})`;\n\nconst donkey = ({ type = \"py\", persistent, terminal, config }) => {\n const args = persistent ? [\"globals()\", \"__locals__\"] : [\"{}\", \"{}\"];\n\n const src = URL.createObjectURL(\n new Blob([\n [\n // this array is to better minify this code once in production\n \"from pyscript import sync, config\",\n '__message__ = lambda e,v: f\"\\x1b[31m\\x1b[1m{e.__name__}\\x1b[0m: {v}\"',\n \"__locals__ = {}\",\n 'if config[\"type\"] == \"py\":',\n \"\timport sys\",\n \"\tdef __error__(_):\",\n \"\t\tinfo = sys.exc_info()\",\n \"\t\treturn __message__(info[0], info[1])\",\n \"else:\",\n \"\t__error__ = lambda e: __message__(e.__class__, e.value)\",\n \"def execute(code):\",\n `\ttry: return ${invoke(\"exec\", args)};`,\n \"\texcept Exception as e: print(__error__(e));\",\n \"def evaluate(code):\",\n `\ttry: return ${invoke(\"eval\", args)};`,\n \"\texcept Exception as e: print(__error__(e));\",\n \"sync.execute = execute\",\n \"sync.evaluate = evaluate\",\n ].join(\"\\n\"),\n ]),\n );\n\n // create the script that exposes the code to execute or evaluate\n const script = assign(document.createElement(\"script\"), { type, src });\n script.toggleAttribute(\"worker\", true);\n script.toggleAttribute(\"terminal\", true);\n if (terminal) script.setAttribute(\"target\", terminal);\n if (config) {\n script.setAttribute(\n \"config\",\n typeof config === \"string\" ? config : stringify(config),\n );\n }\n\n return addPromiseListener(\n document.body.appendChild(script),\n `${type}:done`,\n { stopPropagation: true },\n ).then(() => {\n URL.revokeObjectURL(src);\n return script;\n });\n};\n\nconst utils = async (options) => {\n const script = await donkey(options);\n const { xworker, process, terminal } = script;\n const { execute, evaluate } = xworker.sync;\n script.remove();\n return {\n xworker,\n process,\n terminal,\n execute,\n evaluate,\n };\n};\n\nexport default async (options = {}) => {\n let farmer = await utils(options);\n let working = false;\n const kill = () => {\n if (farmer) {\n farmer.xworker.terminate();\n farmer.terminal.dispose();\n farmer = null;\n }\n working = false;\n };\n const reload = async () => {\n kill();\n farmer = await utils(options);\n };\n const asyncTask = (method) => async (code) => {\n // race condition ... a new task has been\n // assigned while the previous one didn't finish\n if (working) await reload();\n working = true;\n try {\n return await farmer[method](dedent(code));\n } catch (e) {\n console.error(e);\n } finally {\n working = false;\n }\n };\n const asyncMethod = (method) => async () => {\n if (working) await reload();\n else farmer?.terminal[method]();\n };\n return {\n process: asyncTask(\"process\"),\n execute: asyncTask(\"execute\"),\n evaluate: asyncTask(\"evaluate\"),\n clear: asyncMethod(\"clear\"),\n reset: asyncMethod(\"reset\"),\n kill,\n };\n};\n"],"names":["get","Reflect","methods","once","Handler","currentTarget","constructor","this","e","name","value","bind","bound","stringify","JSON","invoke","args","join","donkey","type","persistent","terminal","config","src","URL","createObjectURL","Blob","script","assign","document","createElement","toggleAttribute","setAttribute","element","options","Promise","resolve","reject","handler","signal","abort","event","Proxy","addEventListener","aborted","dispatchEvent","Event","method","addPromiseListener","body","appendChild","stopPropagation","then","revokeObjectURL","utils","async","xworker","process","execute","evaluate","sync","remove","donkey$1","farmer","working","kill","terminate","dispose","reload","asyncTask","code","dedent","console","error","asyncMethod","clear","reset"],"mappings":"8CACA,MAAMA,IAAEA,GAAQC,QAEVC,EAAU,CACd,iBACA,kBACA,4BAGIC,EAAO,CAAEA,MAAM,GAMrB,MAAMC,EACJC,GACA,WAAAC,CAAYD,GACVE,MAAKF,EAAiBA,CACvB,CACD,GAAAL,CAAIQ,EAAGC,GAGL,MAAgB,kBAATA,EAA2BF,MAAKF,EAX7B,EAACG,EAAGE,IAA2B,mBAAVA,EAAuBA,EAAMC,KAAKH,GAAKE,EAWdE,CAAMJ,EAAGR,EAAIQ,EAAGC,GACzE,ECrBH,MAAMI,UAAEA,GAAcC,KAEhBC,EAAS,CAACN,EAAMO,IAAS,GAAGP,WAAcO,EAAKC,KAAK,SAEpDC,EAAS,EAAGC,OAAO,KAAMC,aAAYC,WAAUC,aACjD,MAAMN,EAAOI,EAAa,CAAC,YAAa,cAAgB,CAAC,KAAM,MAEzDG,EAAMC,IAAIC,gBACZ,IAAIC,KAAK,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CAAA,KAC5B,IAAI6B,QAAeT,EAAMpB,GACrB8B,GAAU,EACd,MAAMC,EAAO,KACLF,IACAA,EAAOP,QAAQU,YACfH,EAAO1C,SAAS8C,UAChBJ,EAAS,MAEbC,GAAU,CAAK,EAEbI,EAASb,UACXU,IACAF,QAAeT,EAAMpB,EAAQ,EAE3BmC,EAAatB,GAAWQ,MAAOe,IAG7BN,SAAeI,IACnBJ,GAAU,EACV,IACI,aAAaD,EAAOhB,GAAQwB,EAAOD,GACtC,CAAC,MAAO9D,GACLgE,QAAQC,MAAMjE,EAC1B,CAAkB,QACNwD,GAAU,CACb,GAECU,EAAe3B,GAAWQ,UACxBS,QAAeI,IACdL,GAAQ1C,SAAS0B,IAAS,EAEnC,MAAO,CACHU,QAASY,EAAU,WACnBX,QAASW,EAAU,WACnBV,SAAUU,EAAU,YACpBM,MAAOD,EAAY,SACnBE,MAAOF,EAAY,SACnBT,OACH","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"donkey-Cc8svH2Q.js","sources":["../node_modules/add-promise-listener/index.js","../src/plugins/donkey.js"],"sourcesContent":["const { defineProperty } = Object;\nconst { get } = Reflect;\n\nconst methods = [\n 'preventDefault',\n 'stopPropagation',\n 'stopImmediatePropagation',\n];\n\nconst once = { once: true };\n\n// avoid event.preventDefault throwing due illegal Proxy invocation\nconst bound = (e, value) => typeof value === 'function' ? value.bind(e) : value;\n\n// traps the `event.currentTarget` to be sure it's available later on\nclass Handler {\n #currentTarget;\n constructor(currentTarget) {\n this.#currentTarget = currentTarget;\n }\n get(e, name) {\n // Did you know? event.currentTarget disappears from events on\n // next tick, which is why this proxy handler needs to exist.\n return name === 'currentTarget' ? this.#currentTarget : bound(e, get(e, name));\n }\n}\n\n/**\n * Add a listener that result as a Promise, fulfilled when the event happens once or rejected if the optional provided signal is aborted.\n * @param {Element} element\n * @param {string} type\n * @param {{ signal?:AbortSignal, capture?:boolean, passive?:boolean, preventDefault?:boolean, stopPropagation?:boolean, stopImmediatePropagation?:boolean }?} options\n * @returns {Promise<Event,Event>}\n */\nexport default (element, type, options = null) => new Promise(\n (resolve, reject) => {\n const handler = new Handler(element);\n if (options.signal) {\n const abort = event => reject(new Proxy(event, handler));\n options.signal.addEventListener('abort', abort, once);\n if (options.signal.aborted)\n return options.signal.dispatchEvent(new Event('abort'));\n }\n element.addEventListener(\n type,\n (event) => {\n for (const method of methods) {\n if (options[method]) event[method]();\n }\n resolve(new Proxy(event, handler));\n },\n { ...options, ...once }\n );\n }\n);\n","import addPromiseListener from \"add-promise-listener\";\nimport { assign, dedent } from \"polyscript/exports\";\n\nconst { stringify } = JSON;\n\nconst invoke = (name, args) => `${name}(code, ${args.join(\", \")})`;\n\nconst donkey = ({ type = \"py\", persistent, terminal, config }) => {\n const args = persistent ? [\"globals()\", \"__locals__\"] : [\"{}\", \"{}\"];\n\n const src = URL.createObjectURL(\n new Blob([\n [\n // this array is to better minify this code once in production\n \"from pyscript import sync, config\",\n '__message__ = lambda e,v: f\"\\x1b[31m\\x1b[1m{e.__name__}\\x1b[0m: {v}\"',\n \"__locals__ = {}\",\n 'if config[\"type\"] == \"py\":',\n \"\timport sys\",\n \"\tdef __error__(_):\",\n \"\t\tinfo = sys.exc_info()\",\n \"\t\treturn __message__(info[0], info[1])\",\n \"else:\",\n \"\t__error__ = lambda e: __message__(e.__class__, e.value)\",\n \"def execute(code):\",\n `\ttry: return ${invoke(\"exec\", args)};`,\n \"\texcept Exception as e: print(__error__(e));\",\n \"def evaluate(code):\",\n `\ttry: return ${invoke(\"eval\", args)};`,\n \"\texcept Exception as e: print(__error__(e));\",\n \"sync.execute = execute\",\n \"sync.evaluate = evaluate\",\n ].join(\"\\n\"),\n ]),\n );\n\n // create the script that exposes the code to execute or evaluate\n const script = assign(document.createElement(\"script\"), { type, src });\n script.toggleAttribute(\"worker\", true);\n script.toggleAttribute(\"terminal\", true);\n if (terminal) script.setAttribute(\"target\", terminal);\n if (config) {\n script.setAttribute(\n \"config\",\n typeof config === \"string\" ? config : stringify(config),\n );\n }\n\n return addPromiseListener(\n document.body.appendChild(script),\n `${type}:done`,\n { stopPropagation: true },\n ).then(() => {\n URL.revokeObjectURL(src);\n return script;\n });\n};\n\nconst utils = async (options) => {\n const script = await donkey(options);\n const { xworker, process, terminal } = script;\n const { execute, evaluate } = xworker.sync;\n script.remove();\n return {\n xworker,\n process,\n terminal,\n execute,\n evaluate,\n };\n};\n\nexport default async (options = {}) => {\n let farmer = await utils(options);\n let working = false;\n const kill = () => {\n if (farmer) {\n farmer.xworker.terminate();\n farmer.terminal.dispose();\n farmer = null;\n }\n working = false;\n };\n const reload = async () => {\n kill();\n farmer = await utils(options);\n };\n const asyncTask = (method) => async (code) => {\n // race condition ... a new task has been\n // assigned while the previous one didn't finish\n if (working) await reload();\n working = true;\n try {\n return await farmer[method](dedent(code));\n } catch (e) {\n console.error(e);\n } finally {\n working = false;\n }\n };\n const asyncMethod = (method) => async () => {\n if (working) await reload();\n else farmer?.terminal[method]();\n };\n return {\n process: asyncTask(\"process\"),\n execute: asyncTask(\"execute\"),\n evaluate: asyncTask(\"evaluate\"),\n clear: asyncMethod(\"clear\"),\n reset: asyncMethod(\"reset\"),\n kill,\n };\n};\n"],"names":[],"mappings":";;AACA,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;AACxB;AACA,MAAM,OAAO,GAAG;AAChB,EAAE,gBAAgB;AAClB,EAAE,iBAAiB;AACnB,EAAE,0BAA0B;AAC5B,CAAC,CAAC;AACF;AACA,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC5B;AACA;AACA,MAAM,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,OAAO,KAAK,KAAK,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AAChF;AACA;AACA,MAAM,OAAO,CAAC;AACd,EAAE,cAAc,CAAC;AACjB,EAAE,WAAW,CAAC,aAAa,EAAE;AAC7B,IAAI,IAAI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E,MAAM,MAAM,EAAE,CAAC;AACpC,aAAa,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;AACxC,KAAK,CAAC;AACN,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC;AACrC,QAAQ,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC;AACrC,QAAQ,QAAQ,EAAE,SAAS,CAAC,UAAU,CAAC;AACvC,QAAQ,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC;AACnC,QAAQ,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC;AACnC,QAAQ,IAAI;AACZ,KAAK,CAAC;AACN,CAAC;;;;","x_google_ignoreList":[0]}
@@ -0,0 +1,59 @@
1
+ import { e as exportedHooks, b as buffered } from './core-D2ytnMSk.js';
2
+
3
+ // PyScript Error Plugin
4
+
5
+ let dontBotherDOM = false;
6
+ function notOnDOM() {
7
+ dontBotherDOM = true;
8
+ }
9
+
10
+ exportedHooks.main.onReady.add(function override(pyScript) {
11
+ // be sure this override happens only once
12
+ exportedHooks.main.onReady.delete(override);
13
+
14
+ // trap generic `stderr` to propagate to it regardless
15
+ const { stderr } = pyScript.io;
16
+
17
+ const cb = (error, ...rest) => {
18
+ notify(error.message || error);
19
+ // let other plugins or stderr hook, if any, do the rest
20
+ return stderr(error, ...rest);
21
+ };
22
+
23
+ // override it with our own logic
24
+ pyScript.io.stderr = pyScript.type === "py" ? cb : buffered(cb);
25
+
26
+ // be sure uncaught Python errors are also visible
27
+ addEventListener("error", ({ message }) => {
28
+ if (message.startsWith("Uncaught PythonError")) notify(message);
29
+ });
30
+ });
31
+
32
+ // Error hook utilities
33
+
34
+ // Custom function to show notifications
35
+
36
+ /**
37
+ * Add a banner to the top of the page, notifying the user of an error
38
+ * @param {string} message
39
+ */
40
+ function notify(message) {
41
+ if (dontBotherDOM) return;
42
+ const div = document.createElement("div");
43
+ div.className = "py-error";
44
+ div.textContent = message;
45
+ div.style.cssText = `
46
+ border: 1px solid red;
47
+ background: #ffdddd;
48
+ color: black;
49
+ font-family: courier, monospace;
50
+ white-space: pre;
51
+ overflow-x: auto;
52
+ padding: 8px;
53
+ margin-top: 8px;
54
+ `;
55
+ document.body.append(div);
56
+ }
57
+
58
+ export { notOnDOM, notify };
59
+ //# sourceMappingURL=error-DWoeKPDI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-CVKnHrMr.js","sources":["../src/plugins/error.js"],"sourcesContent":["// PyScript Error Plugin\nimport { buffered } from \"polyscript/exports\";\nimport { hooks } from \"../core.js\";\n\nlet dontBotherDOM = false;\nexport function notOnDOM() {\n dontBotherDOM = true;\n}\n\nhooks.main.onReady.add(function override(pyScript) {\n // be sure this override happens only once\n hooks.main.onReady.delete(override);\n\n // trap generic `stderr` to propagate to it regardless\n const { stderr } = pyScript.io;\n\n const cb = (error, ...rest) => {\n notify(error.message || error);\n // let other plugins or stderr hook, if any, do the rest\n return stderr(error, ...rest);\n };\n\n // override it with our own logic\n pyScript.io.stderr = pyScript.type === \"py\" ? cb : buffered(cb);\n\n // be sure uncaught Python errors are also visible\n addEventListener(\"error\", ({ message }) => {\n if (message.startsWith(\"Uncaught PythonError\")) notify(message);\n });\n});\n\n// Error hook utilities\n\n// Custom function to show notifications\n\n/**\n * Add a banner to the top of the page, notifying the user of an error\n * @param {string} message\n */\nexport function notify(message) {\n if (dontBotherDOM) return;\n const div = document.createElement(\"div\");\n div.className = \"py-error\";\n div.textContent = message;\n div.style.cssText = `\n border: 1px solid red;\n background: #ffdddd;\n color: black;\n font-family: courier, monospace;\n white-space: pre;\n overflow-x: auto;\n padding: 8px;\n margin-top: 8px;\n `;\n document.body.append(div);\n}\n"],"names":["dontBotherDOM","notOnDOM","notify","message","div","document","createElement","className","textContent","style","cssText","body","append","hooks","main","onReady","add","override","pyScript","delete","stderr","io","cb","error","rest","type","buffered","addEventListener","startsWith"],"mappings":"yCAIA,IAAIA,GAAgB,EACb,SAASC,IACZD,GAAgB,CACpB,CAgCO,SAASE,EAAOC,GACnB,GAAIH,EAAe,OACnB,MAAMI,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAY,WAChBH,EAAII,YAAcL,EAClBC,EAAIK,MAAMC,QAAU,6MAUpBL,SAASM,KAAKC,OAAOR,EACzB,CA9CAS,EAAMC,KAAKC,QAAQC,KAAI,SAASC,EAASC,GAErCL,EAAMC,KAAKC,QAAQI,OAAOF,GAG1B,MAAMG,OAAEA,GAAWF,EAASG,GAEtBC,EAAK,CAACC,KAAUC,KAClBtB,EAAOqB,EAAMpB,SAAWoB,GAEjBH,EAAOG,KAAUC,IAI5BN,EAASG,GAAGD,OAA2B,OAAlBF,EAASO,KAAgBH,EAAKI,EAASJ,GAG5DK,iBAAiB,SAAS,EAAGxB,cACrBA,EAAQyB,WAAW,yBAAyB1B,EAAOC,EAAQ,GAEvE"}
1
+ {"version":3,"file":"error-DWoeKPDI.js","sources":["../src/plugins/error.js"],"sourcesContent":["// PyScript Error Plugin\nimport { buffered } from \"polyscript/exports\";\nimport { hooks } from \"../core.js\";\n\nlet dontBotherDOM = false;\nexport function notOnDOM() {\n dontBotherDOM = true;\n}\n\nhooks.main.onReady.add(function override(pyScript) {\n // be sure this override happens only once\n hooks.main.onReady.delete(override);\n\n // trap generic `stderr` to propagate to it regardless\n const { stderr } = pyScript.io;\n\n const cb = (error, ...rest) => {\n notify(error.message || error);\n // let other plugins or stderr hook, if any, do the rest\n return stderr(error, ...rest);\n };\n\n // override it with our own logic\n pyScript.io.stderr = pyScript.type === \"py\" ? cb : buffered(cb);\n\n // be sure uncaught Python errors are also visible\n addEventListener(\"error\", ({ message }) => {\n if (message.startsWith(\"Uncaught PythonError\")) notify(message);\n });\n});\n\n// Error hook utilities\n\n// Custom function to show notifications\n\n/**\n * Add a banner to the top of the page, notifying the user of an error\n * @param {string} message\n */\nexport function notify(message) {\n if (dontBotherDOM) return;\n const div = document.createElement(\"div\");\n div.className = \"py-error\";\n div.textContent = message;\n div.style.cssText = `\n border: 1px solid red;\n background: #ffdddd;\n color: black;\n font-family: courier, monospace;\n white-space: pre;\n overflow-x: auto;\n padding: 8px;\n margin-top: 8px;\n `;\n document.body.append(div);\n}\n"],"names":["hooks"],"mappings":";;AAAA;AAGA;AACA,IAAI,aAAa,GAAG,KAAK,CAAC;AACnB,SAAS,QAAQ,GAAG;AAC3B,IAAI,aAAa,GAAG,IAAI,CAAC;AACzB,CAAC;AACD;AACAA,aAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,QAAQ,CAAC,QAAQ,EAAE;AACnD;AACA,IAAIA,aAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACxC;AACA;AACA,IAAI,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC;AACnC;AACA,IAAI,MAAM,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,IAAI,KAAK;AACnC,QAAQ,MAAM,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;AACvC;AACA,QAAQ,OAAO,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;AACtC,KAAK,CAAC;AACN;AACA;AACA,IAAI,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,KAAK,IAAI,GAAG,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;AACpE;AACA;AACA,IAAI,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK;AAC/C,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;AACxE,KAAK,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,MAAM,CAAC,OAAO,EAAE;AAChC,IAAI,IAAI,aAAa,EAAE,OAAO;AAC9B,IAAI,MAAM,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