This commit is contained in:
szabomarton committed 2025-01-28 11:38:27 +01:00
1 parent 9c5ca86086
commit 7f4a15b9c3
36841 files changed
+4032468 -1

No files matched your search

@@ -0,0 +1 @@
export declare function adjustSelectorSpecificity(selector: string, amount: number): string;
@@ -0,0 +1,3 @@
import type { Container } from 'postcss';
export declare function removeEmptyDescendantBlocks(block: Container): void;
export declare function removeEmptyAncestorBlocks(block: Container): void;
@@ -0,0 +1,8 @@
/** @constant {string} INVALID_LAYER_NAME Used to replace "layer" temporarily when an invalid layer is detected. This allows us to ignore this rule in further processing. */
export declare const INVALID_LAYER_NAME = "csstools-invalid-layer";
/** @constant {string} WITH_SELECTORS_LAYER_NAME Used to replace "layer" temporarily for any layer at rules that contain selectors. This allows us to sort these differently from other layer at rules. */
export declare const WITH_SELECTORS_LAYER_NAME = "csstools-layer-with-selector-rules";
export declare const ANONYMOUS_LAYER_SUFFIX = "6efdb677-bb05-44e5-840f-29d2175862fd";
export declare const IMPLICIT_LAYER_SUFFIX = "b147acf6-11a6-4338-a4d0-80aef4cd1a2f";
export declare const CONDITIONAL_ATRULES: string[];
export declare const ATRULES_WITH_NON_SELECTOR_BLOCK_LISTS: string[];
@@ -0,0 +1,3 @@
import type { Container } from 'postcss';
import type { Model } from './model';
export declare function desugarAndParseLayerNames(root: Container, model: Model): void;
@@ -0,0 +1,3 @@
import type { Container, ChildNode } from 'postcss';
import type { Model } from './model';
export declare function desugarNestedLayers(root: Container<ChildNode>, model: Model): void;
@@ -0,0 +1,2 @@
import type { AtRule } from 'postcss';
export declare function getConditionalAtRuleAncestor(layerRule: AtRule): AtRule | null;
@@ -0,0 +1,2 @@
import type { AtRule, Node } from 'postcss';
export declare function getLayerAtRuleAncestor(node: Node): AtRule | null;
@@ -0,0 +1 @@
"use strict";var e=require("postcss-selector-parser"),r=require("@csstools/selector-specificity");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=a(e);const s=["media","supports"],n=["keyframes"],o=new Set(["layer","supports","media","container","scope"]);function l(e){if("atrule"!==e.type)return!1;if("layer"!==e.name.toLowerCase())return!1;let r=e.parent;for(;r;){if("rule"===r.type)return!1;if("atrule"===r.type&&!o.has(r.name.toLowerCase()))return!1;r=r.parent}return!0}class i{constructor(){this.anonymousLayerCount=0,this.layerCount=0,this.anonymousLayerCount=0,this.layerCount=0,this.layerOrder=new Map,this.layerParamsParsed=new Map,this.layerNameParts=new Map}createAnonymousLayerName(){const e=`anonymous-${this.anonymousLayerCount}-6efdb677-bb05-44e5-840f-29d2175862fd`;return this.addLayerNameParts(e),this.layerParamsParsed.set(e,[e]),this.anonymousLayerCount++,e}createImplicitLayerName(e){const r=this.layerNameParts.get(e),a=`implicit-${r[r.length-1]}-b147acf6-11a6-4338-a4d0-80aef4cd1a2f`;return this.addLayerNameParts([...r,a]),this.layerParamsParsed.set(a,[a]),a}addLayerParams(e,r){r?"string"!=typeof r?this.layerParamsParsed.set(e,r):this.layerParamsParsed.set(e,[r]):this.layerParamsParsed.set(e,[e])}addLayerNameParts(e){"string"!=typeof e?this.layerNameParts.set(e.join("."),e):this.layerNameParts.set(e,[e])}getLayerParams(e){const r=[...this.layerParamsParsed.get(e.params)];let a=e.parent;for(;a;)"atrule"===a.type?(l(a)&&r.push(...this.layerParamsParsed.get(a.params)),a=a.parent):a=a.parent;return r.reverse(),r.flatMap((e=>this.layerNameParts.get(e)))}getLayerNameList(e){const r=this.layerNameParts.get(e),a=[];for(let e=0;e<r.length;e++){const t=r.slice(0,e+1).join(".");this.layerParamsParsed.has(t)||this.layerParamsParsed.set(t,[t]),this.layerNameParts.has(t)||this.layerNameParts.set(t,r.slice(0,e+1)),a.push(r.slice(0,e+1).join("."))}return a}sortLayerNames(){for(const[e,r]of this.layerOrder){const a=this.layerNameParts.get(e);for(let e=1;e<a.length;e++){const t=a.slice(0,e).join(".");this.layerOrder.has(t)||this.layerOrder.set(t,r)}}let e=Array.from(this.layerOrder.entries());e=e.sort(((e,r)=>{const a=this.layerNameParts.get(e[0]),t=this.layerNameParts.get(r[0]);if(a[0]!==t[0])return this.layerOrder.get(a[0])-this.layerOrder.get(t[0]);const s=Math.max(a.length,t.length);for(let e=0;e<s;e++){const r=a[e],s=t[e];if(r!==s)return r?s?this.layerOrder.get(a.slice(0,e).join("."))-this.layerOrder.get(t.slice(0,e).join(".")):-1:1}})),this.layerOrder.clear(),e.forEach(((e,r)=>{this.layerOrder.set(e[0],r)}))}}function u(e,r){const a=t.default().astSync(e),s=t.default().astSync(function(e){if(0===e)return"";let r="";for(let a=0;a<e;a++)r+=":not(#\\#)";return r}(r));let n=!1;for(let e=0;e<a.nodes[0].nodes.length;e++)if("combinator"===a.nodes[0].nodes[e].type||t.default.isPseudoElement(a.nodes[0].nodes[e])){a.nodes[0].insertBefore(a.nodes[0].nodes[e],s),n=!0;break}return n||a.nodes[0].insertAfter(a.nodes[0].nodes[a.nodes[0].nodes.length-1],s),a.toString()}function y(e,r){let a=!1;return e.walk((e=>{if(r(e))return a=!0,!1})),a}function c(e,r){let a=!1;return e.walkAtRules((e=>{if(r(e))return a=!0,!1})),a}function d(e){let r=e.parent;for(;r;)if("atrule"===r.type){if(l(r))return r;r=r.parent}else r=r.parent;return null}function p(e){var r;e.walk((e=>{var r;("rule"===e.type||"atrule"===e.type&&["layer",...s].includes(e.name.toLowerCase()))&&(0===(null==(r=e.nodes)?void 0:r.length)&&e.remove())})),0===(null==(r=e.nodes)?void 0:r.length)&&e.remove()}function m(e){let r=e;for(;r;){if(void 0===r.nodes)return;if(r.nodes.length>0)return;const e=r.parent;r.remove(),r=e}}function f(e,r,{result:a,options:t}){e.walkAtRules((e=>{if(!l(e))return;const n=r.getLayerParams(e),o=n.join(".");r.layerOrder.has(o)||(t.onConditionalRulesChangingLayerOrder&&function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if(s.includes(r.name.toLowerCase()))return r;r=r.parent}else r=r.parent;return null}(e)&&!e.params.endsWith("b147acf6-11a6-4338-a4d0-80aef4cd1a2f")&&!e.params.endsWith("6efdb677-bb05-44e5-840f-29d2175862fd")&&e.warn(a,"handling different layer orders in conditional rules is unsupported by this plugin and will cause style differences between browser versions."),r.layerParamsParsed.has(o)||r.layerParamsParsed.set(o,[o]),r.layerNameParts.has(o)||r.layerNameParts.set(o,[...n]),r.getLayerNameList(o).forEach((e=>{r.layerOrder.has(e)||(r.layerOrder.set(e,r.layerCount),r.layerCount+=1)}))),e.nodes&&0!==e.nodes.length||e.remove()}))}const h=e=>{const a=Object.assign({onRevertLayerKeyword:"warn",onConditionalRulesChangingLayerOrder:"warn",onImportLayerRule:"warn"},e);return{postcssPlugin:"postcss-cascade-layers",OnceExit(e,{result:o}){a.onRevertLayerKeyword&&e.walkDecls((e=>{"revert-layer"===e.value.toLowerCase()&&e.warn(o,'handling "revert-layer" is unsupported by this plugin and will cause style differences between browser versions.')})),a.onImportLayerRule&&e.walkAtRules((e=>{"import"===e.name.toLowerCase()Line truncated
@@ -0,0 +1,4 @@
import type { PluginCreator } from 'postcss';
import { pluginOptions } from './options';
declare const creator: PluginCreator<pluginOptions>;
export default creator;
@@ -0,0 +1 @@
import e from"postcss-selector-parser";import{selectorSpecificity as r}from"@csstools/selector-specificity";const a=["media","supports"],t=["keyframes"],s=new Set(["layer","supports","media","container","scope"]);function n(e){if("atrule"!==e.type)return!1;if("layer"!==e.name.toLowerCase())return!1;let r=e.parent;for(;r;){if("rule"===r.type)return!1;if("atrule"===r.type&&!s.has(r.name.toLowerCase()))return!1;r=r.parent}return!0}class o{constructor(){this.anonymousLayerCount=0,this.layerCount=0,this.anonymousLayerCount=0,this.layerCount=0,this.layerOrder=new Map,this.layerParamsParsed=new Map,this.layerNameParts=new Map}createAnonymousLayerName(){const e=`anonymous-${this.anonymousLayerCount}-6efdb677-bb05-44e5-840f-29d2175862fd`;return this.addLayerNameParts(e),this.layerParamsParsed.set(e,[e]),this.anonymousLayerCount++,e}createImplicitLayerName(e){const r=this.layerNameParts.get(e),a=`implicit-${r[r.length-1]}-b147acf6-11a6-4338-a4d0-80aef4cd1a2f`;return this.addLayerNameParts([...r,a]),this.layerParamsParsed.set(a,[a]),a}addLayerParams(e,r){r?"string"!=typeof r?this.layerParamsParsed.set(e,r):this.layerParamsParsed.set(e,[r]):this.layerParamsParsed.set(e,[e])}addLayerNameParts(e){"string"!=typeof e?this.layerNameParts.set(e.join("."),e):this.layerNameParts.set(e,[e])}getLayerParams(e){const r=[...this.layerParamsParsed.get(e.params)];let a=e.parent;for(;a;)"atrule"===a.type?(n(a)&&r.push(...this.layerParamsParsed.get(a.params)),a=a.parent):a=a.parent;return r.reverse(),r.flatMap((e=>this.layerNameParts.get(e)))}getLayerNameList(e){const r=this.layerNameParts.get(e),a=[];for(let e=0;e<r.length;e++){const t=r.slice(0,e+1).join(".");this.layerParamsParsed.has(t)||this.layerParamsParsed.set(t,[t]),this.layerNameParts.has(t)||this.layerNameParts.set(t,r.slice(0,e+1)),a.push(r.slice(0,e+1).join("."))}return a}sortLayerNames(){for(const[e,r]of this.layerOrder){const a=this.layerNameParts.get(e);for(let e=1;e<a.length;e++){const t=a.slice(0,e).join(".");this.layerOrder.has(t)||this.layerOrder.set(t,r)}}let e=Array.from(this.layerOrder.entries());e=e.sort(((e,r)=>{const a=this.layerNameParts.get(e[0]),t=this.layerNameParts.get(r[0]);if(a[0]!==t[0])return this.layerOrder.get(a[0])-this.layerOrder.get(t[0]);const s=Math.max(a.length,t.length);for(let e=0;e<s;e++){const r=a[e],s=t[e];if(r!==s)return r?s?this.layerOrder.get(a.slice(0,e).join("."))-this.layerOrder.get(t.slice(0,e).join(".")):-1:1}})),this.layerOrder.clear(),e.forEach(((e,r)=>{this.layerOrder.set(e[0],r)}))}}function l(r,a){const t=e().astSync(r),s=e().astSync(function(e){if(0===e)return"";let r="";for(let a=0;a<e;a++)r+=":not(#\\#)";return r}(a));let n=!1;for(let r=0;r<t.nodes[0].nodes.length;r++)if("combinator"===t.nodes[0].nodes[r].type||e.isPseudoElement(t.nodes[0].nodes[r])){t.nodes[0].insertBefore(t.nodes[0].nodes[r],s),n=!0;break}return n||t.nodes[0].insertAfter(t.nodes[0].nodes[t.nodes[0].nodes.length-1],s),t.toString()}function i(e,r){let a=!1;return e.walk((e=>{if(r(e))return a=!0,!1})),a}function u(e,r){let a=!1;return e.walkAtRules((e=>{if(r(e))return a=!0,!1})),a}function y(e){let r=e.parent;for(;r;)if("atrule"===r.type){if(n(r))return r;r=r.parent}else r=r.parent;return null}function m(e){var r;e.walk((e=>{var r;("rule"===e.type||"atrule"===e.type&&["layer",...a].includes(e.name.toLowerCase()))&&(0===(null==(r=e.nodes)?void 0:r.length)&&e.remove())})),0===(null==(r=e.nodes)?void 0:r.length)&&e.remove()}function p(e){let r=e;for(;r;){if(void 0===r.nodes)return;if(r.nodes.length>0)return;const e=r.parent;r.remove(),r=e}}function c(e,r,{result:t,options:s}){e.walkAtRules((e=>{if(!n(e))return;const o=r.getLayerParams(e),l=o.join(".");r.layerOrder.has(l)||(s.onConditionalRulesChangingLayerOrder&&function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if(a.includes(r.name.toLowerCase()))return r;r=r.parent}else r=r.parent;return null}(e)&&!e.params.endsWith("b147acf6-11a6-4338-a4d0-80aef4cd1a2f")&&!e.params.endsWith("6efdb677-bb05-44e5-840f-29d2175862fd")&&e.warn(t,"handling different layer orders in conditional rules is unsupported by this plugin and will cause style differences between browser versions."),r.layerParamsParsed.has(l)||r.layerParamsParsed.set(l,[l]),r.layerNameParts.has(l)||r.layerNameParts.set(l,[...o]),r.getLayerNameList(l).forEach((e=>{r.layerOrder.has(e)||(r.layerOrder.set(e,r.layerCount),r.layerCount+=1)}))),e.nodes&&0!==e.nodes.length||e.remove()}))}const d=s=>{const d=Object.assign({onRevertLayerKeyword:"warn",onConditionalRulesChangingLayerOrder:"warn",onImportLayerRule:"warn"},s);return{postcssPlugin:"postcss-cascade-layers",OnceExit(s,{result:f}){d.onRevertLayerKeyword&&s.walkDecls((e=>{"revert-layer"===e.value.toLowerCase()&&e.warn(f,'handling "revert-layer" is unsupported by this plugin and will cause style differences between browser versions.')})),d.onImportLayerRule&&s.walkAtRules((e=>{"import"===e.name.toLowerCase()&&e.params.toLowerCase().includes("layer")&&e.warn(f,"To use @import with layers, the postcss-impLine truncated
@@ -0,0 +1,2 @@
import type { AtRule } from 'postcss';
export declare function isProcessableLayerRule(atRule: AtRule): boolean;
@@ -0,0 +1,18 @@
import type { AtRule } from 'postcss';
export declare class Model {
anonymousLayerCount: number;
layerCount: number;
layerOrder: Map<string, number>;
layerParamsParsed: Map<string, Array<string>>;
layerNameParts: Map<string, Array<string>>;
constructor();
createAnonymousLayerName(): string;
createImplicitLayerName(layerName: string): string;
addLayerParams(key: string, parts?: string): void;
addLayerParams(key: string, parts: Array<string>): void;
addLayerNameParts(parts: string): void;
addLayerNameParts(parts: Array<string>): void;
getLayerParams(layer: AtRule): Array<string>;
getLayerNameList(layerName: string): Array<string>;
sortLayerNames(): void;
}
@@ -0,0 +1,5 @@
export declare type pluginOptions = {
onRevertLayerKeyword: 'warn' | false;
onConditionalRulesChangingLayerOrder: 'warn' | false;
onImportLayerRule: 'warn' | false;
};
@@ -0,0 +1,7 @@
import type { Container, Result } from 'postcss';
import type { Model } from './model';
import { pluginOptions } from './options';
export declare function recordLayerOrder(root: Container, model: Model, { result, options }: {
result: Result;
options: pluginOptions;
}): void;
@@ -0,0 +1,3 @@
import type { Container, ChildNode, AtRule } from 'postcss';
export declare function someInTree(container: Container, predicate: (node: ChildNode) => boolean): boolean;
export declare function someAtRuleInTree(container: Container, predicate: (node: AtRule) => boolean): boolean;
@@ -0,0 +1,3 @@
import type { Container } from 'postcss';
import type { Model } from './model';
export declare function sortRootNodes(root: Container, model: Model): void;
@@ -0,0 +1,2 @@
import type { Container } from 'postcss';
export declare function splitImportantStyles(root: Container): void;