@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 3.66 kB
JavaScript
import*as TextUtils from"../../models/text_utils/text_utils.js";import*as Common from"../common/common.js";import*as i18n from"../i18n/i18n.js";import*as Platform from"../platform/platform.js";import*as Root from"../root/root.js";import{DeferredDOMNode}from"./DOMModel.js";import{ResourceTreeModel}from"./ResourceTreeModel.js";const UIStrings={couldNotFindTheOriginalStyle:"Could not find the original style sheet.",thereWasAnErrorRetrievingThe:"There was an error retrieving the source styles."},str_=i18n.i18n.registerUIStrings("core/sdk/CSSStyleSheetHeader.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class CSSStyleSheetHeader{#e;id;frameId;sourceURL;hasSourceURL;origin;title;disabled;isInline;isMutable;isConstructed;startLine;startColumn;endLine;endColumn;contentLength;ownerNode;sourceMapURL;loadingFailed;#t;constructor(e,t){this.#e=e,this.id=t.styleSheetId,this.frameId=t.frameId,this.sourceURL=t.sourceURL,this.hasSourceURL=Boolean(t.hasSourceURL),this.origin=t.origin,this.title=t.title,this.disabled=t.disabled,this.isInline=t.isInline,this.isMutable=t.isMutable,this.isConstructed=t.isConstructed,this.startLine=t.startLine,this.startColumn=t.startColumn,this.endLine=t.endLine,this.endColumn=t.endColumn,this.contentLength=t.length,t.ownerNode&&(this.ownerNode=new DeferredDOMNode(e.target(),t.ownerNode)),this.sourceMapURL=t.sourceMapURL,this.loadingFailed=t.loadingFailed??!1,this.#t=null}originalContentProvider(){if(!this.#t){const e=async()=>{const e=await this.#e.originalStyleSheetText(this);return null===e?{content:null,error:i18nString(UIStrings.couldNotFindTheOriginalStyle),isEncoded:!1}:{content:e,isEncoded:!1}};this.#t=new TextUtils.StaticContentProvider.StaticContentProvider(this.contentURL(),this.contentType(),e)}return this.#t}setSourceMapURL(e){this.sourceMapURL=e}cssModel(){return this.#e}isAnonymousInlineStyleSheet(){return!this.resourceURL()&&!this.#e.sourceMapManager().sourceMapForClient(this)}isConstructedByNew(){return this.isConstructed&&0===this.sourceURL.length}resourceURL(){const e=this.isViaInspector()?this.viaInspectorResourceURL():this.sourceURL;return!e&&Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.STYLES_PANE_CSS_CHANGES)?this.dynamicStyleURL():e}getFrameURLPath(){const e=this.#e.target().model(ResourceTreeModel);if(console.assert(Boolean(e)),!e)return"";const t=e.frameForId(this.frameId);if(!t)return"";console.assert(Boolean(t));const n=new Common.ParsedURL.ParsedURL(t.url);let r=n.host+n.folderPathComponents;return r.endsWith("/")||(r+="/"),r}viaInspectorResourceURL(){return`inspector://${this.getFrameURLPath()}inspector-stylesheet`}dynamicStyleURL(){return`stylesheet://${this.getFrameURLPath()}style#${this.id}`}lineNumberInSource(e){return this.startLine+e}columnNumberInSource(e,t){return(e?0:this.startColumn)+t}containsLocation(e,t){const n=e===this.startLine&&t>=this.startColumn||e>this.startLine,r=e<this.endLine||e===this.endLine&&t<=this.endColumn;return n&&r}contentURL(){return this.resourceURL()}contentType(){return Common.ResourceType.resourceTypes.Stylesheet}async requestContent(){try{return{content:await this.#e.getStyleSheetText(this.id),isEncoded:!1}}catch(e){return{content:null,error:i18nString(UIStrings.thereWasAnErrorRetrievingThe),isEncoded:!1}}}async searchInContent(e,t,n){const r=await this.requestContent();return null===r.content?[]:TextUtils.TextUtils.performSearchInContent(r.content,e,t,n)}isViaInspector(){return"inspector"===this.origin}createPageResourceLoadInitiator(){return{target:null,frameId:this.frameId,initiatorUrl:this.hasSourceURL?Platform.DevToolsPath.EmptyUrlString:this.sourceURL}}}