diff --git a/plugins/postcss-private-rule/CHANGELOG.md b/plugins/postcss-private-rule/CHANGELOG.md index 0353b30ef9..a777f32979 100644 --- a/plugins/postcss-private-rule/CHANGELOG.md +++ b/plugins/postcss-private-rule/CHANGELOG.md @@ -1,5 +1,14 @@ # Changes to PostCSS Private Rule +### Unreleased (major) + +- Removed the undocumented `Transpiler` export; use `@csstools/utilities-for-private-properties` instead +- Support `@property` rules in `@private` rules, including multi-name preludes and the shorthand form, and hoist registrations out of `@container`, `@scope` and `@starting-style` while preserving `@media`, `@supports` and `@layer` context +- Rename private properties in `transition`, `transition-property`, `inherit()` and `var()` inside `@container` preludes +- Leave style rules untouched when they contain `@apply`, `@contents`, `!important` declarations or unsupported at-rules, when they are inside a `@mixin` or `@function`, or when a registration is inside an anonymous layer +- Remove conditional group rules that only contained a `@private` rule, and transpile `@private` rules inside `@container` and `@starting-style` when they have no registrations +- Use a separate namespace for generated names so they do not collide with mixin generated names + ### 1.1.1 _October 2, 2026_ diff --git a/plugins/postcss-private-rule/README.md b/plugins/postcss-private-rule/README.md index 46fd14cc20..9c7624c7f5 100644 --- a/plugins/postcss-private-rule/README.md +++ b/plugins/postcss-private-rule/README.md @@ -8,6 +8,12 @@ npm install @csstools/postcss-private-rule --save-dev [PostCSS Private Rule] lets you declare private custom properties following the [CSS Mixins Specification]. +`@property` rules inside `@private` rules are hoisted to the root. Registrations inside `@container`, `@scope` and `@starting-style` are hoisted as if they were defined outside of those rules, matching their specifications. Registrations inside `@layer` and inside `@media` or `@supports` keep their enclosing rules. + +Style rules are left unchanged when the private properties can not be transpiled faithfully: when a registration is inside an anonymous layer, or when `@apply` or `@contents` is still present. + +Run this plugin after `@csstools/postcss-mixins` and before `@csstools/postcss-custom-functions` so that mixin bodies can use private properties and function bodies do not capture them. + ```css section { @private { diff --git a/plugins/postcss-private-rule/dist/index.d.ts b/plugins/postcss-private-rule/dist/index.d.ts index cfe1a6406d..54b07f33d4 100644 --- a/plugins/postcss-private-rule/dist/index.d.ts +++ b/plugins/postcss-private-rule/dist/index.d.ts @@ -1,8 +1,4 @@ -import type { AtRule } from 'postcss'; -import type { Declaration } from 'postcss'; -import type { Node } from 'postcss'; import type { PluginCreator } from 'postcss'; -import type { Rule } from 'postcss'; declare const creator: PluginCreator; export default creator; @@ -11,27 +7,4 @@ export { creator as 'module.exports' } /** postcss-private-rule plugin options */ export declare type pluginOptions = never; -export declare class Transpiler { - privateForRule: WeakMap; - }>; - counter: number; - hashes: Map; - getOrFillPrivateForRule(rule: Rule | AtRule): { - prefix: string; - privateProperties: Set; - }; - getStyleRulesWithPrivateProperties(node: Node): Array<{ - prefix: string; - privateProperties: Set; - rule: Rule; - }>; - registerAndRemovePrivateRules(atRule: AtRule, ownerNode: AtRule | Rule): void; - transpileDeclaration(decl: Declaration): void; - transpileDeclarationPropertyNames(decl: Declaration): void; - transpileDeclarationValues(decl: Declaration): void; - transpileAtRule(atRule: AtRule): void; -} - export { } diff --git a/plugins/postcss-private-rule/dist/index.mjs b/plugins/postcss-private-rule/dist/index.mjs index b8d8f6722b..70083bdc0c 100644 --- a/plugins/postcss-private-rule/dist/index.mjs +++ b/plugins/postcss-private-rule/dist/index.mjs @@ -1 +1 @@ -import{tokenize as e,isTokenIdent as t,mutateIdent as r}from"@csstools/css-tokenizer";import{parseListOfComponentValues as s,walk as i,isFunctionNode as a,isWhiteSpaceOrCommentNode as n,isTokenNode as o,stringify as l}from"@csstools/css-parser-algorithms";const u=/^keyframes$/i,p=/^(container|layer|media|scope|starting-style|supports)$/i,c=/^private$/i;function findStyleRule(e){if(!e.parent)return!1;if("rule"===e.parent.type){const t=e.parent;return("atrule"!==t.parent?.type||!u.test(t.parent.name))&&t}if("atrule"===e.parent.type){const t=e.parent;if(p.test(t.name))return findStyleRule(t)}return!1}function findAllStyleRules(e){let t=e;const r=[];for(;;){const e=findStyleRule(t);if(!e)break;r.push(e),t=e}return r.reverse(),r}function findPrivateRule(e){return"atrule"===e.parent?.type&&(p.test(e.parent.name)?findPrivateRule(e.parent):!!c.test(e.parent.name)&&e.parent)}const f=/\b(var|if)\(/i,v=/^container$/i,h=/^if$/i,m=/^style$/i,g=/^var$/i;class Transpiler{privateForRule=new Map;counter=0;hashes=new Map;getOrFillPrivateForRule(e){const t=this.privateForRule.get(e);if(t)return t;let r;e.source?.input.from?(r=this.hashes.get(e.source.input.from),r||(r=sourceHashFor(e.source.input.from),this.hashes.set(e.source.input.from,r))):r="0";const s=`--_csstools-p-${r}-${this.counter.toString(36)}`;this.counter++;const i={prefix:s,privateProperties:new Set};return this.privateForRule.set(e,i),i}getStyleRulesWithPrivateProperties(e){return findAllStyleRules(e).map(e=>{const t=this.privateForRule.get(e);return!!t&&{prefix:t.prefix,privateProperties:t.privateProperties,rule:e}}).filter(Boolean).reverse()}registerAndRemovePrivateRules(e,t){if(!e.nodes?.length)return;const{prefix:r,privateProperties:s}=this.getOrFillPrivateForRule(t);e.walk(t=>{if("decl"===t.type&&t.variable&&t.prop.startsWith("--"))return s.add(t.prop),void(t.prop=`${r}${t.prop}`);"atrule"===t.type&&findPrivateRule(t)===e||t.remove()}),e.before(e.nodes.map(e=>e.clone())),e.remove()}transpileDeclaration(e){this.transpileDeclarationPropertyNames(e),this.transpileDeclarationValues(e)}transpileDeclarationPropertyNames(e){if(!e.variable||!e.prop.startsWith("--"))return;const t=this.getStyleRulesWithPrivateProperties(e);if(!t.length)return;let r=!1;for(const{prefix:s,privateProperties:i}of t)if(i.has(e.prop)){r=s;break}if(!r)return;const s=`${r}${e.prop}`;e.prop!==s&&(e.prop=s)}transpileDeclarationValues(u){if(!f.test(u.value))return;const p=this.getStyleRulesWithPrivateProperties(u);if(!p.length)return;const c=s(e({css:u.value}));i(c,e=>{if(a(e.node)){if(g.test(e.node.getName())){const s=e.node.value;for(let e=0;e{if(!a(e.node))return;if(!m.test(e.node.getName()))return;const s=e.node.value;for(let e=0;e>>0).toString(36)}function sourceKey(e){const t=e.replaceAll("\\","/").split("/").filter(e=>e.length>0);return 0===t.length?".":1===t.length?`./${t[0]}`:t.slice(-2).join("/")}const creator=()=>({postcssPlugin:"postcss-private-rule",prepare(){const e=new Transpiler;return{postcssPlugin:"postcss-private-rule",Once(t){t.walkAtRules(c,t=>{const r=findStyleRule(t);r&&e.registerAndRemovePrivateRules(t,r)}),t.walkDecls(t=>{e.transpileDeclaration(t)}),t.walkAtRules(t=>{e.transpileAtRule(t)})}}}});creator.postcss=!0;export{Transpiler,creator as default,creator as"module.exports"}; +import{createPrivatePropertyTranspiler as s}from"@csstools/utilities-for-private-properties";const creator=()=>({postcssPlugin:"postcss-private-rule",prepare(){const t=s();return{postcssPlugin:"postcss-private-rule",Once(s){s.append(t.transpile(s.nodes))}}}});creator.postcss=!0;export{creator as default,creator as"module.exports"}; diff --git a/plugins/postcss-private-rule/docs/README.md b/plugins/postcss-private-rule/docs/README.md index 60cf240d1e..fa8c799c95 100644 --- a/plugins/postcss-private-rule/docs/README.md +++ b/plugins/postcss-private-rule/docs/README.md @@ -19,6 +19,12 @@ [] lets you declare private custom properties following the [CSS Mixins Specification]. +`@property` rules inside `@private` rules are hoisted to the root. Registrations inside `@container`, `@scope` and `@starting-style` are hoisted as if they were defined outside of those rules, matching their specifications. Registrations inside `@layer` and inside `@media` or `@supports` keep their enclosing rules. + +Style rules are left unchanged when the private properties can not be transpiled faithfully: when a registration is inside an anonymous layer, or when `@apply` or `@contents` is still present. + +Run this plugin after `@csstools/postcss-mixins` and before `@csstools/postcss-custom-functions` so that mixin bodies can use private properties and function bodies do not capture them. + ```css diff --git a/plugins/postcss-private-rule/package.json b/plugins/postcss-private-rule/package.json index 378ef80d51..95e33910db 100644 --- a/plugins/postcss-private-rule/package.json +++ b/plugins/postcss-private-rule/package.json @@ -41,15 +41,15 @@ "dist" ], "dependencies": { - "@csstools/css-parser-algorithms": "^4.0.2", - "@csstools/css-tokenizer": "^4.0.2" + "@csstools/utilities-for-private-properties": "^0.0.0" }, "peerDependencies": { "postcss": "^8.4" }, "devDependencies": { "@csstools/postcss-bundler": "*", - "@csstools/postcss-tape": "*" + "@csstools/postcss-tape": "*", + "puppeteer": "^25.14.0" }, "scripts": { "build": "rollup -c ../../rollup/default.mjs", diff --git a/plugins/postcss-private-rule/src/index.ts b/plugins/postcss-private-rule/src/index.ts index 7ab284f76c..545e9d976a 100644 --- a/plugins/postcss-private-rule/src/index.ts +++ b/plugins/postcss-private-rule/src/index.ts @@ -1,8 +1,5 @@ import type { Plugin, PluginCreator } from 'postcss'; -import { findStyleRule, IS_PRIVATE_RULE_REGEX } from './valid-atrules'; -import { Transpiler } from './transpiler'; - -export { Transpiler } from './transpiler'; +import { createPrivatePropertyTranspiler } from '@csstools/utilities-for-private-properties'; /** postcss-private-rule plugin options */ export type pluginOptions = never; @@ -11,30 +8,15 @@ const creator: PluginCreator = () => { return { postcssPlugin: 'postcss-private-rule', prepare(): Plugin { - const transpiler = new Transpiler(); + const transpiler = createPrivatePropertyTranspiler(); return { postcssPlugin: 'postcss-private-rule', Once(root): void { - root.walkAtRules(IS_PRIVATE_RULE_REGEX, (atRule) => { - const styleRule = findStyleRule(atRule); - if (!styleRule) { - return; - } - - transpiler.registerAndRemovePrivateRules(atRule, styleRule); - }); - - root.walkDecls((decl) => { - transpiler.transpileDeclaration(decl); - }); - - root.walkAtRules((atRule) => { - transpiler.transpileAtRule(atRule); - }); + root.append(transpiler.transpile(root.nodes)); }, }; - } + }, }; }; diff --git a/plugins/postcss-private-rule/test/_browser.mjs b/plugins/postcss-private-rule/test/_browser.mjs new file mode 100644 index 0000000000..cc4e937cc8 --- /dev/null +++ b/plugins/postcss-private-rule/test/_browser.mjs @@ -0,0 +1,129 @@ +import puppeteer from 'puppeteer'; +import http from 'node:http'; +import fs from 'node:fs/promises'; +import plugin from '@csstools/postcss-private-rule'; +import postcss from 'postcss'; +import test from 'node:test'; +import process from 'node:process'; + +// The transformed cases run the source through this plugin. +// +// No browser implements `@private` yet, so only the transformed form is tested. + +const PAGES = [ + 'wpt/private.html', + 'wpt/private-rule-types.html', +]; + +const requestListener = async function (req, res) { + + const parsedUrl = new URL(req.url, 'http://localhost:8080'); + const pathname = parsedUrl.pathname; + + if (PAGES.includes(pathname.replace(/^\//, ''))) { + res.setHeader('Content-type', 'text/html'); + res.writeHead(200); + res.end(await fs.readFile('test' + pathname, 'utf8')); + return; + } + + if (pathname === '' || pathname === '/') { + res.setHeader('Content-type', 'text/html'); + res.writeHead(200); + + res.end(` + + + Private Rule Test + + +

Private Rule Test

+
    + ${PAGES.map((page) => `
  • ${page}
  • `).join('\n')} +
+ + + `); + return; + } + + if (pathname === '/test/styles.css' && req.method === 'POST') { + const data = await new Promise((resolve, reject) => { + let buf = []; + req.on('data', (chunk) => { + buf.push(chunk); + }); + + req.on('end', () => { + resolve(Buffer.concat(buf).toString()); + }); + + req.on('error', (err) => { + reject(err); + }); + }); + + const css = parsedUrl.searchParams.get('transform') === 'false' + ? data + : (await postcss([plugin()]).process(data, { from: 'test/styles.css', to: 'test/styles.css' })).css; + + res.setHeader('Content-type', 'text/css'); + res.writeHead(200); + res.end(css); + return; + } + + res.setHeader('Content-type', 'text/plain'); + res.writeHead(404); + res.end('Not found'); +}; + +function startServers() { + const server = http.createServer(requestListener); + server.listen(8080); + + return () => { + server.close(); + }; +} + +if (!process.env.DEBUG) { + test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => { + const cleanup = startServers(); + + let browser; + + try { + browser = await puppeteer.launch({ + headless: 'new', + executablePath: process.env.PUPPETEER_EXECUTABLE_PATH, + args: ['--enable-experimental-web-platform-features'], + }); + + const page = await browser.newPage(); + page.on('pageerror', (msg) => { + throw msg; + }); + + for (const url of PAGES) { + await page.goto('http://localhost:8080/' + url); + const result = await page.evaluate(async () => { + // eslint-disable-next-line no-undef + return await window.runTest(); + }); + if (!result) { + throw new Error('Test failed, expected "window.runTest()" to return true'); + } + } + } finally { + await browser?.close(); + + await cleanup(); + } + }); +} else { + startServers(); + + // eslint-disable-next-line no-console + console.log('visit : http://localhost:8080'); +} diff --git a/plugins/postcss-private-rule/test/_tape.mjs b/plugins/postcss-private-rule/test/_tape.mjs index bbb6e15db7..1b3806d29e 100644 --- a/plugins/postcss-private-rule/test/_tape.mjs +++ b/plugins/postcss-private-rule/test/_tape.mjs @@ -12,6 +12,9 @@ postcssTape(plugin)({ encoding: { message: 'all encoded values are valid css', }, + property: { + message: 'supports @property rules in @private rules', + }, bundled: { message: 'all encoded values are valid css', plugins: [ diff --git a/plugins/postcss-private-rule/test/basic.css b/plugins/postcss-private-rule/test/basic.css index 1131e60d6a..e98b4ae372 100644 --- a/plugins/postcss-private-rule/test/basic.css +++ b/plugins/postcss-private-rule/test/basic.css @@ -207,3 +207,131 @@ section > h1 > small { content: var(--foo); } } + +.if-function-media-first { + @private { + --alpha: private; + } + + --bar: if( + media(width > 1px): cyan; + style(--alpha: private): orange; + else: red; + ); +} + +.invalid-at-rules { + @private { + --alpha: 2px; + @apply --mixin; + @font-face { font-family: test; } + @unknown-rule { --alpha: 3px; } + } + + --beta: var(--alpha); +} + +.important-private { + @private { + --alpha: 2px; + --alpha: 3px !important; + } + + --beta: var(--alpha); +} + +.container-private { + @container (width > 0px) { + @private { + --alpha: 2px; + } + } + + --beta: var(--alpha); +} + +.starting-style-private { + @starting-style { + @private { + --alpha: 2px; + } + } + + --beta: var(--alpha); +} + +.container-style-query-value { + @private { + --alpha: 2px; + } + + @container style(--foo: var(--alpha)) { + --beta: var(--alpha); + } +} + +.inherit-private { + @private { + --alpha: 2px; + } + + --beta: inherit(--alpha); +} + +.nested-container-registration { + @private { + --alpha: 2px; + } + + & .inner { + @container (width > 0px) { + @private { + @property --beta : 1px; + --beta: 2px; + } + } + + --gamma: var(--alpha); + } +} + +.scope-private { + @scope (.inner) { + @private { + --alpha: 2px; + } + } + + --beta: var(--alpha); +} + +.scope-registration { + @scope (.inner) { + @private { + @property --scope-size : 1px; + --scope-size: 2px; + } + } + + width: var(--scope-size); +} + +.untranspiled-apply { + @private { + --alpha: 2px; + } + + @apply --some-mixin; + + --beta: var(--alpha); +} + +@mixin --some-mixin() { + .untranspiled-mixin-rule { + @private { + --alpha: 2px; + } + + width: var(--alpha); + } +} diff --git a/plugins/postcss-private-rule/test/basic.expect.css b/plugins/postcss-private-rule/test/basic.expect.css index 578af31df8..3dcfac079f 100644 --- a/plugins/postcss-private-rule/test/basic.expect.css +++ b/plugins/postcss-private-rule/test/basic.expect.css @@ -160,3 +160,111 @@ section > h1 > small { content: var(--_csstools-p-wv7kid-h--foo); } } + +.if-function-media-first { + --_csstools-p-wv7kid-i--alpha: private; + + --bar: if( + media(width > 1px): cyan; + style(--_csstools-p-wv7kid-i--alpha: private): orange; + else: red; + ); +} + +.invalid-at-rules { + @private { + --alpha: 2px; + @apply --mixin; + @font-face { font-family: test; } + @unknown-rule { --alpha: 3px; } + } + + --beta: var(--alpha); +} + +.important-private { + --_csstools-p-wv7kid-j--alpha: 2px; + --_csstools-p-wv7kid-j--alpha: 3px !important; + + --beta: var(--_csstools-p-wv7kid-j--alpha); +} + +.container-private { + @container (width > 0px) { + --_csstools-p-wv7kid-k--alpha: 2px + } + + --beta: var(--_csstools-p-wv7kid-k--alpha); +} + +.starting-style-private { + @starting-style { + --_csstools-p-wv7kid-l--alpha: 2px + } + + --beta: var(--_csstools-p-wv7kid-l--alpha); +} + +.container-style-query-value { + --_csstools-p-wv7kid-m--alpha: 2px; + + @container style(--foo: var(--_csstools-p-wv7kid-m--alpha)) { + --beta: var(--_csstools-p-wv7kid-m--alpha); + } +} + +.inherit-private { + --_csstools-p-wv7kid-n--alpha: 2px; + + --beta: inherit(--_csstools-p-wv7kid-n--alpha); +} + +.nested-container-registration { + --_csstools-p-wv7kid-o--alpha: 2px; + + & .inner { + @container (width > 0px) { + --_csstools-p-wv7kid-p--beta: 2px + } + + --gamma: var(--_csstools-p-wv7kid-o--alpha); + } +} + +.scope-private { + @scope (.inner) { + --_csstools-p-wv7kid-q--alpha: 2px + } + + --beta: var(--_csstools-p-wv7kid-q--alpha); +} + +.scope-registration { + @scope (.inner) { + --_csstools-p-wv7kid-r--scope-size: 2px + } + + width: var(--_csstools-p-wv7kid-r--scope-size); +} + +.untranspiled-apply { + @private { + --alpha: 2px; + } + + @apply --some-mixin; + + --beta: var(--alpha); +} + +@mixin --some-mixin() { + .untranspiled-mixin-rule { + @private { + --alpha: 2px; + } + + width: var(--alpha); + } +} + @property --_csstools-p-wv7kid-p--beta : 1px; + @property --_csstools-p-wv7kid-r--scope-size : 1px diff --git a/plugins/postcss-private-rule/test/property.css b/plugins/postcss-private-rule/test/property.css new file mode 100644 index 0000000000..2ed2d67195 --- /dev/null +++ b/plugins/postcss-private-rule/test/property.css @@ -0,0 +1,198 @@ +.registered { + @private { + @property --size { + syntax: ""; + inherits: false; + initial-value: 10px; + } + + @property --size-a, --size-b { + syntax: ""; + inherits: false; + initial-value: 11px; + } + + @property --size-c : 12px; + + @property --colors type(#): red, blue; + + @property --empty :; + + @property --untyped-empty:; + + @property -- : 1em; + + --size: 20px; + --size-a: 30px; + --size-b: 40px; + --size-c: 50px; + --colors: red, blue; + } + + width: var(--size); + height: var(--size-a); + min-height: var(--size-b); + max-height: var(--size-c); + max-width: var(--colors); + min-width: var(--empty); + border-width: var(--untyped-empty); + outline-width: var(--); +} + +.registered-only { + @private { + @property --untyped: 6px; + } + + color: var(--untyped); +} + +.registered-conditional { + @private { + @media (min-width: 1000px) { + @property --conditional-size : 13px; + } + + --conditional-size: 14px; + } + + width: var(--conditional-size); +} + +@layer parent-layer { + .layer-order { + @private { + @layer private-layer { + @property --layer-size : 10px; + } + } + + width: var(--layer-size); + } +} + +.escaped { + @private { + @property --\66 oo : 10px; + --\66 oo: 20px; + } + + --\66 oo: 30px; + + width: var(--\66 oo); +} + +.outer-conditional { + @media (min-width: 1000px) { + @private { + @property --outer-conditional-size : 13px; + } + } + + @private { + --outer-conditional-size: 14px; + } + + width: var(--outer-conditional-size); +} + +.container-registration { + container-type: inline-size; + + @container (width > 10px) { + @private { + @property --container-size : 10px; + --container-size: 20px; + } + } + + width: var(--container-size); +} + +.starting-style-registration { + @starting-style { + @private { + @property --starting-size : 10px; + } + } + + width: var(--starting-size); +} + +.container-registration-siblings { + @container (width > 10px) { + @private { + @property --sibling-size : 10px; + --sibling-size: 20px; + } + } + + @private { + --sibling-size: 30px; + } + + width: var(--sibling-size); +} + +@media (min-width: 1000px) { + .media-above { + @private { + @property --media-above-size : 1em; + } + } +} + +.registration-layers { + @layer first { + @private { + @property --layer-size : 1px; + } + } + + @layer second { + @private { + @property --layer-size : red; + } + } +} + +.anonymous-registration-layers { + @private { + @layer { + @property --anonymous-size : 1px; + } + + @layer second { + @property --anonymous-size : red; + } + } + + width: var(--anonymous-size); +} + +.transition-references { + @private { + @property --transition-size : 1px; + --transition-size: 2px; + } + + transition: --transition-size 1s; + transition-property: --transition-size; +} + +@media (min-width: 1000px) { + .conditional-combination { + @container (width > 10px) { + @private { + @layer inner { + @property --combination-size : 1em; + --combination-size: 2em; + } + } + + transition: --combination-size 1s; + } + + width: var(--combination-size); + } +} diff --git a/plugins/postcss-private-rule/test/property.expect.css b/plugins/postcss-private-rule/test/property.expect.css new file mode 100644 index 0000000000..b7e01d1ca0 --- /dev/null +++ b/plugins/postcss-private-rule/test/property.expect.css @@ -0,0 +1,180 @@ +.registered { + + @property -- : 1em; + + --_csstools-p-7q9ama-0--size: 20px; + --_csstools-p-7q9ama-0--size-a: 30px; + --_csstools-p-7q9ama-0--size-b: 40px; + --_csstools-p-7q9ama-0--size-c: 50px; + --_csstools-p-7q9ama-0--colors: red, blue; + + width: var(--_csstools-p-7q9ama-0--size); + height: var(--_csstools-p-7q9ama-0--size-a); + min-height: var(--_csstools-p-7q9ama-0--size-b); + max-height: var(--_csstools-p-7q9ama-0--size-c); + max-width: var(--_csstools-p-7q9ama-0--colors); + min-width: var(--_csstools-p-7q9ama-0--empty); + border-width: var(--_csstools-p-7q9ama-0--untyped-empty); + outline-width: var(--); +} + +.registered-only { + + color: var(--_csstools-p-7q9ama-1--untyped); +} + +.registered-conditional { + + --_csstools-p-7q9ama-2--conditional-size: 14px; + + width: var(--_csstools-p-7q9ama-2--conditional-size); +} + +@layer parent-layer { + .layer-order { + @layer private-layer { + } + + width: var(--_csstools-p-7q9ama-3--layer-size); + } +} + +.escaped { + --_csstools-p-7q9ama-4--\66 oo: 20px; + + --_csstools-p-7q9ama-4--\66 oo: 30px; + + width: var(--_csstools-p-7q9ama-4--foo); +} + +.outer-conditional { + --_csstools-p-7q9ama-5--outer-conditional-size: 14px; + + width: var(--_csstools-p-7q9ama-5--outer-conditional-size); +} + +.container-registration { + container-type: inline-size; + + @container (width > 10px) { + --_csstools-p-7q9ama-6--container-size: 20px + } + + width: var(--_csstools-p-7q9ama-6--container-size); +} + +.starting-style-registration { + + width: var(--_csstools-p-7q9ama-7--starting-size); +} + +.container-registration-siblings { + @container (width > 10px) { + --_csstools-p-7q9ama-8--sibling-size: 20px + } + --_csstools-p-7q9ama-8--sibling-size: 30px; + + width: var(--_csstools-p-7q9ama-8--sibling-size); +} + +@media (min-width: 1000px) { + .media-above { + } +} + +.registration-layers { + @layer first { + } + + @layer second { + } +} + +.anonymous-registration-layers { + @private { + @layer { + @property --anonymous-size : 1px; + } + + @layer second { + @property --anonymous-size : red; + } + } + + width: var(--anonymous-size); +} + +.transition-references { + --_csstools-p-7q9ama-b--transition-size: 2px; + + transition: --_csstools-p-7q9ama-b--transition-size 1s; + transition-property: --_csstools-p-7q9ama-b--transition-size; +} + +@media (min-width: 1000px) { + .conditional-combination { + @container (width > 10px) { + @layer inner { + --_csstools-p-7q9ama-c--combination-size: 2em; + } + + transition: --_csstools-p-7q9ama-c--combination-size 1s; + } + + width: var(--_csstools-p-7q9ama-c--combination-size); + } +} + @property --_csstools-p-7q9ama-0--size { + syntax: ""; + inherits: false; + initial-value: 10px; + } + + @property --_csstools-p-7q9ama-0--size-a, --_csstools-p-7q9ama-0--size-b { + syntax: ""; + inherits: false; + initial-value: 11px; + } + + @property --_csstools-p-7q9ama-0--size-c : 12px; + + @property --_csstools-p-7q9ama-0--colors type(#): red, blue; + + @property --_csstools-p-7q9ama-0--empty :; + + @property --_csstools-p-7q9ama-0--untyped-empty:; + @property --_csstools-p-7q9ama-1--untyped: 6px; + @media (min-width: 1000px) { + @property --_csstools-p-7q9ama-2--conditional-size : 13px; + } + +@layer parent-layer { + @layer private-layer { + @property --_csstools-p-7q9ama-3--layer-size : 10px; + } +} + @property --_csstools-p-7q9ama-4--foo : 10px; + @media (min-width: 1000px) { + @property --_csstools-p-7q9ama-5--outer-conditional-size : 13px + } + @property --_csstools-p-7q9ama-6--container-size : 10px; + @property --_csstools-p-7q9ama-7--starting-size : 10px; + @property --_csstools-p-7q9ama-8--sibling-size : 10px; + +@media (min-width: 1000px) { + @property --_csstools-p-7q9ama-9--media-above-size : 1em +} + @layer first { + @property --_csstools-p-7q9ama-a--layer-size : 1px + } + + @layer second { + @property --_csstools-p-7q9ama-a--layer-size : red + } + @property --_csstools-p-7q9ama-b--transition-size : 1px; + +@media (min-width: 1000px) { + @layer inner { + @property --_csstools-p-7q9ama-c--combination-size : 1em; + } +} diff --git a/plugins/postcss-private-rule/test/wpt/private-rule-types.html b/plugins/postcss-private-rule/test/wpt/private-rule-types.html new file mode 100644 index 0000000000..dd7d7aa87d --- /dev/null +++ b/plugins/postcss-private-rule/test/wpt/private-rule-types.html @@ -0,0 +1,178 @@ + +CSS @private: nested rule types + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/plugins/postcss-private-rule/test/wpt/private.html b/plugins/postcss-private-rule/test/wpt/private.html new file mode 100644 index 0000000000..4254a12338 --- /dev/null +++ b/plugins/postcss-private-rule/test/wpt/private.html @@ -0,0 +1,350 @@ + +CSS @private: lexical scope and registration + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +