Skip to content
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

[@scope] Support '@import scope(...)' behind a flag #49178

Merged
merged 1 commit into from
Nov 14, 2024
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
21 changes: 21 additions & 0 deletions css/css-cascade/resources/scope-imported.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.x {
--x: 1;
}

:scope > .y {
--y: 1;
}

@scope (.inner-scope) {
.z {
--z: 1;
}
}

& > .w {
--w: 1;
}

& > & > .u {
--u: 1;
}
25 changes: 25 additions & 0 deletions css/css-cascade/scope-import-implicit.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>@import scope(), implicit scope</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7348">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<main id=main>
<div class=scope>
<style>
@import url("resources/scope-imported.css") scope();
</style>
<div class=x>Inside</div>
</div>
<div class=x>Outside</div>
</main>
<script>
test(() => {
let e = main.querySelector('.scope > .x');
assert_equals(getComputedStyle(e).getPropertyValue('--x'), '1');
}, 'Scope-imported rule applies within implicit scope');

test(() => {
let e = main.querySelector('main > .x');
assert_equals(getComputedStyle(e).getPropertyValue('--x'), '');
}, 'Scope-imported rule does not apply outside of implicit scope');
</script>
29 changes: 29 additions & 0 deletions css/css-cascade/scope-import-inner-scope.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<title>@import scope(), :scope rules in imported stylesheet</title>
<link rel="help" href="https://drafts.csswg.org/css-cascade-6/#scope-atrule">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@import url("resources/scope-imported.css") scope((.scope));
</style>
<main id=main>
<div class=scope>
<div class=inner-scope>
<div class=z>Inside</div>
</div>
</div>
<div class=inner-scope>
<div class=z>Outside</div>
</div>
</main>
<script>
test(() => {
let e = main.querySelector('.scope > .inner-scope > .z');
assert_equals(getComputedStyle(e).getPropertyValue('--z'), '1');
}, '@scope within scope-imported stylesheet matches');

test(() => {
let e = main.querySelector('#main > .inner-scope > .z');
assert_equals(getComputedStyle(e).getPropertyValue('--z'), '');
}, '@scope within scope-imported does not ignore import scope');
</script>
31 changes: 31 additions & 0 deletions css/css-cascade/scope-import-multiple.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<title>@import scope(), same stylesheet imported multiple times</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7348">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@import url("resources/scope-imported.css") scope((.scope1));
@import url("resources/scope-imported.css") scope((.scope2));
</style>
<main id=main>
<div class=scope1>
<div class=x>Inside</div>
</div>
<div class=scope2>
<div class=x>Inside</div>
</div>
<div class=x>Outside</div>
</main>
<script>
test(() => {
let e1 = main.querySelector('.scope1 > .x');
let e2 = main.querySelector('.scope2 > .x');
assert_equals(getComputedStyle(e1).getPropertyValue('--x'), '1');
assert_equals(getComputedStyle(e2).getPropertyValue('--x'), '1');
}, 'A stylesheet may be imported multiple times, and scoped differently');

test(() => {
let e = main.querySelector('main > .x');
assert_equals(getComputedStyle(e).getPropertyValue('--x'), '');
}, 'Scope-imported rule does not apply outside of scope');
</script>
32 changes: 32 additions & 0 deletions css/css-cascade/scope-import-parent-pseudo.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<title>@import scope(), '&' selectors</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7348">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@import url("resources/scope-imported.css") scope((.scope));
</style>
<main id=main>
<div class=scope>
<div class=w>Inside</div>
<div class=scope>
<div class=w>Inner (W)</div>
<div class=u>Inner (U)</div>
</div>
</div>
</main>
<script>
test(() => {
let e = main.querySelector('#main > .scope > .w');
assert_equals(getComputedStyle(e).getPropertyValue('--w'), '1');
}, 'The & selector matches the scoping root');

test(() => {
let w = main.querySelector('#main > .scope > .scope > .w');
assert_equals(getComputedStyle(w).getPropertyValue('--w'), '1');
// The '& > & > .u' selector should behave like ':scope > :scope > .u'
// and therefore never match.
let u = main.querySelector('#main > .scope > .scope > .u');
assert_equals(getComputedStyle(u).getPropertyValue('--u'), '');
}, 'The & selector behaves like :scope');
</script>
27 changes: 27 additions & 0 deletions css/css-cascade/scope-import-scope-end.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<title>@import scope() with &lt;scope-end&gt;</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7348">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@import url("resources/scope-imported.css") scope((.scope) to (.limit));
</style>
<main id=main>
<div class=scope>
<div class=x>Inside</div>
<div class=limit>
<div class=x>Below limit</div>
</div>
</div>
</main>
<script>
test(() => {
let e = main.querySelector('.scope > .x');
assert_equals(getComputedStyle(e).getPropertyValue('--x'), '1');
}, 'Scope-imported rule applies within scope, above limit');

test(() => {
let e = main.querySelector('.limit > .x');
assert_equals(getComputedStyle(e).getPropertyValue('--x'), '');
}, 'Scope-imported rule does not apply below limit');
</script>
29 changes: 29 additions & 0 deletions css/css-cascade/scope-import-scope-pseudo.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<title>@import scope(), :scope rules in imported stylesheet</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7348">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@import url("resources/scope-imported.css") scope((.scope));
</style>
<main id=main>
<div class=scope>
<div class=y>Inside</div>
<div>
<div class=y>Inside, but should not match</div>
</div>
</div>
<div class=y>Outside</div>
</main>
<script>
test(() => {
let inside = main.querySelector('.scope > .y');
assert_equals(getComputedStyle(inside).getPropertyValue('--y'), '1');

let inside_no_match = main.querySelector('.scope > div > .y');
assert_equals(getComputedStyle(inside_no_match).getPropertyValue('--y'), '');

let outside = main.querySelector('#main > .y');
assert_equals(getComputedStyle(outside).getPropertyValue('--y'), '');
}, 'The :scope pseudo-class works in imported stylesheets');
</script>
25 changes: 25 additions & 0 deletions css/css-cascade/scope-import-scope-start.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>@import scope(), &lt;scope-start&gt;</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7348">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@import url("resources/scope-imported.css") scope((.scope));
</style>
<main id=main>
<div class=scope>
<div class=x>Inside</div>
</div>
<div class=x>Outside</div>
</main>
<script>
test(() => {
let e = main.querySelector('.scope > .x');
assert_equals(getComputedStyle(e).getPropertyValue('--x'), '1');
}, 'Scope-imported rule applies within scope');

test(() => {
let e = main.querySelector('main > .x');
assert_equals(getComputedStyle(e).getPropertyValue('--x'), '');
}, 'Scope-imported rule does not apply outside of scope');
</script>