UNPKG

style-to-object

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