{"version":3,"file":"StyledIcon.cjs","sources":["../src/js/StyledIcon.jsx"],"sourcesContent":["import React, { forwardRef } from 'react';\nimport { styled, css } from 'styled-components';\n\nimport { defaultProps } from './default-props';\nimport { useIconPad, parseMetricToNum } from './utils';\n\n// Returns the specific color that should be used according to the theme.\n// If 'dark' is supplied, it takes precedence over 'theme.dark'.\n// Can return undefined.\nconst normalizeColor = (color, theme, dark) => {\n  const colorSpec =\n    theme.global && theme.global.colors[color] !== undefined\n      ? theme.global.colors[color]\n      : color;\n  // If the color has a light or dark object, use that\n  let result = colorSpec;\n  if (colorSpec) {\n    if (\n      (dark === true || (dark === undefined && theme.dark)) &&\n      colorSpec.dark !== undefined\n    ) {\n      result = colorSpec.dark;\n    } else if (\n      (dark === false || !theme.dark) &&\n      colorSpec.light !== undefined\n    ) {\n      result = colorSpec.light;\n    }\n  }\n  // allow one level of indirection in color names\n  if (result && theme.global && theme.global.colors[result] !== undefined) {\n    result = normalizeColor(result, theme, dark);\n  }\n\n  return result;\n};\n\nconst colorStyle = (name, value, theme, required) => css`\n  ${name}: ${normalizeColor(value, theme, required)};\n`;\n\nconst colorCss = css`\n  ${(props) =>\n    colorStyle(\n      'fill',\n      props.color || props.theme.global.colors.icon,\n      props.theme,\n    )}\n  ${(props) =>\n    colorStyle(\n      'stroke',\n      props.color || props.theme.global.colors.icon,\n      props.theme,\n    )}\n\n  g {\n    fill: inherit;\n    stroke: inherit;\n  }\n\n  *:not([stroke]) {\n    &[fill='none'] {\n      stroke-width: 0;\n    }\n  }\n\n  *[stroke*='#'],\n  *[STROKE*='#'] {\n    stroke: inherit;\n    fill: none;\n  }\n\n  *[fill-rule],\n  *[FILL-RULE],\n  *[fill*='#'],\n  *[FILL*='#'] {\n    fill: inherit;\n    stroke: none;\n  }\n`;\n\nconst IconInner = forwardRef(\n  // Copying implementation from original \n  // https://github.com/grommet/grommet-icons/blob/master/src/js/StyledIcon.js\n  // Disabling eslint rule for unused vars. Need to confirm whether \n  // it was intentional to not pass color, size, theme to the svg.\n  // eslint-disable-next-line @typescript-eslint/no-unused-vars\n  ({ a11yTitle, color, size, theme, ...rest }, ref) => (\n    <svg ref={ref} aria-label={a11yTitle} {...rest} />\n  ),\n);\nIconInner.displayName = 'Icon';\n\nconst StyledIcon = styled(IconInner).withConfig({\n  // don't let height attribute leak to DOM\n  // https://styled-components.com/docs/api#shouldforwardprop\n  shouldForwardProp: (prop) => !['height', 'width'].includes(prop),\n})`\n  display: inline-block;\n  flex: 0 0 auto;\n\n  ${({ size: sizeProp = 'medium', theme, viewBox }) => {\n    const [, , w, h] = (viewBox || '0 0 24 24').split(' ');\n    const scale = w / h;\n    const size = theme.icon.size[sizeProp] || sizeProp;\n    const dimension = parseMetricToNum(size);\n    // grab rem, em, px value from resolved size value\n    const unit = size.match(/[a-z]+$/)?.[0] || 'px';\n\n    if (w < h) {\n      return `\n      width: ${dimension}${unit};\n      height: ${dimension / scale}${unit};\n    `;\n    }\n    if (h < w) {\n      return `\n      width: ${dimension * scale}${unit};\n      height: ${dimension}${unit};\n    `;\n    }\n    return `\n      width: ${dimension}${unit};\n      height: ${dimension}${unit};\n    `;\n  }}\n  ${({ color }) => color !== 'plain' && colorCss}\n  ${(props) => (props.height || props.width) && useIconPad(props)}\n  ${({ theme }) => theme && theme.icon.extend}\n`;\n\nStyledIcon.defaultProps = {};\nObject.setPrototypeOf(StyledIcon.defaultProps, defaultProps);\n\nexport { StyledIcon };\n"],"names":["normalizeColor","color","theme","dark","colorSpec","global","colors","result","light","colorStyle","name","value","required","css","colorCss","props","icon","IconInner","forwardRef","a11yTitle","size","rest","ref","displayName","StyledIcon","styled","withConfig","shouldForwardProp","prop","includes","sizeProp","viewBox","w","h","split","scale","dimension","parseMetricToNum","unit","match","height","width","useIconPad","extend","defaultProps","Object","setPrototypeOf"],"mappings":"iOASMA,eAAiB,CAACC,EAAOC,EAAOC,KACpC,MAAMC,EACJF,EAAMG,aAAyC,IAA/BH,EAAMG,OAAOC,OAAOL,GAChCC,EA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