Skip to content

Commit

Permalink
Rename stylesLayer to componentsLayer for improved clarity and co…
Browse files Browse the repository at this point in the history
…nsistency
  • Loading branch information
1aron committed Jan 20, 2025
1 parent 9dc6407 commit 4b7d947
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal
8 changes: 4 additions & 4 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class MasterCSS {
readonly baseLayer = new SyntaxLayer('base', this)
readonly themeLayer = new Layer('theme', this)
readonly presetLayer = new SyntaxLayer('preset', this)
readonly stylesLayer = new SyntaxLayer('components', this)
readonly componentsLayer = new SyntaxLayer('components', this)
readonly generalLayer = new SyntaxLayer('general', this)

get text() {
Expand Down Expand Up @@ -592,7 +592,7 @@ export default class MasterCSS {
this.baseLayer.reset()
this.themeLayer.reset()
this.presetLayer.reset()
this.stylesLayer.reset()
this.componentsLayer.reset()
this.generalLayer.reset()
this.animationsNonLayer.reset()
return this
Expand Down Expand Up @@ -621,7 +621,7 @@ export default class MasterCSS {
for (const className of classNames) {
if (Object.prototype.hasOwnProperty.call(this.components, className)) {
for (const eachSyntax of this.components[className]) {
this.stylesLayer.delete(className + ' ' + eachSyntax)
this.componentsLayer.delete(className + ' ' + eachSyntax)
}
} else {
const atIndex = className.indexOf('@')
Expand All @@ -630,7 +630,7 @@ export default class MasterCSS {
if (Object.prototype.hasOwnProperty.call(this.components, name)) {
const atToken = className.slice(atIndex)
for (const eachSyntax of this.components[name]) {
this.stylesLayer.delete(eachSyntax + atToken + ' ' + className)
this.componentsLayer.delete(eachSyntax + atToken + ' ' + className)
}
} else {
this.generalLayer.delete(className)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/syntax-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class SyntaxRule extends Rule {
}

if (this.fixedClass) {
this.layer = css.stylesLayer
this.layer = css.componentsLayer
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const expectLayers = (
) => {
const css = new MasterCSS(customConfig).add(...(Array.isArray(className) ? className : [className]))
if (layers.theme) expect(css.themeLayer.text).toContain(`@layer theme{${layers.theme ?? ''}}`)
if (layers.components) expect(css.stylesLayer.text).toContain(`@layer components{${layers.components ?? ''}}`)
if (layers.components) expect(css.componentsLayer.text).toContain(`@layer components{${layers.components ?? ''}}`)
if (layers.preset) expect(css.presetLayer.text).toContain(`@layer preset{${layers.preset ?? ''}}`)
if (layers.base) expect(css.baseLayer.text).toContain(`@layer base{${layers.base ?? ''}}`)
if (layers.general) expect(css.generalLayer.text).toContain(`@layer general{${layers.general ?? ''}}`)
Expand Down
14 changes: 7 additions & 7 deletions packages/runtime/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class RuntimeCSS extends MasterCSS {
handleSyntaxLayer(this.presetLayer)
break
case 'components':
this.stylesLayer.native = cssLayerBlockRule
this.componentsLayer.native = cssLayerBlockRule
let stylePreText: string
const createSyntaxRules = (cssRule: any): SyntaxRule[] | undefined => {
if (cssRule.selectorText) {
Expand All @@ -357,10 +357,10 @@ export class RuntimeCSS extends MasterCSS {
for (const node of eachSyntaxRule.nodes) {
if (!node.native && node.text.includes(stylePreText!)) {
node.native = cssRule
if (!this.stylesLayer.rules.includes(eachSyntaxRule)) {
this.stylesLayer.rules.push(eachSyntaxRule)
this.stylesLayer.insertVariables(eachSyntaxRule)
this.stylesLayer.insertAnimations(eachSyntaxRule)
if (!this.componentsLayer.rules.includes(eachSyntaxRule)) {
this.componentsLayer.rules.push(eachSyntaxRule)
this.componentsLayer.insertVariables(eachSyntaxRule)
this.componentsLayer.insertAnimations(eachSyntaxRule)
}
matched = true
break
Expand All @@ -374,14 +374,14 @@ export class RuntimeCSS extends MasterCSS {
console.error(`Cannot recognize the CSS rule in the components layer. \`${cssRule.cssText}\` (https://rc.css.master.co/messages/hydration-errors)`)
}
}
for (const eachRule of this.stylesLayer.rules) {
for (const eachRule of this.componentsLayer.rules) {
for (let k = eachRule.nodes.length - 1; k >= 0; k--) {
if (!eachRule.nodes[k].native) {
eachRule.nodes.splice(k, 1)
}
}
}
if (this.stylesLayer.rules.length) this.rules.push(this.stylesLayer)
if (this.componentsLayer.rules.length) this.rules.push(this.componentsLayer)
break
case 'general':
handleSyntaxLayer(this.generalLayer)
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/tests/progressive/comprehensive/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('hydration', async () => {
})

test('components', () => {
expect(runtimeCSS.stylesLayer.rules[0]).toMatchObject({
expect(runtimeCSS.componentsLayer.rules[0]).toMatchObject({
name: '{inline-flex;bg:primary}',
nodes: [
{
Expand Down

0 comments on commit 4b7d947

Please sign in to comment.