Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/ui/styling/css-selector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ export namespace Selector {

export class RuleSet {
tag: string | number;
scopedTag: string;
constructor(public selectors: SelectorCore[], public declarations: Declaration[]) {
this.selectors.forEach((sel) => (sel.ruleset = this));
}
Expand Down
20 changes: 18 additions & 2 deletions packages/core/ui/styling/style-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export function mergeCssSelectors(): void {
let applicationCssSelectors: RuleSet[] = [];
let applicationCssSelectorVersion = 0;
let applicationSelectors: RuleSet[] = [];
let tagToScopeTag: Map<string | number, string> = new Map();
let currentScopeTag: string = null;
const applicationAdditionalSelectors: RuleSet[] = [];
const applicationKeyframes: any = {};
const animationsSymbol = Symbol('animations');
Expand Down Expand Up @@ -312,12 +314,17 @@ export function removeTaggedAdditionalCSS(tag: string | number): boolean {

export function addTaggedAdditionalCSS(cssText: string, tag?: string | number): boolean {
const parsed: RuleSet[] = CSSSource.fromDetect(cssText, applicationKeyframes, undefined).selectors;
let tagScope = currentScopeTag || (tag && tagToScopeTag.has(tag) && tagToScopeTag.get(tag)) || null;
if (tagScope && tag) {
tagToScopeTag.set(tag, tagScope);
}
let changed = false;
if (parsed && parsed.length) {
changed = true;
if (tag != null) {
if (tag != null || tagScope != null) {
for (let i = 0; i < parsed.length; i++) {
parsed[i].tag = tag;
parsed[i].scopedTag = tagScope;
}
}
applicationAdditionalSelectors.push(...parsed);
Expand Down Expand Up @@ -699,6 +706,7 @@ export class StyleScope {
private _localCssSelectorsAppliedVersion = 0;
private _applicationCssSelectorsAppliedVersion = 0;
private _keyframes = new Map<string, Keyframes>();
private _cssFiles: string[] = [];

get css(): string {
return this._css;
Expand All @@ -720,8 +728,11 @@ export class StyleScope {
if (!cssFileName) {
return;
}
this._cssFiles.push(cssFileName);
currentScopeTag = cssFileName;

const cssSelectors = CSSSource.fromURI(cssFileName, this._keyframes);
currentScopeTag = null;
this._css = cssSelectors.source;
this._localCssSelectors = cssSelectors.selectors;
this._localCssSelectorVersion++;
Expand All @@ -743,8 +754,13 @@ export class StyleScope {
if (!cssString && !cssFileName) {
return;
}
if (cssFileName) {
this._cssFiles.push(cssFileName);
currentScopeTag = cssFileName;
}

const parsedCssSelectors = cssString ? CSSSource.fromSource(cssString, this._keyframes, cssFileName) : CSSSource.fromURI(cssFileName, this._keyframes);
currentScopeTag = null;
this._css = this._css + parsedCssSelectors.source;
this._localCssSelectors.push(...parsedCssSelectors.selectors);
this._localCssSelectorVersion++;
Expand Down Expand Up @@ -788,7 +804,7 @@ export class StyleScope {
@profile
private _createSelectors() {
const toMerge: RuleSet[][] = [];
toMerge.push(applicationCssSelectors);
toMerge.push(applicationCssSelectors.filter((v) => !v.scopedTag || this._cssFiles.indexOf(v.scopedTag) >= 0));
this._applicationCssSelectorsAppliedVersion = applicationCssSelectorVersion;
toMerge.push(this._localCssSelectors);
this._localCssSelectorsAppliedVersion = this._localCssSelectorVersion;
Expand Down