UNPKG

inline-style-parser

Version:
3 lines (2 loc) 1.8 kB
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(n="undefined"!=typeof globalThis?globalThis:n||self).InlineStyleParser=r()}(this,(function(){"use strict";var n=/\/\*(?:[^*]|\*(?!\/))*\*\//g,r=/\n/g,e=/^\s*/,t=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,o=/^((?:'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|url\((?:'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|[^)]*)\)|[^};])+)/,u=/^[;\s]*/;return function(c,f){if("string"!=typeof c)throw new TypeError("First argument must be a string");if(!c)return[];f=f||{};var s=1,a=1;function l(n){var e=n.match(r);e&&(s+=e.length);var t=n.lastIndexOf("\n");a=~t?n.length-t:a+n.length}function h(){var n={line:s,column:a};return function(r){return r.position=new p(n),d(),r}}function p(n){this.start=n,this.end={line:s,column:a},this.source=f.source}function m(n){var r=new Error(f.source+":"+s+":"+a+": "+n);if(r.reason=n,r.filename=f.source,r.line=s,r.column=a,r.source=c,!f.silent)throw r}function v(n){var r=n.exec(c);if(r){var e=r[0];return l(e),c=c.slice(e.length),r}}function d(){v(e)}function g(n){for(var r;r=y();)n.push(r);return n}function y(){var n=h();if("/"==c.charAt(0)&&"*"==c.charAt(1)){for(var r=2;""!=c.charAt(r)&&("*"!=c.charAt(r)||"/"!=c.charAt(r+1));)++r;if(r+=2,""===c.charAt(r-1))return m("End of comment missing");var e=c.slice(2,r-2);return a+=2,l(e),c=c.slice(r),a+=2,n({type:"comment",comment:e})}}function w(){var r=h(),e=v(t);if(e){if(y(),!v(i))return m("property missing ':'");var c=v(o),f=r({type:"declaration",property:e[0].replace(n,"").trim(),value:c?c[0].replace(n,"").trim():""});return v(u),f}}return p.prototype.content=c,d(),function(){var n,r=[];for(g(r);n=w();)r.push(n),g(r);return r}()}})); //# sourceMappingURL=inline-style-parser.min.js.map