-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension-worker.js
More file actions
2 lines (2 loc) · 12 KB
/
extension-worker.js
File metadata and controls
2 lines (2 loc) · 12 KB
1
2
(function(m,f){typeof exports=="object"&&typeof module=="object"?module.exports=f():typeof define=="function"&&define.amd?define([],f):typeof exports=="object"?exports.VirtualMachine=f():m.VirtualMachine=f()})(self,()=>(()=>{var m={92589(l,c,s){const i=s(73707);l.exports=class{constructor(){this.callbacks=[],this.nextResponseId=0}call(r,e){for(var t=arguments.length,o=new Array(t>2?t-2:0),n=2;n<t;n++)o[n-2]=arguments[n];return this.transferCall(r,e,null,...o)}transferCall(r,e,t){try{const{provider:p,isRemote:u}=this._getServiceProvider(r);if(p){for(var o=arguments.length,n=new Array(o>3?o-3:0),a=3;a<o;a++)n[a-3]=arguments[a];if(u)return this._remoteTransferCall(p,r,e,t,...n);const d=p[e].apply(p,n);return Promise.resolve(d)}return Promise.reject(new Error("Service not found: ".concat(r)))}catch(p){return Promise.reject(p)}}_isRemoteService(r){return this._getServiceProvider(r).isRemote}_remoteCall(r,e,t){for(var o=arguments.length,n=new Array(o>3?o-3:0),a=3;a<o;a++)n[a-3]=arguments[a];return this._remoteTransferCall(r,e,t,null,...n)}_remoteTransferCall(r,e,t,o){for(var n=arguments.length,a=new Array(n>4?n-4:0),p=4;p<n;p++)a[p-4]=arguments[p];return new Promise((u,d)=>{const y=this._storeCallbacks(u,d);a.length>0&&typeof a[a.length-1].yield=="function"&&a.pop(),o?r.postMessage({service:e,method:t,responseId:y,args:a},o):r.postMessage({service:e,method:t,responseId:y,args:a})})}_storeCallbacks(r,e){const t=this.nextResponseId++;return this.callbacks[t]=[r,e],t}_deliverResponse(r,e){try{const[t,o]=this.callbacks[r];delete this.callbacks[r],e.error?o(e.error):t(e.result)}catch(t){i.error("Dispatch callback failed: ".concat(JSON.stringify(t)))}}_onMessage(r,e){const t=e.data;let o;t.args=t.args||[],t.service?o=t.service==="dispatch"?this._onDispatchMessage(r,t):this.call(t.service,t.method,...t.args):t.responseId===void 0?i.error("Dispatch caught malformed message from a worker: ".concat(JSON.stringify(e))):this._deliverResponse(t.responseId,t),o&&(t.responseId===void 0?i.error("Dispatch message missing required response ID: ".concat(JSON.stringify(e))):o.then(n=>r.postMessage({responseId:t.responseId,result:n}),n=>r.postMessage({responseId:t.responseId,error:n})))}_getServiceProvider(r){throw new Error("Could not get provider for ".concat(r,": _getServiceProvider not implemented"))}_onDispatchMessage(r,e){throw new Error("Unimplemented dispatch message handler cannot handle ".concat(e.method," method"))}}},63260(l,c,s){const i=s(92589),r=s(73707);l.exports=new class extends i{constructor(){super(),this._connectionPromise=new Promise(e=>{this._onConnect=e}),this.services={},this._onMessage=this._onMessage.bind(this,self),typeof self<"u"&&(self.onmessage=this._onMessage)}get waitForConnection(){return this._connectionPromise}setService(e,t){return Object.prototype.hasOwnProperty.call(this.services,e)&&r.warn("Worker dispatch replacing existing service provider for ".concat(e)),this.services[e]=t,this.waitForConnection.then(()=>this._remoteCall(self,"dispatch","setService",e))}_getServiceProvider(e){const t=this.services[e];return{provider:t||self,isRemote:!t}}_onDispatchMessage(e,t){let o;switch(t.method){case"handshake":o=this._onConnect();break;case"terminate":setTimeout(()=>self.close(),0),o=Promise.resolve();break;default:r.error("Worker dispatch received message for unknown method: ".concat(t.method))}return o}}},56342(l){l.exports={ANGLE:"angle",BOOLEAN:"Boolean",COLOR:"color",NUMBER:"number",STRING:"string",MATRIX:"matrix",NOTE:"note",IMAGE:"image"}},39274(l){l.exports={BOOLEAN:"Boolean",BUTTON:"button",COMMAND:"command",CONDITIONAL:"conditional",EVENT:"event",HAT:"hat",LOOP:"loop",REPORTER:"reporter"}},49432(l){l.exports={SPRITE:"sprite",STAGE:"stage"}},73707(l,c,s){const i=s(6824);i.enable(),l.exports=i("vm")},81920(l){function c(){this._events={}}c.prototype={on:function(s,i){this._events||(this._events={});var r=this._events;return(r[s]||(r[s]=[])).push(i),this},removeListener:function(s,i){var r,e=this._events[s]||[];for(r=e.length-1;r>=0&&e[r];r--)e[r]!==i&&e[r].cb!==i||e.splice(r,1)},removeAllListeners:function(s){s?this._events[s]&&(this._events[s]=[]):this._events={}},listeners:function(s){return this._events&&this._events[s]||[]},emit:function(s){this._events||(this._events={});var i,r=Array.prototype.slice.call(arguments,1),e=this._events[s]||[];for(i=e.length-1;i>=0&&e[i];i--)e[i].apply(this,r);return this},when:function(s,i){return this.once(s,i,!0)},once:function(s,i,r){if(!i)return this;function e(){r||this.removeListener(s,e),i.apply(this,arguments)&&r&&this.removeListener(s,e)}return e.cb=i,this.on(s,e),this}},c.mixin=function(s){var i,r=c.prototype;for(i in r)r.hasOwnProperty(i)&&(s.prototype[i]=r[i])},l.exports=c},78589(l,c,s){var i=s(92491),r={debug:1,info:2,warn:3,error:4};function e(){this.enabled=!0,this.defaultResult=!0,this.clear()}function t(o,n){return o.n.test?o.n.test(n):o.n==n}i.mixin(e),e.prototype.allow=function(o,n){return this._white.push({n:o,l:r[n]}),this},e.prototype.deny=function(o,n){return this._black.push({n:o,l:r[n]}),this},e.prototype.clear=function(){return this._white=[],this._black=[],this},e.prototype.test=function(o,n){var a,p=Math.max(this._white.length,this._black.length);for(a=0;a<p;a++){if(this._white[a]&&t(this._white[a],o)&&r[n]>=this._white[a].l)return!0;if(this._black[a]&&t(this._black[a],o)&&r[n]<=this._black[a].l)return!1}return this.defaultResult},e.prototype.write=function(o,n,a){if(!this.enabled||this.test(o,n))return this.emit("item",o,n,a)},l.exports=e},4932(l,c,s){var i=s(92491),r=s(78589),e=new i,t=Array.prototype.slice;c=l.exports=function(o){var n=function(){return e.write(o,void 0,t.call(arguments)),n};return n.debug=function(){return e.write(o,"debug",t.call(arguments)),n},n.info=function(){return e.write(o,"info",t.call(arguments)),n},n.warn=function(){return e.write(o,"warn",t.call(arguments)),n},n.error=function(){return e.write(o,"error",t.call(arguments)),n},n.log=n.debug,n.suggest=c.suggest,n.format=e.format,n},c.defaultBackend=c.defaultFormatter=null,c.pipe=function(o){return e.pipe(o)},c.end=c.unpipe=c.disable=function(o){return e.unpipe(o)},c.Transform=i,c.Filter=r,c.suggest=new r,c.enable=function(){return c.defaultFormatter?e.pipe(c.suggest).pipe(c.defaultFormatter).pipe(c.defaultBackend):e.pipe(c.suggest).pipe(c.defaultBackend)}},92491(l,c,s){function i(){}s(81920).mixin(i),i.prototype.write=function(r,e,t){this.emit("item",r,e,t)},i.prototype.end=function(){this.emit("end"),this.removeAllListeners()},i.prototype.pipe=function(r){var e=this;function t(){r.write.apply(r,Array.prototype.slice.call(arguments))}function o(){!r._isStdio&&r.end()}return e.emit("unpipe",r),r.emit("pipe",e),e.on("item",t),e.on("end",o),e.when("unpipe",function(n){var a=n===r||n===void 0;return a&&(e.removeListener("item",t),e.removeListener("end",o),r.emit("unpipe")),a}),r},i.prototype.unpipe=function(r){return this.emit("unpipe",r),this},i.prototype.format=function(r){throw new Error(["Warning: .format() is deprecated in Minilog v2! Use .pipe() instead. For example:","var Minilog = require('minilog');","Minilog"," .pipe(Minilog.backends.console.formatClean)"," .pipe(Minilog.backends.console);"].join(`
`))},i.mixin=function(r){var e,t=i.prototype;for(e in t)t.hasOwnProperty(e)&&(r.prototype[e]=t[e])},l.exports=i},27585(l,c,s){var i=s(92491),r=[],e=new i;e.write=function(t,o,n){r.push([t,o,n])},e.get=function(){return r},e.empty=function(){r=[]},l.exports=e},79925(l,c,s){var i=s(92491),r=/\n+$/,e=new i;e.write=function(t,o,n){var a=n.length-1;if(typeof console<"u"&&console.log){if(console.log.apply)return console.log.apply(console,[t,o].concat(n));if(JSON&&JSON.stringify){n[a]&&typeof n[a]=="string"&&(n[a]=n[a].replace(r,""));try{for(a=0;a<n.length;a++)n[a]=JSON.stringify(n[a])}catch{}console.log(n.join(" "))}}},e.formatters=["color","minilog"],e.color=s(329),e.minilog=s(88933),l.exports=e},329(l,c,s){var i=s(92491),r=s(82216),e={debug:["cyan"],info:["purple"],warn:["yellow",!0],error:["red",!0]},t=new i;t.write=function(o,n,a){console[n]&&console[n].apply&&console[n].apply(console,["%c"+o+" %c"+n,r("gray"),r.apply(r,e[n])].concat(a))},t.pipe=function(){},l.exports=t},88933(l,c,s){var i=s(92491),r=s(82216),e={debug:["gray"],info:["purple"],warn:["yellow",!0],error:["red",!0]},t=new i;t.write=function(o,n,a){var p=console.log;n!="debug"&&console[n]&&(p=console[n]);var u=0;if(n!="info"){for(;u<a.length&&typeof a[u]=="string";u++);p.apply(console,["%c"+o+" "+a.slice(0,u).join(" "),r.apply(r,e[n])].concat(a.slice(u)))}else p.apply(console,["%c"+o,r.apply(r,e[n])].concat(a))},t.pipe=function(){},l.exports=t},82216(l){var c={black:"#000",red:"#c23621",green:"#25bc26",yellow:"#bbbb00",blue:"#492ee1",magenta:"#d338d3",cyan:"#33bbc8",gray:"#808080",purple:"#708"};l.exports=function(s,i){return i?"color: #fff; background: "+c[s]+";":"color: "+c[s]+";"}},6824(l,c,s){var i=s(4932),r=i.enable,e=i.disable,t=typeof navigator<"u"&&/chrome/i.test(navigator.userAgent),o=s(79925);if(i.defaultBackend=t?o.minilog:o,typeof window<"u"){try{i.enable(JSON.parse(window.localStorage.minilogSettings))}catch{}if(window.location&&window.location.search){var n=RegExp("[?&]minilog=([^&]*)").exec(window.location.search);n&&i.enable(decodeURIComponent(n[1]))}}i.enable=function(){r.call(i,!0);try{window.localStorage.minilogSettings=JSON.stringify(!0)}catch{}return this},i.disable=function(){e.call(i);try{delete window.localStorage.minilogSettings}catch{}return this},(l.exports=i).backends={array:s(27585),browser:i.defaultBackend,localStorage:s(66178),jQuery:s(93545)}},93545(l,c,s){var i=s(92491),r=new Date().valueOf().toString(36);function e(t){this.url=t.url||"",this.cache=[],this.timer=null,this.interval=t.interval||3e4,this.enabled=!0,this.jQuery=window.jQuery,this.extras={}}i.mixin(e),e.prototype.write=function(t,o,n){this.timer||this.init(),this.cache.push([t,o].concat(n))},e.prototype.init=function(){if(this.enabled&&this.jQuery){var t=this;this.timer=setTimeout(function(){var o,n,a=[],p=t.url;if(t.cache.length==0)return t.init();for(o=0;o<t.cache.length;o++)try{JSON.stringify(t.cache[o]),a.push(t.cache[o])}catch{}t.jQuery.isEmptyObject(t.extras)?(n=JSON.stringify({logs:a}),p=t.url+"?client_id="+r):n=JSON.stringify(t.jQuery.extend({logs:a},t.extras)),t.jQuery.ajax(p,{type:"POST",cache:!1,processData:!1,data:n,contentType:"application/json",timeout:1e4}).success(function(u,d,y){u.interval&&(t.interval=Math.max(1e3,u.interval))}).error(function(){t.interval=3e4}).always(function(){t.init()}),t.cache=[]},this.interval)}},e.prototype.end=function(){},e.jQueryWait=function(t){if(typeof window<"u"&&(window.jQuery||window.$))return t(window.jQuery||window.$);typeof window<"u"&&setTimeout(function(){e.jQueryWait(t)},200)},l.exports=e},66178(l,c,s){var i=s(92491),r=!1,e=new i;e.write=function(t,o,n){if(typeof window<"u"&&typeof JSON<"u"&&JSON.stringify&&JSON.parse)try{r||(r=window.localStorage.minilog?JSON.parse(window.localStorage.minilog):[]),r.push([new Date().toString(),t,o,n]),window.localStorage.minilog=JSON.stringify(r)}catch{}},l.exports=e}},f={};function h(l){var c=f[l];if(c!==void 0)return c.exports;var s=f[l]={exports:{}};return m[l](s,s.exports,h),s.exports}h.g=(function(){if(typeof globalThis=="object")return globalThis;try{return this||new Function("return this")()}catch{if(typeof window=="object")return window}})();const v=h(56342),b=h(39274),g=h(63260),x=h(49432);h.g.Scratch=h.g.Scratch||{},h.g.Scratch.ArgumentType=v,h.g.Scratch.BlockType=b,h.g.Scratch.TargetType=x;const w=new class{constructor(){this.nextExtensionId=0,this.initialRegistrations=[],g.waitForConnection.then(()=>{g.call("extensions","allocateWorker").then(l=>{const[c,s]=l;this.workerId=c;try{importScripts(s);const i=this.initialRegistrations;this.initialRegistrations=null,Promise.all(i).then(()=>g.call("extensions","onWorkerInit",c))}catch(i){g.call("extensions","onWorkerInit",c,i)}})}),this.extensions=[]}register(l){const c=this.nextExtensionId++;this.extensions.push(l);const s="extension.".concat(this.workerId,".").concat(c),i=g.setService(s,l).then(()=>g.call("extensions","registerExtensionService",s));return this.initialRegistrations&&this.initialRegistrations.push(i),i}};return h.g.Scratch.extensions={register:w.register.bind(w)},{}})());