UNPKG

@nivo/theming

Version:
3 lines (2 loc) 4.79 kB
"use strict";var t=require("react"),e=require("lodash/merge.js"),o=require("lodash/get.js"),i=require("lodash/set.js"),r=require("react/jsx-runtime"),n=function(t){var e,o,i,r;if(null==t||"object"!=typeof t){return{topLeft:t,topRight:t,bottomRight:t,bottomLeft:t}}var n=t,l=n.top,a=n.bottom,s=n.left,u=n.right;return{topLeft:null!=(e=n.topLeft)?e:void 0!==l?l:null!=s?s:0,topRight:null!=(o=n.topRight)?o:void 0!==l?l:null!=u?u:0,bottomRight:null!=(i=n.bottomRight)?i:void 0!==a?a:null!=u?u:0,bottomLeft:null!=(r=n.bottomLeft)?r:void 0!==a?a:null!=s?s:0}};function l(){return l=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var i in o)({}).hasOwnProperty.call(o,i)&&(t[i]=o[i])}return t},l.apply(null,arguments)}function a(t,e){if(null==t)return{};var o={};for(var i in t)if({}.hasOwnProperty.call(t,i)){if(-1!==e.indexOf(i))continue;o[i]=t[i]}return o}var s=["outlineWidth","outlineColor","outlineOpacity"],u=["fill","outlineWidth","outlineColor","outlineOpacity"],f={textAlign:{start:"start",center:"middle",end:"end"},textBaseline:{top:"text-before-edge",center:"middle",bottom:"text-after-edge"}},d={textAlign:{start:"left",center:"center",end:"right"},textBaseline:{top:"top",center:"middle",bottom:"bottom"}},p={textAlign:{start:"left",center:"center",end:"right"},textBaseline:{top:"top",center:"middle",bottom:"bottom"}},x={svg:f,css:d,canvas:p},c=["axis.ticks.text","axis.legend.text","legends.title.text","legends.text","legends.ticks.text","legends.title.text","labels.text","dots.text","markers.text","annotations.text"],h=function(t,e){return l({},e,t)},m=function(t,r){var n=e({},t,r);return c.forEach((function(t){i(n,t,h(o(n,t),n.text))})),n},g=function(t,o){return o?e({},t,o):t},b={background:"transparent",text:{fontFamily:"sans-serif",fontSize:11,fill:"#333333",outlineWidth:0,outlineColor:"#ffffff",outlineOpacity:1},axis:{domain:{line:{stroke:"transparent",strokeWidth:1}},ticks:{line:{stroke:"#777777",strokeWidth:1},text:{}},legend:{text:{fontSize:12}}},grid:{line:{stroke:"#dddddd",strokeWidth:1}},legends:{hidden:{symbol:{fill:"#333333",opacity:.6},text:{fill:"#333333",opacity:.6}},text:{},ticks:{line:{stroke:"#777777",strokeWidth:1},text:{fontSize:10}},title:{text:{}}},labels:{text:{}},markers:{lineColor:"#000000",lineStrokeWidth:1,text:{}},dots:{text:{}},tooltip:{container:{background:"white",color:"inherit",fontSize:"inherit",borderRadius:"2px",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.25)",padding:"5px 9px"},basic:{whiteSpace:"pre",display:"flex",alignItems:"center"},chip:{marginRight:7},table:{},tableCell:{padding:"3px 5px"},tableCellValue:{fontWeight:"bold"}},crosshair:{line:{stroke:"#000000",strokeWidth:1,strokeOpacity:.75,strokeDasharray:"6 6"}},annotations:{text:{fontSize:13,outlineWidth:2,outlineColor:"#ffffff",outlineOpacity:1},link:{stroke:"#000000",strokeWidth:1,outlineWidth:2,outlineColor:"#ffffff",outlineOpacity:1},outline:{fill:"none",stroke:"#000000",strokeWidth:2,outlineWidth:2,outlineColor:"#ffffff",outlineOpacity:1},symbol:{fill:"#000000",outlineWidth:2,outlineColor:"#ffffff",outlineOpacity:1}}},v=function(e){return t.useMemo((function(){return m(b,e)}),[e])},y=t.createContext(null),k={};exports.ThemeContext=y,exports.ThemeProvider=function(t){var e=t.theme,o=void 0===e?k:e,i=t.children,n=v(o);return r.jsx(y.Provider,{value:n,children:i})},exports.borderRadiusToCss=function(t){return t.topLeft+"px "+t.topRight+"px "+t.bottomRight+"px "+t.bottomLeft+"px"},exports.canvasStyleAttributesMapping=p,exports.constrainBorderRadius=function(t,e,o){var i=n(t),r=i.topLeft,l=i.topRight,a=i.bottomRight,s=i.bottomLeft,u=Math.max(0,r),f=Math.max(0,l),d=Math.max(0,a),p=Math.max(0,s),x=u+f;if(x>e){var c=e/x;u*=c,f*=c}var h=p+d;if(h>e){var m=e/h;p*=m,d*=m}var g=u+p;if(g>o){var b=o/g;u*=b,p*=b}var v=f+d;if(v>o){var y=o/v;f*=y,d*=y}return{topLeft:u,topRight:f,bottomRight:d,bottomLeft:p}},exports.convertStyleAttribute=function(t,e,o){return x[t][e][o]},exports.cssStyleAttributesMapping=d,exports.defaultTheme=b,exports.extendAxisTheme=g,exports.extendDefaultTheme=m,exports.inheritRootThemeText=h,exports.normalizeBorderRadius=n,exports.sanitizeHtmlTextStyle=function(t){var e=t.fill;return t.outlineWidth,t.outlineColor,t.outlineOpacity,l({},a(t,u),{color:e})},exports.sanitizeSvgTextStyle=function(t){return t.outlineWidth,t.outlineColor,t.outlineOpacity,a(t,s)},exports.styleAttributesMapping=x,exports.svgStyleAttributesMapping=f,exports.useExtendedAxisTheme=function(e,o){return t.useMemo((function(){return g(e,o)}),[e,o])},exports.usePartialTheme=v,exports.useTheme=function(){var e=t.useContext(y);if(null===e)throw new Error("Unable to find the theme, did you forget to wrap your component with ThemeProvider?");return e}; //# sourceMappingURL=nivo-theming.cjs.js.map