-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbindings2.js
More file actions
2 lines (2 loc) · 85.1 KB
/
bindings2.js
File metadata and controls
2 lines (2 loc) · 85.1 KB
1
2
import*as e from"../../core/common/common.js";import*as t from"../../core/platform/platform.js";import{assertNotNullOrUndefined as o}from"../../core/platform/platform.js";import*as r from"../../core/sdk/sdk.js";import"../stack_trace/stack_trace.js";import*as s from"../text_utils/text_utils.js";import*as n from"../workspace/workspace.js";import*as i from"../../core/i18n/i18n.js";import*as a from"../../core/root/root.js";class c extends e.ObjectWrapper.ObjectWrapper{syncFragment;asyncFragments;constructor(e,t){super(),this.syncFragment=e,this.asyncFragments=t,e.stackTraces.add(this),this.asyncFragments.forEach(e=>e.fragment.stackTraces.add(this))}}class u{node;stackTraces=new Set;static getOrCreate(e){return e.fragment||(e.fragment=new u(e)),e.fragment}constructor(e){this.node=e}get frames(){const e=[];for(const t of this.node.getCallStack())e.push(...t.frames);return e}}class l{description;fragment;constructor(e,t){this.description=e,this.fragment=t}get frames(){return this.fragment.frames}}class d{url;uiSourceCode;name;line;column;missingDebugInfo;constructor(e,t,o,r,s,n){this.url=e,this.uiSourceCode=t,this.name=o,this.line=r,this.column=s,this.missingDebugInfo=n}}Object.freeze({__proto__:null,AsyncFragmentImpl:l,FragmentImpl:u,FrameImpl:d,StackTraceImpl:c});class p{parent;children=[];rawFrame;frames=[];fragment;constructor(e,t){this.rawFrame=e,this.parent=t}*getCallStack(){for(let e=this;e.parent;e=e.parent)yield e}}class g{#e={parent:null,children:[]};insert(e){if(0===e.length)throw new Error("Trie.insert called with an empty frames array.");let t=this.#e;for(let o=e.length-1;o>=0;--o)t=this.#t(t,e[o]);return t}#t(e,t){let o=0;for(;o<e.children.length;++o){const r=e.children[o],s=r instanceof WeakRef?r.deref():r;if(!s)continue;const n=h(s.rawFrame,t);if(0===n)return s;if(n>0)break}const r=new p(t,e);return e.parent?e.children.splice(o,0,r):e.children.splice(o,0,new WeakRef(r)),r}walk(e,t){const o=e?[e]:[...this.#e.children].map(e=>e.deref()).filter(e=>Boolean(e));for(let e=o.pop();e;e=o.pop())if(t(e))for(let t=e.children.length-1;t>=0;--t)o.push(e.children[t])}}function h(e,t){const o=(e.scriptId??"").localeCompare(t.scriptId??"");if(0!==o)return o;const r=(e.url??"").localeCompare(t.url??"");if(0!==r)return r;const s=(e.functionName??"").localeCompare(t.functionName??"");return 0!==s?s:e.lineNumber!==t.lineNumber?e.lineNumber-t.lineNumber:e.columnNumber-t.columnNumber}var m=Object.freeze({__proto__:null,FrameNode:p,Trie:g,compareRawFrames:h,isBuiltinFrame:function(e){return-1===e.lineNumber&&-1===e.columnNumber&&!Boolean(e.scriptId)&&!Boolean(e.url)}});class S extends r.SDKModel.SDKModel{#o=new g;static#r(e){const t=(e??r.TargetManager.TargetManager.instance().primaryPageTarget())?.model(S);if(!t)throw new Error("Unable to find StackTraceModel");return t}async createFromProtocolRuntime(e,t){const o=[],s=this.#s(e.callFrames);o.push(this.#n(s,t));const n=[],i=this.target().model(r.DebuggerModel.DebuggerModel);if(i)for await(const{stackTrace:r,target:s}of i.iterateAsyncParents(e)){const e=S.#r(s),i=e.#s(r.callFrames);o.push(e.#n(i,t)),n.push(new l(r.description??"",i))}return await Promise.all(o),new c(s,n)}async scriptInfoChanged(e,t){const o=[];let r=new Set;for(const s of this.#i(e))0===s.node.children.length&&o.push(this.#n(s,t)),r=r.union(s.stackTraces);await Promise.all(o);for(const e of r)e.dispatchEventToListeners("UPDATED")}#s(e){return u.getOrCreate(this.#o.insert(e))}async#n(e,t){const o=e.node.getCallStack().map(e=>e.rawFrame).toArray(),r=await t(o,this.target());console.assert(o.length===r.length,"Broken rawFramesToUIFrames implementation");let s=0;for(const t of e.node.getCallStack())t.frames=r[s++].map(e=>new d(e.url,e.uiSourceCode,e.name,e.line,e.column,e.missingDebugInfo))}#i(e){const t=new Set;this.#o.walk(null,o=>!(o.rawFrame.scriptId===e.scriptId||!o.rawFrame.scriptId&&o.rawFrame.url===e.sourceURL)||(t.add(o),!1));const o=new Set;for(const e of t)this.#o.walk(e,e=>(e.fragment&&o.add(e.fragment),!0));return o}}r.SDKModel.SDKModel.register(S,{capabilities:0,autostart:!1});var f=Object.freeze({__proto__:null,StackTraceModel:S});const M={unknownErrorLoadingFile:"Unknown error loading file"},b=i.i18n.registerUIStrings("models/bindings/ContentProviderBasedProject.ts",M),L=i.i18n.getLocalizedString.bind(void 0,b);class C extends n.Workspace.ProjectStore{#a;#c=new WeakMap;constructor(e,t,o,r,s){super(e,t,o,r),this.#a=s,e.addProject(this)}async requestFileContent(e){const{contentProvider:t}=this.#c.get(e);try{return await t.requestContentData()}catch(e){return{error:e?String(e):L(M.unknownErrorLoadingFile)}}}isServiceProject(){return this.#a}async requestMetadata(e){const{metadata:t}=this.#c.get(e);return t}canSetFileContent(){return!1}async setFileContent(e,t,o){}fullDisplayName(e){let t=e.parentURL().replace(/^(?:https?|file)\:\/\//,"");try{t=decodeURI(t)}catch{}return t+"/"+e.displayName(!0)}mimeType(e){const{mimeType:t}=this.#c.get(e);return t}canRename(){return!1}rename(e,t,o){o(!1)}excludeFolder(e){}canExcludeFolder(e){return!1}async createFile(e,t,o,r){return null}canCreateFile(){return!1}deleteFile(e){}remove(){}searchInFileContent(e,t,o,r){const{contentProvider:s}=this.#c.get(e);return s.searchInContent(t,o,r)}async findFilesMatchingSearchRequest(e,o,r){const n=new Map;return r.totalWork=o.length,await Promise.all(o.map(async function(o){let i=!0,a=[];for(const r of e.queries().slice()){const n=await this.searchInFileContent(o,r,!e.ignoreCase(),e.isRegex());if(!n.length){i=!1;break}a=t.ArrayUtilities.mergeOrdered(a,n,s.ContentProvider.SearchMatch.comparator)}i&&n.set(o,a);++r.worked}.bind(this))),r.done=!0,n}indexContent(e){queueMicrotask(()=>{e.done=!0})}addUISourceCodeWithProvider(e,t,o,r){this.#c.set(e,{mimeType:r,metadata:o,contentProvider:t}),this.addUISourceCode(e)}addContentProvider(e,t,o){const r=this.createUISourceCode(e,t.contentType());return this.addUISourceCodeWithProvider(r,t,null,o),r}reset(){this.removeProject(),this.workspace().addProject(this)}dispose(){this.removeProject()}}var w=Object.freeze({__proto__:null,ContentProviderBasedProject:C});const v=new WeakMap,R=new WeakMap;let I;class T extends e.ObjectWrapper.ObjectWrapper{constructor(){super()}static instance({forceNew:e}={forceNew:!1}){return I&&!e||(I=new T),I}}class y{static resolveFrame(e,t){const o=y.targetForUISourceCode(e),s=o?.model(r.ResourceTreeModel.ResourceTreeModel);return s?s.frameForId(t):null}static setInitialFrameAttribution(e,t){if(!t)return;const o=y.resolveFrame(e,t);if(!o)return;const r=new Map;r.set(t,{frame:o,count:1}),v.set(e,r)}static cloneInitialFrameAttribution(e,t){const o=v.get(e);if(!o)return;const r=new Map;for(const e of o.keys()){const t=o.get(e);void 0!==t&&r.set(e,{frame:t.frame,count:t.count})}v.set(t,r)}static addFrameAttribution(e,t){const o=y.resolveFrame(e,t);if(!o)return;const r=v.get(e);if(!r)return;const s=r.get(t)||{frame:o,count:0};if(s.count+=1,r.set(t,s),1!==s.count)return;const n={uiSourceCode:e,frame:o};T.instance().dispatchEventToListeners("FrameAttributionAdded",n)}static removeFrameAttribution(e,t){const o=v.get(e);if(!o)return;const r=o.get(t);if(console.assert(Boolean(r),"Failed to remove frame attribution for url: "+e.url()),!r)return;if(r.count-=1,r.count>0)return;o.delete(t);const s={uiSourceCode:e,frame:r.frame};T.instance().dispatchEventToListeners("FrameAttributionRemoved",s)}static targetForUISourceCode(e){return R.get(e.project())||null}static setTargetForProject(e,t){R.set(e,t)}static getTargetForProject(e){return R.get(e)||null}static framesForUISourceCode(e){const t=y.targetForUISourceCode(e),o=t?.model(r.ResourceTreeModel.ResourceTreeModel),s=v.get(e);if(!o||!s)return[];return Array.from(s.keys()).map(e=>o.frameForId(e)).filter(e=>!!e)}}var F=Object.freeze({__proto__:null,NetworkProject:y,NetworkProjectManager:T});const U={};let P=class{#u;#l;#d=new Map;#p;#g;#h=new Map;#m=new Map;#S=new t.MapUtilities.Multimap;#f;constructor(e,t,o){this.#u=e.sourceMapManager(),this.#l=o,this.#f=e,this.#p=new C(t,"jsSourceMaps:stub:"+e.target().id(),n.Workspace.projectTypes.Service,"",!0),this.#g=[this.#u.addEventListener(r.SourceMapManager.Events.SourceMapWillAttach,this.sourceMapWillAttach,this),this.#u.addEventListener(r.SourceMapManager.Events.SourceMapFailedToAttach,this.sourceMapFailedToAttach,this),this.#u.addEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),this.#u.addEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)]}setFunctionRanges(e,t){for(const o of this.#S.get(e))o.augmentWithScopes(e.url(),t)}addStubUISourceCode(t){const o=this.#p.addContentProvider(e.ParsedURL.ParsedURL.concatenate(t.sourceURL,":sourcemap"),s.StaticContentProvider.StaticContentProvider.fromString(t.sourceURL,e.ResourceType.resourceTypes.Script,"\n\n\n\n\n// Please wait a bit.\n// Compiled script is not shown while source map is being loaded!"),"text/javascript");this.#d.set(t,o)}removeStubUISourceCode(e){const t=this.#d.get(e);this.#d.delete(e),t&&this.#p.removeUISourceCode(t.url())}getLocationRangesForSameSourceLocation(e){const t=e.debuggerModel,o=e.script();if(!o)return[];const r=this.#u.sourceMapForClient(o);if(!r)return[];const{lineNumber:s,columnNumber:n}=o.rawLocationToRelativeLocation(e),i=r.findEntry(s,n);if(!i?.sourceURL)return[];const a=this.#m.get(r);if(!a)return[];const c=a.uiSourceCodeForURL(i.sourceURL);if(!c)return[];if(!this.#S.hasValue(c,r))return[];return r.findReverseRanges(i.sourceURL,i.sourceLineNumber,i.sourceColumnNumber).map(({startLine:e,startColumn:r,endLine:s,endColumn:n})=>{const i=o.relativeLocationToRawLocation({lineNumber:e,columnNumber:r}),a=o.relativeLocationToRawLocation({lineNumber:s,columnNumber:n});return{start:t.createRawLocation(o,i.lineNumber,i.columnNumber),end:t.createRawLocation(o,a.lineNumber,a.columnNumber)}})}uiSourceCodeForURL(e,t){const o=t?n.Workspace.projectTypes.ContentScripts:n.Workspace.projectTypes.Network;for(const t of this.#h.values()){if(t.type()!==o)continue;const r=t.uiSourceCodeForURL(e);if(r)return r}return null}rawLocationToUILocation(e){const t=e.script();if(!t)return null;const{lineNumber:o,columnNumber:r}=t.rawLocationToRelativeLocation(e),s=this.#d.get(t);if(s)return new n.UISourceCode.UILocation(s,o,r);const i=this.#u.sourceMapForClient(t);if(!i)return null;const a=this.#m.get(i);if(!a)return null;const c=i.findEntry(o,r,e.inlineFrameIndex);if(!c?.sourceURL)return null;const u=a.uiSourceCodeForURL(c.sourceURL);return u&&this.#S.hasValue(u,i)?u.uiLocation(c.sourceLineNumber,c.sourceColumnNumber):null}uiLocationToRawLocations(e,t,o){const r=[];for(const s of this.#S.get(e)){const n=s.sourceLineMapping(e.url(),t,o);if(!n)continue;const i=this.#u.clientForSourceMap(s);if(!i)continue;const a=i.relativeLocationToRawLocation(n);r.push(i.debuggerModel.createRawLocation(i,a.lineNumber,a.columnNumber))}return r}uiLocationRangeToRawLocationRanges(e,t){if(!this.#S.has(e))return null;const o=[];for(const r of this.#S.get(e)){const s=this.#u.clientForSourceMap(r);if(s)for(const n of r.reverseMapTextRanges(e.url(),t)){const e=s.relativeLocationToRawLocation(n.start),t=s.relativeLocationToRawLocation(n.end),r=s.debuggerModel.createRawLocation(s,e.lineNumber,e.columnNumber),i=s.debuggerModel.createRawLocation(s,t.lineNumber,t.columnNumber);o.push({start:r,end:i})}}return o}translateRawFramesStep(e,t){const o=e[0];if(m.isBuiltinFrame(o))return!1;const r=(e=>{const t=this.#f.scriptForId(e.scriptId??"");if(!t||this.#d.has(t))return null;const o=t.sourceMap();return o?.hasScopeInfo()?{sourceMap:o,script:t}:null})(o);if(!r)return!1;const{sourceMap:s,script:n}=r,{lineNumber:i,columnNumber:a}=n.relativeLocationToRawLocation(o);if(!s.isOutlinedFrame(i,a)){const o=s.translateCallSite(i,a);if(!o.length)return!1;e.shift();const r=[];t.push(r);const n=this.#m.get(s);for(const e of o){const t=e.url?n?.uiSourceCodeForURL(e.url):void 0;r.push({...e,url:t?void 0:e.url,uiSourceCode:t??void 0})}return!0}return!1}getMappedLines(e){if(!this.#S.has(e))return null;const t=new Set;for(const o of this.#S.get(e))for(const r of o.mappings())r.sourceURL===e.url()&&t.add(r.sourceLineNumber);return t}sourceMapWillAttach(e){const{client:t}=e.data;this.addStubUISourceCode(t),this.#l.updateLocations(t),n.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(t.sourceURL,{isContentScript:t.isContentScript()})&&this.#u.cancelAttachSourceMap(t)}sourceMapFailedToAttach(e){const{client:t}=e.data;this.removeStubUISourceCode(t),this.#l.updateLocations(t)}sourceMapAttached(t){const{client:o,sourceMap:i}=t.data,a=new Set([o]);this.removeStubUISourceCode(o);const c=o.target(),u=`jsSourceMaps:${o.isContentScript()?"extensions":""}:${c.id()}`;let l=this.#h.get(u);if(!l){const e=o.isContentScript()?n.Workspace.projectTypes.ContentScripts:n.Workspace.projectTypes.Network;l=new C(this.#p.workspace(),u,e,"",!1),y.setTargetForProject(l,c),this.#h.set(u,l)}this.#m.set(i,l);for(const t of i.sourceURLs()){const c=e.ResourceType.resourceTypes.SourceMapScript,u=l.createUISourceCode(t,c);i.hasIgnoreListHint(t)&&u.markKnownThirdParty();const d=i.embeddedContentByURL(t),p=null!==d?s.StaticContentProvider.StaticContentProvider.fromString(t,c,d):new r.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(t,c,o.createPageResourceLoadInitiator());let g=null;if(null!==d){const e=new TextEncoder;g=new n.UISourceCode.UISourceCodeMetadata(null,e.encode(d).length)}const h=e.ResourceType.ResourceType.mimeFromURL(t)??c.canonicalMimeType();this.#S.set(u,i),y.setInitialFrameAttribution(u,o.frameId);const m=l.uiSourceCodeForURL(t);if(null!==m){for(const e of this.#S.get(m)){this.#S.delete(m,e);const o=this.#u.clientForSourceMap(e);o&&(y.removeFrameAttribution(m,o.frameId),i.compatibleForURL(t,e)&&(this.#S.set(u,e),y.addFrameAttribution(u,o.frameId)),a.add(o))}l.removeUISourceCode(t)}l.addUISourceCodeWithProvider(u,p,g,h)}Promise.all([...a].map(e=>this.#l.updateLocations(e))).then(()=>this.sourceMapAttachedForTest(i))}sourceMapDetached(e){const{client:t,sourceMap:o}=e.data,r=this.#m.get(o);if(r){for(const e of r.uiSourceCodes())this.#S.delete(e,o)&&(y.removeFrameAttribution(e,t.frameId),this.#S.has(e)||r.removeUISourceCode(e.url()));this.#m.delete(o),this.#l.updateLocations(t)}}scriptsForUISourceCode(e){const t=[];for(const o of this.#S.get(e)){const e=this.#u.clientForSourceMap(o);e&&t.push(e)}return t}sourceMapAttachedForTest(e){}dispose(){e.EventTarget.removeEventListeners(this.#g);for(const e of this.#h.values())e.dispose();this.#p.dispose()}};U.CompilerScriptMapping=P;class j extends P{addStubUISourceCode(e){}async removeStubUISourceCode(e){}}U.CompilerScriptMapping=j;var D=Object.freeze({__proto__:null,CompilerScriptMapping:j,__scope:U});class N{#M;#b;#L;constructor(e,t){this.#M=e,this.#b=t,this.#b.add(this),this.#L=null}async update(){this.#M&&(this.#L?await this.#L.then(()=>this.update()):(this.#L=this.#M(this),await this.#L,this.#L=null))}async uiLocation(){throw new Error("Not implemented")}dispose(){this.#b.delete(this),this.#M=null}isDisposed(){return!this.#b.has(this)}}class k{#C;constructor(){this.#C=new Set}add(e){this.#C.add(e)}delete(e){this.#C.delete(e)}has(e){return this.#C.has(e)}disposeAll(){for(const e of this.#C)e.dispose()}}var E=Object.freeze({__proto__:null,LiveLocationPool:k,LiveLocationWithPool:N});class O{#u;#w;#g;#v;constructor(e,t,o){this.#u=t,this.#w=new C(o,"cssSourceMaps:"+e.id(),n.Workspace.projectTypes.Network,"",!1),y.setTargetForProject(this.#w,e),this.#v=new Map,this.#g=[this.#u.addEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),this.#u.addEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)]}sourceMapAttachedForTest(e){}async sourceMapAttached(e){const t=e.data.client,o=e.data.sourceMap,r=this.#w,s=this.#v;for(const e of o.sourceURLs()){let n=s.get(e);n||(n=new A(r,e,t.createPageResourceLoadInitiator()),s.set(e,n)),n.addSourceMap(o,t.frameId)}await le.instance().updateLocations(t),this.sourceMapAttachedForTest(o)}async sourceMapDetached(e){const t=e.data.client,o=e.data.sourceMap,r=this.#v;for(const e of o.sourceURLs()){const s=r.get(e);s&&(s.removeSourceMap(o,t.frameId),s.getUiSourceCode()||r.delete(e))}await le.instance().updateLocations(t)}rawLocationToUILocation(e){const t=e.header();if(!t)return null;const o=this.#u.sourceMapForClient(t);if(!o)return null;let{lineNumber:r,columnNumber:s}=e;o.mapsOrigin()&&t.isInline&&(r-=t.startLine,0===r&&(s-=t.startColumn));const n=o.findEntry(r,s);if(!n?.sourceURL)return null;const i=this.#w.uiSourceCodeForURL(n.sourceURL);return i?i.uiLocation(n.sourceLineNumber,n.sourceColumnNumber):null}uiLocationToRawLocations(e){const{uiSourceCode:t,lineNumber:o,columnNumber:s=0}=e,n=x.get(t);if(!n)return[];const i=[];for(const e of n.getReferringSourceMaps()){const n=e.findReverseEntries(t.url(),o,s),a=this.#u.clientForSourceMap(e);a&&i.push(...n.map(e=>new r.CSSModel.CSSLocation(a,e.lineNumber,e.columnNumber)))}return i}static uiSourceOrigin(e){const t=x.get(e);return t?t.getReferringSourceMaps().map(e=>e.compiledURL()):[]}dispose(){e.EventTarget.removeEventListeners(this.#g),this.#w.dispose()}}const x=new WeakMap;let A=class{#w;#R;#I;referringSourceMaps;uiSourceCode;constructor(e,t,o){this.#w=e,this.#R=t,this.#I=o,this.referringSourceMaps=[],this.uiSourceCode=null}recreateUISourceCodeIfNeeded(t){const o=this.referringSourceMaps[this.referringSourceMaps.length-1],i=e.ResourceType.resourceTypes.SourceMapStyleSheet,a=o.embeddedContentByURL(this.#R),c=null!==a?s.StaticContentProvider.StaticContentProvider.fromString(this.#R,i,a):new r.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(this.#R,i,this.#I),u=this.#w.createUISourceCode(this.#R,i);x.set(u,this);const l=e.ResourceType.ResourceType.mimeFromURL(this.#R)||i.canonicalMimeType(),d="string"==typeof a?new n.UISourceCode.UISourceCodeMetadata(null,a.length):null;this.uiSourceCode?(y.cloneInitialFrameAttribution(this.uiSourceCode,u),this.#w.removeUISourceCode(this.uiSourceCode.url())):y.setInitialFrameAttribution(u,t),this.uiSourceCode=u,this.#w.addUISourceCodeWithProvider(this.uiSourceCode,c,d,l)}addSourceMap(e,t){this.uiSourceCode&&y.addFrameAttribution(this.uiSourceCode,t),this.referringSourceMaps.push(e),this.recreateUISourceCodeIfNeeded(t)}removeSourceMap(e,t){const o=this.uiSourceCode;y.removeFrameAttribution(o,t);const r=this.referringSourceMaps.lastIndexOf(e);-1!==r&&this.referringSourceMaps.splice(r,1),this.referringSourceMaps.length?this.recreateUISourceCodeIfNeeded(t):(this.#w.removeUISourceCode(o.url()),this.uiSourceCode=null)}getReferringSourceMaps(){return this.referringSourceMaps}getUiSourceCode(){return this.uiSourceCode}};var W=Object.freeze({__proto__:null,SASSSourceMapping:O});const _=[],B=/[;}]/gm,H=/[\r\n]/g;function z(e){return-1!==e.indexOf(";")}function V(e){return""===e.newText}function q(e){return e.oldRange.startLine===e.oldRange.endLine&&e.oldRange.startColumn===e.oldRange.endColumn}function $(e){const t=e.newRange.endLine-e.newRange.startLine-(e.oldRange.endLine-e.oldRange.startLine),o=e.newRange.endColumn-e.newRange.startColumn,r=e.oldRange.endColumn-e.oldRange.startColumn;return[t,t?e.newRange.endColumn-e.oldRange.endColumn:o-r]}function G(e,t,o){const r=/\r?\n/g;for(let o=0;o<t&&r.exec(e);o++);return r.lastIndex+o}function J(e,t,o){return o.oldRange.startLine<e||o.oldRange.startLine===e&&o.oldRange.startColumn<=t}function K(e,t,o){return o.oldRange.endLine>e||o.oldRange.endLine===e&&o.oldRange.endColumn>t}function X(e,t,o,n,i=0){let a=G(t,n,i),c=e.newText.trim();if(z(t)||(c=c.replace(/;$/,"")),V(e))for(;/\s/.test(t[a-1]);)a--;let u="",l="";const d=a-i,p=t.slice(d,a);if(o&&/^\s*$/.test(p)){const e=function(e,t){let o=t;for(;/\s/.test(e[o]);)o++;return e.slice(t,o)}(t,G(t,n-1,0));a=d,i=0,u=`${e}`,l="\n"}else if(q(e)){let e=a;for(;e>d&&/\s/.test(t[e-1]);)e--;l=`${e===d?"\n":""}${t.slice(e,a)}`}c=`${u}${c}${l}`;const g=q(e)?a:function(e,t){if("/*"===e.substr(t,2))return e.indexOf("*/",t)+2;if(z(e)){B.lastIndex=t;const o=B.exec(e);return o&&";"===o[0]?B.lastIndex:B.lastIndex-1}return H.lastIndex=t,H.exec(e),H.lastIndex-1}(t,a),h=t.slice(0,a)+c+t.slice(g),m=t.slice(a,g),S=s.TextRange.TextRange.createFromLocation(n,i),f=s.TextRange.TextRange.fromEdit(S,m);return[h,new r.CSSModel.Edit("",f,c,null),s.TextRange.TextRange.fromEdit(S,u).collapseToEnd()]}async function Y(e){_.push(e),1===_.length&&await Q()}async function Q(){const e=_[0];if(!e)return;const{header:t,edit:o,isInsertionAtEnd:n}=e,i=le.instance().rawLocationToUILocation(new r.CSSModel.CSSLocation(t,o.oldRange.startLine,o.oldRange.startColumn));if(i?.uiSourceCode){const e=await i.uiSourceCode.requestContentData(),a=s.ContentData.ContentData.textOr(e,"");if(a){const{lineNumber:e,columnNumber:s}=i,[c,u,l]=X(o,a,n,e,s);i.uiSourceCode.setWorkingCopy(c);const d=t.cssModel().sourceMapManager().sourceMapForClient(t);d&&function(e,t,o,s,n){if(t.oldRange.equal(t.newRange)&&s.oldRange.equal(s.newRange))return;for(let o=e.length-1;o>=0;o--){const{lineNumber:r,columnNumber:s}=e[o];J(r,s,t)&&K(r,s,t)&&e.splice(o,1)}const[i,a]=$(t),[c,u]=$(s);for(const r of e)if(J(r.lineNumber,r.columnNumber,t)&&(r.lineNumber+=i),r.lineNumber===t.oldRange.endLine&&r.columnNumber>=t.oldRange.endColumn&&(r.columnNumber+=a),r.sourceURL===o){const e=r.sourceLineNumber,t=r.sourceColumnNumber;J(e,t,s)&&(r.sourceLineNumber+=c),e===s.oldRange.endLine&&t>=s.oldRange.endColumn&&(r.sourceColumnNumber+=u)}V(t)||(e.push(new r.SourceMap.SourceMapEntry(t.newRange.startLine,t.newRange.startColumn,void 0,o,n.startLine,n.startColumn)),e.sort(r.SourceMap.SourceMapEntry.compare))}(d.mappings(),o,i.uiSourceCode.url(),u,l)}}_.shift(),await Q()}function Z(e){return r.ResourceTreeModel.ResourceTreeModel.resourceForURL(e)}function ee(e,t,o){const s=e.model(r.ResourceTreeModel.ResourceTreeModel);if(!s)return null;const n=s.frameForId(t);return n?te(n.resourceForURL(o)):null}function te(e){return!e||"number"!=typeof e.contentSize()&&!e.lastModified()?null:new n.UISourceCode.UISourceCodeMetadata(e.lastModified(),e.contentSize())}var oe=Object.freeze({__proto__:null,displayNameForURL:function(o){if(!o)return"";const s=n.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(o);if(s)return s.displayName();const i=Z(o);if(i)return i.displayName;const a=r.TargetManager.TargetManager.instance().inspectedURL();if(!a)return t.StringUtilities.trimURL(o,"");const c=e.ParsedURL.ParsedURL.fromString(a);if(!c)return o;const u=c.lastPathComponent,l=a.indexOf(u);if(-1!==l&&l+u.length===a.length){const e=a.substring(0,l);if(o.startsWith(e)&&o.length>l)return o.substring(l)}const d=t.StringUtilities.trimURL(o,c.host);return"/"===d?c.host+"/":d},metadataForURL:ee,resourceForURL:Z,resourceMetadata:te});const re={},se=new WeakMap;let ne=class{#T;get cssModel(){return this.#T}set cssModel(e){this.#T=e}#w;#y=new Map;#g;get eventListeners(){return this.#g}set eventListeners(e){this.#g=e}constructor(e,t){this.#T=e;const o=this.#T.target();this.#w=new C(t,"css:"+o.id(),n.Workspace.projectTypes.Network,"",!1),y.setTargetForProject(this.#w,o),this.#g=[this.#T.addEventListener(r.CSSModel.Events.StyleSheetAdded,this.styleSheetAdded,this),this.#T.addEventListener(r.CSSModel.Events.StyleSheetRemoved,this.styleSheetRemoved,this),this.#T.addEventListener(r.CSSModel.Events.StyleSheetChanged,this.styleSheetChanged,this)]}addSourceMap(e,t){this.#y.get(e)?.addSourceMap(e,t)}rawLocationToUILocation(e){const t=e.header();if(!t||!this.acceptsHeader(t))return null;const o=this.#y.get(t.resourceURL());if(!o)return null;let r=e.lineNumber,s=e.columnNumber;if(t.isInline&&t.hasSourceURL){r-=t.lineNumberInSource(0);const e=t.columnNumberInSource(r,0);void 0===e?s=e:s-=e}return o.getUiSourceCode().uiLocation(r,s)}uiLocationToRawLocations(e){const t=se.get(e.uiSourceCode);if(!t)return[];const o=[];for(const s of t.getHeaders()){let t=e.lineNumber,n=e.columnNumber;s.isInline&&s.hasSourceURL&&(n=s.columnNumberInSource(t,e.columnNumber||0),t=s.lineNumberInSource(t)),o.push(new r.CSSModel.CSSLocation(s,t,n))}return o}acceptsHeader(e){return!e.isConstructedByNew()&&(!(e.isInline&&!e.hasSourceURL&&"inspector"!==e.origin)&&!!e.resourceURL())}styleSheetAdded(e){const t=e.data;if(!this.acceptsHeader(t))return;const o=t.resourceURL();let r=this.#y.get(o);r?r.addHeader(t):(r=new ie(this.#T,this.#w,t),this.#y.set(o,r))}styleSheetRemoved(e){const t=e.data;if(!this.acceptsHeader(t))return;const o=t.resourceURL(),r=this.#y.get(o);r&&(1===r.getHeaders().size?(r.dispose(),this.#y.delete(o)):r.removeHeader(t))}styleSheetChanged(e){const t=this.#T.styleSheetHeaderForId(e.data.styleSheetId);if(!t||!this.acceptsHeader(t))return;const o=this.#y.get(t.resourceURL());o&&o.styleSheetChanged(t)}dispose(){for(const e of this.#y.values())e.dispose();this.#y.clear(),e.EventTarget.removeEventListeners(this.#g),this.#w.removeProject()}};re.StylesSourceMapping=ne;class ie{#T;get cssModel(){return this.#T}set cssModel(e){this.#T=e}#w;headers;uiSourceCode;#g;get eventListeners(){return this.#g}set eventListeners(e){this.#g=e}#F=new e.Throttler.Throttler(200);#U=!1;#P;#j;constructor(e,t,o){this.#T=e,this.#w=t,this.headers=new Set([o]);const r=e.target(),s=o.resourceURL(),i=ee(r,o.frameId,s);this.uiSourceCode=this.#w.createUISourceCode(s,o.contentType()),se.set(this.uiSourceCode,this),y.setInitialFrameAttribution(this.uiSourceCode,o.frameId),this.#w.addUISourceCodeWithProvider(this.uiSourceCode,this,i,"text/css"),this.#g=[this.uiSourceCode.addEventListener(n.UISourceCode.Events.WorkingCopyChanged,this.workingCopyChanged,this),this.uiSourceCode.addEventListener(n.UISourceCode.Events.WorkingCopyCommitted,this.workingCopyCommitted,this)]}addHeader(e){this.headers.add(e),y.addFrameAttribution(this.uiSourceCode,e.frameId)}removeHeader(e){this.headers.delete(e),y.removeFrameAttribution(this.uiSourceCode,e.frameId)}styleSheetChanged(e){if(console.assert(this.headers.has(e)),this.#j||!this.headers.has(e))return;const t=this.mirrorContent.bind(this,e,!0);this.#F.schedule(t,"Default")}workingCopyCommitted(){if(this.#P)return;const e=this.mirrorContent.bind(this,this.uiSourceCode,!0);this.#F.schedule(e,"AsSoonAsPossible")}workingCopyChanged(){if(this.#P)return;const e=this.mirrorContent.bind(this,this.uiSourceCode,!1);this.#F.schedule(e,"Default")}async mirrorContent(e,t){if(this.#U)return void this.styleFileSyncedForTest();let o=null;if(o=e===this.uiSourceCode?this.uiSourceCode.workingCopy():s.ContentData.ContentData.textOr(await e.requestContentData(),null),null===o||this.#U)return void this.styleFileSyncedForTest();e!==this.uiSourceCode&&(this.#P=!0,this.uiSourceCode.setWorkingCopy(o),this.#P=!1),this.#j=!0;const r=[];for(const s of this.headers)s!==e&&r.push(this.#T.setStyleSheetText(s.id,o,t));await Promise.all(r),this.#j=!1,this.styleFileSyncedForTest()}styleFileSyncedForTest(){}dispose(){this.#U||(this.#U=!0,this.#w.removeUISourceCode(this.uiSourceCode.url()),e.EventTarget.removeEventListeners(this.#g))}contentURL(){return console.assert(this.headers.size>0),this.#D().originalContentProvider().contentURL()}contentType(){return console.assert(this.headers.size>0),this.#D().originalContentProvider().contentType()}requestContentData(){return console.assert(this.headers.size>0),this.#D().originalContentProvider().requestContentData()}searchInContent(e,t,o){return console.assert(this.headers.size>0),this.#D().originalContentProvider().searchInContent(e,t,o)}#D(){return console.assert(this.headers.size>0),this.headers.values().next().value}getHeaders(){return this.headers}getUiSourceCode(){return this.uiSourceCode}addSourceMap(e,t){const o=this.#T.sourceMapManager();this.headers.forEach(r=>{o.detachSourceMap(r),o.attachSourceMap(r,e,t)})}}class ae extends ne{constructor(e,t){super(e,t);const o=e;this.eventListeners.push(o.edge.addEventListener("StylePropertyChanged",this.stylePropertyChanged,this))}stylePropertyChanged(e){const t=this.cssModel.styleSheetHeaderForId(e.data.styleSheetId);t&&e.data.edit&&Y({header:t,edit:e.data.edit,isInsertionAtEnd:e.data.isInsertionAtEnd})}}re.StylesSourceMapping=ae;var ce=Object.freeze({__proto__:null,StyleFile:ie,StylesSourceMapping:ae,__scope:re});let ue;class le{#N;#k;#E;constructor(e,t){this.#N=e,this.#k=new Map,t.observeModels(r.CSSModel.CSSModel,this),this.#E=new Set}static instance(e={forceNew:null,resourceMapping:null,targetManager:null}){const{forceNew:t,resourceMapping:o,targetManager:r}=e;if(!ue||t){if(!o||!r)throw new Error(`Unable to create CSSWorkspaceBinding: resourceMapping and targetManager must be provided: ${(new Error).stack}`);ue=new le(o,r)}return ue}static removeInstance(){ue=void 0}get modelToInfo(){return this.#k}getCSSModelInfo(e){return this.#k.get(e)}modelAdded(e){this.#k.set(e,new de(e,this.#N))}modelRemoved(e){this.getCSSModelInfo(e).dispose(),this.#k.delete(e)}async pendingLiveLocationChangesPromise(){await Promise.all(this.#E)}recordLiveLocationChange(e){e.then(()=>{this.#E.delete(e)}),this.#E.add(e)}async updateLocations(e){const t=this.getCSSModelInfo(e.cssModel()).updateLocations(e);this.recordLiveLocationChange(t),await t}createLiveLocation(e,t,o){const r=this.getCSSModelInfo(e.cssModel()).createLiveLocation(e,t,o);return this.recordLiveLocationChange(r),r}propertyRawLocation(e,t){const o=e.ownerStyle;if(!o||o.type!==r.CSSStyleDeclaration.Type.Regular||!o.styleSheetId)return null;const s=o.cssModel().styleSheetHeaderForId(o.styleSheetId);if(!s)return null;const n=t?e.nameRange():e.valueRange();if(!n)return null;const i=n.startLine,a=n.startColumn;return new r.CSSModel.CSSLocation(s,s.lineNumberInSource(i),s.columnNumberInSource(i,a))}propertyUILocation(e,t){const o=this.propertyRawLocation(e,t);return o?this.rawLocationToUILocation(o):null}rawLocationToUILocation(e){return this.getCSSModelInfo(e.cssModel()).rawLocationToUILocation(e)}uiLocationToRawLocations(e){const t=[];for(const o of this.#k.values())t.push(...o.uiLocationToRawLocations(e));return t}}let de=class{#g;#N;#O;#x;#C;#A;constructor(e,o){this.#g=[e.addEventListener(r.CSSModel.Events.StyleSheetAdded,e=>{this.styleSheetAdded(e)},this),e.addEventListener(r.CSSModel.Events.StyleSheetRemoved,e=>{this.styleSheetRemoved(e)},this)],this.#N=o,this.#O=new ae(e,o.workspace);const s=e.sourceMapManager();this.#x=new O(e.target(),s,o.workspace),this.#C=new t.MapUtilities.Multimap,this.#A=new t.MapUtilities.Multimap}get locations(){return this.#C}async createLiveLocation(e,t,o){const r=new pe(e,this,t,o),s=e.header();return s?(r.setHeader(s),this.#C.set(s,r),await r.update()):this.#A.set(e.url,r),r}disposeLocation(e){const t=e.header();t?this.#C.delete(t,e):this.#A.delete(e.url,e)}updateLocations(e){const t=[];for(const o of this.#C.get(e))t.push(o.update());return Promise.all(t)}async styleSheetAdded(e){const t=e.data;if(!t.sourceURL)return;const o=[];for(const e of this.#A.get(t.sourceURL))e.setHeader(t),this.#C.set(t,e),o.push(e.update());await Promise.all(o),this.#A.deleteAll(t.sourceURL)}async styleSheetRemoved(e){const t=e.data,o=[];for(const e of this.#C.get(t))e.setHeader(t),this.#A.set(e.url,e),o.push(e.update());await Promise.all(o),this.#C.deleteAll(t)}addSourceMap(e,t){this.#O.addSourceMap(e,t)}rawLocationToUILocation(e){let t=null;return t=t||this.#x.rawLocationToUILocation(e),t=t||this.#O.rawLocationToUILocation(e),t=t||this.#N.cssLocationToUILocation(e),t}uiLocationToRawLocations(e){let t=this.#x.uiLocationToRawLocations(e);return t.length?t:(t=this.#O.uiLocationToRawLocations(e),t.length?t:this.#N.uiLocationToCSSLocations(e))}dispose(){e.EventTarget.removeEventListeners(this.#g),this.#O.dispose(),this.#x.dispose()}};class pe extends N{url;#W;#_;#B;headerInternal;constructor(e,t,o,r){super(o,r),this.url=e.url,this.#W=e.lineNumber,this.#_=e.columnNumber,this.#B=t,this.headerInternal=null}header(){return this.headerInternal}setHeader(e){this.headerInternal=e}async uiLocation(){if(!this.headerInternal)return null;const e=new r.CSSModel.CSSLocation(this.headerInternal,this.#W,this.#_);return le.instance().rawLocationToUILocation(e)}dispose(){super.dispose(),this.#B.disposeLocation(this)}}var ge=Object.freeze({__proto__:null,CSSWorkspaceBinding:le,LiveLocation:pe,ModelInfo:de});const he={errorInDebuggerLanguagePlugin:"Error in debugger language plugin: {PH1}",loadingDebugSymbolsForVia:"[{PH1}] Loading debug symbols for {PH2} (via {PH3})…",loadingDebugSymbolsFor:"[{PH1}] Loading debug symbols for {PH2}…",loadedDebugSymbolsForButDidnt:"[{PH1}] Loaded debug symbols for {PH2}, but didn't find any source files",loadedDebugSymbolsForFound:"[{PH1}] Loaded debug symbols for {PH2}, found {PH3} source file(s)",failedToLoadDebugSymbolsFor:"[{PH1}] Failed to load debug symbols for {PH2} ({PH3})",failedToLoadDebugSymbolsForFunction:'No debug information for function "{PH1}"',debugSymbolsIncomplete:"The debug information for function {PH1} is incomplete"},me=i.i18n.registerUIStrings("models/bindings/DebuggerLanguagePlugins.ts",he),Se=i.i18n.getLocalizedString.bind(void 0,me);function fe(e){return`${e.sourceURL}@${e.hash}`}function Me(e){const{script:t}=e;return{rawModuleId:fe(t),codeOffset:e.location().columnNumber-(t.codeOffset()||0),inlineFrameIndex:e.inlineFrameIndex}}class be extends Error{exception;exceptionDetails;constructor(e,t){const{description:o}=t.exception||{};super(o||t.text),this.exception=e,this.exceptionDetails=t}static makeLocal(e,t){const o={type:"object",subtype:"error",description:t},r={text:"Uncaught",exceptionId:-1,columnNumber:0,lineNumber:0,exception:o},s=e.debuggerModel.runtimeModel().createRemoteObject(o);return new be(s,r)}}class Le extends r.RemoteObject.LocalJSONObject{get description(){return this.type}get type(){return"namespace"}}async function Ce(e,t,o){if("reftype"===t.type){const o=await async function(e,t){if(!/^(local|global|operand)$/.test(t.valueClass))return{type:"undefined"};const o=Number(t.index),r=`${t.valueClass}s[${o}]`,s=await e.debuggerModel.agent.invoke_evaluateOnCallFrame({callFrameId:e.id,expression:r,silent:!0,generatePreview:!0,throwOnSideEffect:!0});return s.getError()||s.exceptionDetails?{type:"undefined"}:s.result}(e,t);return e.debuggerModel.runtimeModel().createRemoteObject(o)}return new Re(e,t,o)}class we extends r.RemoteObject.RemoteObjectImpl{variables;#H;#z;stopId;constructor(e,t,o){super(e.debuggerModel.runtimeModel(),void 0,"object",void 0,null),this.variables=[],this.#H=e,this.#z=o,this.stopId=t}async doGetProperties(e,t,o){if(t)return{properties:[],internalProperties:[]};const s=[],n={};function i(e,t){return new r.RemoteObject.RemoteObjectProperty(e,t,!1,!1,!0,!1)}for(const e of this.variables){let t;try{const o=await this.#z.evaluate(e.name,Me(this.#H),this.stopId);t=o?await Ce(this.#H,o,this.#z):new r.RemoteObject.LocalJSONObject(void 0)}catch(e){console.warn(e),t=new r.RemoteObject.LocalJSONObject(void 0)}if(e.nestedName&&e.nestedName.length>1){let o=n;for(let t=0;t<e.nestedName.length-1;t++){const r=e.nestedName[t];let s=o[r];s||(s=new Le({}),o[r]=s),o=s.value}o[e.nestedName[e.nestedName.length-1]]=t}else s.push(i(e.name,t))}for(const e in n)s.push(i(e,n[e]));return{properties:s,internalProperties:[]}}}class ve{#V;#q;#$;#G;#J;constructor(e,t,o,r,s,n){if(s&&"data:"!==new URL(s).protocol)throw new Error("The icon must be a data:-URL");this.#V=e,this.#q=o,this.#$=r,this.#G=s,this.#J=new we(e,t,n)}async getVariableValue(e){for(let t=0;t<this.#J.variables.length;++t){if(this.#J.variables[t].name!==e)continue;const o=await this.#J.getAllProperties(!1,!1);if(!o.properties)continue;const{value:r}=o.properties[t];if(r)return r}return null}callFrame(){return this.#V}type(){return this.#q}typeName(){return this.#$}name(){}range(){return null}object(){return this.#J}description(){return""}icon(){return this.#G}extraProperties(){return[]}}class Re extends r.RemoteObject.RemoteObject{extensionObject;plugin;callFrame;constructor(e,t,o){super(),this.extensionObject=t,this.plugin=o,this.callFrame=e}get linearMemoryAddress(){return this.extensionObject.linearMemoryAddress}get linearMemorySize(){return this.extensionObject.linearMemorySize}get objectId(){return this.extensionObject.objectId}get type(){return"array"===this.extensionObject.type||"null"===this.extensionObject.type?"object":this.extensionObject.type}get subtype(){if("array"===this.extensionObject.type||"null"===this.extensionObject.type)return this.extensionObject.type}get value(){return this.extensionObject.value}unserializableValue(){}get description(){return this.extensionObject.description}set description(e){}get hasChildren(){return this.extensionObject.hasChildren}get preview(){}get className(){return this.extensionObject.className??null}arrayLength(){return 0}arrayBufferByteLength(){return 0}getOwnProperties(e,t){return this.getAllProperties(!1,e,t)}async getAllProperties(e,t,s){const{objectId:n}=this.extensionObject;if(n){o(this.plugin.getProperties);const e=await this.plugin.getProperties(n);return{properties:await Promise.all(e.map(async e=>new r.RemoteObject.RemoteObjectProperty(e.name,await Ce(this.callFrame,e.value,this.plugin)))),internalProperties:null}}return{properties:null,internalProperties:null}}release(){const{objectId:e}=this.extensionObject;e&&(o(this.plugin.releaseObject),this.plugin.releaseObject(e))}debuggerModel(){return this.callFrame.debuggerModel}runtimeModel(){return this.callFrame.debuggerModel.runtimeModel()}isLinearMemoryInspectable(){return void 0!==this.extensionObject.linearMemoryAddress}}class Ie{#K;#l;#X;#Y;#Q;callFrameByStopId=new Map;stopIdByCallFrame=new Map;nextStopId=0n;constructor(e,t,o){this.#K=t,this.#l=o,this.#X=[],this.#Y=new Map,e.observeModels(r.DebuggerModel.DebuggerModel,this),this.#Q=new Map}async evaluateOnCallFrame(e,t){const{script:o}=e,{expression:s,returnByValue:n,throwOnSideEffect:i}=t,{plugin:a}=await this.rawModuleIdAndPluginForScript(o);if(!a)return null;const c=Me(e);if(0===(await a.rawLocationToSourceLocation(c)).length)return null;if(n)return{error:"Cannot return by value"};if(i)return{error:"Cannot guarantee side-effect freedom"};try{const t=await a.evaluate(s,c,this.stopIdForCallFrame(e));return t?{object:await Ce(e,t,a),exceptionDetails:void 0}:{object:new r.RemoteObject.LocalJSONObject(void 0),exceptionDetails:void 0}}catch(t){if(t instanceof be){const{exception:e,exceptionDetails:o}=t;return{object:e,exceptionDetails:o}}const{exception:o,exceptionDetails:r}=be.makeLocal(e,t.message);return{object:o,exceptionDetails:r}}}stopIdForCallFrame(e){let t=this.stopIdByCallFrame.get(e);return void 0!==t||(t=this.nextStopId++,this.stopIdByCallFrame.set(e,t),this.callFrameByStopId.set(t,e)),t}callFrameForStopId(e){return this.callFrameByStopId.get(e)}expandCallFrames(e){return Promise.all(e.map(async e=>{const t=await this.getFunctionInfo(e.script,e.location());if(t){if("frames"in t&&t.frames.length)return t.frames.map(({name:t},o)=>e.createVirtualCallFrame(o,t));if("missingSymbolFiles"in t&&t.missingSymbolFiles.length){const o=t.missingSymbolFiles,r=Se(he.debugSymbolsIncomplete,{PH1:e.functionName});e.missingDebugInfoDetails={details:r,resources:o}}else e.missingDebugInfoDetails={details:Se(he.failedToLoadDebugSymbolsForFunction,{PH1:e.functionName}),resources:[]}}return e})).then(e=>e.flat())}modelAdded(e){this.#Y.set(e,new Te(e,this.#K)),e.addEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),e.addEventListener(r.DebuggerModel.Events.ParsedScriptSource,this.parsedScriptSource,this),e.addEventListener(r.DebuggerModel.Events.DebuggerResumed,this.debuggerResumed,this),e.setEvaluateOnCallFrameCallback(this.evaluateOnCallFrame.bind(this)),e.setExpandCallFramesCallback(this.expandCallFrames.bind(this))}modelRemoved(t){t.removeEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),t.removeEventListener(r.DebuggerModel.Events.ParsedScriptSource,this.parsedScriptSource,this),t.removeEventListener(r.DebuggerModel.Events.DebuggerResumed,this.debuggerResumed,this),t.setEvaluateOnCallFrameCallback(null),t.setExpandCallFramesCallback(null);const o=this.#Y.get(t);o&&(o.dispose(),this.#Y.delete(t)),this.#Q.forEach((o,r)=>{const s=o.scripts.filter(e=>e.debuggerModel!==t);0===s.length?(o.plugin.removeRawModule(r).catch(t=>{e.Console.Console.instance().error(Se(he.errorInDebuggerLanguagePlugin,{PH1:t.message}),!1)}),this.#Q.delete(r)):o.scripts=s})}globalObjectCleared(e){const t=e.data;this.modelRemoved(t),this.modelAdded(t)}addPlugin(e){this.#X.push(e);for(const e of this.#Y.keys())for(const t of e.scripts())this.hasPluginForScript(t)||this.parsedScriptSource({data:t})}removePlugin(e){this.#X=this.#X.filter(t=>t!==e);const t=new Set;this.#Q.forEach((o,r)=>{o.plugin===e&&(o.scripts.forEach(e=>t.add(e)),this.#Q.delete(r))});for(const e of t){this.#Y.get(e.debuggerModel).removeScript(e),this.parsedScriptSource({data:e})}}hasPluginForScript(e){const t=fe(e),o=this.#Q.get(t);return o?.scripts.includes(e)??!1}async rawModuleIdAndPluginForScript(e){const t=fe(e),o=this.#Q.get(t);return o&&(await o.addRawModulePromise,o===this.#Q.get(t))?{rawModuleId:t,plugin:o.plugin}:{rawModuleId:t,plugin:null}}uiSourceCodeForURL(e,t){const o=this.#Y.get(e);return o?o.getProject().uiSourceCodeForURL(t):null}async rawLocationToUILocation(t){const o=t.script();if(!o)return null;const{rawModuleId:r,plugin:s}=await this.rawModuleIdAndPluginForScript(o);if(!s)return null;const n={rawModuleId:r,codeOffset:t.columnNumber-(o.codeOffset()||0),inlineFrameIndex:t.inlineFrameIndex};try{const e=await s.rawLocationToSourceLocation(n);for(const t of e){const e=this.uiSourceCodeForURL(o.debuggerModel,t.sourceFileURL);if(e)return e.uiLocation(t.lineNumber,t.columnNumber>=0?t.columnNumber:void 0)}}catch(t){e.Console.Console.instance().error(Se(he.errorInDebuggerLanguagePlugin,{PH1:t.message}),!1)}return null}uiLocationToRawLocationRanges(t,o,s=-1){const n=[];return this.scriptsForUISourceCode(t).forEach(e=>{const i=fe(e),a=this.#Q.get(i);if(!a)return;const{plugin:c}=a;n.push(async function(e,n,i){const a={rawModuleId:e,sourceFileURL:t.url(),lineNumber:o,columnNumber:s},c=await n.sourceLocationToRawLocation(a);if(!c)return[];return c.map(e=>({start:new r.DebuggerModel.Location(i.debuggerModel,i.scriptId,0,Number(e.startOffset)+(i.codeOffset()||0)),end:new r.DebuggerModel.Location(i.debuggerModel,i.scriptId,0,Number(e.endOffset)+(i.codeOffset()||0))}))}(i,c,e))}),0===n.length?Promise.resolve(null):Promise.all(n).then(e=>e.flat()).catch(t=>(e.Console.Console.instance().error(Se(he.errorInDebuggerLanguagePlugin,{PH1:t.message}),!1),null))}async uiLocationToRawLocations(e,t,o){const r=await this.uiLocationToRawLocationRanges(e,t,o);return r?r.map(({start:e})=>e):null}async uiLocationRangeToRawLocationRanges(e,t){const o=[];for(let r=t.startLine;r<=t.endLine;++r)o.push(this.uiLocationToRawLocationRanges(e,r));const r=[];for(const e of await Promise.all(o)){if(null===e)return null;for(const o of e){const[e,n]=await Promise.all([this.rawLocationToUILocation(o.start),this.rawLocationToUILocation(o.end)]);if(null===e||null===n)continue;t.intersection(new s.TextRange.TextRange(e.lineNumber,e.columnNumber??0,n.lineNumber,n.columnNumber??1/0)).isEmpty()||r.push(o)}}return r}async translateRawFramesStep(e,t,o){const s=e[0],n=o.model(r.DebuggerModel.DebuggerModel)?.scriptForId(s.scriptId??"");if(!n)return!1;const i=await this.getFunctionInfo(n,s);if(!i)return!1;if(e.shift(),"frames"in i&&i.frames.length){const e=i.frames.map(async({name:e},t)=>{const o=new r.DebuggerModel.Location(n.debuggerModel,n.scriptId,s.lineNumber,s.columnNumber,t),i=await this.rawLocationToUILocation(o);return{uiSourceCode:i?.uiSourceCode,url:i?void 0:s.url,name:e,line:i?.lineNumber??s.lineNumber,column:i?.columnNumber??s.columnNumber}});return t.push(await Promise.all(e)),!0}const a={url:s.url,name:s.functionName,line:s.lineNumber,column:s.columnNumber};return"missingSymbolFiles"in i&&i.missingSymbolFiles.length?t.push([{...a,missingDebugInfo:{type:"PARTIAL_INFO",missingDebugFiles:i.missingSymbolFiles}}]):t.push([{...a,missingDebugInfo:{type:"NO_INFO"}}]),!0}scriptsForUISourceCode(e){for(const t of this.#Y.values()){const o=t.uiSourceCodeToScripts.get(e);if(o)return o}return[]}setDebugInfoURL(e,t){this.hasPluginForScript(e)||(e.debugSymbols={type:"ExternalDWARF",externalURL:t},this.parsedScriptSource({data:e}),e.debuggerModel.setDebugInfoURL(e,t))}parsedScriptSource(t){const o=t.data;if(o.sourceURL)for(const t of this.#X){if(!t.handleScript(o))continue;const r=fe(o);let s=this.#Q.get(r);if(s)s.scripts.push(o);else{const n=(async()=>{const n=e.Console.Console.instance(),i=o.sourceURL,a=o.debugSymbols?.externalURL||"";a?n.log(Se(he.loadingDebugSymbolsForVia,{PH1:t.name,PH2:i,PH3:a})):n.log(Se(he.loadingDebugSymbolsFor,{PH1:t.name,PH2:i}));try{const c=!a&&e.ParsedURL.schemeIs(i,"wasm:")?await o.getWasmBytecode():void 0,u=await t.addRawModule(r,a,{url:i,code:c});if(s!==this.#Q.get(r))return[];if("missingSymbolFiles"in u){const e=t.createPageResourceLoadInitiator();return{missingSymbolFiles:u.missingSymbolFiles.map(t=>({resourceUrl:t,initiator:e}))}}const l=u;return 0===l.length?n.warn(Se(he.loadedDebugSymbolsForButDidnt,{PH1:t.name,PH2:i})):n.log(Se(he.loadedDebugSymbolsForFound,{PH1:t.name,PH2:i,PH3:l.length})),l}catch(e){return n.error(Se(he.failedToLoadDebugSymbolsFor,{PH1:t.name,PH2:i,PH3:e.message}),!1),this.#Q.delete(r),[]}})();s={rawModuleId:r,plugin:t,scripts:[o],addRawModulePromise:n},this.#Q.set(r,s)}return void s.addRawModulePromise.then(e=>{if(!("missingSymbolFiles"in e)&&o.debuggerModel.scriptForId(o.scriptId)===o){const t=this.#Y.get(o.debuggerModel);t&&(t.addSourceFiles(o,e),this.#l.updateLocations(o))}})}}debuggerResumed(e){const t=Array.from(this.callFrameByStopId.values()).filter(t=>t.debuggerModel===e.data);for(const e of t){const t=this.stopIdByCallFrame.get(e);o(t),this.stopIdByCallFrame.delete(e),this.callFrameByStopId.delete(t)}}getSourcesForScript(e){const t=fe(e),o=this.#Q.get(t);return o?o.addRawModulePromise:Promise.resolve(void 0)}async resolveScopeChain(t){const o=t.script,{rawModuleId:r,plugin:s}=await this.rawModuleIdAndPluginForScript(o);if(!s)return null;const n={rawModuleId:r,codeOffset:t.location().columnNumber-(o.codeOffset()||0),inlineFrameIndex:t.inlineFrameIndex},i=this.stopIdForCallFrame(t);try{if(0===(await s.rawLocationToSourceLocation(n)).length)return null;const e=new Map,o=await s.listVariablesInScope(n);for(const r of o||[]){let o=e.get(r.scope);if(!o){const{type:n,typeName:a,icon:c}=await s.getScopeInfo(r.scope);o=new ve(t,i,n,a,c,s),e.set(r.scope,o)}o.object().variables.push(r)}return Array.from(e.values())}catch(t){return e.Console.Console.instance().error(Se(he.errorInDebuggerLanguagePlugin,{PH1:t.message}),!1),null}}async getFunctionInfo(t,o){const{rawModuleId:r,plugin:s}=await this.rawModuleIdAndPluginForScript(t);if(!s)return null;const n={rawModuleId:r,codeOffset:o.columnNumber-(t.codeOffset()||0),inlineFrameIndex:0};try{const e=await s.getFunctionInfo(n);if("missingSymbolFiles"in e){const t=s.createPageResourceLoadInitiator();return{missingSymbolFiles:e.missingSymbolFiles.map(e=>({resourceUrl:e,initiator:t})),..."frames"in e&&{frames:e.frames}}}return e}catch(t){return e.Console.Console.instance().warn(Se(he.errorInDebuggerLanguagePlugin,{PH1:t.message})),{frames:[]}}}async getInlinedFunctionRanges(t){const o=t.script();if(!o)return[];const{rawModuleId:s,plugin:n}=await this.rawModuleIdAndPluginForScript(o);if(!n)return[];const i={rawModuleId:s,codeOffset:t.columnNumber-(o.codeOffset()||0)};try{return(await n.getInlinedFunctionRanges(i)).map(e=>({start:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.startOffset)+(o.codeOffset()||0)),end:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.endOffset)+(o.codeOffset()||0))}))}catch(t){return e.Console.Console.instance().warn(Se(he.errorInDebuggerLanguagePlugin,{PH1:t.message})),[]}}async getInlinedCalleesRanges(t){const o=t.script();if(!o)return[];const{rawModuleId:s,plugin:n}=await this.rawModuleIdAndPluginForScript(o);if(!n)return[];const i={rawModuleId:s,codeOffset:t.columnNumber-(o.codeOffset()||0)};try{return(await n.getInlinedCalleesRanges(i)).map(e=>({start:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.startOffset)+(o.codeOffset()||0)),end:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.endOffset)+(o.codeOffset()||0))}))}catch(t){return e.Console.Console.instance().warn(Se(he.errorInDebuggerLanguagePlugin,{PH1:t.message})),[]}}async getMappedLines(e){const t=await Promise.all(this.scriptsForUISourceCode(e).map(e=>this.rawModuleIdAndPluginForScript(e)));let o=null;for(const{rawModuleId:r,plugin:s}of t){if(!s)continue;const t=await s.getMappedLines(r,e.url());void 0!==t&&(null===o?o=new Set(t):t.forEach(e=>o.add(e)))}return o}}let Te=class{project;uiSourceCodeToScripts;constructor(e,t){this.project=new C(t,"language_plugins::"+e.target().id(),n.Workspace.projectTypes.Network,"",!1),y.setTargetForProject(this.project,e.target()),this.uiSourceCodeToScripts=new Map}addSourceFiles(t,o){const s=t.createPageResourceLoadInitiator();for(const n of o){let o=this.project.uiSourceCodeForURL(n);if(o){const e=this.uiSourceCodeToScripts.get(o);e.includes(t)||e.push(t)}else{o=this.project.createUISourceCode(n,e.ResourceType.resourceTypes.SourceMapScript),y.setInitialFrameAttribution(o,t.frameId),this.uiSourceCodeToScripts.set(o,[t]);const i=new r.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(n,e.ResourceType.resourceTypes.SourceMapScript,s),a=e.ResourceType.ResourceType.mimeFromURL(n)||"text/javascript";this.project.addUISourceCodeWithProvider(o,i,null,a)}}}removeScript(e){this.uiSourceCodeToScripts.forEach((t,o)=>{t=t.filter(t=>t!==e),0===t.length?(this.uiSourceCodeToScripts.delete(o),this.project.removeUISourceCode(o.url())):this.uiSourceCodeToScripts.set(o,t)})}dispose(){this.project.dispose()}getProject(){return this.project}};var ye=Object.freeze({__proto__:null,DebuggerLanguagePluginManager:Ie,ExtensionRemoteObject:Re,SourceScope:ve});class Fe{#l;#w;#g;#Z;#ee;constructor(e,t,o){Ue.add(this),this.#l=o,this.#w=new C(t,"debugger:"+e.target().id(),n.Workspace.projectTypes.Debugger,"",!0),this.#g=[e.addEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),e.addEventListener(r.DebuggerModel.Events.ParsedScriptSource,this.parsedScriptSource,this),e.addEventListener(r.DebuggerModel.Events.DiscardedAnonymousScriptSource,this.discardedScriptSource,this)],this.#Z=new Map,this.#ee=new Map}static createV8ScriptURL(t){const o=e.ParsedURL.ParsedURL.extractName(t.sourceURL);return"debugger:///VM"+t.scriptId+(o?" "+o:"")}static scriptForUISourceCode(e){for(const t of Ue){const o=t.#Z.get(e);if(void 0!==o)return o}return null}uiSourceCodeForScript(e){return this.#ee.get(e)??null}rawLocationToUILocation(e){const t=e.script();if(!t)return null;const o=this.#ee.get(t);if(!o)return null;const{lineNumber:r,columnNumber:s}=t.rawLocationToRelativeLocation(e);return o.uiLocation(r,s)}uiLocationToRawLocations(e,t,o){const r=this.#Z.get(e);return r?(({lineNumber:t,columnNumber:o}=r.relativeLocationToRawLocation({lineNumber:t,columnNumber:o})),[r.debuggerModel.createRawLocation(r,t,o??0)]):[]}uiLocationRangeToRawLocationRanges(e,{startLine:t,startColumn:o,endLine:r,endColumn:s}){const n=this.#Z.get(e);if(!n)return[];({lineNumber:t,columnNumber:o}=n.relativeLocationToRawLocation({lineNumber:t,columnNumber:o})),({lineNumber:r,columnNumber:s}=n.relativeLocationToRawLocation({lineNumber:r,columnNumber:s}));return[{start:n.debuggerModel.createRawLocation(n,t,o),end:n.debuggerModel.createRawLocation(n,r,s)}]}parsedScriptSource(t){const o=t.data,r=Fe.createV8ScriptURL(o),s=this.#w.createUISourceCode(r,e.ResourceType.resourceTypes.Script);o.isBreakpointCondition&&s.markAsUnconditionallyIgnoreListed(),this.#Z.set(s,o),this.#ee.set(o,s),this.#w.addUISourceCodeWithProvider(s,o,null,"text/javascript"),this.#l.updateLocations(o)}discardedScriptSource(e){const t=e.data,o=this.#ee.get(t);void 0!==o&&(this.#ee.delete(t),this.#Z.delete(o),this.#w.removeUISourceCode(o.url()))}globalObjectCleared(){this.#ee.clear(),this.#Z.clear(),this.#w.reset()}dispose(){Ue.delete(this),e.EventTarget.removeEventListeners(this.#g),this.globalObjectCleared(),this.#w.dispose()}}const Ue=new Set;var Pe=Object.freeze({__proto__:null,DefaultScriptMapping:Fe});const je={liveEditFailed:"`LiveEdit` failed: {PH1}",liveEditCompileFailed:"`LiveEdit` compile failed: {PH1}"},De=i.i18n.registerUIStrings("models/bindings/ResourceScriptMapping.ts",je),Ne=i.i18n.getLocalizedString.bind(void 0,De);class ke{debuggerModel;#K;debuggerWorkspaceBinding;#te;#h;#ee;#g;constructor(e,t,o){this.debuggerModel=e,this.#K=t,this.debuggerWorkspaceBinding=o,this.#te=new Map,this.#h=new Map,this.#ee=new Map;const s=e.runtimeModel();this.#g=[this.debuggerModel.addEventListener(r.DebuggerModel.Events.ParsedScriptSource,e=>this.addScript(e.data),this),this.debuggerModel.addEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),s.addEventListener(r.RuntimeModel.Events.ExecutionContextDestroyed,this.executionContextDestroyed,this),s.target().targetManager().addEventListener("InspectedURLChanged",this.inspectedURLChanged,this)]}project(e){const t=(e.isContentScript()?"js:extensions:":"js::")+this.debuggerModel.target().id()+":"+e.frameId;let o=this.#h.get(t);if(!o){const r=e.isContentScript()?n.Workspace.projectTypes.ContentScripts:n.Workspace.projectTypes.Network;o=new C(this.#K,t,r,"",!1),y.setTargetForProject(o,this.debuggerModel.target()),this.#h.set(t,o)}return o}uiSourceCodeForScript(e){return this.#ee.get(e)??null}rawLocationToUILocation(e){const t=e.script();if(!t)return null;const o=this.#ee.get(t);if(!o)return null;const r=this.#te.get(o);if(!r)return null;if(r.hasDivergedFromVM()&&!r.isMergingToVM()||r.isDivergingFromVM())return null;if(r.script!==t)return null;const{lineNumber:s,columnNumber:n=0}=e;return o.uiLocation(s,n)}uiLocationToRawLocations(e,t,o){const r=this.#te.get(e);if(!r)return[];const{script:s}=r;return s?[this.debuggerModel.createRawLocation(s,t,o)]:[]}uiLocationRangeToRawLocationRanges(e,{startLine:t,startColumn:o,endLine:r,endColumn:s}){const n=this.#te.get(e);if(!n)return null;const{script:i}=n;if(!i)return null;return[{start:this.debuggerModel.createRawLocation(i,t,o),end:this.debuggerModel.createRawLocation(i,r,s)}]}inspectedURLChanged(e){for(let t=this.debuggerModel.target();t!==e.data;t=t.parentTarget())if(null===t)return;for(const e of Array.from(this.#ee.keys()))this.removeScripts([e]),this.addScript(e)}addScript(t){if(t.isLiveEdit()||t.isBreakpointCondition)return;let o=t.sourceURL;if(!o)return;if(t.hasSourceURL)o=r.SourceMapManager.SourceMapManager.resolveRelativeSourceURL(t.debuggerModel.target(),o);else{if(t.isInlineScript())return;if(t.isContentScript()){if(!new e.ParsedURL.ParsedURL(o).isValid)return}}const s=this.project(t),n=s.uiSourceCodeForURL(o);if(n){const e=this.#te.get(n);e?.script&&this.removeScripts([e.script])}const i=t.originalContentProvider(),a=s.createUISourceCode(o,i.contentType());y.setInitialFrameAttribution(a,t.frameId);const c=ee(this.debuggerModel.target(),t.frameId,o),u=new Ee(this,a,t);this.#te.set(a,u),this.#ee.set(t,a);const l=t.isWasm()?"application/wasm":"text/javascript";s.addUISourceCodeWithProvider(a,i,c,l),this.debuggerWorkspaceBinding.updateLocations(t)}scriptFile(e){return this.#te.get(e)||null}removeScripts(e){const o=new t.MapUtilities.Multimap;for(const t of e){const e=this.#ee.get(t);if(!e)continue;const r=this.#te.get(e);r&&r.dispose(),this.#te.delete(e),this.#ee.delete(t),o.set(e.project(),e),this.debuggerWorkspaceBinding.updateLocations(t)}for(const e of o.keysArray()){const t=o.get(e);let r=!0;for(const o of e.uiSourceCodes())if(!t.has(o)){r=!1;break}r?(this.#h.delete(e.id()),e.removeProject()):t.forEach(t=>e.removeUISourceCode(t.url()))}}executionContextDestroyed(e){const t=e.data;this.removeScripts(this.debuggerModel.scriptsForExecutionContext(t))}globalObjectCleared(){const e=Array.from(this.#ee.keys());this.removeScripts(e)}resetForTest(){this.globalObjectCleared()}dispose(){e.EventTarget.removeEventListeners(this.#g),this.globalObjectCleared()}}class Ee extends e.ObjectWrapper.ObjectWrapper{#oe;uiSourceCode;script;#re;#se;#ne;#ie;#ae=new e.Mutex.Mutex;constructor(e,t,o){super(),this.#oe=e,this.uiSourceCode=t,this.script=this.uiSourceCode.contentType().isScript()?o:null,this.uiSourceCode.addEventListener(n.UISourceCode.Events.WorkingCopyChanged,this.workingCopyChanged,this),this.uiSourceCode.addEventListener(n.UISourceCode.Events.WorkingCopyCommitted,this.workingCopyCommitted,this)}isDiverged(){if(this.uiSourceCode.isDirty())return!0;if(!this.script)return!1;if(void 0===this.#re||null===this.#re)return!1;const e=this.uiSourceCode.workingCopy();if(!e)return!1;if(!e.startsWith(this.#re.trimEnd()))return!0;const t=this.uiSourceCode.workingCopy().substr(this.#re.length);return Boolean(t.length)&&!t.match(r.Script.sourceURLRegex)}workingCopyChanged(){this.update()}workingCopyCommitted(){if(!1===a.Runtime.hostConfig.devToolsLiveEdit?.enabled)return;if(this.uiSourceCode.project().canSetFileContent())return;if(!this.script)return;const e=this.uiSourceCode.workingCopy();this.script.editSource(e).then(({status:t,exceptionDetails:o})=>{this.scriptSourceWasSet(e,t,o)})}async scriptSourceWasSet(t,o,r){if("Ok"===o&&(this.#re=t),await this.update(),"Ok"===o)return;if(!r)return void e.Console.Console.instance().addMessage(Ne(je.liveEditFailed,{PH1:function(e){switch(e){case"BlockedByActiveFunction":return"Functions that are on the stack (currently being executed) can not be edited";case"BlockedByActiveGenerator":return"Async functions/generators that are active can not be edited";case"BlockedByTopLevelEsModuleChange":return"The top-level of ES modules can not be edited";case"CompileError":case"Ok":throw new Error("Compile errors and Ok status must not be reported on the console")}}(o)}),"warning");const s=Ne(je.liveEditCompileFailed,{PH1:r.text});this.uiSourceCode.addLineMessage("Error",s,r.lineNumber,r.columnNumber)}async update(){const e=await this.#ae.acquire(),t=this.isDiverged();t&&!this.#ne?await this.divergeFromVM():!t&&this.#ne&&await this.mergeToVM(),e()}async divergeFromVM(){this.script&&(this.#se=!0,await this.#oe.debuggerWorkspaceBinding.updateLocations(this.script),this.#se=void 0,this.#ne=!0,this.dispatchEventToListeners(Ee.Events.DID_DIVERGE_FROM_VM,this.uiSourceCode))}async mergeToVM(){this.script&&(this.#ne=void 0,this.#ie=!0,await this.#oe.debuggerWorkspaceBinding.updateLocations(this.script),this.#ie=void 0,this.dispatchEventToListeners(Ee.Events.DID_MERGE_TO_VM,this.uiSourceCode))}hasDivergedFromVM(){return Boolean(this.#ne)}isDivergingFromVM(){return Boolean(this.#se)}isMergingToVM(){return Boolean(this.#ie)}checkMapping(){this.script&&void 0===this.#re?this.script.requestContentData().then(e=>{this.#re=s.ContentData.ContentData.textOr(e,null),this.update().then(()=>this.mappingCheckedForTest())}):this.mappingCheckedForTest()}mappingCheckedForTest(){}dispose(){this.uiSourceCode.removeEventListener(n.UISourceCode.Events.WorkingCopyChanged,this.workingCopyChanged,this),this.uiSourceCode.removeEventListener(n.UISourceCode.Events.WorkingCopyCommitted,this.workingCopyCommitted,this)}addSourceMapURL(e){this.script&&this.script.debuggerModel.setSourceMapURL(this.script,e)}addDebugInfoURL(e){if(!this.script)return;const{pluginManager:t}=Ae.instance();t.setDebugInfoURL(this.script,e)}hasSourceMapURL(){return Boolean(this.script?.sourceMapURL)}async missingSymbolFiles(){if(!this.script)return null;const{pluginManager:e}=this.#oe.debuggerWorkspaceBinding,t=await e.getSourcesForScript(this.script);return t&&"missingSymbolFiles"in t?t.missingSymbolFiles:null}}!function(e){let t;!function(e){e.DID_MERGE_TO_VM="DidMergeToVM",e.DID_DIVERGE_FROM_VM="DidDivergeFromVM"}(t=e.Events||(e.Events={}))}(Ee||(Ee={}));var Oe=Object.freeze({__proto__:null,get ResourceScriptFile(){return Ee},ResourceScriptMapping:ke});let xe;class Ae{resourceMapping;#Y;#E;pluginManager;constructor(e,t,o){this.resourceMapping=e,this.#Y=new Map,t.addModelListener(r.DebuggerModel.DebuggerModel,r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),t.addModelListener(r.DebuggerModel.DebuggerModel,r.DebuggerModel.Events.DebuggerResumed,this.debuggerResumed,this),t.observeModels(r.DebuggerModel.DebuggerModel,this),o.addEventListener("IGNORED_SCRIPT_RANGES_UPDATED",e=>this.updateLocations(e.data)),this.#E=new Set,this.pluginManager=new Ie(t,e.workspace,this)}setFunctionRanges(e,t){for(const o of this.#Y.values())o.compilerMapping.setFunctionRanges(e,t)}static instance(e={forceNew:null,resourceMapping:null,targetManager:null,ignoreListManager:null}){const{forceNew:t,resourceMapping:o,targetManager:r,ignoreListManager:s}=e;if(!xe||t){if(!o||!r||!s)throw new Error(`Unable to create DebuggerWorkspaceBinding: resourceMapping, targetManager and IgnoreLIstManager must be provided: ${(new Error).stack}`);xe=new Ae(o,r,s)}return xe}static removeInstance(){xe=void 0}async computeAutoStepRanges(e,t){function o(e,t){const{start:o,end:r}=t;return o.scriptId===e.scriptId&&(!(e.lineNumber<o.lineNumber||e.lineNumber>r.lineNumber)&&(!(e.lineNumber===o.lineNumber&&e.columnNumber<o.columnNumber)&&!(e.lineNumber===r.lineNumber&&e.columnNumber>=r.columnNumber)))}const r=t.location();if(!r)return[];const s=this.pluginManager;let n=[];if("StepOut"===e)return await s.getInlinedFunctionRanges(r);const i=await s.rawLocationToUILocation(r);if(i)return n=await s.uiLocationToRawLocationRanges(i.uiSourceCode,i.lineNumber,i.columnNumber)||[],n=n.filter(e=>o(r,e)),"StepOver"===e&&(n=n.concat(await s.getInlinedCalleesRanges(r))),n;const a=this.#Y.get(r.debuggerModel)?.compilerMapping;return a?(n=a.getLocationRangesForSameSourceLocation(r),n=n.filter(e=>o(r,e)),n):[]}modelAdded(e){e.setBeforePausedCallback(this.shouldPause.bind(this)),this.#Y.set(e,new We(e,this)),e.setComputeAutoStepRangesCallback(this.computeAutoStepRanges.bind(this))}modelRemoved(e){e.setComputeAutoStepRangesCallback(null);const t=this.#Y.get(e);t&&(t.dispose(),this.#Y.delete(e))}async pendingLiveLocationChangesPromise(){await Promise.all(this.#E)}recordLiveLocationChange(e){e.then(()=>{this.#E.delete(e)}),this.#E.add(e)}async updateLocations(e){const t=[e.target().model(f.StackTraceModel)?.scriptInfoChanged(e,this.#ce.bind(this))],o=this.#Y.get(e.debuggerModel);if(o){const r=o.updateLocations(e);this.recordLiveLocationChange(r),t.push(r)}await Promise.all(t)}async createStackTraceFromProtocolRuntime(e,t){const o=t.model(f.StackTraceModel);return await o.createFromProtocolRuntime(e,this.#ce.bind(this))}async createLiveLocation(e,t,o){const r=this.#Y.get(e.debuggerModel);if(!r)return null;const s=r.createLiveLocation(e,t,o);return this.recordLiveLocationChange(s),await s}async createStackTraceTopFrameLiveLocation(e,t,o){console.assert(e.length>0);const r=Be.createStackTraceTopFrameLocation(e,this,t,o);return this.recordLiveLocationChange(r),await r}async createCallFrameLiveLocation(e,t,o){if(!e.script())return null;const r=e.debuggerModel,s=this.createLiveLocation(e,t,o);this.recordLiveLocationChange(s);const n=await s;return n?(this.registerCallFrameLiveLocation(r,n),n):null}async rawLocationToUILocation(e){const t=await this.pluginManager.rawLocationToUILocation(e);if(t)return t;const o=this.#Y.get(e.debuggerModel);return o?o.rawLocationToUILocation(e):null}uiSourceCodeForSourceMapSourceURL(e,t,o){const r=this.#Y.get(e);return r?r.compilerMapping.uiSourceCodeForURL(t,o):null}async uiSourceCodeForSourceMapSourceURLPromise(e,t,o){const r=this.uiSourceCodeForSourceMapSourceURL(e,t,o);return await(r||this.waitForUISourceCodeAdded(t,e.target()))}async uiSourceCodeForDebuggerLanguagePluginSourceURLPromise(e,t){const o=this.pluginManager.uiSourceCodeForURL(e,t);return await(o||this.waitForUISourceCodeAdded(t,e.target()))}uiSourceCodeForScript(e){const t=this.#Y.get(e.debuggerModel);return t?t.uiSourceCodeForScript(e):null}waitForUISourceCodeAdded(e,t){return new Promise(o=>{const r=n.Workspace.WorkspaceImpl.instance(),s=r.addEventListener(n.Workspace.Events.UISourceCodeAdded,i=>{const a=i.data;a.url()===e&&y.targetForUISourceCode(a)===t&&(r.removeEventListener(n.Workspace.Events.UISourceCodeAdded,s.listener),o(a))})})}async uiLocationToRawLocations(e,t,o){const r=await this.pluginManager.uiLocationToRawLocations(e,t,o);if(r)return r;for(const r of this.#Y.values()){const s=r.uiLocationToRawLocations(e,t,o);if(s.length)return s}return[]}async uiLocationRangeToRawLocationRanges(e,t){const o=await this.pluginManager.uiLocationRangeToRawLocationRanges(e,t);if(o)return o;for(const o of this.#Y.values()){const r=o.uiLocationRangeToRawLocationRanges(e,t);if(r)return r}return[]}async normalizeUILocation(e){const t=await this.uiLocationToRawLocations(e.uiSourceCode,e.lineNumber,e.columnNumber);for(const e of t){const t=await this.rawLocationToUILocation(e);if(t)return t}return e}async getMappedLines(e){for(const t of this.#Y.values()){const o=t.getMappedLines(e);if(null!==o)return o}return await this.pluginManager.getMappedLines(e)}scriptFile(e,t){const o=this.#Y.get(t);return o?o.getResourceScriptMapping().scriptFile(e):null}scriptsForUISourceCode(e){const t=new Set;this.pluginManager.scriptsForUISourceCode(e).forEach(e=>t.add(e));for(const o of this.#Y.values()){const r=o.getResourceScriptMapping().scriptFile(e);r?.script&&t.add(r.script),o.compilerMapping.scriptsForUISourceCode(e).forEach(e=>t.add(e))}return[...t]}supportsConditionalBreakpoints(e){return this.pluginManager.scriptsForUISourceCode(e).every(e=>e.isJavaScript())}globalObjectCleared(e){this.reset(e.data)}reset(e){const t=this.#Y.get(e);if(t){for(const e of t.callFrameLocations.values())this.removeLiveLocation(e);t.callFrameLocations.clear()}}resetForTest(e){const t=e.model(r.DebuggerModel.DebuggerModel),o=this.#Y.get(t);o&&o.getResourceScriptMapping().resetForTest()}registerCallFrameLiveLocation(e,t){const o=this.#Y.get(e);if(o){o.callFrameLocations.add(t)}}removeLiveLocation(e){const t=this.#Y.get(e.rawLocation.debuggerModel);t&&t.disposeLocation(e)}debuggerResumed(e){this.reset(e.data)}async shouldPause(t,o){const{callFrames:[r]}=t;if(!r)return!1;const s=r.functionLocation();if(!(o&&"step"===t.reason&&s&&r.script.isWasm()&&e.Settings.moduleSetting("wasm-auto-stepping").get()&&this.pluginManager.hasPluginForScript(r.script)))return!0;return!!await this.pluginManager.rawLocationToUILocation(r.location())||(o.script()!==s.script()||o.columnNumber!==s.columnNumber||o.lineNumber!==s.lineNumber)}async#ce(e,t){const o=e.slice(0),r=[];for(;o.length;)await this.#ue(o,r,t);return r}async#ue(e,t,o){if(await this.pluginManager.translateRawFramesStep(e,t,o))return;const s=this.#Y.get(o.model(r.DebuggerModel.DebuggerModel));if(s)return void s.translateRawFramesStep(e,t);const n=e.shift(),{url:i,lineNumber:a,columnNumber:c,functionName:u}=n;t.push([{url:i,line:a,column:c,name:u}])}}class We{#f;#l;callFrameLocations;#le;#N;#oe;compilerMapping;#C;constructor(e,o){this.#f=e,this.#l=o,this.callFrameLocations=new Set;const{workspace:r}=o.resourceMapping;this.#le=new Fe(e,r,o),this.#N=o.resourceMapping,this.#oe=new ke(e,r,o),this.compilerMapping=new j(e,r,o),this.#C=new t.MapUtilities.Multimap}async createLiveLocation(e,t,o){console.assert(""!==e.scriptId);const r=e.scriptId,s=new _e(r,e,this.#l,t,o);return this.#C.set(r,s),await s.update(),s}disposeLocation(e){this.#C.delete(e.scriptId,e)}async updateLocations(e){const t=[];for(const o of this.#C.get(e.scriptId))t.push(o.update());await Promise.all(t)}rawLocationToUILocation(e){let t=this.compilerMapping.rawLocationToUILocation(e);return t=t||this.#oe.rawLocationToUILocation(e),t=t||this.#N.jsLocationToUILocation(e),t=t||this.#le.rawLocationToUILocation(e),t}uiSourceCodeForScript(e){let t=null;return t=t||this.#oe.uiSourceCodeForScript(e),t=t||this.#N.uiSourceCodeForScript(e),t=t||this.#le.uiSourceCodeForScript(e),t}uiLocationToRawLocations(e,t,o=0){let r=this.compilerMapping.uiLocationToRawLocations(e,t,o);return r=r.length?r:this.#oe.uiLocationToRawLocations(e,t,o),r=r.length?r:this.#N.uiLocationToJSLocations(e,t,o),r=r.length?r:this.#le.uiLocationToRawLocations(e,t,o),r}uiLocationRangeToRawLocationRanges(e,t){let o=this.compilerMapping.uiLocationRangeToRawLocationRanges(e,t);return o??=this.#oe.uiLocationRangeToRawLocationRanges(e,t),o??=this.#N.uiLocationRangeToJSLocationRanges(e,t),o??=this.#le.uiLocationRangeToRawLocationRanges(e,t),o}translateRawFramesStep(e,t){this.compilerMapping.translateRawFramesStep(e,t)||this.#de(e,t)}#de(e,t){const o=e.shift(),{scriptId:r,url:s,lineNumber:n,columnNumber:i,functionName:a}=o,c=r?this.#f.createRawLocationByScriptId(r,n,i):s?this.#f.createRawLocationByURL(s,n,i):null;if(c){const e=this.rawLocationToUILocation(c);if(e)return void t.push([{uiSourceCode:e.uiSourceCode,name:a,line:e.lineNumber,column:e.columnNumber??-1}])}t.push([{url:s,line:n,column:i,name:a}])}getMappedLines(e){return this.compilerMapping.getMappedLines(e)}dispose(){this.#f.setBeforePausedCallback(null),this.compilerMapping.dispose(),this.#oe.dispose(),this.#le.dispose()}getResourceScriptMapping(){return this.#oe}}class _e extends N{scriptId;rawLocation;#pe;constructor(e,t,o,r,s){super(r,s),this.scriptId=e,this.rawLocation=t,this.#pe=o}async uiLocation(){const e=this.rawLocation;return await this.#pe.rawLocationToUILocation(e)}dispose(){super.dispose(),this.#pe.removeLiveLocation(this)}}class Be extends N{#ge;#he;#C;constructor(e,t){super(e,t),this.#ge=!0,this.#he=null,this.#C=null}static async createStackTraceTopFrameLocation(e,t,o,r){const s=new Be(o,r),n=e.map(e=>t.createLiveLocation(e,s.scheduleUpdate.bind(s),r));return s.#C=(await Promise.all(n)).filter(e=>!!e),await s.updateLocation(),s}async uiLocation(){return this.#he?await this.#he.uiLocation():null}dispose(){if(super.dispose(),this.#C)for(const e of this.#C)e.dispose();this.#C=null,this.#he=null}async scheduleUpdate(){this.#ge||(this.#ge=!0,queueMicrotask(()=>{this.updateLocation()}))}async updateLocation(){if(this.#ge=!1,this.#C&&0!==this.#C.length){this.#he=this.#C[0];for(const e of this.#C){const t=await e.uiLocation();if(!t?.isIgnoreListed()){this.#he=e;break}}this.update()}}}var He=Object.freeze({__proto__:null,DebuggerWorkspaceBinding:Ae,Location:_e});class ze{#me;#Se;#fe;#Me;#be;#Le;#Ce;#we;#ve;#Re;#Ie;#Te;constructor(e,t,o){this.#me=e,this.#Se=e.size,this.#fe=0,this.#be=t||Number.MAX_VALUE,this.#Le=o,this.#Ce=new TextDecoder,this.#we=!1,this.#ve=null,this.#Me=null}async read(t){if(this.#Le&&this.#Le(this),this.#me?.type.endsWith("gzip")){const t=this.#me.stream(),o=e.Gzip.decompressStream(t);this.#Me=o.getReader()}else this.#Te=new FileReader,this.#Te.onload=this.onChunkLoaded.bind(this),this.#Te.onerror=this.onError.bind(this);return this.#Ie=t,this.loadChunk(),await new Promise(e=>{this.#Re=e})}cancel(){this.#we=!0}loadedSize(){return this.#fe}fileSize(){return this.#Se}fileName(){return this.#me?this.#me.name:""}error(){return this.#ve}onChunkLoaded(e){if(this.#we)return;if(e.target.readyState!==FileReader.DONE)return;if(!this.#Te)return;const t=this.#Te.result;this.#fe+=t.byteLength;const o=this.#fe===this.#Se;this.decodeChunkBuffer(t,o)}async decodeChunkBuffer(e,t){if(!this.#Ie)return;const o=this.#Ce.decode(e,{stream:!t});await this.#Ie.write(o,t),this.#we||(this.#Le&&this.#Le(this),t?this.finishRead():this.loadChunk())}async finishRead(){this.#Ie&&(this.#me=null,this.#Te=null,await this.#Ie.close(),this.#Re(!this.#ve))}async loadChunk(){if(this.#Ie&&this.#me){if(this.#Me){const{value:e,done:t}=await this.#Me.read();if(t||!e)return await this.#Ie.write("",!0),await this.finishRead();this.decodeChunkBuffer(e.buffer,!1)}if(this.#Te){const e=this.#fe,t=Math.min(this.#Se,e+this.#be),o=this.#me.slice(e,t);this.#Te.readAsArrayBuffer(o)}}}onError(e){const t=e.target;this.#ve=t.error,this.#Re(!1)}}var Ve=Object.freeze({__proto__:null,ChunkedFileReader:ze,FileOutputStream:class{#ye;#Fe;#Ue;constructor(){this.#ye=[]}async open(e){this.#Ue=!1,this.#ye=[],this.#Fe=e;const t=await n.FileManager.FileManager.instance().save(this.#Fe,s.ContentData.EMPTY_TEXT_CONTENT_DATA,!0);return t&&n.FileManager.FileManager.instance().addEventListener("AppendedToURL",this.onAppendDone,this),Boolean(t)}write(e){return new Promise(t=>{this.#ye.push(t),n.FileManager.FileManager.instance().append(this.#Fe,e)})}async close(){this.#Ue=!0,this.#ye.length||(n.FileManager.FileManager.instance().removeEventListener("AppendedToURL",this.onAppendDone,this),n.FileManager.FileManager.instance().close(this.#Fe))}onAppendDone(e){if(e.data!==this.#Fe)return;const t=this.#ye.shift();t&&t(),this.#ye.length||this.#Ue&&(n.FileManager.FileManager.instance().removeEventListener("AppendedToURL",this.onAppendDone,this),n.FileManager.FileManager.instance().close(this.#Fe))}}});class qe{#Pe=new WeakMap;constructor(){r.TargetManager.TargetManager.instance().observeModels(r.DebuggerModel.DebuggerModel,this),r.TargetManager.TargetManager.instance().observeModels(r.CSSModel.CSSModel,this)}modelAdded(e){const t=e.target(),o=this.#Pe.get(t)??new $e;e instanceof r.DebuggerModel.DebuggerModel?o.setDebuggerModel(e):o.setCSSModel(e),this.#Pe.set(t,o)}modelRemoved(e){const t=e.target(),o=this.#Pe.get(t);o?.clear()}addMessage(e,t,o){const r=this.#Pe.get(o);r?.addMessage(e,t)}clear(){for(const e of r.TargetManager.TargetManager.instance().targets()){const t=this.#Pe.get(e);t?.clear()}}}class $e{#f;#T;#je=new Map;#b;constructor(){this.#b=new k,n.Workspace.WorkspaceImpl.instance().addEventListener(n.Workspace.Events.UISourceCodeAdded,this.#De.bind(this))}setDebuggerModel(e){if(this.#f)throw new Error("Cannot set DebuggerModel twice");this.#f=e,e.addEventListener(r.DebuggerModel.Events.ParsedScriptSource,e=>{queueMicrotask(()=>{this.#Ne(e)})}),e.addEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.#ke,this)}setCSSModel(e){if(this.#T)throw new Error("Cannot set CSSModel twice");this.#T=e,e.addEventListener(r.CSSModel.Events.StyleSheetAdded,e=>queueMicrotask(()=>this.#Ee(e)))}async addMessage(e,t){const o=new Je(e,this.#b),r=this.#Oe(t)??this.#xe(t)??this.#Ae(t);if(r&&await o.updateLocationSource(r),t.url){let e=this.#je.get(t.url);e||(e=[],this.#je.set(t.url,e)),e.push({source:t,presentation:o})}}#Ae(e){if(!e.url)return null;const t=n.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e.url);return t?new n.UISourceCode.UILocation(t,e.line,e.column):null}#xe(e){if(!this.#T||!e.url)return null;return this.#T.createRawLocationsByURL(e.url,e.line,e.column)[0]??null}#Oe(e){if(!this.#f)return null;if(e.scriptId)return this.#f.createRawLocationByScriptId(e.scriptId,e.line,e.column);const t=e.stackTrace?.callFrames?e.stackTrace.callFrames[0]:null;return t?this.#f.createRawLocationByScriptId(t.scriptId,t.lineNumber,t.columnNumber):e.url?this.#f.createRawLocationByURL(e.url,e.line,e.column):null}#Ne(e){const t=e.data,o=this.#je.get(t.sourceURL),r=[];for(const{presentation:e,source:s}of o??[]){const o=this.#Oe(s);o&&t.scriptId===o.scriptId&&r.push(e.updateLocationSource(o))}Promise.all(r).then(this.parsedScriptSourceForTest.bind(this))}parsedScriptSourceForTest(){}#De(e){const t=e.data,o=this.#je.get(t.url()),r=[];for(const{presentation:e,source:s}of o??[])r.push(e.updateLocationSource(new n.UISourceCode.UILocation(t,s.line,s.column)));Promise.all(r).then(this.uiSourceCodeAddedForTest.bind(this))}uiSourceCodeAddedForTest(){}#Ee(e){const t=e.data,o=this.#je.get(t.sourceURL),s=[];for(const{source:e,presentation:n}of o??[])t.containsLocation(e.line,e.column)&&s.push(n.updateLocationSource(new r.CSSModel.CSSLocation(t,e.line,e.column)));Promise.all(s).then(this.styleSheetAddedForTest.bind(this))}styleSheetAddedForTest(){}clear(){this.#ke()}#ke(){const e=Array.from(this.#je.values()).flat();for(const{presentation:t}of e)t.dispose();this.#je.clear(),this.#b.disposeAll()}}class Ge extends N{#Ae;constructor(e,t,o){super(t,o),this.#Ae=e}async uiLocation(){return this.#Ae}}class Je{#We;#_e;#b;#Be;constructor(e,t){this.#Be=e,this.#b=t}async updateLocationSource(e){e instanceof r.DebuggerModel.Location?await Ae.instance().createLiveLocation(e,this.#He.bind(this),this.#b):e instanceof r.CSSModel.CSSLocation?await le.instance().createLiveLocation(e,this.#He.bind(this),this.#b):e instanceof n.UISourceCode.UILocation&&(this.#_e||(this.#_e=new Ge(e,this.#He.bind(this),this.#b),await this.#_e.update()))}async#He(e){this.#We&&this.#We.removeMessage(this.#Be),e!==this.#_e&&(this.#We?.removeMessage(this.#Be),this.#_e?.dispose(),this.#_e=e);const t=await e.uiLocation();t&&(this.#Be.range=s.TextRange.TextRange.createFromLocation(t.lineNumber,t.columnNumber||0),this.#We=t.uiSourceCode,this.#We.addMessage(this.#Be))}dispose(){this.#We?.removeMessage(this.#Be),this.#_e?.dispose()}}var Ke=Object.freeze({__proto__:null,PresentationConsoleMessageManager:class{#ze=new qe;constructor(){r.TargetManager.TargetManager.instance().addModelListener(r.ConsoleModel.ConsoleModel,r.ConsoleModel.Events.MessageAdded,e=>this.consoleMessageAdded(e.data)),r.ConsoleModel.ConsoleModel.allMessagesUnordered().forEach(this.consoleMessageAdded,this),r.TargetManager.TargetManager.instance().addModelListener(r.ConsoleModel.ConsoleModel,r.ConsoleModel.Events.ConsoleCleared,()=>this.#ze.clear())}consoleMessageAdded(e){const t=e.runtimeModel();if(!e.isErrorOrWarning()||!e.runtimeModel()||"violation"===e.source||!t)return;const o="error"===e.level?"Error":"Warning";this.#ze.addMessage(new n.UISourceCode.Message(o,e.messageText),e,t.target())}},PresentationSourceFrameMessage:Je,PresentationSourceFrameMessageHelper:$e,PresentationSourceFrameMessageManager:qe});const Xe=new WeakMap,Ye=new WeakMap,Qe=new WeakSet;function Ze(e){return new s.TextRange.TextRange(e.lineOffset,e.columnOffset,e.endLine,e.endColumn)}function et(e){return new s.TextRange.TextRange(e.startLine,e.startColumn,e.endLine,e.endColumn)}class tt{project;#v=new Map;#T;#g;constructor(e,t){const o=t.target();this.project=new C(e,"resources:"+o.id(),n.Workspace.projectTypes.Network,"",!1),y.setTargetForProject(this.project,o);const s=o.model(r.CSSModel.CSSModel);console.assert(Boolean(s)),this.#T=s;for(const e of t.frames())for(const t of e.getResourcesMap().values())this.addResource(t);this.#g=[t.addEventListener(r.ResourceTreeModel.Events.ResourceAdded,this.resourceAdded,this),t.addEventListener(r.ResourceTreeModel.Events.FrameWillNavigate,this.frameWillNavigate,this),t.addEventListener(r.ResourceTreeModel.Events.FrameDetached,this.frameDetached,this),this.#T.addEventListener(r.CSSModel.Events.StyleSheetChanged,e=>{this.styleSheetChanged(e)},this)]}async styleSheetChanged(e){const t=this.#T.styleSheetHeaderForId(e.data.styleSheetId);if(!t||!t.isInline||t.isInline&&t.isMutable)return;const o=this.#v.get(t.resourceURL());o&&await o.styleSheetChanged(t,e.data.edit||null)}acceptsResource(t){const o=t.resourceType();return(o===e.ResourceType.resourceTypes.Image||o===e.ResourceType.resourceTypes.Font||o===e.ResourceType.resourceTypes.Document||o===e.ResourceType.resourceTypes.Manifest||o===e.ResourceType.resourceTypes.Fetch||o===e.ResourceType.resourceTypes.XHR)&&(!(o===e.ResourceType.resourceTypes.Image&&t.mimeType&&!t.mimeType.startsWith("image"))&&(!(o===e.ResourceType.resourceTypes.Font&&t.mimeType&&!t.mimeType.includes("font"))&&(o!==e.ResourceType.resourceTypes.Image&&o!==e.ResourceType.resourceTypes.Font||!e.ParsedURL.schemeIs(t.contentURL(),"data:"))))}resourceAdded(e){this.addResource(e.data)}addResource(e){if(!this.acceptsResource(e))return;let t=this.#v.get(e.url);t?t.addResource(e):(t=new ot(this.project,e),this.#v.set(e.url,t))}removeFrameResources(e){for(const t of e.resources()){if(!this.acceptsResource(t))continue;const e=this.#v.get(t.url);e&&(1===e.resources.size?(e.dispose(),this.#v.delete(t.url)):e.removeResource(t))}}frameWillNavigate(e){this.removeFrameResources(e.data)}frameDetached(e){this.removeFrameResources(e.data.frame)}resetForTest(){for(const e of this.#v.values())e.dispose();this.#v.clear()}dispose(){e.EventTarget.removeEventListeners(this.#g);for(const e of this.#v.values())e.dispose();this.#v.clear(),this.project.removeProject()}getProject(){return this.project}}class ot{resources;#w;#We;#Ve=[];constructor(e,t){this.resources=new Set([t]),this.#w=e,this.#We=this.#w.createUISourceCode(t.url,t.contentType()),Qe.add(this.#We),t.frameId&&y.setInitialFrameAttribution(this.#We,t.frameId),this.#w.addUISourceCodeWithProvider(this.#We,this,te(t),t.mimeType),Promise.all([...this.inlineScripts().map(e=>Ae.instance().updateLocations(e)),...this.inlineStyles().map(e=>le.instance().updateLocations(e))])}inlineStyles(){const e=y.targetForUISourceCode(this.#We),t=[];if(!e)return t;const o=e.model(r.CSSModel.CSSModel);if(o)for(const e of o.getStyleSheetIdsForURL(this.#We.url())){const r=o.styleSheetHeaderForId(e);r&&t.push(r)}return t}inlineScripts(){const e=y.targetForUISourceCode(this.#We);if(!e)return[];const t=e.model(r.DebuggerModel.DebuggerModel);return t?t.scripts().filter(e=>e.embedderName()===this.#We.url()):[]}async styleSheetChanged(e,t){if(this.#Ve.push({stylesheet:e,edit:t}),this.#Ve.length>1)return;const o=await this.#We.requestContentData();s.ContentData.ContentData.isError(o)||await this.innerStyleSheetChanged(o.text),this.#Ve=[]}async innerStyleSheetChanged(e){const t=this.inlineScripts(),o=this.inlineStyles();let r=new s.Text.Text(e);for(const e of this.#Ve){const n=e.edit;if(!n)continue;const i=e.stylesheet,a=Xe.get(i)??et(i),c=n.oldRange.relativeFrom(a.startLine,a.startColumn),u=n.newRange.relativeFrom(a.startLine,a.startColumn);r=new s.Text.Text(r.replaceRange(c,n.newText));const l=[];for(const e of t){const t=Ye.get(e)??Ze(e);t.follows(c)&&(Ye.set(e,t.rebaseAfterTextEdit(c,u)),l.push(Ae.instance().updateLocations(e)))}for(const e of o){const t=Xe.get(e)??et(e);t.follows(c)&&(Xe.set(e,t.rebaseAfterTextEdit(c,u)),l.push(le.instance().updateLocations(e)))}await Promise.all(l)}this.#We.addRevision(r.value())}addResource(e){this.resources.add(e),e.frameId&&y.addFrameAttribution(this.#We,e.frameId)}removeResource(e){this.resources.delete(e),e.frameId&&y.removeFrameAttribution(this.#We,e.frameId)}dispose(){this.#w.removeUISourceCode(this.#We.url()),Promise.all([...this.inlineScripts().map(e=>Ae.instance().updateLocations(e)),...this.inlineStyles().map(e=>le.instance().updateLocations(e))])}firstResource(){return console.assert(this.resources.size>0),this.resources.values().next().value}contentURL(){return this.firstResource().contentURL()}contentType(){return this.firstResource().contentType()}requestContentData(){return this.firstResource().requestContentData()}searchInContent(e,t,o){return this.firstResource().searchInContent(e,t,o)}}var rt=Object.freeze({__proto__:null,ResourceMapping:class{workspace;#k=new Map;constructor(e,t){this.workspace=t,e.observeModels(r.ResourceTreeModel.ResourceTreeModel,this)}modelAdded(e){const t=new tt(this.workspace,e);this.#k.set(e,t)}modelRemoved(e){const t=this.#k.get(e);t&&(t.dispose(),this.#k.delete(e))}infoForTarget(e){const t=e.model(r.ResourceTreeModel.ResourceTreeModel);return t&&this.#k.get(t)||null}uiSourceCodeForScript(e){const t=this.infoForTarget(e.debuggerModel.target());if(!t)return null;return t.getProject().uiSourceCodeForURL(e.sourceURL)}cssLocationToUILocation(e){const t=e.header();if(!t)return null;const o=this.infoForTarget(e.cssModel().target());if(!o)return null;const r=o.getProject().uiSourceCodeForURL(e.url);if(!r)return null;const s=Xe.get(t)??et(t),n=e.lineNumber+s.startLine-t.startLine;let i=e.columnNumber;return e.lineNumber===t.startLine&&(i+=s.startColumn-t.startColumn),r.uiLocation(n,i)}jsLocationToUILocation(e){const t=e.script();if(!t)return null;const o=this.infoForTarget(e.debuggerModel.target());if(!o)return null;const r=t.embedderName();if(!r)return null;const s=o.getProject().uiSourceCodeForURL(r);if(!s)return null;const{startLine:n,startColumn:i}=Ye.get(t)??Ze(t);let{lineNumber:a,columnNumber:c}=e;return a===t.lineOffset&&(c+=i-t.columnOffset),a+=n-t.lineOffset,t.hasSourceURL&&(0===a&&(c+=t.columnOffset),a+=t.lineOffset),s.uiLocation(a,c)}uiLocationToJSLocations(e,t,o){if(!Qe.has(e))return[];const s=y.targetForUISourceCode(e);if(!s)return[];const n=s.model(r.DebuggerModel.DebuggerModel);if(!n)return[];const i=[];for(const r of n.scripts()){if(r.embedderName()!==e.url())continue;const s=Ye.get(r)??Ze(r);if(!s.containsLocation(t,o))continue;let a=t,c=o;r.hasSourceURL&&(a-=s.startLine,0===a&&(c-=s.startColumn)),i.push(n.createRawLocation(r,a,c))}return i}uiLocationRangeToJSLocationRanges(e,t){if(!Qe.has(e))return null;const o=y.targetForUISourceCode(e);if(!o)return null;const s=o.model(r.DebuggerModel.DebuggerModel);if(!s)return null;const n=[];for(const o of s.scripts()){if(o.embedderName()!==e.url())continue;const r=(Ye.get(o)??Ze(o)).intersection(t);if(r.isEmpty())continue;let{startLine:i,startColumn:a,endLine:c,endColumn:u}=r;o.hasSourceURL&&(i-=r.startLine,0===i&&(a-=r.startColumn),c-=r.startLine,0===c&&(u-=r.startColumn));const l=s.createRawLocation(o,i,a),d=s.createRawLocation(o,c,u);n.push({start:l,end:d})}return n}getMappedLines(e){if(!Qe.has(e))return null;const t=y.targetForUISourceCode(e);if(!t)return null;const o=t.model(r.DebuggerModel.DebuggerModel);if(!o)return null;const s=new Set;for(const t of o.scripts()){if(t.embedderName()!==e.url())continue;const{startLine:o,endLine:r}=Ye.get(t)??Ze(t);for(let e=o;e<=r;++e)s.add(e)}return s}uiLocationToCSSLocations(e){if(!Qe.has(e.uiSourceCode))return[];const t=y.targetForUISourceCode(e.uiSourceCode);if(!t)return[];const o=t.model(r.CSSModel.CSSModel);return o?o.createRawLocationsByURL(e.uiSourceCode.url(),e.lineNumber,e.columnNumber):[]}resetForTest(e){const t=e.model(r.ResourceTreeModel.ResourceTreeModel),o=t?this.#k.get(t):null;o&&o.resetForTest()}}});var st=Object.freeze({__proto__:null,TempFile:class{#qe;constructor(){this.#qe=null}write(e){this.#qe&&e.unshift(this.#qe),this.#qe=new Blob(e,{type:"text/plain"})}read(){return this.readRange()}size(){return this.#qe?this.#qe.size:0}async readRange(t,o){if(!this.#qe)return e.Console.Console.instance().error("Attempt to read a temp file that was never written"),"";const r="number"==typeof t||"number"==typeof o?this.#qe.slice(t,o):this.#qe,s=new FileReader;try{await new Promise((e,t)=>{s.onloadend=e,s.onerror=t,s.readAsText(r)})}catch(t){e.Console.Console.instance().error("Failed to read from temp file: "+t.message)}return s.result}async copyToOutputStream(e,t){if(!this.#qe)return e.close(),null;const o=new ze(this.#qe,1e7,t);return await o.read(e).then(e=>e?null:o.error())}remove(){this.#qe=null}}});export{ge as CSSWorkspaceBinding,D as CompilerScriptMapping,w as ContentProviderBasedProject,ye as DebuggerLanguagePlugins,He as DebuggerWorkspaceBinding,Pe as DefaultScriptMapping,Ve as FileUtils,E as LiveLocation,F as NetworkProject,Ke as PresentationConsoleMessageHelper,rt as ResourceMapping,Oe as ResourceScriptMapping,oe as ResourceUtils,W as SASSSourceMapping,ce as StylesSourceMapping,st as TempFile};
//# sourceMappingURL=bindings.js.map