{"version":3,"file":"nivo-text.mjs","sources":["../src/boxAnchor.ts","../src/canvas.ts","../src/Text.tsx"],"sourcesContent":["import { BoxAnchor } from '@nivo/core'\nimport { TextAlign, TextBaseline } from '@nivo/theming'\n\nconst textAlignByBoxAnchor: Record<BoxAnchor, TextAlign> = {\n    center: 'center',\n    'top-left': 'start',\n    top: 'center',\n    'top-right': 'end',\n    right: 'end',\n    'bottom-right': 'end',\n    bottom: 'center',\n    'bottom-left': 'start',\n    left: 'start',\n}\n\nconst textAlignOppositeMap: Record<TextAlign, TextAlign> = {\n    start: 'end',\n    center: 'center',\n    end: 'start',\n}\n\nconst textBaselineByBoxAnchor: Record<BoxAnchor, TextBaseline> = {\n    center: 'center',\n    'top-left': 'top',\n    top: 'top',\n    'top-right': 'top',\n    right: 'center',\n    'bottom-right': 'bottom',\n    bottom: 'bottom',\n    'bottom-left': 'bottom',\n    left: 'center',\n}\n\nconst textBaselineOppositeMap: Record<TextBaseline, TextBaseline> = {\n    top: 'bottom',\n    center: 'center',\n    bottom: 'top',\n}\n\nexport const getTextAlignFromBoxAnchor = (anchor: BoxAnchor, isOutside = false) => {\n    const align = textAlignByBoxAnchor[anchor]\n    if (!isOutside) return align\n    return textAlignOppositeMap[align]\n}\n\nexport const getTextBaselineFromBoxAnchor = (anchor: BoxAnchor, isOutside = false) => {\n    const baseline = textBaselineByBoxAnchor[anchor]\n    if (!isOutside) return baseline\n    return textBaselineOppositeMap[baseline]\n}\n","import { TextStyle } from '@nivo/theming'\n\nexport const setCanvasFont = (ctx: CanvasRenderingContext2D, style: TextStyle) => {\n    ctx.font = `${style.fontWeight ? `${style.fontWeight} ` : ''}${style.fontSize}px ${\n        style.fontFamily\n    }`\n}\n\nexport const drawCanvasText = (\n    ctx: CanvasRenderingContext2D,\n    style: TextStyle,\n    text: string,\n    x = 0,\n    y = 0\n) => {\n    if (style.outlineWidth > 0) {\n        ctx.strokeStyle = style.outlineColor\n        ctx.lineWidth = style.outlineWidth * 2\n        ctx.lineJoin = 'round'\n        ctx.strokeText(text, x, y)\n    }\n\n    ctx.fillStyle = style.fill\n    ctx.fillText(text, x, y)\n}\n","import { PropsWithChildren, ComponentProps } from 'react'\nimport { animated } from '@react-spring/web'\nimport { TextStyle } from '@nivo/theming'\n\ntype AnimatedComponentProps = ComponentProps<(typeof animated)['text']>\n\nexport type TextProps = PropsWithChildren<\n    Omit<AnimatedComponentProps, 'style'> & {\n        style: AnimatedComponentProps['style'] &\n            Pick<TextStyle, 'outlineWidth' | 'outlineColor' | 'outlineOpacity'>\n    }\n>\n\nexport const Text = ({ style: fullStyle, children, ...attributes }: TextProps) => {\n    const { outlineWidth, outlineColor, outlineOpacity, ...style } = fullStyle\n\n    return (\n        <>\n            {outlineWidth > 0 && (\n                <animated.text\n                    {...attributes}\n                    style={{\n                        ...style,\n                        strokeWidth: outlineWidth * 2,\n                        stroke: outlineColor,\n                        strokeOpacity: outlineOpacity,\n                        strokeLinejoin: 'round',\n                    }}\n                >\n                    {children}\n                </animated.text>\n            )}\n            <animated.text {...attributes} style={style}>\n                {children}\n            </animated.text>\n        </>\n    )\n}\n"],"names":["textAlignByBoxAnchor","center","top","right","bottom","left","textAlignOppositeMap","start","end","textBaselineByBoxAnchor","textBaselineOppositeMap","getTextAlignFromBoxAnchor","anchor","isOutside","align","getTextBaselineFromBoxAnchor","baseline","setCanvasFont","ctx","style","font","fontWeight","fontSize","fontFamily","drawCanvasText","text","x","y","outlineWidth","strokeStyle","outlineColor","lineWidth","lineJoin","strokeText","fillStyle","fill","fillText","Text","_ref","fullStyle","children","attributes","_objectWithoutPropertiesLoose","_excluded","outlineOpacity","_excluded2","_jsxs","_Fragment","_jsx","animated","_extends","strokeWidth","stroke","strokeOpacity","strokeLinejoin"],"mappings":"6GAGA,IAAMA,EAAqD,CACvDC,OAAQ,SACR,WAAY,QACZC,IAAK,SACL,YAAa,MACbC,MAAO,MACP,eAAgB,MAChBC,OAAQ,SACR,cAAe,QACfC,KAAM,SAGJC,EAAqD,CACvD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