-
Notifications
You must be signed in to change notification settings - Fork 0
/
jss.min.js
1 lines (1 loc) · 4.89 KB
/
jss.min.js
1
!function(){function e(e){for(var t=e.cssRules||e.rules||[],r={},n=0;n<t.length;n++)if("undefined"!=typeof t[n].selectorText){var s=i(t[n].selectorText);r[s]||(r[s]=[]),r[s].push({sheet:e,index:n,style:t[n].style})}return r}function t(e,t){var r=e.cssRules||e.rules||[],n=[];t=t.toLowerCase();for(var s=0;s<r.length;s++){var o=r[s].selectorText;"undefined"!=typeof o&&(!o||o!==t&&o!==v(t)&&o!==p(t)||n.push({sheet:e,index:s,style:r[s].style}))}return n}function r(e){for(var t=e.cssRules||e.rules||[],r=[],n=0;n<t.length;n++)r.push(t[n].cssText);return r.join("\n")}function n(e,t){var r=e.cssRules||e.rules||[],n=r.length,i=o(e,t,r,n);return i||s(e,t,n),{sheet:e,index:n,style:r[n].style}}function s(e,t,r){e.insertRule?e.insertRule(t+" { }",r):e.addRule(t,null,r)}function o(e,t,r,n){var o,l;if(k.exec(t))o=t,l=u(t);else{if(!j.exec(t))return!1;o=i(t),l=t}return w||(s(e,o,n),r.length<=n&&(w=!0)),w&&s(e,l,n),!0}function i(e){return e.replace(j,function(e,t,r,n){return t+"::"+n})}function u(e){return e.replace(k,function(e,t,r){return":"+r})}function l(e){var t=e.sheet;t.deleteRule?t.deleteRule(e.index):t.removeRule&&t.removeRule(e.index)}function h(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e}function f(e,t,r,n){return e===r&&n===t&&e===t?[e]:e===r&&n===t?[e,t]:n===t?[e,t,r]:[e,t,r,n]}function a(e,t){var r,n,s,o,i=t.indexOf("-");return r=e[t.substring(0,i)+"-top"+t.substr(i)],n=e[t.substring(0,i)+"-bottom"+t.substr(i)],s=e[t.substring(0,i)+"-left"+t.substr(i)],o=e[t.substring(0,i)+"-right"+t.substr(i)],f(r,n,s,o)}function d(e,t){var r,n,s,o,i,u,l,h=e[t];switch(t){case"margin":case"padding":r=e[t+"-top"],n=e[t+"-bottom"],s=e[t+"-left"],o=e[t+"-right"],h=f(r,o,n,s).join(" ");break;case"border":i=a(e,"border-width"),u=a(e,"border-style"),l=a(e,"border-color"),1===l.length&&1===u.length&&1===i.length?h=i[0]+" "+u[0]+" "+l[0]:1===i.length&&1===u.length?h=i[0]+" "+u[0]:1===i.length&&(h=i[0]);break;case"border-top":case"border-left":case"border-right":case"border-bottom":i=e[t+"-width"],u=e[t+"-style"],l=e[t+"-color"],i&&l&&u?h=i+" "+u+" "+l:i&&u?h=i+" "+u:i&&(h=i);break;case"border-width":case"border-style":case"border-color":h=a(e,t).join(" ");break;case"border-radius":break;case"background":break;case"font":break;case"transition":break;default:h=e[t]}return h}function c(e){for(var t={},r=0;r<e.length;r++)h(t,g(e[r].style));return t}function g(e){for(var t={},r=0;r<e.length;r++)t[e[r]]=e[y(e[r])];return t}function v(e){for(var t,r="",n=0;null!==(t=R.exec(e))&&""!==t[0];)r+=e.substring(n,t.index),r+=e.substr(t.index+t[1].length,t[2].length),r+=e.substr(t.index,t[1].length),n=t.index+t[0].length;return r+=e.substr(n)}function p(e){return k.exec(e)?u(e):e}function b(e,t){for(var r in t){var n=t[r],s=n.indexOf(" !important");e.style.removeProperty(r),s>0?e.style.setProperty(r,n.substr(0,s),"important"):e.style.setProperty(r,n)}}function y(e){return e.replace(/-([a-z])/g,function(e,t){return t.toUpperCase()})}function x(e){var t={};for(var r in e)t[m(r)]=e[r];return t}function m(e){return e.replace(/([A-Z])/g,function(e,t){return"-"+t.toLowerCase()})}function S(e){return e=e||document,new P(e)}var w,R=/((?:\.|#)[^\.\s#]+)((?:\.|#)[^\.\s#]+)/g,k=/(::)(before|after|first-line|first-letter|selection)/,j=/([^:])(:)(before|after|first-line|first-letter|selection)/,P=function(e){this.doc=e,this.head=this.doc.head||this.doc.getElementsByTagName("head")[0],this.sheets=this.doc.styleSheets||[]};P.prototype={get:function(r){if(this.defaultSheet=this._getDefaultSheet(),r)return c(t(this.defaultSheet,r));var n=e(this.defaultSheet);for(r in n)n[r]=c(n[r]);return n},getAll:function(e){for(var r={},n=0;n<this.sheets.length;n++)h(r,c(t(this.sheets[n],e)));return r},getProperty:function(e,t){return d(this.getAll(e),t)},exportSheets:function(){for(var e=[],t=0;t<this.sheets.length;t++){var n=this.sheets[t],s={url:n.href,node_id:n.ownerNode.id,text:r(n)};e.push(s)}return e},set:function(e,r){this.defaultSheet=this._getDefaultSheet(),r=x(r);var s=t(this.defaultSheet,e);s.length||(s=[n(this.defaultSheet,e)]);for(var o=0;o<s.length;o++)b(s[o],r)},setProperty:function(e,t,r){var n={};n[t]=r,this.set(e,n)},remove:function(e){if(this.defaultSheet=this._getDefaultSheet(),!e)return this._removeSheet(this.defaultSheet),void delete this.defaultSheet;for(var r=t(this.defaultSheet,e),n=0;n<r.length;n++)l(r[n]);return r.length},removeProperty:function(e,r){for(var n=0;n<this.sheets.length;n++){var s=t(this.sheets[n],e);s.length>0&&(s[0].style[r]="")}},_getDefaultSheet:function(){var e=this.doc.getElementById("jss-generated-styles");return null===e&&(e=this.doc.createElement("style"),e.type="text/css",e.rel="stylesheet",e.id="jss-generated-styles",this.head.appendChild(e)),e.sheet},_removeSheet:function(e){var t=e.ownerNode;t.parentNode.removeChild(t)}},"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=S),exports.jss=S):"function"==typeof define&&define.amd?define("jss",function(){return S}):window.jss=S}();