UNPKG

@nivo/theming

Version:
3 lines (2 loc) 4.74 kB
import{useMemo as t,createContext as e,useContext as o}from"react";import i from"lodash/merge.js";import n from"lodash/get.js";import r from"lodash/set.js";import{jsx as l}from"react/jsx-runtime";var a=function(t){var e,o,i,n;if(null==t||"object"!=typeof t){return{topLeft:t,topRight:t,bottomRight:t,bottomLeft:t}}var r=t,l=r.top,a=r.bottom,f=r.left,u=r.right;return{topLeft:null!=(e=r.topLeft)?e:void 0!==l?l:null!=f?f:0,topRight:null!=(o=r.topRight)?o:void 0!==l?l:null!=u?u:0,bottomRight:null!=(i=r.bottomRight)?i:void 0!==a?a:null!=u?u:0,bottomLeft:null!=(n=r.bottomLeft)?n:void 0!==a?a:null!=f?f:0}},f=function(t,e,o){var i=a(t),n=i.topLeft,r=i.topRight,l=i.bottomRight,f=i.bottomLeft,u=Math.max(0,n),d=Math.max(0,r),s=Math.max(0,l),c=Math.max(0,f),p=u+d;if(p>e){var h=e/p;u*=h,d*=h}var x=c+s;if(x>e){var m=e/x;c*=m,s*=m}var g=u+c;if(g>o){var b=o/g;u*=b,c*=b}var v=d+s;if(v>o){var k=o/v;d*=k,s*=k}return{topLeft:u,topRight:d,bottomRight:s,bottomLeft:c}};function u(){return u=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},u.apply(null,arguments)}function d(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"],c=["fill","outlineWidth","outlineColor","outlineOpacity"],p={textAlign:{start:"start",center:"middle",end:"end"},textBaseline:{top:"text-before-edge",center:"middle",bottom:"text-after-edge"}},h={textAlign:{start:"left",center:"center",end:"right"},textBaseline:{top:"top",center:"middle",bottom:"bottom"}},x={textAlign:{start:"left",center:"center",end:"right"},textBaseline:{top:"top",center:"middle",bottom:"bottom"}},m={svg:p,css:h,canvas:x},g=function(t,e,o){return m[t][e][o]},b=function(t){return t.outlineWidth,t.outlineColor,t.outlineOpacity,d(t,s)},v=function(t){var e=t.fill;return t.outlineWidth,t.outlineColor,t.outlineOpacity,u({},d(t,c),{color:e})},k=function(t){return t.topLeft+"px "+t.topRight+"px "+t.bottomRight+"px "+t.bottomLeft+"px"},y=["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"],W=function(t,e){return u({},e,t)},O=function(t,e){var o=i({},t,e);return y.forEach((function(t){r(o,t,W(n(o,t),o.text))})),o},R=function(t,e){return e?i({},t,e):t},C={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}}},L=function(e){return t((function(){return O(C,e)}),[e])},w=function(e,o){return t((function(){return R(e,o)}),[e,o])},S=e(null),j={},z=function(t){var e=t.theme,o=void 0===e?j:e,i=t.children,n=L(o);return l(S.Provider,{value:n,children:i})},M=function(){var t=o(S);if(null===t)throw new Error("Unable to find the theme, did you forget to wrap your component with ThemeProvider?");return t};export{S as ThemeContext,z as ThemeProvider,k as borderRadiusToCss,x as canvasStyleAttributesMapping,f as constrainBorderRadius,g as convertStyleAttribute,h as cssStyleAttributesMapping,C as defaultTheme,R as extendAxisTheme,O as extendDefaultTheme,W as inheritRootThemeText,a as normalizeBorderRadius,v as sanitizeHtmlTextStyle,b as sanitizeSvgTextStyle,m as styleAttributesMapping,p as svgStyleAttributesMapping,w as useExtendedAxisTheme,L as usePartialTheme,M as useTheme}; //# sourceMappingURL=nivo-theming.mjs.map