webpack-theme-color-replacer
Version:
A webpack plugin designed to dynamicly change the theme colors at runtime. 实现运行时快速动态替换主题色的webpack插件.
1 lines • 4.18 kB
JavaScript
var tcrClient=function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=1)}([function(e,n){function t(e){var n=e.toString(16);return 1===n.length&&(n="0"+n),n}function r(e,n,r,o,c){e=i(e),n=i(n),void 0===r&&(r=.5),void 0===o&&(o=1),void 0===c&&(c=1);var a=2*r-1,f=o-c,s=((a*f==-1?a:(a+f)/(1+a*f))+1)/2,l=1-s,d=u(e),p=u(n),g=Math.round(s*d[0]+l*p[0]),h=Math.round(s*d[1]+l*p[1]),v=Math.round(s*d[2]+l*p[2]);return"#"+t(g)+t(h)+t(v)}function o(e,n,t){return r(e,t||"fff",.5,n,1-n)}function u(e){return 3===(e=i(e)).length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}function i(e){return e.replace("#","")}function c(e,n,t){var r=e/255,o=n/255,u=t/255,i=Math.max(r,o,u),c=Math.min(r,o,u),a=i-c,f=(i+c)/2,s=0,l=0;if(Math.abs(a)>1e-5){l=f<=.5?a/(i+c):a/(2-i-c);var d=(i-r)/a,p=(i-o)/a,g=(i-u)/a;s=r==i?g-p:o==i?2+d-g:4+p-d,(s*=60)<0&&(s+=360)}return[s,l,f]}e.exports={lighten:function(e,n){return r("fff",e,n)},darken:function(e,n){return r("000",e,n)},mix:r,toNum3:u,rgb:o,rgbaToRgb:o,pad2:t,rgbToHsl:c,rrggbbToHsl:function(e){var n=u(e),t=c.apply(0,n);return[t[0].toFixed(0),(100*t[1]).toFixed(3)+"%",(100*t[2]).toFixed(3)+"%"].join(",")}}},function(e,n,t){var r=t(2),o=t(0),u=t(4);e.exports={changer:r,varyColor:o,getElementUISeries:u}},function(e,n,t){(function(n){var t,r={};function o(){return"undefined"==typeof window?n:window}e.exports={_tryNum:0,changeColor:function(e,n){var u=n||o().Promise,i=this;if(!t){t=o()._themeCfg;var c=function(){if(!t){if(i._tryNum<9)return i._tryNum=i._tryNum+1,new u((function(t,r){setTimeout((function(){t(i.changeColor(e,n))}),100)}));t={}}}();if(c)return c}var a=e.oldColors||t.colors||[],f=e.newColors||[],s=t.url||e.cssUrl;return e.changeUrl&&(s=e.changeUrl(s)),new u((function(n,t){var o=r[s];o&&(a=o.colors),function(e,n){if(e.length!==n.length)return!1;for(var t=0,r=e.length;t<r;t++)if(e[t]!==n[t])return!1;return!0}(a,f)?n():function(n,t,o,u){var c=n&&document.getElementById(n.id);if(c&&n.colors)l(c.innerText),n.colors=f,o();else{var s="css_"+ +new Date;(c=document.querySelector(e.appendToEl||"body").appendChild(document.createElement("style"))).setAttribute("id",s),i.getCssString(t,(function(e){l(e),r[t]={id:s,colors:f},o()}),u)}function l(e){e=i.replaceCssText(e,a,f),c.innerText=e}}(o,s,n,t)}))},replaceCssText:function(e,n,t){return n.forEach((function(n,r){var o=new RegExp(n.replace(/\s/g,"").replace(/,/g,",\\s*")+"([\\da-f]{2})?(\\b|\\)|,|\\s)","ig");e=e.replace(o,t[r]+"$1$2")})),e},getCssString:function(e,n,r){var o=t.cssCode;if(o)return t.cssCode="",void n(o);var u=new XMLHttpRequest;u.onreadystatechange=function(){4===u.readyState&&(200===u.status?n(u.responseText):r(u.status))},u.onerror=function(e){r(e)},u.ontimeout=function(e){r(e)},u.open("GET",e),u.send()}}}).call(this,t(3))},function(e,n){var t;t=function(){return this}();try{t=t||new Function("return this")()}catch(e){"object"==typeof window&&(t=window)}e.exports=t},function(e,n,t){var r=t(0);e.exports=function(e,n){"#"===e[0]&&(e=e.slice(1));for(var t=["#"+e,r.toNum3(e).join(",")],o=1;o<=9;o++)t.push(r.lighten(e,Number((o/10).toFixed(2)))),t.push(r.darken(e,Number((o/10).toFixed(2))));return t.push(r.lighten(e,.925)),t.push(r.lighten(e,.95)),t.push(r.lighten(e,.975)),t.push(r.rrggbbToHsl(e)),[].push.apply(t,n),t}}]);