@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 4.53 kB
JavaScript
import*as Common from"../../core/common/common.js";import*as Platform from"../../core/platform/platform.js";import*as SDK from"../../core/sdk/sdk.js";import{LiveLocationWithPool}from"./LiveLocation.js";import{SASSSourceMapping}from"./SASSSourceMapping.js";import{StylesSourceMapping}from"./StylesSourceMapping.js";let cssWorkspaceBindingInstance;export class CSSWorkspaceBinding{#e;#o;#t;constructor(e,o){this.#e=e,this.#o=new Map,o.observeModels(SDK.CSSModel.CSSModel,this),this.#t=new Set}static instance(e={forceNew:null,resourceMapping:null,targetManager:null}){const{forceNew:o,resourceMapping:t,targetManager:n}=e;if(!cssWorkspaceBindingInstance||o){if(!t||!n)throw new Error(`Unable to create CSSWorkspaceBinding: resourceMapping and targetManager must be provided: ${(new Error).stack}`);cssWorkspaceBindingInstance=new CSSWorkspaceBinding(t,n)}return cssWorkspaceBindingInstance}static removeInstance(){cssWorkspaceBindingInstance=void 0}get modelToInfo(){return this.#o}getCSSModelInfo(e){return this.#o.get(e)}modelAdded(e){this.#o.set(e,new ModelInfo(e,this.#e))}modelRemoved(e){this.getCSSModelInfo(e).dispose(),this.#o.delete(e)}async pendingLiveLocationChangesPromise(){await Promise.all(this.#t)}recordLiveLocationChange(e){e.then((()=>{this.#t.delete(e)})),this.#t.add(e)}async updateLocations(e){const o=this.getCSSModelInfo(e.cssModel()).updateLocations(e);this.recordLiveLocationChange(o),await o}createLiveLocation(e,o,t){const n=this.getCSSModelInfo(e.cssModel()).createLiveLocation(e,o,t);return this.recordLiveLocationChange(n),n}propertyRawLocation(e,o){const t=e.ownerStyle;if(!t||t.type!==SDK.CSSStyleDeclaration.Type.Regular||!t.styleSheetId)return null;const n=t.cssModel().styleSheetHeaderForId(t.styleSheetId);if(!n)return null;const s=o?e.nameRange():e.valueRange();if(!s)return null;const i=s.startLine,a=s.startColumn;return new SDK.CSSModel.CSSLocation(n,n.lineNumberInSource(i),n.columnNumberInSource(i,a))}propertyUILocation(e,o){const t=this.propertyRawLocation(e,o);return t?this.rawLocationToUILocation(t):null}rawLocationToUILocation(e){return this.getCSSModelInfo(e.cssModel()).rawLocationToUILocation(e)}uiLocationToRawLocations(e){const o=[];for(const t of this.#o.values())o.push(...t.uiLocationToRawLocations(e));return o}}export class ModelInfo{#n;#e;#s;#i;#a;#r;constructor(e,o){this.#n=[e.addEventListener(SDK.CSSModel.Events.StyleSheetAdded,(e=>{this.styleSheetAdded(e)}),this),e.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved,(e=>{this.styleSheetRemoved(e)}),this)],this.#e=o,this.#s=new StylesSourceMapping(e,o.workspace);const t=e.sourceMapManager();this.#i=new SASSSourceMapping(e.target(),t,o.workspace),this.#a=new Platform.MapUtilities.Multimap,this.#r=new Platform.MapUtilities.Multimap}get locations(){return this.#a}async createLiveLocation(e,o,t){const n=new LiveLocation(e,this,o,t),s=e.header();return s?(n.setHeader(s),this.#a.set(s,n),await n.update()):this.#r.set(e.url,n),n}disposeLocation(e){const o=e.header();o?this.#a.delete(o,e):this.#r.delete(e.url,e)}updateLocations(e){const o=[];for(const t of this.#a.get(e))o.push(t.update());return Promise.all(o)}async styleSheetAdded(e){const o=e.data;if(!o.sourceURL)return;const t=[];for(const e of this.#r.get(o.sourceURL))e.setHeader(o),this.#a.set(o,e),t.push(e.update());await Promise.all(t),this.#r.deleteAll(o.sourceURL)}async styleSheetRemoved(e){const o=e.data,t=[];for(const e of this.#a.get(o))e.setHeader(o),this.#r.set(e.url,e),t.push(e.update());await Promise.all(t),this.#a.deleteAll(o)}rawLocationToUILocation(e){let o=null;return o=o||this.#i.rawLocationToUILocation(e),o=o||this.#s.rawLocationToUILocation(e),o=o||this.#e.cssLocationToUILocation(e),o}uiLocationToRawLocations(e){let o=this.#i.uiLocationToRawLocations(e);return o.length?o:(o=this.#s.uiLocationToRawLocations(e),o.length?o:this.#e.uiLocationToCSSLocations(e))}dispose(){Common.EventTarget.removeEventListeners(this.#n),this.#s.dispose(),this.#i.dispose()}}export class LiveLocation extends LiveLocationWithPool{url;#c;#l;#u;headerInternal;constructor(e,o,t,n){super(t,n),this.url=e.url,this.#c=e.lineNumber,this.#l=e.columnNumber,this.#u=o,this.headerInternal=null}header(){return this.headerInternal}setHeader(e){this.headerInternal=e}async uiLocation(){if(!this.headerInternal)return null;const e=new SDK.CSSModel.CSSLocation(this.headerInternal,this.#c,this.#l);return CSSWorkspaceBinding.instance().rawLocationToUILocation(e)}dispose(){super.dispose(),this.#u.disposeLocation(this)}async isIgnoreListed(){return!1}}