import{s as f}from"./chunk-DZLz74EQ.js";import{c as h,d as b}from"./jotai-DDOP7CKM.js";import{t as g}from"./react-BcIddLXZ.js";import{br as m,yr as A}from"./cells-B6jS0AIj.js";import{n as E,t as v}from"./jsx-runtime-DvsdsEjx.js";import{t as x}from"./mode-BdfAcJv1.js";import{t as y}from"./copy-icon-5DWltDxB.js";import{t as d}from"./purify.es-D83HMRRD.js";import{t as S}from"./useRunCells-uzADaSkg.js";var _=b(t=>!(t(S)||x()==="read"));function j(){return h(_)}var u="data-temp-href-target";d.addHook("beforeSanitizeAttributes",t=>{t.tagName==="A"&&(t.hasAttribute("target")||t.setAttribute("target","_self"),t.hasAttribute("target")&&t.setAttribute(u,t.getAttribute("target")||""))}),d.addHook("afterSanitizeAttributes",t=>{t.tagName==="A"&&t.hasAttribute(u)&&(t.setAttribute("target",t.getAttribute(u)||""),t.removeAttribute(u),t.getAttribute("target")==="_blank"&&t.setAttribute("rel","noopener"))});function N(t){return d.sanitize(t,{USE_PROFILES:{html:!0,svg:!0,mathMl:!0},FORCE_BODY:!0,CUSTOM_ELEMENT_HANDLING:{tagNameCheck:/^marimo-[A-Za-z][\w-]*$/,attributeNameCheck:/^[A-Za-z][\w-]*$/}})}var z=f(E(),1),c=f(g(),1),n=f(v(),1),w=t=>{if(t instanceof m.Element&&!/^[A-Za-z][\w-]*$/.test(t.name))return c.createElement(c.Fragment)},H=(t,e)=>{if(e instanceof m.Element&&e.name==="body"){if((0,c.isValidElement)(t)&&"props"in t){let r=t.props.children;return(0,n.jsx)(n.Fragment,{children:r})}return}},R=(t,e)=>{if(e instanceof m.Element&&e.name==="html"){if((0,c.isValidElement)(t)&&"props"in t){let r=t.props.children;return(0,n.jsx)(n.Fragment,{children:r})}return}},C=t=>{if(t instanceof m.Element&&t.attribs&&t.name==="iframe"){let e=document.createElement("iframe");return Object.entries(t.attribs).forEach(([r,i])=>{r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1)),e.setAttribute(r,i)}),(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:e.outerHTML}})}},F=t=>{if(t instanceof m.Element&&t.name==="script"){let e=t.attribs.src;if(!e)return;if(!document.querySelector(`script[src="${e}"]`)){let r=document.createElement("script");r.src=e,document.head.append(r)}return(0,n.jsx)(n.Fragment,{})}},M=(t,e,r)=>{var i,a;if(e instanceof m.Element&&e.name==="div"&&((a=(i=e.attribs)==null?void 0:i.class)!=null&&a.includes("codehilite")))return(0,n.jsx)(O,{children:t},r)},O=t=>{let e=(0,z.c)(3),{children:r}=t,i=(0,c.useRef)(null),a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=(0,n.jsx)("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsx)(y,{tooltip:!1,className:"p-1",value:()=>{var l;let o=(l=i.current)==null?void 0:l.firstChild;return o&&o.textContent||""}})}),e[0]=a):a=e[0];let s;return e[1]===r?s=e[2]:(s=(0,n.jsxs)("div",{className:"relative group codehilite-wrapper",ref:i,children:[r,a]}),e[1]=r,e[2]=s),s};const k=({html:t,additionalReplacements:e=[],alwaysSanitizeHtml:r=!0})=>(0,n.jsx)(L,{html:t,alwaysSanitizeHtml:r,additionalReplacements:e});var L=({html:t,additionalReplacements:e=[],alwaysSanitizeHtml:r})=>{let i=j();return T({html:(0,c.useMemo)(()=>r||i?N(t):t,[t,r,i]),additionalReplacements:e})};function T({html:t,additionalReplacements:e=[]}){let r=[w,C,F,...e],i=[M,H,R];return A(t,{replace:(a,s)=>{for(let o of r){let l=o(a,s);if(l)return l}return a},transform:(a,s,o)=>{for(let l of i){let p=l(a,s,o);if(p)return p}return a}})}export{k as t};
