You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
3.8 KiB
1 lines
3.8 KiB
import n from"postcss-value-parser";function e(n){const e=n[0];let t=n[1],r=n[2];if(t/=100,r/=100,t+r>=1){const n=t/(t+r);return[n,n,n].map((n=>Math.round(255*n)))}const u=function(n){let e=n[0],t=n[1],r=n[2];e%=360,e<0&&(e+=360);function u(n){const u=(n+e/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)]}([e,100,50]);for(let n=0;n<3;n++)u[n]*=1-t-r,u[n]+=t;return u.map((n=>Math.round(255*n)))}function t(t){const a=t.nodes.slice().filter((n=>"comment"!==n.type&&"space"!==n.type)),s=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const t=n.unit(e.value);if(!t)return!1;return!!t.number&&("deg"===t.unit||"grad"===t.unit||"rad"===t.unit||"turn"===t.unit||""===t.unit)}(e[0]))return null;if(!r(e[1]))return null;if(!r(e[2]))return null;const t={h:n.unit(e[0].value),hNode:e[0],w:n.unit(e[1].value),wNode:e[1],b:n.unit(e[2].value),bNode:e[2]};if(function(n){switch(n.unit){case"deg":return void(n.unit="");case"rad":return n.unit="",void(n.number=(180*parseFloat(n.number)/Math.PI).toString());case"grad":return n.unit="",void(n.number=(.9*parseFloat(n.number)).toString());case"turn":n.unit="",n.number=(360*parseFloat(n.number)).toString()}}(t.h),""!==t.h.unit)return null;o(t.w),o(t.b),function(n){return n&&"div"===n.type&&"/"===n.value}(e[3])&&(t.slash=e[3]);(r(e[4])||function(n){return n&&"function"===n.type&&"calc"===n.value}(e[4])||function(n){return n&&"function"===n.type&&"var"===n.value}(e[4]))&&(t.alpha=e[4]);return t}(a);if(!s)return;if(a.length>3&&(!s.slash||!s.alpha))return;t.value="rgb",function(e,t,r){if(!t||!r)return;if(e.value="rgba",t.value=",",t.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const t=n.unit(e.value);if(!t)return!1;return!!t.number}(r))return;const u=n.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(n){return[n.h,n.w,n.b]}(s),m=e([d.number,v.number,b.number].map((n=>parseFloat(n))));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(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const t=n.unit(e.value);return!!t&&("%"===t.unit||""===t.unit)}function u(n,e,t){const r=n.indexOf(e);n[r]=t}function o(n){if("%"!==n.unit)return n.unit="%",void(n.number=(100*parseFloat(n.number)).toString())}function i(e){if(!e||!e.value)return!1;try{return!1!==n.unit(e.value)}catch(n){return!1}}const a=e=>{const r="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-hwb-function",Declaration:(e,{result:u,postcss:o})=>{if(r&&function(n){let e=n.parent;for(;e;)if("atrule"===e.type){if("supports"===e.name&&-1!==e.params.indexOf("(color: hwb(0% 0 0))"))return!0;e=e.parent}else e=e.parent;return!1}(e))return;const i=e.value;if(!i.includes("hwb"))return;const a=function(e,r,u){let o;try{o=n(e)}catch(n){r.warn(u,`Failed to parse value '${e}' as a hwb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((n=>{n.type&&"function"===n.type&&"hwb"===n.value&&t(n)}));const i=String(o);if(i===e)return;return i}(i,e,u);if(void 0!==a)if(e.variable&&r){const n=e.parent,t=o.atRule({name:"supports",params:"(color: hwb(0% 0 0))",source:e.source}),r=n.clone();r.removeAll(),r.append(e.clone()),t.append(r),function(n,e,t){let r=e,u=e.next();for(;r&&u&&"atrule"===u.type&&"supports"===u.name&&u.params===t;)r=u,u=u.next();r.after(n)}(t,n,"(color: hwb(0% 0 0))"),e.value=a}else r?e.cloneBefore({value:a}):e.value=a}}};a.postcss=!0;export{a as default};
|
|
|