@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 4.98 kB
JavaScript
import*as TextUtils from"../../models/text_utils/text_utils.js";import{cssMetadata}from"./CSSMetadata.js";import{CSSProperty}from"./CSSProperty.js";export class CSSStyleDeclaration{#t;parentRule;#e;styleSheetId;range;cssText;#n;#r;#s;#i;type;constructor(t,e,n,r){this.#t=t,this.parentRule=e,this.#a(n),this.type=r}rebase(t){if(this.styleSheetId===t.styleSheetId&&this.range)if(t.oldRange.equal(this.range))this.#a(t.payload);else{this.range=this.range.rebaseAfterTextEdit(t.oldRange,t.newRange);for(let e=0;e<this.#e.length;++e)this.#e[e].rebase(t)}}#a(t){this.styleSheetId=t.styleSheetId,this.range=t.range?TextUtils.TextRange.TextRange.fromObject(t.range):null;const e=t.shorthandEntries;this.#n=new Map,this.#r=new Set;for(let t=0;t<e.length;++t)this.#n.set(e[t].name,e[t].value),e[t].important&&this.#r.add(e[t].name);if(this.#e=[],t.cssText&&this.range){const e=new TextUtils.Text.Text(t.cssText);let n={line:this.range.startLine,column:this.range.startColumn};const r=[];for(const s of t.cssProperties){const t=s.range;if(!t)continue;this.#o(e,n.line,n.column,t.startLine,t.startColumn),n={line:t.endLine,column:t.endColumn};const i=CSSProperty.parsePayload(this,this.#e.length,s);this.#e.push(i);for(const t of i.getLonghandProperties())r.push(t)}for(const t of r)t.index=this.#e.length,this.#e.push(t);this.#o(e,n.line,n.column,this.range.endLine,this.range.endColumn)}else for(const e of t.cssProperties)this.#e.push(CSSProperty.parsePayload(this,this.#e.length,e));this.#l(),this.#h(),this.#s=new Map;for(const t of this.#e)t.activeInStyle()&&this.#s.set(t.name,t);this.cssText=t.cssText,this.#i=null}#o(t,e,n,r,s){const i=new TextUtils.TextRange.TextRange(e,n,r,s);if(!this.range)return;const a=t.extract(i.relativeTo(this.range.startLine,this.range.startColumn)).split("\n"),o={inComment:!1,nestedBlocks:0,validContent:""};for(let t=0;t<a.length;t++){if(l(a[t],o),o.nestedBlocks>0||!o.validContent)continue;let r=0;for(const s of o.validContent.split(";")){const i=s.trim();if(i){let a,o;const l=i.indexOf(":");-1===l?(a=i,o=""):(a=i.substring(0,l).trim(),o=i.substring(l+1).trim());const h=new TextUtils.TextRange.TextRange(t,r,t,r+s.length);this.#e.push(new CSSProperty(this,this.#e.length,a,o,!1,!1,!1,!1,s,h.relativeFrom(e,n)))}r+=s.length+1}}function l(t,e){e.validContent="";for(let n=0;n<t.length;n++)e.inComment?"*/"===t.substring(n,n+2)&&(e.inComment=!1,n++):"{"===t[n]?(e.nestedBlocks++,e.validContent=e.validContent.substring(0,e.validContent.lastIndexOf(";")+1)):"}"===t[n]?e.nestedBlocks--:"/*"===t.substring(n,n+2)?(e.inComment=!0,n++):0===e.nestedBlocks&&(e.validContent+=t[n])}}#l(){if(this.range)return;if(!this.#n.size)return;const t=new Set;for(const e of this.#e)t.add(e.name);const e=[];for(const n of this.#e){const r=cssMetadata().getShorthands(n.name)||[];for(const n of r){if(t.has(n))continue;const r=this.#n.get(n);if(!r)continue;const s=Boolean(this.#r.has(n)),i=new CSSProperty(this,this.allProperties().length,n,r,s,!1,!0,!1);e.push(i),t.add(n)}}this.#e=this.#e.concat(e)}#p(){if(this.range)return this.#e.filter((function(t){return Boolean(t.range)}));const t=[];for(const e of this.#e){const n=cssMetadata().getShorthands(e.name)||[];let r=!1;for(const t of n)if(this.#n.get(t)){r=!0;break}r||t.push(e)}return t}leadingProperties(){return this.#i||(this.#i=this.#p()),this.#i}target(){return this.#t.target()}cssModel(){return this.#t}#h(){const t=new Map,e=new Set;for(const n of this.#e){if(n.disabled||!n.parsedOk){n.setActive(!1);continue}if(e.has(n))continue;const r=cssMetadata().canonicalPropertyName(n.name);for(const r of n.getLonghandProperties()){const n=t.get(r.name);n?!n.important||r.important?(n.setActive(!1),t.set(r.name,r)):r.setActive(!1):t.set(r.name,r),e.add(r)}const s=t.get(r);s?!s.important||n.important?(s.setActive(!1),t.set(r,n)):n.setActive(!1):t.set(r,n)}}allProperties(){return this.#e}hasActiveProperty(t){return this.#s.has(t)}getPropertyValue(t){const e=this.#s.get(t);return e?e.value:""}isPropertyImplicit(t){const e=this.#s.get(t);return!!e&&e.implicit}propertyAt(t){return t<this.allProperties().length?this.allProperties()[t]:null}pastLastSourcePropertyIndex(){for(let t=this.allProperties().length-1;t>=0;--t)if(this.allProperties()[t].range)return t+1;return 0}#c(t){const e=this.propertyAt(t);if(e&&e.range)return e.range.collapseToStart();if(!this.range)throw new Error("CSSStyleDeclaration.range is null");return this.range.collapseToEnd()}newBlankProperty(t){t=void 0===t?this.pastLastSourcePropertyIndex():t;return new CSSProperty(this,t,"","",!1,!1,!0,!1,"",this.#c(t))}setText(t,e){return this.range&&this.styleSheetId?this.#t.setStyleText(this.styleSheetId,this.range,t,e):Promise.resolve(!1)}insertPropertyAt(t,e,n,r){this.newBlankProperty(t).setText(e+": "+n+";",!1,!0).then(r)}appendProperty(t,e,n){this.insertPropertyAt(this.allProperties().length,t,e,n)}}export var Type;!function(t){t.Regular="Regular",t.Inline="Inline",t.Attributes="Attributes",t.Pseudo="Pseudo"}(Type||(Type={}));