UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 5.03 kB
import*as Platform from"../platform/platform.js";const queryParamsObject=new URLSearchParams(location.search);let runtimeInstance,runtimePlatform="";export function getRemoteBase(e=self.location.toString()){const t=new URL(e).searchParams.get("remoteBase");if(!t)return null;const n=/\/serve_file\/(@[0-9a-zA-Z]+)\/?$/.exec(t);return n?{base:`devtools://devtools/remote/serve_file/${n[1]}/`,version:n[1]}:null}export class Runtime{constructor(){}static instance(e={forceNew:null}){const{forceNew:t}=e;return runtimeInstance&&!t||(runtimeInstance=new Runtime),runtimeInstance}static removeInstance(){runtimeInstance=void 0}static queryParam(e){return queryParamsObject.get(e)}static setQueryParamForTesting(e,t){queryParamsObject.set(e,t)}static experimentsSetting(){try{return JSON.parse(self.localStorage&&self.localStorage.experiments?self.localStorage.experiments:"{}")}catch(e){return console.error("Failed to parse localStorage['experiments']"),{}}}static setPlatform(e){runtimePlatform=e}static platform(){return runtimePlatform}static isDescriptorEnabled(e){const t=e.experiment;if("*"===t)return!0;if(t&&t.startsWith("!")&&experiments.isEnabled(t.substring(1)))return!1;if(t&&!t.startsWith("!")&&!experiments.isEnabled(t))return!1;const n=e.condition;return!(n&&!n.startsWith("!")&&!Runtime.queryParam(n))&&!(n&&n.startsWith("!")&&Runtime.queryParam(n.substring(1)))}loadLegacyModule(e){return import(`../../${e}`)}}export class ExperimentsSupport{#e;#t;#n;#r;#s;#i;constructor(){this.#e=[],this.#t=new Set,this.#n=new Set,this.#r=new Set,this.#s=new Set,this.#i=new Set}allConfigurableExperiments(){const e=[];for(const t of this.#e)this.#n.has(t.name)||this.#i.has(t.name)||e.push(t);return e}setExperimentsSetting(e){self.localStorage&&(self.localStorage.experiments=JSON.stringify(e))}register(e,t,n,r,s){Platform.DCHECK((()=>!this.#t.has(e)),"Duplicate registration of experiment "+e),this.#t.add(e),this.#e.push(new Experiment(this,e,t,Boolean(n),r??Platform.DevToolsPath.EmptyUrlString,s??Platform.DevToolsPath.EmptyUrlString))}isEnabled(e){return this.checkExperiment(e),!1!==Runtime.experimentsSetting()[e]&&(!(!this.#n.has(e)&&!this.#r.has(e))||(!!this.#s.has(e)||Boolean(Runtime.experimentsSetting()[e])))}setEnabled(e,t){this.checkExperiment(e);const n=Runtime.experimentsSetting();n[e]=t,this.setExperimentsSetting(n)}enableExperimentsTransiently(e){for(const t of e)this.checkExperiment(t),this.#n.add(t)}enableExperimentsByDefault(e){for(const t of e)this.checkExperiment(t),this.#r.add(t)}setServerEnabledExperiments(e){for(const t of e)this.checkExperiment(t),this.#s.add(t)}setNonConfigurableExperiments(e){for(const t of e)this.checkExperiment(t),this.#i.add(t)}enableForTest(e){this.checkExperiment(e),this.#n.add(e)}disableForTest(e){this.checkExperiment(e),this.#n.delete(e)}clearForTest(){this.#e=[],this.#t.clear(),this.#n.clear(),this.#r.clear(),this.#s.clear()}cleanUpStaleExperiments(){const e=Runtime.experimentsSetting(),t={};for(const{name:n}of this.#e)if(e.hasOwnProperty(n)){const r=e[n];(r||this.#r.has(n))&&(t[n]=r)}this.setExperimentsSetting(t)}checkExperiment(e){Platform.DCHECK((()=>this.#t.has(e)),"Unknown experiment "+e)}}export class Experiment{name;title;unstable;docLink;feedbackLink;#e;constructor(e,t,n,r,s,i){this.name=t,this.title=n,this.unstable=r,this.docLink=s,this.feedbackLink=i,this.#e=e}isEnabled(){return this.#e.isEnabled(this.name)}setEnabled(e){this.#e.setEnabled(this.name,e)}}export const experiments=new ExperimentsSupport;export var ExperimentName;!function(e){e.CAPTURE_NODE_CREATION_STACKS="captureNodeCreationStacks",e.CSS_OVERVIEW="cssOverview",e.LIVE_HEAP_PROFILE="liveHeapProfile",e.DEVELOPER_RESOURCES_VIEW="developerResourcesView",e.CSP_VIOLATIONS_VIEW="cspViolationsView",e.WASM_DWARF_DEBUGGING="wasmDWARFDebugging",e.ALL="*",e.PROTOCOL_MONITOR="protocolMonitor",e.WEBAUTHN_PANE="webauthnPane",e.FULL_ACCESSIBILITY_TREE="fullAccessibilityTree",e.PRECISE_CHANGES="preciseChanges",e.STYLES_PANE_CSS_CHANGES="stylesPaneCSSChanges",e.HEADER_OVERRIDES="headerOverrides",e.EYEDROPPER_COLOR_PICKER="eyedropperColorPicker",e.INSTRUMENTATION_BREAKPOINTS="instrumentationBreakpoints",e.AUTHORED_DEPLOYED_GROUPING="authoredDeployedGrouping",e.IMPORTANT_DOM_PROPERTIES="importantDOMProperties",e.JUST_MY_CODE="justMyCode",e.PRELOADING_STATUS_PANEL="preloadingStatusPanel",e.DISABLE_COLOR_FORMAT_SETTING="disableColorFormatSetting",e.TIMELINE_AS_CONSOLE_PROFILE_RESULT_PANEL="timelineAsConsoleProfileResultPanel",e.OUTERMOST_TARGET_SELECTOR="outermostTargetSelector",e.JS_PROFILER_TEMP_ENABLE="jsProfilerTemporarilyEnable",e.HIGHLIGHT_ERRORS_ELEMENTS_PANEL="highlightErrorsElementsPanel",e.SET_ALL_BREAKPOINTS_EAGERLY="setAllBreakpointsEagerly",e.SELF_XSS_WARNING="selfXssWarning",e.USE_SOURCE_MAP_SCOPES="useSourceMapScopes",e.STORAGE_BUCKETS_TREE="storageBucketsTree"}(ExperimentName||(ExperimentName={}));export var ConditionName;!function(e){e.CAN_DOCK="can_dock",e.NOT_SOURCES_HIDE_ADD_FOLDER="!sources.hide_add_folder"}(ConditionName||(ConditionName={}));