@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 4.06 kB
JavaScript
import*as Common from"../../core/common/common.js";import*as SDK from"../../core/sdk/sdk.js";import*as TextUtils from"../text_utils/text_utils.js";import*as Workspace from"../workspace/workspace.js";import{ContentProviderBasedProject}from"./ContentProviderBasedProject.js";import{CSSWorkspaceBinding}from"./CSSWorkspaceBinding.js";import{NetworkProject}from"./NetworkProject.js";export class SASSSourceMapping{#e;#r;#o;#t;constructor(e,r,o){this.#e=r,this.#r=new ContentProviderBasedProject(o,"cssSourceMaps:"+e.id(),Workspace.Workspace.projectTypes.Network,"",!1),NetworkProject.setTargetForProject(this.#r,e),this.#t=new Map,this.#o=[this.#e.addEventListener(SDK.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),this.#e.addEventListener(SDK.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)]}sourceMapAttachedForTest(e){}async sourceMapAttached(e){const r=e.data.client,o=e.data.sourceMap,t=this.#r,i=this.#t;for(const e of o.sourceURLs()){let s=i.get(e);s||(s=new Binding(t,e,r.createPageResourceLoadInitiator()),i.set(e,s)),s.addSourceMap(o,r.frameId)}await CSSWorkspaceBinding.instance().updateLocations(r),this.sourceMapAttachedForTest(o)}async sourceMapDetached(e){const r=e.data.client,o=e.data.sourceMap,t=this.#t;for(const e of o.sourceURLs()){const i=t.get(e);i&&(i.removeSourceMap(o,r.frameId),i.getUiSourceCode()||t.delete(e))}await CSSWorkspaceBinding.instance().updateLocations(r)}rawLocationToUILocation(e){const r=e.header();if(!r)return null;const o=this.#e.sourceMapForClient(r);if(!o)return null;let{lineNumber:t,columnNumber:i}=e;o.mapsOrigin()&&r.isInline&&(t-=r.startLine,0===t&&(i-=r.startColumn));const s=o.findEntry(t,i);if(!s||!s.sourceURL)return null;const n=this.#r.uiSourceCodeForURL(s.sourceURL);return n?n.uiLocation(s.sourceLineNumber,s.sourceColumnNumber):null}uiLocationToRawLocations(e){const{uiSourceCode:r,lineNumber:o,columnNumber:t=0}=e,i=uiSourceCodeToBinding.get(r);if(!i)return[];const s=[];for(const e of i.getReferringSourceMaps()){const i=e.findReverseEntries(r.url(),o,t),n=this.#e.clientForSourceMap(e);n&&s.push(...i.map((e=>new SDK.CSSModel.CSSLocation(n,e.lineNumber,e.columnNumber))))}return s}static uiSourceOrigin(e){const r=uiSourceCodeToBinding.get(e);return r?r.getReferringSourceMaps().map((e=>e.compiledURL())):[]}dispose(){Common.EventTarget.removeEventListeners(this.#o),this.#r.dispose()}}const uiSourceCodeToBinding=new WeakMap;class Binding{#r;#i;#s;referringSourceMaps;uiSourceCode;constructor(e,r,o){this.#r=e,this.#i=r,this.#s=o,this.referringSourceMaps=[],this.uiSourceCode=null}recreateUISourceCodeIfNeeded(e){const r=this.referringSourceMaps[this.referringSourceMaps.length-1],o=Common.ResourceType.resourceTypes.SourceMapStyleSheet,t=r.embeddedContentByURL(this.#i),i=null!==t?TextUtils.StaticContentProvider.StaticContentProvider.fromString(this.#i,o,t):new SDK.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(this.#i,o,this.#s),s=this.#r.createUISourceCode(this.#i,o);uiSourceCodeToBinding.set(s,this);const n=Common.ResourceType.ResourceType.mimeFromURL(this.#i)||o.canonicalMimeType(),c="string"==typeof t?new Workspace.UISourceCode.UISourceCodeMetadata(null,t.length):null;this.uiSourceCode?(NetworkProject.cloneInitialFrameAttribution(this.uiSourceCode,s),this.#r.removeUISourceCode(this.uiSourceCode.url())):NetworkProject.setInitialFrameAttribution(s,e),this.uiSourceCode=s,this.#r.addUISourceCodeWithProvider(this.uiSourceCode,i,c,n)}addSourceMap(e,r){this.uiSourceCode&&NetworkProject.addFrameAttribution(this.uiSourceCode,r),this.referringSourceMaps.push(e),this.recreateUISourceCodeIfNeeded(r)}removeSourceMap(e,r){const o=this.uiSourceCode;NetworkProject.removeFrameAttribution(o,r);const t=this.referringSourceMaps.lastIndexOf(e);-1!==t&&this.referringSourceMaps.splice(t,1),this.referringSourceMaps.length?this.recreateUISourceCodeIfNeeded(r):(this.#r.removeUISourceCode(o.url()),this.uiSourceCode=null)}getReferringSourceMaps(){return this.referringSourceMaps}getUiSourceCode(){return this.uiSourceCode}}