{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/content/raw.ts"],"sourcesContent":["// --- raw() helper: inject pre-rendered HTML without escaping ---\n//\n// Nix.js templates escape interpolated values by default. When rendering\n// Markdown or other trusted HTML, we need to bypass that escaping. `raw()`\n// creates a NixTemplate that inserts the HTML string directly, the same\n// pattern used by `island()` for server-side rendering.\n\nimport { NIX_RENDER_PROTOCOL, type NixTemplate } from \"@deijose/nix-js\";\n\n/**\n * Creates a NixTemplate that renders the given HTML string without escaping.\n *\n * **Security:** Only use `raw()` with trusted content (e.g. Markdown you\n * authored, or HTML you generated and sanitized). Never use it with\n * user-supplied input without sanitization.\n */\nexport function raw(html: string): NixTemplate {\n  return {\n    __isNixTemplate: true as const,\n    [NIX_RENDER_PROTOCOL]: {\n      renderServer: () => html,\n    },\n    mount(container: Element | string) {\n      const el = typeof container === \"string\" ? document.querySelector(container) : container;\n      if (!el) throw new Error(\"[nix-js-kit] raw(): container not found\");\n      el.innerHTML = html;\n      return {\n        unmount() {\n          el.innerHTML = \"\";\n        },\n      };\n    },\n    _render(parent: Node, before: Node | null): () => void {\n      const wrapper = document.createElement(\"template\");\n      wrapper.innerHTML = html;\n      const fragment = wrapper.content;\n      const inserted = Array.from(fragment.childNodes);\n      parent.insertBefore(fragment, before);\n      return () => {\n        for (const node of inserted) {\n          if (node.parentNode) node.parentNode.removeChild(node);\n        }\n      };\n    },\n  } as unknown as NixTemplate;\n}\n"],"mappings":"mJAgBA,SAAgB,EAAI,EAA2B,CAC7C,MAAO,CACL,gBAAiB,IAChB,EAAA,qBAAsB,CACrB,iBAAoB,CACtB,EACA,MAAM,EAA6B,CACjC,IAAM,EAAK,OAAO,GAAc,SAAW,SAAS,cAAc,CAAS,EAAI,EAC/E,GAAI,CAAC,EAAI,MAAU,MAAM,yCAAyC,EAElE,MADA,GAAG,UAAY,EACR,CACL,SAAU,CACR,EAAG,UAAY,EACjB,CACF,CACF,EACA,QAAQ,EAAc,EAAiC,CACrD,IAAM,EAAU,SAAS,cAAc,UAAU,EACjD,EAAQ,UAAY,EACpB,IAAM,EAAW,EAAQ,QACnB,EAAW,MAAM,KAAK,EAAS,UAAU,EAE/C,OADA,EAAO,aAAa,EAAU,CAAM,MACvB,CACX,IAAK,IAAM,KAAQ,EACb,EAAK,YAAY,EAAK,WAAW,YAAY,CAAI,CAEzD,CACF,CACF,CACF"}