diff --git a/experimental/postcss-gradient-stop-increments/dist/index.cjs b/experimental/postcss-gradient-stop-increments/dist/index.cjs index 17865cecf..88ebfa0b6 100644 --- a/experimental/postcss-gradient-stop-increments/dist/index.cjs +++ b/experimental/postcss-gradient-stop-increments/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("@csstools/css-parser-algorithms"),n=require("@csstools/css-calc"),o=require("@csstools/css-tokenizer");const t=/(repeating-)?(linear|radial|conic)-gradient\(/i,i=/^(repeating-)?(linear|radial|conic)-gradient$/i,s=/^(abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=n=>{const a=Object.assign({preserve:!1},n);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(n){if(!t.test(n.value))return;const r=o.tokenize({css:n.value});if(!r.find((e=>o.isTokenDelim(e)&&"+"===e[4].value)))return;const c=e.stringify(e.replaceComponentValues(e.parseCommaSeparatedListOfComponentValues(r),(n=>{if(!e.isFunctionNode(n))return;const t=n.getName();if(!i.test(t))return;let a=null;for(let t=0;t0)}function isZeroOrNegative(n){return!!(e.isTokenNode(n)&&o.isTokenNumeric(n.value)&&n.value[4].value<=0)}function incrementLengthNode(t,i,s){if(!t)return s;const a=new e.FunctionNode([o.TokenType.Function,"calc(",-1,-1,{value:"calc"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),i,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),s]),[[r]]=n.calcFromComponentValues([[a]]);return r}function maxOfLastAndCurrentLengthNode(t,i){if(!t)return i;const s=new e.FunctionNode([o.TokenType.Function,"max(",-1,-1,{value:"max"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.TokenNode([o.TokenType.Comma,",",-1,-1,void 0]),new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),i]),[[a]]=n.calcFromComponentValues([[s]]);return a}creator.postcss=!0,module.exports=creator; +"use strict";var e=require("@csstools/css-parser-algorithms"),n=require("@csstools/css-calc"),o=require("@csstools/css-tokenizer");const t=/(?:repeating-)?(?:linear|radial|conic)-gradient\(/i,i=/^(?:repeating-)?(?:linear|radial|conic)-gradient$/i,s=/^(?:abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=n=>{const a=Object.assign({preserve:!1},n);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(n){if(!t.test(n.value))return;const r=o.tokenize({css:n.value});if(!r.find((e=>o.isTokenDelim(e)&&"+"===e[4].value)))return;const c=e.stringify(e.replaceComponentValues(e.parseCommaSeparatedListOfComponentValues(r),(n=>{if(!e.isFunctionNode(n))return;const t=n.getName();if(!i.test(t))return;let a=null;for(let t=0;t0)}function isZeroOrNegative(n){return!!(e.isTokenNode(n)&&o.isTokenNumeric(n.value)&&n.value[4].value<=0)}function incrementLengthNode(t,i,s){if(!t)return s;const a=new e.FunctionNode([o.TokenType.Function,"calc(",-1,-1,{value:"calc"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),i,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),s]),[[r]]=n.calcFromComponentValues([[a]]);return r}function maxOfLastAndCurrentLengthNode(t,i){if(!t)return i;const s=new e.FunctionNode([o.TokenType.Function,"max(",-1,-1,{value:"max"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.TokenNode([o.TokenType.Comma,",",-1,-1,void 0]),new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),i]),[[a]]=n.calcFromComponentValues([[s]]);return a}creator.postcss=!0,module.exports=creator; diff --git a/experimental/postcss-gradient-stop-increments/dist/index.mjs b/experimental/postcss-gradient-stop-increments/dist/index.mjs index a887315da..05555841c 100644 --- a/experimental/postcss-gradient-stop-increments/dist/index.mjs +++ b/experimental/postcss-gradient-stop-increments/dist/index.mjs @@ -1 +1 @@ -import{stringify as e,replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as t,isFunctionNode as a,isTokenNode as r,isCommentNode as s,TokenNode as o,FunctionNode as i,WhitespaceNode as c}from"@csstools/css-parser-algorithms";import{calcFromComponentValues as l}from"@csstools/css-calc";import{tokenize as u,isTokenDelim as v,TokenType as m,NumberType as f,isTokenNumeric as d}from"@csstools/css-tokenizer";const p=/(repeating-)?(linear|radial|conic)-gradient\(/i,g=/^(repeating-)?(linear|radial|conic)-gradient$/i,h=/^(abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=i=>{const c=Object.assign({preserve:!1},i);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(i){if(!p.test(i.value))return;const l=u({css:i.value});if(!l.find((e=>v(e)&&"+"===e[4].value)))return;const d=e(n(t(l),(e=>{if(!a(e))return;const n=e.getName();if(!g.test(n))return;let t=null;for(let n=0;n0)}function isZeroOrNegative(e){return!!(r(e)&&d(e.value)&&e.value[4].value<=0)}function incrementLengthNode(e,n,t){if(!e)return t;const a=new i([m.Function,"calc(",-1,-1,{value:"calc"}],[m.CloseParen,")",-1,-1,void 0],[e,new c([[m.Whitespace," ",-1,-1,void 0]]),n,new c([[m.Whitespace," ",-1,-1,void 0]]),t]),[[r]]=l([[a]]);return r}function maxOfLastAndCurrentLengthNode(e,n){if(!e)return n;const t=new i([m.Function,"max(",-1,-1,{value:"max"}],[m.CloseParen,")",-1,-1,void 0],[e,new o([m.Comma,",",-1,-1,void 0]),new c([[m.Whitespace," ",-1,-1,void 0]]),n]),[[a]]=l([[t]]);return a}creator.postcss=!0;export{creator as default}; +import{stringify as e,replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as t,isFunctionNode as a,isTokenNode as r,isCommentNode as s,TokenNode as o,FunctionNode as i,WhitespaceNode as c}from"@csstools/css-parser-algorithms";import{calcFromComponentValues as l}from"@csstools/css-calc";import{tokenize as u,isTokenDelim as v,TokenType as m,NumberType as f,isTokenNumeric as d}from"@csstools/css-tokenizer";const p=/(?:repeating-)?(?:linear|radial|conic)-gradient\(/i,g=/^(?:repeating-)?(?:linear|radial|conic)-gradient$/i,h=/^(?:abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=i=>{const c=Object.assign({preserve:!1},i);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(i){if(!p.test(i.value))return;const l=u({css:i.value});if(!l.find((e=>v(e)&&"+"===e[4].value)))return;const d=e(n(t(l),(e=>{if(!a(e))return;const n=e.getName();if(!g.test(n))return;let t=null;for(let n=0;n0)}function isZeroOrNegative(e){return!!(r(e)&&d(e.value)&&e.value[4].value<=0)}function incrementLengthNode(e,n,t){if(!e)return t;const a=new i([m.Function,"calc(",-1,-1,{value:"calc"}],[m.CloseParen,")",-1,-1,void 0],[e,new c([[m.Whitespace," ",-1,-1,void 0]]),n,new c([[m.Whitespace," ",-1,-1,void 0]]),t]),[[r]]=l([[a]]);return r}function maxOfLastAndCurrentLengthNode(e,n){if(!e)return n;const t=new i([m.Function,"max(",-1,-1,{value:"max"}],[m.CloseParen,")",-1,-1,void 0],[e,new o([m.Comma,",",-1,-1,void 0]),new c([[m.Whitespace," ",-1,-1,void 0]]),n]),[[a]]=l([[t]]);return a}creator.postcss=!0;export{creator as default}; diff --git a/experimental/postcss-gradient-stop-increments/src/index.ts b/experimental/postcss-gradient-stop-increments/src/index.ts index cf5d48606..fec152eeb 100644 --- a/experimental/postcss-gradient-stop-increments/src/index.ts +++ b/experimental/postcss-gradient-stop-increments/src/index.ts @@ -11,9 +11,9 @@ export type pluginOptions = { preserve?: boolean, }; -const GRADIENT_FUNCTION_REGEX = /(repeating-)?(linear|radial|conic)-gradient\(/i; -const GRADIENT_NAME_REGEX = /^(repeating-)?(linear|radial|conic)-gradient$/i; -const MATH_FUNCTION_NAME_REGEX = /^(abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i; +const GRADIENT_FUNCTION_REGEX = /(?:repeating-)?(?:linear|radial|conic)-gradient\(/i; +const GRADIENT_NAME_REGEX = /^(?:repeating-)?(?:linear|radial|conic)-gradient$/i; +const MATH_FUNCTION_NAME_REGEX = /^(?:abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i; const creator: PluginCreator = (opts?: pluginOptions) => { const options: pluginOptions = Object.assign( diff --git a/plugin-packs/postcss-bundler/dist/index.cjs b/plugin-packs/postcss-bundler/dist/index.cjs index 6d014b5b0..82c4f8e6a 100644 --- a/plugin-packs/postcss-bundler/dist/index.cjs +++ b/plugin-packs/postcss-bundler/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("@csstools/css-parser-algorithms"),t=require("@csstools/css-tokenizer"),s=require("path"),o=require("module"),n=require("fs/promises"),r=require("@csstools/postcss-rebase-url");function isWarning(e){return"warning"===e.type}function isNodesStatement(e){return"nodes"===e.type}function isImportStatement(e){return"import"===e.type}function isPreImportStatement(e){return"pre-import"===e.type}const i=/^data:text\/css(?:;(base64|plain))?,/i,a=/^data:text\/css;base64,/i,c=/^data:text\/css;plain,/i;function isValidDataURL(e){return!!e&&i.test(e)}const p=/^charset$/i,u=/^import$/i,l=/^url$/i,m=/^layer$/i,d=/^supports$/i;function parseAtImport(s){const o=t.tokenize({css:s});if(2===o.length&&(t.isTokenString(o[0])||t.isTokenURL(o[0]))){let e=o[0][4].value;return e=stripHash(e),!!e&&{uri:e,fullUri:o[0][1]}}const n=e.parseListOfComponentValues(o);let r,i,a,c="",p="";for(let s=0;s{const i=parseStylesheet(e,t,s,o,n);if(r.charset&&i.charset&&r.charset.params.toLowerCase()!==i.charset.params.toLowerCase())throw i.charset.error(`Incompatible @charset statements:\n ${i.charset.params} specified in ${i.charset.source?.input.file}\n ${r.charset.params} specified in ${r.charset.source?.input.file}`);!r.charset&&i.charset&&(r.charset=i.charset),r.statements.push(...i.statements)})),r;let i,a,c=[],l=[];for(let r=0;r({postcssPlugin:"noop-plugin",Once(){}});async function parseStyles(e,t,s,o,n,r){const i=parseStylesheet(e,t,s,o,n);{let t,s,o;const n=[];for(const a of i.statements)isImportStatement(a)&&isProcessableURL(a.uri)&&(t&&s&&o||([t,s,o]=createRequire(a.node,e),t&&s&&o))&&n.push(resolveImportId(e,a,r,t,s,o));n.length&&await Promise.all(n)}for(let e=0;e{if(isWarning(s)||isPreImportStatement(s)||!s.conditions?.length)return;if(isImportStatement(s))return void(s.node.params=base64EncodedConditionalImport(s.fullUri,s.conditions));const n=s.nodes;if(!n.length)return;const r=n[0].parent;if(!r)return;const i=[];for(const e of s.conditions){if(void 0!==e.media){const o=t({name:"media",params:e.media,source:s.importingNode?.source??r.source});i.push(o)}if(void 0!==e.supports){const o=t({name:"supports",params:"("+e.supports+")",source:s.importingNode?.source??r.source});i.push(o)}if(void 0!==e.layer){const o=t({name:"layer",params:e.layer,source:s.importingNode?.source??r.source});i.push(o)}}const a=i[0];if(!a)return;for(let e=0;e{e.parent=void 0})),c.append(n),e.statements[o]={type:"nodes",nodes:[a],conditions:s.conditions,from:s.from,importingNode:s.importingNode}}))}function applyStyles(e,t){t.nodes=[],e.charset&&(e.charset.parent=void 0,t.append(e.charset)),e.statements.forEach((e=>{isImportStatement(e)?(e.node.parent=void 0,t.append(e.node)):isNodesStatement(e)&&e.nodes.forEach((e=>{e.parent=void 0,t.append(e)}))}))}function postProcess(e,t){let s=-1,o=-1,n=-1;for(let t=0;t({postcssPlugin:"postcss-bundler",async Once(e,{result:t,atRule:s,postcss:o}){const n=await parseStyles(t,e,null,[],[],o);postProcess(n,s),applyConditions(n,s),applyStyles(n,e)}});creator$1.postcss=!0;const creator=()=>({postcssPlugin:"postcss-bundler",plugins:[creator$1(),r()]});creator.postcss=!0,module.exports=creator; +"use strict";var e=require("@csstools/css-parser-algorithms"),t=require("@csstools/css-tokenizer"),s=require("path"),o=require("module"),n=require("fs/promises"),r=require("@csstools/postcss-rebase-url");function isWarning(e){return"warning"===e.type}function isNodesStatement(e){return"nodes"===e.type}function isImportStatement(e){return"import"===e.type}function isPreImportStatement(e){return"pre-import"===e.type}const i=/^data:text\/css(?:;(?:base64|plain))?,/i,a=/^data:text\/css;base64,/i,c=/^data:text\/css;plain,/i;function isValidDataURL(e){return!!e&&i.test(e)}const p=/^charset$/i,u=/^import$/i,l=/^url$/i,m=/^layer$/i,d=/^supports$/i;function parseAtImport(s){const o=t.tokenize({css:s});if(2===o.length&&(t.isTokenString(o[0])||t.isTokenURL(o[0]))){let e=o[0][4].value;return e=stripHash(e),!!e&&{uri:e,fullUri:o[0][1]}}const n=e.parseListOfComponentValues(o);let r,i,a,c="",p="";for(let s=0;s{const i=parseStylesheet(e,t,s,o,n);if(r.charset&&i.charset&&r.charset.params.toLowerCase()!==i.charset.params.toLowerCase())throw i.charset.error(`Incompatible @charset statements:\n ${i.charset.params} specified in ${i.charset.source?.input.file}\n ${r.charset.params} specified in ${r.charset.source?.input.file}`);!r.charset&&i.charset&&(r.charset=i.charset),r.statements.push(...i.statements)})),r;let i,a,c=[],l=[];for(let r=0;r({postcssPlugin:"noop-plugin",Once(){}});async function parseStyles(e,t,s,o,n,r){const i=parseStylesheet(e,t,s,o,n);{let t,s,o;const n=[];for(const a of i.statements)isImportStatement(a)&&isProcessableURL(a.uri)&&(t&&s&&o||([t,s,o]=createRequire(a.node,e),t&&s&&o))&&n.push(resolveImportId(e,a,r,t,s,o));n.length&&await Promise.all(n)}for(let e=0;e{if(isWarning(s)||isPreImportStatement(s)||!s.conditions?.length)return;if(isImportStatement(s))return void(s.node.params=base64EncodedConditionalImport(s.fullUri,s.conditions));const n=s.nodes;if(!n.length)return;const r=n[0].parent;if(!r)return;const i=[];for(const e of s.conditions){if(void 0!==e.media){const o=t({name:"media",params:e.media,source:s.importingNode?.source??r.source});i.push(o)}if(void 0!==e.supports){const o=t({name:"supports",params:"("+e.supports+")",source:s.importingNode?.source??r.source});i.push(o)}if(void 0!==e.layer){const o=t({name:"layer",params:e.layer,source:s.importingNode?.source??r.source});i.push(o)}}const a=i[0];if(!a)return;for(let e=0;e{e.parent=void 0})),c.append(n),e.statements[o]={type:"nodes",nodes:[a],conditions:s.conditions,from:s.from,importingNode:s.importingNode}}))}function applyStyles(e,t){t.nodes=[],e.charset&&(e.charset.parent=void 0,t.append(e.charset)),e.statements.forEach((e=>{isImportStatement(e)?(e.node.parent=void 0,t.append(e.node)):isNodesStatement(e)&&e.nodes.forEach((e=>{e.parent=void 0,t.append(e)}))}))}function postProcess(e,t){let s=-1,o=-1,n=-1;for(let t=0;t({postcssPlugin:"postcss-bundler",async Once(e,{result:t,atRule:s,postcss:o}){const n=await parseStyles(t,e,null,[],[],o);postProcess(n,s),applyConditions(n,s),applyStyles(n,e)}});creator$1.postcss=!0;const creator=()=>({postcssPlugin:"postcss-bundler",plugins:[creator$1(),r()]});creator.postcss=!0,module.exports=creator; diff --git a/plugin-packs/postcss-bundler/dist/index.mjs b/plugin-packs/postcss-bundler/dist/index.mjs index d87ca10b1..e9606786d 100644 --- a/plugin-packs/postcss-bundler/dist/index.mjs +++ b/plugin-packs/postcss-bundler/dist/index.mjs @@ -1 +1 @@ -import{parseListOfComponentValues as e,isWhitespaceNode as t,isCommentNode as s,isTokenNode as o,isFunctionNode as r,stringify as n}from"@csstools/css-parser-algorithms";import{tokenize as i,isTokenString as a,isTokenURL as c,isTokenIdent as p}from"@csstools/css-tokenizer";import u from"path";import l from"module";import m from"fs/promises";import d from"@csstools/postcss-rebase-url";function isWarning(e){return"warning"===e.type}function isNodesStatement(e){return"nodes"===e.type}function isImportStatement(e){return"import"===e.type}function isPreImportStatement(e){return"pre-import"===e.type}const f=/^data:text\/css(?:;(base64|plain))?,/i,h=/^data:text\/css;base64,/i,y=/^data:text\/css;plain,/i;function isValidDataURL(e){return!!e&&f.test(e)}const g=/^charset$/i,v=/^import$/i,I=/^url$/i,S=/^layer$/i,b=/^supports$/i;function parseAtImport(u){const l=i({css:u});if(2===l.length&&(a(l[0])||c(l[0]))){let e=l[0][4].value;return e=stripHash(e),!!e&&{uri:e,fullUri:l[0][1]}}const m=e(l);let d,f,h,y="",g="";for(let e=0;e{const i=parseStylesheet(e,t,s,o,r);if(n.charset&&i.charset&&n.charset.params.toLowerCase()!==i.charset.params.toLowerCase())throw i.charset.error(`Incompatible @charset statements:\n ${i.charset.params} specified in ${i.charset.source?.input.file}\n ${n.charset.params} specified in ${n.charset.source?.input.file}`);!n.charset&&i.charset&&(n.charset=i.charset),n.statements.push(...i.statements)})),n;let i,a,c=[],p=[];for(let n=0;n({postcssPlugin:"noop-plugin",Once(){}});async function parseStyles(e,t,s,o,r,n){const i=parseStylesheet(e,t,s,o,r);{let t,s,o;const r=[];for(const a of i.statements)isImportStatement(a)&&isProcessableURL(a.uri)&&(t&&s&&o||([t,s,o]=createRequire(a.node,e),t&&s&&o))&&r.push(resolveImportId(e,a,n,t,s,o));r.length&&await Promise.all(r)}for(let e=0;e{if(isWarning(s)||isPreImportStatement(s)||!s.conditions?.length)return;if(isImportStatement(s))return void(s.node.params=base64EncodedConditionalImport(s.fullUri,s.conditions));const r=s.nodes;if(!r.length)return;const n=r[0].parent;if(!n)return;const i=[];for(const e of s.conditions){if(void 0!==e.media){const o=t({name:"media",params:e.media,source:s.importingNode?.source??n.source});i.push(o)}if(void 0!==e.supports){const o=t({name:"supports",params:"("+e.supports+")",source:s.importingNode?.source??n.source});i.push(o)}if(void 0!==e.layer){const o=t({name:"layer",params:e.layer,source:s.importingNode?.source??n.source});i.push(o)}}const a=i[0];if(!a)return;for(let e=0;e{e.parent=void 0})),c.append(r),e.statements[o]={type:"nodes",nodes:[a],conditions:s.conditions,from:s.from,importingNode:s.importingNode}}))}function applyStyles(e,t){t.nodes=[],e.charset&&(e.charset.parent=void 0,t.append(e.charset)),e.statements.forEach((e=>{isImportStatement(e)?(e.node.parent=void 0,t.append(e.node)):isNodesStatement(e)&&e.nodes.forEach((e=>{e.parent=void 0,t.append(e)}))}))}function postProcess(e,t){let s=-1,o=-1,r=-1;for(let t=0;t({postcssPlugin:"postcss-bundler",async Once(e,{result:t,atRule:s,postcss:o}){const r=await parseStyles(t,e,null,[],[],o);postProcess(r,s),applyConditions(r,s),applyStyles(r,e)}});creator$1.postcss=!0;const creator=()=>({postcssPlugin:"postcss-bundler",plugins:[creator$1(),d()]});creator.postcss=!0;export{creator as default}; +import{parseListOfComponentValues as e,isWhitespaceNode as t,isCommentNode as s,isTokenNode as o,isFunctionNode as r,stringify as n}from"@csstools/css-parser-algorithms";import{tokenize as i,isTokenString as a,isTokenURL as c,isTokenIdent as p}from"@csstools/css-tokenizer";import u from"path";import l from"module";import m from"fs/promises";import d from"@csstools/postcss-rebase-url";function isWarning(e){return"warning"===e.type}function isNodesStatement(e){return"nodes"===e.type}function isImportStatement(e){return"import"===e.type}function isPreImportStatement(e){return"pre-import"===e.type}const f=/^data:text\/css(?:;(?:base64|plain))?,/i,h=/^data:text\/css;base64,/i,y=/^data:text\/css;plain,/i;function isValidDataURL(e){return!!e&&f.test(e)}const g=/^charset$/i,v=/^import$/i,I=/^url$/i,S=/^layer$/i,b=/^supports$/i;function parseAtImport(u){const l=i({css:u});if(2===l.length&&(a(l[0])||c(l[0]))){let e=l[0][4].value;return e=stripHash(e),!!e&&{uri:e,fullUri:l[0][1]}}const m=e(l);let d,f,h,y="",g="";for(let e=0;e{const i=parseStylesheet(e,t,s,o,r);if(n.charset&&i.charset&&n.charset.params.toLowerCase()!==i.charset.params.toLowerCase())throw i.charset.error(`Incompatible @charset statements:\n ${i.charset.params} specified in ${i.charset.source?.input.file}\n ${n.charset.params} specified in ${n.charset.source?.input.file}`);!n.charset&&i.charset&&(n.charset=i.charset),n.statements.push(...i.statements)})),n;let i,a,c=[],p=[];for(let n=0;n({postcssPlugin:"noop-plugin",Once(){}});async function parseStyles(e,t,s,o,r,n){const i=parseStylesheet(e,t,s,o,r);{let t,s,o;const r=[];for(const a of i.statements)isImportStatement(a)&&isProcessableURL(a.uri)&&(t&&s&&o||([t,s,o]=createRequire(a.node,e),t&&s&&o))&&r.push(resolveImportId(e,a,n,t,s,o));r.length&&await Promise.all(r)}for(let e=0;e{if(isWarning(s)||isPreImportStatement(s)||!s.conditions?.length)return;if(isImportStatement(s))return void(s.node.params=base64EncodedConditionalImport(s.fullUri,s.conditions));const r=s.nodes;if(!r.length)return;const n=r[0].parent;if(!n)return;const i=[];for(const e of s.conditions){if(void 0!==e.media){const o=t({name:"media",params:e.media,source:s.importingNode?.source??n.source});i.push(o)}if(void 0!==e.supports){const o=t({name:"supports",params:"("+e.supports+")",source:s.importingNode?.source??n.source});i.push(o)}if(void 0!==e.layer){const o=t({name:"layer",params:e.layer,source:s.importingNode?.source??n.source});i.push(o)}}const a=i[0];if(!a)return;for(let e=0;e{e.parent=void 0})),c.append(r),e.statements[o]={type:"nodes",nodes:[a],conditions:s.conditions,from:s.from,importingNode:s.importingNode}}))}function applyStyles(e,t){t.nodes=[],e.charset&&(e.charset.parent=void 0,t.append(e.charset)),e.statements.forEach((e=>{isImportStatement(e)?(e.node.parent=void 0,t.append(e.node)):isNodesStatement(e)&&e.nodes.forEach((e=>{e.parent=void 0,t.append(e)}))}))}function postProcess(e,t){let s=-1,o=-1,r=-1;for(let t=0;t({postcssPlugin:"postcss-bundler",async Once(e,{result:t,atRule:s,postcss:o}){const r=await parseStyles(t,e,null,[],[],o);postProcess(r,s),applyConditions(r,s),applyStyles(r,e)}});creator$1.postcss=!0;const creator=()=>({postcssPlugin:"postcss-bundler",plugins:[creator$1(),d()]});creator.postcss=!0;export{creator as default}; diff --git a/plugin-packs/postcss-bundler/src/postcss-import/lib/data-url.ts b/plugin-packs/postcss-bundler/src/postcss-import/lib/data-url.ts index 1c270a163..8bb0464bf 100644 --- a/plugin-packs/postcss-bundler/src/postcss-import/lib/data-url.ts +++ b/plugin-packs/postcss-bundler/src/postcss-import/lib/data-url.ts @@ -1,18 +1,18 @@ -const ANY_DATA_URL_REGEXP = /^data:text\/css(?:;(base64|plain))?,/i; -const BASE64_DATA_URL_REGEXP = /^data:text\/css;base64,/i; -const PLAIN_DATA_URL_REGEXP = /^data:text\/css;plain,/i; +const ANY_DATA_URL_REGEX = /^data:text\/css(?:;(?:base64|plain))?,/i; +const BASE64_DATA_URL_REGEX = /^data:text\/css;base64,/i; +const PLAIN_DATA_URL_REGEX = /^data:text\/css;plain,/i; export function isValidDataURL(url?: string): boolean { - return !!url && ANY_DATA_URL_REGEXP.test(url); + return !!url && ANY_DATA_URL_REGEX.test(url); } export function dataURLContents(url: string): string { - if (BASE64_DATA_URL_REGEXP.test(url)) { + if (BASE64_DATA_URL_REGEX.test(url)) { // "data:text/css;base64,".length === 21 return Buffer.from(url.slice(21), 'base64').toString(); } - if (PLAIN_DATA_URL_REGEXP.test(url)) { + if (PLAIN_DATA_URL_REGEX.test(url)) { // "data:text/css;plain,".length === 20 return decodeURIComponent(url.slice(20)); } diff --git a/plugins/postcss-attribute-case-insensitive/dist/index.cjs b/plugins/postcss-attribute-case-insensitive/dist/index.cjs index 38c1791e4..87e4e618e 100644 --- a/plugins/postcss-attribute-case-insensitive/dist/index.cjs +++ b/plugins/postcss-attribute-case-insensitive/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("postcss-selector-parser");function nodeIsInsensitiveAttribute(e){return"attribute"===e.type&&(e.insensitive??!1)}function selectorHasInsensitiveAttribute(e){return e.some(nodeIsInsensitiveAttribute)}function transformString(e,t,s){const r=s.charAt(t);if(""===r)return e;let n=e.map((e=>e+r));const o=r.toLocaleUpperCase();return o!==r&&(n=n.concat(e.map((e=>e+o)))),transformString(n,t+1,s)}function createNewSelectors(t){let s=[e.selector({value:"",nodes:[]})];return t.each((e=>{if(!nodeIsInsensitiveAttribute(e))return void s.forEach((t=>{t.append(e.clone())}));const t=transformString([""],0,(r=e).value??"").map((e=>{const t=r.clone({spaces:{after:r.spaces.after,before:r.spaces.before},insensitive:!1});return t.setValue(e),t}));var r;const n=[];t.forEach((e=>{s.forEach((t=>{const s=t.clone({});s.append(e),n.push(s)}))})),s=n})),s}const creator=t=>{const s=Object.assign({preserve:!1},t);return{postcssPlugin:"postcss-attribute-case-insensitive",prepare(){const t=new WeakSet;return{postcssPlugin:"postcss-attribute-case-insensitive",Rule(r,{result:n}){if(t.has(r))return;if(!/i\s*]/gim.test(r.selector))return;let o;try{o=e((e=>{let t=[];e.each((e=>{selectorHasInsensitiveAttribute(e)&&(t=t.concat(createNewSelectors(e)),e.remove())})),t.length&&t.forEach((t=>e.append(t)))})).processSync(r.selector)}catch(e){return void r.warn(n,`Failed to parse selector : "${r.selector}" with message: "${e instanceof Error?e.message:e}"`)}o!==r.selector&&(t.add(r),r.cloneBefore({selector:o}),s.preserve||r.remove())}}}}};creator.postcss=!0,module.exports=creator; +"use strict";var e=require("postcss-selector-parser");function nodeIsInsensitiveAttribute(e){return"attribute"===e.type&&(e.insensitive??!1)}function selectorHasInsensitiveAttribute(e){return e.some(nodeIsInsensitiveAttribute)}function transformString(e,t,s){const r=s.charAt(t);if(""===r)return e;let n=e.map((e=>e+r));const o=r.toLocaleUpperCase();return o!==r&&(n=n.concat(e.map((e=>e+o)))),transformString(n,t+1,s)}function createNewSelectors(t){let s=[e.selector({value:"",nodes:[]})];return t.each((e=>{if(!nodeIsInsensitiveAttribute(e))return void s.forEach((t=>{t.append(e.clone())}));const t=transformString([""],0,(r=e).value??"").map((e=>{const t=r.clone({spaces:{after:r.spaces.after,before:r.spaces.before},insensitive:!1});return t.setValue(e),t}));var r;const n=[];t.forEach((e=>{s.forEach((t=>{const s=t.clone({});s.append(e),n.push(s)}))})),s=n})),s}const creator=t=>{const s=Object.assign({preserve:!1},t);return{postcssPlugin:"postcss-attribute-case-insensitive",prepare(){const t=new WeakSet;return{postcssPlugin:"postcss-attribute-case-insensitive",Rule(r,{result:n}){if(t.has(r))return;if(!/i\s*\]/i.test(r.selector))return;let o;try{o=e((e=>{let t=[];e.each((e=>{selectorHasInsensitiveAttribute(e)&&(t=t.concat(createNewSelectors(e)),e.remove())})),t.length&&t.forEach((t=>e.append(t)))})).processSync(r.selector)}catch(e){return void r.warn(n,`Failed to parse selector : "${r.selector}" with message: "${e instanceof Error?e.message:e}"`)}o!==r.selector&&(t.add(r),r.cloneBefore({selector:o}),s.preserve||r.remove())}}}}};creator.postcss=!0,module.exports=creator; diff --git a/plugins/postcss-attribute-case-insensitive/dist/index.mjs b/plugins/postcss-attribute-case-insensitive/dist/index.mjs index 6da75f8c5..a4d2eeca0 100644 --- a/plugins/postcss-attribute-case-insensitive/dist/index.mjs +++ b/plugins/postcss-attribute-case-insensitive/dist/index.mjs @@ -1 +1 @@ -import e from"postcss-selector-parser";function nodeIsInsensitiveAttribute(e){return"attribute"===e.type&&(e.insensitive??!1)}function selectorHasInsensitiveAttribute(e){return e.some(nodeIsInsensitiveAttribute)}function transformString(e,t,s){const r=s.charAt(t);if(""===r)return e;let n=e.map((e=>e+r));const o=r.toLocaleUpperCase();return o!==r&&(n=n.concat(e.map((e=>e+o)))),transformString(n,t+1,s)}function createNewSelectors(t){let s=[e.selector({value:"",nodes:[]})];return t.each((e=>{if(!nodeIsInsensitiveAttribute(e))return void s.forEach((t=>{t.append(e.clone())}));const t=transformString([""],0,(r=e).value??"").map((e=>{const t=r.clone({spaces:{after:r.spaces.after,before:r.spaces.before},insensitive:!1});return t.setValue(e),t}));var r;const n=[];t.forEach((e=>{s.forEach((t=>{const s=t.clone({});s.append(e),n.push(s)}))})),s=n})),s}const creator=t=>{const s=Object.assign({preserve:!1},t);return{postcssPlugin:"postcss-attribute-case-insensitive",prepare(){const t=new WeakSet;return{postcssPlugin:"postcss-attribute-case-insensitive",Rule(r,{result:n}){if(t.has(r))return;if(!/i\s*]/gim.test(r.selector))return;let o;try{o=e((e=>{let t=[];e.each((e=>{selectorHasInsensitiveAttribute(e)&&(t=t.concat(createNewSelectors(e)),e.remove())})),t.length&&t.forEach((t=>e.append(t)))})).processSync(r.selector)}catch(e){return void r.warn(n,`Failed to parse selector : "${r.selector}" with message: "${e instanceof Error?e.message:e}"`)}o!==r.selector&&(t.add(r),r.cloneBefore({selector:o}),s.preserve||r.remove())}}}}};creator.postcss=!0;export{creator as default}; +import e from"postcss-selector-parser";function nodeIsInsensitiveAttribute(e){return"attribute"===e.type&&(e.insensitive??!1)}function selectorHasInsensitiveAttribute(e){return e.some(nodeIsInsensitiveAttribute)}function transformString(e,t,s){const r=s.charAt(t);if(""===r)return e;let n=e.map((e=>e+r));const o=r.toLocaleUpperCase();return o!==r&&(n=n.concat(e.map((e=>e+o)))),transformString(n,t+1,s)}function createNewSelectors(t){let s=[e.selector({value:"",nodes:[]})];return t.each((e=>{if(!nodeIsInsensitiveAttribute(e))return void s.forEach((t=>{t.append(e.clone())}));const t=transformString([""],0,(r=e).value??"").map((e=>{const t=r.clone({spaces:{after:r.spaces.after,before:r.spaces.before},insensitive:!1});return t.setValue(e),t}));var r;const n=[];t.forEach((e=>{s.forEach((t=>{const s=t.clone({});s.append(e),n.push(s)}))})),s=n})),s}const creator=t=>{const s=Object.assign({preserve:!1},t);return{postcssPlugin:"postcss-attribute-case-insensitive",prepare(){const t=new WeakSet;return{postcssPlugin:"postcss-attribute-case-insensitive",Rule(r,{result:n}){if(t.has(r))return;if(!/i\s*\]/i.test(r.selector))return;let o;try{o=e((e=>{let t=[];e.each((e=>{selectorHasInsensitiveAttribute(e)&&(t=t.concat(createNewSelectors(e)),e.remove())})),t.length&&t.forEach((t=>e.append(t)))})).processSync(r.selector)}catch(e){return void r.warn(n,`Failed to parse selector : "${r.selector}" with message: "${e instanceof Error?e.message:e}"`)}o!==r.selector&&(t.add(r),r.cloneBefore({selector:o}),s.preserve||r.remove())}}}}};creator.postcss=!0;export{creator as default}; diff --git a/plugins/postcss-attribute-case-insensitive/src/index.ts b/plugins/postcss-attribute-case-insensitive/src/index.ts index 7395c98d5..7db3f5622 100644 --- a/plugins/postcss-attribute-case-insensitive/src/index.ts +++ b/plugins/postcss-attribute-case-insensitive/src/index.ts @@ -98,7 +98,7 @@ const creator: PluginCreator = (opts?: pluginOptions) => { return; } - if (!(/i\s*]/gmi.test(rule.selector))) { + if (!(/i\s*\]/i.test(rule.selector))) { return; } diff --git a/plugins/postcss-browser-comments/dist/index.cjs b/plugins/postcss-browser-comments/dist/index.cjs index af9dfe4ee..f85da74e9 100644 --- a/plugins/postcss-browser-comments/dist/index.cjs +++ b/plugins/postcss-browser-comments/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("browserslist");const creator=s=>({postcssPlugin:"postcss-browser-comments",prepare(t){console.log("result",t.root?.source?.input.file);const r=new Set(e(Object(s).browsers||null,{path:t.root?.source?.input.file}));return{postcssPlugin:"postcss-browser-comments",Once(s){const t=s.nodes.slice(0);for(const s of t){if(!isBrowserCommentNode(s))continue;const t=s.next();if(!t||"rule"!==t.type)continue;const o=getBrowserData(s.text);o.isNumbered?(t.nodes.filter(isBrowserReferenceCommentNode).map((s=>{const t=parseFloat(s.text)-1,n=e(o.browserslist[t]);browserslistsOverlap(r,n)||(s.prev()?.remove(),s.remove())})),t.nodes.length||(t.remove(),s.remove())):browserslistsOverlap(r,e(o.browserslist))||(t.remove(),s.remove())}}}}});function isBrowserCommentNode(e){return"comment"===e.type&&(!!s.test(e.text)&&"rule"===e.next()?.type)}creator.postcss=!0;const s=/^\*\n * /;function isBrowserReferenceCommentNode(e){return"comment"===e.type&&t.test(e.text)}const t=/^\d+$/;function getBrowserData(e){const s=e.match(r);return s?{browserslist:s.map((e=>getBrowsersList(e.replace(n,"$1")))),isNumbered:!0}:{browserslist:getBrowsersList(e.replace(o,"")),isNumbered:!1}}const r=/(\n \* \d+\. (?:[^\n]+|\n \* {4,})+)/g,o=/^\*\n \* ?|\n \*/g,n=/\n \* (?:( )\s*)?/g;function getBrowsersList(e){return e.split(c).slice(1).map((e=>e.split(i).filter((e=>e)))).reduce(((e,s)=>e.concat(s)),[]).map((e=>e.replace(l,((e,s,t)=>"all"===s?"> 0%":`${s}${t?/^((?:\d*\.)?\d+)-$/.test(t)?` <= ${t.slice(0,-1)}`:` ${t}`:" > 0"}`)).toLowerCase()))}const c=/\s+in\s+/,i=/(?: and|, and|,)/,l=/^\s*(\w+)(?: ((?:(?:\d*\.)?\d+-)?(?:\d*\.)?\d+[+-]?))?.*$/;function browserslistsOverlap(e,s){return s.some((s=>e.has(s)))}module.exports=creator; +"use strict";var e=require("browserslist");const creator=s=>({postcssPlugin:"postcss-browser-comments",prepare(t){console.log("result",t.root?.source?.input.file);const r=new Set(e(Object(s).browsers||null,{path:t.root?.source?.input.file}));return{postcssPlugin:"postcss-browser-comments",Once(s){const t=s.nodes.slice(0);for(const s of t){if(!isBrowserCommentNode(s))continue;const t=s.next();if(!t||"rule"!==t.type)continue;const o=getBrowserData(s.text);o.isNumbered?(t.nodes.filter(isBrowserReferenceCommentNode).map((s=>{const t=parseFloat(s.text)-1,n=e(o.browserslist[t]);browserslistsOverlap(r,n)||(s.prev()?.remove(),s.remove())})),t.nodes.length||(t.remove(),s.remove())):browserslistsOverlap(r,e(o.browserslist))||(t.remove(),s.remove())}}}}});function isBrowserCommentNode(e){return"comment"===e.type&&(!!s.test(e.text)&&"rule"===e.next()?.type)}creator.postcss=!0;const s=/^\*\n +/;function isBrowserReferenceCommentNode(e){return"comment"===e.type&&t.test(e.text)}const t=/^\d+$/;function getBrowserData(e){const s=e.match(r);return s?{browserslist:s.map((e=>getBrowsersList(e.replace(n,"$1")))),isNumbered:!0}:{browserslist:getBrowsersList(e.replace(o,"")),isNumbered:!1}}const r=/(\n \* \d+\. (?:[^\n]|\n \* {4,})+)/g,o=/^\*\n \* ?|\n \*/g,n=/\n \* (?:( )\s*)?/g;function getBrowsersList(e){return e.split(c).slice(1).map((e=>e.split(i).filter((e=>e)))).reduce(((e,s)=>e.concat(s)),[]).map((e=>e.replace(l,((e,s,t)=>"all"===s?"> 0%":`${s}${t?/^((?:\d*\.)?\d+)-$/.test(t)?` <= ${t.slice(0,-1)}`:` ${t}`:" > 0"}`)).toLowerCase()))}const c=/\s+in\s+/,i=/ and|, and|,/,l=/^\s*(\w+)(?: ((?:(?:\d*\.)?\d+-)?(?:\d*\.)?\d+[+-]?))?.*$/;function browserslistsOverlap(e,s){return s.some((s=>e.has(s)))}module.exports=creator; diff --git a/plugins/postcss-browser-comments/dist/index.mjs b/plugins/postcss-browser-comments/dist/index.mjs index beb60c4ac..776cd1ca2 100644 --- a/plugins/postcss-browser-comments/dist/index.mjs +++ b/plugins/postcss-browser-comments/dist/index.mjs @@ -1 +1 @@ -import e from"browserslist";const creator=s=>({postcssPlugin:"postcss-browser-comments",prepare(t){console.log("result",t.root?.source?.input.file);const r=new Set(e(Object(s).browsers||null,{path:t.root?.source?.input.file}));return{postcssPlugin:"postcss-browser-comments",Once(s){const t=s.nodes.slice(0);for(const s of t){if(!isBrowserCommentNode(s))continue;const t=s.next();if(!t||"rule"!==t.type)continue;const o=getBrowserData(s.text);o.isNumbered?(t.nodes.filter(isBrowserReferenceCommentNode).map((s=>{const t=parseFloat(s.text)-1,n=e(o.browserslist[t]);browserslistsOverlap(r,n)||(s.prev()?.remove(),s.remove())})),t.nodes.length||(t.remove(),s.remove())):browserslistsOverlap(r,e(o.browserslist))||(t.remove(),s.remove())}}}}});function isBrowserCommentNode(e){return"comment"===e.type&&(!!s.test(e.text)&&"rule"===e.next()?.type)}creator.postcss=!0;const s=/^\*\n * /;function isBrowserReferenceCommentNode(e){return"comment"===e.type&&t.test(e.text)}const t=/^\d+$/;function getBrowserData(e){const s=e.match(r);return s?{browserslist:s.map((e=>getBrowsersList(e.replace(n,"$1")))),isNumbered:!0}:{browserslist:getBrowsersList(e.replace(o,"")),isNumbered:!1}}const r=/(\n \* \d+\. (?:[^\n]+|\n \* {4,})+)/g,o=/^\*\n \* ?|\n \*/g,n=/\n \* (?:( )\s*)?/g;function getBrowsersList(e){return e.split(c).slice(1).map((e=>e.split(i).filter((e=>e)))).reduce(((e,s)=>e.concat(s)),[]).map((e=>e.replace(l,((e,s,t)=>"all"===s?"> 0%":`${s}${t?/^((?:\d*\.)?\d+)-$/.test(t)?` <= ${t.slice(0,-1)}`:` ${t}`:" > 0"}`)).toLowerCase()))}const c=/\s+in\s+/,i=/(?: and|, and|,)/,l=/^\s*(\w+)(?: ((?:(?:\d*\.)?\d+-)?(?:\d*\.)?\d+[+-]?))?.*$/;function browserslistsOverlap(e,s){return s.some((s=>e.has(s)))}export{creator as default}; +import e from"browserslist";const creator=s=>({postcssPlugin:"postcss-browser-comments",prepare(t){console.log("result",t.root?.source?.input.file);const r=new Set(e(Object(s).browsers||null,{path:t.root?.source?.input.file}));return{postcssPlugin:"postcss-browser-comments",Once(s){const t=s.nodes.slice(0);for(const s of t){if(!isBrowserCommentNode(s))continue;const t=s.next();if(!t||"rule"!==t.type)continue;const o=getBrowserData(s.text);o.isNumbered?(t.nodes.filter(isBrowserReferenceCommentNode).map((s=>{const t=parseFloat(s.text)-1,n=e(o.browserslist[t]);browserslistsOverlap(r,n)||(s.prev()?.remove(),s.remove())})),t.nodes.length||(t.remove(),s.remove())):browserslistsOverlap(r,e(o.browserslist))||(t.remove(),s.remove())}}}}});function isBrowserCommentNode(e){return"comment"===e.type&&(!!s.test(e.text)&&"rule"===e.next()?.type)}creator.postcss=!0;const s=/^\*\n +/;function isBrowserReferenceCommentNode(e){return"comment"===e.type&&t.test(e.text)}const t=/^\d+$/;function getBrowserData(e){const s=e.match(r);return s?{browserslist:s.map((e=>getBrowsersList(e.replace(n,"$1")))),isNumbered:!0}:{browserslist:getBrowsersList(e.replace(o,"")),isNumbered:!1}}const r=/(\n \* \d+\. (?:[^\n]|\n \* {4,})+)/g,o=/^\*\n \* ?|\n \*/g,n=/\n \* (?:( )\s*)?/g;function getBrowsersList(e){return e.split(c).slice(1).map((e=>e.split(i).filter((e=>e)))).reduce(((e,s)=>e.concat(s)),[]).map((e=>e.replace(l,((e,s,t)=>"all"===s?"> 0%":`${s}${t?/^((?:\d*\.)?\d+)-$/.test(t)?` <= ${t.slice(0,-1)}`:` ${t}`:" > 0"}`)).toLowerCase()))}const c=/\s+in\s+/,i=/ and|, and|,/,l=/^\s*(\w+)(?: ((?:(?:\d*\.)?\d+-)?(?:\d*\.)?\d+[+-]?))?.*$/;function browserslistsOverlap(e,s){return s.some((s=>e.has(s)))}export{creator as default}; diff --git a/plugins/postcss-browser-comments/src/index.ts b/plugins/postcss-browser-comments/src/index.ts index c51d18864..786cf7fdc 100644 --- a/plugins/postcss-browser-comments/src/index.ts +++ b/plugins/postcss-browser-comments/src/index.ts @@ -91,7 +91,7 @@ function isBrowserCommentNode(node: Node): node is Comment { return node.next()?.type === 'rule'; } -const IS_BROWSER_COMMENT_NODE_REGEX = /^\*\n * /; +const IS_BROWSER_COMMENT_NODE_REGEX = /^\*\n +/; // returns whether a node is a browser reference comment function isBrowserReferenceCommentNode(node: Node): node is Comment { @@ -122,7 +122,7 @@ function getBrowserData(text: string): { browserslist: Array, isNumbered }; } -const BROWSER_DATA_MULTI_REGEX = /(\n \* \d+\. (?:[^\n]+|\n \* {4,})+)/g; +const BROWSER_DATA_MULTI_REGEX = /(\n \* \d+\. (?:[^\n]|\n \* {4,})+)/g; const BROWSER_DATA_NEWLINE_REGEX = /^\*\n \* ?|\n \*/g; const BROWSER_DATA_NUMBERED_NEWLINE_REGEX = /\n \* (?:( )\s*)?/g; @@ -148,7 +148,7 @@ function getBrowsersList(text: string): Array { } const GET_BROWSERSLIST_IN_SPLIT_REGEX = /\s+in\s+/; -const GET_BROWSERSLIST_AND_SPLIT_REGEX = /(?: and|, and|,)/; +const GET_BROWSERSLIST_AND_SPLIT_REGEX = / and|, and|,/; const GET_BROWSERSLIST_QUERY_REGEX = /^\s*(\w+)(?: ((?:(?:\d*\.)?\d+-)?(?:\d*\.)?\d+[+-]?))?.*$/; function browserslistsOverlap(clientBrowserList: Set, commentBrowsersList: Array): boolean { diff --git a/plugins/postcss-color-function/dist/index.cjs b/plugins/postcss-color-function/dist/index.cjs index 608715ec5..dc6acb952 100644 --- a/plugins/postcss-color-function/dist/index.cjs +++ b/plugins/postcss-color-function/dist/index.cjs @@ -1 +1 @@ -"use strict";var s=require("@csstools/postcss-progressive-custom-properties"),e=require("@csstools/css-tokenizer"),o=require("@csstools/css-color-parser"),r=require("@csstools/utilities"),t=require("@csstools/css-parser-algorithms");const a=/\b(?:color)\(/i,n=/^(?:color)$/i,basePlugin=s=>({postcssPlugin:"postcss-color-function",Declaration(i){const c=i.value;if(!a.test(c))return;if(r.hasFallback(i))return;if(r.hasSupportsAtRuleAncestor(i,a))return;const l=e.tokenize({css:c}),u=t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(l),(s=>{if(!t.isFunctionNode(s)||!n.test(s.getName()))return;const e=o.color(s);return e&&!(e.syntaxFlags.has(o.SyntaxFlag.Experimental)||e.syntaxFlags.has(o.SyntaxFlag.HasNoneKeywords)||e.syntaxFlags.has(o.SyntaxFlag.RelativeColorSyntax))?o.serializeRGB(e):void 0})),p=t.stringify(u);p!==c&&(i.cloneBefore({value:p}),s?.preserve||i.remove())}});basePlugin.postcss=!0;const postcssPlugin=e=>{const o=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},e);return o.enableProgressiveCustomProperties&&o.preserve?{postcssPlugin:"postcss-color-function",plugins:[s(),basePlugin(o)]}:basePlugin(o)};postcssPlugin.postcss=!0,module.exports=postcssPlugin; +"use strict";var s=require("@csstools/postcss-progressive-custom-properties"),e=require("@csstools/css-tokenizer"),o=require("@csstools/css-color-parser"),r=require("@csstools/utilities"),t=require("@csstools/css-parser-algorithms");const a=/\bcolor\(/i,n=/^color$/i,basePlugin=s=>({postcssPlugin:"postcss-color-function",Declaration(i){const c=i.value;if(!a.test(c))return;if(r.hasFallback(i))return;if(r.hasSupportsAtRuleAncestor(i,a))return;const l=e.tokenize({css:c}),u=t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(l),(s=>{if(!t.isFunctionNode(s)||!n.test(s.getName()))return;const e=o.color(s);return e&&!(e.syntaxFlags.has(o.SyntaxFlag.Experimental)||e.syntaxFlags.has(o.SyntaxFlag.HasNoneKeywords)||e.syntaxFlags.has(o.SyntaxFlag.RelativeColorSyntax))?o.serializeRGB(e):void 0})),p=t.stringify(u);p!==c&&(i.cloneBefore({value:p}),s?.preserve||i.remove())}});basePlugin.postcss=!0;const postcssPlugin=e=>{const o=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},e);return o.enableProgressiveCustomProperties&&o.preserve?{postcssPlugin:"postcss-color-function",plugins:[s(),basePlugin(o)]}:basePlugin(o)};postcssPlugin.postcss=!0,module.exports=postcssPlugin; diff --git a/plugins/postcss-color-function/dist/index.mjs b/plugins/postcss-color-function/dist/index.mjs index d1cf0967e..704bf2e14 100644 --- a/plugins/postcss-color-function/dist/index.mjs +++ b/plugins/postcss-color-function/dist/index.mjs @@ -1 +1 @@ -import s from"@csstools/postcss-progressive-custom-properties";import{tokenize as o}from"@csstools/css-tokenizer";import{color as r,SyntaxFlag as e,serializeRGB as t}from"@csstools/css-color-parser";import{hasFallback as c,hasSupportsAtRuleAncestor as i}from"@csstools/utilities";import{replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as l,isFunctionNode as a,stringify as p}from"@csstools/css-parser-algorithms";const u=/\b(?:color)\(/i,m=/^(?:color)$/i,basePlugin=s=>({postcssPlugin:"postcss-color-function",Declaration(f){const g=f.value;if(!u.test(g))return;if(c(f))return;if(i(f,u))return;const v=o({css:g}),x=n(l(v),(s=>{if(!a(s)||!m.test(s.getName()))return;const o=r(s);return o&&!(o.syntaxFlags.has(e.Experimental)||o.syntaxFlags.has(e.HasNoneKeywords)||o.syntaxFlags.has(e.RelativeColorSyntax))?t(o):void 0})),P=p(x);P!==g&&(f.cloneBefore({value:P}),s?.preserve||f.remove())}});basePlugin.postcss=!0;const postcssPlugin=o=>{const r=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},o);return r.enableProgressiveCustomProperties&&r.preserve?{postcssPlugin:"postcss-color-function",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0;export{postcssPlugin as default}; +import s from"@csstools/postcss-progressive-custom-properties";import{tokenize as o}from"@csstools/css-tokenizer";import{color as r,SyntaxFlag as e,serializeRGB as t}from"@csstools/css-color-parser";import{hasFallback as c,hasSupportsAtRuleAncestor as i}from"@csstools/utilities";import{replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as l,isFunctionNode as a,stringify as p}from"@csstools/css-parser-algorithms";const u=/\bcolor\(/i,m=/^color$/i,basePlugin=s=>({postcssPlugin:"postcss-color-function",Declaration(f){const g=f.value;if(!u.test(g))return;if(c(f))return;if(i(f,u))return;const v=o({css:g}),x=n(l(v),(s=>{if(!a(s)||!m.test(s.getName()))return;const o=r(s);return o&&!(o.syntaxFlags.has(e.Experimental)||o.syntaxFlags.has(e.HasNoneKeywords)||o.syntaxFlags.has(e.RelativeColorSyntax))?t(o):void 0})),P=p(x);P!==g&&(f.cloneBefore({value:P}),s?.preserve||f.remove())}});basePlugin.postcss=!0;const postcssPlugin=o=>{const r=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},o);return r.enableProgressiveCustomProperties&&r.preserve?{postcssPlugin:"postcss-color-function",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0;export{postcssPlugin as default}; diff --git a/plugins/postcss-color-function/src/index.ts b/plugins/postcss-color-function/src/index.ts index be6e91d08..2d075a73d 100644 --- a/plugins/postcss-color-function/src/index.ts +++ b/plugins/postcss-color-function/src/index.ts @@ -9,8 +9,8 @@ type basePluginOptions = { preserve: boolean, } -const COLOR_FUNCTION_REGEX = /\b(?:color)\(/i; -const COLOR_NAME_REGEX = /^(?:color)$/i; +const COLOR_FUNCTION_REGEX = /\bcolor\(/i; +const COLOR_NAME_REGEX = /^color$/i; /* Transform the color() function in CSS. */ const basePlugin: PluginCreator = (opts?: basePluginOptions) => { diff --git a/plugins/postcss-color-hex-alpha/dist/index.cjs b/plugins/postcss-color-hex-alpha/dist/index.cjs index 5deda5879..4bae5967f 100644 --- a/plugins/postcss-color-hex-alpha/dist/index.cjs +++ b/plugins/postcss-color-hex-alpha/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("postcss-value-parser"),s=require("@csstools/utilities");const creator=a=>{const l=Object.assign({preserve:!1},a);return{postcssPlugin:"postcss-color-hex-alpha",Declaration(a){if(!t.test(a.value))return;if(s.hasFallback(a))return;const{value:c}=a,n=e(c);n.walk((e=>{if("function"===e.type&&"url"===e.value)return!1;"word"===e.type&&r.test(e.value)&&hexa2rgba(e)}));const o=n.toString();o!==c&&(a.cloneBefore({value:o}),l.preserve||a.remove())}}};creator.postcss=!0;const t=/#([0-9a-f]{4}(?:[0-9a-f]{4})?)\b/i,r=/^#([0-9a-f]{4}(?:[0-9a-f]{4})?)$/i,a=1e5,l=/[0-9a-f]/gi;function hexa2rgba(e){const s=e.value,t=`0x${5===s.length?s.slice(1).replace(l,"$&$&"):s.slice(1)}`,[r,c,n,o]=[parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),parseInt(t.slice(6,8),16),Math.round(parseInt(t.slice(8,10),16)/255*a)/a];e.value=`rgba(${r},${c},${n},${o})`}module.exports=creator; +"use strict";var e=require("postcss-value-parser"),s=require("@csstools/utilities");const creator=a=>{const l=Object.assign({preserve:!1},a);return{postcssPlugin:"postcss-color-hex-alpha",Declaration(a){if(!t.test(a.value))return;if(s.hasFallback(a))return;const{value:c}=a,n=e(c);n.walk((e=>{if("function"===e.type&&"url"===e.value)return!1;"word"===e.type&&r.test(e.value)&&hexa2rgba(e)}));const o=n.toString();o!==c&&(a.cloneBefore({value:o}),l.preserve||a.remove())}}};creator.postcss=!0;const t=/#[0-9a-f]{4}(?:[0-9a-f]{4})?\b/i,r=/^#[0-9a-f]{4}(?:[0-9a-f]{4})?$/i,a=1e5,l=/[0-9a-f]/gi;function hexa2rgba(e){const s=e.value,t=`0x${5===s.length?s.slice(1).replace(l,"$&$&"):s.slice(1)}`,[r,c,n,o]=[parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),parseInt(t.slice(6,8),16),Math.round(parseInt(t.slice(8,10),16)/255*a)/a];e.value=`rgba(${r},${c},${n},${o})`}module.exports=creator; diff --git a/plugins/postcss-color-hex-alpha/dist/index.mjs b/plugins/postcss-color-hex-alpha/dist/index.mjs index 27b52f0b2..4698fa88c 100644 --- a/plugins/postcss-color-hex-alpha/dist/index.mjs +++ b/plugins/postcss-color-hex-alpha/dist/index.mjs @@ -1 +1 @@ -import e from"postcss-value-parser";import{hasFallback as s}from"@csstools/utilities";const creator=a=>{const o=Object.assign({preserve:!1},a);return{postcssPlugin:"postcss-color-hex-alpha",Declaration(a){if(!t.test(a.value))return;if(s(a))return;const{value:l}=a,n=e(l);n.walk((e=>{if("function"===e.type&&"url"===e.value)return!1;"word"===e.type&&r.test(e.value)&&hexa2rgba(e)}));const c=n.toString();c!==l&&(a.cloneBefore({value:c}),o.preserve||a.remove())}}};creator.postcss=!0;const t=/#([0-9a-f]{4}(?:[0-9a-f]{4})?)\b/i,r=/^#([0-9a-f]{4}(?:[0-9a-f]{4})?)$/i,a=1e5,o=/[0-9a-f]/gi;function hexa2rgba(e){const s=e.value,t=`0x${5===s.length?s.slice(1).replace(o,"$&$&"):s.slice(1)}`,[r,l,n,c]=[parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),parseInt(t.slice(6,8),16),Math.round(parseInt(t.slice(8,10),16)/255*a)/a];e.value=`rgba(${r},${l},${n},${c})`}export{creator as default}; +import e from"postcss-value-parser";import{hasFallback as s}from"@csstools/utilities";const creator=a=>{const o=Object.assign({preserve:!1},a);return{postcssPlugin:"postcss-color-hex-alpha",Declaration(a){if(!t.test(a.value))return;if(s(a))return;const{value:l}=a,n=e(l);n.walk((e=>{if("function"===e.type&&"url"===e.value)return!1;"word"===e.type&&r.test(e.value)&&hexa2rgba(e)}));const c=n.toString();c!==l&&(a.cloneBefore({value:c}),o.preserve||a.remove())}}};creator.postcss=!0;const t=/#[0-9a-f]{4}(?:[0-9a-f]{4})?\b/i,r=/^#[0-9a-f]{4}(?:[0-9a-f]{4})?$/i,a=1e5,o=/[0-9a-f]/gi;function hexa2rgba(e){const s=e.value,t=`0x${5===s.length?s.slice(1).replace(o,"$&$&"):s.slice(1)}`,[r,l,n,c]=[parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),parseInt(t.slice(6,8),16),Math.round(parseInt(t.slice(8,10),16)/255*a)/a];e.value=`rgba(${r},${l},${n},${c})`}export{creator as default}; diff --git a/plugins/postcss-color-hex-alpha/src/index.ts b/plugins/postcss-color-hex-alpha/src/index.ts index 86d3e2e0d..1c11ed383 100644 --- a/plugins/postcss-color-hex-alpha/src/index.ts +++ b/plugins/postcss-color-hex-alpha/src/index.ts @@ -64,9 +64,9 @@ creator.postcss = true; export default creator; -const HAS_HEX_ALPHA_REGEX = /#([0-9a-f]{4}(?:[0-9a-f]{4})?)\b/i; +const HAS_HEX_ALPHA_REGEX = /#[0-9a-f]{4}(?:[0-9a-f]{4})?\b/i; -const IS_HEX_ALPHA_REGEX = /^#([0-9a-f]{4}(?:[0-9a-f]{4})?)$/i; +const IS_HEX_ALPHA_REGEX = /^#[0-9a-f]{4}(?:[0-9a-f]{4})?$/i; /** Decimal precision. */ const alphaDecimalPrecision = 100000; diff --git a/plugins/postcss-color-mix-function/dist/index.cjs b/plugins/postcss-color-mix-function/dist/index.cjs index f539e7613..5bf9fd70e 100644 --- a/plugins/postcss-color-mix-function/dist/index.cjs +++ b/plugins/postcss-color-mix-function/dist/index.cjs @@ -1 +1 @@ -"use strict";var s=require("@csstools/postcss-progressive-custom-properties"),e=require("@csstools/css-color-parser"),r=require("@csstools/utilities"),t=require("@csstools/css-parser-algorithms"),o=require("@csstools/css-tokenizer");const i=/\b(?:color-mix)\(/i,a=/^(?:color-mix)$/i,basePlugin=s=>({postcssPlugin:"postcss-color-mix-function",Declaration(n){const l=n.value;if(!i.test(l))return;if(r.hasFallback(n))return;if(r.hasSupportsAtRuleAncestor(n,i))return;const u=o.tokenize({css:l}),c=t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(u),(s=>{if(!t.isFunctionNode(s)||!a.test(s.getName()))return;const r=e.color(s);return r&&!r.syntaxFlags.has(e.SyntaxFlag.Experimental)?e.serializeRGB(r):void 0})),p=t.stringify(c);if(p===l)return;let m=p;s?.subFeatures.displayP3&&(m=t.stringify(t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(u),(s=>{if(!t.isFunctionNode(s)||!a.test(s.getName()))return;const r=e.color(s);return r&&!r.syntaxFlags.has(e.SyntaxFlag.Experimental)?e.colorDataFitsRGB_Gamut(r)?e.serializeRGB(r):e.serializeP3(r):void 0})))),n.cloneBefore({value:p}),s?.subFeatures.displayP3&&m!==p&&n.cloneBefore({value:m}),s?.preserve||n.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return r.subFeatures=Object.assign({displayP3:!0},r.subFeatures),r.enableProgressiveCustomProperties&&(r.preserve||r.subFeatures.displayP3)?{postcssPlugin:"postcss-color-mix-function",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0,module.exports=postcssPlugin; +"use strict";var s=require("@csstools/postcss-progressive-custom-properties"),e=require("@csstools/css-color-parser"),r=require("@csstools/utilities"),t=require("@csstools/css-parser-algorithms"),o=require("@csstools/css-tokenizer");const i=/\bcolor-mix\(/i,a=/^color-mix$/i,basePlugin=s=>({postcssPlugin:"postcss-color-mix-function",Declaration(n){const l=n.value;if(!i.test(l))return;if(r.hasFallback(n))return;if(r.hasSupportsAtRuleAncestor(n,i))return;const u=o.tokenize({css:l}),c=t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(u),(s=>{if(!t.isFunctionNode(s)||!a.test(s.getName()))return;const r=e.color(s);return r&&!r.syntaxFlags.has(e.SyntaxFlag.Experimental)?e.serializeRGB(r):void 0})),p=t.stringify(c);if(p===l)return;let m=p;s?.subFeatures.displayP3&&(m=t.stringify(t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(u),(s=>{if(!t.isFunctionNode(s)||!a.test(s.getName()))return;const r=e.color(s);return r&&!r.syntaxFlags.has(e.SyntaxFlag.Experimental)?e.colorDataFitsRGB_Gamut(r)?e.serializeRGB(r):e.serializeP3(r):void 0})))),n.cloneBefore({value:p}),s?.subFeatures.displayP3&&m!==p&&n.cloneBefore({value:m}),s?.preserve||n.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return r.subFeatures=Object.assign({displayP3:!0},r.subFeatures),r.enableProgressiveCustomProperties&&(r.preserve||r.subFeatures.displayP3)?{postcssPlugin:"postcss-color-mix-function",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0,module.exports=postcssPlugin; diff --git a/plugins/postcss-color-mix-function/dist/index.mjs b/plugins/postcss-color-mix-function/dist/index.mjs index 1996ee7ff..785d57332 100644 --- a/plugins/postcss-color-mix-function/dist/index.mjs +++ b/plugins/postcss-color-mix-function/dist/index.mjs @@ -1 +1 @@ -import s from"@csstools/postcss-progressive-custom-properties";import{color as e,SyntaxFlag as r,serializeRGB as t,colorDataFitsRGB_Gamut as o,serializeP3 as i}from"@csstools/css-color-parser";import{hasFallback as c,hasSupportsAtRuleAncestor as a}from"@csstools/utilities";import{replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as l,isFunctionNode as u,stringify as p}from"@csstools/css-parser-algorithms";import{tokenize as m}from"@csstools/css-tokenizer";const f=/\b(?:color-mix)\(/i,g=/^(?:color-mix)$/i,basePlugin=s=>({postcssPlugin:"postcss-color-mix-function",Declaration(v){const b=v.value;if(!f.test(b))return;if(c(v))return;if(a(v,f))return;const P=m({css:b}),x=n(l(P),(s=>{if(!u(s)||!g.test(s.getName()))return;const o=e(s);return o&&!o.syntaxFlags.has(r.Experimental)?t(o):void 0})),d=p(x);if(d===b)return;let F=d;s?.subFeatures.displayP3&&(F=p(n(l(P),(s=>{if(!u(s)||!g.test(s.getName()))return;const c=e(s);return c&&!c.syntaxFlags.has(r.Experimental)?o(c)?t(c):i(c):void 0})))),v.cloneBefore({value:d}),s?.subFeatures.displayP3&&F!==d&&v.cloneBefore({value:F}),s?.preserve||v.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return r.subFeatures=Object.assign({displayP3:!0},r.subFeatures),r.enableProgressiveCustomProperties&&(r.preserve||r.subFeatures.displayP3)?{postcssPlugin:"postcss-color-mix-function",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0;export{postcssPlugin as default}; +import s from"@csstools/postcss-progressive-custom-properties";import{color as e,SyntaxFlag as r,serializeRGB as t,colorDataFitsRGB_Gamut as o,serializeP3 as i}from"@csstools/css-color-parser";import{hasFallback as c,hasSupportsAtRuleAncestor as a}from"@csstools/utilities";import{replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as l,isFunctionNode as u,stringify as p}from"@csstools/css-parser-algorithms";import{tokenize as m}from"@csstools/css-tokenizer";const f=/\bcolor-mix\(/i,g=/^color-mix$/i,basePlugin=s=>({postcssPlugin:"postcss-color-mix-function",Declaration(v){const b=v.value;if(!f.test(b))return;if(c(v))return;if(a(v,f))return;const P=m({css:b}),x=n(l(P),(s=>{if(!u(s)||!g.test(s.getName()))return;const o=e(s);return o&&!o.syntaxFlags.has(r.Experimental)?t(o):void 0})),d=p(x);if(d===b)return;let F=d;s?.subFeatures.displayP3&&(F=p(n(l(P),(s=>{if(!u(s)||!g.test(s.getName()))return;const c=e(s);return c&&!c.syntaxFlags.has(r.Experimental)?o(c)?t(c):i(c):void 0})))),v.cloneBefore({value:d}),s?.subFeatures.displayP3&&F!==d&&v.cloneBefore({value:F}),s?.preserve||v.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return r.subFeatures=Object.assign({displayP3:!0},r.subFeatures),r.enableProgressiveCustomProperties&&(r.preserve||r.subFeatures.displayP3)?{postcssPlugin:"postcss-color-mix-function",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0;export{postcssPlugin as default}; diff --git a/plugins/postcss-color-mix-function/src/index.ts b/plugins/postcss-color-mix-function/src/index.ts index 134e9a95e..cf7b417d0 100644 --- a/plugins/postcss-color-mix-function/src/index.ts +++ b/plugins/postcss-color-mix-function/src/index.ts @@ -12,8 +12,8 @@ type basePluginOptions = { } }; -const COLOR_MIX_FUNCTION_REGEX = /\b(?:color-mix)\(/i; -const COLOR_MIX_NAME_REGEX = /^(?:color-mix)$/i; +const COLOR_MIX_FUNCTION_REGEX = /\bcolor-mix\(/i; +const COLOR_MIX_NAME_REGEX = /^color-mix$/i; /* Transform color-mix() functions in CSS. */ const basePlugin: PluginCreator = (opts?: basePluginOptions) => { diff --git a/plugins/postcss-custom-properties/dist/index.cjs b/plugins/postcss-custom-properties/dist/index.cjs index e1bb45652..325ad83df 100644 --- a/plugins/postcss-custom-properties/dist/index.cjs +++ b/plugins/postcss-custom-properties/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("@csstools/cascade-layer-name-parser"),t=require("postcss-value-parser"),r=require("@csstools/utilities");const n=e.parse("csstools-implicit-layer")[0];function collectCascadeLayerOrder(t){const r=new Map,o=new Map,s=[];t.walkAtRules((t=>{if("layer"!==t.name.toLowerCase())return;{let e=t.parent;for(;e;){if("atrule"!==e.type||"layer"!==e.name.toLowerCase()){if(e===t.root())break;return}e=e.parent}}let a;if(t.nodes)a=normalizeLayerName(t.params,1);else{if(!t.params.trim())return;a=t.params}let i=e.parse(a);if(i?.length){{let e=t.parent;for(;e&&"atrule"===e.type&&"layer"===e.name.toLowerCase();){const t=o.get(e);t?(i=i.map((e=>t.concat(e))),e=e.parent):e=e.parent}}if(e.addLayerToModel(s,i),t.nodes){const e=i[0].concat(n);r.set(t,e),o.set(t,i[0])}}}));for(const t of r.values())e.addLayerToModel(s,[t]);const a=new WeakMap;for(const[e,t]of r)a.set(e,s.findIndex((e=>t.equal(e))));return a}function normalizeLayerName(e,t){return e.trim()?e:"csstools-anon-layer--"+t++}const o=/(!\s*)?postcss-custom-properties:\s*off\b/i,s=new WeakMap;function isBlockIgnored(e){if(!e||!e.nodes)return!1;if(s.has(e))return s.get(e);const t=e.some((e=>isIgnoreComment(e,o)));return s.set(e,t),t}const a=/(!\s*)?postcss-custom-properties:\s*ignore\s+next\b/i;function isDeclarationIgnored(e){return!!e&&(!!isBlockIgnored(e.parent)||isIgnoreComment(e.prev(),a))}function isIgnoreComment(e,t){return!!e&&"comment"===e.type&&t.test(e.text)}const i=new Set(["layer"]);function isProcessableRule(e){let t=e.parent;for(;t;){if("atrule"===t.type&&!i.has(t.name.toLowerCase()))return!1;t=t.parent}return!0}const l=/^html$/i,c=/^:where\(html\)$/i,u=/^:root$/i,p=/^:where\(:root\)$/i,f=/(html|:root)/i,d=/^var$/i;function isVarFunction(e){return"function"===e.type&&d.test(e.value)&&Object(e.nodes).length>0}const m=/\bvar\(/i;function parseOrCached(e,r){let n=r.get(e);return n||(n=t(e),r.set(e,n),n)}function toposort(e,t){let r=e.length;const n=new Array(r),o={};let s=r;const a=makeOutgoingEdges(t),i=makeNodesHash(e);for(;s--;)o[s]||visit(e[s],s,new Set);return n;function visit(e,t,s){if(s.has(e)){let t;try{t=", node was:"+JSON.stringify(e)}catch(e){t=""}throw new Error("Cyclic dependency"+t)}if(!i.has(e))throw new Error("Found unknown node. Make sure to provided all involved nodes. Unknown node: "+JSON.stringify(e));if(o[t])return;o[t]=!0;const l=Array.from(a.get(e)||new Set);if(t=l.length){s.add(e);do{const e=l[--t];visit(e,i.get(e),s)}while(t);s.delete(e)}n[--r]=e}}function removeCyclicReferences(e,t){const r=new Set;for(;e.size>0;){const n=findCyclicNode(Array.from(e.keys()),t);if(!n)return r;e.delete(n),r.add(n),t=t.filter((e=>-1===e.indexOf(n)))}return r}function findCyclicNode(e,t){let r=e.length;const n=new Array(r),o={};let s=r;const a=makeOutgoingEdges(t),i=makeNodesHash(e);for(;s--;)if(!o[s]){const t=visit(e[s],s,new Set);if(!t)continue;return t}function visit(e,t,s){if(s.has(e))return e;if(!i.has(e))return;if(o[t])return;o[t]=!0;const l=Array.from(a.get(e)||new Set);if(t=l.length){s.add(e);do{const e=l[--t],r=visit(e,i.get(e),s);if(r)return r}while(t);s.delete(e)}n[--r]=e}}function makeOutgoingEdges(e){const t=new Map;for(let r=0,n=e.length;r{if(!isVarFunction(e))return;const s=parseVarFunction(e);if(!s)return;let a=!1;s.fallback&&t.walk(s.fallback,(e=>{if(!isVarFunction(e))return;const t=parseVarFunction(e);return t?t.fallback||r.has(t.name.value)?void 0:(a=!0,!1):void 0}));let i=r.get(s.name.value)?.nodes;i||!s.fallback||a||(i=s.fallback),void 0!==i&&(i.length?o.splice(n,1,...i):o.splice(n,1,{type:"div",value:" ",before:"",after:"",sourceIndex:e.sourceIndex,sourceEndIndex:e.sourceEndIndex}))})),t.stringify(e.nodes)):""}function walk(e,t){let r,n,o;for(r=0,n=e.length;r"comment"!==e.type&&"space"!==e.type));return 1===t.length&&("word"===t[0].type&&v.test(t[0].value))}function buildCustomPropertiesMap(e,r,n){if(!e.size)return r;const o=new Map(r);{const s=[];for(const[a,i]of e.entries()){const l=parseOrCached(i,n);let c=!1;t.walk(l.nodes,(t=>{if(!isVarFunction(t))return;const n=parseVarFunction(t);n&&(n.fallback||e.has(n.name.value)||r.has(n.name.value)?s.push([n.name.value,a]):c=!0)})),c||o.set(a,l)}removeCyclicReferences(o,s)}{const e=[];for(const[r,n]of o.entries())t.walk(n.nodes,(t=>{if(!isVarFunction(t))return;const n=parseVarFunction(t);n&&(n.fallback||o.has(n.name.value)?e.push([n.name.value,r]):o.delete(r))}));for(let t=0;t{f.test(e.selector)&&e.nodes?.length&&isProcessableRule(e)&&(isBlockIgnored(e)||e.selectors.forEach((t=>{let s=-1;if(c.test(t)||p.test(t))s=0;else if(l.test(t))s=1;else{if(!u.test(t))return;s=2}const a=(f=o,((i=e).parent&&"atrule"===i.parent.type&&"layer"===i.parent.name.toLowerCase()?f.has(i.parent)?f.get(i.parent)+1:0:1e7)+10+s);var i,f;e.each((e=>{if("decl"!==e.type)return;if(!e.variable||isDeclarationIgnored(e))return;if("initial"===e.value.toLowerCase().trim())return;const t=n.get(e.prop)??-1;a>=t&&(n.set(e.prop,a),r.set(e.prop,e.value))}))})))})),buildCustomPropertiesMap(r,new Map,t)}function getCustomPropertiesFromSiblings(e,t,r){if(!e.parent)return t;const n=new Map;return e.parent.each((t=>{"decl"===t.type&&t.variable&&e!==t&&(isDeclarationIgnored(t)||n.set(t.prop,t.value))})),n.size?buildCustomPropertiesMap(n,t,r):t}function transformProperties(e,r,n){if(isTransformableDecl(e)&&!isDeclarationIgnored(e)){const o=e.value,s=transformValueAST(t(o),r);if(s===o)return;if(parentHasExactFallback(e,s))return void(n.preserve||e.remove());if(n.preserve){const t=e.cloneBefore({value:s});hasTrailingComment(t)&&t.raws?.value&&(t.raws.value.value=t.value.replace(w,"$1"),t.raws.value.raw=t.raws.value.value+t.raws.value.raw.replace(w,"$2"))}else e.value=s,hasTrailingComment(e)&&e.raws?.value&&(e.raws.value.value=e.value.replace(w,"$1"),e.raws.value.raw=e.raws.value.value+e.raws.value.raw.replace(w,"$2"))}}const isTransformableDecl=e=>!e.variable&&e.value.includes("--")&&e.value.toLowerCase().includes("var("),hasTrailingComment=e=>"value"in Object(Object(e.raws).value)&&"raw"in(e.raws?.value??{})&&w.test(e.raws.value?.raw??""),w=/^([\W\w]+)(\s*\/\*[\W\w]+?\*\/)$/;function parentHasExactFallback(e,t){if(!e||!e.parent)return!1;let r=!1;const n=e.parent.index(e);return e.parent.each(((o,s)=>o!==e&&(!(s>=n)&&void("decl"===o.type&&o.prop.toLowerCase()===e.prop.toLowerCase()&&o.value===t&&(r=!0))))),r}const g=/(?:\bvar\()|(?:\(top: var\(--f\))/i,creator=e=>{const t=!("preserve"in Object(e))||Boolean(e?.preserve);if("importFrom"in Object(e))throw new Error('[postcss-custom-properties] "importFrom" is no longer supported');if("exportTo"in Object(e))throw new Error('[postcss-custom-properties] "exportTo" is no longer supported');return{postcssPlugin:"postcss-custom-properties",prepare(){let e=new Map;const n=new WeakMap,o=new Map;return{postcssPlugin:"postcss-custom-properties",Once(t){e=getCustomPropertiesFromRoot(t,o)},Declaration(s){if(!m.test(s.value))return;if(r.hasSupportsAtRuleAncestor(s,g))return;let a=e;t&&s.parent&&(a=n.get(s.parent)??getCustomPropertiesFromSiblings(s,e,o),n.set(s.parent,a)),transformProperties(s,a,{preserve:t})}}}}};creator.postcss=!0,module.exports=creator; +"use strict";var e=require("@csstools/cascade-layer-name-parser"),t=require("postcss-value-parser"),r=require("@csstools/utilities");const n=e.parse("csstools-implicit-layer")[0];function collectCascadeLayerOrder(t){const r=new Map,o=new Map,s=[];t.walkAtRules((t=>{if("layer"!==t.name.toLowerCase())return;{let e=t.parent;for(;e;){if("atrule"!==e.type||"layer"!==e.name.toLowerCase()){if(e===t.root())break;return}e=e.parent}}let a;if(t.nodes)a=normalizeLayerName(t.params,1);else{if(!t.params.trim())return;a=t.params}let i=e.parse(a);if(i?.length){{let e=t.parent;for(;e&&"atrule"===e.type&&"layer"===e.name.toLowerCase();){const t=o.get(e);t?(i=i.map((e=>t.concat(e))),e=e.parent):e=e.parent}}if(e.addLayerToModel(s,i),t.nodes){const e=i[0].concat(n);r.set(t,e),o.set(t,i[0])}}}));for(const t of r.values())e.addLayerToModel(s,[t]);const a=new WeakMap;for(const[e,t]of r)a.set(e,s.findIndex((e=>t.equal(e))));return a}function normalizeLayerName(e,t){return e.trim()?e:"csstools-anon-layer--"+t++}const o=/(?:!\s*)?postcss-custom-properties:\s*off\b/i,s=new WeakMap;function isBlockIgnored(e){if(!e||!e.nodes)return!1;if(s.has(e))return s.get(e);const t=e.some((e=>isIgnoreComment(e,o)));return s.set(e,t),t}const a=/(?:!\s*)?postcss-custom-properties:\s*ignore\s+next\b/i;function isDeclarationIgnored(e){return!!e&&(!!isBlockIgnored(e.parent)||isIgnoreComment(e.prev(),a))}function isIgnoreComment(e,t){return!!e&&"comment"===e.type&&t.test(e.text)}const i=new Set(["layer"]);function isProcessableRule(e){let t=e.parent;for(;t;){if("atrule"===t.type&&!i.has(t.name.toLowerCase()))return!1;t=t.parent}return!0}const l=/^html$/i,c=/^:where\(html\)$/i,u=/^:root$/i,p=/^:where\(:root\)$/i,f=/(html|:root)/i,d=/^var$/i;function isVarFunction(e){return"function"===e.type&&d.test(e.value)&&Object(e.nodes).length>0}const m=/\bvar\(/i;function parseOrCached(e,r){let n=r.get(e);return n||(n=t(e),r.set(e,n),n)}function toposort(e,t){let r=e.length;const n=new Array(r),o={};let s=r;const a=makeOutgoingEdges(t),i=makeNodesHash(e);for(;s--;)o[s]||visit(e[s],s,new Set);return n;function visit(e,t,s){if(s.has(e)){let t;try{t=", node was:"+JSON.stringify(e)}catch(e){t=""}throw new Error("Cyclic dependency"+t)}if(!i.has(e))throw new Error("Found unknown node. Make sure to provided all involved nodes. Unknown node: "+JSON.stringify(e));if(o[t])return;o[t]=!0;const l=Array.from(a.get(e)||new Set);if(t=l.length){s.add(e);do{const e=l[--t];visit(e,i.get(e),s)}while(t);s.delete(e)}n[--r]=e}}function removeCyclicReferences(e,t){const r=new Set;for(;e.size>0;){const n=findCyclicNode(Array.from(e.keys()),t);if(!n)return r;e.delete(n),r.add(n),t=t.filter((e=>-1===e.indexOf(n)))}return r}function findCyclicNode(e,t){let r=e.length;const n=new Array(r),o={};let s=r;const a=makeOutgoingEdges(t),i=makeNodesHash(e);for(;s--;)if(!o[s]){const t=visit(e[s],s,new Set);if(!t)continue;return t}function visit(e,t,s){if(s.has(e))return e;if(!i.has(e))return;if(o[t])return;o[t]=!0;const l=Array.from(a.get(e)||new Set);if(t=l.length){s.add(e);do{const e=l[--t],r=visit(e,i.get(e),s);if(r)return r}while(t);s.delete(e)}n[--r]=e}}function makeOutgoingEdges(e){const t=new Map;for(let r=0,n=e.length;r{if(!isVarFunction(e))return;const s=parseVarFunction(e);if(!s)return;let a=!1;s.fallback&&t.walk(s.fallback,(e=>{if(!isVarFunction(e))return;const t=parseVarFunction(e);return t?t.fallback||r.has(t.name.value)?void 0:(a=!0,!1):void 0}));let i=r.get(s.name.value)?.nodes;i||!s.fallback||a||(i=s.fallback),void 0!==i&&(i.length?o.splice(n,1,...i):o.splice(n,1,{type:"div",value:" ",before:"",after:"",sourceIndex:e.sourceIndex,sourceEndIndex:e.sourceEndIndex}))})),t.stringify(e.nodes)):""}function walk(e,t){let r,n,o;for(r=0,n=e.length;r"comment"!==e.type&&"space"!==e.type));return 1===t.length&&("word"===t[0].type&&v.test(t[0].value))}function buildCustomPropertiesMap(e,r,n){if(!e.size)return r;const o=new Map(r);{const s=[];for(const[a,i]of e.entries()){const l=parseOrCached(i,n);let c=!1;t.walk(l.nodes,(t=>{if(!isVarFunction(t))return;const n=parseVarFunction(t);n&&(n.fallback||e.has(n.name.value)||r.has(n.name.value)?s.push([n.name.value,a]):c=!0)})),c||o.set(a,l)}removeCyclicReferences(o,s)}{const e=[];for(const[r,n]of o.entries())t.walk(n.nodes,(t=>{if(!isVarFunction(t))return;const n=parseVarFunction(t);n&&(n.fallback||o.has(n.name.value)?e.push([n.name.value,r]):o.delete(r))}));for(let t=0;t{f.test(e.selector)&&e.nodes?.length&&isProcessableRule(e)&&(isBlockIgnored(e)||e.selectors.forEach((t=>{let s=-1;if(c.test(t)||p.test(t))s=0;else if(l.test(t))s=1;else{if(!u.test(t))return;s=2}const a=(f=o,((i=e).parent&&"atrule"===i.parent.type&&"layer"===i.parent.name.toLowerCase()?f.has(i.parent)?f.get(i.parent)+1:0:1e7)+10+s);var i,f;e.each((e=>{if("decl"!==e.type)return;if(!e.variable||isDeclarationIgnored(e))return;if("initial"===e.value.toLowerCase().trim())return;const t=n.get(e.prop)??-1;a>=t&&(n.set(e.prop,a),r.set(e.prop,e.value))}))})))})),buildCustomPropertiesMap(r,new Map,t)}function getCustomPropertiesFromSiblings(e,t,r){if(!e.parent)return t;const n=new Map;return e.parent.each((t=>{"decl"===t.type&&t.variable&&e!==t&&(isDeclarationIgnored(t)||n.set(t.prop,t.value))})),n.size?buildCustomPropertiesMap(n,t,r):t}function transformProperties(e,r,n){if(isTransformableDecl(e)&&!isDeclarationIgnored(e)){const o=e.value,s=transformValueAST(t(o),r);if(s===o)return;if(parentHasExactFallback(e,s))return void(n.preserve||e.remove());if(n.preserve){const t=e.cloneBefore({value:s});hasTrailingComment(t)&&t.raws?.value&&(t.raws.value.value=t.value.replace(w,"$1"),t.raws.value.raw=t.raws.value.value+t.raws.value.raw.replace(w,"$2"))}else e.value=s,hasTrailingComment(e)&&e.raws?.value&&(e.raws.value.value=e.value.replace(w,"$1"),e.raws.value.raw=e.raws.value.value+e.raws.value.raw.replace(w,"$2"))}}const isTransformableDecl=e=>!e.variable&&e.value.includes("--")&&e.value.toLowerCase().includes("var("),hasTrailingComment=e=>"value"in Object(Object(e.raws).value)&&"raw"in(e.raws?.value??{})&&w.test(e.raws.value?.raw??""),w=/^([\W\w]+)(\s*\/\*[\W\w]+?\*\/)$/;function parentHasExactFallback(e,t){if(!e||!e.parent)return!1;let r=!1;const n=e.parent.index(e);return e.parent.each(((o,s)=>o!==e&&(!(s>=n)&&void("decl"===o.type&&o.prop.toLowerCase()===e.prop.toLowerCase()&&o.value===t&&(r=!0))))),r}const g=/\bvar\(|\(top: var\(--f\)/i,creator=e=>{const t=!("preserve"in Object(e))||Boolean(e?.preserve);if("importFrom"in Object(e))throw new Error('[postcss-custom-properties] "importFrom" is no longer supported');if("exportTo"in Object(e))throw new Error('[postcss-custom-properties] "exportTo" is no longer supported');return{postcssPlugin:"postcss-custom-properties",prepare(){let e=new Map;const n=new WeakMap,o=new Map;return{postcssPlugin:"postcss-custom-properties",Once(t){e=getCustomPropertiesFromRoot(t,o)},Declaration(s){if(!m.test(s.value))return;if(r.hasSupportsAtRuleAncestor(s,g))return;let a=e;t&&s.parent&&(a=n.get(s.parent)??getCustomPropertiesFromSiblings(s,e,o),n.set(s.parent,a)),transformProperties(s,a,{preserve:t})}}}}};creator.postcss=!0,module.exports=creator; diff --git a/plugins/postcss-custom-properties/dist/index.mjs b/plugins/postcss-custom-properties/dist/index.mjs index 97cc1987b..1ccb53dfe 100644 --- a/plugins/postcss-custom-properties/dist/index.mjs +++ b/plugins/postcss-custom-properties/dist/index.mjs @@ -1 +1 @@ -import{parse as e,addLayerToModel as t}from"@csstools/cascade-layer-name-parser";import r from"postcss-value-parser";import{hasSupportsAtRuleAncestor as n}from"@csstools/utilities";const o=e("csstools-implicit-layer")[0];function collectCascadeLayerOrder(r){const n=new Map,s=new Map,a=[];r.walkAtRules((r=>{if("layer"!==r.name.toLowerCase())return;{let e=r.parent;for(;e;){if("atrule"!==e.type||"layer"!==e.name.toLowerCase()){if(e===r.root())break;return}e=e.parent}}let i;if(r.nodes)i=normalizeLayerName(r.params,1);else{if(!r.params.trim())return;i=r.params}let l=e(i);if(l?.length){{let e=r.parent;for(;e&&"atrule"===e.type&&"layer"===e.name.toLowerCase();){const t=s.get(e);t?(l=l.map((e=>t.concat(e))),e=e.parent):e=e.parent}}if(t(a,l),r.nodes){const e=l[0].concat(o);n.set(r,e),s.set(r,l[0])}}}));for(const e of n.values())t(a,[e]);const i=new WeakMap;for(const[e,t]of n)i.set(e,a.findIndex((e=>t.equal(e))));return i}function normalizeLayerName(e,t){return e.trim()?e:"csstools-anon-layer--"+t++}const s=/(!\s*)?postcss-custom-properties:\s*off\b/i,a=new WeakMap;function isBlockIgnored(e){if(!e||!e.nodes)return!1;if(a.has(e))return a.get(e);const t=e.some((e=>isIgnoreComment(e,s)));return a.set(e,t),t}const i=/(!\s*)?postcss-custom-properties:\s*ignore\s+next\b/i;function isDeclarationIgnored(e){return!!e&&(!!isBlockIgnored(e.parent)||isIgnoreComment(e.prev(),i))}function isIgnoreComment(e,t){return!!e&&"comment"===e.type&&t.test(e.text)}const l=new Set(["layer"]);function isProcessableRule(e){let t=e.parent;for(;t;){if("atrule"===t.type&&!l.has(t.name.toLowerCase()))return!1;t=t.parent}return!0}const c=/^html$/i,u=/^:where\(html\)$/i,p=/^:root$/i,f=/^:where\(:root\)$/i,d=/(html|:root)/i,m=/^var$/i;function isVarFunction(e){return"function"===e.type&&m.test(e.value)&&Object(e.nodes).length>0}const v=/\bvar\(/i;function parseOrCached(e,t){let n=t.get(e);return n||(n=r(e),t.set(e,n),n)}function toposort(e,t){let r=e.length;const n=new Array(r),o={};let s=r;const a=makeOutgoingEdges(t),i=makeNodesHash(e);for(;s--;)o[s]||visit(e[s],s,new Set);return n;function visit(e,t,s){if(s.has(e)){let t;try{t=", node was:"+JSON.stringify(e)}catch(e){t=""}throw new Error("Cyclic dependency"+t)}if(!i.has(e))throw new Error("Found unknown node. Make sure to provided all involved nodes. Unknown node: "+JSON.stringify(e));if(o[t])return;o[t]=!0;const l=Array.from(a.get(e)||new Set);if(t=l.length){s.add(e);do{const e=l[--t];visit(e,i.get(e),s)}while(t);s.delete(e)}n[--r]=e}}function removeCyclicReferences(e,t){const r=new Set;for(;e.size>0;){const n=findCyclicNode(Array.from(e.keys()),t);if(!n)return r;e.delete(n),r.add(n),t=t.filter((e=>-1===e.indexOf(n)))}return r}function findCyclicNode(e,t){let r=e.length;const n=new Array(r),o={};let s=r;const a=makeOutgoingEdges(t),i=makeNodesHash(e);for(;s--;)if(!o[s]){const t=visit(e[s],s,new Set);if(!t)continue;return t}function visit(e,t,s){if(s.has(e))return e;if(!i.has(e))return;if(o[t])return;o[t]=!0;const l=Array.from(a.get(e)||new Set);if(t=l.length){s.add(e);do{const e=l[--t],r=visit(e,i.get(e),s);if(r)return r}while(t);s.delete(e)}n[--r]=e}}function makeOutgoingEdges(e){const t=new Map;for(let r=0,n=e.length;r{if(!isVarFunction(e))return;const s=parseVarFunction(e);if(!s)return;let a=!1;s.fallback&&r.walk(s.fallback,(e=>{if(!isVarFunction(e))return;const r=parseVarFunction(e);return r?r.fallback||t.has(r.name.value)?void 0:(a=!0,!1):void 0}));let i=t.get(s.name.value)?.nodes;i||!s.fallback||a||(i=s.fallback),void 0!==i&&(i.length?o.splice(n,1,...i):o.splice(n,1,{type:"div",value:" ",before:"",after:"",sourceIndex:e.sourceIndex,sourceEndIndex:e.sourceEndIndex}))})),r.stringify(e.nodes)):""}function walk(e,t){let r,n,o;for(r=0,n=e.length;r"comment"!==e.type&&"space"!==e.type));return 1===t.length&&("word"===t[0].type&&w.test(t[0].value))}function buildCustomPropertiesMap(e,t,n){if(!e.size)return t;const o=new Map(t);{const s=[];for(const[a,i]of e.entries()){const l=parseOrCached(i,n);let c=!1;r.walk(l.nodes,(r=>{if(!isVarFunction(r))return;const n=parseVarFunction(r);n&&(n.fallback||e.has(n.name.value)||t.has(n.name.value)?s.push([n.name.value,a]):c=!0)})),c||o.set(a,l)}removeCyclicReferences(o,s)}{const e=[];for(const[t,n]of o.entries())r.walk(n.nodes,(r=>{if(!isVarFunction(r))return;const n=parseVarFunction(r);n&&(n.fallback||o.has(n.name.value)?e.push([n.name.value,t]):o.delete(t))}));for(let t=0;t{d.test(e.selector)&&e.nodes?.length&&isProcessableRule(e)&&(isBlockIgnored(e)||e.selectors.forEach((t=>{let s=-1;if(u.test(t)||f.test(t))s=0;else if(c.test(t))s=1;else{if(!p.test(t))return;s=2}const a=(l=o,((i=e).parent&&"atrule"===i.parent.type&&"layer"===i.parent.name.toLowerCase()?l.has(i.parent)?l.get(i.parent)+1:0:1e7)+10+s);var i,l;e.each((e=>{if("decl"!==e.type)return;if(!e.variable||isDeclarationIgnored(e))return;if("initial"===e.value.toLowerCase().trim())return;const t=n.get(e.prop)??-1;a>=t&&(n.set(e.prop,a),r.set(e.prop,e.value))}))})))})),buildCustomPropertiesMap(r,new Map,t)}function getCustomPropertiesFromSiblings(e,t,r){if(!e.parent)return t;const n=new Map;return e.parent.each((t=>{"decl"===t.type&&t.variable&&e!==t&&(isDeclarationIgnored(t)||n.set(t.prop,t.value))})),n.size?buildCustomPropertiesMap(n,t,r):t}function transformProperties(e,t,n){if(isTransformableDecl(e)&&!isDeclarationIgnored(e)){const o=e.value,s=transformValueAST(r(o),t);if(s===o)return;if(parentHasExactFallback(e,s))return void(n.preserve||e.remove());if(n.preserve){const t=e.cloneBefore({value:s});hasTrailingComment(t)&&t.raws?.value&&(t.raws.value.value=t.value.replace(g,"$1"),t.raws.value.raw=t.raws.value.value+t.raws.value.raw.replace(g,"$2"))}else e.value=s,hasTrailingComment(e)&&e.raws?.value&&(e.raws.value.value=e.value.replace(g,"$1"),e.raws.value.raw=e.raws.value.value+e.raws.value.raw.replace(g,"$2"))}}const isTransformableDecl=e=>!e.variable&&e.value.includes("--")&&e.value.toLowerCase().includes("var("),hasTrailingComment=e=>"value"in Object(Object(e.raws).value)&&"raw"in(e.raws?.value??{})&&g.test(e.raws.value?.raw??""),g=/^([\W\w]+)(\s*\/\*[\W\w]+?\*\/)$/;function parentHasExactFallback(e,t){if(!e||!e.parent)return!1;let r=!1;const n=e.parent.index(e);return e.parent.each(((o,s)=>o!==e&&(!(s>=n)&&void("decl"===o.type&&o.prop.toLowerCase()===e.prop.toLowerCase()&&o.value===t&&(r=!0))))),r}const h=/(?:\bvar\()|(?:\(top: var\(--f\))/i,creator=e=>{const t=!("preserve"in Object(e))||Boolean(e?.preserve);if("importFrom"in Object(e))throw new Error('[postcss-custom-properties] "importFrom" is no longer supported');if("exportTo"in Object(e))throw new Error('[postcss-custom-properties] "exportTo" is no longer supported');return{postcssPlugin:"postcss-custom-properties",prepare(){let e=new Map;const r=new WeakMap,o=new Map;return{postcssPlugin:"postcss-custom-properties",Once(t){e=getCustomPropertiesFromRoot(t,o)},Declaration(s){if(!v.test(s.value))return;if(n(s,h))return;let a=e;t&&s.parent&&(a=r.get(s.parent)??getCustomPropertiesFromSiblings(s,e,o),r.set(s.parent,a)),transformProperties(s,a,{preserve:t})}}}}};creator.postcss=!0;export{creator as default}; +import{parse as e,addLayerToModel as t}from"@csstools/cascade-layer-name-parser";import r from"postcss-value-parser";import{hasSupportsAtRuleAncestor as n}from"@csstools/utilities";const o=e("csstools-implicit-layer")[0];function collectCascadeLayerOrder(r){const n=new Map,s=new Map,a=[];r.walkAtRules((r=>{if("layer"!==r.name.toLowerCase())return;{let e=r.parent;for(;e;){if("atrule"!==e.type||"layer"!==e.name.toLowerCase()){if(e===r.root())break;return}e=e.parent}}let i;if(r.nodes)i=normalizeLayerName(r.params,1);else{if(!r.params.trim())return;i=r.params}let l=e(i);if(l?.length){{let e=r.parent;for(;e&&"atrule"===e.type&&"layer"===e.name.toLowerCase();){const t=s.get(e);t?(l=l.map((e=>t.concat(e))),e=e.parent):e=e.parent}}if(t(a,l),r.nodes){const e=l[0].concat(o);n.set(r,e),s.set(r,l[0])}}}));for(const e of n.values())t(a,[e]);const i=new WeakMap;for(const[e,t]of n)i.set(e,a.findIndex((e=>t.equal(e))));return i}function normalizeLayerName(e,t){return e.trim()?e:"csstools-anon-layer--"+t++}const s=/(?:!\s*)?postcss-custom-properties:\s*off\b/i,a=new WeakMap;function isBlockIgnored(e){if(!e||!e.nodes)return!1;if(a.has(e))return a.get(e);const t=e.some((e=>isIgnoreComment(e,s)));return a.set(e,t),t}const i=/(?:!\s*)?postcss-custom-properties:\s*ignore\s+next\b/i;function isDeclarationIgnored(e){return!!e&&(!!isBlockIgnored(e.parent)||isIgnoreComment(e.prev(),i))}function isIgnoreComment(e,t){return!!e&&"comment"===e.type&&t.test(e.text)}const l=new Set(["layer"]);function isProcessableRule(e){let t=e.parent;for(;t;){if("atrule"===t.type&&!l.has(t.name.toLowerCase()))return!1;t=t.parent}return!0}const c=/^html$/i,u=/^:where\(html\)$/i,p=/^:root$/i,f=/^:where\(:root\)$/i,d=/(html|:root)/i,m=/^var$/i;function isVarFunction(e){return"function"===e.type&&m.test(e.value)&&Object(e.nodes).length>0}const v=/\bvar\(/i;function parseOrCached(e,t){let n=t.get(e);return n||(n=r(e),t.set(e,n),n)}function toposort(e,t){let r=e.length;const n=new Array(r),o={};let s=r;const a=makeOutgoingEdges(t),i=makeNodesHash(e);for(;s--;)o[s]||visit(e[s],s,new Set);return n;function visit(e,t,s){if(s.has(e)){let t;try{t=", node was:"+JSON.stringify(e)}catch(e){t=""}throw new Error("Cyclic dependency"+t)}if(!i.has(e))throw new Error("Found unknown node. Make sure to provided all involved nodes. Unknown node: "+JSON.stringify(e));if(o[t])return;o[t]=!0;const l=Array.from(a.get(e)||new Set);if(t=l.length){s.add(e);do{const e=l[--t];visit(e,i.get(e),s)}while(t);s.delete(e)}n[--r]=e}}function removeCyclicReferences(e,t){const r=new Set;for(;e.size>0;){const n=findCyclicNode(Array.from(e.keys()),t);if(!n)return r;e.delete(n),r.add(n),t=t.filter((e=>-1===e.indexOf(n)))}return r}function findCyclicNode(e,t){let r=e.length;const n=new Array(r),o={};let s=r;const a=makeOutgoingEdges(t),i=makeNodesHash(e);for(;s--;)if(!o[s]){const t=visit(e[s],s,new Set);if(!t)continue;return t}function visit(e,t,s){if(s.has(e))return e;if(!i.has(e))return;if(o[t])return;o[t]=!0;const l=Array.from(a.get(e)||new Set);if(t=l.length){s.add(e);do{const e=l[--t],r=visit(e,i.get(e),s);if(r)return r}while(t);s.delete(e)}n[--r]=e}}function makeOutgoingEdges(e){const t=new Map;for(let r=0,n=e.length;r{if(!isVarFunction(e))return;const s=parseVarFunction(e);if(!s)return;let a=!1;s.fallback&&r.walk(s.fallback,(e=>{if(!isVarFunction(e))return;const r=parseVarFunction(e);return r?r.fallback||t.has(r.name.value)?void 0:(a=!0,!1):void 0}));let i=t.get(s.name.value)?.nodes;i||!s.fallback||a||(i=s.fallback),void 0!==i&&(i.length?o.splice(n,1,...i):o.splice(n,1,{type:"div",value:" ",before:"",after:"",sourceIndex:e.sourceIndex,sourceEndIndex:e.sourceEndIndex}))})),r.stringify(e.nodes)):""}function walk(e,t){let r,n,o;for(r=0,n=e.length;r"comment"!==e.type&&"space"!==e.type));return 1===t.length&&("word"===t[0].type&&w.test(t[0].value))}function buildCustomPropertiesMap(e,t,n){if(!e.size)return t;const o=new Map(t);{const s=[];for(const[a,i]of e.entries()){const l=parseOrCached(i,n);let c=!1;r.walk(l.nodes,(r=>{if(!isVarFunction(r))return;const n=parseVarFunction(r);n&&(n.fallback||e.has(n.name.value)||t.has(n.name.value)?s.push([n.name.value,a]):c=!0)})),c||o.set(a,l)}removeCyclicReferences(o,s)}{const e=[];for(const[t,n]of o.entries())r.walk(n.nodes,(r=>{if(!isVarFunction(r))return;const n=parseVarFunction(r);n&&(n.fallback||o.has(n.name.value)?e.push([n.name.value,t]):o.delete(t))}));for(let t=0;t{d.test(e.selector)&&e.nodes?.length&&isProcessableRule(e)&&(isBlockIgnored(e)||e.selectors.forEach((t=>{let s=-1;if(u.test(t)||f.test(t))s=0;else if(c.test(t))s=1;else{if(!p.test(t))return;s=2}const a=(l=o,((i=e).parent&&"atrule"===i.parent.type&&"layer"===i.parent.name.toLowerCase()?l.has(i.parent)?l.get(i.parent)+1:0:1e7)+10+s);var i,l;e.each((e=>{if("decl"!==e.type)return;if(!e.variable||isDeclarationIgnored(e))return;if("initial"===e.value.toLowerCase().trim())return;const t=n.get(e.prop)??-1;a>=t&&(n.set(e.prop,a),r.set(e.prop,e.value))}))})))})),buildCustomPropertiesMap(r,new Map,t)}function getCustomPropertiesFromSiblings(e,t,r){if(!e.parent)return t;const n=new Map;return e.parent.each((t=>{"decl"===t.type&&t.variable&&e!==t&&(isDeclarationIgnored(t)||n.set(t.prop,t.value))})),n.size?buildCustomPropertiesMap(n,t,r):t}function transformProperties(e,t,n){if(isTransformableDecl(e)&&!isDeclarationIgnored(e)){const o=e.value,s=transformValueAST(r(o),t);if(s===o)return;if(parentHasExactFallback(e,s))return void(n.preserve||e.remove());if(n.preserve){const t=e.cloneBefore({value:s});hasTrailingComment(t)&&t.raws?.value&&(t.raws.value.value=t.value.replace(g,"$1"),t.raws.value.raw=t.raws.value.value+t.raws.value.raw.replace(g,"$2"))}else e.value=s,hasTrailingComment(e)&&e.raws?.value&&(e.raws.value.value=e.value.replace(g,"$1"),e.raws.value.raw=e.raws.value.value+e.raws.value.raw.replace(g,"$2"))}}const isTransformableDecl=e=>!e.variable&&e.value.includes("--")&&e.value.toLowerCase().includes("var("),hasTrailingComment=e=>"value"in Object(Object(e.raws).value)&&"raw"in(e.raws?.value??{})&&g.test(e.raws.value?.raw??""),g=/^([\W\w]+)(\s*\/\*[\W\w]+?\*\/)$/;function parentHasExactFallback(e,t){if(!e||!e.parent)return!1;let r=!1;const n=e.parent.index(e);return e.parent.each(((o,s)=>o!==e&&(!(s>=n)&&void("decl"===o.type&&o.prop.toLowerCase()===e.prop.toLowerCase()&&o.value===t&&(r=!0))))),r}const h=/\bvar\(|\(top: var\(--f\)/i,creator=e=>{const t=!("preserve"in Object(e))||Boolean(e?.preserve);if("importFrom"in Object(e))throw new Error('[postcss-custom-properties] "importFrom" is no longer supported');if("exportTo"in Object(e))throw new Error('[postcss-custom-properties] "exportTo" is no longer supported');return{postcssPlugin:"postcss-custom-properties",prepare(){let e=new Map;const r=new WeakMap,o=new Map;return{postcssPlugin:"postcss-custom-properties",Once(t){e=getCustomPropertiesFromRoot(t,o)},Declaration(s){if(!v.test(s.value))return;if(n(s,h))return;let a=e;t&&s.parent&&(a=r.get(s.parent)??getCustomPropertiesFromSiblings(s,e,o),r.set(s.parent,a)),transformProperties(s,a,{preserve:t})}}}}};creator.postcss=!0;export{creator as default}; diff --git a/plugins/postcss-custom-properties/src/index.ts b/plugins/postcss-custom-properties/src/index.ts index eaec56051..6d4caace5 100644 --- a/plugins/postcss-custom-properties/src/index.ts +++ b/plugins/postcss-custom-properties/src/index.ts @@ -13,7 +13,7 @@ export type pluginOptions = { preserve?: boolean, }; -const SUPPORTS_REGEX = /(?:\bvar\()|(?:\(top: var\(--f\))/i; +const SUPPORTS_REGEX = /\bvar\(|\(top: var\(--f\)/i; const creator: PluginCreator = (opts?: pluginOptions) => { const preserve = 'preserve' in Object(opts) ? Boolean(opts?.preserve) : true; diff --git a/plugins/postcss-custom-properties/src/is-ignored.ts b/plugins/postcss-custom-properties/src/is-ignored.ts index 191e3f377..75c1abe0f 100644 --- a/plugins/postcss-custom-properties/src/is-ignored.ts +++ b/plugins/postcss-custom-properties/src/is-ignored.ts @@ -1,6 +1,6 @@ import type { Comment, Container, Declaration, Node } from 'postcss'; -const blockRegExp = /(!\s*)?postcss-custom-properties:\s*off\b/i; +const blockRegExp = /(?:!\s*)?postcss-custom-properties:\s*off\b/i; const blockIgnoredCache = new WeakMap(); @@ -19,7 +19,7 @@ export function isBlockIgnored(container: Container | undefined): boolean { return result; } -const DECLARATION_REG_EXP = /(!\s*)?postcss-custom-properties:\s*ignore\s+next\b/i; +const DECLARATION_REG_EXP = /(?:!\s*)?postcss-custom-properties:\s*ignore\s+next\b/i; export function isDeclarationIgnored(decl: Declaration | undefined): boolean { if (!decl) { diff --git a/plugins/postcss-gradients-interpolation-method/dist/index.cjs b/plugins/postcss-gradients-interpolation-method/dist/index.cjs index 4aab2eb48..68872a756 100644 --- a/plugins/postcss-gradients-interpolation-method/dist/index.cjs +++ b/plugins/postcss-gradients-interpolation-method/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("@csstools/postcss-progressive-custom-properties"),o=require("@csstools/utilities"),t=require("@csstools/css-parser-algorithms"),i=require("@csstools/css-tokenizer"),n=require("@csstools/css-color-parser");const s=/(repeating-)?(linear|radial|conic)-gradient\(/i,r=/\bin\b/i,a={test:e=>s.test(e)&&r.test(e)},l=/^(repeating-)?(linear|radial|conic)-gradient$/i;function interpolateColorsInColorStopsList(e,o,s,r=!1){const a=[],l=[];for(let r=0;r0&&N.some((e=>!t.isCommentNode(e)))&&N.push(new t.TokenNode([i.TokenType.Comma,",",-1,-1,void 0]),new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]])),trim([...N,...trim(g)])}function trim(e){let o=0,i=e.length-1;for(let i=0;i=0;o--)if(!t.isWhitespaceNode(e[o])){i=o;break}return e.slice(o,i+1)}const basePlugin=e=>({postcssPlugin:"postcss-gradients-interpolation-method",Declaration(n){if(!a.test(n.value))return;if(o.hasFallback(n))return;if(o.hasSupportsAtRuleAncestor(n,a))return;const s=i.tokenize({css:n.value}),r=t.stringify(t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(s),(e=>{if(!t.isFunctionNode(e))return;const o=modifyGradientFunctionComponentValues(e);o&&(e.value=o)})));if(r===n.value)return;const l=t.stringify(t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(s),(e=>{if(!t.isFunctionNode(e))return;const o=modifyGradientFunctionComponentValues(e,!0);o&&(e.value=o)})));n.cloneBefore({value:r}),r!==l&&n.cloneBefore({value:l}),e?.preserve||n.remove()}});basePlugin.postcss=!0;const postcssPlugin=o=>{const t=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0},o);return t.enableProgressiveCustomProperties?{postcssPlugin:"postcss-gradients-interpolation-method",plugins:[e(),basePlugin(t)]}:basePlugin(t)};postcssPlugin.postcss=!0,module.exports=postcssPlugin; +"use strict";var e=require("@csstools/postcss-progressive-custom-properties"),o=require("@csstools/utilities"),t=require("@csstools/css-parser-algorithms"),i=require("@csstools/css-tokenizer"),n=require("@csstools/css-color-parser");const s=/(?:repeating-)?(?:linear|radial|conic)-gradient\(/i,r=/\bin\b/i,a={test:e=>s.test(e)&&r.test(e)},l=/^(repeating-)?(linear|radial|conic)-gradient$/i;function interpolateColorsInColorStopsList(e,o,s,r=!1){const a=[],l=[];for(let r=0;r0&&N.some((e=>!t.isCommentNode(e)))&&N.push(new t.TokenNode([i.TokenType.Comma,",",-1,-1,void 0]),new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]])),trim([...N,...trim(g)])}function trim(e){let o=0,i=e.length-1;for(let i=0;i=0;o--)if(!t.isWhitespaceNode(e[o])){i=o;break}return e.slice(o,i+1)}const basePlugin=e=>({postcssPlugin:"postcss-gradients-interpolation-method",Declaration(n){if(!a.test(n.value))return;if(o.hasFallback(n))return;if(o.hasSupportsAtRuleAncestor(n,a))return;const s=i.tokenize({css:n.value}),r=t.stringify(t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(s),(e=>{if(!t.isFunctionNode(e))return;const o=modifyGradientFunctionComponentValues(e);o&&(e.value=o)})));if(r===n.value)return;const l=t.stringify(t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(s),(e=>{if(!t.isFunctionNode(e))return;const o=modifyGradientFunctionComponentValues(e,!0);o&&(e.value=o)})));n.cloneBefore({value:r}),r!==l&&n.cloneBefore({value:l}),e?.preserve||n.remove()}});basePlugin.postcss=!0;const postcssPlugin=o=>{const t=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0},o);return t.enableProgressiveCustomProperties?{postcssPlugin:"postcss-gradients-interpolation-method",plugins:[e(),basePlugin(t)]}:basePlugin(t)};postcssPlugin.postcss=!0,module.exports=postcssPlugin; diff --git a/plugins/postcss-gradients-interpolation-method/dist/index.mjs b/plugins/postcss-gradients-interpolation-method/dist/index.mjs index 9bd4676fe..705469842 100644 --- a/plugins/postcss-gradients-interpolation-method/dist/index.mjs +++ b/plugins/postcss-gradients-interpolation-method/dist/index.mjs @@ -1 +1 @@ -import o from"@csstools/postcss-progressive-custom-properties";import{hasFallback as e,hasSupportsAtRuleAncestor as t}from"@csstools/utilities";import{WhitespaceNode as i,TokenNode as r,FunctionNode as n,isCommentNode as s,isWhitespaceNode as l,isTokenNode as a,stringify as c,replaceComponentValues as u,parseCommaSeparatedListOfComponentValues as p,isFunctionNode as v}from"@csstools/css-parser-algorithms";import{TokenType as f,isTokenComma as h,isTokenIdent as m,tokenize as g}from"@csstools/css-tokenizer";import{serializeP3 as d,color as w,colorDataFitsRGB_Gamut as D,serializeRGB as C,SyntaxFlag as b}from"@csstools/css-color-parser";const x=/(repeating-)?(linear|radial|conic)-gradient\(/i,W=/\bin\b/i,P={test:o=>x.test(o)&&W.test(o)},A=/^(repeating-)?(linear|radial|conic)-gradient$/i;function interpolateColorsInColorStopsList(o,e,t,s=!1){const l=[],a=[];for(let s=0;s0&&C.some((o=>!s(o)))&&C.push(new r([f.Comma,",",-1,-1,void 0]),new i([[f.Whitespace," ",-1,-1,void 0]])),trim([...C,...trim(D)])}function trim(o){let e=0,t=o.length-1;for(let t=0;t=0;e--)if(!l(o[e])){t=e;break}return o.slice(e,t+1)}const basePlugin=o=>({postcssPlugin:"postcss-gradients-interpolation-method",Declaration(i){if(!P.test(i.value))return;if(e(i))return;if(t(i,P))return;const r=g({css:i.value}),n=c(u(p(r),(o=>{if(!v(o))return;const e=modifyGradientFunctionComponentValues(o);e&&(o.value=e)})));if(n===i.value)return;const s=c(u(p(r),(o=>{if(!v(o))return;const e=modifyGradientFunctionComponentValues(o,!0);e&&(o.value=e)})));i.cloneBefore({value:n}),n!==s&&i.cloneBefore({value:s}),o?.preserve||i.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const t=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0},e);return t.enableProgressiveCustomProperties?{postcssPlugin:"postcss-gradients-interpolation-method",plugins:[o(),basePlugin(t)]}:basePlugin(t)};postcssPlugin.postcss=!0;export{postcssPlugin as default}; +import o from"@csstools/postcss-progressive-custom-properties";import{hasFallback as e,hasSupportsAtRuleAncestor as t}from"@csstools/utilities";import{WhitespaceNode as i,TokenNode as r,FunctionNode as n,isCommentNode as s,isWhitespaceNode as l,isTokenNode as a,stringify as c,replaceComponentValues as u,parseCommaSeparatedListOfComponentValues as p,isFunctionNode as v}from"@csstools/css-parser-algorithms";import{TokenType as f,isTokenComma as h,isTokenIdent as m,tokenize as g}from"@csstools/css-tokenizer";import{serializeP3 as d,color as w,colorDataFitsRGB_Gamut as D,serializeRGB as C,SyntaxFlag as b}from"@csstools/css-color-parser";const x=/(?:repeating-)?(?:linear|radial|conic)-gradient\(/i,W=/\bin\b/i,P={test:o=>x.test(o)&&W.test(o)},A=/^(repeating-)?(linear|radial|conic)-gradient$/i;function interpolateColorsInColorStopsList(o,e,t,s=!1){const l=[],a=[];for(let s=0;s0&&C.some((o=>!s(o)))&&C.push(new r([f.Comma,",",-1,-1,void 0]),new i([[f.Whitespace," ",-1,-1,void 0]])),trim([...C,...trim(D)])}function trim(o){let e=0,t=o.length-1;for(let t=0;t=0;e--)if(!l(o[e])){t=e;break}return o.slice(e,t+1)}const basePlugin=o=>({postcssPlugin:"postcss-gradients-interpolation-method",Declaration(i){if(!P.test(i.value))return;if(e(i))return;if(t(i,P))return;const r=g({css:i.value}),n=c(u(p(r),(o=>{if(!v(o))return;const e=modifyGradientFunctionComponentValues(o);e&&(o.value=e)})));if(n===i.value)return;const s=c(u(p(r),(o=>{if(!v(o))return;const e=modifyGradientFunctionComponentValues(o,!0);e&&(o.value=e)})));i.cloneBefore({value:n}),n!==s&&i.cloneBefore({value:s}),o?.preserve||i.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const t=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0},e);return t.enableProgressiveCustomProperties?{postcssPlugin:"postcss-gradients-interpolation-method",plugins:[o(),basePlugin(t)]}:basePlugin(t)};postcssPlugin.postcss=!0;export{postcssPlugin as default}; diff --git a/plugins/postcss-gradients-interpolation-method/src/is-gradient.ts b/plugins/postcss-gradients-interpolation-method/src/is-gradient.ts index 0952927f6..f8856e547 100644 --- a/plugins/postcss-gradients-interpolation-method/src/is-gradient.ts +++ b/plugins/postcss-gradients-interpolation-method/src/is-gradient.ts @@ -1,4 +1,4 @@ -const GRADIENT_FUNCTION_REGEX = /(repeating-)?(linear|radial|conic)-gradient\(/i; +const GRADIENT_FUNCTION_REGEX = /(?:repeating-)?(?:linear|radial|conic)-gradient\(/i; const IN_KEYWORD_REGEX = /\bin\b/i; export const IS_GRADIENT_FUNCTION = { diff --git a/plugins/postcss-gradients-interpolation-method/src/modify-gradient-component-values.ts b/plugins/postcss-gradients-interpolation-method/src/modify-gradient-component-values.ts index 5ea50cbf6..fa97eb7af 100644 --- a/plugins/postcss-gradients-interpolation-method/src/modify-gradient-component-values.ts +++ b/plugins/postcss-gradients-interpolation-method/src/modify-gradient-component-values.ts @@ -5,9 +5,9 @@ import { isCommentNode, isTokenNode, isWhitespaceNode, TokenNode, WhitespaceNode import { parseColorStops } from './parse-color-stops'; import { TokenType, isTokenComma, isTokenIdent } from '@csstools/css-tokenizer'; -const COLOR_SPACE_REGEX = /^(srgb|srgb-linear|lab|oklab|xyz|xyz-d50|xyz-d65|hsl|hwb|lch|oklch)$/i; -const POLAR_COLOR_SPACE_REGEX = /^(hsl|hwb|lch|oklch)$/i; -const HUE_INTERPOLATION_METHOD_REGEX = /^(shorter|longer|increasing|decreasing)$/i; +const COLOR_SPACE_REGEX = /^(?:srgb|srgb-linear|lab|oklab|xyz|xyz-d50|xyz-d65|hsl|hwb|lch|oklch)$/i; +const POLAR_COLOR_SPACE_REGEX = /^(?:hsl|hwb|lch|oklch)$/i; +const HUE_INTERPOLATION_METHOD_REGEX = /^(?:shorter|longer|increasing|decreasing)$/i; const IN_KEYWORD_REGEX = /^in$/i; const HUE_KEYWORD_REGEX = /^hue$/i; diff --git a/plugins/postcss-image-set-function/dist/index.cjs b/plugins/postcss-image-set-function/dist/index.cjs index a2ab6d1f5..8e33821a3 100644 --- a/plugins/postcss-image-set-function/dist/index.cjs +++ b/plugins/postcss-image-set-function/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("postcss-value-parser"),t=require("@csstools/utilities");const n=/^(cross-fade|image|(repeating-)?(conic|linear|radial)-gradient|url|var)$/i;function getImage(t){return!(!t||!t.type)&&("string"===t.type?"url("+e.stringify(t)+")":!("function"!==t.type||!n.test(t.value))&&e.stringify(t))}const i=new Map([["dpcm",2.54],["dpi",1],["dppx",96],["x",96]]);function getMedia(e,t,n){if("boolean"==typeof e)return!1;const i=Math.floor(e/96*100)/100;return t.atRule({name:"media",params:`(-webkit-min-device-pixel-ratio: ${i}), (min-resolution: ${e}dpi)`,source:n.source})}function getMediaDPI(t){if(!t)return!1;if("word"!==t.type)return!1;if(!isNumericNode(t))return!1;const n=e.unit(t.value);if(!n)return!1;const r=i.get(n.unit.toLowerCase());return!!r&&Number(n.number)*r}function isNumericNode(t){if(!t||!t.value)return!1;try{return!1!==e.unit(t.value)}catch(e){return!1}}const handleInvalidation=(e,t,n)=>{if("warn"===e.oninvalid)e.decl.warn(e.result,t,{word:String(n)});else if("throw"===e.oninvalid)throw e.decl.error(t,{word:String(n)})},processImageSet=(t,n,i)=>{const r=n.parent;if(!r)return;const o=new Map,s=n.value;for(let r=0;re-t)),u=l.map((e=>o.get(e)?.atRule)).filter((e=>!!e));if(!u.length)return;const c=o.get(l[0])?.value;if(!c)return;const f=u.slice(1);f.length&&r.after(f),n.cloneBefore({value:c.trim()}),i.preserve||(n.remove(),r.nodes?.length||r.remove())},r=/(^|[^\w-])(-webkit-)?image-set\(/i,o=/^(-webkit-)?image-set$/i,creator=n=>{const i=!("preserve"in Object(n))||Boolean(n?.preserve),s="onInvalid"in Object(n)?n?.onInvalid:"ignore";if("oninvalid"in Object(n))throw new Error('"oninvalid" was changed to "onInvalid" to match other plugins with similar options');return{postcssPlugin:"postcss-image-set-function",Declaration(n,{result:a,postcss:l}){const u=n.value;if(!r.test(u))return;if(t.hasFallback(n))return;let c;try{c=e(u)}catch(e){n.warn(a,`Failed to parse value '${u}' as an image-set function. Leaving the original value intact.`)}if(void 0===c)return;const f=[];c.walk((t=>{if("function"!==t.type)return;if(!o.test(t.value))return;let i=!1;if(e.walk(t.nodes,(e=>{"function"===e.type&&o.test(e.value)&&(i=!0)})),i)return handleInvalidation({decl:n,oninvalid:s,result:a},"nested image-set functions are not allowed",e.stringify(t)),!1;const r=t.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type));f.push({imageSetFunction:t,imageSetOptionNodes:r})})),processImageSet(f,n,{decl:n,oninvalid:s,preserve:i,result:a,postcss:l})}}};creator.postcss=!0,module.exports=creator; +"use strict";var e=require("postcss-value-parser"),t=require("@csstools/utilities");const n=/^(?:cross-fade|image|(?:repeating-)?(?:conic|linear|radial)-gradient|url|var)$/i;function getImage(t){return!(!t||!t.type)&&("string"===t.type?"url("+e.stringify(t)+")":!("function"!==t.type||!n.test(t.value))&&e.stringify(t))}const i=new Map([["dpcm",2.54],["dpi",1],["dppx",96],["x",96]]);function getMedia(e,t,n){if("boolean"==typeof e)return!1;const i=Math.floor(e/96*100)/100;return t.atRule({name:"media",params:`(-webkit-min-device-pixel-ratio: ${i}), (min-resolution: ${e}dpi)`,source:n.source})}function getMediaDPI(t){if(!t)return!1;if("word"!==t.type)return!1;if(!isNumericNode(t))return!1;const n=e.unit(t.value);if(!n)return!1;const r=i.get(n.unit.toLowerCase());return!!r&&Number(n.number)*r}function isNumericNode(t){if(!t||!t.value)return!1;try{return!1!==e.unit(t.value)}catch(e){return!1}}const handleInvalidation=(e,t,n)=>{if("warn"===e.oninvalid)e.decl.warn(e.result,t,{word:String(n)});else if("throw"===e.oninvalid)throw e.decl.error(t,{word:String(n)})},processImageSet=(t,n,i)=>{const r=n.parent;if(!r)return;const o=new Map,s=n.value;for(let r=0;re-t)),u=l.map((e=>o.get(e)?.atRule)).filter((e=>!!e));if(!u.length)return;const c=o.get(l[0])?.value;if(!c)return;const f=u.slice(1);f.length&&r.after(f),n.cloneBefore({value:c.trim()}),i.preserve||(n.remove(),r.nodes?.length||r.remove())},r=/(?:^|[^\w-])(?:-webkit-)?image-set\(/i,o=/^(?:-webkit-)?image-set$/i,creator=n=>{const i=!("preserve"in Object(n))||Boolean(n?.preserve),s="onInvalid"in Object(n)?n?.onInvalid:"ignore";if("oninvalid"in Object(n))throw new Error('"oninvalid" was changed to "onInvalid" to match other plugins with similar options');return{postcssPlugin:"postcss-image-set-function",Declaration(n,{result:a,postcss:l}){const u=n.value;if(!r.test(u))return;if(t.hasFallback(n))return;let c;try{c=e(u)}catch(e){n.warn(a,`Failed to parse value '${u}' as an image-set function. Leaving the original value intact.`)}if(void 0===c)return;const f=[];c.walk((t=>{if("function"!==t.type)return;if(!o.test(t.value))return;let i=!1;if(e.walk(t.nodes,(e=>{"function"===e.type&&o.test(e.value)&&(i=!0)})),i)return handleInvalidation({decl:n,oninvalid:s,result:a},"nested image-set functions are not allowed",e.stringify(t)),!1;const r=t.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type));f.push({imageSetFunction:t,imageSetOptionNodes:r})})),processImageSet(f,n,{decl:n,oninvalid:s,preserve:i,result:a,postcss:l})}}};creator.postcss=!0,module.exports=creator; diff --git a/plugins/postcss-image-set-function/dist/index.mjs b/plugins/postcss-image-set-function/dist/index.mjs index c091d01a4..b07e52627 100644 --- a/plugins/postcss-image-set-function/dist/index.mjs +++ b/plugins/postcss-image-set-function/dist/index.mjs @@ -1 +1 @@ -import e from"postcss-value-parser";import{hasFallback as t}from"@csstools/utilities";const n=/^(cross-fade|image|(repeating-)?(conic|linear|radial)-gradient|url|var)$/i;function getImage(t){return!(!t||!t.type)&&("string"===t.type?"url("+e.stringify(t)+")":!("function"!==t.type||!n.test(t.value))&&e.stringify(t))}const i=new Map([["dpcm",2.54],["dpi",1],["dppx",96],["x",96]]);function getMedia(e,t,n){if("boolean"==typeof e)return!1;const i=Math.floor(e/96*100)/100;return t.atRule({name:"media",params:`(-webkit-min-device-pixel-ratio: ${i}), (min-resolution: ${e}dpi)`,source:n.source})}function getMediaDPI(t){if(!t)return!1;if("word"!==t.type)return!1;if(!isNumericNode(t))return!1;const n=e.unit(t.value);if(!n)return!1;const r=i.get(n.unit.toLowerCase());return!!r&&Number(n.number)*r}function isNumericNode(t){if(!t||!t.value)return!1;try{return!1!==e.unit(t.value)}catch(e){return!1}}const handleInvalidation=(e,t,n)=>{if("warn"===e.oninvalid)e.decl.warn(e.result,t,{word:String(n)});else if("throw"===e.oninvalid)throw e.decl.error(t,{word:String(n)})},processImageSet=(t,n,i)=>{const r=n.parent;if(!r)return;const o=new Map,s=n.value;for(let r=0;re-t)),u=l.map((e=>o.get(e)?.atRule)).filter((e=>!!e));if(!u.length)return;const c=o.get(l[0])?.value;if(!c)return;const f=u.slice(1);f.length&&r.after(f),n.cloneBefore({value:c.trim()}),i.preserve||(n.remove(),r.nodes?.length||r.remove())},r=/(^|[^\w-])(-webkit-)?image-set\(/i,o=/^(-webkit-)?image-set$/i,creator=n=>{const i=!("preserve"in Object(n))||Boolean(n?.preserve),s="onInvalid"in Object(n)?n?.onInvalid:"ignore";if("oninvalid"in Object(n))throw new Error('"oninvalid" was changed to "onInvalid" to match other plugins with similar options');return{postcssPlugin:"postcss-image-set-function",Declaration(n,{result:a,postcss:l}){const u=n.value;if(!r.test(u))return;if(t(n))return;let c;try{c=e(u)}catch(e){n.warn(a,`Failed to parse value '${u}' as an image-set function. Leaving the original value intact.`)}if(void 0===c)return;const f=[];c.walk((t=>{if("function"!==t.type)return;if(!o.test(t.value))return;let i=!1;if(e.walk(t.nodes,(e=>{"function"===e.type&&o.test(e.value)&&(i=!0)})),i)return handleInvalidation({decl:n,oninvalid:s,result:a},"nested image-set functions are not allowed",e.stringify(t)),!1;const r=t.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type));f.push({imageSetFunction:t,imageSetOptionNodes:r})})),processImageSet(f,n,{decl:n,oninvalid:s,preserve:i,result:a,postcss:l})}}};creator.postcss=!0;export{creator as default}; +import e from"postcss-value-parser";import{hasFallback as t}from"@csstools/utilities";const n=/^(?:cross-fade|image|(?:repeating-)?(?:conic|linear|radial)-gradient|url|var)$/i;function getImage(t){return!(!t||!t.type)&&("string"===t.type?"url("+e.stringify(t)+")":!("function"!==t.type||!n.test(t.value))&&e.stringify(t))}const i=new Map([["dpcm",2.54],["dpi",1],["dppx",96],["x",96]]);function getMedia(e,t,n){if("boolean"==typeof e)return!1;const i=Math.floor(e/96*100)/100;return t.atRule({name:"media",params:`(-webkit-min-device-pixel-ratio: ${i}), (min-resolution: ${e}dpi)`,source:n.source})}function getMediaDPI(t){if(!t)return!1;if("word"!==t.type)return!1;if(!isNumericNode(t))return!1;const n=e.unit(t.value);if(!n)return!1;const r=i.get(n.unit.toLowerCase());return!!r&&Number(n.number)*r}function isNumericNode(t){if(!t||!t.value)return!1;try{return!1!==e.unit(t.value)}catch(e){return!1}}const handleInvalidation=(e,t,n)=>{if("warn"===e.oninvalid)e.decl.warn(e.result,t,{word:String(n)});else if("throw"===e.oninvalid)throw e.decl.error(t,{word:String(n)})},processImageSet=(t,n,i)=>{const r=n.parent;if(!r)return;const o=new Map,s=n.value;for(let r=0;re-t)),u=l.map((e=>o.get(e)?.atRule)).filter((e=>!!e));if(!u.length)return;const c=o.get(l[0])?.value;if(!c)return;const f=u.slice(1);f.length&&r.after(f),n.cloneBefore({value:c.trim()}),i.preserve||(n.remove(),r.nodes?.length||r.remove())},r=/(?:^|[^\w-])(?:-webkit-)?image-set\(/i,o=/^(?:-webkit-)?image-set$/i,creator=n=>{const i=!("preserve"in Object(n))||Boolean(n?.preserve),s="onInvalid"in Object(n)?n?.onInvalid:"ignore";if("oninvalid"in Object(n))throw new Error('"oninvalid" was changed to "onInvalid" to match other plugins with similar options');return{postcssPlugin:"postcss-image-set-function",Declaration(n,{result:a,postcss:l}){const u=n.value;if(!r.test(u))return;if(t(n))return;let c;try{c=e(u)}catch(e){n.warn(a,`Failed to parse value '${u}' as an image-set function. Leaving the original value intact.`)}if(void 0===c)return;const f=[];c.walk((t=>{if("function"!==t.type)return;if(!o.test(t.value))return;let i=!1;if(e.walk(t.nodes,(e=>{"function"===e.type&&o.test(e.value)&&(i=!0)})),i)return handleInvalidation({decl:n,oninvalid:s,result:a},"nested image-set functions are not allowed",e.stringify(t)),!1;const r=t.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type));f.push({imageSetFunction:t,imageSetOptionNodes:r})})),processImageSet(f,n,{decl:n,oninvalid:s,preserve:i,result:a,postcss:l})}}};creator.postcss=!0;export{creator as default}; diff --git a/plugins/postcss-image-set-function/src/index.ts b/plugins/postcss-image-set-function/src/index.ts index 28b71331c..6864d6893 100644 --- a/plugins/postcss-image-set-function/src/index.ts +++ b/plugins/postcss-image-set-function/src/index.ts @@ -4,8 +4,8 @@ import type { PluginCreator } from 'postcss'; import { handleInvalidation } from './lib/handle-invalidation'; import { hasFallback } from '@csstools/utilities'; -const IMAGE_SET_VALUE_MATCH_REGEX = /(^|[^\w-])(-webkit-)?image-set\(/i; -const IMAGE_SET_FUNCTION_MATCH_REGEX = /^(-webkit-)?image-set$/i; +const IMAGE_SET_VALUE_MATCH_REGEX = /(?:^|[^\w-])(?:-webkit-)?image-set\(/i; +const IMAGE_SET_FUNCTION_MATCH_REGEX = /^(?:-webkit-)?image-set$/i; /** postcss-image-set-function plugin options */ export type pluginOptions = { diff --git a/plugins/postcss-image-set-function/src/lib/get-image.ts b/plugins/postcss-image-set-function/src/lib/get-image.ts index 485429305..1cb82b854 100644 --- a/plugins/postcss-image-set-function/src/lib/get-image.ts +++ b/plugins/postcss-image-set-function/src/lib/get-image.ts @@ -1,6 +1,6 @@ import valueParser from 'postcss-value-parser'; -const IMAGE_FUNC_REGEX = /^(cross-fade|image|(repeating-)?(conic|linear|radial)-gradient|url|var)$/i; +const IMAGE_FUNC_REGEX = /^(?:cross-fade|image|(?:repeating-)?(?:conic|linear|radial)-gradient|url|var)$/i; export function getImage(node: valueParser.Node): string|false { // | | | diff --git a/plugins/postcss-minify/dist/index.cjs b/plugins/postcss-minify/dist/index.cjs index 61bd40990..00c395f7d 100644 --- a/plugins/postcss-minify/dist/index.cjs +++ b/plugins/postcss-minify/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("@csstools/css-tokenizer");const t=/(?:license|copyright)/i,r=/sourceMappingURL/i,s=/(?:\s|\/\*)/,o=/^layer$/i;function minify(t,r){if(!r)return r;if(t.has(r))return t.get(r);const o=r.trim();if(""===o)return t.set(r,""),"";if(!s.test(o))return t.set(r,o),o;const n=e.tokenize({css:o});let i,a=!1;for(let t=0;t{const e=new Map;return{postcssPlugin:"postcss-minify",OnceExit(s){s.raws.before="",s.raws.after="\n",s.walk((s=>{switch(s.type){case"atrule":if(removeEmptyNodes(s))return;return s.raws.after="",s.raws.afterName=" ",s.raws.before="",s.raws.between="",s.raws.params=void 0,setSemicolon(s),void(s.params=minify(e,s.params));case"rule":if(removeEmptyNodes(s))return;return s.raws.after="",s.raws.before="",s.raws.between="",s.raws.selector=void 0,setSemicolon(s),void(s.selector=minify(e,s.selector));case"decl":return s.prop.startsWith("--")?void(s.raws.before=""):(s.raws.before="",s.raws.between=":",s.raws.important=s.important?"!important":"",s.raws.value=void 0,void(s.value=minify(e,s.value)));case"comment":return s.text.startsWith("!")||t.test(s.text)||r.test(s.text)?void(s.raws.before=""):void s.remove()}}))}}};creator.postcss=!0,module.exports=creator; +"use strict";var e=require("@csstools/css-tokenizer");const t=/license|copyright/i,r=/sourceMappingURL/i,s=/\s|\/\*/,o=/^layer$/i;function minify(t,r){if(!r)return r;if(t.has(r))return t.get(r);const o=r.trim();if(""===o)return t.set(r,""),"";if(!s.test(o))return t.set(r,o),o;const n=e.tokenize({css:o});let i,a=!1;for(let t=0;t{const e=new Map;return{postcssPlugin:"postcss-minify",OnceExit(s){s.raws.before="",s.raws.after="\n",s.walk((s=>{switch(s.type){case"atrule":if(removeEmptyNodes(s))return;return s.raws.after="",s.raws.afterName=" ",s.raws.before="",s.raws.between="",s.raws.params=void 0,setSemicolon(s),void(s.params=minify(e,s.params));case"rule":if(removeEmptyNodes(s))return;return s.raws.after="",s.raws.before="",s.raws.between="",s.raws.selector=void 0,setSemicolon(s),void(s.selector=minify(e,s.selector));case"decl":return s.prop.startsWith("--")?void(s.raws.before=""):(s.raws.before="",s.raws.between=":",s.raws.important=s.important?"!important":"",s.raws.value=void 0,void(s.value=minify(e,s.value)));case"comment":return s.text.startsWith("!")||t.test(s.text)||r.test(s.text)?void(s.raws.before=""):void s.remove()}}))}}};creator.postcss=!0,module.exports=creator; diff --git a/plugins/postcss-minify/dist/index.mjs b/plugins/postcss-minify/dist/index.mjs index da8be65bb..9b4fa8977 100644 --- a/plugins/postcss-minify/dist/index.mjs +++ b/plugins/postcss-minify/dist/index.mjs @@ -1 +1 @@ -import{tokenize as e,isTokenWhiteSpaceOrComment as t}from"@csstools/css-tokenizer";const r=/(?:license|copyright)/i,s=/sourceMappingURL/i,o=/(?:\s|\/\*)/,n=/^layer$/i;function minify(r,s){if(!s)return s;if(r.has(s))return r.get(s);const n=s.trim();if(""===n)return r.set(s,""),"";if(!o.test(n))return r.set(s,n),n;const a=e({css:n});let i,c=!1;for(let e=0;e{const e=new Map;return{postcssPlugin:"postcss-minify",OnceExit(t){t.raws.before="",t.raws.after="\n",t.walk((t=>{switch(t.type){case"atrule":if(removeEmptyNodes(t))return;return t.raws.after="",t.raws.afterName=" ",t.raws.before="",t.raws.between="",t.raws.params=void 0,setSemicolon(t),void(t.params=minify(e,t.params));case"rule":if(removeEmptyNodes(t))return;return t.raws.after="",t.raws.before="",t.raws.between="",t.raws.selector=void 0,setSemicolon(t),void(t.selector=minify(e,t.selector));case"decl":return t.prop.startsWith("--")?void(t.raws.before=""):(t.raws.before="",t.raws.between=":",t.raws.important=t.important?"!important":"",t.raws.value=void 0,void(t.value=minify(e,t.value)));case"comment":return t.text.startsWith("!")||r.test(t.text)||s.test(t.text)?void(t.raws.before=""):void t.remove()}}))}}};creator.postcss=!0;export{creator as default}; +import{tokenize as e,isTokenWhiteSpaceOrComment as t}from"@csstools/css-tokenizer";const r=/license|copyright/i,s=/sourceMappingURL/i,o=/\s|\/\*/,n=/^layer$/i;function minify(r,s){if(!s)return s;if(r.has(s))return r.get(s);const n=s.trim();if(""===n)return r.set(s,""),"";if(!o.test(n))return r.set(s,n),n;const a=e({css:n});let i,c=!1;for(let e=0;e{const e=new Map;return{postcssPlugin:"postcss-minify",OnceExit(t){t.raws.before="",t.raws.after="\n",t.walk((t=>{switch(t.type){case"atrule":if(removeEmptyNodes(t))return;return t.raws.after="",t.raws.afterName=" ",t.raws.before="",t.raws.between="",t.raws.params=void 0,setSemicolon(t),void(t.params=minify(e,t.params));case"rule":if(removeEmptyNodes(t))return;return t.raws.after="",t.raws.before="",t.raws.between="",t.raws.selector=void 0,setSemicolon(t),void(t.selector=minify(e,t.selector));case"decl":return t.prop.startsWith("--")?void(t.raws.before=""):(t.raws.before="",t.raws.between=":",t.raws.important=t.important?"!important":"",t.raws.value=void 0,void(t.value=minify(e,t.value)));case"comment":return t.text.startsWith("!")||r.test(t.text)||s.test(t.text)?void(t.raws.before=""):void t.remove()}}))}}};creator.postcss=!0;export{creator as default}; diff --git a/plugins/postcss-minify/src/index.ts b/plugins/postcss-minify/src/index.ts index 790118086..3fd3f00cc 100644 --- a/plugins/postcss-minify/src/index.ts +++ b/plugins/postcss-minify/src/index.ts @@ -2,9 +2,9 @@ import type { AtRule, Container, Document, PluginCreator, Rule } from 'postcss'; import type { CSSToken } from '@csstools/css-tokenizer'; import { isTokenWhiteSpaceOrComment, tokenize } from '@csstools/css-tokenizer'; -const HAS_LEGAL_KEYWORDS_REGEX = /(?:license|copyright)/i; +const HAS_LEGAL_KEYWORDS_REGEX = /license|copyright/i; const HAS_SOURCE_MAP_REGEX = /sourceMappingURL/i; -const HAS_WHITESPACE_OR_COMMENTS_REGEX = /(?:\s|\/\*)/; +const HAS_WHITESPACE_OR_COMMENTS_REGEX = /\s|\/\*/; const IS_LAYER_REGEX = /^layer$/i; function minify(cache: Map, x: string | undefined): string | undefined { diff --git a/plugins/postcss-nested-calc/dist/index.cjs b/plugins/postcss-nested-calc/dist/index.cjs index 27ae530a2..013b648ec 100644 --- a/plugins/postcss-nested-calc/dist/index.cjs +++ b/plugins/postcss-nested-calc/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("postcss-value-parser"),t=require("@csstools/utilities");const r=/calc\(/gim;const creator=s=>{const a=Object.assign({preserve:!0},s);return{postcssPlugin:"postcss-nested-calc",Declaration(s,{result:o}){if((s.value.match(r)||[]).length<2)return;if(s.variable)return;if(t.hasFallback(s))return;const c=s.value;let l;try{l=e(c)}catch(e){return void s.warn(o,`Failed to parse value '${c}'. Leaving the original value intact.`)}if(void 0===l)return;e.walk(l.nodes,(t=>{t.type&&"function"===t.type&&"calc"===t.value.toLowerCase()&&e.walk(t.nodes,(e=>{if(e.type&&"function"===e.type)return"calc"===e.value.toLowerCase()&&void(e.value="")}))}),!0);const n=String(l);n!==c&&(s.cloneBefore({value:n}),a.preserve||s.remove())}}};creator.postcss=!0,module.exports=creator; +"use strict";var e=require("postcss-value-parser"),t=require("@csstools/utilities");const r=/calc\(/gi;const creator=s=>{const a=Object.assign({preserve:!0},s);return{postcssPlugin:"postcss-nested-calc",Declaration(s,{result:o}){if((s.value.match(r)||[]).length<2)return;if(s.variable)return;if(t.hasFallback(s))return;const c=s.value;let l;try{l=e(c)}catch(e){return void s.warn(o,`Failed to parse value '${c}'. Leaving the original value intact.`)}if(void 0===l)return;e.walk(l.nodes,(t=>{t.type&&"function"===t.type&&"calc"===t.value.toLowerCase()&&e.walk(t.nodes,(e=>{if(e.type&&"function"===e.type)return"calc"===e.value.toLowerCase()&&void(e.value="")}))}),!0);const n=String(l);n!==c&&(s.cloneBefore({value:n}),a.preserve||s.remove())}}};creator.postcss=!0,module.exports=creator; diff --git a/plugins/postcss-nested-calc/dist/index.mjs b/plugins/postcss-nested-calc/dist/index.mjs index 5ef02cade..c6bc9d565 100644 --- a/plugins/postcss-nested-calc/dist/index.mjs +++ b/plugins/postcss-nested-calc/dist/index.mjs @@ -1 +1 @@ -import e from"postcss-value-parser";import{hasFallback as t}from"@csstools/utilities";const r=/calc\(/gim;const creator=s=>{const a=Object.assign({preserve:!0},s);return{postcssPlugin:"postcss-nested-calc",Declaration(s,{result:o}){if((s.value.match(r)||[]).length<2)return;if(s.variable)return;if(t(s))return;const n=s.value;let c;try{c=e(n)}catch(e){return void s.warn(o,`Failed to parse value '${n}'. Leaving the original value intact.`)}if(void 0===c)return;e.walk(c.nodes,(t=>{t.type&&"function"===t.type&&"calc"===t.value.toLowerCase()&&e.walk(t.nodes,(e=>{if(e.type&&"function"===e.type)return"calc"===e.value.toLowerCase()&&void(e.value="")}))}),!0);const l=String(c);l!==n&&(s.cloneBefore({value:l}),a.preserve||s.remove())}}};creator.postcss=!0;export{creator as default}; +import e from"postcss-value-parser";import{hasFallback as t}from"@csstools/utilities";const r=/calc\(/gi;const creator=s=>{const a=Object.assign({preserve:!0},s);return{postcssPlugin:"postcss-nested-calc",Declaration(s,{result:o}){if((s.value.match(r)||[]).length<2)return;if(s.variable)return;if(t(s))return;const n=s.value;let c;try{c=e(n)}catch(e){return void s.warn(o,`Failed to parse value '${n}'. Leaving the original value intact.`)}if(void 0===c)return;e.walk(c.nodes,(t=>{t.type&&"function"===t.type&&"calc"===t.value.toLowerCase()&&e.walk(t.nodes,(e=>{if(e.type&&"function"===e.type)return"calc"===e.value.toLowerCase()&&void(e.value="")}))}),!0);const l=String(c);l!==n&&(s.cloneBefore({value:l}),a.preserve||s.remove())}}};creator.postcss=!0;export{creator as default}; diff --git a/plugins/postcss-nested-calc/src/occurrences.ts b/plugins/postcss-nested-calc/src/occurrences.ts index 90937e34e..26f86592c 100644 --- a/plugins/postcss-nested-calc/src/occurrences.ts +++ b/plugins/postcss-nested-calc/src/occurrences.ts @@ -1,9 +1,8 @@ // check for "calc(" // - case insensitive // - multiline -// - multiple matches -const calcExpressionRegExp = /calc\(/gim; +const CALC_EXPRESSION_REGEX = /calc\(/gi; export function numberOfCalcOccurrences(value: string): number { - return (value.match(calcExpressionRegExp) || []).length; + return (value.match(CALC_EXPRESSION_REGEX) || []).length; } diff --git a/plugins/postcss-relative-color-syntax/dist/index.cjs b/plugins/postcss-relative-color-syntax/dist/index.cjs index 3ce20e78e..47704393c 100644 --- a/plugins/postcss-relative-color-syntax/dist/index.cjs +++ b/plugins/postcss-relative-color-syntax/dist/index.cjs @@ -1 +1 @@ -"use strict";var s=require("@csstools/postcss-progressive-custom-properties"),e=require("@csstools/css-color-parser"),a=require("@csstools/utilities"),r=require("@csstools/css-parser-algorithms"),t=require("@csstools/css-tokenizer");const o=/\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(/i,l=/\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(\s*?from/i,i=/^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)$/i,n=/from/i,basePlugin=s=>({postcssPlugin:"postcss-relative-color-syntax",Declaration(c){const u=c.value;if(!o.test(u)||!n.test(u))return;if(a.hasFallback(c))return;if(a.hasSupportsAtRuleAncestor(c,l))return;const p=t.tokenize({css:u}),g=r.replaceComponentValues(r.parseCommaSeparatedListOfComponentValues(p),(s=>{if(!r.isFunctionNode(s)||!i.test(s.getName()))return;const a=e.color(s);return a&&!a.syntaxFlags.has(e.SyntaxFlag.Experimental)&&!a.syntaxFlags.has(e.SyntaxFlag.HasNoneKeywords)&&a.syntaxFlags.has(e.SyntaxFlag.RelativeColorSyntax)?e.serializeRGB(a):void 0})),b=r.stringify(g);if(b===u)return;let y=b;s?.subFeatures.displayP3&&(y=r.stringify(r.replaceComponentValues(r.parseCommaSeparatedListOfComponentValues(p),(s=>{if(!r.isFunctionNode(s)||!i.test(s.getName()))return;const a=e.color(s);return a&&!a.syntaxFlags.has(e.SyntaxFlag.Experimental)&&!a.syntaxFlags.has(e.SyntaxFlag.HasNoneKeywords)&&a.syntaxFlags.has(e.SyntaxFlag.RelativeColorSyntax)?e.colorDataFitsRGB_Gamut(a)?e.serializeRGB(a):e.serializeP3(a):void 0})))),c.cloneBefore({value:b}),s?.subFeatures.displayP3&&y!==b&&c.cloneBefore({value:y}),s?.preserve||c.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const a=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return a.subFeatures=Object.assign({displayP3:!0},a.subFeatures),a.enableProgressiveCustomProperties&&(a.preserve||a.subFeatures.displayP3)?{postcssPlugin:"postcss-relative-color-syntax",plugins:[s(),basePlugin(a)]}:basePlugin(a)};postcssPlugin.postcss=!0,module.exports=postcssPlugin; +"use strict";var s=require("@csstools/postcss-progressive-custom-properties"),e=require("@csstools/css-color-parser"),a=require("@csstools/utilities"),r=require("@csstools/css-parser-algorithms"),t=require("@csstools/css-tokenizer");const o=/\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(/i,l=/\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(\s*from/i,i=/^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)$/i,n=/from/i,basePlugin=s=>({postcssPlugin:"postcss-relative-color-syntax",Declaration(c){const u=c.value;if(!o.test(u)||!n.test(u))return;if(a.hasFallback(c))return;if(a.hasSupportsAtRuleAncestor(c,l))return;const p=t.tokenize({css:u}),g=r.replaceComponentValues(r.parseCommaSeparatedListOfComponentValues(p),(s=>{if(!r.isFunctionNode(s)||!i.test(s.getName()))return;const a=e.color(s);return a&&!a.syntaxFlags.has(e.SyntaxFlag.Experimental)&&!a.syntaxFlags.has(e.SyntaxFlag.HasNoneKeywords)&&a.syntaxFlags.has(e.SyntaxFlag.RelativeColorSyntax)?e.serializeRGB(a):void 0})),b=r.stringify(g);if(b===u)return;let y=b;s?.subFeatures.displayP3&&(y=r.stringify(r.replaceComponentValues(r.parseCommaSeparatedListOfComponentValues(p),(s=>{if(!r.isFunctionNode(s)||!i.test(s.getName()))return;const a=e.color(s);return a&&!a.syntaxFlags.has(e.SyntaxFlag.Experimental)&&!a.syntaxFlags.has(e.SyntaxFlag.HasNoneKeywords)&&a.syntaxFlags.has(e.SyntaxFlag.RelativeColorSyntax)?e.colorDataFitsRGB_Gamut(a)?e.serializeRGB(a):e.serializeP3(a):void 0})))),c.cloneBefore({value:b}),s?.subFeatures.displayP3&&y!==b&&c.cloneBefore({value:y}),s?.preserve||c.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const a=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return a.subFeatures=Object.assign({displayP3:!0},a.subFeatures),a.enableProgressiveCustomProperties&&(a.preserve||a.subFeatures.displayP3)?{postcssPlugin:"postcss-relative-color-syntax",plugins:[s(),basePlugin(a)]}:basePlugin(a)};postcssPlugin.postcss=!0,module.exports=postcssPlugin; diff --git a/plugins/postcss-relative-color-syntax/dist/index.mjs b/plugins/postcss-relative-color-syntax/dist/index.mjs index 0184ff352..f2ae3d62b 100644 --- a/plugins/postcss-relative-color-syntax/dist/index.mjs +++ b/plugins/postcss-relative-color-syntax/dist/index.mjs @@ -1 +1 @@ -import s from"@csstools/postcss-progressive-custom-properties";import{color as e,SyntaxFlag as r,serializeRGB as o,colorDataFitsRGB_Gamut as t,serializeP3 as a}from"@csstools/css-color-parser";import{hasFallback as l,hasSupportsAtRuleAncestor as i}from"@csstools/utilities";import{replaceComponentValues as c,parseCommaSeparatedListOfComponentValues as n,isFunctionNode as u,stringify as p}from"@csstools/css-parser-algorithms";import{tokenize as b}from"@csstools/css-tokenizer";const g=/\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(/i,h=/\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(\s*?from/i,m=/^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)$/i,y=/from/i,basePlugin=s=>({postcssPlugin:"postcss-relative-color-syntax",Declaration(f){const v=f.value;if(!g.test(v)||!y.test(v))return;if(l(f))return;if(i(f,h))return;const x=b({css:v}),F=c(n(x),(s=>{if(!u(s)||!m.test(s.getName()))return;const t=e(s);return t&&!t.syntaxFlags.has(r.Experimental)&&!t.syntaxFlags.has(r.HasNoneKeywords)&&t.syntaxFlags.has(r.RelativeColorSyntax)?o(t):void 0})),P=p(F);if(P===v)return;let d=P;s?.subFeatures.displayP3&&(d=p(c(n(x),(s=>{if(!u(s)||!m.test(s.getName()))return;const l=e(s);return l&&!l.syntaxFlags.has(r.Experimental)&&!l.syntaxFlags.has(r.HasNoneKeywords)&&l.syntaxFlags.has(r.RelativeColorSyntax)?t(l)?o(l):a(l):void 0})))),f.cloneBefore({value:P}),s?.subFeatures.displayP3&&d!==P&&f.cloneBefore({value:d}),s?.preserve||f.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return r.subFeatures=Object.assign({displayP3:!0},r.subFeatures),r.enableProgressiveCustomProperties&&(r.preserve||r.subFeatures.displayP3)?{postcssPlugin:"postcss-relative-color-syntax",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0;export{postcssPlugin as default}; +import s from"@csstools/postcss-progressive-custom-properties";import{color as e,SyntaxFlag as r,serializeRGB as o,colorDataFitsRGB_Gamut as t,serializeP3 as a}from"@csstools/css-color-parser";import{hasFallback as l,hasSupportsAtRuleAncestor as i}from"@csstools/utilities";import{replaceComponentValues as c,parseCommaSeparatedListOfComponentValues as n,isFunctionNode as u,stringify as p}from"@csstools/css-parser-algorithms";import{tokenize as b}from"@csstools/css-tokenizer";const g=/\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(/i,h=/\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(\s*from/i,m=/^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)$/i,y=/from/i,basePlugin=s=>({postcssPlugin:"postcss-relative-color-syntax",Declaration(f){const v=f.value;if(!g.test(v)||!y.test(v))return;if(l(f))return;if(i(f,h))return;const x=b({css:v}),F=c(n(x),(s=>{if(!u(s)||!m.test(s.getName()))return;const t=e(s);return t&&!t.syntaxFlags.has(r.Experimental)&&!t.syntaxFlags.has(r.HasNoneKeywords)&&t.syntaxFlags.has(r.RelativeColorSyntax)?o(t):void 0})),P=p(F);if(P===v)return;let d=P;s?.subFeatures.displayP3&&(d=p(c(n(x),(s=>{if(!u(s)||!m.test(s.getName()))return;const l=e(s);return l&&!l.syntaxFlags.has(r.Experimental)&&!l.syntaxFlags.has(r.HasNoneKeywords)&&l.syntaxFlags.has(r.RelativeColorSyntax)?t(l)?o(l):a(l):void 0})))),f.cloneBefore({value:P}),s?.subFeatures.displayP3&&d!==P&&f.cloneBefore({value:d}),s?.preserve||f.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return r.subFeatures=Object.assign({displayP3:!0},r.subFeatures),r.enableProgressiveCustomProperties&&(r.preserve||r.subFeatures.displayP3)?{postcssPlugin:"postcss-relative-color-syntax",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0;export{postcssPlugin as default}; diff --git a/plugins/postcss-relative-color-syntax/src/index.ts b/plugins/postcss-relative-color-syntax/src/index.ts index 914630bfe..f3a8e8df2 100644 --- a/plugins/postcss-relative-color-syntax/src/index.ts +++ b/plugins/postcss-relative-color-syntax/src/index.ts @@ -13,7 +13,7 @@ type basePluginOptions = { }; const FUNCTION_REGEX = /\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(/i; -const SUPPORTS_REGEX = /\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(\s*?from/i; +const SUPPORTS_REGEX = /\b(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)\(\s*from/i; const NAME_REGEX = /^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklch|oklab|color)$/i; const FROM_REGEX = /from/i; diff --git a/plugins/postcss-trigonometric-functions/src/index.ts b/plugins/postcss-trigonometric-functions/src/index.ts index 8e2ab39e2..a65edf74d 100644 --- a/plugins/postcss-trigonometric-functions/src/index.ts +++ b/plugins/postcss-trigonometric-functions/src/index.ts @@ -7,7 +7,7 @@ export type pluginOptions = { preserve?: boolean, }; -const FUNCTION_CALL_REGEXP = /(? = (opts?: pluginOptions) => { const options: pluginOptions = Object.assign( @@ -22,7 +22,7 @@ const creator: PluginCreator = (opts?: pluginOptions) => { return { postcssPlugin: 'postcss-trigonometric-functions', Declaration(decl): void { - if (!FUNCTION_CALL_REGEXP.test(decl.value)) { + if (!FUNCTION_CALL_REGEX.test(decl.value)) { return; }