@@ -29,7 +29,7 @@ limitations under the License.
2929/******************************************************************************
3030Base classes and constants.
3131******************************************************************************/
32- class Plugin {
32+ class PyScriptPlugin {
3333 /*
3434 Defines a "plugin" in PyScript.
3535 */
@@ -91,7 +91,7 @@ class Runtime {
9191 Dispatch the py-runtime-ready event (for when the runtime has
9292 eventually started and is ready to evaluate code).
9393 */
94- const pyRuntimeReady = new CustomEvent ( "py-runtime-ready" ) ;
94+ const pyRuntimeReady = new CustomEvent ( "py-runtime-ready" , this ) ;
9595 document . dispatchEvent ( pyRuntimeReady ) ;
9696 }
9797
@@ -124,14 +124,15 @@ class Runtime {
124124
125125
126126// The innerHTML of the default splash screen to show while PyScript is
127- // starting up. Currently a simple SVG animation above the word "PyScript".
127+ // starting up. Currently the page is greyed out and the words
128+ // "Loading PyScript...".
128129const defaultSplash = '<div style="position:fixed;width:100%;height:100%;top:0;left:0;right:0;bottom:0;background-color:rgba(0,0,0,0.5);z-index:99999;"><div style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);color:white;font-family:monospace;font-size:10px;">Loading PyScript...</div></div>' ;
129130
130131
131132/******************************************************************************
132133Built-in plugins and runtimes.
133134******************************************************************************/
134- class PyScriptTag extends Plugin {
135+ class PyScriptTag extends PyScriptPlugin {
135136 start ( config ) {
136137 // Define the PyScript element.
137138 class PyScript extends HTMLElement {
@@ -268,13 +269,11 @@ class PyodideRuntime extends Runtime {
268269The core PyScript app definition.
269270******************************************************************************/
270271const main = function ( ) {
271- // Used to measure start-up times.
272- const start = new Date ( ) ;
273272 // Really simple logging. Emoji 🐍 highlights PyScript app logs. ;-)
274273 const logger = function ( ) {
275274 return Function . prototype . bind . call ( console . log , console , "🐍 " , ...arguments ) ;
276275 } ( ) ;
277- logger ( "Starting PyScript. 👋" , start ) ;
276+ logger ( "Starting PyScript. 👋" ) ;
278277
279278 // Default configuration settings for PyScript. These may be overridden by
280279 // the app.loadConfig function.
@@ -301,8 +300,6 @@ const main = function() {
301300 "cpython" : CPythonRuntime ,
302301 "pyodide" : PyodideRuntime
303302 }
304- // Default to smallest/fastest runtime.
305- runtimes [ "default" ] = runtimes [ "micropython" ]
306303
307304 // Eventually references an instance of the Runtime class, representing the
308305 // started runtime.
@@ -377,28 +374,25 @@ const main = function() {
377374
378375 TL;DR - a new script tag with the correct src is added to the head.
379376 */
380- const runtimeName = config . runtime ? config . runtime : "default" ;
381- if ( ! runtimes . hasOwnProperty ( runtimeName ) ) {
382- throw `💥 Unknown runtime: "${ runtimeName } " (known runtimes: ${ Object . keys ( runtimes ) } )` ;
377+ if ( ! runtimes . hasOwnProperty ( config . runtime ) ) {
378+ throw `💥 Unknown runtime: "${ config . runtime } " (known runtimes: ${ Object . keys ( runtimes ) } )` ;
383379 }
384380 const runtimeElement = document . createElement ( "script" ) ;
385- runtimeElement . src = runtimes [ runtimeName . toLowerCase ( ) ] . url ;
381+ runtimeElement . src = runtimes [ config . runtime . toLowerCase ( ) ] . url ;
386382 runtimeElement . onload = function ( e ) {
387- let duration = new Date ( ) - start ;
388- logger ( `Runtime "${ runtimeName } " loaded (${ duration } ms). 👍` ) ;
389- const pyRuntimeLoaded = new CustomEvent ( "py-runtime-loaded" , { detail : runtimeName } ) ;
383+ logger ( `Runtime "${ config . runtime } " loaded. 👍` ) ;
384+ const pyRuntimeLoaded = new CustomEvent ( "py-runtime-loaded" , { detail : config . runtime } ) ;
390385 document . dispatchEvent ( pyRuntimeLoaded ) ;
391386 } ;
392387 var head = document . getElementsByTagName ( 'head' ) [ 0 ] ;
393- logger ( `Loading runtime "${ runtimeName } ". 🚀` )
388+ logger ( `Loading runtime "${ config . runtime } ". 🚀` )
394389 head . appendChild ( runtimeElement ) ;
395390 } ,
396391 startRuntime : function ( ) {
397392 /*
398393 Congigure and start the Python runtime.
399394 */
400- const runtimeName = config . runtime ? config . runtime : "default" ;
401- runtime = new runtimes [ runtimeName . toLowerCase ( ) ] ( ) ;
395+ runtime = new runtimes [ config . runtime . toLowerCase ( ) ] ( ) ;
402396 runtime . start ( config ) ;
403397 } ,
404398 runtimeStarted : function ( ) {
@@ -407,8 +401,7 @@ const main = function() {
407401 through each registered plugin's onRuntimeReady method, and begin
408402 evaluating any code in the pendingScripts queue.
409403 */
410- let duration = new Date ( ) - start ;
411- logger ( `Runtime started (${ duration } ms). 🎬` ) ;
404+ logger ( `Runtime started. 🎬` ) ;
412405 runtimeReady = true ;
413406 plugins . forEach ( function ( plugin ) {
414407 plugin . onRuntimeReady ( config , runtime ) ;
0 commit comments