UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 52.4 kB
import*as Common from"../../core/common/common.js";import*as Host from"../../core/host/host.js";import*as i18n from"../../core/i18n/i18n.js";import*as Platform from"../../core/platform/platform.js";import*as Root from"../../core/root/root.js";import*as SDK from"../../core/sdk/sdk.js";import*as Bindings from"../../models/bindings/bindings.js";import*as Breakpoints from"../../models/breakpoints/breakpoints.js";import*as Formatter from"../../models/formatter/formatter.js";import*as SourceMapScopes from"../../models/source_map_scopes/source_map_scopes.js";import*as TextUtils from"../../models/text_utils/text_utils.js";import*as Workspace from"../../models/workspace/workspace.js";import*as CodeMirror from"../../third_party/codemirror.next/codemirror.next.js";import*as ObjectUI from"../../ui/legacy/components/object_ui/object_ui.js";import*as SourceFrame from"../../ui/legacy/components/source_frame/source_frame.js";import*as UI from"../../ui/legacy/legacy.js";import*as SourceComponents from"./components/components.js";import{AddDebugInfoURLDialog}from"./AddSourceMapURLDialog.js";import{BreakpointEditDialog}from"./BreakpointEditDialog.js";import{Plugin}from"./Plugin.js";import{SourcesPanel}from"./SourcesPanel.js";const{EMPTY_BREAKPOINT_CONDITION:EMPTY_BREAKPOINT_CONDITION,NEVER_PAUSE_HERE_CONDITION:NEVER_PAUSE_HERE_CONDITION}=Breakpoints.BreakpointManager,UIStrings={thisScriptIsOnTheDebuggersIgnore:"This script is on the debugger's ignore list",removeFromIgnoreList:"Remove from ignore list",configure:"Configure",addBreakpoint:"Add breakpoint",addConditionalBreakpoint:"Add conditional breakpoint…",addLogpoint:"Add logpoint…",neverPauseHere:"Never pause here",removeBreakpoint:"{n, plural, =1 {Remove breakpoint} other {Remove all breakpoints in line}}",editBreakpoint:"Edit breakpoint…",disableBreakpoint:"{n, plural, =1 {Disable breakpoint} other {Disable all breakpoints in line}}",enableBreakpoint:"{n, plural, =1 {Enable breakpoint} other {Enable all breakpoints in line}}",addSourceMap:"Add source map…",addWasmDebugInfo:"Add DWARF debug info…",sourceMapLoaded:"Source map loaded.",associatedFilesAreAvailable:"Associated files are available via file tree or {PH1}.",associatedFilesShouldBeAdded:"Associated files should be added to the file tree. You can debug these resolved source files as regular JavaScript files.",theDebuggerWillSkipStepping:"The debugger will skip stepping through this script, and will not stop on exceptions.",sourceMapSkipped:"Source map skipped for this file.",sourceMapFailed:"Source map failed to load.",debuggingPowerReduced:"DevTools can't show authored sources, but you can debug the deployed code.",reloadForSourceMap:"To enable again, make sure the file isn't on the ignore list and reload.",errorLoading:"Error loading url {PH1}: {PH2}",ignoreScript:"Ignore this file",ignoreContentScripts:"Ignore extension scripts",debugFileNotFound:'Failed to load debug file "{PH1}".',debugInfoNotFound:"Failed to load any debug info for {PH1}."},str_=i18n.i18n.registerUIStrings("panels/sources/DebuggerPlugin.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_),MAX_POSSIBLE_BREAKPOINT_LINE=2500,MAX_CODE_SIZE_FOR_VALUE_DECORATIONS=1e4,MAX_PROPERTIES_IN_SCOPE_FOR_VALUE_DECORATIONS=500,debuggerPluginForUISourceCode=new Map;export class DebuggerPlugin extends Plugin{transformer;editor=void 0;executionLocation=null;controlDown=!1;controlTimeout=void 0;sourceMapInfobar=null;scriptsPanel;breakpointManager;popoverHelper=null;scriptFileForDebuggerModel;breakpoints=[];continueToLocations=null;liveLocationPool;muted;initializedMuted;ignoreListInfobar;refreshBreakpointsTimeout=void 0;activeBreakpointDialog=null;#e=void 0;#t=!1;missingDebugInfoBar=null;#o=!1;loader;ignoreListCallback;constructor(e,t){super(e),this.transformer=t,debuggerPluginForUISourceCode.set(e,this),this.scriptsPanel=SourcesPanel.instance(),this.breakpointManager=Breakpoints.BreakpointManager.BreakpointManager.instance(),this.breakpointManager.addEventListener(Breakpoints.BreakpointManager.Events.BreakpointAdded,this.breakpointChange,this),this.breakpointManager.addEventListener(Breakpoints.BreakpointManager.Events.BreakpointRemoved,this.breakpointChange,this),this.uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyChanged,this.workingCopyChanged,this),this.uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCommitted,this.workingCopyCommitted,this),this.scriptFileForDebuggerModel=new Map,this.loader=SDK.PageResourceLoader.PageResourceLoader.instance(),this.loader.addEventListener(SDK.PageResourceLoader.Events.Update,this.showSourceMapInfobarIfNeeded.bind(this),this),this.ignoreListCallback=this.showIgnoreListInfobarIfNeeded.bind(this),Bindings.IgnoreListManager.IgnoreListManager.instance().addChangeListener(this.ignoreListCallback),UI.Context.Context.instance().addFlavorChangeListener(SDK.DebuggerModel.CallFrame,this.callFrameChanged,this),this.liveLocationPool=new Bindings.LiveLocation.LiveLocationPool,this.updateScriptFiles(),this.muted=this.uiSourceCode.isDirty(),this.initializedMuted=this.muted,this.ignoreListInfobar=null,this.showIgnoreListInfobarIfNeeded();for(const e of this.scriptFileForDebuggerModel.values())e.checkMapping()}editorExtension(){const e=this.shortcutHandlers();return[CodeMirror.EditorView.updateListener.of((e=>this.onEditorUpdate(e))),CodeMirror.EditorView.domEventHandlers({keydown:t=>!!this.onKeyDown(t)||(e(t),t.defaultPrevented),keyup:e=>this.onKeyUp(e),mousemove:e=>this.onMouseMove(e),mousedown:e=>this.onMouseDown(e),focusout:e=>this.onBlur(e),wheel:e=>this.onWheel(e)}),CodeMirror.lineNumbers({domEventHandlers:{mousedown:(e,t,o)=>this.handleGutterClick(e.state.doc.lineAt(t.from),o)}}),infobarState,breakpointMarkers,CodeMirror.Prec.highest(executionLine.field),CodeMirror.Prec.lowest(continueToMarkers.field),markIfContinueTo,valueDecorations.field,CodeMirror.Prec.lowest(evalExpression.field),theme,this.uiSourceCode.project().type()===Workspace.Workspace.projectTypes.Debugger?CodeMirror.EditorView.editorAttributes.of({class:"source-frame-debugger-script"}):[]]}shortcutHandlers(){const e=e=>e.state.doc.lineAt(e.state.selection.main.head);return UI.ShortcutRegistry.ShortcutRegistry.instance().getShortcutListener({"debugger.toggle-breakpoint":async()=>!(this.muted||!this.editor)&&(await this.toggleBreakpoint(e(this.editor),!1),!0),"debugger.toggle-breakpoint-enabled":async()=>!(this.muted||!this.editor)&&(await this.toggleBreakpoint(e(this.editor),!0),!0),"debugger.breakpoint-input-window":async()=>{if(this.muted||!this.editor)return!1;const t=e(this.editor);return Host.userMetrics.breakpointEditDialogRevealedFrom(4),this.#i(t),!0}})}#i(e){if(this.muted)return;this.activeBreakpointDialog&&this.activeBreakpointDialog.finishEditing(!1,"");const t=this.breakpoints.find((t=>t.position>=e.from&&t.position<=e.to))?.breakpoint||null;this.editBreakpointCondition({line:e,breakpoint:t,location:null,isLogpoint:t?.isLogpoint()})}editorInitialized(e){this.editor=e,computeNonBreakableLines(e.state,this.transformer,this.uiSourceCode).then((t=>{t.length&&e.dispatch({effects:SourceFrame.SourceFrame.addNonBreakableLines.of(t)})}),console.error),this.ignoreListInfobar&&this.attachInfobar(this.ignoreListInfobar),this.missingDebugInfoBar&&this.attachInfobar(this.missingDebugInfoBar),this.sourceMapInfobar&&this.attachInfobar(this.sourceMapInfobar),this.muted||this.refreshBreakpoints(),this.callFrameChanged(),this.popoverHelper?.dispose(),this.popoverHelper=new UI.PopoverHelper.PopoverHelper(e,this.getPopoverRequest.bind(this)),this.popoverHelper.setDisableOnClick(!0),this.popoverHelper.setTimeout(250,250),this.popoverHelper.setHasPadding(!0)}static accepts(e){return e.contentType().hasScripts()}showIgnoreListInfobarIfNeeded(){const e=this.uiSourceCode;if(!e.contentType().hasScripts())return;if(!Bindings.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(e))return void this.hideIgnoreListInfobar();this.ignoreListInfobar&&this.ignoreListInfobar.dispose();const t=new UI.Infobar.Infobar(UI.Infobar.Type.Warning,i18nString(UIStrings.thisScriptIsOnTheDebuggersIgnore),[{text:i18nString(UIStrings.removeFromIgnoreList),highlight:!1,delegate:function(){Bindings.IgnoreListManager.IgnoreListManager.instance().unIgnoreListUISourceCode(e)},dismiss:!0},{text:i18nString(UIStrings.configure),highlight:!1,delegate:UI.ViewManager.ViewManager.instance().showView.bind(UI.ViewManager.ViewManager.instance(),"blackbox"),dismiss:!1}]);this.ignoreListInfobar=t,t.setCloseCallback((()=>this.removeInfobar(this.ignoreListInfobar))),t.createDetailsRowMessage(i18nString(UIStrings.theDebuggerWillSkipStepping)),this.attachInfobar(this.ignoreListInfobar)}attachInfobar(e){this.editor&&this.editor.dispatch({effects:addInfobar.of(e)})}removeInfobar(e){this.editor&&e&&this.editor.dispatch({effects:removeInfobar.of(e)})}hideIgnoreListInfobar(){this.ignoreListInfobar&&(this.ignoreListInfobar.dispose(),this.ignoreListInfobar=null)}willHide(){this.popoverHelper?.hidePopover()}editBreakpointLocation({breakpoint:e,uiLocation:t}){const{lineNumber:o}=this.transformer.uiLocationToEditorLocation(t.lineNumber,t.columnNumber),i=this.editor?.state.doc.line(o+1);i&&this.editBreakpointCondition({line:i,breakpoint:e,location:null,isLogpoint:e.isLogpoint()})}populateLineGutterContextMenu(e,t){const o=new Workspace.UISourceCode.UILocation(this.uiSourceCode,t,0);if(this.scriptsPanel.appendUILocationItems(e,o),this.muted||!this.editor)return;const i=this.editor.state.doc.line(t+1),n=this.lineBreakpoints(i),r=Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().supportsConditionalBreakpoints(this.uiSourceCode);if(n.length){const t=i18nString(UIStrings.removeBreakpoint,{n:n.length});e.debugSection().appendItem(t,(()=>n.forEach((e=>{Host.userMetrics.actionTaken(Host.UserMetrics.Action.BreakpointRemovedFromGutterContextMenu),e.remove(!1)})))),1===n.length&&r&&e.debugSection().appendItem(i18nString(UIStrings.editBreakpoint),(()=>{Host.userMetrics.breakpointEditDialogRevealedFrom(2),this.editBreakpointCondition({line:i,breakpoint:n[0],location:null})}));if(n.some((e=>e.enabled()))){const t=i18nString(UIStrings.disableBreakpoint,{n:n.length});e.debugSection().appendItem(t,(()=>n.forEach((e=>e.setEnabled(!1)))))}if(n.some((e=>!e.enabled()))){const t=i18nString(UIStrings.enableBreakpoint,{n:n.length});e.debugSection().appendItem(t,(()=>n.forEach((e=>e.setEnabled(!0)))))}}else this.editor&&SourceFrame.SourceFrame.isBreakableLine(this.editor.state,i)&&(e.debugSection().appendItem(i18nString(UIStrings.addBreakpoint),this.createNewBreakpoint.bind(this,i,EMPTY_BREAKPOINT_CONDITION,!0,!1)),r&&(e.debugSection().appendItem(i18nString(UIStrings.addConditionalBreakpoint),(()=>{Host.userMetrics.breakpointEditDialogRevealedFrom(3),this.editBreakpointCondition({line:i,breakpoint:null,location:null,isLogpoint:!1})})),e.debugSection().appendItem(i18nString(UIStrings.addLogpoint),(()=>{Host.userMetrics.breakpointEditDialogRevealedFrom(3),this.editBreakpointCondition({line:i,breakpoint:null,location:null,isLogpoint:!0})})),e.debugSection().appendItem(i18nString(UIStrings.neverPauseHere),this.createNewBreakpoint.bind(this,i,NEVER_PAUSE_HERE_CONDITION,!0,!1))))}populateTextAreaContextMenu(e){function t(e,t){t&&e.addSourceMapURL(t)}function o(e,t){t&&e.addDebugInfoURL(t)}if(this.uiSourceCode.project().type()===Workspace.Workspace.projectTypes.Network&&Common.Settings.Settings.instance().moduleSetting("jsSourceMapsEnabled").get()&&!Bindings.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(this.uiSourceCode.url())&&this.scriptFileForDebuggerModel.size){const i=this.scriptFileForDebuggerModel.values().next().value,n=i18nString(UIStrings.addSourceMap);e.debugSection().appendItem(n,function(e){AddDebugInfoURLDialog.createAddSourceMapURLDialog(t.bind(null,e)).show()}.bind(null,i)),i.script?.isWasm()&&!Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().pluginManager?.hasPluginForScript(i.script)&&e.debugSection().appendItem(i18nString(UIStrings.addWasmDebugInfo),function(e){AddDebugInfoURLDialog.createAddDWARFSymbolsURLDialog(o.bind(null,e)).show()}.bind(null,i))}}workingCopyChanged(){this.scriptFileForDebuggerModel.size||this.setMuted(this.uiSourceCode.isDirty())}workingCopyCommitted(){this.scriptsPanel.updateLastModificationTime(),this.scriptFileForDebuggerModel.size||this.setMuted(!1)}didMergeToVM(){this.consistentScripts()&&this.setMuted(!1)}didDivergeFromVM(){this.setMuted(!0)}setMuted(e){this.initializedMuted||e!==this.muted&&(this.muted=e,e?this.editor&&this.editor.dispatch({effects:muteBreakpoints.of(null)}):this.restoreBreakpointsAfterEditing())}consistentScripts(){for(const e of this.scriptFileForDebuggerModel.values())if(e.hasDivergedFromVM()||e.isMergingToVM())return!1;return!0}isVariableIdentifier(e){return"VariableName"===e||"VariableDefinition"===e}isIdentifier(e){return"VariableName"===e||"VariableDefinition"===e||"PropertyName"===e||"PropertyDefinition"===e}getPopoverRequest(e){if(UI.KeyboardShortcut.KeyboardShortcut.eventHasCtrlEquivalentKey(e))return null;const t=UI.Context.Context.instance().flavor(SDK.Target.Target),o=t?t.model(SDK.DebuggerModel.DebuggerModel):null,{editor:i}=this;if(!o||!o.isPaused()||!i)return null;const n=UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame);if(!n)return null;let r=i.editor.posAtCoords(e);if(!r)return null;const s=i.editor.coordsAtPos(r);if(!s||e.clientY<s.top||e.clientY>s.bottom||e.clientX<s.left-30||e.clientX>s.right+30)return null;e.clientX<s.left&&r>i.state.doc.lineAt(r).from&&(r-=1);const a=computePopoverHighlightRange(i.state,this.uiSourceCode.mimeType(),r);if(!a)return null;const c=i.state.doc.lineAt(a.from);if(a.to>c.to)return null;const l=i.editor.coordsAtPos(a.from),d=i.editor.coordsAtPos(a.to);if(!l||!d)return null;const u=new AnchorBox(l.left,l.top-2,d.right-l.left,d.bottom-l.top),p=i.state.sliceDoc(a.from,a.to);let g=null;return{box:u,show:async e=>{let t="";if(Root.Runtime.experiments.isEnabled("evaluateExpressionsWithSourceMaps")){const e=await SourceMapScopes.NamesResolver.allVariablesInCallFrame(n);try{t=await Formatter.FormatterWorkerPool.formatterWorkerPool().javaScriptSubstitute(p,e)}catch{}}else t=await SourceMapScopes.NamesResolver.resolveExpression(n,p,this.uiSourceCode,c.number-1,a.from-c.from,a.to-c.from);const r=Root.Runtime.experiments.isEnabled("evaluateExpressionsWithSourceMaps")&&a.containsCallExpression,s=await n.evaluate({expression:t||p,objectGroup:"popover",includeCommandLineAPI:!1,silent:!0,returnByValue:!1,generatePreview:!1,throwOnSideEffect:r,timeout:void 0,disableBreaks:void 0,replMode:void 0,allowUnsafeEvalBlockedByCSP:void 0});if(!s||"error"in s||!s.object||"object"===s.object.type&&"error"===s.object.subtype)return!1;g=await ObjectUI.ObjectPopoverHelper.ObjectPopoverHelper.buildObjectPopover(s.object,e);const l=UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame);if(!g||n!==l)return o.runtimeModel().releaseObjectGroup("popover"),g&&g.dispose(),!1;const d=CodeMirror.Decoration.set(evalExpressionMark.range(a.from,a.to));return i.dispatch({effects:evalExpression.update.of(d)}),!0},hide:()=>{g&&g.dispose(),o.runtimeModel().releaseObjectGroup("popover"),i.dispatch({effects:evalExpression.update.of(CodeMirror.Decoration.none)})}}}onEditorUpdate(e){if(!e.changes.empty)for(const t of this.breakpoints)t.position=e.changes.mapPos(t.position)}onWheel(e){this.executionLocation&&UI.KeyboardShortcut.KeyboardShortcut.eventHasCtrlEquivalentKey(e)&&e.preventDefault()}onKeyDown(e){const t=UI.KeyboardShortcut.KeyboardShortcut.eventHasCtrlEquivalentKey(e);return t||this.setControlDown(!1),e.key===Platform.KeyboardUtilities.ESCAPE_KEY&&this.popoverHelper&&this.popoverHelper.isPopoverVisible()?(this.popoverHelper.hidePopover(),e.consume(),!0):(t&&this.executionLocation&&this.setControlDown(!0),!1)}onMouseMove(e){this.executionLocation&&this.controlDown&&UI.KeyboardShortcut.KeyboardShortcut.eventHasCtrlEquivalentKey(e)&&(this.continueToLocations||this.showContinueToLocations())}onMouseDown(e){if(!this.executionLocation||!UI.KeyboardShortcut.KeyboardShortcut.eventHasCtrlEquivalentKey(e))return;if(!this.continueToLocations||!this.editor)return;e.consume();const t=this.editor.editor.posAtCoords(e);if(null!==t)for(const{from:e,to:o,click:i}of this.continueToLocations)if(e<=t&&o>=t){i();break}}onBlur(e){this.setControlDown(!1)}onKeyUp(e){this.setControlDown(!1)}setControlDown(e){e!==this.controlDown&&(this.controlDown=e,clearTimeout(this.controlTimeout),this.controlTimeout=void 0,e&&this.executionLocation?this.controlTimeout=window.setTimeout((()=>{this.executionLocation&&this.controlDown&&this.showContinueToLocations()}),150):this.clearContinueToLocations())}editBreakpointCondition(e){const{line:t,breakpoint:o,location:i,isLogpoint:n}=e;if(o?.isRemoved)return;this.#t=!1;if(this.#e&&function(e,t){if(e.line.number!==t.line.number)return!1;if(e.line.from!==t.line.from)return!1;if(e.line.text!==t.line.text)return!1;if(e.breakpoint!==t.breakpoint)return!1;if(e.location!==t.location)return!1;return e.isLogpoint===t.isLogpoint}(this.#e,e))return;this.activeBreakpointDialog&&this.activeBreakpointDialog.saveAndFinish();const r=this.editor,s=o?o.condition():"",a=o?.isLogpoint()??Boolean(n),c=document.createElement("div"),l=new CodeMirror.Compartment,d=new BreakpointEditDialog(t.number-1,s,a,(async e=>{this.activeBreakpointDialog=null,this.#e=void 0,d.detach(),r.dispatch({effects:l.reconfigure([])}),e.committed?(SourceComponents.BreakpointsView.BreakpointsSidebarController.instance().breakpointEditFinished(o,s!==e.condition),function(e){const{condition:t,isLogpoint:i}=e,n=0!==t.length&&!i,r=o?.isLogpoint(),a=s&&0!==s.length&&!r;i&&!r?Host.userMetrics.breakpointWithConditionAdded(0):n&&!a&&Host.userMetrics.breakpointWithConditionAdded(1)}(e),o?o.setCondition(e.condition,e.isLogpoint):i?await this.setBreakpoint(i.lineNumber,i.columnNumber,e.condition,!0,e.isLogpoint):await this.createNewBreakpoint(t,e.condition,!0,e.isLogpoint)):SourceComponents.BreakpointsView.BreakpointsSidebarController.instance().breakpointEditFinished(o,!1)}));r.dispatch({effects:CodeMirror.StateEffect.appendConfig.of(l.of(CodeMirror.EditorView.decorations.of(CodeMirror.Decoration.set([CodeMirror.Decoration.widget({block:!0,widget:new class extends CodeMirror.WidgetType{toDOM(){return c}},side:1}).range(t.to)]))))}),d.element.addEventListener("blur",(async e=>{(!e.relatedTarget||e.relatedTarget&&!e.relatedTarget.isSelfOrDescendant(d.element))&&(this.#t=!0,setTimeout((()=>{this.activeBreakpointDialog===d&&(this.#t?(d.saveAndFinish(),this.#t=!1):d.focusEditor())}),200))}),!0),d.markAsExternallyManaged(),d.show(c),d.focusEditor(),this.activeBreakpointDialog=d,this.#e=e}computeExecutionDecorations(e,t,o){const{doc:i}=e;if(t>=i.lines)return CodeMirror.Decoration.none;const n=i.line(t+1),r=[executionLineDeco.range(n.from)],s=Math.min(n.to,n.from+o);let a=CodeMirror.syntaxTree(e).resolveInner(s,1);a.to===a.from-1&&/[(.]/.test(i.sliceString(a.from,a.to))&&(a=a.resolve(a.to,1));const c=Math.min(n.to,a.to);return c>s&&r.push(executionTokenDeco.range(s,c)),CodeMirror.Decoration.set(r)}async updateValueDecorations(){if(!this.editor)return;const e=this.executionLocation?await this.computeValueDecorations():null;this.editor&&(e||this.editor.state.field(valueDecorations.field).size)&&this.editor.dispatch({effects:valueDecorations.update.of(e||CodeMirror.Decoration.none)})}async#n(e,t){const o=e&&await Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().rawLocationToUILocation(e);if(!o||o.uiSourceCode.url()!==t)return null;const i=this.editor?.toOffset(this.transformer.uiLocationToEditorLocation(o.lineNumber,o.columnNumber));return i??null}async computeValueDecorations(){if(!this.editor)return null;if(!Common.Settings.Settings.instance().moduleSetting("inlineVariableValues").get())return null;if(!UI.Context.Context.instance().flavor(SDK.RuntimeModel.ExecutionContext))return null;const e=UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame);if(!e)return null;const t=this.uiSourceCode.url(),o=this.#n(e.functionLocation(),t),i=this.#n(e.location(),t),[n,r]=await Promise.all([o,i]);if(!n||!r||!this.editor)return null;if(n>=r||r-n>1e4)return null;const s=getVariableNamesByLine(this.editor.state,n,r,r);if(0===s.length)return null;const a=await computeScopeMappings(e,(e=>this.#n(e,t)));if(0===a.length)return null;const c=getVariableValuesByLine(a,s);if(!c||!this.editor)return null;const l=[];for(const[e,t]of c){const o=c.get(e-1);let i=o?Array.from(t).filter((e=>o.get(e[0])!==e[1])):Array.from(t);i.length&&(i.length>10&&(i=i.slice(0,10)),l.push(CodeMirror.Decoration.widget({widget:new ValueDecoration(i),side:1}).range(this.editor.state.doc.line(e+1).to)))}return CodeMirror.Decoration.set(l,!0)}async showContinueToLocations(){this.popoverHelper?.hidePopover();if(!UI.Context.Context.instance().flavor(SDK.RuntimeModel.ExecutionContext)||!this.editor)return;const e=UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame);if(!e)return;const t=e.functionLocation()||e.location(),o=e.debuggerModel,{state:i}=this.editor,n=await o.getPossibleBreakpoints(t,null,!0);this.continueToLocations=[];let r=-1;for(const e of n.reverse()){const t=this.transformer.uiLocationToEditorLocation(e.lineNumber,e.columnNumber);if(r===t.lineNumber&&"call"!==e.type||t.lineNumber>=i.doc.lines)continue;const o=i.doc.line(t.lineNumber+1),n=Math.min(o.to,o.from+t.columnNumber);let s=CodeMirror.syntaxTree(i).resolveInner(n,1);if(s.firstChild||s.from<o.from||s.to>o.to)continue;if("."===s.name){const e=s.resolve(s.to,1);if(e.firstChild||e.from<o.from||e.to>o.to)continue;s=e}const a=s.name,c="this"===a||"return"===a||"new"===a||"break"===a||"continue"===a;if(!c&&!this.isIdentifier(a))continue;this.continueToLocations.push({from:s.from,to:s.to,async:!1,click:()=>e.continueToLocation()}),"call"===e.type&&(r=t.lineNumber);const l=c?"":o.text.slice(s.from-o.from,s.to-o.from);let d=null;if("then"===l&&"MemberExpression"===s.parent?.name?d=s.parent.parent:"setTimeout"!==l&&"setInterval"!==l&&"postMessage"!==l||(d=s.parent),"new"===a){const e=s.parent?.getChild("Expression");e&&"VariableName"===e.name&&"Worker"===i.sliceDoc(e.from,e.to)&&(d=s.parent)}if(d&&("CallExpression"===d.name||"NewExpression"===d.name)&&"call"===e.type){const t=d.getChild("ArgList")?.firstChild?.nextSibling;let o;if("VariableName"===t?.name?o=t:"ArrowFunction"!==t?.name&&"FunctionExpression"!==t?.name||(o=t.firstChild,"async"===o?.name&&(o=o.nextSibling)),o){const t=this.executionLocation&&e.lineNumber===this.executionLocation.lineNumber&&e.columnNumber===this.executionLocation.columnNumber;this.continueToLocations.push({from:o.from,to:o.to,async:!0,click:()=>this.asyncStepIn(e,Boolean(t))})}}}const s=CodeMirror.Decoration.set(this.continueToLocations.map((e=>(e.async?asyncContinueToMark:continueToMark).range(e.from,e.to))),!0);this.editor.dispatch({effects:continueToMarkers.update.of(s)})}clearContinueToLocations(){this.editor&&this.editor.state.field(continueToMarkers.field).size&&this.editor.dispatch({effects:continueToMarkers.update.of(CodeMirror.Decoration.none)})}asyncStepIn(e,t){function o(){e.debuggerModel.scheduleStepIntoAsync()}t?o():e.continueToLocation(o)}fetchBreakpoints(){if(!this.editor)return[];const{editor:e}=this;return this.breakpointManager.breakpointLocationsForUISourceCode(this.uiSourceCode).map((({uiLocation:t,breakpoint:o})=>{const i=this.transformer.uiLocationToEditorLocation(t.lineNumber,t.columnNumber);return{position:e.toOffset(i),breakpoint:o}}))}lineBreakpoints(e){return this.breakpoints.filter((t=>t.position>=e.from&&t.position<=e.to)).map((e=>e.breakpoint))}async computeBreakpointDecoration(e,t){const o=[],i=[],n=new Map,r=new Map,s=[],a=new Set,c=(e,t,o)=>{let i=r.get(e);i||(i=[],r.set(e,i)),i.push({breakpoint:o,column:t})};for(const{position:o,breakpoint:i}of t){const t=e.doc.lineAt(o);let r=n.get(t.from);if(r||(r=[],n.set(t.from,r)),i.enabled()&&r.every((e=>!e.enabled()))){const e=this.transformer.editorLocationToUILocation(t.number-1,0),o=this.transformer.editorLocationToUILocation(t.number-1,Math.min(t.length,2500)),i=new TextUtils.TextRange.TextRange(e.lineNumber,e.columnNumber||0,o.lineNumber,o.columnNumber||0);s.push(this.breakpointManager.possibleBreakpoints(this.uiSourceCode,i).then((e=>l(t,e))))}r.push(i),i.enabled()&&(a.add(o),c(t.from,o-t.from,i))}for(const[e,t]of n){const o=t.sort(mostSpecificBreakpoint)[0];let n="cm-breakpoint";o.enabled()||(n+=" cm-breakpoint-disabled"),o.bound()||(n+=" cm-breakpoint-unbound"),o.isLogpoint()?n+=" cm-breakpoint-logpoint":o.condition()&&(n+=" cm-breakpoint-conditional"),i.push(new BreakpointGutterMarker(n).range(e))}const l=(e,t)=>{for(const o of t){const t=this.transformer.uiLocationToEditorLocation(o.lineNumber,o.columnNumber);if(t.lineNumber!==e.number-1)continue;const i=Math.min(e.to,e.from+t.columnNumber);a.has(i)||c(e.from,t.columnNumber,null)}};await Promise.all(s);for(const[e,t]of r)if(t.length>1)for(const{column:i,breakpoint:n}of t){const t=new BreakpointInlineMarker(n,this);o.push(CodeMirror.Decoration.widget({widget:t,side:-1}).range(e+i))}return{content:CodeMirror.Decoration.set(o,!0),gutter:CodeMirror.RangeSet.of(i,!0)}}async restoreBreakpointsAfterEditing(){const{breakpoints:e}=this,t=this.editor;this.breakpoints=[],await Promise.all(e.map((async e=>{const{breakpoint:o,position:i}=e,n=o.condition(),r=o.enabled(),s=o.isLogpoint();await o.remove(!1);const a=t.toLineColumn(i),c=this.transformer.editorLocationToUILocation(a.lineNumber,a.columnNumber);await this.setBreakpoint(c.lineNumber,c.columnNumber,n,r,s)})))}async refreshBreakpoints(){if(this.editor){this.breakpoints=this.fetchBreakpoints();const e=this.breakpoints,t=await this.computeBreakpointDecoration(this.editor.state,e);this.editor&&this.breakpoints===e&&(t.gutter.size||this.editor.state.field(breakpointMarkers,!1)?.gutter.size)&&this.editor.dispatch({effects:setBreakpointDeco.of(t)})}}breakpointChange(e){const{uiLocation:t}=e.data;if(t.uiSourceCode===this.uiSourceCode&&!this.muted){for(const e of this.scriptFileForDebuggerModel.values())if(e.isDivergingFromVM()||e.isMergingToVM())return;window.clearTimeout(this.refreshBreakpointsTimeout),this.refreshBreakpointsTimeout=window.setTimeout((()=>this.refreshBreakpoints()),50)}}onInlineBreakpointMarkerClick(e,t){if(e.consume(!0),t)e.shiftKey?t.setEnabled(!t.enabled()):t.remove(!1);else if(this.editor){const t=this.editor.editor.posAtDOM(e.target),o=this.editor.state.doc.lineAt(t),i=this.transformer.editorLocationToUILocation(o.number-1,t-o.from);this.setBreakpoint(i.lineNumber,i.columnNumber,EMPTY_BREAKPOINT_CONDITION,!0,!1)}}onInlineBreakpointMarkerContextMenu(e,t){e.consume(!0);const o=this.editor,i=o.editor.posAtDOM(e.target),n=o.state.doc.lineAt(i);if(!SourceFrame.SourceFrame.isBreakableLine(o.state,n)||!Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().supportsConditionalBreakpoints(this.uiSourceCode))return;const r=new UI.ContextMenu.ContextMenu(e);if(t)r.debugSection().appendItem(i18nString(UIStrings.editBreakpoint),(()=>{Host.userMetrics.breakpointEditDialogRevealedFrom(2),this.editBreakpointCondition({line:n,breakpoint:t,location:null})}));else{const e=this.transformer.editorLocationToUILocation(n.number-1,i-n.from);r.debugSection().appendItem(i18nString(UIStrings.addConditionalBreakpoint),(()=>{Host.userMetrics.breakpointEditDialogRevealedFrom(2),this.editBreakpointCondition({line:n,breakpoint:null,location:e,isLogpoint:!1})})),r.debugSection().appendItem(i18nString(UIStrings.addLogpoint),(()=>{Host.userMetrics.breakpointEditDialogRevealedFrom(2),this.editBreakpointCondition({line:n,breakpoint:null,location:e,isLogpoint:!0})})),r.debugSection().appendItem(i18nString(UIStrings.neverPauseHere),(()=>this.setBreakpoint(e.lineNumber,e.columnNumber,NEVER_PAUSE_HERE_CONDITION,!0,!1)))}r.show()}updateScriptFiles(){for(const e of SDK.TargetManager.TargetManager.instance().models(SDK.DebuggerModel.DebuggerModel)){Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().scriptFile(this.uiSourceCode,e)&&this.updateScriptFile(e)}this.showSourceMapInfobarIfNeeded()}updateScriptFile(e){const t=this.scriptFileForDebuggerModel.get(e),o=Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().scriptFile(this.uiSourceCode,e);this.scriptFileForDebuggerModel.delete(e),t&&(t.removeEventListener("DidMergeToVM",this.didMergeToVM,this),t.removeEventListener("DidDivergeFromVM",this.didDivergeFromVM,this),this.muted&&!this.uiSourceCode.isDirty()&&this.consistentScripts()&&this.setMuted(!1)),o&&(this.scriptFileForDebuggerModel.set(e,o),o.addEventListener("DidMergeToVM",this.didMergeToVM,this),o.addEventListener("DidDivergeFromVM",this.didDivergeFromVM,this),o.checkMapping(),o.missingSymbolFiles().then((e=>{if(e){const t=i18nString(UIStrings.debugInfoNotFound,{PH1:o.uiSourceCode.url()});this.updateMissingDebugInfoInfobar({resources:e,details:t})}else this.updateMissingDebugInfoInfobar(null)})))}updateMissingDebugInfoInfobar(e){if(!this.missingDebugInfoBar){if(null===e)return this.removeInfobar(this.missingDebugInfoBar),void(this.missingDebugInfoBar=null);if(this.missingDebugInfoBar=UI.Infobar.Infobar.create(UI.Infobar.Type.Error,e.details,[]),this.missingDebugInfoBar){for(const t of e.resources){const e=this.missingDebugInfoBar?.createDetailsRowMessage(i18nString(UIStrings.debugFileNotFound,{PH1:t}));e&&e.classList.add("infobar-selectable")}this.missingDebugInfoBar.setCloseCallback((()=>{this.removeInfobar(this.missingDebugInfoBar),this.missingDebugInfoBar=null})),this.attachInfobar(this.missingDebugInfoBar)}}}scriptHasSourceMap(){for(const e of SDK.TargetManager.TargetManager.instance().models(SDK.DebuggerModel.DebuggerModel)){const t=Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().scriptFile(this.uiSourceCode,e);if(t&&t.hasSourceMapURL())return!0}return!1}getSourceMapResource(){const e=this.loader.getResourcesLoaded();for(const[t,o]of this.scriptFileForDebuggerModel.entries()){const i=o.script?.sourceMapURL;if(i){const n=SDK.SourceMapManager.SourceMapManager.resolveRelativeSourceURL(t.target(),o.script.sourceURL),r=Common.ParsedURL.ParsedURL.completeURL(n,i);if(r){const t=e.get(SDK.PageResourceLoader.PageResourceLoader.makeKey(r,o.script.createPageResourceLoadInitiator()));if(t)return t}}}return null}showSourceMapInfobarIfNeeded(){if(this.sourceMapInfobar)return;if(!Common.Settings.Settings.instance().moduleSetting("jsSourceMapsEnabled").get())return;if(!this.scriptHasSourceMap())return;const e=this.getSourceMapResource();if(!e||null!==e.success){if(e)if(e.success){if(this.sourceMapInfobar=UI.Infobar.Infobar.create(UI.Infobar.Type.Info,i18nString(UIStrings.sourceMapLoaded),[],Common.Settings.Settings.instance().createSetting("sourceMapInfobarDisabled",!1)),!this.sourceMapInfobar)return;this.sourceMapInfobar.createDetailsRowMessage(i18nString(UIStrings.associatedFilesShouldBeAdded)),this.sourceMapInfobar.createDetailsRowMessage(i18nString(UIStrings.associatedFilesAreAvailable,{PH1:String(UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction("quickOpen.show"))}))}else{let t,o;const i=Bindings.IgnoreListManager.IgnoreListManager.instance();if(this.uiSourceCode.project().type()===Workspace.Workspace.projectTypes.ContentScripts?(t=i18nString(UIStrings.ignoreContentScripts),o=i.ignoreListContentScripts.bind(i)):(t=i18nString(UIStrings.ignoreScript),o=i.ignoreListUISourceCode.bind(i,this.uiSourceCode)),this.sourceMapInfobar=UI.Infobar.Infobar.create(UI.Infobar.Type.Warning,i18nString(UIStrings.sourceMapFailed),[{text:t,highlight:!1,delegate:o,dismiss:!0}]),!this.sourceMapInfobar)return;this.sourceMapInfobar.createDetailsRowMessage(i18nString(UIStrings.debuggingPowerReduced)),e.errorMessage&&this.sourceMapInfobar.createDetailsRowMessage(i18nString(UIStrings.errorLoading,{PH1:Platform.StringUtilities.trimMiddle(e.url,UI.UIUtils.MaxLengthForDisplayedURLs),PH2:e.errorMessage}))}else{if(this.sourceMapInfobar=UI.Infobar.Infobar.create(UI.Infobar.Type.Info,i18nString(UIStrings.sourceMapSkipped),[],Common.Settings.Settings.instance().createSetting("sourceMapSkippedInfobarDisabled",!1)),!this.sourceMapInfobar)return;this.sourceMapInfobar.createDetailsRowMessage(i18nString(UIStrings.debuggingPowerReduced)),this.sourceMapInfobar.createDetailsRowMessage(i18nString(UIStrings.reloadForSourceMap))}this.sourceMapInfobar.setCloseCallback((()=>{this.removeInfobar(this.sourceMapInfobar),this.sourceMapInfobar=null})),this.attachInfobar(this.sourceMapInfobar)}}handleGutterClick(e,t){return!this.muted&&0===t.button&&!t.altKey&&(t.metaKey||t.ctrlKey?!t.shiftKey&&(Host.userMetrics.breakpointEditDialogRevealedFrom(6),this.#i(e),!0):(this.toggleBreakpoint(e,t.shiftKey),!0))}async toggleBreakpoint(e,t){if(this.muted)return;this.activeBreakpointDialog&&this.activeBreakpointDialog.finishEditing(!1,"");const o=this.lineBreakpoints(e);if(!o.length)return void await this.createNewBreakpoint(e,EMPTY_BREAKPOINT_CONDITION,!0,!1);const i=o.some((e=>!e.enabled()));for(const e of o)t?e.setEnabled(i):(Host.userMetrics.actionTaken(Host.UserMetrics.Action.BreakpointRemovedFromGutterToggle),e.remove(!1))}async createNewBreakpoint(e,t,o,i){if(!this.editor||!SourceFrame.SourceFrame.isBreakableLine(this.editor.state,e))return;Host.userMetrics.actionTaken(Host.UserMetrics.Action.ScriptsBreakpointSet),this.#r();const n=this.transformer.editorLocationToUILocation(e.number-1);await this.setBreakpoint(n.lineNumber,n.columnNumber,t,o,i)}async setBreakpoint(e,t,o,i,n){Common.Settings.Settings.instance().moduleSetting("breakpointsActive").set(!0);const r=await this.breakpointManager.setBreakpoint(this.uiSourceCode,e,t,o,i,n,"USER_ACTION");return this.breakpointWasSetForTest(e,t,o,i),r}breakpointWasSetForTest(e,t,o,i){}async callFrameChanged(){this.liveLocationPool.disposeAll();const e=UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame);e?await Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createCallFrameLiveLocation(e.location(),(async t=>{const o=await t.uiLocation();o&&o.uiSourceCode===this.uiSourceCode?(this.setExecutionLocation(o),this.updateMissingDebugInfoInfobar(e.missingDebugInfoDetails),this.#r()):this.setExecutionLocation(null)}),this.liveLocationPool):this.setExecutionLocation(null)}setExecutionLocation(e){if(this.executionLocation!==e&&this.editor)if(this.executionLocation=e,e){const t=this.transformer.uiLocationToEditorLocation(e.lineNumber,e.columnNumber),o=this.computeExecutionDecorations(this.editor.state,t.lineNumber,t.columnNumber);this.editor.dispatch({effects:executionLine.update.of(o)}),this.updateValueDecorations(),this.controlDown&&this.showContinueToLocations()}else this.editor.dispatch({effects:[executionLine.update.of(CodeMirror.Decoration.none),continueToMarkers.update.of(CodeMirror.Decoration.none),valueDecorations.update.of(CodeMirror.Decoration.none)]})}dispose(){this.hideIgnoreListInfobar(),this.sourceMapInfobar&&this.sourceMapInfobar.dispose();for(const e of this.scriptFileForDebuggerModel.values())e.removeEventListener("DidMergeToVM",this.didMergeToVM,this),e.removeEventListener("DidDivergeFromVM",this.didDivergeFromVM,this);this.scriptFileForDebuggerModel.clear(),this.popoverHelper?.hidePopover(),this.popoverHelper?.dispose(),this.setExecutionLocation(null),this.breakpointManager.removeEventListener(Breakpoints.BreakpointManager.Events.BreakpointAdded,this.breakpointChange,this),this.breakpointManager.removeEventListener(Breakpoints.BreakpointManager.Events.BreakpointRemoved,this.breakpointChange,this),this.uiSourceCode.removeEventListener(Workspace.UISourceCode.Events.WorkingCopyChanged,this.workingCopyChanged,this),this.uiSourceCode.removeEventListener(Workspace.UISourceCode.Events.WorkingCopyCommitted,this.workingCopyCommitted,this),Bindings.IgnoreListManager.IgnoreListManager.instance().removeChangeListener(this.ignoreListCallback),debuggerPluginForUISourceCode.delete(this.uiSourceCode),super.dispose(),window.clearTimeout(this.refreshBreakpointsTimeout),this.editor=void 0,UI.Context.Context.instance().removeFlavorChangeListener(SDK.DebuggerModel.CallFrame,this.callFrameChanged,this),this.liveLocationPool.disposeAll()}#r(){if(this.#o)return;this.#o=!0;const e=Common.ResourceType.ResourceType.mimeFromURL(this.uiSourceCode.url()),t=Common.ResourceType.ResourceType.mediaTypeForMetrics(e??"",this.uiSourceCode.contentType().isFromSourceMap(),TextUtils.TextUtils.isMinified(this.uiSourceCode.content()));Host.userMetrics.sourcesPanelFileDebugged(t)}}let breakpointLocationRevealerInstance;export class BreakpointLocationRevealer{static instance({forceNew:e}={forceNew:!1}){return breakpointLocationRevealerInstance&&!e||(breakpointLocationRevealerInstance=new BreakpointLocationRevealer),breakpointLocationRevealerInstance}async reveal(e,t){if(!(e instanceof Breakpoints.BreakpointManager.BreakpointLocation))throw new Error("Internal error: not a breakpoint location");const{uiLocation:o}=e;SourcesPanel.instance().showUILocation(o,t);const i=debuggerPluginForUISourceCode.get(o.uiSourceCode);i?i.editBreakpointLocation(e):SourceComponents.BreakpointsView.BreakpointsSidebarController.instance().breakpointEditFinished(e.breakpoint,!1)}}const addInfobar=CodeMirror.StateEffect.define(),removeInfobar=CodeMirror.StateEffect.define(),infobarState=CodeMirror.StateField.define({create:()=>[],update(e,t){for(const o of t.effects)o.is(addInfobar)?e=e.concat(o.value):o.is(removeInfobar)&&(e=e.filter((e=>e!==o.value)));return e},provide:e=>CodeMirror.showPanel.computeN([e],(t=>t.field(e).map((e=>()=>({dom:e.element})))))});async function computeNonBreakableLines(e,t,o){const i=Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(),n=await i.getMappedLines(o);if(!n)return[];const r=[];for(let o=0;o<e.doc.lines;o++){const{lineNumber:i}=t.editorLocationToUILocation(o,0);n.has(i)||r.push(e.doc.line(o+1).from)}return r}const setBreakpointDeco=CodeMirror.StateEffect.define(),muteBreakpoints=CodeMirror.StateEffect.define();function muteGutterMarkers(e,t){const o=[];return e.between(0,t.length,((e,t,i)=>{let n=i.elementClass;/cm-breakpoint-disabled/.test(n)||(n+=" cm-breakpoint-disabled"),o.push(new BreakpointGutterMarker(n).range(e))})),CodeMirror.RangeSet.of(o,!1)}const breakpointMarkers=CodeMirror.StateField.define({create:()=>({content:CodeMirror.RangeSet.empty,gutter:CodeMirror.RangeSet.empty}),update(e,t){t.changes.empty||(e={content:e.content.map(t.changes),gutter:e.gutter.map(t.changes)});for(const o of t.effects)o.is(setBreakpointDeco)?e=o.value:o.is(muteBreakpoints)&&(e={content:CodeMirror.RangeSet.empty,gutter:muteGutterMarkers(e.gutter,t.state.doc)});return e},provide:e=>[CodeMirror.EditorView.decorations.from(e,(e=>e.content)),CodeMirror.lineNumberMarkers.from(e,(e=>e.gutter))]});class BreakpointInlineMarker extends CodeMirror.WidgetType{breakpoint;parent;class;constructor(e,t){super(),this.breakpoint=e,this.parent=t,this.class="cm-inlineBreakpoint",e?.isLogpoint()?this.class+=" cm-inlineBreakpoint-logpoint":e?.condition()&&(this.class+=" cm-inlineBreakpoint-conditional"),e?.enabled()||(this.class+=" cm-inlineBreakpoint-disabled")}eq(e){return e.class===this.class&&e.breakpoint===this.breakpoint}toDOM(){const e=document.createElement("span");return e.className=this.class,e.addEventListener("click",(e=>{this.parent.onInlineBreakpointMarkerClick(e,this.breakpoint),e.consume()})),e.addEventListener("contextmenu",(e=>{this.parent.onInlineBreakpointMarkerContextMenu(e,this.breakpoint),e.consume()})),e}ignoreEvent(){return!0}}class BreakpointGutterMarker extends CodeMirror.GutterMarker{elementClass;constructor(e){super(),this.elementClass=e}eq(e){return e.elementClass===this.elementClass}}function mostSpecificBreakpoint(e,t){return e.enabled()!==t.enabled()?e.enabled()?-1:1:e.bound()!==t.bound()?e.bound()?-1:1:Boolean(e.condition())!==Boolean(t.condition())?Boolean(e.condition())?-1:1:0}function defineStatefulDecoration(){const e=CodeMirror.StateEffect.define(),t=CodeMirror.StateField.define({create:()=>CodeMirror.Decoration.none,update:(t,o)=>o.effects.reduce(((t,o)=>o.is(e)?o.value:t),t.map(o.changes)),provide:e=>CodeMirror.EditorView.decorations.from(e)});return{update:e,field:t}}const executionLineDeco=CodeMirror.Decoration.line({attributes:{class:"cm-executionLine"}}),executionTokenDeco=CodeMirror.Decoration.mark({attributes:{class:"cm-executionToken"}}),executionLine=defineStatefulDecoration(),continueToMark=CodeMirror.Decoration.mark({class:"cm-continueToLocation"}),asyncContinueToMark=CodeMirror.Decoration.mark({class:"cm-continueToLocation cm-continueToLocation-async"}),continueToMarkers=defineStatefulDecoration(),noMarkers={},hasContinueMarkers={class:"cm-hasContinueMarkers"},markIfContinueTo=CodeMirror.EditorView.contentAttributes.compute([continueToMarkers.field],(e=>e.field(continueToMarkers.field).size?hasContinueMarkers:noMarkers));class ValueDecoration extends CodeMirror.WidgetType{pairs;constructor(e){super(),this.pairs=e}eq(e){return this.pairs.length===e.pairs.length&&this.pairs.every(((t,o)=>t[0]===e.pairs[o][0]&&t[1]===e.pairs[o][1]))}toDOM(){const e=new ObjectUI.RemoteObjectPreviewFormatter.RemoteObjectPreviewFormatter,t=document.createElement("div");t.classList.add("cm-variableValues");let o=!0;for(const[i,n]of this.pairs){o?o=!1:UI.UIUtils.createTextChild(t,", ");const r=t.createChild("span");UI.UIUtils.createTextChild(r,i+" = ");const s=n.preview?n.preview.properties.length:0,a=n.preview&&n.preview.entries?n.preview.entries.length:0;if(n.preview&&s+a<10)e.appendObjectPreview(r,n.preview,!1);else{const e=ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.createPropertyValue(n,!1,!1);r.appendChild(e.element)}}return t}}const valueDecorations=defineStatefulDecoration();function isVariableIdentifier(e){return"VariableName"===e||"VariableDefinition"===e}function isVariableDefinition(e){return"VariableDefinition"===e}function isLetConstDefinition(e){return"let"===e||"const"===e}function isScopeNode(e){return"Block"===e||"ForSpec"===e}class SiblingScopeVariables{blockList=new Set;variables=[]}export function getVariableNamesByLine(e,t,o,i){const n=e.doc.lineAt(t);t=Math.min(n.to,t),o=e.doc.lineAt(o).from;const r=CodeMirror.ensureSyntaxTree(e,o,100);if(!r)return[];function s(e){return isScopeNode(e.name)&&(e.to<i||i<e.from)}const a=[];let c=n;const l=[];let d=null;function u(){return l.length?l[l.length-1].variables:a}return r.iterate({from:t,to:o,enter:o=>{if(o.from<t)return;if(isLetConstDefinition(o.name))return void(d=o.node.nextSibling);if(s(o))return void l.push(new SiblingScopeVariables);const i=isVariableIdentifier(o.name)&&e.sliceDoc(o.from,o.to);i&&(d&&isVariableDefinition(o.name)&&l.length>0?l[l.length-1].blockList.add(i):(o.from>c.to&&(c=e.doc.lineAt(o.from)),u().push({line:c.number-1,from:o.from,id:i})))},leave:e=>{if(d===e.node)d=null;else if(s(e)){const e=l.pop(),t=u();for(const o of e?.variables??[])e?.blockList.has(o.id)||t.push(o)}}}),a}export async function computeScopeMappings(e,t){const o=[];for(const i of e.scopeChain()){const e=await t(i.range()?.start??null);if(!e)break;const n=await t(i.range()?.end??null);if(!n)break;const{properties:r}=await SourceMapScopes.NamesResolver.resolveScopeInObject(i).getAllProperties(!1,!1);if(!r||r.length>500)break;const s=new Map(r.map((e=>[e.name,e.value])));if(o.push({scopeStart:e,scopeEnd:n,variableMap:s}),"local"===i.type())break}return o}export function getVariableValuesByLine(e,t){const o=new Map;for(const{line:n,from:r,id:s}of t){const t=i(s,r,e);if(!t)continue;let a=o.get(n);a||(a=new Map,o.set(n,a)),a.set(s,t)}return o;function i(e,t,o){for(const i of o){if(t<i.scopeStart||t>=i.scopeEnd)continue;const o=i.variableMap.get(e);if(o)return o}return null}}export function computePopoverHighlightRange(e,t,o){const{main:i}=e.selection;if(!i.empty)return o<i.from||i.to<o?null:{from:i.from,to:i.to,containsCallExpression:!1};const n=CodeMirror.ensureSyntaxTree(e,o,5e3);if(!n)return null;const r=n.resolveInner(o,1);if(r.firstChild)return null;switch(t){case"application/wasm":{if("Identifier"!==r.name)return null;const t=["block","loop","if","else","end","br","br_if","br_table"];for(let o=r.parent;o;o=o.parent)if("App"===o.name){const i=o.firstChild,n="Keyword"===i?.name&&e.sliceDoc(i.from,i.to);if(n&&t.includes(n))return null}return{from:r.from,to:r.to,containsCallExpression:!1}}case"text/html":case"text/javascript":case"text/jsx":case"text/typescript":case"text/typescript-jsx":{let e=r;for(;e&&"this"!==e.name&&"VariableDefinition"!==e.name&&"VariableName"!==e.name&&"MemberExpression"!==e.name&&("PropertyName"!==e.name||"PatternProperty"!==e.parent?.name||":"===e.nextSibling?.name)&&("PropertyDefinition"!==e.name||"Property"!==e.parent?.name||":"===e.nextSibling?.name);)e=e.parent;return e?{from:e.from,to:e.to,containsCallExpression:nodeContainsCallExpression(e)}:null}default:return r.to-r.from>50||/[^\w_\-$]/.test(e.sliceDoc(r.from,r.to))?null:{from:r.from,to:r.to,containsCallExpression:!1}}}function nodeContainsCallExpression(e){let t=!1;return e.cursor().iterate((e=>(t||="CallExpression"===e.name,!t))),t}const evalExpressionMark=CodeMirror.Decoration.mark({class:"cm-evaluatedExpression"}),evalExpression=defineStatefulDecoration(),theme=CodeMirror.EditorView.baseTheme({".cm-gutters .cm-gutter.cm-lineNumbers .cm-gutterElement":{"&:hover, &.cm-breakpoint":{borderStyle:"solid",borderWidth:"1px 4px 1px 1px",marginRight:"-4px",paddingLeft:"8px",lineHeight:"calc(1.2em - 2px)",position:"relative"},"&:hover":{WebkitBorderImage:lineNumberArrow("#ebeced","#ebeced")},"&.cm-breakpoint":{color:"#fff",WebkitBorderImage:lineNumberArrow("#4285f4","#1a73e8")},"&.cm-breakpoint-conditional":{WebkitBorderImage:lineNumberArrow("#f29900","#e37400"),"&::before":{content:'"?"',position:"absolute",top:0,left:"1px"}},"&.cm-breakpoint-logpoint":{WebkitBorderImage:lineNumberArrow("#f439a0","#d01884"),"&::before":{content:'"‥"',position:"absolute",top:"-3px",left:"1px"}}},"&dark .cm-gutters .cm-gutter.cm-lineNumbers .cm-gutterElement":{"&:hover":{WebkitBorderImage:lineNumberArrow("#3c4043","#3c4043")},"&.cm-breakpoint":{WebkitBorderImage:lineNumberArrow("#5186EC","#1a73e8")},"&.cm-breakpoint-conditional":{WebkitBorderImage:lineNumberArrow("#e9a33a","#e37400")},"&.cm-breakpoint-logpoint":{WebkitBorderImage:lineNumberArrow("#E54D9B","#d01884")}},":host-context(.breakpoints-deactivated) & .cm-gutters .cm-gutter.cm-lineNumbers .cm-gutterElement.cm-breakpoint, .cm-gutters .cm-gutter.cm-lineNumbers .cm-gutterElement.cm-breakpoint-disabled":{color:"#1a73e8",WebkitBorderImage:lineNumberArrow("#d9e7fd","#1a73e8"),"&.cm-breakpoint-conditional":{color:"#e37400",WebkitBorderImage:lineNumberArrow("#fcebcc","#e37400")},"&.cm-breakpoint-logpoint":{color:"#d01884",WebkitBorderImage:lineNumberArrow("#fdd7ec","#f439a0")}},":host-context(.breakpoints-deactivated) &dark .cm-gutters .cm-gutter.cm-lineNumbers .cm-gutterElement.cm-breakpoint, &dark .cm-gutters .cm-gutter.cm-lineNumbers .cm-gutterElement.cm-breakpoint-disabled":{WebkitBorderImage:lineNumberArrow("#2a384e","#1a73e8"),"&.cm-breakpoint-conditional":{WebkitBorderImage:lineNumberArrow("#4d3c1d","#e37400")},"&.cm-breakpoint-logpoint":{WebkitBorderImage:lineNumberArrow("#4e283d","#f439a0")}},".cm-inlineBreakpoint":{cursor:"pointer",position:"relative",top:"1px",content:inlineBreakpointArrow("#4285F4","#1A73E8"),height:"10px","&.cm-inlineBreakpoint-conditional":{content:inlineConditionalBreakpointArrow("#F29900","#E37400")},"&.cm-inlineBreakpoint-logpoint":{content:inlineLogpointArrow("#F439A0","#D01884")}},"&dark .cm-inlineBreakpoint":{content:inlineBreakpointArrow("#5186EC","#1A73E8"),"&.cm-inlineBreakpoint-conditional":{content:inlineConditionalBreakpointArrow("#e9a33a","#E37400")},"&.cm-inlineBreakpoint-logpoint":{content:inlineLogpointArrow("#E54D9B","#D01884")}},":host-context(.breakpoints-deactivated) & .cm-inlineBreakpoint, .cm-inlineBreakpoint-disabled":{content:inlineBreakpointArrow("#4285F4","#1A73E8","0.2"),"&.cm-inlineBreakpoint-conditional":{content:inlineConditionalBreakpointArrow("#F9AB00","#E37400","0.2")},"&.cm-inlineBreakpoint-logpoint":{content:inlineLogpointArrow("#F439A0","#D01884","0.2")}},".cm-executionLine":{backgroundColor:"var(--color-execution-line-background)",outline:"1px solid var(--color-execution-line-outline)",".cm-hasContinueMarkers &":{backgroundColor:"transparent"},"&.cm-highlightedLine":{animation:"cm-fading-highlight-execution 2s 0s"}},".cm-executionToken":{backgroundColor:"var(--color-execution-token-background)"},"@keyframes cm-fading-highlight-execution":{from:{backgroundColor:"var(--color-highlighted-line)"},to:{backgroundColor:"var(--color-execution-line-background)"}},".cm-continueToLocation":{cursor:"pointer",backgroundColor:"var(--color-continue-to-location)","&:hover":{backgroundColor:"var(--color-continue-to-location-hover)",border:"1px solid var(--color-continue-to-location-hover-border)",margin:"0 -1px"},"&.cm-continueToLocation-async":{backgroundColor:"var(--color-continue-to-location-async)","&:hover":{backgroundColor:"var(--color-continue-to-location-async-hover)",border:"1px solid var(--color-continue-to-location-async-hover-border)",margin:"0 -1px"}}},".cm-evaluatedExpression":{backgroundColor:"var(--color-evaluated-expression)",border:"1px solid var(--color-evaluated-expression-border)",margin:"0 -1px"},".cm-variableValues":{display:"inline",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"1000px",opacity:"80%",backgroundColor:"var(--color-variable-values)",marginLeft:"10px",padding:"0 5px",userSelect:"text",".cm-executionLine &":{backgroundColor:"transparent",opacity:"50%"}}});function lineNumberArrow(e,t){return`url('data:image/svg+xml,<svg height="11" width="26" xmlns="http://www.w3.org/2000/svg"><path d="M22.8.5l2.7 5-2.7 5H.5V.5z" fill="${encodeURIComponent(e)}" stroke="${encodeURIComponent(t)}"