{"version":3,"file":"serializerHelpers.cjs","sources":["../../../src/lib/serializerHelpers.ts"],"sourcesContent":["import { escapeHTML } from \"./escapeHTML\";\nimport {\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTPreformattedNode,\n\tRTImageNode,\n\tRTEmbedNode,\n\tRTLinkNode,\n\tLinkType,\n\tRichTextNodeType,\n} from \"@prismicio/types\";\n\nimport { asLink } from \"../asLink\";\nimport { LinkResolverFunction } from \"../types\";\n\nexport const getLabel = (node: RTBlockNode | RTInlineNode): string => {\n\treturn \"data\" in node && \"label\" in node.data\n\t\t? ` class=\"${node.data.label}\"`\n\t\t: \"\";\n};\n\nexport const serializeStandardTag = (\n\ttag: string,\n\tnode: RTBlockNode | RTInlineNode,\n\tchildren: string[],\n): string => {\n\treturn `<${tag}${getLabel(node)}>${children.join(\"\")}</${tag}>`;\n};\n\nexport const serializePreFormatted = (node: RTPreformattedNode): string => {\n\treturn `<pre${getLabel(node)}>${escapeHTML(node.text)}</pre>`;\n};\n\nexport const serializeImage = (\n\tlinkResolver: LinkResolverFunction<string> | undefined | null,\n\tnode: RTImageNode,\n): string => {\n\tlet imageTag = `<img src=\"${node.url}\" alt=\"${escapeHTML(node.alt)}\"${\n\t\tnode.copyright ? ` copyright=\"${escapeHTML(node.copyright)}\"` : \"\"\n\t} />`;\n\n\t// If the image has a link, we wrap it with an anchor tag\n\tif (node.linkTo) {\n\t\timageTag = serializeHyperlink(\n\t\t\tlinkResolver,\n\t\t\t{\n\t\t\t\ttype: RichTextNodeType.hyperlink,\n\t\t\t\tdata: node.linkTo,\n\t\t\t\tstart: 0,\n\t\t\t\tend: 0,\n\t\t\t},\n\t\t\t[imageTag],\n\t\t);\n\t}\n\n\treturn `<p class=\"block-img\">${imageTag}</p>`;\n};\n\nexport const serializeEmbed = (node: RTEmbedNode): string => {\n\treturn `<div data-oembed=\"${node.oembed.embed_url}\" data-oembed-type=\"${\n\t\tnode.oembed.type\n\t}\" data-oembed-provider=\"${node.oembed.provider_name}\"${getLabel(node)}>${\n\t\tnode.oembed.html\n\t}</div>`;\n};\n\nexport const serializeHyperlink = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n\tnode: RTLinkNode,\n\tchildren: string[],\n): string => {\n\tswitch (node.data.link_type) {\n\t\tcase LinkType.Web: {\n\t\t\treturn `<a href=\"${escapeHTML(node.data.url)}\" ${\n\t\t\t\tnode.data.target ? `target=\"${node.data.target}\" ` : \"\"\n\t\t\t}rel=\"noopener noreferrer\"${getLabel(node)}>${children.join(\"\")}</a>`;\n\t\t}\n\n\t\tcase LinkType.Document: {\n\t\t\treturn `<a href=\"${asLink(node.data, linkResolver)}\"${getLabel(\n\t\t\t\tnode,\n\t\t\t)}>${children.join(\"\")}</a>`;\n\t\t}\n\n\t\tcase LinkType.Media: {\n\t\t\treturn `<a href=\"${node.data.url}\"${getLabel(node)}>${children.join(\n\t\t\t\t\"\",\n\t\t\t)}</a>`;\n\t\t}\n\t}\n};\n\nexport const serializeSpan = (content?: string): string => {\n\treturn content ? escapeHTML(content).replace(/\\n/g, \"<br />\") : \"\";\n};\n"],"names":["escapeHTML","RichTextNodeType","LinkType","asLink"],"mappings":";;;;;AAea,MAAA,WAAW,CAAC,SAA4C;AAC7D,SAAA,UAAU,QAAQ,WAAW,KAAK,OACtC,WAAW,KAAK,KAAK,WACrB;AACJ;AAEO,MAAM,uBAAuB,CACnC,KACA,MACA,aACW;AACJ,SAAA,IAAI,MAAM,SAAS,IAAI,KAAK,SAAS,KAAK,EAAE,MAAM;AAC1D;AAEa,MAAA,wBAAwB,CAAC,SAAoC;AACzE,SAAO,OAAO,SAAS,IAAI,KAAKA,WAAA,WAAW,KAAK,IAAI;AACrD;AAEa,MAAA,iBAAiB,CAC7B,cACA,SACW;AACX,MAAI,WAAW,aAAa,KAAK,aAAaA,sBAAW,KAAK,GAAG,KAChE,KAAK,YAAY,eAAeA,WAAAA,WAAW,KAAK,SAAS,OAAO;AAIjE,MAAI,KAAK,QAAQ;AAChB,eAAW,mBAC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