{"version":3,"names":["resolveLoaded","whenLoaded","Promise","resolve","mybase","window","location","host","pathname","replace","externalSite","lively4url","match","document","search","protocol","hostname","navigator","lively4chrome","console","log","root","serviceworkerReady","onReady","serviceWorkerMessageHandlers","serviceWorker","onmessage","event","key","message","data","type","messageColors","lively","notify","command","addEventListener","controller","postMessage","warn","register","URL","then","registration","lively4swxregistration","scope","catch","err","ready","Notification","permission","requestPermission"],"sources":["load-swx.js"],"sourcesContent":["/* Load Lively */\n\nvar resolveLoaded \nexport var whenLoaded = new Promise(resolve => {\n  resolveLoaded = resolve\n})\n\nvar mybase = window.location.host + window.location.pathname.replace(/\\/[^/]+$/, \"\");\nvar externalSite = !lively4url.match(mybase); // I am not somewhere below lively4url\n\nif (document.location.search.match(\"noserviceworker\")) {\n  externalSite = true\n}\n\n// service worker, only works on localhost or HTTPS\nif (window.location.protocol == \"http:\" && window.location.hostname != \"localhost\") {\n  externalSite = true\n}\n\nif ('serviceWorker' in navigator || window.lively4chrome || externalSite) {\n  console.log(\"LOAD Lively4: boot lively4 service worker\");\n  var root = \"\" + lively4url + \"/\";\n  var serviceworkerReady = false;\n\n  var onReady = function() {\n    serviceworkerReady = true;\n    // Lively has all the dependencies\n\n\n    // Workaround because only one function can listen to serviceworker messages\n    window.serviceWorkerMessageHandlers = {};\n\n    if (window.navigator.serviceWorker) {\n      window.navigator.serviceWorker.onmessage = function(event) {\n        for (let key in window.serviceWorkerMessageHandlers) {\n          window.serviceWorkerMessageHandlers[key](event);\n        }\n      }\n\n      // Add listener for serviceWorker messages\n      window.serviceWorkerMessageHandlers['networkNotifications'] = (event) => {\n        const message = event.data;\n\n        // Only handle notifications here\n        if (message.type != 'notification') return;\n\n        let messageColors = {\n          'info': '',\n          'warning': 'yellow',\n          'error': 'red'\n        };\n\n        if ('lively' in window) {\n          lively.notify('ServiceWorker', message.data, 5, null, messageColors[message.command]);\n        }\n      }\n\n      // Add listener for offline/online events\n      // This is currently only used in the ServiceWorker, but the ServiceWorker does not get these events\n      // So we register here and forward the events\n      window.addEventListener('online', () => {\n        navigator.serviceWorker.controller.postMessage({\n          type: 'network',\n          command: 'online'\n        });\n      });\n\n      window.addEventListener('offline', () => {\n        navigator.serviceWorker.controller.postMessage({\n          type: 'network',\n          command: 'offline'\n        });\n      });\n    }\n\n    resolveLoaded()\n\n  };\n\n  if (('serviceWorker' in navigator && navigator.serviceWorker.controller) || window.lively4chrome || externalSite) {\n\n    console.warn(\"NO Service worker during migration!!!\")\n    if (window.lively4chrome) {\n      console.log(\"[Livley4] running without service worker\");\n    } else if (externalSite) {\n      console.warn(\"[Lively4] load from external site\");\n    } else {\n      console.warn(\"[Lively4] Use existing service worker\");\n    }\n    // we don't have to do anything here... the service worker is already there\n    onReady();\n  } else {\n    // the scope of the serviceworker can only be refined to something below it's root... so we have to install it as a file at the content's side. \n    navigator.serviceWorker.register(new URL('swx-loader.js', window.location)).then(function(registration) {\n      console.warn(\"SWX registration\", registration)\n      window.lively4swxregistration = registration; // for debugging\n      // Registration was successful\n      console.warn('ServiceWorker registration successful with scope: ', registration.scope);\n\n      // so now we have to reload!\n      console.warn(\"ok... lets wait for the service worker.\");\n      // console.log(\"Lively4 ServiceWorker installed! Reboot needed! ;-)\")\n      // window.location = window.location\n    }).catch(function(err) {\n      // registration failed\n      console.warn('ServiceWorker registration failed: ', err);\n    });\n    navigator.serviceWorker.ready.then(onReady);\n  }\n}\n\ndocument.addEventListener('DOMContentLoaded', function() {\n  if (Notification.permission !== \"granted\")\n    Notification.requestPermission();\n});\n\n\n\n"],"mappings":";;;;;;;;;MAAA;MAEIA,aAAa;MAAA;QAAA;UAAA;QAAA;QAAA;UAAbA,8CAAa;UAAA;QAAA;QAAA;QAAA;MAAA;MAAA,sBACNC,UAAU,GAAG,IAAIC,OAAO,CAACC,OAAO,IAAI;QAC7C,mFAAAH,aAAa,GAAGG,OAAO;MACzB,CAAC,CAAC;MAAA;QAAA;UAAA;QAAA;QAAA;UAAA,sBAFSF,2CAAU;UAAA;QAAA;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