{"version":3,"file":"index.mjs","names":[],"sources":["../src/modules/hooks.tsx","../src/modules/elementCache.ts","../src/modules/utils.ts","../src/modules/useInlineSVG.ts","../src/index.tsx"],"sourcesContent":["import { EffectCallback, useEffect, useRef } from 'react';\n\nexport function useMount(effect: EffectCallback) {\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  useEffect(effect, []);\n}\n\nexport function usePrevious<T>(state: T): T | undefined {\n  const ref = useRef<T>(undefined);\n\n  useEffect(() => {\n    ref.current = state;\n  });\n\n  return ref.current;\n}\n","import { ReactElement } from 'react';\n\nimport { ELEMENT_CACHE_MAX_SIZE } from '../config';\n\nconst store = new Map<string, ReactElement>();\n\nexport function clearElementCache() {\n  store.clear();\n}\n\nexport function getCachedElement(key: string): ReactElement | undefined {\n  const element = store.get(key);\n\n  if (element) {\n    // Re-insert so the least recently used entry is always the next one evicted.\n    store.delete(key);\n    store.set(key, element);\n  }\n\n  return element;\n}\n\nexport function getElementCacheSize(): number {\n  return store.size;\n}\n\nexport function setCachedElement(key: string, element: ReactElement) {\n  store.delete(key);\n  store.set(key, element);\n\n  if (store.size > ELEMENT_CACHE_MAX_SIZE) {\n    const oldest = store.keys().next().value;\n\n    if (oldest !== undefined) {\n      store.delete(oldest);\n    }\n  }\n}\n","import { isValidElement, ReactElement } from 'react';\nimport convert from 'react-from-dom';\n\nimport { Props, State } from '../types';\n\nimport { getCachedElement, setCachedElement } from './elementCache';\n\ninterface GetNodeOptions extends Props, Pick<State, 'content'> {\n  handleError: (error: Error) => void;\n  hash: string;\n}\n\ninterface UpdateSVGAttributesOptions extends Pick<Props, 'baseURL' | 'uniquifyIDs'> {\n  hash: string;\n}\n\nfunction getElementCacheKey(\n  content: string,\n  title: string | null | undefined,\n  description: string | undefined,\n  uniquifyIDs: boolean | undefined,\n  hash: string,\n  baseURL: string | undefined,\n): string {\n  return JSON.stringify([\n    content,\n    // `title` is three-way — undefined keeps an existing `<title>`, null removes it — and\n    // JSON.stringify flattens undefined to null, so it becomes a value that can't collide.\n    title === undefined ? false : title,\n    description,\n    // `uniquifyIDs` bakes both of these into the output, so those instances only share an entry\n    // when they also share a `uniqueHash`. Each is its own part, so neither can look like the other.\n    uniquifyIDs ? hash : null,\n    uniquifyIDs ? (baseURL ?? '') : null,\n  ]);\n}\n\nfunction uniquifyStyleIds(svgText: string, hash: string, baseURL: string): string {\n  const idMatches = svgText.matchAll(/\\bid=([\"'])([^\"']+)\\1/g);\n  const ids = [...new Set([...idMatches].map(m => m[2]))];\n\n  if (!ids.length) {\n    return svgText;\n  }\n\n  ids.sort((a, b) => b.length - a.length);\n\n  return svgText.replace(/<style[^>]*>([\\S\\s]*?)<\\/style>/gi, (fullMatch, cssContent) => {\n    let modified = cssContent as string;\n\n    for (const id of ids) {\n      const escaped = id.replace(/[$()*+.?[\\\\\\]^{|}]/g, '\\\\$&');\n\n      modified = modified.replace(\n        new RegExp(`url\\\\((['\"]?)#${escaped}\\\\1\\\\)`, 'g'),\n        `url($1${baseURL}#${id}__${hash}$1)`,\n      );\n      modified = modified.replace(\n        new RegExp(`#${escaped}(?![a-zA-Z0-9_-])`, 'g'),\n        `#${id}__${hash}`,\n      );\n    }\n\n    return fullMatch.replace(cssContent, modified);\n  });\n}\n\nexport function convertToElement(options: GetNodeOptions): ReactElement | null {\n  const { baseURL, cacheElements, content, description, hash, preProcessor, title, uniquifyIDs } =\n    options;\n  const svgText = preProcessor ? preProcessor(content) : content;\n\n  // Keyed by the pre-processed content and by every prop that shapes the markup.\n  const key = cacheElements\n    ? getElementCacheKey(svgText, title, description, uniquifyIDs, hash, baseURL)\n    : null;\n\n  if (key) {\n    const cached = getCachedElement(key);\n\n    if (cached) {\n      return cached;\n    }\n  }\n\n  // The pre-processed content is passed on so it isn't processed twice.\n  const node = getNode({ ...options, content: svgText, preProcessor: undefined });\n  const element = convert(node as Node);\n\n  if (!isValidElement(element)) {\n    return null;\n  }\n\n  if (key) {\n    setCachedElement(key, element);\n  }\n\n  return element;\n}\n\nexport function getNode(options: GetNodeOptions) {\n  const {\n    baseURL,\n    content,\n    description,\n    handleError,\n    hash,\n    preProcessor,\n    title,\n    uniquifyIDs = false,\n  } = options;\n\n  try {\n    let svgText = preProcessor ? preProcessor(content) : content;\n\n    if (uniquifyIDs) {\n      svgText = uniquifyStyleIds(svgText, hash, baseURL ?? '');\n    }\n\n    const node = convert(svgText, { nodeOnly: true });\n\n    if (!node || !(node instanceof SVGSVGElement)) {\n      throw new Error('Could not convert the src to a DOM Node');\n    }\n\n    const svg = updateSVGAttributes(node, { baseURL, hash, uniquifyIDs });\n\n    if (description) {\n      const originalDesc = svg.querySelector('desc');\n\n      if (originalDesc?.parentNode) {\n        originalDesc.parentNode.removeChild(originalDesc);\n      }\n\n      const descElement = document.createElementNS('http://www.w3.org/2000/svg', 'desc');\n\n      descElement.innerHTML = description;\n      svg.prepend(descElement);\n    }\n\n    if (typeof title !== 'undefined') {\n      const originalTitle = svg.querySelector('title');\n\n      if (originalTitle?.parentNode) {\n        originalTitle.parentNode.removeChild(originalTitle);\n      }\n\n      if (title) {\n        const titleElement = document.createElementNS('http://www.w3.org/2000/svg', 'title');\n\n        titleElement.innerHTML = title;\n        svg.prepend(titleElement);\n      }\n    }\n\n    return svg;\n  } catch (error: any) {\n    return handleError(error);\n  }\n}\n\nexport function updateSVGAttributes(\n  node: SVGSVGElement,\n  options: UpdateSVGAttributesOptions,\n): SVGSVGElement {\n  const { baseURL = '', hash, uniquifyIDs } = options;\n  const replaceableAttributes = ['id', 'href', 'xlink:href', 'xlink:role', 'xlink:arcrole'];\n  const linkAttributes = ['href', 'xlink:href'];\n  const isDataValue = (name: string, value: string) =>\n    linkAttributes.includes(name) && (value ? !value.includes('#') : false);\n\n  if (!uniquifyIDs) {\n    return node;\n  }\n\n  [...node.children].forEach(d => {\n    if (d.attributes?.length) {\n      const attributes = Object.values(d.attributes).map(a => {\n        const attribute = a;\n        const match = /url\\((.*?)\\)/.exec(a.value);\n\n        if (match?.[1]) {\n          attribute.value = a.value.replace(match[0], `url(${baseURL}${match[1]}__${hash})`);\n        }\n\n        return attribute;\n      });\n\n      replaceableAttributes.forEach(r => {\n        const attribute = attributes.find(a => a.name === r);\n\n        if (attribute && !isDataValue(r, attribute.value)) {\n          attribute.value = `${attribute.value}__${hash}`;\n        }\n      });\n    }\n\n    if (d.children.length) {\n      return updateSVGAttributes(d as SVGSVGElement, options);\n    }\n\n    return d;\n  });\n\n  return node;\n}\n","import { useCallback, useEffect, useReducer, useRef } from 'react';\n\nimport { STATUS } from '../config';\nimport type { FetchError, Props, State } from '../types';\n\nimport type CacheStore from './cache';\nimport { canUseDOM, isSupportedEnvironment, randomString, request } from './helpers';\nimport { useMount, usePrevious } from './hooks';\nimport { convertToElement } from './utils';\n\nexport default function useInlineSVG(props: Props, cacheStore: CacheStore) {\n  const {\n    baseURL,\n    cacheElements = false,\n    cacheRequests = true,\n    description,\n    fetchOptions,\n    onError,\n    onLoad,\n    preProcessor,\n    src,\n    title,\n    uniqueHash,\n    uniquifyIDs,\n  } = props;\n\n  const hashRef = useRef(uniqueHash);\n  // Read once, like `hashRef`: a later `uniqueHash` doesn't replace a random hash already in use.\n  const hasStableHash = useRef(uniqueHash !== undefined).current;\n  // A random hash makes the key unique to this instance, so the entry could never be reused.\n  const shouldCacheElement = cacheElements && !(uniquifyIDs && !hasStableHash);\n  const fetchOptionsRef = useRef(fetchOptions);\n  const onErrorRef = useRef(onError);\n  const onLoadRef = useRef(onLoad);\n  const preProcessorRef = useRef(preProcessor);\n\n  fetchOptionsRef.current = fetchOptions;\n  onErrorRef.current = onError;\n  onLoadRef.current = onLoad;\n  preProcessorRef.current = preProcessor;\n\n  const getHash = useCallback(() => {\n    const hash = hashRef.current ?? randomString(8);\n\n    hashRef.current = hash;\n\n    return hash;\n  }, []);\n\n  const [state, setState] = useReducer(\n    (previousState: State, nextState: Partial<State>) => ({\n      ...previousState,\n      ...nextState,\n    }),\n    {\n      content: '',\n      element: null,\n      isCached: false,\n      status: STATUS.IDLE,\n    },\n    (initial): State => {\n      const cached = cacheRequests && cacheStore.isCached(src);\n\n      if (!cached) {\n        return initial;\n      }\n\n      const cachedContent = cacheStore.getContent(src);\n\n      try {\n        const convertedElement = convertToElement({\n          ...props,\n          cacheElements: shouldCacheElement,\n          handleError: () => {},\n          hash: uniquifyIDs ? getHash() : '',\n          content: cachedContent,\n        });\n\n        if (convertedElement) {\n          return {\n            content: cachedContent,\n            element: convertedElement,\n            isCached: true,\n            status: STATUS.READY,\n          };\n        }\n      } catch {\n        // Fall through to effect-driven flow\n      }\n\n      return {\n        ...initial,\n        content: cachedContent,\n        isCached: true,\n        status: STATUS.LOADED,\n      };\n    },\n  );\n  const { content, element, isCached, status } = state;\n  const previousProps = usePrevious(props);\n  const previousState = usePrevious(state);\n  const isActive = useRef(false);\n  const isInitialized = useRef(false);\n\n  const handleError = useCallback((error: Error | FetchError) => {\n    if (isActive.current) {\n      setState({\n        status:\n          error.message === 'Browser does not support SVG' ? STATUS.UNSUPPORTED : STATUS.FAILED,\n      });\n\n      onErrorRef.current?.(error);\n    }\n  }, []);\n\n  const getElement = useCallback(() => {\n    try {\n      const convertedElement = convertToElement({\n        baseURL,\n        cacheElements: shouldCacheElement,\n        content,\n        description,\n        handleError,\n        hash: uniquifyIDs ? getHash() : '',\n        preProcessor: preProcessorRef.current,\n        src,\n        title,\n        uniquifyIDs,\n      });\n\n      if (!convertedElement) {\n        throw new Error('Could not convert the src to a React element');\n      }\n\n      setState({\n        element: convertedElement,\n        status: STATUS.READY,\n      });\n    } catch (error: any) {\n      handleError(error);\n    }\n  }, [\n    baseURL,\n    content,\n    description,\n    getHash,\n    handleError,\n    shouldCacheElement,\n    src,\n    title,\n    uniquifyIDs,\n  ]);\n\n  // Mount\n  useMount(() => {\n    isActive.current = true;\n\n    if (!canUseDOM() || isInitialized.current) {\n      return undefined;\n    }\n\n    try {\n      if (status === STATUS.READY) {\n        onLoadRef.current?.(src, isCached);\n      } else if (status === STATUS.IDLE) {\n        if (!isSupportedEnvironment()) {\n          throw new Error('Browser does not support SVG');\n        }\n\n        if (!src) {\n          throw new Error('Missing src');\n        }\n\n        setState({ content: '', element: null, isCached: false, status: STATUS.LOADING });\n      }\n    } catch (error: any) {\n      handleError(error);\n    }\n\n    isInitialized.current = true;\n\n    return () => {\n      isActive.current = false;\n    };\n  });\n\n  // Src changes\n  useEffect(() => {\n    if (!canUseDOM() || !previousProps) {\n      return;\n    }\n\n    if (previousProps.src !== src) {\n      if (!src) {\n        handleError(new Error('Missing src'));\n\n        return;\n      }\n\n      setState({ content: '', element: null, isCached: false, status: STATUS.LOADING });\n    }\n  }, [handleError, previousProps, src]);\n\n  // Fetch content when status is LOADING\n  useEffect(() => {\n    if (status !== STATUS.LOADING) {\n      return undefined;\n    }\n\n    const controller = new AbortController();\n    let active = true;\n\n    (async () => {\n      try {\n        const dataURI = /^data:image\\/svg[^,]*?(;base64)?,(.*)/.exec(src);\n        let inlineSrc;\n\n        if (dataURI) {\n          inlineSrc = dataURI[1] ? window.atob(dataURI[2]) : decodeURIComponent(dataURI[2]);\n        } else if (src.includes('<svg')) {\n          inlineSrc = src;\n        }\n\n        if (inlineSrc) {\n          if (active) {\n            setState({ content: inlineSrc, isCached: false, status: STATUS.LOADED });\n          }\n\n          return;\n        }\n\n        const fetchParameters = { ...fetchOptionsRef.current, signal: controller.signal };\n        let loadedContent: string;\n        let hasCache = false;\n\n        if (cacheRequests) {\n          hasCache = cacheStore.isCached(src);\n          loadedContent = await cacheStore.get(src, fetchParameters);\n        } else {\n          loadedContent = await request(src, fetchParameters);\n        }\n\n        if (active) {\n          setState({ content: loadedContent, isCached: hasCache, status: STATUS.LOADED });\n        }\n      } catch (error: any) {\n        if (active && error.name !== 'AbortError') {\n          handleError(error);\n        }\n      }\n    })();\n\n    return () => {\n      active = false;\n      controller.abort();\n    };\n  }, [cacheRequests, cacheStore, handleError, src, status]);\n\n  // LOADED -> READY\n  useEffect(() => {\n    if (status === STATUS.LOADED && content) {\n      getElement();\n    }\n  }, [content, getElement, status]);\n\n  // Title and description changes\n  useEffect(() => {\n    if (!canUseDOM() || !previousProps || previousProps.src !== src) {\n      return;\n    }\n\n    if (previousProps.title !== title || previousProps.description !== description) {\n      getElement();\n    }\n  }, [description, getElement, previousProps, src, title]);\n\n  // READY -> onLoad\n  useEffect(() => {\n    if (!previousState) {\n      return;\n    }\n\n    if (status === STATUS.READY && previousState.status !== STATUS.READY) {\n      onLoadRef.current?.(src, isCached);\n    }\n  }, [isCached, previousState, src, status]);\n\n  return { element, status };\n}\n","import { cloneElement, ReactElement, ReactNode, SVGProps } from 'react';\n\nimport { STATUS } from './config';\nimport CacheStore from './modules/cache';\nimport { canUseDOM, omit } from './modules/helpers';\nimport useInlineSVG from './modules/useInlineSVG';\nimport { useCacheStore } from './provider';\nimport { Props, Status } from './types';\n\nexport const cacheStore = new CacheStore();\n\nexport { clearElementCache } from './modules/elementCache';\n\nexport default function InlineSVG(props: Props): ReactNode {\n  const { children = null, innerRef, loader = null } = props;\n  const contextStore = useCacheStore();\n  const store = contextStore ?? cacheStore;\n\n  const { element, status } = useInlineSVG(props, store);\n\n  if (!canUseDOM()) {\n    return loader;\n  }\n\n  if (element) {\n    return cloneElement(element as ReactElement<SVGProps<SVGElement>>, {\n      ref: innerRef,\n      ...omit(\n        props,\n        'baseURL',\n        'cacheElements',\n        'cacheRequests',\n        'children',\n        'description',\n        'fetchOptions',\n        'innerRef',\n        'loader',\n        'onError',\n        'onLoad',\n        'preProcessor',\n        'src',\n        'title',\n        'uniqueHash',\n        'uniquifyIDs',\n      ),\n    });\n  }\n\n  if (([STATUS.UNSUPPORTED, STATUS.FAILED] as Status[]).includes(status)) {\n    return children;\n  }\n\n  return loader;\n}\n\nexport * from './types';\n"],"mappings":";;;;;AAEA,SAAgB,SAAS,QAAwB;CAE/C,UAAU,QAAQ,CAAC,CAAC;AACtB;AAEA,SAAgB,YAAe,OAAyB;CACtD,MAAM,MAAM,OAAU,KAAA,CAAS;CAE/B,gBAAgB;EACd,IAAI,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