{"version":3,"file":"html-renderer.mjs","names":[],"sources":["../../src/utils/html-renderer.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport parse, { attributesToProps, domToReact } from 'html-react-parser';\nimport { safeHTML } from '@wordpress/dom';\n\n/**\n * Renders HTML content as React elements with optional wrapper props.\n *\n * @param {Object} props              - The props for the component.\n * @param {Object} props.wrapperProps - The props to merge with the root element.\n *                                    className and style are merged with the parsed HTML attributes.\n * @param {string} props.html         - The HTML content to render.\n * @return {React.JSX.Element} The rendered React elements.\n */\nconst HtmlRenderer = ( { wrapperProps = {}, html = '' } ) => {\n\tconst options = {\n\t\treplace: ( { name, type, attribs, parent, children } ) => {\n\t\t\tif ( type === 'tag' && name ) {\n\t\t\t\tconst parsedProps = attributesToProps( attribs || {} );\n\t\t\t\tconst TagName = name;\n\t\t\t\tif ( ! parent ) {\n\t\t\t\t\tconst mergedProps = {\n\t\t\t\t\t\t...parsedProps,\n\t\t\t\t\t\t...wrapperProps,\n\t\t\t\t\t\tclassName: clsx(\n\t\t\t\t\t\t\tparsedProps.className,\n\t\t\t\t\t\t\twrapperProps.className\n\t\t\t\t\t\t),\n\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t...( parsedProps.style || {} ),\n\t\t\t\t\t\t\t...( wrapperProps.style || {} ),\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<TagName { ...mergedProps }>\n\t\t\t\t\t\t\t{ domToReact( children, options ) }\n\t\t\t\t\t\t</TagName>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n\n\tconst sanitizedContent = safeHTML( html );\n\tconst parsedContent = parse( sanitizedContent, options );\n\n\treturn parsedContent;\n};\n\nexport default HtmlRenderer;\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAM,gBAAiB,EAAE,eAAe,CAAC,GAAG,OAAO,SAAU;CAC5D,MAAM,UAAU,EACf,UAAW,EAAE,MAAM,MAAM,SAAS,QAAQ,eAAgB;EACzD,IAAK,SAAS,SAAS,MAAO;GAC7B,MAAM,cAAc,kBAAmB,WAAW,CAAC,CAAE;GACrD,MAAM,UAAU;GAChB,IAAK,CAAE,QAAS;IACf,MAAM,cAAc;KACnB,GAAG;KACH,GAAG;KACH,WAAW,KACV,YAAY,WACZ,aAAa,SACd;KACA,OAAO;MACN,GAAK,YAAY,SAAS,CAAC;MAC3B,GAAK,aAAa,SAAS,CAAC;KAC7B;IACD;IACA,OACC,oBAAC,SAAD;KAAS,GAAK;KACX,UAAA,WAAY,UAAU,OAAQ;IACxB,CAAA;GAEX;EACD;CACD,EACD;CAEA,MAAM,mBAAmB,SAAU,IAAK;CAGxC,OAFsB,MAAO,kBAAkB,OAE5B;AACpB"}