@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 15.2 kB
JavaScript
import*as Platform from"../../core/platform/platform.js";self.injectedExtensionAPI=function(e,t,n,o,s,r,i){const a=new Set(o),c=window.chrome||{};if(Object.getOwnPropertyDescriptor(c,"devtools"))return;let d=!1,u=!1;function l(e,t){this._type=e,this._listeners=[],this._customDispatch=t}function p(){this.onRequestFinished=new q("network-request-finished",(function(e){const t=e.arguments[1];t.__proto__=new L(e.arguments[0]),this._fire(t)})),b(this,"network","onFinished","onRequestFinished"),this.onNavigated=new q("inspected-url-changed")}function h(e){this._id=e}function m(){const e={elements:new C,sources:new M};function t(t){return e[t]}for(const n in e)Object.defineProperty(this,n,{get:t.bind(null,n),enumerable:!0});this.applyStyleSheet=function(e){J.sendRequest({command:"applyStyleSheet",styleSheet:e})}}function f(e){this._id=e,e&&(this.onShown=new q("view-shown-"+e,(function(e){const t=e.arguments[0];"number"==typeof t?this._fire(window.parent.frames[t]):this._fire()})),this.onHidden=new q("view-hidden,"+e))}function g(e){f.call(this,null),this._hostPanelName=e,this.onSelectionChanged=new q("panel-objectSelected-"+e)}function w(){this._plugins=new Map}function y(){this._plugins=new Map}function _(e){return function(...t){const n={__proto__:e.prototype};e.apply(n,t),function(e,t){for(const n in t){if("_"===n.charAt(0))continue;let o=null;for(let e=t;e&&!o;e=e.__proto__)o=Object.getOwnPropertyDescriptor(e,n);o&&("function"==typeof o.value?e[n]=o.value.bind(t):"function"==typeof o.get?e.__defineGetter__(n,o.get.bind(t)):Object.defineProperty(e,n,o))}}(this,n)}}function b(e,t,n,o){let s=!1;e.__defineGetter__(n,(function(){return s||(console.warn(t+"."+n+" is deprecated. Use "+t+"."+o+" instead"),s=!0),e[o]}))}function R(e){const t=e[e.length-1];return"function"==typeof t?t:void 0}l.prototype={addListener:function(e){if("function"!=typeof e)throw"addListener: callback is not a function";0===this._listeners.length&&J.sendRequest({command:"subscribe",type:this._type}),this._listeners.push(e),J.registerHandler("notify-"+this._type,this._dispatch.bind(this))},removeListener:function(e){const t=this._listeners;for(let n=0;n<t.length;++n)if(t[n]===e){t.splice(n,1);break}0===this._listeners.length&&J.sendRequest({command:"unsubscribe",type:this._type})},_fire:function(...e){const t=this._listeners.slice();for(let e=0;e<t.length;++e)t[e].apply(null,Array.from(arguments))},_dispatch:function(e){this._customDispatch?this._customDispatch.call(this,e):this._fire.apply(this,e.arguments)}},p.prototype={getHAR:function(e){J.sendRequest({command:"getHAR"},e&&function(t){const n=t,o=n&&n.entries||[];for(let e=0;e<o.length;++e)o[e].__proto__=new L(o[e]._requestId),delete o[e]._requestId;e&&e(n)})},addRequestHeaders:function(e){J.sendRequest({command:"addRequestHeaders",headers:e,extensionId:window.location.hostname})}},h.prototype={getContent:function(e){J.sendRequest({command:"getRequestContent",id:this._id},e&&function(t){const{content:n,encoding:o}=t;e&&e(n,o)})}},m.prototype={create:function(e,t,n,o){const s="extension-panel-"+J.nextObjectId();J.sendRequest({command:"createPanel",id:s,title:e,page:n},o&&(()=>o.call(this,new S(s))))},setOpenResourceHandler:function(e){const t=J.hasHandler("open-resource");e?J.registerHandler("open-resource",(function(t){d=!0;try{const{resource:n,lineNumber:o}=t;F(n)&&e.call(null,new E(n),o)}finally{d=!1}})):J.unregisterHandler("open-resource"),t===!e&&J.sendRequest({command:"setOpenResourceHandler",handlerPresent:Boolean(e)})},setThemeChangeHandler:function(e){const t=J.hasHandler("host-theme-change");e?J.registerHandler("host-theme-change",(function(t){const{themeName:n}=t;c.devtools.panels.themeName=n,e.call(null,n)})):J.unregisterHandler("host-theme-change"),t===!e&&J.sendRequest({command:"setThemeChangeHandler",handlerPresent:Boolean(e)})},openResource:function(e,t,n,o){const s=R(arguments),r="number"==typeof n?n:0;J.sendRequest({command:"openResource",url:e,lineNumber:t,columnNumber:r},s)},get SearchAction(){return{CancelSearch:"cancelSearch",PerformSearch:"performSearch",NextSearchResult:"nextSearchResult",PreviousSearchResult:"previousSearchResult"}}},g.prototype={createSidebarPane:function(e,t){const n="extension-sidebar-"+J.nextObjectId();J.sendRequest({command:"createSidebarPane",panel:this._hostPanelName,id:n,title:e},t&&function(){t&&t(new O(n))})},__proto__:f.prototype},w.prototype={registerRecorderExtensionPlugin:async function(e,t,n){if(this._plugins.has(e))throw new Error(`Tried to register plugin '${t}' twice`);const o=new MessageChannel,s=o.port1;this._plugins.set(e,s),s.onmessage=({data:t})=>{const{requestId:n}=t;(async function(t){switch(t.method){case"stringify":return e.stringify(t.parameters.recording);case"stringifyStep":return e.stringifyStep(t.parameters.step);case"replay":try{return d=!0,u=!0,e.replay(t.parameters.recording)}finally{d=!1,u=!1}default:throw new Error(`'${t.method}' is not recognized`)}})(t).then((e=>s.postMessage({requestId:n,result:e}))).catch((e=>s.postMessage({requestId:n,error:{message:e.message}})))};const r=[];"stringify"in e&&"stringifyStep"in e&&r.push("export"),"replay"in e&&r.push("replay"),await new Promise((e=>{J.sendRequest({command:"registerRecorderExtensionPlugin",pluginName:t,mediaType:n,capabilities:r,port:o.port2},(()=>e()),[o.port2])}))},unregisterRecorderExtensionPlugin:async function(e){const t=this._plugins.get(e);if(!t)throw new Error("Tried to unregister a plugin that was not previously registered");this._plugins.delete(e),t.postMessage({event:"unregisteredRecorderExtensionPlugin"}),t.close()},createView:async function(e,t){const n="recorder-extension-view-"+J.nextObjectId();return await new Promise((o=>{J.sendRequest({command:"createRecorderView",id:n,title:e,pagePath:t},o)})),new x(n)}},y.prototype={registerLanguageExtensionPlugin:async function(e,t,n){if(this._plugins.has(e))throw new Error(`Tried to register plugin '${t}' twice`);const o=new MessageChannel,s=o.port1;this._plugins.set(e,s),s.onmessage=({data:t})=>{const{requestId:n}=t;console.time(`${n}: ${t.method}`),function(t){switch(t.method){case"addRawModule":return e.addRawModule(t.parameters.rawModuleId,t.parameters.symbolsURL,t.parameters.rawModule);case"removeRawModule":return e.removeRawModule(t.parameters.rawModuleId);case"sourceLocationToRawLocation":return e.sourceLocationToRawLocation(t.parameters.sourceLocation);case"rawLocationToSourceLocation":return e.rawLocationToSourceLocation(t.parameters.rawLocation);case"getScopeInfo":return e.getScopeInfo(t.parameters.type);case"listVariablesInScope":return e.listVariablesInScope(t.parameters.rawLocation);case"getFunctionInfo":return e.getFunctionInfo(t.parameters.rawLocation);case"getInlinedFunctionRanges":return e.getInlinedFunctionRanges(t.parameters.rawLocation);case"getInlinedCalleesRanges":return e.getInlinedCalleesRanges(t.parameters.rawLocation);case"getMappedLines":return"getMappedLines"in e?e.getMappedLines(t.parameters.rawModuleId,t.parameters.sourceFileURL):Promise.resolve(void 0);case"formatValue":return"evaluate"in e&&e.evaluate?e.evaluate(t.parameters.expression,t.parameters.context,t.parameters.stopId):Promise.resolve(void 0);case"getProperties":if("getProperties"in e&&e.getProperties)return e.getProperties(t.parameters.objectId);if(!("evaluate"in e)||!e.evaluate)return Promise.resolve(void 0);break;case"releaseObject":if("releaseObject"in e&&e.releaseObject)return e.releaseObject(t.parameters.objectId)}throw new Error(`Unknown language plugin method ${t.method}`)}(t).then((e=>s.postMessage({requestId:n,result:e}))).catch((e=>s.postMessage({requestId:n,error:{message:e.message}}))).finally((()=>console.timeEnd(`${n}: ${t.method}`)))},await new Promise((e=>{J.sendRequest({command:"registerLanguageExtensionPlugin",pluginName:t,port:o.port2,supportedScriptTypes:n},(()=>e()),[o.port2])}))},unregisterLanguageExtensionPlugin:async function(e){const t=this._plugins.get(e);if(!t)throw new Error("Tried to unregister a plugin that was not previously registered");this._plugins.delete(e),t.postMessage({event:"unregisteredLanguageExtensionPlugin"}),t.close()},getWasmLinearMemory:async function(e,t,n){const o=await new Promise((o=>J.sendRequest({command:"getWasmLinearMemory",offset:e,length:t,stopId:n},o)));return Array.isArray(o)?new Uint8Array(o).buffer:new ArrayBuffer(0)},getWasmLocal:async function(e,t){return new Promise((n=>J.sendRequest({command:"getWasmLocal",local:e,stopId:t},n)))},getWasmGlobal:async function(e,t){return new Promise((n=>J.sendRequest({command:"getWasmGlobal",global:e,stopId:t},n)))},getWasmOp:async function(e,t){return new Promise((n=>J.sendRequest({command:"getWasmOp",op:e,stopId:t},n)))}};const v=_(y),I=_(w),P=_(N),q=_(l),S=_(T),x=_(H),O=_(A),j=_(g),L=_(h),E=_(D),k=_(K);class C extends j{constructor(){super("elements")}}class M extends j{constructor(){super("sources")}}function T(e){f.call(this,e),this.onSearch=new q("panel-search-"+e)}function H(e){f.call(this,e)}function A(e){f.call(this,e)}function N(e){this._id=e,this.onClicked=new q("button-clicked-"+e)}function W(){}function K(e){this._id=e}function B(e){this.onRecordingStarted=new q("trace-recording-started-"+e,(function(e){const t=e.arguments[0];this._fire(new k(t))})),this.onRecordingStopped=new q("trace-recording-stopped-"+e)}function F(t){try{return e.allowFileAccess||"file:"!==new URL(t.url).protocol}catch(e){return!1}}function U(){this.onResourceAdded=new q("resource-added",(function(e){const t=e.arguments[0];F(t)&&this._fire(new E(t))})),this.onResourceContentCommitted=new q("resource-content-committed",(function(e){const t=e.arguments[0];F(t)&&this._fire(new E(t),e.arguments[1])}))}function D(e){if(!F(e))throw new Error("Resource access not allowed");this._url=e.url,this._type=e.type}T.prototype={createStatusBarButton:function(e,t,n){const o="button-"+J.nextObjectId();return J.sendRequest({command:"createToolbarButton",panel:this._id,id:o,icon:e,tooltip:t,disabled:Boolean(n)}),new P(o)},show:function(){d&&J.sendRequest({command:"showPanel",id:this._id})},__proto__:f.prototype},H.prototype={show:function(){d&&u&&J.sendRequest({command:"showRecorderView",id:this._id})},__proto__:f.prototype},A.prototype={setHeight:function(e){J.sendRequest({command:"setSidebarHeight",id:this._id,height:e})},setExpression:function(e,t,n,o){J.sendRequest({command:"setSidebarContent",id:this._id,expression:e,rootTitle:t,evaluateOnPage:!0,evaluateOptions:"object"==typeof n?n:{}},R(arguments))},setObject:function(e,t,n){J.sendRequest({command:"setSidebarContent",id:this._id,expression:e,rootTitle:t},n)},setPage:function(e){J.sendRequest({command:"setSidebarPage",id:this._id,page:e})},__proto__:f.prototype},N.prototype={update:function(e,t,n){J.sendRequest({command:"updateButton",id:this._id,icon:e,tooltip:t,disabled:Boolean(n)})}},W.prototype={addTraceProvider:function(e,t){const n="extension-trace-provider-"+J.nextObjectId();return J.sendRequest({command:"addTraceProvider",id:n,categoryName:e,categoryTooltip:t}),new B(n)}},K.prototype={complete:function(e,t){J.sendRequest({command:"completeTra.eSession",id:this._id,url:e||Platform.DevToolsPath.EmptyUrlString,timeOffset:t||0})}},U.prototype={reload:function(e){let t=null;"object"==typeof e?t=e:"string"==typeof e&&(t={userAgent:e},console.warn("Passing userAgent as string parameter to inspectedWindow.reload() is deprecated. Use inspectedWindow.reload({ userAgent: value}) instead.")),J.sendRequest({command:"Reload",options:t})},eval:function(e,t){const n=R(arguments);return J.sendRequest({command:"evaluateOnInspectedPage",expression:e,evaluateOptions:"object"==typeof t?t:void 0},n&&function(e){const{isError:t,isException:o,value:s}=e;t||o?n&&n(void 0,e):n&&n(s)}),null},getResources:function(e){function t(e){return new E(e)}J.sendRequest({command:"getPageResources"},e&&function(n){e&&e(n.filter(F).map(t))})}},D.prototype={get url(){return this._url},get type(){return this._type},getContent:function(e){J.sendRequest({command:"getResourceContent",url:this._url},e&&function(t){const{content:n,encoding:o}=t;e&&e(n,o)})},setContent:function(e,t,n){J.sendRequest({command:"setResourceContent",url:this._url,content:e,commit:t},n)}};let $=[],V=null;function G(){V=null,J.sendRequest({command:"_forwardKeyboardEvent",entries:$}),$=[]}function z(e){this._callbacks={},this._handlers={},this._lastRequestId=0,this._lastObjectId=0,this.registerHandler("callback",this._onCallback.bind(this));const t=new MessageChannel;this._port=t.port1,this._port.addEventListener("message",this._onMessage.bind(this),!1),this._port.start(),e.postMessage("registerExtension","*",[t.port2])}document.addEventListener("keydown",(function(e){const t=document.activeElement;if(t){if(("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName||t.isContentEditable)&&!(e.ctrlKey||e.altKey||e.metaKey))return}let n=0;e.shiftKey&&(n|=1),e.ctrlKey&&(n|=2),e.altKey&&(n|=4),e.metaKey&&(n|=8);const o=255&e.keyCode|n<<8;if(!a.has(o))return;e.preventDefault();const s={eventType:e.type,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey,keyIdentifier:e.keyIdentifier,key:e.key,code:e.code,location:e.location,keyCode:e.keyCode};$.push(s),V||(V=window.setTimeout(G,0))}),!1),z.prototype={sendRequest:function(e,t,n){"function"==typeof t&&(e.requestId=this._registerCallback(t)),this._port.postMessage(e,n)},hasHandler:function(e){return Boolean(this._handlers[e])},registerHandler:function(e,t){this._handlers[e]=t},unregisterHandler:function(e){delete this._handlers[e]},nextObjectId:function(){return r.toString()+"_"+ ++this._lastObjectId},_registerCallback:function(e){const t=++this._lastRequestId;return this._callbacks[t]=e,t},_onCallback:function(e){if(e.requestId in this._callbacks){const t=this._callbacks[e.requestId];delete this._callbacks[e.requestId],t(e.result)}},_onMessage:function(e){const t=e.data,n=this._handlers[t.command];n&&n.call(this,t)}};const J=new z(i||window.parent),X=new function(){this.inspectedWindow=new U,this.panels=new m,this.network=new p,this.timeline=new W,this.languageServices=new v,this.recorder=new I,b(this,"webInspector","resources","network")};if(Object.defineProperty(c,"devtools",{value:{},enumerable:!0}),c.devtools.inspectedWindow={},Object.defineProperty(c.devtools.inspectedWindow,"tabId",{get:function(){return t}}),c.devtools.inspectedWindow.__proto__=X.inspectedWindow,c.devtools.network=X.network,c.devtools.panels=X.panels,c.devtools.panels.themeName=n,c.devtools.languageServices=X.languageServices,c.devtools.recorder=X.recorder,!1!==e.exposeExperimentalAPIs){c.experimental=c.experimental||{},c.experimental.devtools=c.experimental.devtools||{};const e=Object.getOwnPropertyNames(X);for(let t=0;t<e.length;++t){const n=Object.getOwnPropertyDescriptor(X,e[t]);n&&Object.defineProperty(c.experimental.devtools,e[t],n)}c.experimental.devtools.inspectedWindow=c.devtools.inspectedWindow}e.exposeWebInspectorNamespace&&(window.webInspector=X),s(J,X)},self.buildExtensionAPIInjectedScript=function(e,t,n,o,s){const r=[e,t||null,n,o].map((e=>JSON.stringify(e))).join(",");return s||(s=()=>{}),"(function(injectedScriptId){ ("+self.injectedExtensionAPI.toString()+")("+r+","+s+", injectedScriptId);})"};