This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
import type { Node } from 'postcss';
export declare function hasSupportsAtRuleAncestor(node: Node): boolean;

View File

@@ -0,0 +1,3 @@
declare type color = [number, number, number];
export declare function hwbToRgb(hwb: color): color;
export {};

View File

@@ -0,0 +1 @@
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("postcss-value-parser"));function n(e){const t=e[0];let n=e[1],r=e[2];if(n/=100,r/=100,n+r>=1){const e=n/(n+r);return[e,e,e].map((e=>Math.round(255*e)))}const u=function(e){let t=e[0],n=e[1],r=e[2];t%=360,t<0&&(t+=360);function u(e){const u=(e+t/30)%12,o=n*Math.min(r,1-r);return r-o*Math.max(-1,Math.min(u-3,9-u,1))}return n/=100,r/=100,[u(0),u(8),u(4)]}([t,100,50]);for(let e=0;e<3;e++)u[e]*=1-n-r,u[e]+=n;return u.map((e=>Math.round(255*e)))}function r(e){const r=e.nodes.slice().filter((e=>"comment"!==e.type&&"space"!==e.type)),s=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const n=t.default.unit(e.value);if(!n)return!1;const r=n.unit.toLowerCase();return!!n.number&&("deg"===r||"grad"===r||"rad"===r||"turn"===r||""===r)}(e[0]))return null;if(!u(e[1]))return null;if(!u(e[2]))return null;const n={h:t.default.unit(e[0].value),hNode:e[0],w:t.default.unit(e[1].value),wNode:e[1],b:t.default.unit(e[2].value),bNode:e[2]};if(function(e){switch(e.unit.toLowerCase()){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=(360*parseFloat(e.number)).toString()}}(n.h),""!==n.h.unit)return null;a(n.w),a(n.b),function(e){return e&&"div"===e.type&&"/"===e.value}(e[3])&&(n.slash=e[3]);(u(e[4])||function(e){return e&&"function"===e.type&&"calc"===e.value.toLowerCase()}(e[4])||function(e){return e&&"function"===e.type&&"var"===e.value.toLowerCase()}(e[4]))&&(n.alpha=e[4]);return n}(r);if(!s)return;if(r.length>3&&(!s.slash||!s.alpha))return;e.value="rgb",function(e,n,r){if(!n||!r)return;if(e.value="rgba",n.value=",",n.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const n=t.default.unit(e.value);if(!n)return!1;return!!n.number}(r))return;const u=t.default.unit(r.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),r.value=String(u.number))}(e,s.slash,s.alpha);const[l,c,f]=[(d=s).hNode,d.wNode,d.bNode];var d;const[p,v,b]=function(e){return[e.h,e.w,e.b]}(s),h=n([p.number,v.number,b.number].map((e=>parseFloat(e))));e.nodes.splice(e.nodes.indexOf(l)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),e.nodes.splice(e.nodes.indexOf(c)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),o(e.nodes,l,{...l,value:String(h[0])}),o(e.nodes,c,{...c,value:String(h[1])}),o(e.nodes,f,{...f,value:String(h[2])})}function u(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const n=t.default.unit(e.value);return!!n&&("%"===n.unit||""===n.unit)}function o(e,t,n){const r=e.indexOf(t);e[r]=n}function a(e){if("%"!==e.unit)return e.unit="%",void(e.number=(100*parseFloat(e.number)).toString())}function i(e){if(!e||!e.value)return!1;try{return!1!==t.default.unit(e.value)}catch(e){return!1}}const s=e=>{const n="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-hwb-function",Declaration:(e,{result:u,postcss:o})=>{if(n&&function(e){let t=e.parent;for(;t;)if("atrule"===t.type){if("supports"===t.name.toLowerCase()&&-1!==t.params.toLowerCase().indexOf("(color: hwb(0% 0 0))"))return!0;t=t.parent}else t=t.parent;return!1}(e))return;const a=e.value;if(!a.toLowerCase().includes("hwb"))return;const i=function(e,n,u){let o;try{o=t.default(e)}catch(t){n.warn(u,`Failed to parse value '${e}' as a hwb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((e=>{e.type&&"function"===e.type&&"hwb"===e.value.toLowerCase()&&r(e)}));const a=String(o);if(a===e)return;return a}(a,e,u);if(void 0!==i)if(e.variable&&n){const t=e.parent,n=o.atRule({name:"supports",params:"(color: hwb(0% 0 0))",source:e.source}),r=t.clone();r.removeAll(),r.append(e.clone()),n.append(r),function(e,t,n){let r=t,u=t.next();for(;r&&u&&"atrule"===u.type&&"supports"===u.name.toLowerCase()&&u.params===n;)r=u,u=u.next();r.after(e)}(n,t,"(color: hwb(0% 0 0))"),e.replaceWith(e.clone({value:i}))}else n?e.cloneBefore({value:i}):e.replaceWith(e.clone({value:i}))}}};s.postcss=!0,module.exports=s;

View File

@@ -0,0 +1,6 @@
import type { PluginCreator } from 'postcss';
/** Transform hwb() functions in CSS. */
declare const postcssPlugin: PluginCreator<{
preserve: boolean;
}>;
export default postcssPlugin;

View File

@@ -0,0 +1 @@
import e from"postcss-value-parser";function n(e){const n=e[0];let t=e[1],r=e[2];if(t/=100,r/=100,t+r>=1){const e=t/(t+r);return[e,e,e].map((e=>Math.round(255*e)))}const u=function(e){let n=e[0],t=e[1],r=e[2];n%=360,n<0&&(n+=360);function u(e){const u=(e+n/30)%12,o=t*Math.min(r,1-r);return r-o*Math.max(-1,Math.min(u-3,9-u,1))}return t/=100,r/=100,[u(0),u(8),u(4)]}([n,100,50]);for(let e=0;e<3;e++)u[e]*=1-t-r,u[e]+=t;return u.map((e=>Math.round(255*e)))}function t(t){const i=t.nodes.slice().filter((e=>"comment"!==e.type&&"space"!==e.type)),s=function(n){if(!function(n){if(!n||"word"!==n.type)return!1;if(!a(n))return!1;const t=e.unit(n.value);if(!t)return!1;const r=t.unit.toLowerCase();return!!t.number&&("deg"===r||"grad"===r||"rad"===r||"turn"===r||""===r)}(n[0]))return null;if(!r(n[1]))return null;if(!r(n[2]))return null;const t={h:e.unit(n[0].value),hNode:n[0],w:e.unit(n[1].value),wNode:n[1],b:e.unit(n[2].value),bNode:n[2]};if(function(e){switch(e.unit.toLowerCase()){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=(360*parseFloat(e.number)).toString()}}(t.h),""!==t.h.unit)return null;o(t.w),o(t.b),function(e){return e&&"div"===e.type&&"/"===e.value}(n[3])&&(t.slash=n[3]);(r(n[4])||function(e){return e&&"function"===e.type&&"calc"===e.value.toLowerCase()}(n[4])||function(e){return e&&"function"===e.type&&"var"===e.value.toLowerCase()}(n[4]))&&(t.alpha=n[4]);return t}(i);if(!s)return;if(i.length>3&&(!s.slash||!s.alpha))return;t.value="rgb",function(n,t,r){if(!t||!r)return;if(n.value="rgba",t.value=",",t.before="",!function(n){if(!n||"word"!==n.type)return!1;if(!a(n))return!1;const t=e.unit(n.value);if(!t)return!1;return!!t.number}(r))return;const u=e.unit(r.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),r.value=String(u.number))}(t,s.slash,s.alpha);const[l,c,f]=[(p=s).hNode,p.wNode,p.bNode];var p;const[d,v,b]=function(e){return[e.h,e.w,e.b]}(s),m=n([d.number,v.number,b.number].map((e=>parseFloat(e))));t.nodes.splice(t.nodes.indexOf(l)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),t.nodes.splice(t.nodes.indexOf(c)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),u(t.nodes,l,{...l,value:String(m[0])}),u(t.nodes,c,{...c,value:String(m[1])}),u(t.nodes,f,{...f,value:String(m[2])})}function r(n){if(!n||"word"!==n.type)return!1;if(!a(n))return!1;const t=e.unit(n.value);return!!t&&("%"===t.unit||""===t.unit)}function u(e,n,t){const r=e.indexOf(n);e[r]=t}function o(e){if("%"!==e.unit)return e.unit="%",void(e.number=(100*parseFloat(e.number)).toString())}function a(n){if(!n||!n.value)return!1;try{return!1!==e.unit(n.value)}catch(e){return!1}}const i=n=>{const r="preserve"in Object(n)&&Boolean(n.preserve);return{postcssPlugin:"postcss-hwb-function",Declaration:(n,{result:u,postcss:o})=>{if(r&&function(e){let n=e.parent;for(;n;)if("atrule"===n.type){if("supports"===n.name.toLowerCase()&&-1!==n.params.toLowerCase().indexOf("(color: hwb(0% 0 0))"))return!0;n=n.parent}else n=n.parent;return!1}(n))return;const a=n.value;if(!a.toLowerCase().includes("hwb"))return;const i=function(n,r,u){let o;try{o=e(n)}catch(e){r.warn(u,`Failed to parse value '${n}' as a hwb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((e=>{e.type&&"function"===e.type&&"hwb"===e.value.toLowerCase()&&t(e)}));const a=String(o);if(a===n)return;return a}(a,n,u);if(void 0!==i)if(n.variable&&r){const e=n.parent,t=o.atRule({name:"supports",params:"(color: hwb(0% 0 0))",source:n.source}),r=e.clone();r.removeAll(),r.append(n.clone()),t.append(r),function(e,n,t){let r=n,u=n.next();for(;r&&u&&"atrule"===u.type&&"supports"===u.name.toLowerCase()&&u.params===t;)r=u,u=u.next();r.after(e)}(t,e,"(color: hwb(0% 0 0))"),n.replaceWith(n.clone({value:i}))}else r?n.cloneBefore({value:i}):n.replaceWith(n.clone({value:i}))}}};i.postcss=!0;export{i as default};

View File

@@ -0,0 +1,2 @@
import type { FunctionNode } from 'postcss-value-parser';
export declare function onCSSFunctionSRgb(node: FunctionNode): void;