{"version":3,"file":"index.mjs","sources":[""],"sourcesContent":["export type TGetHTMLFromStrArgs = Parameters<typeof getHTMLFromStr>;\r\nexport type TGetHTMLFromStrReturn = ReturnType<typeof getHTMLFromStr>;\r\n\r\n/**\r\n * Get parsed HTML from string and return NodeList that includes elements and text\r\n * @param str{string} - source string\r\n * @param {DOMParserSupportedType}type - content type:\r\n *   \"application/xhtml+xml\", \"application/xml\", \"image/svg+xml\",\r\n *   \"text/html\" (default), or \"text/xml\"\r\n * @returns {Promise<NodeList>} Promise resolving to NodeList, or rejecting with TypeError on invalid arguments.\r\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser\r\n * @example\r\n * // How to get parsed HTML elements from string?\r\n * const nodes = await getHTMLFromStr(`\r\n *   <p>Hello world!</p>\r\n *   <p>Hello world!</p>\r\n * `);\n * const elements = Array.from(nodes); // array of two paragraph nodes\n * @example\n * // Parse an SVG string into DOM nodes on the browser or server\n * const iconNodes = await getHTMLFromStr(\n *   `<svg viewBox=\"0 0 24 24\"><path d=\"M4 12h16\" /></svg>`,\n *   \"image/svg+xml\"\n * );\n */\nexport const getHTMLFromStr = async (\r\n  str: string = \"\",\r\n  type: DOMParserSupportedType = \"text/html\"\r\n): Promise<NodeList> => {\r\n\r\n  if (typeof str !== \"string\" || str.length === 0) {\r\n    throw new TypeError(\"getHTMLFromStr: str must be a non-empty string\");\r\n  }\r\n\r\n  const allowed: DOMParserSupportedType[] = [\r\n    \"application/xhtml+xml\",\r\n    \"application/xml\",\r\n    \"image/svg+xml\",\r\n    \"text/html\",\r\n    \"text/xml\",\r\n  ];\r\n\r\n  if (!allowed.includes(type)) {\r\n    throw new TypeError(\"getHTMLFromStr: type must be a supported DOMParser type\");\r\n  }\r\n\r\n  if (typeof DOMParser === \"undefined\") {\n    const { parse } = await import(\"node-html-parser\");\n    return parse(str).childNodes as unknown as NodeList;\n  }\n\r\n  const parsed = new DOMParser().parseFromString(str, type);\n  return type === \"text/html\" ? parsed.body.childNodes : parsed.childNodes;\n};\n"],"names":["getHTMLFromStr","async","str","type","length","TypeError","allowed","includes","DOMParser","parse","import","childNodes","parsed","parseFromString","body"],"mappings":"AAyBO,MAAMA,eAAiBC,MAC5BC,IAAc,GACdC,KAA+B,eAG/B,UAAWD,MAAQ,UAAYA,IAAIE,SAAW,EAC5C,MAAM,IAAIC,UAAU,kDAGtB,MAAMC,QAAoC,CACxC,wBACA,kBACA,gBACA,YACA,YAGF,IAAKA,QAAQC,SAASJ,MACpB,MAAM,IAAIE,UAAU,2DAGtB,UAAWG,YAAc,YAAa,CACpC,MAAMC,MAAEA,aAAgBC,OAAO,oBAC/B,OAAOD,MAAMP,KAAKS,UACpB,CAEA,MAAMC,QAAS,IAAIJ,WAAYK,gBAAgBX,IAAKC,MACpD,OAAOA,OAAS,YAAcS,OAAOE,KAAKH,WAAaC,OAAOD"}