UNPKG

@fusioncharts/core

Version:

JavaScript Data Visualisation Library

1 lines 6.03 kB
"use strict";exports.__esModule=true;exports.default=_default;var _lib=require("../../lib");function _default(R){var UNDEF,eve=R.eve,g=R._g,paperproto=R.fn,elproto=R.el,separator=/[, ]+/,E="",S=" ",cssStyleRegEx=/\B([A-Z]{1})/g,TITLE_STR="fusioncharts-raphael-stylesheet",StyleSheet,sheetproto;StyleSheet=function StyleSheet(ns){this.styleSheet=E;this.rules={};this.ns=ns||E};sheetproto=StyleSheet.prototype;sheetproto.getSheet=function(){var node=this.node;this.styleSheet=sheetproto.getStyleSheet(TITLE_STR);if(!this.styleSheet){node=this.node=g.doc.createElement("style");node.setAttribute("id",R.format("raphael-stylesheet-{0}",R._oid++));node.setAttribute("type","text/css");node.setAttribute("title",TITLE_STR);(g.doc.head||g.doc.getElementsByTagName("head")[0]).appendChild(this.node);this.styleSheet=sheetproto.getStyleSheet(TITLE_STR)}return this.styleSheet};sheetproto.getStyleSheet=function(title){var styleSheets=g.doc.styleSheets,len=styleSheets.length,sheet;while(len--){sheet=styleSheets[len];if(sheet.title===title){return sheet}}};sheetproto.applyCSSRule=function(selector,rule){var styleSheet=this.styleSheet,rules,len;if(!styleSheet){if(selector&&rule){styleSheet=this.getSheet()}else{return}}rules=styleSheet.rules||styleSheet.cssRules||{};len=rules.length||0;if(styleSheet.insertRule){styleSheet.insertRule(selector+"{"+rule+"}",len)}else if(styleSheet.addRule){styleSheet.addRule(selector,rule,len)}};sheetproto.removeCSS=function(_selector){var styleSheet=this.styleSheet,rules=styleSheet.rules||styleSheet.cssRules||{},len=rules.length||0,rule,selector=_selector;selector=selector||this.ns;while(len--){rule=rules[len];if(new RegExp(selector).test(rule.selectorText)){if(styleSheet.removeRule){styleSheet.removeRule(len)}else{styleSheet.deleteRule(len)}}}};sheetproto.destroy=function(){this.removeCSS();delete this.node;delete this.styleSheet;delete this.ns;delete this.rules};sheetproto.clear=function(){this.removeCSS();this.rules={}};sheetproto.add=function(selector,styles,compressed){var prop,css=E,s=this.rules[selector]||(this.rules[selector]={}),indent=compressed?E:"\t",keyseparator=compressed?":":": ";for(prop in styles){(s[prop]=styles[prop])&&(css+=indent+prop.replace(cssStyleRegEx,"-$1").toLowerCase()+keyseparator+s[prop]+";")}this.applyCSSRule(selector,css)};sheetproto.render=function(){this.setCssText()};sheetproto.setCssText=function(compressed){var indent=compressed?E:"\t",keyseparator=compressed?":":": ",css=E,selector=E,rule,prop;for(rule in this.rules){css=E;selector=rule.replace(/(^|\,)/g,"$1"+this.ns+S);rule=this.rules[rule];for(prop in rule){rule[prop]&&(css+=indent+prop.replace(cssStyleRegEx,"-$1").toLowerCase()+keyseparator+rule[prop]+";")}this.applyCSSRule(selector,css)}};eve.on("raphael.new",(function(){this._stylesheet=this._stylesheet||new StyleSheet;this.cssNamespace(E)}));eve.on("raphael.remove",(function(){this._stylesheet&&this._stylesheet.destroy();delete this._stylesheet}));paperproto.cssNamespace=function(ns){if(arguments.length){this._stylesheet.ns=R.format("{0}#raphael-paper-{1}",ns&&ns+S||E,this.id)}return this._stylesheet.ns};paperproto.cssAddRule=function(selector,styles){if(arguments.length===1&&typeof selector==="object"){for(var prop in selector){this.cssAddRule(prop,selector[prop])}return this}return this._stylesheet.add(selector,styles),this};paperproto.cssRender=function(){return R.svg&&this._stylesheet.render(),this};paperproto.cssClear=function(){return this._stylesheet.clear(),this};R.ca["class"]=function(_value){var o=this,value=_value,node=o.node,paper=o.paper,selector="."+value,className,universalClassName="fusioncharts-div",styleRules=paper._stylesheet&&paper._stylesheet.rules,target=o.parent,attrs=o.attrs,cssObj={},rule,targetClass,i;if(R.svg){value=value||E;node.setAttribute("class",o.type==="group"&&o._id?"raphael-group-"+o.id+"-"+o._id+S+value:value)}else if(R.vml){className=node.className=o.type==="group"?value&&o._id+S+value||o._id:"rvml "+value;node.className=className?className+" "+universalClassName:universalClassName;if(selector&&styleRules){rule=styleRules[selector];for(i in rule){i==="color"&&o.type==="text"&&(i="fill");!attrs[i]&&(cssObj[i]=rule[i])}while(target&&target.attr){if(targetClass=target.attr("class")){selector="."+targetClass+S+selector;rule=styleRules[selector];for(i in rule){i==="color"&&o.type==="text"&&(i="fill");!attrs[i]&&!cssObj[i]&&(cssObj[i]=rule[i])}}target=target.parent}o.css(cssObj)}}};elproto.css=function(_name,value,doNotTune){var names,name=_name,params,out,otherkey,doattrs,i,ii;if(this.removed){return this}if(!this.styles){this.styles={}}if(value===UNDEF&&R.is(name,"string")){names=name.split(separator);out={};for(i=0,ii=names.length;i<ii;i++){name=names[i];if(name in this.styles){out[name]=this.styles[name]}}return ii-1?out:out[names[0]]}if(value===UNDEF&&R.is(name,"array")){out={};for(i=0,ii=name.length;i<ii;i++){out[name[i]]=this.styles(name[i])}return out}if(value!==UNDEF){params={};params[name]=value}else if(name&&R.is(name,"object")){params=name}doattrs={};for(i in params){otherkey=i.replace(/\B([A-Z]{1})/g,"-$1").toLowerCase();if(R._availableAttrs.hasOwnProperty(otherkey)||otherkey==="color"){otherkey==="color"&&this.type==="text"&&(otherkey="fill");doattrs[otherkey]=params[i];doattrs.dirty=true;continue}eve("raphael.css."+otherkey+"."+this.id,this,params[i],otherkey);this.node.style[otherkey]=params[i];this.styles[otherkey]=params[i]}for(i=0,ii=this.followers.length;i<ii;i++){this.followers[i].el.attr(params)}if(doattrs.hasOwnProperty("dirty")){delete doattrs.dirty;doNotTune&&(doattrs["_do-not-tune"]=true);this.attr(doattrs)}return this};elproto.removeCSS=function(_params){var element=this,params=_params,param,i,len;!params&&(params=_lib.appliedCSS);if(this.removed){return this}if(R.is(params,"string")){params=params.split(",")}if(R.is(params,"array")){len=params.length;for(i=0;i<len;i++){param=params[i].replace(/\B([A-Z]{1})/g,"-$1").toLowerCase();element.node.removeAttribute(param);element.node.style[param]=""}}return this}}