css-gradient-parser
Advanced tools
Comparing version
@@ -15,2 +15,15 @@ interface LinearOrientation { | ||
export { LinearResult, parseLinearGradient }; | ||
type RgExtentKeyword = 'closest-corner' | 'closest-side' | 'farthest-corner' | 'farthest-side'; | ||
interface RadiusResult { | ||
shape: 'circle' | 'ellipse'; | ||
size: string; | ||
position: string; | ||
stops: Array<{ | ||
color: string; | ||
offset: string; | ||
hint?: string; | ||
}>; | ||
} | ||
declare function parseRadialGradient(input: string): RadiusResult; | ||
export { LinearResult, RadiusResult, RgExtentKeyword, parseLinearGradient, parseRadialGradient }; |
@@ -1,2 +0,2 @@ | ||
var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var c=(t,e)=>{for(var r in e)o(t,r,{get:e[r],enumerable:!0})},g=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of u(e))!f.call(t,n)&&n!==r&&o(t,n,{get:()=>e[n],enumerable:!(i=p(e,n))||i.enumerable});return t};var h=t=>g(o({},"__esModule",{value:!0}),t);var L={};c(L,{parseLinearGradient:()=>m});module.exports=h(L);function a(t,e=","){let r=[],i=0,n=0;e=new RegExp(e);for(let s=0;s<t.length;s++)t[s]==="("?n++:t[s]===")"&&n--,n===0&&e.test(t[s])&&(r.push(t.slice(i,s).trim()),i=s+1);return r.push(t.slice(i).trim()),r}function l(t){let e=[];for(let r=0,i=t.length;r<i;){let[n,s]=a(t[r],/\s+/);d(t[r+1])?(e.push({color:n,offset:s,hint:t[r+1]}),r+=2):(e.push({color:n,offset:s}),r++)}return e}function d(t){return/^\d+\.?\d*(%|vw|vh|px|em|rem)?$/.test(t)}function m(t){if(!t.startsWith("linear-gradient("))throw new SyntaxError(`unsupported input: ${t}`);let[,e]=t.match(/linear-gradient\((.+)\)/),r={orientation:{type:"directional",value:"bottom"},stops:[]},i=a(e),n=x(i[0]);return n&&(r.orientation=n,i.shift()),{...r,stops:l(i)}}function x(t){return t.startsWith("to ")?{type:"directional",value:t.replace("to ","")}:["turn","deg"].some(e=>t.endsWith(e))?{type:"angular",value:t}:null}0&&(module.exports={parseLinearGradient}); | ||
var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},m=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of h(e))!g.call(t,s)&&s!==r&&l(t,s,{get:()=>e[s],enumerable:!(i=u(e,s))||i.enumerable});return t};var x=t=>m(l({},"__esModule",{value:!0}),t);var b={};d(b,{parseLinearGradient:()=>y,parseRadialGradient:()=>w});module.exports=x(b);function o(t,e=","){let r=[],i=0,s=0;e=new RegExp(e);for(let n=0;n<t.length;n++)t[n]==="("?s++:t[n]===")"&&s--,s===0&&e.test(t[n])&&(r.push(t.slice(i,n).trim()),i=n+1);return r.push(t.slice(i).trim()),r}function a(t){let e=[];for(let r=0,i=t.length;r<i;){let[s,n]=o(t[r],/\s+/);R(t[r+1])?(e.push({color:s,offset:n,hint:t[r+1]}),r+=2):(e.push({color:s,offset:n}),r++)}return e}function R(t){return/^\d+\.?\d*(%|vw|vh|px|em|rem)?$/.test(t)}function y(t){if(!t.startsWith("linear-gradient("))throw new SyntaxError(`unsupported input: ${t}`);let[,e]=t.match(/linear-gradient\((.+)\)/),r={orientation:{type:"directional",value:"bottom"},stops:[]},i=o(e),s=v(i[0]);return s&&(r.orientation=s,i.shift()),{...r,stops:a(i)}}function v(t){return t.startsWith("to ")?{type:"directional",value:t.replace("to ","")}:["turn","deg"].some(e=>t.endsWith(e))?{type:"angular",value:t}:null}function w(t){if(!t.startsWith("radial-gradient("))throw new SyntaxError(`unsupported input: ${t}`);let e={shape:"ellipse",size:"farthest-corner",position:"center",stops:[]},[,r]=t.match(/radial-gradient\((.+)\)/),i=o(r);if(L(i[0]))return{...e,stops:a(i)};let s=i[0].split("at").map(f=>f.trim()),n=((s[0]||"").match(/(circle|ellipse)/)||[])[1],p=((s[0]||"").match(/(\d+\.?\d*(vw|vh|px|em|rem)?|closest-corner|closest-side|farthest-corner|farthest-side)/)||[])[1],c=s[1];return(n||p||c)&&(i.shift(),Object.assign(e,{shape:n||"ellipse",size:p||"farthest-corner",position:c||"center"})),{...e,stops:a(i)}}function L(t){return/^rgba?|hwb|hsl|lab|lch|oklab|color|#/.test(t)}0&&(module.exports={parseLinearGradient,parseRadialGradient}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "css-gradient-parser", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "a css gradient parser", | ||
@@ -5,0 +5,0 @@ "packageManager": "pnpm@8.7.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21867
50.29%42
75%