Skip to content

Commit 4b7d947

Browse files
committed
Rename stylesLayer to componentsLayer for improved clarity and consistency
1 parent 9dc6407 commit 4b7d947

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

internal

packages/core/src/core.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class MasterCSS {
2525
readonly baseLayer = new SyntaxLayer('base', this)
2626
readonly themeLayer = new Layer('theme', this)
2727
readonly presetLayer = new SyntaxLayer('preset', this)
28-
readonly stylesLayer = new SyntaxLayer('components', this)
28+
readonly componentsLayer = new SyntaxLayer('components', this)
2929
readonly generalLayer = new SyntaxLayer('general', this)
3030

3131
get text() {
@@ -592,7 +592,7 @@ export default class MasterCSS {
592592
this.baseLayer.reset()
593593
this.themeLayer.reset()
594594
this.presetLayer.reset()
595-
this.stylesLayer.reset()
595+
this.componentsLayer.reset()
596596
this.generalLayer.reset()
597597
this.animationsNonLayer.reset()
598598
return this
@@ -621,7 +621,7 @@ export default class MasterCSS {
621621
for (const className of classNames) {
622622
if (Object.prototype.hasOwnProperty.call(this.components, className)) {
623623
for (const eachSyntax of this.components[className]) {
624-
this.stylesLayer.delete(className + ' ' + eachSyntax)
624+
this.componentsLayer.delete(className + ' ' + eachSyntax)
625625
}
626626
} else {
627627
const atIndex = className.indexOf('@')
@@ -630,7 +630,7 @@ export default class MasterCSS {
630630
if (Object.prototype.hasOwnProperty.call(this.components, name)) {
631631
const atToken = className.slice(atIndex)
632632
for (const eachSyntax of this.components[name]) {
633-
this.stylesLayer.delete(eachSyntax + atToken + ' ' + className)
633+
this.componentsLayer.delete(eachSyntax + atToken + ' ' + className)
634634
}
635635
} else {
636636
this.generalLayer.delete(className)

packages/core/src/syntax-rule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ export class SyntaxRule extends Rule {
474474
}
475475

476476
if (this.fixedClass) {
477-
this.layer = css.stylesLayer
477+
this.layer = css.componentsLayer
478478
}
479479
}
480480

packages/core/tests/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const expectLayers = (
1515
) => {
1616
const css = new MasterCSS(customConfig).add(...(Array.isArray(className) ? className : [className]))
1717
if (layers.theme) expect(css.themeLayer.text).toContain(`@layer theme{${layers.theme ?? ''}}`)
18-
if (layers.components) expect(css.stylesLayer.text).toContain(`@layer components{${layers.components ?? ''}}`)
18+
if (layers.components) expect(css.componentsLayer.text).toContain(`@layer components{${layers.components ?? ''}}`)
1919
if (layers.preset) expect(css.presetLayer.text).toContain(`@layer preset{${layers.preset ?? ''}}`)
2020
if (layers.base) expect(css.baseLayer.text).toContain(`@layer base{${layers.base ?? ''}}`)
2121
if (layers.general) expect(css.generalLayer.text).toContain(`@layer general{${layers.general ?? ''}}`)

packages/runtime/src/core.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export class RuntimeCSS extends MasterCSS {
332332
handleSyntaxLayer(this.presetLayer)
333333
break
334334
case 'components':
335-
this.stylesLayer.native = cssLayerBlockRule
335+
this.componentsLayer.native = cssLayerBlockRule
336336
let stylePreText: string
337337
const createSyntaxRules = (cssRule: any): SyntaxRule[] | undefined => {
338338
if (cssRule.selectorText) {
@@ -357,10 +357,10 @@ export class RuntimeCSS extends MasterCSS {
357357
for (const node of eachSyntaxRule.nodes) {
358358
if (!node.native && node.text.includes(stylePreText!)) {
359359
node.native = cssRule
360-
if (!this.stylesLayer.rules.includes(eachSyntaxRule)) {
361-
this.stylesLayer.rules.push(eachSyntaxRule)
362-
this.stylesLayer.insertVariables(eachSyntaxRule)
363-
this.stylesLayer.insertAnimations(eachSyntaxRule)
360+
if (!this.componentsLayer.rules.includes(eachSyntaxRule)) {
361+
this.componentsLayer.rules.push(eachSyntaxRule)
362+
this.componentsLayer.insertVariables(eachSyntaxRule)
363+
this.componentsLayer.insertAnimations(eachSyntaxRule)
364364
}
365365
matched = true
366366
break
@@ -374,14 +374,14 @@ export class RuntimeCSS extends MasterCSS {
374374
console.error(`Cannot recognize the CSS rule in the components layer. \`${cssRule.cssText}\` (https://rc.css.master.co/messages/hydration-errors)`)
375375
}
376376
}
377-
for (const eachRule of this.stylesLayer.rules) {
377+
for (const eachRule of this.componentsLayer.rules) {
378378
for (let k = eachRule.nodes.length - 1; k >= 0; k--) {
379379
if (!eachRule.nodes[k].native) {
380380
eachRule.nodes.splice(k, 1)
381381
}
382382
}
383383
}
384-
if (this.stylesLayer.rules.length) this.rules.push(this.stylesLayer)
384+
if (this.componentsLayer.rules.length) this.rules.push(this.componentsLayer)
385385
break
386386
case 'general':
387387
handleSyntaxLayer(this.generalLayer)

packages/runtime/tests/progressive/comprehensive/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('hydration', async () => {
4747
})
4848

4949
test('components', () => {
50-
expect(runtimeCSS.stylesLayer.rules[0]).toMatchObject({
50+
expect(runtimeCSS.componentsLayer.rules[0]).toMatchObject({
5151
name: '{inline-flex;bg:primary}',
5252
nodes: [
5353
{

0 commit comments

Comments
 (0)