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ChB,SACA,UAAU,CAAC,EACX,QAAO,EACP,aAAY,EACZ,cAEA,MAEM,EAAU,GAFE,IAAsB,MAAM,cAAc,IAAK,KAAM,EAAM,WAI7E,IAAK,EACH,OAAO,GAAQ,EAAuB,MAAM,cAAc,EAAS,KAAmB,MAAM,cAAc,gBAAiB,CACzH,OAAQ,EACR,QAAS,KACQ,MAAM,cAAc,gBAAiB,CACtD,OAAQ,EACR,QAAS,IAIb,MAAM,EAAa,EAAO,MAAM,SAC/B,KAAI,GAAQ,EAAK,SACjB,QAAO,GAAQ,IACf,KAAI,CAAC,EAAY,IAAmB,MAAM,cAAc,EAAS,CAChE,IAAK,GACS,MAAM,cAAc,gBAAiB,CACnD,OAAQ,EACR,QAAS,OAEX,OAAoB,MAAM,cAAc,MAAM,SAAU,KAAM,EAAW,EAG3E,UAAU,UAAY,CACpB,OAAQ,UAAU,OAAO,WACzB,QAAS,UAAU,SAAS,UAAU,UAAU,CAAC,UAAU,OAAQ,UAAU,OAAQ,UAAU,QAAS,UAAU,QAAQ,UAAU,UAAU,CAAC,UAAU,OAAQ,UAAU,cAC3K,KAAM,UAAU,KAChB,QAAS,UAAU,YACnB,UAAW,UAAU,MAGvB,OAAO,QAAU","file":"/npm/@reuters-graphics/react-smart-text@0.2.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@reuters-graphics/react-smart-text@0.2.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar PropTypes = _interopDefault(require('prop-types'));\nvar React = _interopDefault(require('react'));\nvar Mustache = _interopDefault(require('mustache'));\nvar ReactMarkdown = _interopDefault(require('react-markdown'));\nvar bracketedSpans = _interopDefault(require('remark-bracketed-spans'));\nvar last = _interopDefault(require('lodash/last'));\nvar pickBy = _interopDefault(require('lodash/pickBy'));\nvar reallyRelaxedJson = require('really-relaxed-json');\n\nconst RenderedString = props => {\n  const markdownString = Mustache.render(props.source, props.context);\n  return /*#__PURE__*/React.createElement(ReactMarkdown, {\n    source: markdownString,\n    escapeHtml: false,\n    disallowedTypes: ['paragraph'],\n    unwrapDisallowed: true,\n    plugins: [[bracketedSpans]]\n  });\n};\n\nconst isPluralize = key => key.split('.pluralize:').length > 1;\n\nconst getPluralizedParts = key => {\n  const [context, pluralstring] = key.split('.pluralize:');\n  const plurals = pluralstring.split('|').map(d => d.trim());\n  return [context, plurals];\n};\n\nconst isPlural = context => Array.isArray(context) ? context.length > 1 : context > 1; // Props handlers\n\n\nconst isProps = key => key.split('.props:').length > 1;\n\nconst getPropsParts = key => {\n  const [componentKey, propsString] = key.split('.props:');\n  const propsParts = propsString.split('|').map(d => d.trim());\n  const props = {};\n\n  for (const propsPart of propsParts) {\n    const [key, script] = propsPart.split('=');\n\n    try {\n      const prop = JSON.parse(reallyRelaxedJson.toJson(script));\n      props[key] = prop;\n    } catch (e) {\n      console.warn(`Unable to parse prop \"${key}\" in SmartText component. Skipping.`);\n    }\n  }\n\n  return [componentKey, props];\n};\n\nconst SmartTextString = ({\n  source,\n  context = {}\n}) => {\n  const tokens = Mustache.parse(source);\n  const componentTokens = [];\n\n  const concatOrAppend = (arr, item) => {\n    const lastItem = last(arr);\n\n    if (typeof lastItem === 'string' && typeof item === 'string') {\n      arr.splice(-1, 1, lastItem + item);\n    } else {\n      arr.push(item);\n    }\n  };\n\n  for (const token of tokens) {\n    const [type, key] = token; // Text\n\n    if (type === 'text') {\n      concatOrAppend(componentTokens, key); // Template tokens\n    } else if (type === 'name') {\n      // Pluralize\n      if (isPluralize(key)) {\n        const [refKey, plurals] = getPluralizedParts(key);\n        const [singular, plural] = plurals;\n        const contextElement = context[refKey];\n        if (!contextElement) continue;\n\n        if (isPlural(contextElement)) {\n          concatOrAppend(componentTokens, plural);\n        } else {\n          concatOrAppend(componentTokens, singular);\n        }\n\n        continue;\n      } // Props\n\n\n      if (isProps(key)) {\n        const [componentKey, props] = getPropsParts(key);\n        const component = context[componentKey];\n        if (!component) continue;\n        componentTokens.push( /*#__PURE__*/React.cloneElement(component, props));\n        continue;\n      } // Recreate mustache templates to pass through for later processing\n\n\n      if (!context[key] || typeof context[key] === 'string') {\n        concatOrAppend(componentTokens, `${Mustache.tags[0]} ${key} ${Mustache.tags[1]}`); // Components\n      } else {\n        componentTokens.push(context[key]);\n      }\n    }\n  }\n  const cleanContext = pickBy(context, d => typeof d === 'string');\n  const Components = componentTokens.map((componentToken, i) => {\n    if (typeof componentToken !== 'string') return componentToken;\n    return /*#__PURE__*/React.createElement(RenderedString, {\n      source: componentToken,\n      context: cleanContext,\n      key: i\n    });\n  });\n  return /*#__PURE__*/React.createElement(React.Fragment, null, Components);\n};\n\nSmartTextString.propTypes = {\n  source: PropTypes.string.isRequired,\n  context: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.element, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.element]))]))\n};\n\nconst SmartText = ({\n  source,\n  context = {},\n  wrap = false,\n  multiline = false,\n  wrapper\n}) => {\n  const Paragraph = props => /*#__PURE__*/React.createElement(\"p\", null, props.children);\n\n  const Wrapper = wrapper || Paragraph;\n\n  if (!multiline) {\n    return wrap || wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, /*#__PURE__*/React.createElement(SmartTextString, {\n      source: source,\n      context: context\n    })) : /*#__PURE__*/React.createElement(SmartTextString, {\n      source: source,\n      context: context\n    });\n  }\n\n  const Components = source.split(/\\r?\\n/) // Split on paragraph breaking newlines\n  .map(line => line.trim()) // Trim lines\n  .filter(line => line) // Filter out empty lines caused by multiple new lines\n  .map((sourceLine, i) => /*#__PURE__*/React.createElement(Wrapper, {\n    key: i\n  }, /*#__PURE__*/React.createElement(SmartTextString, {\n    source: sourceLine,\n    context: context\n  })));\n  return /*#__PURE__*/React.createElement(React.Fragment, null, Components);\n};\n\nSmartText.propTypes = {\n  source: PropTypes.string.isRequired,\n  context: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.element, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.element]))])),\n  wrap: PropTypes.bool,\n  wrapper: PropTypes.elementType,\n  multiline: PropTypes.bool\n};\n\nmodule.exports = SmartText;\n"]}