var Theming={__namespace:true};Theming_module_def();function Theming_module_def(){Theming.ApplyThemeToCss=tb;Theming.ReplaceCssTextForElement=J;Theming.ThemeInfo=E;Theming.ImageProcessor=R;Theming.Colors={Color:a,ColorApplication:x,HslColor:h};function cb(d,c,e){for(var b=true,a=0;aa){i=new d(c.font_family,b.substring(g,e));if(k)a=e}break}else if(g===-1&&/\S/.test(h))break}return i}function v(){var h,n=0,j=null;g=a;a:for(;;a++){e=b.charAt(a);if(!Boolean(e))break a;var i;while((i=r[e])===undefined&&a=0&&d<=b))throw new Error("Argument must be a Number in [0, 255]");var a=c.toString(16);if(c<16)a="0"+a;return a}function A(a,c){return a.Ab||e<0)e=b}d[3]=e;return r.apply(null,d)}a.FromHtmlColor=q;function q(c){function d(a,b,c){return parseInt(a.charAt(b)+a.charAt(c),16)}var a=[NaN,NaN,NaN,b];if(typeof c==="string"&&c.charAt(0)==="#")switch(c.length){case 9:a[3]=d(c,1,2);a[0]=d(c,3,4);a[1]=d(c,5,6);a[2]=d(c,7,8);break;case 7:a[0]=d(c,1,2);a[1]=d(c,3,4);a[2]=d(c,5,6);break;case 4:a[0]=d(c,1,1);a[1]=d(c,2,2);a[2]=d(c,3,3)}var e=null;if(isNaN(a[0])||isNaN(a[1])||isNaN(a[2])||isNaN(a[3]))f("Theming: Invalid HTML color: "+String(c));else e=r.apply(null,a);return e}var u={};function ib(b){var c=a.Black;if(u.hasOwnProperty(b))c=u[b];else if(o()){var d=document.createElement("canvas");d.width=d.height="1";var e=d.getContext("2d");e.fillStyle=b;e.fillRect(0,0,1,1);c=u[b]=r.apply(null,e.getImageData(0,0,1,1).data)}return c}function L(a){return typeof a=="number"&&a>=0&&a<=1}function t(a){return Math.min(1,Math.max(0,a))}function j(c){var a=Math.round(b*c);return Math.min(b,Math.max(0,a))}function h(d,c,b,e){if(d!==-1)d=t(d);c=t(c);b=t(b);this.Lighten=function(a){if(!L(a)){f("Lighten: factor must be in [0,1]");return}b=b*a+(1-a)};this.Darken=function(a){if(!L(a)){f("Darken: factor must be in [0,1]");return}b=b*a};this.getHue=function(){return d};this.getSaturation=function(){return c};this.getLuminance=function(){return b};this.setLuminance=function(a){b=a};this.ToRgbaColor=function(){var k,i,h;if(Math.round(c*1e4)===0)k=i=h=j(b);else{var g,f;if(b<=.5)f=b*(1+c);else f=b+c-b*c;g=2*b-f;k=v(g,f,d+1/3);i=v(g,f,d);h=v(g,f,d-1/3)}return new a(k,i,h,e)}}function v(c,d,a){var b;if(a<0)a+=1;if(a>1)a-=1;if(a<1/6)b=c+(d-c)*a*6;else if(a<1/2)b=d;else if(a<2/3)b=c+(d-c)*(2/3-a)*6;else b=c;return j(b)}h.FromRgba=function(f){var k=b,a=0,e=0,p=0,j=f.R,i=f.G,l=f.B,c=Math.max(Math.max(j,i),l),g=Math.min(Math.min(j,i),l),q=c+g;p=q/(2*k);if(c===g){e=0;a=-1}else{var d=c-g,r=c+g;if(q<=1*k)e=d/r;else e=d/(2*k-r);var o=(c-j)*(1/6)/d,n=(c-i)*(1/6)/d,m=(c-l)*(1/6)/d;if(j===c)a=m-n;else if(i===c)a=1/3+o-m;else a=2/3+n-o;if(a<0)a+=1;if(a>1)a-=1}return new h(a,e,p,f.A)};var g={color:c.color,gradient:c.string,rgb:c.rgb,rgba:c.rgba};D.prototype={str:"#000000",type:g.color,color:void 0,getColor:function(){if(this.color===void 0)if(this.type===g.color||this.type===g.gradient)this.color=q(this.str);else this.color=Z(this.str,this.type===g.rgba);return this.color}};function D(){}function mb(c,b){var a=new D;a.str=c;a.type=b;return a}function nb(b){var a=new D;a.color=b;return a}var ob=["Coral","Rose","LightOrange","Tan","Tan","LightYellow","LightYellow","Tan","LightGreen","Lime","LightGreen","LightGreen","Aqua","SkyBlue","LightTurquoise","PaleBlue","LightBlue","IceBlue","Periwinkle","Lavender","Pink","Tan","Rose"],P=["Coral","Red","Orange","Brown","Tan","Gold","Yellow","OliveGreen","OliveGreen","Green","Green","BrightGreen","Teal","Aqua","Turquoise","PaleBlue","Blue","BlueGray","Indigo","Purple","Pink","Brown","Red"],qb=["Brown","DarkRed","Brown","Brown","Brown","DarkYellow","DarkYellow","Brown","DarkGreen","DarkGreen","DarkGreen","DarkGreen","DarkTeal","DarkTeal","DarkTeal","DarkBlue","DarkBlue","BlueGray","Indigo","DarkPurple","Plum","Brown","DarkRed"],X=[[8,0,0,44,0,0,0,63,0,0,122,0,134,0,0,0,0,166,176,241,0,256,0],[0,10,0,32,46,0,0,0,61,0,106,0,136,144,0,0,0,158,166,241,0,0,256],[0,8,0,0,39,46,0,0,0,71,120,0,131,144,0,0,163,0,177,211,249,0,256],[0,11,26,0,0,38,45,0,0,56,100,121,129,0,140,0,180,0,0,224,241,0,256],[0,13,27,0,0,36,45,0,0,59,118,0,127,136,142,0,185,0,0,216,239,0,256]],N=[75,115,150,240],H=[[130,100,115,100,100,100,110,75,100,90,100,100,100,100,80,100,100,100,100,100,100,100,100],[170,170,170,155,170,170,170,170,170,115,170,170,170,170,170,170,170,170,150,150,170,140,165]];function fb(l,g){function a(b){var a=g[b];if(!Boolean(a))a=b;return a}var e=h.FromRgba(l),c=j(e.getLuminance()),f=j(e.getSaturation()),m=j(e.getHue());if(c>240)return a("White");else if(c<20)return a("Black");if(f<=20)return c>170?a("Gray25"):c>100?a("Gray50"):a("Gray80");for(var k=N.length,d=0;dH[1][b]?a(ob[b]):c=b&&a<=e&&d>=c&&d<=f}return d}var t=!O(b.excludeRectangle)?x(b.excludeRectangle):null,g=a.Black,j,o;if(Boolean(b.themeColor)){var z=n[b.method],s=p.GetColorForApplication({themeColor:b.themeColor});if(s==null){f("Cannot find theme color: "+b.themeColor);return}o=function(){return kb(g,s,z)}}else{var e=eb(b,p),k=db(b,p);if(e==null||k==null){f("Theming: Missing attributes in RecolorImage: "+JSON.stringify(b));return}var E=e.R<<16,C=e.G<<16,A=e.B<<16,F=k.R-e.R<<8,D=k.G-e.G<<8,B=k.B-e.B<<8;o=function(){var b=h.FromRgba(g).getLuminance();return new a(Math.max(E+F*b>>16,0),Math.max(C+D*b>>16,0),Math.max(A+B*b>>16,0))}}for(var c=0,m=q;mb+1){a=a.substring(0,d);if(b>0){var c=a.indexOf("/",b+2);if(c<0)c=a.length;e=a.substring(0,c)}}else a=null;return f;function f(b){var c=b;if(a!=null&&Boolean(b)&&b!=="none"&&b!=="inherit"&&b.indexOf("://")<0){var d=b.charAt(0)==="/"?e:a;c=M(d,b)}return c}}function f(a){typeof window.console!="undefined"&&typeof window.console.log!="undefined"&&window.console.log(a)}function W(){var a=0;this.getNext=function(){return a++}}function k(b){var c={"'":"%27",'"':"%22","(":"%28",")":"%29"},a=null;if(b!=null)a=b.replace(/(['"\(\)])/gm,function(b,a){return c[a]});return a}function I(a){if(Boolean(a)){var b=a.charAt(0);if((b==="'"||b==='"')&&b===a.charAt(a.length-1))a=decodeURI(a.slice(1,-1))}return a}function Q(d,a){var b;if(a==null)a=0;return c;function c(c){clearTimeout(b);if(!Boolean(c))b=setTimeout(d,a)}}function vb(d,c,b){var a=new XMLHttpRequest;a.onreadystatechange=function(){if(a==null||a.readyState!=4)return;if(a.status==200)c(a.responseText);else Boolean(b)&&b(a.status);a=null};try{a.open("GET",d,true);a.send("")}catch(e){Boolean(b)&&b(-1)}}function y(){var a=[];this.clear=b;this.execute=c;this.push=d;function b(){a=[]}function c(){var d=a;b();for(var g=d.length,c=0;c0&&e<=1,l=g>0&&g<=1;if(Boolean(b.IsInverted)){e=1-e;g=1-g}if(k||l){var j=h.FromRgba(c);k&&j.Darken(e);l&&j.Lighten(g);c=j.ToRgbaColor()}var i=Number(d.opacity);if(i>=0){if(i>1){f("Opacity in CSS theming annotation was out of range. Opacity must be between 0 and 1.");i=1}c=new a(c.R,c.G,c.B,Math.floor(255*i))}return c}function p(c){var a=d[c];if(a==null){a=j[c];if(a==null){var b=c.split("-");if(b.length>1){a=l(b[0],b[1]);if(a==null)a=l("Content"+b[0],b[1]);j[c]=a}}}return a}function l(j,k){var f=d[j],g=r(k);if(f==null||g==0)return f;var e=g-1,b=h.FromRgba(f),i=b.getLuminance();if(a.Equals(f,a.White))b.Darken(x[e]);else if(a.Equals(f,a.Black))b.Lighten(y[e]);else if(iw)b.Darken(B[e]);else if(e1){b=d[1];a.setAttribute(c,b);a.setAttribute("data-ThemeSrc",d[0])}}if(b!=null)Fb.RegisterImage(a,b);else a.setAttribute(c,f)}}ib(a);l&&q()}function yb(b,d){var a=b.getAttribute(u);if(!Boolean(a)){a=Bb.getNext().toString(10);b.setAttribute(u,a)}if(!g.contains(a)){var c=new H(b,d);g.set(a,c);!L(c)&&q()}}function zb(b,d){function c(a){b.SetNewCss(a);d!=null&&d()}if(!Boolean(b.text))return;var f=b.replaceNode;if(r()){c(b.text);return}b.PrepareForTheming(e(),true);b.themableCss.ApplyTheme(c,a)}function gb(d){var c;if(b.contains(d)){var a=b.get(d);if(a!=null)c=a._newCss==null?a.text:a._newCss}return c}t.prototype.cssRules=null;t.prototype.cssText="";t.prototype.rules=null;function t(e,d,c,a){var b=hb(O(a));this.cssRules=this.rules=b;this.cssText=c;this.disabled=false;this.href=e;this.ownerNode=a;this.parentStyleSheet=null;this.title=d;this.type="text/css"}function O(b){var a=b.sheet;if(a==null)a=b.styleSheet;return a}function hb(a){var b=[];if(a!=null)if(a.rules!=null)b=a.rules;else if(a.cssRules!=null)b=a.cssRules;return b}function ob(f){var c=[];if(r())c=document.styleSheets;else{b.foreach(function(a){if(a.url!=null){var b=a.replaceNodeModified||a.replaceNode==null?a.node:a.replaceNode,f=a.replaceNode!=null?a.replaceNode.title:null,d=null;if(a._newCss!=null)d=a._newCss;else if(a.text!=null)d=a.text;else{var e=O(b);if(e!=null)d=e.cssText}(b.sheet!=null||b.styleSheet!=null)&&c.push(new t(a.url,f,d,b))}});if(f){var d=document.styleSheets;if(d!=null)for(var e=0;e0&&n!=null)c=C.ThemeImage(b,d,n)}catch(e){}return c}function h(){if(e)return;if(k&&(m||d)){var b=a;c.foreach(function(a){if(!d&&a.callbacks.length>0)b=u(a.rules);for(var c=0;c=0&&e>=b){a=Boolean(a);var h=b+(a?0:d.length),i=e+(a?f.length:0);g=c.substring(h,i)}}return g}var n="progid:DXImageTransform.Microsoft.gradient",q="progid:DXImageTransform.Microsoft.AlphaImageLoader";function t(b){if(e.getReplaceColor()!=null&&b.indexOf(n)>-1){var c=h(b,"(",")");if(Boolean(c)){var d=h(c,"startColorstr=",",");j(d,g.gradient)}else a.push(b);return}if(e.getReplaceBGImage()&&b.indexOf(q)>-1){a.pushThemableString(function(a){if(!Boolean(a.backgroundImageUri))return"none";else{var c=h(b,"src='","'",true);return b.replace(c,"src='"+a.backgroundImageUri+"'")}});return}if(e.getColorName()){a.pushThemableString(function(d,c){var a=c.lastColorRead;return a!=null&&a.getColor()!=null?'"'+fb(c.lastColorRead.getColor(),d.ColorNames)+'"':b});return}a.push(b)}function r(b){if(i){a.push(b);return}a.pushThemableImage(b,e.getRecolorImage())}var l={};function w(a){var b=a;if(o!=null&&Boolean(a)&&a!="none"&&a!="inherit"&&a.charAt(0)!="#")if(l.hasOwnProperty(a))b=l[a];else b=l[a]=o(a);return b}function m(a){return Boolean(a)?'url("'+k(a)+'")':"none"}function v(d){var c=I(d),b=w(c);if(!Boolean(b))b=c;if(e.getReplaceBGImage())a.pushThemableString(function(a){return!Boolean(a.backgroundImageUri)?m(b):m(a.backgroundImageUri)});else{a.push('url("');if(e.getRecolorImage()!=null)r(b);else a.push(k(b));a.push('")')}}function j(i,d){function h(a,b){switch(b){case g.rgba:return"rgba("+a+")";case g.rgb:return"rgb("+a+")";case g.gradient:return'"'+n+"(startColorstr="+a+", endColorstr="+a+')"';default:return a}}var f=e.getReplaceColor(),b=e.getReplaceTwoColors();if((f==null||!Boolean(f.themeColor)&&!Boolean(f.color))&&(b==null||!Boolean(b.themeColor1)&&!Boolean(b.color1)||!Boolean(b.themeColor2)&&!Boolean(b.color2)))a.pushThemableString(function(b,a){a.lastColorRead=mb(i,d);return h(i,d)});else{var c="",j=f;if(b!=null&&f==null){if(!("colorIndex"in b))c=b.colorIndex="1";else c=b.colorIndex="2";j=new x(b["themeColor"+c],b["color"+c],b["themeShade"+c],b["themeTint"+c],b["opacity"+c])}a.pushThemableString(function(f,e){var a=f.GetColorForApplication(j);if(a!=null){e.lastColorRead=nb(a);var c=d===g.gradient,b=A(a,c);if(c)b=h(b,d);return b}else return h(i,d)})}}function u(c){var b=e.getReplaceFont();a.push("font-family:");Boolean(b)&&Boolean(b.themeFont)&&a.pushThemableString(function(g,f){var a=null,e=g.GetThemeFontByName(b.themeFont);if(e!=null){var c=e.fontFace;c.IsWebFont&&f.fontFaceBlocks.push(c.PreviewFontFaceBlock);a=c.Name}var d="";if(a!=null)d='"'+a.replace('"','\\"')+'",';return d});a.push(c)}a:while(true){d=y.getNext();var c=d.text;switch(d.kind){case b.comment:s(c);break;case b.colon:e.commit();a.push(c);break;case b.font_family:e.commit();u(c);break;case b.right_curly:case b.semicolon:a.push(c);e.clear();break;case b.url:v(c);break;case b.rgb:case b.rgba:j(c,d.kind);break;case b.color:j(c,d.kind);break;case b.string:t(c);break;case b.text:default:if(!Boolean(c))break a;a.push(c)}}return{ApplyTheme:function(b,c){a.generateResult(c,b)},Cancel:function(){a.cancel()}};function s(i){var j=/^\/\*\s*\[(\w+)(?:\(\s*([^\)]+)\s*\))?\]\s*\*\/$/,d=j.exec(i),g=false,b=null,c=null,h=e.values;if(d!=null){b=d[1];c=d[2]}if(b in h)try{h[b]=b==="ColorName"||b==="ReplaceBGImage"?{}:p(c);g=true}catch(k){f("Failed to parse theme attribute: "+c)}!g&&a.push(i)}function p(value){var parsed=null;if(value==null)parsed={};else eval("parsed={"+value+"}");return parsed}}};