@macu/dynamic-stylesheet-js
Version:
Dynamically render a document stylesheet
1 lines • 3.02 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DynamicStylesheet=t():e.DynamicStylesheet=t()}(self,(function(){return(()=>{"use strict";var e={497:(e,t,r)=>{function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}r.r(t),r.d(t,{addStylesheetRules:()=>i,buildStylesheetCSS:()=>s,appendStylesheet:()=>a});var o=/^\/\*(?:[^\*]|\*(?!\/))+\*\/$/;function i(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;if(!t||"object"!==n(t))return 0;var a=0,f=[],l=function(){var t=r.join("").trim();if(t){for(var n=0;n<f.length;n++){var i=f[n].trim();i&&!o.test(i)&&";"!==i.charAt(i.length-1)&&(f[n]=i+";")}(f=f.join(""))&&((e.sheet||{}).insertRule?e.sheet.insertRule(t+"{"+f+"}",s+a):(e.styleSheet||e.sheet).addRule(t,f,s+a),a++),f=[]}else f=[]};if(Array.isArray(t))for(var c=0;c<t.length;c++){var u=t[c];u&&("string"==typeof u?f.push(u):"object"===n(u)&&(l(),a+=i(e,u,r,s+a)))}else for(var y in t)if(t.hasOwnProperty(y)){var p=t[y];p&&("string"==typeof p?f.push(y+":"+p+";"):"object"===n(p)&&(l(),"&"===y.charAt(0)?y=y.substr(1):[">",":","+","~"," "].indexOf(y.charAt(0))<0&&(y=" "+y),a+=i(e,p,r.concat([y]),s+a)))}return l(),a}function s(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(!e||"object"!==n(e))return"";var r="",i=[],a=function(){var e=t.join("").trim();if(e){for(var n=[],s=0;s<i.length;s++){var a=i[s].trim();a?";"===a.charAt(a.length-1)||o.test(a)?n.push(a):n.push(a+";"):n.push("")}n.length&&(n=n.join("\n\t"),r+="\n"+e+" {\n\t"+n+"\n}")}else for(var f=0;f<i.length;f++){var l=i[f].trim();l&&!o.test(l)||(r+="\n"+l)}i=[]};if(Array.isArray(e))for(var f=0;f<e.length;f++){var l=e[f];"string"==typeof l?i.push(l):l&&"object"===n(l)&&(a(),r+=s(l,t.concat([""])))}else for(var c in e)if(e.hasOwnProperty(c)){var u=e[c];if(u)switch(n(u)){case"string":i.push(c+": "+u+";");break;case"object":a(),"&"===c.charAt(0)?c=c.substr(1):[">",":","+","~"," "].indexOf(c.charAt(0))<0&&(c=" "+c),r+=s(u,t.concat([c]));break;case"boolean":i.push(c)}}return a(),r+(t.length?"":"\n")}function a(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=document.createElement("style");return n.type="text/css",e.appendChild(n),!n.styleSheet&&!n.sheet||r?n.innerHTML=s(t):i(n,t),n}}},t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}return r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(497)})()}));