Skip to content

cascade-layers : add support for scope and container at rules #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
6 changes: 6 additions & 0 deletions plugins/postcss-cascade-layers/.tape.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ postcssTape(plugin)({
atrules: {
message: "supports @keyframes usage",
},
'container-scope--reference': {
message: "Layered styles without @container or @scope but with the same layers and layer order as the @container/@scope test",
},
'container-scope': {
message: "Layered styles with @container or @scope, these at rules are expected not to have any effect on the final order or specificity",
},
nested: {
message: "supports nested layer usage",
},
Expand Down
4 changes: 4 additions & 0 deletions plugins/postcss-cascade-layers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to PostCSS Cascade Layers

### Unreleased

- Add support for `@scope` and `@container` as parent rules for `@layer`

### 1.0.6 (September 7, 2022)

- Fix broken `@keyframes` in `@layer`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AtRule, ChildNode, Container, Document } from 'postcss';

const allowedParentAtRules = new Set(['layer', 'supports', 'media']);
const allowedParentAtRules = new Set(['layer', 'supports', 'media', 'container', 'scope']);

export function isProcessableLayerRule(atRule: AtRule): boolean {
if (atRule.type !== 'atrule') {
Expand Down
30 changes: 30 additions & 0 deletions plugins/postcss-cascade-layers/test/atrules.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,43 @@
from { translate: 0; }
to { translate: -100% 0; }
}

.foo {
order: 1.1;
}

@container (min-width: 700px) {
.foo {
order: 1.2;
}

@keyframes slide-left {
from { translate: 700; }
to { translate: -100% 0; }
}
}
}

@layer framework {
@keyframes slide-left {
from { margin-left: 0; }
to { margin-left: -100%; }
}

.foo {
order: 2.1;
}

@container (min-width: 700px) {
.foo {
order: 2.2;
}

@keyframes slide-left {
from { margin-left: 700; }
to { margin-left: -100%; }
}
}
}

#target {
Expand Down
36 changes: 35 additions & 1 deletion plugins/postcss-cascade-layers/test/atrules.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,51 @@
@keyframes slide-left {
from { margin-left: 0; }
to { margin-left: -100%; }
}@keyframes slide-left {
}

@container (min-width: 700px) {

@keyframes slide-left {
from { margin-left: 700; }
to { margin-left: -100%; }
}
}

@keyframes slide-left {
from { translate: 0; }
to { translate: -100% 0; }
}

@container (min-width: 700px) {

@keyframes slide-left {
from { translate: 700; }
to { translate: -100% 0; }
}
}

@keyframes anim {
from { background-color: red; }
}

@counter-style custom-counter-style {
system: extends three;
}.foo:not(#\#):not(#\#) {
order: 1.1;
}@container (min-width: 700px) {
.foo:not(#\#):not(#\#) {
order: 1.2;
}
}

.foo {
order: 2.1;
}

@container (min-width: 700px) {
.foo {
order: 2.2;
}
}

#target:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
Expand Down
41 changes: 41 additions & 0 deletions plugins/postcss-cascade-layers/test/container-scope--reference.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@keyframes slide-left {
from { margin-left: 0; }
to { margin-left: -100%; }
}

@layer A {
#target {
color: red;
}
}

@layer {
#foo #bar target::before:hover {
color: green;
}
}

@layer B {
#target {
color: orange;
}
}

@layer B {
#target {
color: yellow;
}

@keyframes slide-left {
from { translate: 0; }
to { translate: -100% 0; }
}
}

target {
color: purple;
}

target:before {
color: pink;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


@keyframes slide-left {
from { translate: 0; }
to { translate: -100% 0; }
}@keyframes slide-left {
from { margin-left: 0; }
to { margin-left: -100%; }
}

#target {
color: red;
}

#foo:not(#\#):not(#\#):not(#\#) #bar target::before:hover {
color: green;
}

#target:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
color: orange;
}

#target:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
color: yellow;
}

target:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
color: purple;
}

target:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):before {
color: pink;
}
47 changes: 47 additions & 0 deletions plugins/postcss-cascade-layers/test/container-scope.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@scope (.media) to (.content) {
@keyframes slide-left {
from { margin-left: 0; }
to { margin-left: -100%; }
}
}

@layer A {
#target {
color: red;
}
}

@container (min-width: 700px) {
@layer {
#foo #bar target::before:hover {
color: green;
}
}
}

@layer B {
#target {
color: orange;
}
}

@scope (.media) to (.content) {
@layer B {
#target {
color: yellow;
}

@keyframes slide-left {
from { translate: 0; }
to { translate: -100% 0; }
}
}
}

target {
color: purple;
}

target:before {
color: pink;
}
42 changes: 42 additions & 0 deletions plugins/postcss-cascade-layers/test/container-scope.expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@


@scope (.media) to (.content) {

@keyframes slide-left {
from { translate: 0; }
to { translate: -100% 0; }
}
}@scope (.media) to (.content) {
@keyframes slide-left {
from { margin-left: 0; }
to { margin-left: -100%; }
}
}

#target {
color: red;
}

@container (min-width: 700px) {
#foo:not(#\#):not(#\#):not(#\#) #bar target::before:hover {
color: green;
}
}

#target:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
color: orange;
}

@scope (.media) to (.content) {
#target:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
color: yellow;
}
}

target:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
color: purple;
}

target:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):before {
color: pink;
}